├── AUTHORS
├── Admin
├── Manual.txt
├── conf.json
├── css
│ ├── bootstrap-modal-bs3patch.css
│ ├── bootstrap-modal.css
│ ├── bootstrap.css
│ ├── css.css
│ └── whitedb.css
├── fonts
│ ├── glyphicons-halflings-regular.eot
│ ├── glyphicons-halflings-regular.svg
│ ├── glyphicons-halflings-regular.ttf
│ └── glyphicons-halflings-regular.woff
├── html
│ ├── data.html
│ ├── edit.html
│ ├── graph.html
│ └── new.html
├── index.html
└── js
│ ├── ._templates.js
│ ├── bootstrap-modal.js
│ ├── bootstrap-modalmanager.js
│ ├── bootstrap.min.js
│ ├── d3.min.js
│ ├── data.js
│ ├── edit.js
│ ├── graph.js
│ ├── handlebars.js
│ ├── helpers.js
│ ├── index.js
│ ├── jquery-2.1.0.min.js
│ ├── js.js
│ ├── new.js
│ └── templates.js
├── Bootstrap
├── COPYING
├── ChangeLog
├── Db
├── Makefile.am
├── crc1.h
├── dballoc.c
├── dballoc.h
├── dbapi.h
├── dbcompare.c
├── dbcompare.h
├── dbdata.c
├── dbdata.h
├── dbdump.c
├── dbdump.h
├── dbfeatures.h
├── dbhash.c
├── dbhash.h
├── dbindex.c
├── dbindex.h
├── dbjson.c
├── dbjson.h
├── dblock.c
├── dblock.h
├── dblog.c
├── dblog.h
├── dbmem.c
├── dbmem.h
├── dbmpool.c
├── dbmpool.h
├── dbquery.c
├── dbquery.h
├── dbschema.c
├── dbschema.h
├── dbutil.c
├── dbutil.h
├── indexapi.h
└── rdfapi.h
├── Doc
├── Install.txt
├── Install2html.sed
├── Manual.txt
├── Manual2html.sed
├── Tutorial.txt
├── Tutorial2html.sed
├── Utilities.txt
├── python.txt
├── python2html.sed
└── whitedb.7
├── Doxyfile
├── Examples
├── Makefile.am
├── compile_demo.bat
├── compile_demo.sh
├── compile_query.bat
├── compile_query.sh
├── demo.c
├── dserve.c
├── query.c
├── raptortry.c
├── speed
│ ├── README
│ ├── speed1.c
│ ├── speed10.c
│ ├── speed11.c
│ ├── speed12.c
│ ├── speed13.c
│ ├── speed15.c
│ ├── speed16.c
│ ├── speed2.c
│ ├── speed20.c
│ ├── speed21.c
│ ├── speed3.c
│ ├── speed4.c
│ ├── speed5.c
│ ├── speed6.c
│ ├── speed7.c
│ └── speed8.c
├── tut1.c
├── tut2.c
├── tut3.c
├── tut4.c
├── tut5.c
├── tut6.c
└── tut7.c
├── GPLLICENCE
├── INSTALL
├── MANIFEST
├── Main
├── Makefile.am
├── gendata.c
├── indextool.c
├── selftest.c
├── stresstest.c
└── wgdb.c
├── Makefile.am
├── NEWS
├── Parser
├── Makefile.am
├── dbgenparse.h
├── dbotter.l
├── dbotter.y
├── dbotterparse.h
├── dbparse.c
├── dbparse.h
├── dbprolog.l
├── dbprolog.y
└── dbprologparse.h
├── Printer
├── Makefile.am
├── dbotterprint.c
└── dbotterprint.h
├── Python
├── Makefile.am
├── WGandalf.py
├── compile.bat
├── compile.sh
├── tests.py
├── wgdbmodule.c
└── whitedb.py
├── README
├── README.asc
├── Reasoner
├── Makefile.am
├── build.c
├── build.h
├── clstore.c
├── clstore.h
├── clterm.c
├── clterm.h
├── derive.c
├── derive.h
├── glb.c
├── glb.h
├── mem.c
├── mem.h
├── printerrutils.c
├── printerrutils.h
├── rgenloop.c
├── rgenloop.h
├── rincludes.h
├── rmain.c
├── rmain.h
├── rtechdoc.txt
├── subsume.c
├── subsume.h
├── types.h
├── unify.c
└── unify.h
├── Rexamples
├── luka.txt
├── luka2.txt
├── otter.txt
├── otter1.txt
├── otter2.txt
├── otter4.txt
├── otter5.txt
├── otter7.txt
├── otter_parse_test.txt
├── p1.otter
├── rrun
├── rules.txt
├── steam.txt
├── viga.txt
└── wrong_notprovable.txt
├── Server
├── Makefile
├── Manifest
├── Manual.txt
├── README
├── compile.bat
├── compile.sh
├── conf.txt
├── conf_example.txt
├── dserve.c
├── dserve.h
├── dserve_net.c
├── dserve_util.c
├── examplecertificate.crt
├── exampleprivateKey.key
├── exampleprivateKey.pem
├── exampleprivatekey.key
├── nsmeasure.c
└── timecmd.bat
├── Test
├── Makefile.am
├── common.test
├── dbtest.c
├── dbtest.h
├── log.test
├── rtest.c
└── rtest.h
├── acinclude.m4
├── compile.bat
├── compile.sh
├── config-gcc.h
├── config-w32.h
├── configure.ac
├── gendoc.sh
├── java
└── jni
│ ├── Readme.txt
│ ├── classes
│ └── .gitignore
│ ├── compileBridge.bat
│ ├── compileJava.bat
│ ├── compile_bridge.sh
│ ├── compile_java.sh
│ ├── config.h
│ ├── library
│ └── .gitignore
│ ├── runJava.bat
│ ├── run_java.sh
│ ├── setEnv.bat
│ └── src
│ ├── native
│ └── whitedbDriver.c
│ └── whitedb
│ ├── driver
│ ├── WhiteDB.java
│ └── tests.java
│ ├── holder
│ ├── Database.java
│ ├── Query.java
│ ├── Record.java
│ └── SampleObject.java
│ └── util
│ ├── ArgListEntry.java
│ └── FieldComparator.java
├── json
├── Makefile.am
├── yajl_all.c
├── yajl_all.h
└── yajl_api.h
├── unite.sh
├── wgdb.def
└── whitedb.pc.in
/AUTHORS:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/priitj/whitedb/9d898103330695dd18db5839120e0d2522329154/AUTHORS
--------------------------------------------------------------------------------
/Admin/Manual.txt:
--------------------------------------------------------------------------------
1 | Copy files into a folder which Apache folder. For example /var/www/ in Ubuntu.
2 | Configure conf.json according to where you have dserve and which database you use.
--------------------------------------------------------------------------------
/Admin/conf.json:
--------------------------------------------------------------------------------
1 | {
2 | "url" : "http://localhost/cgi-bin/dserve",
3 | "database" : "1000"
4 | }
--------------------------------------------------------------------------------
/Admin/css/bootstrap-modal-bs3patch.css:
--------------------------------------------------------------------------------
1 | /*!
2 | * Bootstrap Modal
3 | *
4 | * Copyright Jordan Schroter
5 | * Licensed under the Apache License v2.0
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Boostrap 3 patch for for bootstrap-modal. Include BEFORE bootstrap-modal.css!
9 | */
10 |
11 | body.modal-open,
12 | .modal-open .navbar-fixed-top,
13 | .modal-open .navbar-fixed-bottom {
14 | margin-right: 0;
15 | }
16 |
17 | .modal {
18 | left: 50%;
19 | bottom: auto;
20 | right: auto;
21 | padding: 0;
22 | width: 500px;
23 | margin-left: -250px;
24 | background-color: #ffffff;
25 | border: 1px solid #999999;
26 | border: 1px solid rgba(0, 0, 0, 0.2);
27 | border-radius: 6px;
28 | -webkit-box-shadow: 0 3px 9px rgba(0, 0, 0, 0.5);
29 | box-shadow: 0 3px 9px rgba(0, 0, 0, 0.5);
30 | background-clip: padding-box;
31 | }
32 |
33 | .modal.container {
34 | max-width: none;
35 | }
--------------------------------------------------------------------------------
/Admin/css/css.css:
--------------------------------------------------------------------------------
1 | .remove-item {
2 | display: inline-block;
3 | padding: 6px 12px;
4 | margin-bottom: 0;
5 | font-size: 14px;
6 | font-weight: normal;
7 | line-height: 1.42857143;
8 | text-align: center;
9 | white-space: nowrap;
10 | vertical-align: middle;
11 | cursor: pointer;
12 | -webkit-user-select: none;
13 | -moz-user-select: none;
14 | -ms-user-select: none;
15 | user-select: none;
16 | background-image: none;
17 | border: 1px solid transparent;
18 | border-radius: 4px;
19 | }
20 | .show-buttons {
21 | padding-bottom: 5px;
22 | }
23 | .kustuta {
24 | margin-right: 5px;
25 | }
26 | .full-width {
27 | width: 100% !important;
28 | }
29 | .id-div {
30 | /*font-weight: bold;*/
31 | font-size: 20px;
32 | }
33 | .edit-container {
34 | padding: 0 !important;
35 | margin-top: 0 !important;
36 | }
37 | .select-field {
38 | width: 83.33333333% !important;
39 | }
40 | .margin-right {
41 | padding-right: 10px;
42 | }
43 | .index-pointer {
44 | cursor: default;
45 | }
46 | .field-error {
47 | border-color: rgb(169, 68, 66);
48 | box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset, 0 0 6px rgb(206, 132, 131);
49 | }
50 | .error-span {
51 | color: rgb(169, 68, 66);
52 | font-weight: bold;
53 | }
54 | .error-div {
55 | color: rgb(169, 68, 66);
56 | font-weight: bold;
57 | font-size: 18px;
58 | }
59 | .index {
60 | margin-left: 50px;
61 | margin-right: 50px;
62 | }
63 |
64 | #end-arrow {
65 | marker-end: url("#end-arrow");
66 | }
--------------------------------------------------------------------------------
/Admin/fonts/glyphicons-halflings-regular.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/priitj/whitedb/9d898103330695dd18db5839120e0d2522329154/Admin/fonts/glyphicons-halflings-regular.eot
--------------------------------------------------------------------------------
/Admin/fonts/glyphicons-halflings-regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/priitj/whitedb/9d898103330695dd18db5839120e0d2522329154/Admin/fonts/glyphicons-halflings-regular.ttf
--------------------------------------------------------------------------------
/Admin/fonts/glyphicons-halflings-regular.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/priitj/whitedb/9d898103330695dd18db5839120e0d2522329154/Admin/fonts/glyphicons-halflings-regular.woff
--------------------------------------------------------------------------------
/Admin/html/data.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
53 |
54 |
101 |
102 |
103 |
--------------------------------------------------------------------------------
/Admin/js/._templates.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/priitj/whitedb/9d898103330695dd18db5839120e0d2522329154/Admin/js/._templates.js
--------------------------------------------------------------------------------
/Admin/js/data.js:
--------------------------------------------------------------------------------
1 | $(function(){
2 | Configuration = getConf("../conf.json");
3 | getShowData(location.search.substring(1));
4 |
5 | $('.delete').on('click', function(){
6 | deleteRecord($('.id-span').text());
7 | });
8 | $('.change').on('click', function(){
9 | redirect("edit.html?recids="+$('.id-span').text());
10 | });
11 | $('.back').on('click', function(){
12 | parent.history.back();
13 | return false;
14 | });
15 | });
16 |
17 | function deleteRecord(id){
18 | $.ajax({
19 | type: 'GET',
20 | url: Configuration.url+"?db="+Configuration.database+"&op=delete&recids=" + id,
21 | dataType: 'json',
22 | success: function(data){
23 | $(location).attr('href',"../index.html");
24 | }
25 | });
26 | }
27 |
28 | function getShowData(data){
29 | var res = [];
30 | var rows = {rows:[]};
31 | var ajax = $.ajax({
32 | type: "GET",
33 | url: Configuration.url+"?db="+Configuration.database+"&" + data,
34 | dataType: 'json',
35 | success: function (data) {
36 | if(!error(data)){
37 | $.each(data, function(key, val){
38 | $('.id-span').append(val[0]);
39 | rows.rows.push(val);
40 | })
41 | var theTemplateScript = Templates.show;
42 |
var theTemplate = Handlebars.compile(theTemplateScript);
43 | $('.main-container').append(theTemplate(rows));
44 | }
45 |
46 | }
47 | });
48 | }
49 |
--------------------------------------------------------------------------------
/Admin/js/edit.js:
--------------------------------------------------------------------------------
1 | $(function(){
2 | Configuration = getConf("../conf.json");
3 | getEditData(location.search.substring(1).split('&'));
4 | $('.back').on('click', function(){
5 | parent.history.back();
6 | return false;
7 | });
8 | $('.save').on('click', function(){
9 | updateData($('.edit-form').serialize());
10 | })
11 | });
12 |
13 | function deleteRecord(id){
14 | $.ajax({
15 | type: 'GET',
16 | url: Configuration.url+"?db="+Configuration.database+"&op=delete&recids=" + id,
17 | dataType: 'json',
18 | success: function(data){
19 | $(location).attr('href',"../index.html");
20 | }
21 | });
22 | }
23 |
24 | function getEditData(dataId){
25 | var res = [];
26 | var rows = {rows:[]};
27 | var ajax = $.ajax({
28 | type: "GET",
29 | url: Configuration.url+"?db="+Configuration.database+"&op=search&showid=yes&"+dataId,
30 | dataType: 'json',
31 | success: function (data) {
32 | console.log(data);
33 | if (data.length > 0) {
34 | if(!error(data)){
35 | $.each(data, function(key, val){
36 | $('.id-span').append(val[0]);
37 | rows.rows.push(val);
38 | });
39 | var theTemplateScript = Templates.edit;
40 |
var theTemplate = Handlebars.compile(theTemplateScript);
41 | $('.main-container').append(theTemplate(rows));
42 | }
43 | }else{
44 | $('.error-div').html("No record found");
45 | $('.edit-container').hide();
46 | };
47 | }
48 | });
49 | }
50 |
--------------------------------------------------------------------------------
/Admin/js/helpers.js:
--------------------------------------------------------------------------------
1 | (function (root, factory) {
2 | if (typeof exports === 'object') {
3 | module.exports = factory(require('handlebars'));
4 | } else if (typeof define === 'function' && define.amd) {
5 | define(['handlebars'], factory);
6 | } else {
7 | root.HandlebarsHelpersRegistry = factory(root.Handlebars);
8 | }
9 | }(this, function (Handlebars) {
10 |
11 | var isArray = function(value) {
12 | return Object.prototype.toString.call(value) === '[object Array]';
13 | }
14 |
15 | var ExpressionRegistry = function() {
16 | this.expressions = [];
17 | };
18 |
19 | ExpressionRegistry.prototype.add = function (operator, method) {
20 | this.expressions[operator] = method;
21 | };
22 |
23 | ExpressionRegistry.prototype.call = function (operator, left, right) {
24 | if ( ! this.expressions.hasOwnProperty(operator)) {
25 | throw new Error('Unknown operator "'+operator+'"');
26 | }
27 |
28 | return this.expressions[operator](left, right);
29 | };
30 |
31 | var eR = new ExpressionRegistry;
32 | eR.add('not', function(left, right) {
33 | return left != right;
34 | });
35 | eR.add('>', function(left, right) {
36 | return left > right;
37 | });
38 | eR.add('<', function(left, right) {
39 | return left < right;
40 | });
41 | eR.add('>=', function(left, right) {
42 | return left >= right;
43 | });
44 | eR.add('<=', function(left, right) {
45 | return left <= right;
46 | });
47 | eR.add('===', function(left, right) {
48 | return left === right;
49 | });
50 | eR.add('!==', function(left, right) {
51 | return left !== right;
52 | });
53 | eR.add('in', function(left, right) {
54 | if ( ! isArray(right)) {
55 | right = right.split(',');
56 | }
57 | return right.indexOf(left) !== -1;
58 | });
59 |
60 | var isHelper = function() {
61 | var args = arguments
62 | , left = args[0]
63 | , operator = args[1]
64 | , right = args[2]
65 | , options = args[3]
66 | ;
67 |
68 | if (args.length == 2) {
69 | options = args[1];
70 | if (left) return options.fn(this);
71 | return options.inverse(this);
72 | }
73 |
74 | if (args.length == 3) {
75 | right = args[1];
76 | options = args[2];
77 | if (left == right) return options.fn(this);
78 | return options.inverse(this);
79 | }
80 |
81 | if (eR.call(operator, left, right)) {
82 | return options.fn(this);
83 | }
84 | return options.inverse(this);
85 | };
86 |
87 | Handlebars.registerHelper('is', isHelper);
88 |
89 | Handlebars.registerHelper('nl2br', function(text) {
90 | var nl2br = (text + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + '
' + '$2');
91 | return new Handlebars.SafeString(nl2br);
92 | });
93 |
94 | Handlebars.registerHelper('log', function() {
95 | console.log(['Values:'].concat(
96 | Array.prototype.slice.call(arguments, 0, -1)
97 | ));
98 | });
99 |
100 | Handlebars.registerHelper('debug', function() {
101 | console.log('Context:', this);
102 | console.log(['Values:'].concat(
103 | Array.prototype.slice.call(arguments, 0, -1)
104 | ));
105 | });
106 | return eR;
107 | }));
--------------------------------------------------------------------------------
/Admin/js/js.js:
--------------------------------------------------------------------------------
1 | function error(str){
2 | if(str.indexOf("ERROR")>-1){
3 | $('.error-div').html(str);
4 | $('.main-container').hide();
5 | $('.main-pager').hide();
6 | $('.error-div').show();
7 | return true;
8 | }else{
9 | $('.error-div').hide();
10 | $('.main-container').show();
11 | $('.main-pager').show();
12 | return false;
13 | }
14 | }
15 |
16 | function getConf(url){
17 | var conf = {};
18 | $.ajax({
19 | url: url,
20 | async: false,
21 | success: function(data){
22 | conf = data;
23 | }
24 | });
25 | return conf;
26 | }
27 |
28 | function updateData(formData){
29 |
30 | }
31 |
32 | function redirect(url){
33 | window.location = url;
34 | }
35 |
36 | function isRecord(str){
37 | return str.slice(0,2) == "r:";
38 | }
39 |
40 | function hasMoreThanNChars(str, count){
41 | var c = parseInt(count);
42 | if(str.length > c){
43 | return str.slice(0, c) + "...";
44 | }else{
45 | return str;
46 | }
47 | }
48 |
49 | Handlebars.registerHelper("substract", function(from, value){
50 | return parseInt(from) - parseInt(value);
51 | });
52 |
53 | Handlebars.registerHelper("append_new", function(value){
54 | return value;
55 | });
56 |
57 | Handlebars.registerHelper("is_record", function(value){
58 | var str = value.toString();
59 | if (isRecord(str)){
60 | return "
";
61 | }else{
62 | return str;
63 | }
64 | });
65 |
66 | Handlebars.registerHelper("show_first_n", function(value, count){
67 | var str = value.toString();
68 | if (isRecord(str)){
69 | var record = str.slice(2);
70 | return "
"+record+"";
71 | }else{
72 | return hasMoreThanNChars(str, count);
73 | }
74 | });
--------------------------------------------------------------------------------
/Admin/js/new.js:
--------------------------------------------------------------------------------
1 | $(function(){
2 | Configuration = getConf("../conf.json");
3 | var i = -1;
4 | $('.add-field').on('click', function(event){
5 | event.preventDefault();
6 | if($('.new-field-data').val()==""){
7 | $('.new-field-data').addClass("field-error");
8 | $('.error-span').html('Enter a value');
9 | return false;
10 | }else{
11 | var rows = {rows: []}
12 | var theTemplateScript = Templates.add_new_field;
13 |
var theTemplate = Handlebars.compile(theTemplateScript);
14 |
15 | rows.rows.push($('.new-field-data').val());
16 | $('.new-row-form').append(theTemplate(rows));
17 |
18 | i++;
19 | $('.field-label').last().html(i);
20 | $('.new-field-data').val("");
21 | }
22 | });
23 | $('.new-row-form').on('click', '.remove-item', function(event){
24 | event.preventDefault();
25 | $(this).parent('.form-group').remove();
26 | i = 0;
27 | $.each($('.field-label'), function(){
28 | $(this).html(i++);
29 | });
30 | });
31 | $('.create').on('click', function(){
32 | var data = "rec=";
33 | $.each($('.field'), function(){
34 | data += $(this).val()+",";
35 | console.log($(this).val());
36 | })
37 | console.log(data.slice(0, -1));
38 | });
39 | $('.new-field-data').on('click', function(){
40 | $(this).removeClass('field-error');
41 | $('.error-span').html('');
42 | })
43 | });
--------------------------------------------------------------------------------
/Admin/js/templates.js:
--------------------------------------------------------------------------------
1 | Templates = {}
2 | Templates.index_view = [
3 | ""
30 | ].join('\n')
31 |
32 | Templates.show = [
33 | "
",
34 | "{{#each rows}}",
35 | "{{#each this}}",
36 | "{{#is @index '>' 0}}",
37 | "",
38 | "{{#substract @index 1}}{{/substract}} | ",
39 | "{{#is_record this}}{{/is_record}} | ",
40 | "
",
41 | "{{/is}}",
42 | "{{/each}}",
43 | "{{/each}}",
44 | "
"
45 | ].join('\n')
46 |
47 | Templates.edit = [
48 | "
"
66 | ].join('\n')
67 |
68 |
69 | Templates.add_new_field = [
70 | "
"
88 | ].join('\n')
--------------------------------------------------------------------------------
/Bootstrap:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # $Id: $
4 | # $Source: $
5 |
6 | # Booting up the GNU automake, autoconf, etc system:
7 | # not needed after the configure executable script has been built
8 |
9 | # Need to use use autoconf >= 2.50 an automake >= 1.5. This allows user to
10 | # set these variables in their environment, or to just use the defaults below.
11 | # This is needed since some systems still use autoconf-2.13 and automake-1.4 as
12 | # the defaults (e.g. debian).
13 |
14 | : ${ACLOCAL=aclocal}
15 | : ${AUTOMAKE=automake}
16 | : ${AUTOCONF=autoconf}
17 | : ${AUTOHEADER=autoheader}
18 | : ${LIBTOOLIZE=libtoolize}
19 |
20 | command -v glibtoolize && LIBTOOLIZE=glibtoolize
21 |
22 | set -e
23 |
24 | set -x
25 | (
26 | ${ACLOCAL}
27 | ${AUTOHEADER}
28 | ${AUTOCONF}
29 | ${LIBTOOLIZE} --no-warn
30 | [ -d config-aux ] || mkdir config-aux
31 | ${AUTOMAKE} -a -c
32 | )
33 | rm -f config.cache
34 |
--------------------------------------------------------------------------------
/ChangeLog:
--------------------------------------------------------------------------------
1 | ChangeLog
2 | =========
3 |
4 | Nothing here: see https://github.com/priitj/whitedb for history
--------------------------------------------------------------------------------
/Db/Makefile.am:
--------------------------------------------------------------------------------
1 | #
2 | # - - - - main db sources - - -
3 |
4 | noinst_LTLIBRARIES = libDb.la
5 | libDb_la_SOURCES = dbmem.c dbmem.h\
6 | dballoc.c dballoc.h dbfeatures.h\
7 | dbdata.c dbdata.h\
8 | dblock.c dblock.h\
9 | dbdump.c dbdump.h crc1.h\
10 | dblog.c dblog.h\
11 | dbhash.c dbhash.h\
12 | dbindex.c dbindex.h\
13 | dbcompare.c dbcompare.h\
14 | dbquery.c dbquery.h\
15 | dbutil.c dbutil.h\
16 | dbmpool.c dbmpool.h\
17 | dbjson.c dbjson.h\
18 | dbschema.c dbschema.h
19 |
20 | if RAPTOR
21 | AM_CFLAGS += `$(RAPTOR_CONFIG) --cflags`
22 | endif
23 |
24 |
--------------------------------------------------------------------------------
/Db/dbcompare.h:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Priit Järv 2010
6 | *
7 | * This file is part of WhiteDB
8 | *
9 | * WhiteDB is free software: you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation, either version 3 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * WhiteDB is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with WhiteDB. If not, see
.
21 | *
22 | */
23 |
24 | /** @file dbcompare.h
25 | * Public headers for data comparison functions.
26 | */
27 |
28 | #ifndef DEFINED_DBCOMPARE_H
29 | #define DEFINED_DBCOMPARE_H
30 | #ifdef _WIN32
31 | #include "../config-w32.h"
32 | #else
33 | #include "../config.h"
34 | #endif
35 |
36 | /* For gint data type */
37 | #include "dbdata.h"
38 |
39 | /* ==== Public macros ==== */
40 |
41 | #define WG_EQUAL 0
42 | #define WG_GREATER 1
43 | #define WG_LESSTHAN -1
44 |
45 | /* If backlinking is enabled, records can be compared by their
46 | * contents instead of just pointers. With no backlinking this
47 | * is disabled so that records' comparative values do not change
48 | * when updating their contents.
49 | */
50 | #ifdef USE_BACKLINKING
51 | #define WG_COMPARE_REC_DEPTH 7 /** recursion depth for record comparison */
52 | #else
53 | #define WG_COMPARE_REC_DEPTH 0
54 | #endif
55 |
56 | /* wrapper macro for wg_compare(), if encoded values are
57 | * equal they will also decode to an equal value and so
58 | * we can avoid calling the function.
59 | */
60 | #define WG_COMPARE(d,a,b) (a==b ? WG_EQUAL :\
61 | wg_compare(d,a,b,WG_COMPARE_REC_DEPTH))
62 |
63 | /* ==== Protos ==== */
64 |
65 | gint wg_compare(void *db, gint a, gint b, int depth);
66 |
67 | #endif /* DEFINED_DBCOMPARE_H */
68 |
--------------------------------------------------------------------------------
/Db/dbdump.h:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Andri Rebane 2009
6 | *
7 | * This file is part of WhiteDB
8 | *
9 | * WhiteDB is free software: you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation, either version 3 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * WhiteDB is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with WhiteDB. If not, see
.
21 | *
22 | */
23 |
24 | /** @file dbdump.h
25 | * Public headers for memory dumping to the disk.
26 | */
27 |
28 | #ifndef DEFINED_DBDUMP_H
29 | #define DEFINED_DBDUMP_H
30 | #ifdef _WIN32
31 | #include "../config-w32.h"
32 | #else
33 | #include "../config.h"
34 | #endif
35 |
36 | /* ====== data structures ======== */
37 |
38 |
39 | /* ==== Protos ==== */
40 |
41 | gint wg_dump(void * db,char fileName[]); /* dump shared memory database to the disk */
42 | gint wg_dump_internal(void * db,char fileName[], int locking); /* handle the dump */
43 | gint wg_import_dump(void * db,char fileName[]); /* import database from the disk */
44 | gint wg_check_dump(void *db, char fileName[],
45 | gint *mixsize, gint *maxsize); /* check the dump file and get the db size */
46 |
47 | #endif /* DEFINED_DBDUMP_H */
48 |
--------------------------------------------------------------------------------
/Db/dbfeatures.h:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Priit Järv 2010
6 | *
7 | * This file is part of WhiteDB
8 | *
9 | * WhiteDB is free software: you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation, either version 3 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * WhiteDB is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with WhiteDB. If not, see
.
21 | *
22 | */
23 |
24 | /** @file dbfeatures.h
25 | * Constructs bit vector of libwgdb compile-time features
26 | */
27 |
28 | #ifndef DEFINED_DBFEATURES_H
29 | #define DEFINED_DBFEATURES_H
30 |
31 | #ifdef _WIN32
32 | #include "../config-w32.h"
33 | #else
34 | #include "../config.h"
35 | #endif
36 |
37 | /* Used to check for individual features */
38 | #define FEATURE_BITS_64BIT 0x1
39 | #define FEATURE_BITS_QUEUED_LOCKS 0x2
40 | #define FEATURE_BITS_TTREE_CHAINED 0x4
41 | #define FEATURE_BITS_BACKLINK 0x8
42 | #define FEATURE_BITS_CHILD_DB 0x10
43 | #define FEATURE_BITS_INDEX_TMPL 0x20
44 |
45 | /* Construct the bit vector */
46 | #ifdef HAVE_64BIT_GINT
47 | #define FEATURE_BITS_01 FEATURE_BITS_64BIT
48 | #else
49 | #define FEATURE_BITS_01 0x0
50 | #endif
51 |
52 | #if (LOCK_PROTO==3)
53 | #define FEATURE_BITS_02 FEATURE_BITS_QUEUED_LOCKS
54 | #else
55 | #define FEATURE_BITS_02 0x0
56 | #endif
57 |
58 | #ifdef TTREE_CHAINED_NODES
59 | #define FEATURE_BITS_03 FEATURE_BITS_TTREE_CHAINED
60 | #else
61 | #define FEATURE_BITS_03 0x0
62 | #endif
63 |
64 | #ifdef USE_BACKLINKING
65 | #define FEATURE_BITS_04 FEATURE_BITS_BACKLINK
66 | #else
67 | #define FEATURE_BITS_04 0x0
68 | #endif
69 |
70 | #ifdef USE_CHILD_DB
71 | #define FEATURE_BITS_05 FEATURE_BITS_CHILD_DB
72 | #else
73 | #define FEATURE_BITS_05 0x0
74 | #endif
75 |
76 | #ifdef USE_INDEX_TEMPLATE
77 | #define FEATURE_BITS_06 FEATURE_BITS_INDEX_TMPL
78 | #else
79 | #define FEATURE_BITS_06 0x0
80 | #endif
81 |
82 | #define MEMSEGMENT_FEATURES (FEATURE_BITS_01 |\
83 | FEATURE_BITS_02 |\
84 | FEATURE_BITS_03 |\
85 | FEATURE_BITS_04 |\
86 | FEATURE_BITS_05 |\
87 | FEATURE_BITS_06)
88 |
89 | #endif /* DEFINED_DBFEATURES_H */
90 |
--------------------------------------------------------------------------------
/Db/dbhash.h:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Tanel Tammet 2004,2005,2006,2007,2008,2009
6 | * Copyright (c) Priit Järv 2013,2014
7 | *
8 | * Contact: tanel.tammet@gmail.com
9 | *
10 | * This file is part of WhiteDB
11 | *
12 | * WhiteDB is free software: you can redistribute it and/or modify
13 | * it under the terms of the GNU General Public License as published by
14 | * the Free Software Foundation, either version 3 of the License, or
15 | * (at your option) any later version.
16 | *
17 | * WhiteDB is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU General Public License
23 | * along with WhiteDB. If not, see
.
24 | *
25 | */
26 |
27 | /** @file dbhash.h
28 | * Public headers for hash-related procedures.
29 | */
30 |
31 | #ifndef DEFINED_DBHASH_H
32 | #define DEFINED_DBHASH_H
33 |
34 | #ifdef _WIN32
35 | #include "../config-w32.h"
36 | #else
37 | #include "../config.h"
38 | #endif
39 | #include "dballoc.h"
40 |
41 | /* ==== Public macros ==== */
42 |
43 | #define HASHIDX_META_POS 1
44 | #define HASHIDX_RECLIST_POS 2
45 | #define HASHIDX_HASHCHAIN_POS 3
46 | #define HASHIDX_HEADER_SIZE 4
47 |
48 | /* ==== Protos ==== */
49 |
50 | int wg_hash_typedstr(void* db, const char* data, const char* extrastr, gint type, gint length);
51 | gint wg_find_strhash_bucket(void* db, const char* data, const char* extrastr, gint type, gint size, gint hashchain);
52 | int wg_right_strhash_bucket
53 | (void* db, gint longstr, const char* cstr, const char* cextrastr, gint ctype, gint cstrsize);
54 | gint wg_remove_from_strhash(void* db, gint longstr);
55 |
56 | gint wg_decode_for_hashing(void *db, gint enc, char **decbytes);
57 | gint wg_idxhash_store(void* db, db_hash_area_header *ha,
58 | char* data, gint length, gint offset);
59 | gint wg_idxhash_remove(void* db, db_hash_area_header *ha,
60 | char* data, gint length, gint offset);
61 | gint wg_idxhash_find(void* db, db_hash_area_header *ha,
62 | char* data, gint length);
63 |
64 | void *wg_ginthash_init(void *db);
65 | gint wg_ginthash_addkey(void *db, void *tbl, gint key, gint val);
66 | gint wg_ginthash_getkey(void *db, void *tbl, gint key, gint *val);
67 | void wg_ginthash_free(void *db, void *tbl);
68 |
69 | void *wg_dhash_init(void *db, size_t entries);
70 | void wg_dhash_free(void *db, void *tbl);
71 | gint wg_dhash_addkey(void *db, void *tbl, gint key);
72 | gint wg_dhash_haskey(void *db, void *tbl, gint key);
73 |
74 | #endif /* DEFINED_DBHASH_H */
75 |
--------------------------------------------------------------------------------
/Db/dbjson.h:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Priit Järv 2013, 2014
6 | *
7 | * This file is part of WhiteDB
8 | *
9 | * WhiteDB is free software: you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation, either version 3 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * WhiteDB is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with WhiteDB. If not, see
.
21 | *
22 | */
23 |
24 | /** @file dbjson.h
25 | * Public headers for JSON I/O.
26 | */
27 |
28 | #ifndef DEFINED_DBJSON_H
29 | #define DEFINED_DBJSON_H
30 |
31 |
32 | /* ====== data structures ======== */
33 |
34 |
35 | /* ==== Protos ==== */
36 |
37 | gint wg_parse_json_file(void *db, const char *filename);
38 | gint wg_check_json(void *db, const char *buf);
39 | gint wg_parse_json_document(void *db, const char *buf, void **document);
40 | gint wg_parse_json_fragment(void *db, const char *buf, void **document);
41 | gint wg_parse_json_param(void *db, const char *buf, void **document);
42 | void wg_print_json_document(void *db, void *cb, void *cb_ctx, void *document);
43 |
44 | #endif /* DEFINED_DBJSON_H */
45 |
--------------------------------------------------------------------------------
/Db/dblog.h:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Andri Rebane 2009
6 | * Copyright (c) Priit Järv 2013,2014
7 | *
8 | * This file is part of WhiteDB
9 | *
10 | * WhiteDB is free software: you can redistribute it and/or modify
11 | * it under the terms of the GNU General Public License as published by
12 | * the Free Software Foundation, either version 3 of the License, or
13 | * (at your option) any later version.
14 | *
15 | * WhiteDB is distributed in the hope that it will be useful,
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 | * GNU General Public License for more details.
19 | *
20 | * You should have received a copy of the GNU General Public License
21 | * along with WhiteDB. If not, see
.
22 | *
23 | */
24 |
25 | /** @file dblog.h
26 | * Public headers for the recovery journal.
27 | */
28 |
29 | #ifndef DEFINED_DBLOG_H
30 | #define DEFINED_DBLOG_H
31 |
32 | #ifndef _WIN32
33 | #define WG_JOURNAL_FILENAME DBLOG_DIR "/wgdb.journal"
34 | #else
35 | #define WG_JOURNAL_FILENAME DBLOG_DIR "\\wgdb_journal"
36 | #endif
37 | #define WG_JOURNAL_FN_BUFSIZE (sizeof(WG_JOURNAL_FILENAME) + 20)
38 | #define WG_JOURNAL_MAX_BACKUPS 10
39 | #define WG_JOURNAL_MAGIC "wgdb"
40 | #define WG_JOURNAL_MAGIC_BYTES 4
41 |
42 | #define WG_JOURNAL_ENTRY_ENC ((unsigned char) 0) /* top bits clear |= type */
43 | #define WG_JOURNAL_ENTRY_CRE ((unsigned char) 0x40)
44 | #define WG_JOURNAL_ENTRY_DEL ((unsigned char) 0x80)
45 | #define WG_JOURNAL_ENTRY_SET ((unsigned char) 0xc0)
46 | #define WG_JOURNAL_ENTRY_META ((unsigned char) 0x20)
47 | #define WG_JOURNAL_ENTRY_CMDMASK (0xe0)
48 | #define WG_JOURNAL_ENTRY_TYPEMASK (0x1f)
49 |
50 |
51 | /* ====== data structures ======== */
52 |
53 | typedef struct {
54 | FILE *f;
55 | int fd;
56 | gint serial;
57 | int umask;
58 | } db_handle_logdata;
59 |
60 | /* ==== Protos ==== */
61 |
62 | gint wg_init_handle_logdata(void *db);
63 | void wg_cleanup_handle_logdata(void *db);
64 | int wg_log_umask(void *db, int cmask);
65 |
66 | void wg_journal_filename(void *db, char *buf, size_t buflen);
67 | gint wg_start_logging(void *db);
68 | gint wg_stop_logging(void *db);
69 | gint wg_replay_log(void *db, char *filename);
70 |
71 | gint wg_log_create_record(void *db, gint length);
72 | gint wg_log_delete_record(void *db, gint enc);
73 | gint wg_log_encval(void *db, gint enc);
74 | gint wg_log_encode(void *db, gint type, const void *data, gint length,
75 | const void *extdata, gint extlength);
76 | gint wg_log_set_field(void *db, void *rec, gint col, gint data);
77 | gint wg_log_set_meta(void *db, void *rec, gint meta);
78 |
79 | #endif /* DEFINED_DBLOG_H */
80 |
--------------------------------------------------------------------------------
/Db/dbmem.h:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Tanel Tammet 2004,2005,2006,2007,2008,2009
6 | *
7 | * Contact: tanel.tammet@gmail.com
8 | *
9 | * This file is part of WhiteDB
10 | *
11 | * WhiteDB is free software: you can redistribute it and/or modify
12 | * it under the terms of the GNU General Public License as published by
13 | * the Free Software Foundation, either version 3 of the License, or
14 | * (at your option) any later version.
15 | *
16 | * WhiteDB is distributed in the hope that it will be useful,
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | * GNU General Public License for more details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with WhiteDB. If not, see
.
23 | *
24 | */
25 |
26 | /** @file dbmem.h
27 | * Public headers for database memory handling.
28 | */
29 |
30 | #ifndef DEFINED_DBMEM_H
31 | #define DEFINED_DBMEM_H
32 |
33 | #ifdef _WIN32
34 | #include "../config-w32.h"
35 | #else
36 | #include "../config.h"
37 | #endif
38 |
39 | #define DEFAULT_MEMDBASE_KEY 1000
40 | //#define DEFAULT_MEMDBASE_SIZE 1000000 // 1 meg
41 | #define DEFAULT_MEMDBASE_SIZE 10000000 // 10 meg
42 | //#define DEFAULT_MEMDBASE_SIZE 800000000 // 800 meg
43 | //#define DEFAULT_MEMDBASE_SIZE 2000000000
44 |
45 | #define MAX_FILENAME_SIZE 100
46 |
47 | /* ====== data structures ======== */
48 |
49 |
50 | /* ==== Protos ==== */
51 |
52 | void* wg_attach_database(const char* dbasename, gint size); // returns a pointer to the database, NULL if failure
53 | void* wg_attach_existing_database(const char* dbasename); // like wg_attach_database, but does not create a new base
54 | void* wg_attach_logged_database(const char* dbasename, gint size); // like wg_attach_database, but activates journal logging on creation
55 | void* wg_attach_database_mode(const char* dbasename, gint size, int mode); // like wg_attach_database, set shared segment permissions to "mode"
56 | void* wg_attach_logged_database_mode(const char* dbasename, gint size, int mode); // like above, activate journal logging
57 |
58 | void* wg_attach_memsegment(const char* dbasename, gint minsize,
59 | gint size, int create, int logging, int mode); // same as wg_attach_database, does not check contents
60 | int wg_detach_database(void* dbase); // detaches a database: returns 0 if OK
61 | int wg_delete_database(const char* dbasename); // deletes a database: returns 0 if OK
62 | int wg_check_header_compat(db_memsegment_header *dbh); // check memory image compatibility
63 | void wg_print_code_version(void); // show libwgdb version info
64 | void wg_print_header_version(db_memsegment_header *dbh, int verbose); // show version info from header
65 |
66 | void* wg_attach_local_database(gint size);
67 | void wg_delete_local_database(void* dbase);
68 |
69 | int wg_memmode(void *db);
70 | int wg_memowner(void *db);
71 | int wg_memgroup(void *db);
72 |
73 | #endif /* DEFINED_DBMEM_H */
74 |
--------------------------------------------------------------------------------
/Db/dbmpool.h:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Tanel Tammet 2004,2005,2006,2007,2008,2009
6 | *
7 | * Contact: tanel.tammet@gmail.com
8 | *
9 | * This file is part of WhiteDB
10 | *
11 | * WhiteDB is free software: you can redistribute it and/or modify
12 | * it under the terms of the GNU General Public License as published by
13 | * the Free Software Foundation, either version 3 of the License, or
14 | * (at your option) any later version.
15 | *
16 | * WhiteDB is distributed in the hope that it will be useful,
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | * GNU General Public License for more details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with WhiteDB. If not, see
.
23 | *
24 | */
25 |
26 | /** @file dbmpool.h
27 | * Public headers for memory pool utilities.
28 | */
29 |
30 | #ifndef DEFINED_DBMPOOL_H
31 | #define DEFINED_DBMPOOL_H
32 |
33 | #ifdef _WIN32
34 | #include "../config-w32.h"
35 | #else
36 | #include "../config.h"
37 | #endif
38 |
39 |
40 | /* ====== data structures ======== */
41 |
42 |
43 | /* ==== Protos ==== */
44 |
45 | void* wg_create_mpool(void* db, int bytes); // call this to init pool with initial size bytes
46 | void* wg_alloc_mpool(void* db, void* mpool, int bytes); // call each time you want to "malloc":
47 | // automatically extends pool if no space left
48 | void wg_free_mpool(void* db, void* mpool); // remove the whole pool
49 |
50 | int wg_ispair(void* db, void* ptr);
51 | void* wg_mkpair(void* db, void* mpool, void* x, void* y);
52 | void* wg_first(void* db, void* ptr);
53 | void* wg_rest(void* db, void *ptr);
54 |
55 | int wg_listtreecount(void* db, void *ptr);
56 |
57 | int wg_isatom(void* db, void* ptr);
58 | void* wg_mkatom(void* db, void* mpool, int type, char* str1, char* str2);
59 | int wg_atomtype(void* db, void* ptr);
60 | char* wg_atomstr1(void* db, void* ptr);
61 | char* wg_atomstr2(void* db, void* ptr);
62 |
63 | void wg_mpool_print(void* db, void* ptr);
64 |
65 |
66 | #endif /* DEFINED_DBMPOOL_H */
67 |
--------------------------------------------------------------------------------
/Db/dbschema.h:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Priit Järv 2013
6 | *
7 | * This file is part of WhiteDB
8 | *
9 | * WhiteDB is free software: you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation, either version 3 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * WhiteDB is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with WhiteDB. If not, see
.
21 | *
22 | */
23 |
24 | /** @file dbschema.h
25 | * Public headers for the strucured data functions.
26 | */
27 |
28 | #ifndef DEFINED_DBSCHEMA_H
29 | #define DEFINED_DBSCHEMA_H
30 |
31 | /* ==== Public macros ==== */
32 |
33 | #define WG_SCHEMA_TRIPLE_SIZE 3
34 | #define WG_SCHEMA_TRIPLE_OFFSET 0
35 | #define WG_SCHEMA_KEY_OFFSET (WG_SCHEMA_TRIPLE_OFFSET + 1)
36 | #define WG_SCHEMA_VALUE_OFFSET (WG_SCHEMA_TRIPLE_OFFSET + 2)
37 |
38 | /* ====== data structures ======== */
39 |
40 |
41 | /* ==== Protos ==== */
42 |
43 | void *wg_create_triple(void *db, gint subj, gint prop, gint ob, gint isparam);
44 | #define wg_create_kvpair(db, key, val, ip) \
45 | wg_create_triple(db, 0, key, val, ip)
46 | void *wg_create_array(void *db, gint size, gint isdocument, gint isparam);
47 | void *wg_create_object(void *db, gint size, gint isdocument, gint isparam);
48 | void *wg_find_document(void *db, void *rec);
49 | gint wg_delete_document(void *db, void *document);
50 |
51 | #endif /* DEFINED_DBSCHEMA_H */
52 |
--------------------------------------------------------------------------------
/Db/dbutil.h:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Priit Järv 2010
6 | *
7 | * This file is part of WhiteDB
8 | *
9 | * WhiteDB is free software: you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation, either version 3 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * WhiteDB is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with WhiteDB. If not, see
.
21 | *
22 | */
23 |
24 | /** @file dbutil.h
25 | * Public headers for miscellaneous functions.
26 | */
27 |
28 | #ifndef DEFINED_DBUTIL_H
29 | #define DEFINED_DBUTIL_H
30 |
31 | #ifdef HAVE_RAPTOR
32 | #include
33 | #endif
34 |
35 | #ifdef _WIN32
36 | #include "../config-w32.h"
37 | #else
38 | #include "../config.h"
39 | #endif
40 |
41 |
42 | /* ====== data structures ======== */
43 |
44 | #ifdef HAVE_RAPTOR
45 | struct wg_triple_handler_params {
46 | void *db;
47 | int pref_fields; /** number of fields preceeding the triple */
48 | int suff_fields; /** number of fields to reserve at the end */
49 | gint (*callback) (void *, void *); /** function called after
50 | *the triple is stored */
51 | raptor_parser *rdf_parser; /** parser object */
52 | int count; /** return status: rows parsed */
53 | int error; /** return status: error level */
54 | };
55 | #endif
56 |
57 | /* ==== Protos ==== */
58 |
59 | /* API functions (copied in dbapi.h) */
60 | void wg_print_db(void *db);
61 | void wg_print_record(void *db, gint* rec);
62 | void wg_snprint_value(void *db, gint enc, char *buf, int buflen);
63 | gint wg_parse_and_encode(void *db, const char *buf);
64 | gint wg_parse_and_encode_param(void *db, const char *buf);
65 | void wg_export_db_csv(void *db, const char *filename);
66 | gint wg_import_db_csv(void *db, const char *filename);
67 |
68 | #ifdef USE_ERROR_CALLBACK
69 | int wg_set_error_callback(void *errcallback);
70 | int wg_unset_error_callback(void *errcallback);
71 |
72 | // for internal use, not part of public api
73 | void error_callback(const gint errnumber, const char* errmessage);
74 | #endif
75 |
76 | #ifdef USE_ERROR_CALLBACK
77 | #define LOG_ERROR(errnumber, errformat, errmessage, ...) \
78 | fprintf(stderr, errformat, errmessage, ##__VA_ARGS__); \
79 | char *buffer = malloc(256); \
80 | if (buffer != NULL) \
81 | { \
82 | int size = snprintf(buffer, 256, errformat, errmessage, ##__VA_ARGS__); \
83 | if (size >= 256) { free(buffer); buffer = malloc(size); snprintf(buffer, size, errformat, errmessage, ##__VA_ARGS__); } \
84 | error_callback(errnumber, buffer); \
85 | free(buffer); \
86 | }
87 | #else
88 | #define LOG_ERROR(errnumber, errformat, errmessage, ...) fprintf(stderr, errformat, errmessage, ##__VA_ARGS__)
89 | #endif
90 |
91 | /* Separate raptor API (copied in rdfapi.h) */
92 | #ifdef HAVE_RAPTOR
93 | gint wg_import_raptor_file(void *db, gint pref_fields, gint suff_fields,
94 | gint (*callback) (void *, void *), char *filename);
95 | gint wg_import_raptor_rdfxml_file(void *db, gint pref_fields, gint suff_fields,
96 | gint (*callback) (void *, void *), char *filename);
97 | gint wg_rdfparse_default_callback(void *db, void *rec);
98 | gint wg_export_raptor_file(void *db, gint pref_fields, char *filename,
99 | char *serializer);
100 | gint wg_export_raptor_rdfxml_file(void *db, gint pref_fields, char *filename);
101 | #endif
102 |
103 | void wg_pretty_print_memsize(gint memsz, char *buf, size_t buflen);
104 |
105 | #endif /* DEFINED_DBUTIL_H */
106 |
--------------------------------------------------------------------------------
/Db/indexapi.h:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Priit Järv 2011
6 | *
7 | * This file is part of WhiteDB
8 | *
9 | * WhiteDB is free software: you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation, either version 3 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * WhiteDB is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with WhiteDB. If not, see .
21 | *
22 | */
23 |
24 | /** @file indexapi.h
25 | *
26 | * Index management API for WhiteDB.
27 | *
28 | * wg_int type is defined in dbapi.h
29 | */
30 |
31 | #ifndef DEFINED_INDEXAPI_H
32 | #define DEFINED_INDEXAPI_H
33 |
34 | #ifdef __cplusplus
35 | extern "C" {
36 | #endif
37 |
38 | /* Public macros */
39 |
40 | #define WG_INDEX_TYPE_TTREE 50
41 | #define WG_INDEX_TYPE_TTREE_JSON 51
42 | #define WG_INDEX_TYPE_HASH 60
43 | #define WG_INDEX_TYPE_HASH_JSON 61
44 |
45 | /* Public protos */
46 |
47 | wg_int wg_create_index(void *db, wg_int column, wg_int type,
48 | wg_int *matchrec, wg_int reclen);
49 | wg_int wg_create_multi_index(void *db, wg_int *columns, wg_int col_count,
50 | wg_int type, wg_int *matchrec, wg_int reclen);
51 | wg_int wg_drop_index(void *db, wg_int index_id);
52 | wg_int wg_column_to_index_id(void *db, wg_int column, wg_int type,
53 | wg_int *matchrec, wg_int reclen);
54 | wg_int wg_multi_column_to_index_id(void *db, wg_int *columns,
55 | wg_int col_count, wg_int type, wg_int *matchrec, wg_int reclen);
56 | wg_int wg_get_index_type(void *db, wg_int index_id);
57 | void * wg_get_index_template(void *db, wg_int index_id, wg_int *reclen);
58 | void * wg_get_all_indexes(void *db, wg_int *count);
59 |
60 | #ifdef __cplusplus
61 | }
62 | #endif
63 |
64 | #endif /* DEFINED_INDEXAPI_H */
65 |
--------------------------------------------------------------------------------
/Db/rdfapi.h:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Priit Järv 2010
6 | *
7 | * This file is part of WhiteDB
8 | *
9 | * WhiteDB is free software: you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation, either version 3 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * WhiteDB is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with WhiteDB. If not, see .
21 | *
22 | */
23 |
24 | /** @file rdfapi.h
25 | *
26 | * RDF parsing API for WhiteDB, depends on libraptor.
27 | *
28 | */
29 |
30 | #ifndef DEFINED_RDFAPI_H
31 | #define DEFINED_RDFAPI_H
32 |
33 | wg_int wg_import_raptor_file(void *db, wg_int pref_fields, wg_int suff_fields,
34 | wg_int (*callback) (void *, void *), char *filename);
35 | wg_int wg_import_raptor_rdfxml_file(void *db, wg_int pref_fields,
36 | wg_int suff_fields, wg_int (*callback) (void *, void *), char *filename);
37 | wg_int wg_rdfparse_default_callback(void *db, void *rec);
38 | wg_int wg_export_raptor_file(void *db, wg_int pref_fields, char *filename,
39 | char *serializer);
40 | wg_int wg_export_raptor_rdfxml_file(void *db, wg_int pref_fields,
41 | char *filename);
42 |
43 | #endif /* DEFINED_RDFAPI_H */
44 |
--------------------------------------------------------------------------------
/Doc/Install2html.sed:
--------------------------------------------------------------------------------
1 | s/^Quick-start instructions/\[\[anchor-1\]\]\n&/
2 | s/"Quick-start instructions"/xref:anchor-1\[\]/
3 | s/^Building the repository version/\[\[anchor-2\]\]\n&/
4 | s/"Building the repository version"/xref:anchor-2\[\]/
5 |
--------------------------------------------------------------------------------
/Doc/Manual2html.sed:
--------------------------------------------------------------------------------
1 | s/'python\.txt'/link:python\.html\[Python API\]/
2 | s/the section "Encoding and decoding data stored in the record fields"/xref:anchor-1\[\]/
3 | s/Encoding and decoding data stored/\[\[anchor-1\]\]\n&/
4 | s/see next chapter/see xref:anchor-1\[\]/
5 | s/^\(Returns datatype in field fieldnr\)/\[\[anchor-2,wg_get_field_type()\]\]\n\1/
6 | s/`wg_get_field_type()`/xref:anchor-2\[\]/
7 | s/^Compiling and linking against WhiteDB installation/\[\[anchor-3\]\]\n&/
8 | s/section "Compiling and linking against WhiteDB installation"/xref:anchor-3\[\]/
9 | s/^Dynamic linking under Windows/\[\[anchor-4\]\]\n&/
10 | s/"Dynamic linking under Windows"/xref:anchor-4\[\]/
11 | s/^Compiling with database source files/\[\[anchor-5\]\]\n&/
12 | s/"Compiling with database source files"/xref:anchor-5\[\]/
13 | s/^Query functions/\[\[anchor-6\]\]\n&/
14 | s/"Query functions"/xref:anchor-6\[\]/
15 |
--------------------------------------------------------------------------------
/Doc/Tutorial2html.sed:
--------------------------------------------------------------------------------
1 | s/^Connecting to the database/\[\[anchor-1\]\]\n&/
2 | s/"Connecting to the database"/xref:anchor-1\[\]/
3 | s/^Looking at data/\[\[anchor-2\]\]\n&/
4 | s/"Looking at data"/xref:anchor-2\[\]/
5 | s/'python\.txt'/link:python\.html\[Python documentation\]/
6 | s/'Manual\.txt' file/link:Manual\.html\[Manual\]/
7 | s/The manual will provide/link:Manual\.html\[The manual\] will provide/
8 | s/"<="/"\\<="/
9 | s/given in 'Manual\.txt'/given in link:Manual\.html\[the manual\]/
10 |
--------------------------------------------------------------------------------
/Doc/python2html.sed:
--------------------------------------------------------------------------------
1 | s/^Compilation and Installation/\[\[anchor-1\]\]\n&/
2 | s/The second part, "Compilation and Installation"/xref:anchor-1\[\]/
3 | s/^wgdb.so (wgdb.pyd) module/\[\[anchor-2\]\]\n&/
4 | s/The third part, "wgdb.so (wgdb.pyd) module"/xref:anchor-2\[\]/
5 | s/^whitedb.py module (high level API)/\[\[anchor-3\]\]\n&/
6 | s/The last part, "whitedb.py module (high level API)"/xref:anchor-3\[\]/
7 | s/^Specifying field encoding and extended information/\[\[anchor-4\]\]\n&/
8 | s/"Specifying field encoding and extended information"/xref:anchor-4\[\]/
9 | s/^`attach_database()` allows/\[\[anchor-5,attach_database()\]\]\n&/
10 | s/^`wgdb.attach_database()`\( for possible\)/xref:anchor-5\[\]\1/
11 | s/^Writing and reading field contents/\[\[anchor-6\]\]\n&/
12 | s/section "Writing and reading field contents"/xref:anchor-6\[\]/
13 | s/^Queries/\[\[anchor-7\]\]\n&/
14 | s/\(see the\) section "Queries"/\1 xref:anchor-7\[\]/
15 |
--------------------------------------------------------------------------------
/Doc/whitedb.7:
--------------------------------------------------------------------------------
1 | .\" Manpage for whitedb.
2 | .\" Contact tane.tammet@gmail.com to correct errors or typos.
3 | .TH man 7 "27 Jan 2014" "0.7" "whitedb man page"
4 | .SH NAME
5 | WhiteDB \- shared memory database library
6 | .SH SYNOPSIS
7 | [see Doc folder and http://whitedb.org for the full manual]
8 | .SH DESCRIPTION
9 | WhiteDB is a lightweight NoSQL database library written in C, operating fully in main memory.
10 | There is no server process. Data is read and written directly from/to shared memory,
11 | no sockets are used between WhiteDB and the application program. All
12 | the data is accessible to separate processes.
13 |
14 | Each database record is a tuple of N elements, encoded in WhiteDB-s simple compact format.
15 | You can store both conventional datatypes and direct pointers to records:
16 | the latter enables highly efficient traversal of complex data.
17 |
18 | Each element is encoded as an integer: configurable as either 32 or 64 bits.
19 | The integers in the tuple encode values directly or as pointers.
20 | Columns have no type: any encoded value can be stored to any field.
21 | You can always get a direct pointer to a record, store it into a field of a record or
22 | use it in your own program directly. A record pointer can thus be used as an automatically
23 | assigned id of the record which requires no search at all to access the record.
24 |
25 | The low bits of an integer in a record indicate the type of data.
26 | Anything which does not fit into the remainining bits is allocated
27 | separately and pointed to by the same integer.
28 |
29 | We use a database level lock implemented via a task-fair
30 | atomic spinlock queue for concurrency control,
31 | but alternative faster and simpler preference policies can be configured:
32 | either a reader-preference or a writer-preference spinlock.
33 | We provide safe atomic updates of simple values without taking a write lock.
34 |
35 | The simplest index provided is a T-tree index on any field
36 | containing any mixture of objects (integers, strings, etc).
37 | The index is automatically maintained when records are added, deleted or changed.
38 |
39 | Two mechanisms are available for storing the shared memory database to disk.
40 | First, the whole database can be dumped and restored.
41 | Second, all inserts, deletions and updates can be logged to a file.
42 |
43 | .SH SEE ALSO
44 | The Whitedb web site can be found at:
45 | http://whitedb.org
46 | .SH REPORTING PROBLEMS
47 | Please use either https://github.com/priitj/whitedb or email to authors.
48 | .SH AUTHORS
49 | Copyright (C) 2008-2014 Tanel Tammet (tanel.tammet@gmail.com), Priit Järv (priit@whitedb.org)
50 |
51 |
52 |
--------------------------------------------------------------------------------
/Examples/Makefile.am:
--------------------------------------------------------------------------------
1 | # $Id: $
2 | # $Source: $
3 | #
4 | # Compile test program(s)
5 |
6 |
7 | # ---- options ----
8 |
9 | # ---- targets ----
10 |
11 | noinst_PROGRAMS = demo query
12 | #if RAPTOR
13 | #noinst_PROGRAMS += raptortry
14 | #endif
15 |
16 | # ---- extra dependencies, flags, etc -----
17 |
18 | LIBDEPS = -lm # dependency from libm round() should be removed
19 | if RAPTOR
20 | LIBDEPS += `$(RAPTOR_CONFIG) --libs`
21 | endif
22 |
23 | #if RAPTOR
24 | #raptortry_CFLAGS = $(AM_CFLAGS) `$(RAPTOR_CONFIG) --cflags`
25 | #endif
26 |
27 | AM_LDFLAGS = $(LIBDEPS)
28 |
29 | # ----- all sources for the created programs -----
30 |
31 | #raptortry_SOURCES = raptortry.c
32 | #raptortry_LDADD = ../Main/libwgdb.la
33 |
34 | demo_SOURCES = demo.c
35 | demo_LDADD = ../Main/libwgdb.la
36 |
37 | query_SOURCES = query.c
38 | query_LDADD = ../Main/libwgdb.la ../Test/libTest.la
39 |
--------------------------------------------------------------------------------
/Examples/compile_demo.bat:
--------------------------------------------------------------------------------
1 | cl /Ox /W3 /I..\Db demo.c ..\Db\dbmem.c ..\Db\dballoc.c ..\Db\dbdata.c ..\Db\dblock.c ..\DB\dbindex.c ..\Db\dblog.c ..\Db\dbhash.c ..\Db\dbcompare.c ..\Db\dbquery.c ..\Db\dbutil.c ..\Db\dbmpool.c ..\Db\dbjson.c ..\Db\dbschema.c ..\json\yajl_all.c
2 |
--------------------------------------------------------------------------------
/Examples/compile_demo.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | [ -z "$CC" ] && CC="cc"
4 |
5 | if [ -z "$(which $CC 2>/dev/null)" ]; then
6 | echo "Error: No compiler found"
7 | exit 1
8 | fi
9 |
10 | # run unite.sh if needed
11 | if [ ! -f ../whitedb.c ]; then
12 | cd ..; ./unite.sh; cd "$OLDPWD"
13 | fi
14 |
15 | # use output of unite.sh
16 | $CC -O2 -I.. -o demo demo.c ../whitedb.c -lm
17 |
18 | #$CC -O2 -o demo demo.c ../Db/dbmem.c ../Db/dballoc.c ../Db/dbdata.c ../Db/dblock.c ../Db/dbindex.c ../Db/dblog.c ../Db/dbhash.c ../Db/dbcompare.c ../Db/dbquery.c ../Db/dbutil.c ../Db/dbmpool.c ../Db/dbjson.c ../Db/dbschema.c ../json/yajl_all.c -lm
19 |
--------------------------------------------------------------------------------
/Examples/compile_query.bat:
--------------------------------------------------------------------------------
1 | cl /Ox /W3 /I..\Db query.c ..\Db\dbmem.c ..\Db\dballoc.c ..\Db\dbdata.c ..\Db\dblock.c ..\DB\dbindex.c ..\Db\dblog.c ..\Db\dbhash.c ..\Db\dbcompare.c ..\Db\dbquery.c ..\Db\dbutil.c ..\Test\dbtest.c ..\Db\dbmpool.c ..\Db\dbjson.c ..\Db\dbschema.c ..\json\yajl_all.c
2 |
--------------------------------------------------------------------------------
/Examples/compile_query.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | [ -z "$CC" ] && CC="cc"
4 |
5 | if [ -z "$(which $CC 2>/dev/null)" ]; then
6 | echo "Error: No compiler found"
7 | exit 1
8 | fi
9 |
10 | # run unite.sh if needed
11 | if [ ! -f ../whitedb.c ]; then
12 | cd ..; ./unite.sh; cd "$OLDPWD"
13 | fi
14 |
15 | # use output of unite.sh
16 | $CC -O2 -I.. -o query query.c ../Test/dbtest.c ../whitedb.c -lm
17 |
18 | #$CC -O2 -o query query.c ../Db/dbmem.c ../Db/dballoc.c ../Db/dbdata.c ../Db/dblock.c ../Db/dbindex.c ../Db/dblog.c ../Db/dbhash.c ../Db/dbcompare.c ../Db/dbquery.c ../Db/dbutil.c ../Test/dbtest.c ../Db/dbmpool.c ../Db/dbjson.c ../Db/dbschema.c ../json/yajl_all.c -lm
19 |
--------------------------------------------------------------------------------
/Examples/speed/README:
--------------------------------------------------------------------------------
1 | Simple single-core speed tests covered in http://whitedb.org/speed.html
2 |
--------------------------------------------------------------------------------
/Examples/speed/speed1.c:
--------------------------------------------------------------------------------
1 | /*
2 | creating and deleting a 1 GB database 1000 times:
3 |
4 | real 0m9.694s
5 | user 0m2.044s
6 | sys 0m7.642s
7 |
8 | creating and deleting a 10 MB database 100000 times:
9 |
10 | real 0m12.800s
11 | user 0m2.622s
12 | sys 0m10.137s
13 |
14 | */
15 |
16 | #include
17 | #include
18 | #include
19 |
20 | int main(int argc, char **argv) {
21 | void *db;
22 | char *name="1";
23 | int i;
24 | for(i=0;i<1000;i++) { // 100000
25 | db = wg_attach_database(name,1000000000); // 10000000
26 | if (!db) { printf("failed at try %d\n", i); exit(0); }
27 | wg_detach_database(db);
28 | wg_delete_database(name);
29 | }
30 | printf("i %d\n", i);
31 | return 0;
32 | }
33 |
--------------------------------------------------------------------------------
/Examples/speed/speed10.c:
--------------------------------------------------------------------------------
1 | /*
2 | creating and immediately filling with integer data
3 | 10 million records of 5 fields in a 1 GIG database.
4 |
5 | Field values are computed as the last five digits
6 | of the record number, thus storing each number
7 | between 0...100000 to 100 different records.
8 |
9 | Database created will be later used by speed11 for
10 | scanning.
11 |
12 | real 0m0.483s
13 | user 0m0.381s
14 | sys 0m0.101s
15 |
16 | */
17 |
18 | #include
19 | #include
20 | #include
21 |
22 | int main(int argc, char **argv) {
23 | void *db, *rec;
24 | char *name="10";
25 | int i,j;
26 | db = wg_attach_database(name, 1000000000);
27 | if (!db) { printf("db creation failed \n"); exit(0); }
28 | for(i=0;i<10000000;i++) {
29 | rec = wg_create_raw_record(db, 5);
30 | if (!rec) { printf("record creation failed \n"); exit(0); }
31 | wg_set_new_field(db,rec,3,wg_encode_int(db,i%100000));
32 | }
33 | printf("i %d\n", i);
34 | return 0;
35 | }
36 |
--------------------------------------------------------------------------------
/Examples/speed/speed11.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Scan through 10 million records in a pre-built database,
4 | counting all these records which have integer 123 as the value of the third field.
5 |
6 | Database was created earlier by speed10. Do not forget to delete database later,
7 | a la: wgdb 10 free
8 |
9 | real 0m0.201s
10 | user 0m0.157s
11 | sys 0m0.044s
12 |
13 | */
14 |
15 | #include
16 | #include
17 | #include
18 |
19 | int main(int argc, char **argv) {
20 | void *db, *rec;
21 | char *name="10";
22 | int i=0;
23 | int count=0;
24 | wg_int encval;
25 | db = wg_attach_database(name, 1000000000);
26 | if (!db) { printf("db attaching failed \n"); exit(0); }
27 | encval=wg_encode_int(db,123); // encode for faster comparison in the loop
28 | rec=wg_get_first_record(db);
29 | do {
30 | //if (wg_decode_int(db,wg_get_field(db,rec,3))==123) count++; // a bit slower alternative
31 | if (wg_get_field(db,rec,3)==encval) count++;
32 | rec=wg_get_next_record(db,rec);
33 | i++;
34 | } while(rec!=NULL);
35 | wg_free_encoded(db,encval); // have to free encval since we did not store it to db
36 | printf("i %d, count %d\n", i,count);
37 | return 0;
38 | }
39 |
--------------------------------------------------------------------------------
/Examples/speed/speed12.c:
--------------------------------------------------------------------------------
1 | /*
2 | create an index for the field 3 in the previously built
3 | database of 10 million records.
4 |
5 | real 0m6.540s
6 | user 0m6.436s
7 | sys 0m0.098s
8 |
9 | */
10 |
11 | #include
12 | #include // must additionally include indexapi.h
13 | #include
14 | #include
15 |
16 | int main(int argc, char **argv) {
17 | void *db, *rec;
18 | char *name="10";
19 | int tmp;
20 | db = wg_attach_database(name, 1000000000);
21 | if (!db) { printf("db creation failed \n"); exit(0); }
22 | tmp=wg_create_index(db,3,WG_INDEX_TYPE_TTREE,NULL,0);
23 | if (tmp) printf("Index creation failed\n");
24 | else printf("Index creation succeeded\n");
25 | return 0;
26 | }
27 |
--------------------------------------------------------------------------------
/Examples/speed/speed13.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Outer loop: run the inner loop million times to obtain sensible timings.
4 |
5 | Inner loop: prepare query and search from the index on 10 million records, counting all these which have
6 | integer 123 as the value of the third field, using query on the indexed field. There are 100 of
7 | such values.
8 |
9 | Database was created earlier by speed11 and indexed by speed 12.
10 | Do not forget to delete database later, a la: wgdb 10 free
11 |
12 | Outer loop time (i.e. 1 million identical query building / performing / deallocating operations) altogether:
13 |
14 | real 0m3.256s
15 | user 0m3.252s
16 | sys 0m0.001s
17 |
18 | */
19 |
20 |
21 | #include
22 | #include
23 | #include
24 |
25 | int main(int argc, char **argv) {
26 | void *db, *rec;
27 | char *name="10";
28 | int i;
29 | int count=0;
30 | wg_query *query;
31 | wg_query_arg arglist[5];
32 |
33 | db = wg_attach_database(name, 1000000000);
34 | if (!db) { printf("db attaching failed \n"); exit(0); }
35 | // outer loop is just for sensible timing: do the same thing 1000 times
36 | for(i=0;i<1000000;i++) {
37 | arglist[0].column = 3;
38 | arglist[0].cond = WG_COND_EQUAL;
39 | arglist[0].value = wg_encode_query_param_int(db,123);
40 | query = wg_make_query(db, NULL, 0, arglist, 1);
41 | if(!query) { printf("query creation failed \n"); exit(0); }
42 | while((rec = wg_fetch(db, query))) {
43 | count++;
44 | //wg_print_record(db, rec); printf("\n");
45 | }
46 | wg_free_query(db,query);
47 | }
48 | printf("count altogether for i %d runs: %d\n", i, count);
49 | return 0;
50 | }
51 |
--------------------------------------------------------------------------------
/Examples/speed/speed15.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | creating a flat pointer list of 10 million records of 5 fields in
4 | a 1 GB database:
5 | store a pointer to the previous record to field 3 of each record,
6 | store a pointer to the last record to field 2 of first record.
7 |
8 | Observe that we use standard C int 0 for the NULL pointer,
9 | this is also what wg_encode_null(db,0) always gives.
10 |
11 | real 0m0.666s
12 | user 0m0.516s
13 | sys 0m0.150s
14 |
15 | */
16 |
17 | #include
18 | #include
19 | #include
20 |
21 | int main(int argc, char **argv) {
22 | void *db, *rec, *firstrec, *lastrec;
23 | char *name="15";
24 | int i;
25 | db = wg_attach_database(name, 1000000000);
26 | if (!db) { printf("db creation failed \n"); exit(0); }
27 | rec = wg_create_raw_record(db, 5);
28 | firstrec=rec; // store for use in the end
29 | lastrec=rec;
30 | for(i=1;i<10000000;i++) {
31 | rec = wg_create_raw_record(db, 5);
32 | if (!rec) { printf("record creation failed \n"); exit(0); }
33 | // store a pointer to the previously built record
34 | wg_set_new_field(db,rec,3,wg_encode_record(db,lastrec));
35 | lastrec=rec;
36 | }
37 | // field 3 of the first record will be an encoded NULL pointer
38 | // which is always just (wg_int)0
39 | wg_set_new_field(db,firstrec,3,wg_encode_null(db,0));
40 | // field 2 of the first record will be a pointer to the last record
41 | wg_set_new_field(db,firstrec,2,wg_encode_record(db,lastrec));
42 | printf("i %d\n", i);
43 | wg_detach_database(db);
44 | return 0;
45 | }
46 |
--------------------------------------------------------------------------------
/Examples/speed/speed16.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | traversing a flat pre-built (in speed15.c) pointer list of 10 million records
4 | of 5 fields in a 1 GB database:
5 | a pointer to the previous record is stored in field 3 of each record,
6 | a pointer to the last record is stored in field 2 of first record.
7 |
8 | Observe that we use standard C int 0 for the NULL pointer,
9 | this is also what wg_encode_null(db,0) always gives.
10 |
11 | Database was created earlier by speed15.
12 | Do not forget to delete database later, a la: wgdb 15 free
13 |
14 | real 0m0.153s
15 | user 0m0.110s
16 | sys 0m0.043s
17 |
18 | */
19 |
20 | #include
21 | #include
22 | #include
23 |
24 | int main(int argc, char **argv) {
25 | void *db, *rec;
26 | char *name="15";
27 | int i;
28 | wg_int encptr;
29 | db = wg_attach_database(name, 1000000000);
30 | if (!db) { printf("db creation failed \n"); exit(0); }
31 | rec=wg_get_first_record(db);
32 | // get a pointer to the last record
33 | rec=wg_decode_record(db,wg_get_field(db,rec,2));
34 | i=1;
35 | while(1) {
36 | encptr=wg_get_field(db,rec,3); // encptr is not yet decoded
37 | if (encptr==(wg_int)0) break; // encoded null is always standard 0
38 | rec=wg_decode_record(db,encptr); // get a pointer to the previous record
39 | i++;
40 | }
41 | printf("i %d\n", i);
42 | wg_detach_database(db);
43 | return 0;
44 | }
--------------------------------------------------------------------------------
/Examples/speed/speed2.c:
--------------------------------------------------------------------------------
1 | /*
2 | creating 10 million records of 5 fields in a 1 GB database
3 |
4 | real 0m0.586s
5 | user 0m0.473s
6 | sys 0m0.113s
7 |
8 | creating 10 million records of 9 fields in a 1 GB database
9 |
10 | real 0m0.812s
11 | user 0m0.645s
12 | sys 0m0.166s
13 |
14 |
15 | */
16 |
17 | #include
18 | #include
19 | #include
20 |
21 | int main(int argc, char **argv) {
22 | void *db, *rec;
23 | char *name="2";
24 | int i;
25 | db = wg_attach_database(name, 1000000000);
26 | if (!db) { printf("db creation failed \n"); exit(0); }
27 | for(i=0;i<10000000;i++) {
28 | rec = wg_create_record(db, 9);
29 | if (!rec) { printf("record creation failed \n"); exit(0); }
30 | }
31 | printf("i %d\n", i);
32 | wg_detach_database(db);
33 | wg_delete_database(name);
34 | return 0;
35 | }
36 |
--------------------------------------------------------------------------------
/Examples/speed/speed20.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | call with
4 | speed20 N
5 | where N is the number of segments (N >= 1), default 1
6 |
7 | compile with
8 | gcc speed21.c -o speed21 -O2 -lwgdb -lpthread
9 |
10 | creating a flat pointer list of 10 million records of 5 fields in
11 | a 1 GB database:
12 | store a pointer to the previous record to field 3 of each record,
13 | thus first list elems are actually created last.
14 |
15 | Store lstlen-i to field 1.
16 |
17 | Additionally create a ctrl record with pointers to the middle of the list,
18 | to be used for parallel multicore scanning of the list later.
19 | Ctrl record fields:
20 | 0: type (unused)
21 | 1: ptr field (3 here)
22 | 2: start pointer
23 | 3: midpointer0
24 | 4: midpointer1
25 | ...
26 | N: ptr to last record
27 | N+1: NULL
28 |
29 | Observe that we use standard C int 0 for the NULL pointer,
30 | this is also what wg_encode_null(db,0) always gives.
31 |
32 | */
33 |
34 | #include
35 | #include
36 | #include
37 |
38 | #define DB_NAME "20"
39 |
40 | int main(int argc, char **argv) {
41 | void *db, *rec, *ctrlrec, *firstrec, *lastrec;
42 | char *name=DB_NAME;
43 | int i;
44 | int lstlen=10000000; // total nr of elems in list
45 | int ptrfld=3; // field where a pointer is stored
46 | int segnr=1; // total number of segments
47 | int midcount=0; // middle ptr count
48 | int midlasti=0; // last i where midpoint stored
49 | int midseglen; // mid segment length
50 | wg_int tmp;
51 |
52 | if (argc>=2) {
53 | segnr=atoi(argv[1]);
54 | }
55 | printf("creating a list with %d segments \n",segnr);
56 | midseglen=lstlen/segnr; // mid segment length
57 |
58 | db = wg_attach_database(name, 1000000000);
59 | if (!db) { printf("db creation failed \n"); exit(0); }
60 | ctrlrec = wg_create_record(db, 1000); // this will contain info about the list
61 | // build the list
62 | firstrec=wg_create_raw_record(db, 5);
63 | lastrec=firstrec;
64 | // next ptr from the last record is an encoded NULL pointer
65 | wg_set_new_field(db,firstrec,ptrfld,wg_encode_null(db,0));
66 | wg_set_new_field(db,firstrec,1,wg_encode_int(db,lstlen));
67 | for(i=1;i=midseglen) {
79 | // this lst is built from end to beginning
80 | wg_set_field(db,ctrlrec,2+(segnr-1)-midcount,wg_encode_record(db,rec));
81 | printf("\nmidpoint %d at i %d to field %d val %d",midcount,i,2+(segnr-1)-midcount,
82 | (int)(db,wg_get_field(db,ctrlrec,2+(segnr-1)-midcount)));
83 | midlasti=i;
84 | midcount++;
85 | }
86 | }
87 | // set ctrlrec fields: type,ptr field,first pointer,midpointer1,midpointer2,...
88 | wg_set_field(db,ctrlrec,0,wg_encode_int(db,1)); // type not used
89 | wg_set_field(db,ctrlrec,1,wg_encode_int(db,ptrfld)); // ptrs at field 3
90 | wg_set_field(db,ctrlrec,2,wg_encode_record(db,lastrec)); // lst starts here
91 | wg_set_field(db,ctrlrec,2+segnr,wg_encode_record(db,firstrec)); // last record in a list
92 | printf("\nfinal i %d\n", i);
93 | printf("\nctrl rec ptr fld val %d \n",wg_decode_int(db,wg_get_field(db,ctrlrec,1)));
94 | for(i=0;i<1000;i++) {
95 | tmp=wg_get_field(db,ctrlrec,2+i);
96 | if (!(int)tmp) break;
97 | printf("ptr %d value %d content %d\n",i,(int)tmp,
98 | wg_decode_int(db,wg_get_field(db,wg_decode_record(db,tmp),1)) );
99 | }
100 | wg_detach_database(db);
101 | return 0;
102 | }
103 |
--------------------------------------------------------------------------------
/Examples/speed/speed3.c:
--------------------------------------------------------------------------------
1 | /*
2 | creating 10 million raw records of 5 fields in a 1 GB database
3 |
4 | real 0m0.349s
5 | user 0m0.217s
6 | sys 0m0.131s
7 |
8 | */
9 |
10 | #include
11 | #include
12 | #include
13 |
14 | int main(int argc, char **argv) {
15 | void *db, *rec;
16 | char *name="3";
17 | int i;
18 | db = wg_attach_database(name, 1000000000);
19 | if (!db) { printf("db creation failed \n"); exit(0); }
20 | for(i=0;i<10000000;i++) {
21 | rec = wg_create_raw_record(db, 5);
22 | if (!rec) { printf("record creation failed \n"); exit(0); }
23 | }
24 | printf("i %d\n", i);
25 | wg_detach_database(db);
26 | wg_delete_database(name);
27 | return 0;
28 | }
29 |
--------------------------------------------------------------------------------
/Examples/speed/speed4.c:
--------------------------------------------------------------------------------
1 | /*
2 | creating and immediately deleting 10 million records of 5 fields in a 1 GIG database
3 |
4 | real 0m1.160s
5 | user 0m1.149s
6 | sys 0m0.009s
7 |
8 | */
9 |
10 | #include
11 | #include
12 | #include
13 |
14 | int main(int argc, char **argv) {
15 | void *db, *rec;
16 | char *name="4";
17 | int i;
18 | db = wg_attach_database(name, 1000000000);
19 | if (!db) { printf("db creation failed \n"); exit(0); }
20 | for(i=0;i<10000000;i++) {
21 | rec = wg_create_record(db, 5);
22 | if (!rec) { printf("record creation failed \n"); exit(0); }
23 | wg_delete_record(db, rec);
24 | }
25 | printf("i %d\n", i);
26 | wg_detach_database(db);
27 | wg_delete_database(name);
28 | return 0;
29 | }
30 |
--------------------------------------------------------------------------------
/Examples/speed/speed5.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | creating and immediately filling with data 10 million
4 | records of 5 fields in a 1 GIG database
5 |
6 | real 0m1.163s
7 | user 0m1.042s
8 | sys 0m0.120s
9 |
10 | adding code to read back the value and add it to a counter:
11 |
12 | real 0m1.768s
13 | user 0m1.643s
14 | sys 0m0.124s
15 |
16 | doing record filling with 1000 records of length 50 thousand:
17 |
18 | real 0m0.941s
19 | user 0m0.863s
20 | sys 0m0.077s
21 |
22 | */
23 |
24 | #include
25 | #include
26 | #include
27 |
28 | int main(int argc, char **argv) {
29 | void *db, *rec;
30 | char *name="51";
31 | int i,j,count=0;
32 | db = wg_attach_database(name, 1000000000);
33 | if (!db) { printf("db creation failed \n"); exit(0); }
34 | for(i=0;i<10000000;i++) {
35 | rec = wg_create_raw_record(db, 5);
36 | if (!rec) { printf("record creation failed \n"); exit(0); }
37 | for (j=0;j<5;j++) {
38 | wg_set_new_field(db,rec,j,wg_encode_int(db,i+j));
39 | //count+=wg_decode_int(db,wg_get_field(db, rec, j));
40 | }
41 | }
42 | printf("i %d count %d\n", i,count);
43 | wg_detach_database(db);
44 | wg_delete_database(name);
45 | return 0;
46 | }
47 |
--------------------------------------------------------------------------------
/Examples/speed/speed6.c:
--------------------------------------------------------------------------------
1 | /*
2 | creating and immediately filling with string data
3 | 1 million records of 5 fields in a 1 GIG database:
4 | the string is 30 bytes long and is encoded each time
5 | using up 32 bytes
6 |
7 | real 0m0.403s
8 | user 0m0.283s
9 | sys 0m0.119s
10 |
11 | */
12 |
13 | #include
14 | #include
15 | #include
16 |
17 | int main(int argc, char **argv) {
18 | void *db, *rec;
19 | char *name="69";
20 | int i,j;
21 | char* content="01234567890";
22 | db = wg_attach_database(name, 1000000000);
23 | if (!db) { printf("db creation failed \n"); exit(0); }
24 | for(i=0;i<1000000;i++) {
25 | rec = wg_create_raw_record(db, 5);
26 | if (!rec) { printf("record creation failed \n"); exit(0); }
27 | for (j=0;j<5;j++) {
28 | wg_set_new_field(db,rec,j,wg_encode_str(db,content,NULL));
29 | }
30 | }
31 | printf("i %d \n", i);
32 | wg_detach_database(db);
33 | wg_delete_database(name);
34 | return 0;
35 | }
36 |
--------------------------------------------------------------------------------
/Examples/speed/speed7.c:
--------------------------------------------------------------------------------
1 | /*
2 | creating and immediately filling with string data
3 | 1 million records of 5 fields in a 1 GIG database:
4 | the string is 100 bytes long and is encoded each time.
5 |
6 | real 0m1.464s
7 | user 0m1.446s
8 | sys 0m0.017s
9 |
10 | */
11 |
12 | #include
13 | #include
14 | #include
15 |
16 | int main(int argc, char **argv) {
17 | void *db, *rec;
18 | char *name="7";
19 | int i,j;
20 | char* content="0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789";
21 | db = wg_attach_database(name, 1000000000);
22 | if (!db) { printf("db creation failed \n"); exit(0); }
23 | for(i=0;i<1000000;i++) {
24 | rec = wg_create_raw_record(db, 5);
25 | if (!rec) { printf("record creation failed \n"); exit(0); }
26 | for (j=0;j<5;j++) {
27 | wg_set_new_field(db,rec,j,wg_encode_str(db,content,NULL));
28 | }
29 | }
30 | printf("i %d \n", i);
31 | wg_detach_database(db);
32 | wg_delete_database(name);
33 | return 0;
34 | }
35 |
--------------------------------------------------------------------------------
/Examples/speed/speed8.c:
--------------------------------------------------------------------------------
1 | /*
2 | creating and immediately filling with double data
3 | 1 million records of 5 fields in a 1 GIG database.
4 | The double value is encoded each time.
5 |
6 | real 0m0.190s
7 | user 0m0.144s
8 | sys 0m0.045s
9 |
10 | */
11 |
12 | #include
13 | #include
14 | #include
15 |
16 | int main(int argc, char **argv) {
17 | void *db, *rec;
18 | char *name="9";
19 | int i,j;
20 | db = wg_attach_database(name, 1000000000);
21 | if (!db) { printf("db creation failed \n"); exit(0); }
22 | for(i=0;i<1000000;i++) {
23 | rec = wg_create_raw_record(db, 5);
24 | if (!rec) { printf("record creation failed \n"); exit(0); }
25 | for (j=0;j<5;j++) {
26 | wg_set_new_field(db,rec,j,wg_encode_double(db,(double)(i+j)));
27 | }
28 | }
29 | printf("i %d \n", i);
30 | wg_detach_database(db);
31 | wg_delete_database(name);
32 | return 0;
33 | }
34 |
--------------------------------------------------------------------------------
/Examples/tut1.c:
--------------------------------------------------------------------------------
1 | #include /* or #include on Windows */
2 |
3 | int main(int argc, char **argv) {
4 | void *db;
5 | db = wg_attach_database("1000", 2000000);
6 | return 0;
7 | }
8 |
9 |
--------------------------------------------------------------------------------
/Examples/tut2.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(int argc, char **argv) {
4 | void *db, *rec, *rec2;
5 | wg_int enc, enc2;
6 |
7 | db = wg_attach_database("1000", 2000000);
8 | rec = wg_create_record(db, 10);
9 | rec2 = wg_create_record(db, 2);
10 |
11 | enc = wg_encode_int(db, 443);
12 | enc2 = wg_encode_str(db, "this is my string", NULL);
13 |
14 | wg_set_field(db, rec, 7, enc);
15 | wg_set_field(db, rec2, 0, enc2);
16 |
17 | return 0;
18 | }
19 |
20 |
--------------------------------------------------------------------------------
/Examples/tut3.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int main(int argc, char **argv) {
5 | void *db, *rec;
6 | wg_int enc;
7 |
8 | db = wg_attach_database("1000", 2000000);
9 |
10 | /* create some records for testing */
11 | rec = wg_create_record(db, 10);
12 | enc = wg_encode_int(db, 443); /* will match */
13 | wg_set_field(db, rec, 7, enc);
14 |
15 | rec = wg_create_record(db, 10);
16 | enc = wg_encode_int(db, 442);
17 | wg_set_field(db, rec, 7, enc); /* will not match */
18 |
19 | /* now find the records that match our condition
20 | * "field 7 equals 443"
21 | */
22 | rec = wg_find_record_int(db, 7, WG_COND_EQUAL, 443, NULL);
23 | while(rec) {
24 | printf("Found a record where field 7 is 443\n");
25 | rec = wg_find_record_int(db, 7, WG_COND_EQUAL, 443, rec);
26 | }
27 |
28 | return 0;
29 | }
30 |
31 |
--------------------------------------------------------------------------------
/Examples/tut4.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int main(int argc, char **argv) {
5 | void *db, *rec;
6 | wg_int enc;
7 | wg_query_arg arglist[2]; /* holds the arguments to the query */
8 | wg_query *query; /* used to fetch the query results */
9 |
10 | db = wg_attach_database("1000", 2000000);
11 |
12 | /* just in case, create some records for testing */
13 | rec = wg_create_record(db, 10);
14 | enc = wg_encode_int(db, 443); /* will match */
15 | wg_set_field(db, rec, 7, enc);
16 |
17 | rec = wg_create_record(db, 10);
18 | enc = wg_encode_int(db, 442);
19 | wg_set_field(db, rec, 7, enc); /* will not match */
20 |
21 | /* now find the records that match the condition
22 | * "field 7 equals 443 and field 6 equals NULL". The
23 | * second part is a bit redundant but we're adding it
24 | * to show the use of the argument list.
25 | */
26 | arglist[0].column = 7;
27 | arglist[0].cond = WG_COND_EQUAL;
28 | arglist[0].value = wg_encode_query_param_int(db, 443);
29 |
30 | arglist[1].column = 6;
31 | arglist[1].cond = WG_COND_EQUAL;
32 | arglist[1].value = wg_encode_query_param_null(db, NULL);
33 |
34 | query = wg_make_query(db, NULL, 0, arglist, 2);
35 |
36 | while((rec = wg_fetch(db, query))) {
37 | printf("Found a record where field 7 is 443 and field 6 is NULL\n");
38 | }
39 |
40 | /* Free the memory allocated for the query */
41 | wg_free_query(db, query);
42 | wg_free_query_param(db, arglist[0].value);
43 | wg_free_query_param(db, arglist[1].value);
44 | return 0;
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/Examples/tut5.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | int main(int argc, char **argv) {
6 | void *db, *rec, *lastrec;
7 | wg_int enc;
8 | int i;
9 |
10 | db = wg_attach_database("1000", 1000000); /* 1MB should fill up fast */
11 | if(!db) {
12 | printf("ERR: Could not attach to database.\n");
13 | exit(1);
14 | }
15 |
16 | lastrec = NULL;
17 | for(i=0;;i++) {
18 | char buf[20];
19 | rec = wg_create_record(db, 1);
20 | if(!rec) {
21 | printf("ERR: Failed to create a record (made %d so far)\n", i);
22 | break;
23 | }
24 | lastrec = rec;
25 | sprintf(buf, "%d", i); /* better to use snprintf() in real applications */
26 | enc = wg_encode_str(db, buf, NULL);
27 | if(enc == WG_ILLEGAL) {
28 | printf("ERR: Failed to encode a string (%d records currently)\n", i+1);
29 | break;
30 | }
31 | if(wg_set_field(db, rec, 0, enc)) {
32 | printf("ERR: This error is less likely, but wg_set_field() failed.\n");
33 | break;
34 | }
35 | }
36 |
37 | /* For educational purposes, let's pretend we're interested in what's
38 | * stored in the last record.
39 | */
40 | if(lastrec) {
41 | char *str = wg_decode_str(db, wg_get_field(db, lastrec, 0));
42 | if(!str) {
43 | printf("ERR: Decoding the string field failed.\n");
44 | if(wg_get_field_type(db, lastrec, 0) != WG_STRTYPE) {
45 | printf("ERR: The field type is not string - "
46 | "should have checked that first!\n");
47 | }
48 | }
49 | }
50 |
51 | wg_detach_database(db);
52 | return 0;
53 | }
54 |
--------------------------------------------------------------------------------
/Examples/tut6.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #define NUM_INCREMENTS 100000
6 |
7 | void die(void *db, int err) {
8 | wg_detach_database(db);
9 | exit(err);
10 | }
11 |
12 | int main(int argc, char **argv) {
13 | void *db, *rec;
14 | wg_int lock_id;
15 | int i, val;
16 |
17 | if(!(db = wg_attach_database("1000", 1000000))) {
18 | exit(1); /* failed to attach */
19 | }
20 |
21 | /* First we need to make sure both counting programs start at the
22 | * same time (otherwise the example would be boring).
23 | */
24 | lock_id = wg_start_read(db);
25 | rec = wg_get_first_record(db); /* our database only contains one record,
26 | * so we don't need to make a query.
27 | */
28 | wg_end_read(db, lock_id);
29 |
30 | if(!rec) {
31 | /* There is no record yet, we're the first to run and have
32 | * to set up the counter.
33 | */
34 | lock_id = wg_start_write(db);
35 | if(!lock_id) die(db, 2);
36 | rec = wg_create_record(db, 1);
37 | wg_end_write(db, lock_id);
38 |
39 | if(!rec) die(db, 3);
40 | printf("Press a key when all the counter programs have been started.");
41 | fgetc(stdin);
42 |
43 | /* Setting the counter to 0 lets each counting program know it can
44 | * start counting now.
45 | */
46 | lock_id = wg_start_write(db);
47 | if(!lock_id) die(db, 2);
48 | wg_set_field(db, rec, 0, wg_encode_int(db, 0));
49 | wg_end_write(db, lock_id);
50 | } else {
51 | /* Some other program has started first, we wait until the counter
52 | * is ready.
53 | */
54 | int ready = 0;
55 |
56 | while(!ready) {
57 | lock_id = wg_start_read(db);
58 | if(!lock_id) die(db, 2);
59 | if(wg_get_field_type(db, rec, 0) == WG_INTTYPE)
60 | ready = 1;
61 | wg_end_read(db, lock_id);
62 | }
63 | }
64 |
65 | /* Now start the actual counting. */
66 | for(i=0; i
2 | #include
3 |
4 | int main(int argc, char **argv) {
5 | void *db, *rec, *rec2, *rec3;
6 | wg_int enc;
7 |
8 | if(!(db = wg_attach_database("1000", 2000000)))
9 | exit(1); /* failed to attach */
10 |
11 | rec = wg_create_record(db, 2); /* this is some record */
12 | rec2 = wg_create_record(db, 3); /* this is another record */
13 | rec3 = wg_create_record(db, 4); /* this is a third record */
14 |
15 | if(!rec || !rec2 || !rec3)
16 | exit(2);
17 |
18 | /* Add some content */
19 | wg_set_field(db, rec, 1, wg_encode_str(db, "hello", NULL));
20 | wg_set_field(db, rec2, 0, wg_encode_str(db,
21 | "I'm pointing to other records", NULL));
22 | wg_set_field(db, rec3, 0, wg_encode_str(db,
23 | "I'm linked from two records", NULL));
24 |
25 | /* link the records to each other */
26 | enc = wg_encode_record(db, rec);
27 | wg_set_field(db, rec2, 2, enc); /* rec2[2] points to rec */
28 | enc = wg_encode_record(db, rec3);
29 | wg_set_field(db, rec2, 1, enc); /* rec2[1] points to rec3 */
30 | wg_set_field(db, rec, 0, enc); /* rec[0] points to rec3 */
31 |
32 | wg_detach_database(db);
33 | return 0;
34 | }
35 |
36 |
--------------------------------------------------------------------------------
/INSTALL:
--------------------------------------------------------------------------------
1 | See Doc/Install.txt for installation instructions.
2 |
--------------------------------------------------------------------------------
/MANIFEST:
--------------------------------------------------------------------------------
1 | MANIFEST
2 | ========
3 |
4 | This is the top folder of the WhiteDB system.
5 |
6 | FOLDERS
7 | -------
8 |
9 | Main components:
10 |
11 | Doc : plain text documentation
12 | Main : top level source, main compiled binaries
13 | Db : WhiteDB core source; start here
14 | json : json handling
15 | Python : Python bindings
16 | java : java bindings
17 |
18 |
19 | Under development:
20 |
21 | Reasoner : reasoner core
22 | Parser : parsers for various input languages: used by reasoner
23 | Printer : printing and other output functions: used by reasoner
24 | Rexamples: reasoner examples
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/Main/Makefile.am:
--------------------------------------------------------------------------------
1 | # $Id: $
2 | # $Source: $
3 | #
4 | # Creating the WhiteDB binaries
5 |
6 |
7 | # ---- options ----
8 |
9 | # ---- path variables ----
10 |
11 | dbdir=../Db
12 | printerdir=../Printer
13 | parserdir=../Parser
14 | reasonerdir=../Reasoner
15 | jsondir=../json
16 | testdir=../Test
17 |
18 | # ---- targets ----
19 |
20 | lib_LTLIBRARIES = libwgdb.la
21 | bin_PROGRAMS = wgdb
22 | noinst_PROGRAMS = stresstest selftest gendata indextool
23 | pkginclude_HEADERS = $(dbdir)/dbapi.h $(dbdir)/rdfapi.h $(dbdir)/indexapi.h
24 |
25 | # ---- extra dependencies, flags, etc -----
26 |
27 | LIBDEPS =
28 | if RAPTOR
29 | LIBDEPS += `$(RAPTOR_CONFIG) --libs`
30 | endif
31 |
32 | AM_LDFLAGS = $(LIBDEPS)
33 |
34 | stresstest_LIBS=$(PTHREAD_LIBS)
35 | stresstest_CFLAGS=$(AM_CFLAGS) $(PTHREAD_CFLAGS)
36 | stresstest_LDFLAGS= -static $(PTHREAD_CFLAGS) $(LIBDEPS)
37 | stresstest_CC=$(PTHREAD_CC)
38 |
39 | libwgdb_la_LDFLAGS =
40 |
41 | # ----- all sources for the created programs -----
42 |
43 | libwgdb_la_SOURCES =
44 | libwgdb_la_LIBADD = $(dbdir)/libDb.la ${jsondir}/libjson.la
45 | if REASONER
46 | libwgdb_la_LIBADD += $(parserdir)/libParser.la \
47 | $(printerdir)/libPrinter.la $(reasonerdir)/libReasoner.la
48 | endif
49 |
50 | wgdb_SOURCES = wgdb.c
51 | wgdb_LDADD = libwgdb.la
52 |
53 | stresstest_SOURCES = stresstest.c
54 | stresstest_LDADD = libwgdb.la
55 |
56 | indextool_SOURCES = indextool.c
57 | indextool_LDADD = libwgdb.la
58 |
59 | selftest_SOURCES = selftest.c
60 | selftest_LDADD = $(testdir)/libTest.la libwgdb.la
61 |
62 | gendata_SOURCES = gendata.c
63 | gendata_LDADD = $(testdir)/libTest.la libwgdb.la
64 |
--------------------------------------------------------------------------------
/Main/gendata.c:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Priit Järv 2014
6 | *
7 | * This file is part of WhiteDB
8 | *
9 | * WhiteDB is free software: you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation, either version 3 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * WhiteDB is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with WhiteDB. If not, see .
21 | *
22 | */
23 |
24 | /** @file gendata.c
25 | * WhiteDB test tool: generate integer data
26 | */
27 |
28 | /* ====== Includes =============== */
29 |
30 |
31 |
32 | #include
33 | #include
34 | #include
35 |
36 | #ifdef __cplusplus
37 | extern "C" {
38 | #endif
39 |
40 | #ifdef _WIN32
41 | #include "../config-w32.h"
42 | #else
43 | #include "../config.h"
44 | #endif
45 | #include "../Db/dballoc.h"
46 | #include "../Db/dbmem.h"
47 | #include "../Db/dblock.h"
48 | #include "../Test/dbtest.h"
49 |
50 |
51 | /* ====== Private defs =========== */
52 |
53 | #define TESTREC_SIZE 3
54 |
55 |
56 | /* Helper macros for database lock management */
57 |
58 | #define WLOCK(d,i) i = wg_start_write(d); \
59 | if(!i) { \
60 | fprintf(stderr, "Failed to get database lock\n"); \
61 | break; \
62 | }
63 |
64 | #define WULOCK(d,i) if(i) { \
65 | wg_end_write(d,i); \
66 | i = 0; \
67 | }
68 |
69 | /* ======= Private protos ================ */
70 |
71 | /* ====== Functions ============== */
72 |
73 |
74 | /** usage: display command line help.
75 | *
76 | */
77 |
78 | void usage(char *prog) {
79 | printf("usage: %s [shmname] [command arguments]\n"\
80 | "Where:\n"\
81 | " shmname - (numeric) shared memory name for database. May be omitted.\n"\
82 | " command - required, one of:\n\n"\
83 | " help (or \"-h\") - display this text.\n"\
84 | " fill [asc | desc | mix] - fill db with integer data.\n",
85 | prog);
86 | }
87 |
88 | /** Command line parser.
89 | *
90 | *
91 | */
92 |
93 | int main(int argc, char **argv) {
94 |
95 | char *shmname = NULL;
96 | void *shmptr = NULL;
97 | int i, scan_to;
98 | gint shmsize;
99 | gint wlock = 0;
100 |
101 | /* look for commands in argv[1] or argv[2] */
102 | if(argc < 3) scan_to = argc;
103 | else scan_to = 3;
104 | shmsize = 0;
105 |
106 | /* loop passes are handled like in wgdb.c:
107 | * if the first loop doesn't find a command, the
108 | * argument is assumed to be the shared memory key.
109 | */
110 | for(i=1; i(i+1) && !strcmp(argv[i], "fill")) {
116 | int rows = atol(argv[i+1]);
117 | if(!rows) {
118 | fprintf(stderr, "Invalid number of rows.\n");
119 | exit(1);
120 | }
121 |
122 | shmptr=wg_attach_database(shmname, shmsize);
123 | if(!shmptr) {
124 | fprintf(stderr, "Failed to attach to database.\n");
125 | exit(1);
126 | }
127 |
128 | WLOCK(shmptr, wlock);
129 | if(argc > (i+2) && !strcmp(argv[i+2], "mix"))
130 | wg_genintdata_mix(shmptr, rows, TESTREC_SIZE);
131 | else if(argc > (i+2) && !strcmp(argv[i+2], "desc"))
132 | wg_genintdata_desc(shmptr, rows, TESTREC_SIZE);
133 | else
134 | wg_genintdata_asc(shmptr, rows, TESTREC_SIZE);
135 | WULOCK(shmptr, wlock);
136 | printf("Data inserted\n");
137 | break;
138 | }
139 |
140 | shmname = argv[1];
141 | }
142 |
143 | if(i==scan_to) {
144 | usage(argv[0]);
145 | }
146 | if(shmptr) {
147 | WULOCK(shmptr, wlock);
148 | wg_detach_database(shmptr);
149 | }
150 | exit(0);
151 | }
152 |
153 |
154 | #ifdef __cplusplus
155 | }
156 | #endif
157 |
--------------------------------------------------------------------------------
/Main/selftest.c:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Priit Järv 2014
6 | *
7 | * This file is part of WhiteDB
8 | *
9 | * WhiteDB is free software: you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation, either version 3 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * WhiteDB is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with WhiteDB. If not, see .
21 | *
22 | */
23 |
24 | /** @file selftest.c
25 | * WhiteDB regression test utility
26 | */
27 |
28 | /* ====== Includes =============== */
29 |
30 |
31 |
32 | #include
33 | #include
34 | #include
35 |
36 | #ifdef __cplusplus
37 | extern "C" {
38 | #endif
39 |
40 | #ifdef _WIN32
41 | #include "../config-w32.h"
42 | #else
43 | #include "../config.h"
44 | #endif
45 | #include "../Db/dballoc.h"
46 | #include "../Test/dbtest.h"
47 | #ifdef USE_REASONER
48 | #include "../Test/rtest.h"
49 | #include "../Parser/dbparse.h"
50 | #endif
51 |
52 |
53 | /* ====== Private defs =========== */
54 |
55 | #define FLAGS_QUIET 0x1
56 |
57 | /* ======= Private protos ================ */
58 |
59 | gint parse_flag(char *arg);
60 |
61 | /* ====== Functions ============== */
62 |
63 |
64 | /** usage: display command line help.
65 | *
66 | */
67 |
68 | void usage(char *prog) {
69 | printf("usage: %s [-q] \n"\
70 | "Where:\n"\
71 | " command is one of:\n\n"\
72 | " help (or \"-h\") - display this text.\n"\
73 | " common - run quick tests of common functionality.\n"\
74 | " query - run in-depth query tests.\n"\
75 | " index - run in-depth index tests.\n"\
76 | " log - run journal logging tests.\n", prog);
77 | #ifdef USE_REASONER
78 | printf(" reasoner - test the reasoner.\n");
79 | #endif
80 | printf("\nThe flag `-q' will disable most of the output from the tests.\n");
81 | }
82 |
83 | /** Handle a command-line flag
84 | *
85 | */
86 | gint parse_flag(char *arg) {
87 | while(arg[0] == '-')
88 | arg++;
89 | switch(arg[0]) {
90 | case 'q':
91 | return FLAGS_QUIET;
92 | default:
93 | fprintf(stderr, "Unrecognized option: `%c'\n", arg[0]);
94 | break;
95 | }
96 | return 0;
97 | }
98 |
99 | /** Parse the command line and execute at most one command.
100 | *
101 | *
102 | */
103 |
104 | int main(int argc, char **argv) {
105 | int i, flags = 0;
106 | int rc = 0;
107 |
108 | for(i=1; i no commands found */
145 | usage(argv[0]);
146 | }
147 | exit(rc);
148 | }
149 |
150 |
151 | #ifdef __cplusplus
152 | }
153 | #endif
154 |
--------------------------------------------------------------------------------
/Makefile.am:
--------------------------------------------------------------------------------
1 | # $Id: $
2 | # $Source: $
3 | #
4 | # Top level Makefile.am of WhiteDB: calling makes in subdirs
5 | #
6 |
7 | #AUTOMAKE_OPTIONS = foreign
8 | AUTOMAKE_OPTIONS = subdir-objects
9 |
10 | SUBDIRS = Db json
11 | if REASONER
12 | SUBDIRS += Parser Reasoner Printer
13 | endif
14 | SUBDIRS += Test Main Examples
15 | if PYTHON
16 | SUBDIRS += Python
17 | endif
18 |
19 | # --- man ---
20 |
21 | man_MANS = Doc/whitedb.7
22 |
23 | # --- optional components ----
24 |
25 |
26 | # -------- Tests -------------------
27 |
28 | TESTS = Test/common.test Test/log.test
29 | Test/log.log: Test/common.log
30 |
31 | # -------- Extras -------------------
32 |
33 |
34 | EXTRA_DIST = Bootstrap README INSTALL MANIFEST GPLLICENCE NEWS AUTHORS \
35 | Doc/whitedb.7 Doc/python.txt Doc/Manual.txt \
36 | Doc/Install.txt Doc/Utilities.txt Doc/Tutorial.txt \
37 | wgdb.def config-w32.h config-gcc.h Doxyfile compile.sh compile.bat \
38 | unite.sh \
39 | Db/dbapi.h Db/rdfapi.h Db/indexapi.h \
40 | Examples/compile_demo.sh Examples/compile_demo.bat \
41 | Examples/compile_query.sh Examples/compile_query.bat \
42 | Examples/dserve.c Examples/tut1.c Examples/tut2.c Examples/tut3.c \
43 | Examples/tut4.c Examples/tut5.c Examples/tut6.c Examples/tut7.c \
44 | Examples/speed/README Examples/speed/speed1.c Examples/speed/speed2.c \
45 | Examples/speed/speed3.c Examples/speed/speed4.c Examples/speed/speed5.c \
46 | Examples/speed/speed6.c Examples/speed/speed7.c Examples/speed/speed8.c \
47 | Examples/speed/speed10.c Examples/speed/speed11.c Examples/speed/speed12.c \
48 | Examples/speed/speed13.c Examples/speed/speed15.c Examples/speed/speed16.c \
49 | Python/compile.bat Python/compile.sh Python/tests.py \
50 | Parser/dbotter.y Parser/dbotter.l Parser/dbprolog.y Parser/dbprolog.l \
51 | Rexamples \
52 | Test/common.test Test/log.test \
53 | whitedb.pc.in
54 |
55 | # this conflicts with the distcheck target, so disabled for now.
56 | #dist-hook:
57 | # cp $(top_distdir)/config-gcc.h $(top_distdir)/config.h
58 |
59 | # -------- Pkg-config ---------------
60 |
61 | pkgconfigdir = $(libdir)/pkgconfig
62 | pkgconfig_DATA = whitedb.pc
63 |
--------------------------------------------------------------------------------
/NEWS:
--------------------------------------------------------------------------------
1 | News
2 | ====
3 |
4 | Nothing here: see https://github.com/priitj/whitedb for history
--------------------------------------------------------------------------------
/Parser/Makefile.am:
--------------------------------------------------------------------------------
1 | #
2 | # - - - - reasoner sources - - - -
3 |
4 | parsergenfiles = dbotter.tab.c dbotter.tab.h\
5 | dbotter.yy.c dbprolog.tab.c\
6 | dbprolog.tab.h dbprolog.yy.c
7 |
8 | parserfiles = dbparse.c dbparse.h dbgenparse.h\
9 | dbotterparse.h\
10 | dbprologparse.h\
11 | $(parsergenfiles)
12 |
13 | # - - - - reasoner sources for flex and bison and their compilation to c - - - -
14 |
15 | dbotter.tab.c dbotter.tab.h: dbotter.y dbotterparse.h dbgenparse.h
16 | $(BISON) -pwg_yyotter -d -v dbotter.y -o dbotter.tab.c
17 |
18 | dbotter.yy.c: dbotter.l dbotter.tab.h dbotterparse.h dbgenparse.h
19 | $(LEX) -Pwg_yyotter -odbotter.yy.c dbotter.l
20 |
21 | dbprolog.tab.c dbprolog.tab.h: dbprolog.y dbprologparse.h dbgenparse.h
22 | $(BISON) -pwg_yyprolog -d -v dbprolog.y -o dbprolog.tab.c
23 |
24 | dbprolog.yy.c: dbprolog.l dbprolog.tab.h dbprologparse.h dbgenparse.h
25 | $(LEX) -Pwg_yyprolog -odbprolog.yy.c dbprolog.l
26 |
27 | MAINTAINERCLEANFILES = $(parsergenfiles)
28 |
29 | noinst_LTLIBRARIES = libParser.la
30 | libParser_la_SOURCES = $(parserfiles)
31 |
32 |
--------------------------------------------------------------------------------
/Parser/dbgenparse.h:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Tanel Tammet 2004,2005,2006,2007,2008,2009,2010
6 | *
7 | * Contact: tanel.tammet@gmail.com
8 | *
9 | * This file is part of WhiteDB
10 | *
11 | * WhiteDB is free software: you can redistribute it and/or modify
12 | * it under the terms of the GNU General Public License as published by
13 | * the Free Software Foundation, either version 3 of the License, or
14 | * (at your option) any later version.
15 | *
16 | * WhiteDB is distributed in the hope that it will be useful,
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | * GNU General Public License for more details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with WhiteDB. If not, see .
23 | *
24 | */
25 |
26 | /** @file dbgenparse.h
27 | * Top level/generic headers and defs for parsers
28 | *
29 | */
30 |
31 | #ifndef DEFINED_DBGENPARSE_H
32 | #define DEFINED_DBGENPARSE_H
33 |
34 | #include "../Db/dbdata.h"
35 | #include "../Db/dbmpool.h"
36 | #include "dbparse.h"
37 |
38 | #define parseprintf(...)
39 |
40 | #define MKWGPAIR(pp,x,y) (wg_mkpair(((parse_parm*)pp)->db,((parse_parm*)pp)->mpool,x,y))
41 |
42 | #define MKWGINT(pp,x) (wg_mkatom(((parse_parm*)pp)->db,((parse_parm*)pp)->mpool,WG_INTTYPE,x,NULL))
43 | #define MKWGFLOAT(pp,x) (wg_mkatom(((parse_parm*)pp)->db,((parse_parm*)pp)->mpool,WG_DOUBLETYPE,x,NULL))
44 | #define MKWGDATE(pp,x) (wg_mkatom(((parse_parm*)pp)->db,((parse_parm*)pp)->mpool,WG_DATETYPE,x,NULL))
45 | #define MKWGTIME(pp,x) (wg_mkatom(((parse_parm*)pp)->db,((parse_parm*)pp)->mpool,WG_TIMETYPE,x,NULL))
46 | #define MKWGID(pp,x) (wg_mkatom(((parse_parm*)pp)->db,((parse_parm*)pp)->mpool,WG_URITYPE,x,NULL))
47 | #define MKWGURI(pp,x) (wg_mkatom(((parse_parm*)pp)->db,((parse_parm*)pp)->mpool,WG_URITYPE,x,NULL))
48 | #define MKWGSTRING(pp,x) (wg_mkatom(((parse_parm*)pp)->db,((parse_parm*)pp)->mpool,WG_STRTYPE,x,NULL))
49 | #define MKWGCONST(pp,x) (wg_mkatom(((parse_parm*)pp)->db,((parse_parm*)pp)->mpool,WG_ANONCONSTTYPE,x,NULL))
50 | #define MKWGVAR(pp,x) (wg_mkatom(((parse_parm*)pp)->db,((parse_parm*)pp)->mpool,WG_VARTYPE,x,NULL))
51 | #define MKWGNIL NULL
52 |
53 |
54 | // ---- reeentrant ----
55 |
56 | typedef struct parse_parm_s {
57 | void *yyscanner; // has to be present
58 | char *buf; // for parse from str case
59 | int pos; // for parse from str case
60 | int length; // for parse from str case
61 | char* filename; // for err handling
62 | void* result; // parser result
63 | void* db; // database pointer
64 | void* mpool; // mpool pointer
65 | char* foo; // if NULL, use input from stdin, else from buf (str case)
66 | } parse_parm;
67 |
68 | #define YYSTYPE char*
69 | #define YY_EXTRA_TYPE parse_parm *
70 |
71 |
72 |
73 | #endif
74 |
--------------------------------------------------------------------------------
/Parser/dbotter.y:
--------------------------------------------------------------------------------
1 | /* Copyright (c) Mindstone 2004
2 | *
3 | * This program is free software; you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation; either version 1, or (at your option)
6 | * any later version.
7 | *
8 | * This program is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with this program: the file COPYING contains this copy.
15 | * if not, write to the Free Software
16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 | *
18 | */
19 |
20 |
21 | %{
22 |
23 | #include
24 | #include "dbotterparse.h"
25 |
26 | //#define PP ((void*)(((* parse_parm)parm)->foo))
27 | #define PP (parm)
28 |
29 | %}
30 |
31 |
32 | /*
33 | ** 'pure_parser' tells bison to use no global variables and create a
34 | ** reentrant parser.
35 | */
36 |
37 | %pure_parser
38 | %parse-param {parse_parm *parm}
39 | %parse-param {void *scanner}
40 | %lex-param {yyscan_t *scanner}
41 |
42 |
43 | %token VARIABLE
44 | %token FILEEND
45 |
46 | %token INT
47 | %token FLOAT
48 | %token DATE
49 | %token TIME
50 | %token STRING
51 | %token ID
52 | %token URI
53 | %token CONST
54 | %token VAR
55 |
56 |
57 |
58 | %% /* Grammar rules and actions follow */
59 |
60 | input: /* empty */
61 | | sentencelist {
62 | (parm->result)=$1;
63 | }
64 | ;
65 |
66 | sentence: assertion { $$ = $1; }
67 | ;
68 |
69 | sentencelist: sentence { $$ = MKWGPAIR(PP,$1,MKWGNIL); }
70 | | sentencelist sentence { $$ = MKWGPAIR(PP,$2,$1); }
71 | ;
72 |
73 |
74 | assertion: primsentence '.' { $$ = $1; }
75 | ;
76 |
77 |
78 | primsentence: term { $$ = MKWGPAIR(PP,$1,MKWGNIL); }
79 | | loglist { $$ = $1; }
80 | ;
81 |
82 | loglist: term { $$ = MKWGPAIR(PP,$1,MKWGNIL); }
83 | | term '|' loglist { $$ = MKWGPAIR(PP,$1,$3); }
84 | ;
85 |
86 | term: prim { $$ = $1; }
87 | | prim '(' ')' { $$ = MKWGPAIR(PP,$1,NULL); }
88 | | prim '(' termlist ')' { $$ = MKWGPAIR(PP,$1,$3); }
89 | | '-' term { $$ = MKWGPAIR(PP,MKWGCONST(PP,"not"),MKWGPAIR(PP,$2,MKWGNIL)); }
90 | ;
91 |
92 |
93 | termlist: term { $$ = MKWGPAIR(PP,$1,MKWGNIL); }
94 | | term ',' termlist { $$ = MKWGPAIR(PP,$1,$3); }
95 | ;
96 |
97 |
98 | prim: INT { $$ = MKWGINT(PP,$1); }
99 | | FLOAT { $$ = MKWGFLOAT(PP,$1); }
100 | | DATE { $$ = MKWGDATE(PP,$1); }
101 | | TIME { $$ = MKWGTIME(PP,$1); }
102 | | STRING { $$ = MKWGSTRING(PP,$1); }
103 | | VAR { $$ = MKWGVAR(PP,$1); }
104 | | URI { $$ = MKWGURI(PP,$1); }
105 | | ID { $$ = MKWGCONST(PP,$1); }
106 | | CONST { $$ = MKWGCONST(PP,$1); }
107 | ;
108 |
109 |
110 |
111 | %%
112 |
113 |
--------------------------------------------------------------------------------
/Parser/dbotterparse.h:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Tanel Tammet 2004,2005,2006,2007,2008,2009,2010
6 | *
7 | * Contact: tanel.tammet@gmail.com
8 | *
9 | * This file is part of WhiteDB
10 | *
11 | * WhiteDB is free software: you can redistribute it and/or modify
12 | * it under the terms of the GNU General Public License as published by
13 | * the Free Software Foundation, either version 3 of the License, or
14 | * (at your option) any later version.
15 | *
16 | * WhiteDB is distributed in the hope that it will be useful,
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | * GNU General Public License for more details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with WhiteDB. If not, see .
23 | *
24 | */
25 |
26 | /** @file dbotterparse.h
27 | * Special defs and headers for otter parser
28 | *
29 | */
30 |
31 | #ifndef DEFINED_DBOTTERPARSE_H
32 | #define DEFINED_DBOTTERPARSE_H
33 |
34 | #include "dbgenparse.h"
35 |
36 | int wg_yyotterlex(YYSTYPE *, void *);
37 | int wg_yyotterlex_init(void **);
38 | int wg_yyotterlex_destroy(void *);
39 | void wg_yyotterset_extra(YY_EXTRA_TYPE, void *);
40 | int wg_yyotterparse(parse_parm *, void *);
41 |
42 | void wg_yyottererror (parse_parm* parm, void* scanner, char* msg);
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/Parser/dbparse.h:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Tanel Tammet 2004,2005,2006,2007,2008,2009,2010
6 | *
7 | * Contact: tanel.tammet@gmail.com
8 | *
9 | * This file is part of WhiteDB
10 | *
11 | * WhiteDB is free software: you can redistribute it and/or modify
12 | * it under the terms of the GNU General Public License as published by
13 | * the Free Software Foundation, either version 3 of the License, or
14 | * (at your option) any later version.
15 | *
16 | * WhiteDB is distributed in the hope that it will be useful,
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | * GNU General Public License for more details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with WhiteDB. If not, see .
23 | *
24 | */
25 |
26 | /** @file dbparse.h
27 | * Top level/generic headers and defs for parsers
28 | *
29 | */
30 |
31 | #ifndef DEFINED_DBPARSE_H
32 | #define DEFINED_DBPARSE_H
33 |
34 | #include "../Db/dballoc.h"
35 | #include "../Reasoner/mem.h"
36 | #include "../Reasoner/glb.h"
37 |
38 | #define OTTER_DECIMAL_SEPARATOR '.'
39 |
40 | int wr_import_otter_file(glb* g, char* filename, char* strasfile, cvec clvec);
41 | //int wg_import_otter_file(void* db, char* filename, int printlevel);
42 | int wr_import_prolog_file(glb* g, char* filename, char* strasfile, cvec clvec);
43 |
44 | void* wr_parse_clauselist(glb* g,void* mpool,cvec clvec,void* clauselist);
45 | void* wr_parse_atom(glb* g,void* mpool,void* term, int isneg, int issimple, char** vardata);
46 | void* wr_parse_term(glb* g,void* mpool,void* term, char** vardata);
47 | gint wr_parse_primitive(glb* g,void* mpool,void* term, char** vardata);
48 |
49 | gint wr_parse_and_encode_otter_prim(glb* g, char *buf);
50 | gint wr_parse_and_encode_otter_uri(glb* g, char *buf);
51 |
52 | gint wr_print_parseres(glb* g, gint x);
53 |
54 |
55 | #endif
56 |
--------------------------------------------------------------------------------
/Parser/dbprologparse.h:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Tanel Tammet 2004,2005,2006,2007,2008,2009,2010
6 | *
7 | * Contact: tanel.tammet@gmail.com
8 | *
9 | * This file is part of WhiteDB
10 | *
11 | * WhiteDB is free software: you can redistribute it and/or modify
12 | * it under the terms of the GNU General Public License as published by
13 | * the Free Software Foundation, either version 3 of the License, or
14 | * (at your option) any later version.
15 | *
16 | * WhiteDB is distributed in the hope that it will be useful,
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | * GNU General Public License for more details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with WhiteDB. If not, see .
23 | *
24 | */
25 |
26 | /** @file dbprologparse.h
27 | * Special defs and headers for prolog parser
28 | *
29 | */
30 |
31 | #ifndef DEFINED_PROLOGPARSE_H
32 | #define DEFINED_PROLOGPARSE_H
33 |
34 | #include "dbgenparse.h"
35 |
36 |
37 | int wg_yyprologlex(YYSTYPE *, void *);
38 | int wg_yyprologlex_init(void **);
39 | int wg_yyprologlex_destroy(void *);
40 | void wg_yyprologset_extra(YY_EXTRA_TYPE, void *);
41 | int wg_yyprologparse(parse_parm *, void *);
42 |
43 | void wg_yyprologerror (parse_parm* parm, void* scanner, char* msg);
44 |
45 |
46 | #endif
47 |
48 |
--------------------------------------------------------------------------------
/Printer/Makefile.am:
--------------------------------------------------------------------------------
1 | #
2 | # - - - - reasoner sources - - - -
3 |
4 | noinst_LTLIBRARIES = libPrinter.la
5 | libPrinter_la_SOURCES = dbotterprint.c dbotterprint.h
6 |
7 |
--------------------------------------------------------------------------------
/Printer/dbotterprint.h:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Tanel Tammet 2004,2005,2006,2007,2008,2009,2010
6 | *
7 | * Contact: tanel.tammet@gmail.com
8 | *
9 | * This file is part of WhiteDB
10 | *
11 | * WhiteDB is free software: you can redistribute it and/or modify
12 | * it under the terms of the GNU General Public License as published by
13 | * the Free Software Foundation, either version 3 of the License, or
14 | * (at your option) any later version.
15 | *
16 | * WhiteDB is distributed in the hope that it will be useful,
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | * GNU General Public License for more details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with WhiteDB. If not, see .
23 | *
24 | */
25 |
26 | /** @file dbotterprint.h
27 | * Top level/generic headers and defs for otterprinter
28 | *
29 | */
30 |
31 | #ifndef DEFINED_DBOTTERPRINT_H
32 | #define DEFINED_DBOTTERPRINT_H
33 |
34 | #include "../Db/dballoc.h"
35 |
36 | #include "../Reasoner/types.h"
37 | #include "../Reasoner/mem.h"
38 | #include "../Reasoner/glb.h"
39 |
40 | void wr_print_clause(glb* g, gptr rec);
41 | void wr_print_term(glb* g, gint rec);
42 | void wr_print_record(glb* g, gptr rec);
43 |
44 | void wr_print_db_otter(glb* g,int printlevel);
45 |
46 | void wr_print_clause_otter(glb* g, gint* rec,int printlevel);
47 | void wr_print_rule_clause_otter(glb* g, gint* rec,int printlevel);
48 | void wr_print_fact_clause_otter(glb* g, gint* rec,int printlevel);
49 | void wr_print_atom_otter(glb* g, gint rec,int printlevel);
50 | void wr_print_term_otter(glb* g, gint rec,int printlevel);
51 | void wr_print_simpleterm_otter(glb* g, gint enc,int printlevel);
52 |
53 | #endif
54 |
--------------------------------------------------------------------------------
/Python/Makefile.am:
--------------------------------------------------------------------------------
1 | # $Id: $
2 | # $Source: $
3 | #
4 | # Compile Python extension module
5 |
6 |
7 | # ---- options ----
8 |
9 | # ---- targets ----
10 |
11 | python_PYTHON = whitedb.py WGandalf.py
12 | pyexec_LTLIBRARIES = wgdb.la
13 |
14 | # ---- path variables ----
15 |
16 | dbdir=../Db
17 |
18 | # ---- extra dependencies, flags, etc -----
19 |
20 | LIBDEPS = -lm # dependency from libm round() should be removed
21 | if RAPTOR
22 | LIBDEPS += `$(RAPTOR_CONFIG) --libs`
23 | endif
24 |
25 | AM_CPPFLAGS = $(PYTHON_INCLUDES) -I $(dbdir)
26 | wgdb_la_LDFLAGS = -module -avoid-version $(LIBDEPS)
27 |
28 | # ----- all sources for the created programs -----
29 |
30 | wgdb_la_SOURCES = wgdbmodule.c
31 | wgdb_la_LIBADD = ../Main/libwgdb.la
32 |
--------------------------------------------------------------------------------
/Python/WGandalf.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: latin-1 -*-
3 | #
4 | # Copyright (c) Priit Järv 2013
5 | #
6 | # This file is part of WhiteDB
7 | #
8 | # WhiteDB is free software: you can redistribute it and/or modify
9 | # it under the terms of the GNU General Public License as published by
10 | # the Free Software Foundation, either version 3 of the License, or
11 | # (at your option) any later version.
12 | #
13 | # WhiteDB is distributed in the hope that it will be useful,
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | # GNU General Public License for more details.
17 | #
18 | # You should have received a copy of the GNU General Public License
19 | # along with WhiteDB. If not, see .
20 |
21 | """@file WGandalf.py
22 |
23 | Backwards compatibility wrapper for WhiteDB database Python API
24 | """
25 |
26 | from warnings import warn
27 | warn("WGandalf module is deprecated, use whitedb instead", DeprecationWarning)
28 |
29 | from whitedb import *
30 |
--------------------------------------------------------------------------------
/Python/compile.bat:
--------------------------------------------------------------------------------
1 | @rem Check that this matches your Python path
2 | set PYDIR=c:\Python25
3 |
4 | @rem When compiling for Python 3, replace /export:initwgdb
5 | @rem with /export:PyInit_wgdb
6 |
7 | @cl /Ox /W3 /MT /I..\Db /I%PYDIR%\include wgdbmodule.c ..\Db\dbmem.c ..\Db\dballoc.c ..\Db\dbdata.c ..\Db\dblock.c ..\DB\dbdump.c ..\Db\dblog.c ..\Db\dbhash.c ..\Db\dbindex.c ..\Db\dbcompare.c ..\Db\dbquery.c ..\Db\dbutil.c ..\Db\dbmpool.c ..\Db\dbjson.c ..\Db\dbschema.c ..\json\yajl_all.c /link /dll /incremental:no /MANIFEST:NO /LIBPATH:%PYDIR%\libs /export:initwgdb /out:wgdb.pyd
8 | @rem Currently this script produced a statically linked DLL for ease of
9 | @rem testing and debugging. If dynamic linking is needed:
10 | @rem 1. replace /MT with /MD
11 | @rem 2. remove /manifest:no or just the "NO" part
12 | @rem 3. uncomment the following:
13 | @rem mt -manifest wgdb.pyd.manifest -outputresource:wgdb.pyd;2
14 | @rem You may also need to:
15 | @rem 4. distribute msvcrxx.dll from the compiler suite with the lib
16 |
--------------------------------------------------------------------------------
/Python/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | [ -z "$CC" ] && CC="cc"
4 |
5 | if [ -z "$(which $CC 2>/dev/null)" ]; then
6 | echo "Error: No compiler found"
7 | exit 1
8 | fi
9 |
10 | export PYDIR=/usr/include/python2.7
11 |
12 | # run unite.sh if needed
13 | if [ ! -f ../whitedb.c ]; then
14 | cd ..; ./unite.sh; cd "$OLDPWD"
15 | fi
16 |
17 | $CC -O3 -Wall -fPIC -shared -I.. -I../Db -I${PYDIR} -o wgdb.so wgdbmodule.c ../whitedb.c
18 |
19 | #$CC -O3 -Wall -fPIC -shared -I../Db -I${PYDIR} -o wgdb.so wgdbmodule.c ../Db/dbmem.c ../Db/dballoc.c ../Db/dbdata.c ../Db/dblock.c ../Db/dbindex.c ../Db/dblog.c ../Db/dbhash.c ../Db/dbcompare.c ../Db/dbquery.c ../Db/dbutil.c ../Db/dbmpool.c ../Db/dbjson.c ../Db/dbschema.c ../json/yajl_all.c
20 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | WhiteDB (wgdb) README
2 | ======================
3 |
4 | WhiteDB is a lightweight database library operating fully in main memory.
5 | Disk is used only for dumping/restoring database and logging.
6 |
7 | Data is persistantly kept in the shared memory area: it is available simultaneously
8 | to all processes and is kept intact even if no processes are currently using the
9 | database.
10 |
11 | WhiteDB has no server process. Data is read and written directly from/to memory,
12 | no sockets are used between WhiteDB and the application using WhiteDB.
13 |
14 | WhiteDB keeps data as N-tuples: each database record is a tuple of N elements.
15 | Each element (record field) may have an arbitrary type amongst the types provided
16 | by WhiteDB. Each record field contains exactly one integer (4 bytes or 8 bytes).
17 | Datatypes which cannot be fit into one integer are allocated separately
18 | and the record field contains an (encoded) pointer to the real data.
19 |
20 | WhiteDB is written in pure C in a portable manner and should compile and function
21 | without additional porting at least under Linux (gcc) and Windows
22 | (native Windows C compiler cl). It has Python and experimental Java bindings.
23 |
24 | WhiteDB has several goals:
25 |
26 | - speed
27 | - portability
28 | - small footprint and low memory usage
29 | - usability as an rdf database
30 | - usability as an extended rdf database, xml database and outside these scopes
31 | - integration with the Gandalf rule engine (work in progress)
32 |
33 | See http://whitedb.org for up-to-date documentation and other information.
34 | This distribution also includes various documentation:
35 |
36 | Doc/Install.txt - the installation instructions
37 | Doc/Tutorial.txt - getting started with the database
38 | Doc/Manual.txt - full C API documentation
39 | Doc/Utilities.txt - command line utilities and other programs
40 | Doc/python.txt - Python API documentation
41 |
42 | WhiteDB is licenced under GPL version 3.
43 |
44 |
--------------------------------------------------------------------------------
/README.asc:
--------------------------------------------------------------------------------
1 | WhiteDB (wgdb) README
2 | ======================
3 |
4 | WhiteDB is a lightweight database library operating fully in main memory.
5 | Disk is used only for dumping/restoring database and logging.
6 |
7 | Data is persistantly kept in the shared memory area: it is available simultaneously
8 | to all processes and is kept intact even if no processes are currently using the
9 | database.
10 |
11 | WhiteDB has no server process. Data is read and written directly from/to memory,
12 | no sockets are used between WhiteDB and the application using WhiteDB.
13 |
14 | WhiteDB keeps data as N-tuples: each database record is a tuple of N elements.
15 | Each element (record field) may have an arbitrary type amongst the types provided
16 | by WhiteDB. Each record field contains exactly one integer (4 bytes or 8 bytes).
17 | Datatypes which cannot be fit into one integer are allocated separately
18 | and the record field contains an (encoded) pointer to the real data.
19 |
20 | WhiteDB is written in pure C in a portable manner and should compile and function
21 | without additional porting at least under Linux (gcc) and Windows
22 | (native Windows C compiler cl). It has Python and experimental Java bindings.
23 |
24 | WhiteDB has several goals:
25 |
26 | - speed
27 | - portability
28 | - small footprint and low memory usage
29 | - usability as an rdf database
30 | - usability as an extended rdf database, xml database and outside these scopes
31 | - seamless integration with the Gandalf rule engine (work in progress)
32 |
33 | See http://whitedb.org for up-to-date documentation and other information.
34 | This distribution also includes various documentation:
35 |
36 | - Doc/Install.txt - the installation instructions
37 | - Doc/Tutorial.txt - getting started with the database
38 | - Doc/Manual.txt - full C API documentation
39 | - Doc/Utilities.txt - command line utilities and other programs
40 | - Doc/python.txt - Python API documentation
41 |
42 | WhiteDB is licenced under GPL version 3.
43 |
44 | NOTE: if you're looking for release packages, please don't use the ones Github
45 | generates automatically. Get them from http://whitedb.org/download.html
46 | instead.
47 |
48 |
49 |
--------------------------------------------------------------------------------
/Reasoner/Makefile.am:
--------------------------------------------------------------------------------
1 | #
2 | # - - - - reasoner sources - - - -
3 |
4 | noinst_LTLIBRARIES = libReasoner.la
5 | libReasoner_la_SOURCES = types.h rincludes.h \
6 | printerrutils.c printerrutils.h\
7 | rmain.c rmain.h\
8 | glb.c glb.h\
9 | rgenloop.c rgenloop.h\
10 | derive.c derive.h\
11 | subsume.c subsume.h\
12 | unify.c unify.h\
13 | build.c build.h\
14 | clstore.c clstore.h\
15 | clterm.c clterm.h\
16 | mem.c mem.h
17 |
18 |
--------------------------------------------------------------------------------
/Reasoner/build.h:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Tanel Tammet 2004,2005,2006,2007,2008,2009,2010
6 | *
7 | * Contact: tanel.tammet@gmail.com
8 | *
9 | * This file is part of WhiteDB
10 | *
11 | * WhiteDB is free software: you can redistribute it and/or modify
12 | * it under the terms of the GNU General Public License as published by
13 | * the Free Software Foundation, either version 3 of the License, or
14 | * (at your option) any later version.
15 | *
16 | * WhiteDB is distributed in the hope that it will be useful,
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | * GNU General Public License for more details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with WhiteDB. If not, see .
23 | *
24 | */
25 |
26 |
27 | /** @file build.h
28 | * Term and clause building functions.
29 | *
30 | */
31 |
32 |
33 | #ifndef DEFINED_BUILD_H
34 | #define DEFINED_BUILD_H
35 |
36 |
37 | #include "glb.h"
38 |
39 | #define CVEC_ALLOC_ALIGNMENT_BYTES 8
40 |
41 | gptr wr_build_calc_cl(glb* g, gptr x);
42 | gint wr_build_calc_term(glb* g, gint x);
43 |
44 | int wr_computable_termptr(glb* g, gptr yptr);
45 | gint wr_compute_from_termptr(glb* g, gptr yptr);
46 | gint wr_compute_fun_plus(glb* g, gptr tptr);
47 | gint wr_compute_fun_equal(glb* g, gptr tptr);
48 |
49 | #endif
50 |
--------------------------------------------------------------------------------
/Reasoner/clstore.h:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Tanel Tammet 2004,2005,2006,2007,2008,2009,2010
6 | *
7 | * Contact: tanel.tammet@gmail.com
8 | *
9 | * This file is part of WhiteDB
10 | *
11 | * WhiteDB is free software: you can redistribute it and/or modify
12 | * it under the terms of the GNU General Public License as published by
13 | * the Free Software Foundation, either version 3 of the License, or
14 | * (at your option) any later version.
15 | *
16 | * WhiteDB is distributed in the hope that it will be useful,
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | * GNU General Public License for more details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with WhiteDB. If not, see .
23 | *
24 | */
25 |
26 | /** @file clstore.h
27 | * Headers for clause storage functions.
28 | */
29 |
30 |
31 | #ifndef DEFINED_CLSTORE_H
32 | #define DEFINED_CLSTORE_H
33 |
34 | /* ==== Includes ==== */
35 |
36 | #include "types.h"
37 | #include "glb.h"
38 |
39 | /* ==== Global defines ==== */
40 |
41 | #define CLTERM_HASHNODE_GINT_NR 3
42 | #define CLTERM_HASHNODE_LEN_POS 0
43 | #define CLTERM_HASHNODE_TERM_POS 0
44 | #define CLTERM_HASHNODE_CL_POS 1
45 | #define CLTERM_HASHNODE_NEXT_POS 2
46 |
47 | #define MAXHASHPOS 30
48 |
49 | /* ==== Protos ==== */
50 |
51 |
52 | void wr_push_clpickstack_cl(glb* g, gptr cl);
53 | void wr_show_clpickstack(glb* g);
54 | void wr_push_clqueue_cl(glb* g, gptr cl);
55 | void wr_show_clqueue(glb* g);
56 | void wr_push_clactive_cl(glb* g, gptr cl);
57 | void wr_show_clactive(glb* g);
58 |
59 | int wr_cl_store_res_terms(glb* g, gptr cl);
60 |
61 | int wr_term_hashstore(glb* g, void* hashdata, gint atom, gptr cl);
62 |
63 | gint wr_term_complexhash(glb* g, gint* hasharr, gint hashposbits, gint term);
64 | gint wr_atom_funhash(glb* g, gint atom);
65 | gint wr_term_basehash(glb* g, gint enc);
66 |
67 | int wr_clterm_add_hashlist(glb* g, vec hashvec, gint hash, gint term, gptr cl);
68 | int wr_clterm_hashlist_len(glb* g, vec hashvec, gint hash);
69 | gint wr_clterm_hashlist_start(glb* g, vec hashvec, gint hash);
70 | gint wr_clterm_hashlist_next(glb* g, vec hashvec, gint lastel);
71 |
72 | gptr wr_clterm_alloc_hashnode(glb* g);
73 | void wr_clterm_free_hashnode(glb* g, gptr node);
74 | void wr_clterm_hashlist_free(glb* g, vec hashvec);
75 | void wr_clterm_hashlist_print(glb* g, vec hashvec);
76 |
77 |
78 |
79 | #endif
80 |
--------------------------------------------------------------------------------
/Reasoner/derive.h:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Tanel Tammet 2004,2005,2006,2007,2008,2009,2010
6 | *
7 | * Contact: tanel.tammet@gmail.com
8 | *
9 | * This file is part of WhiteDB
10 | *
11 | * WhiteDB is free software: you can redistribute it and/or modify
12 | * it under the terms of the GNU General Public License as published by
13 | * the Free Software Foundation, either version 3 of the License, or
14 | * (at your option) any later version.
15 | *
16 | * WhiteDB is distributed in the hope that it will be useful,
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | * GNU General Public License for more details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with WhiteDB. If not, see .
23 | *
24 | */
25 |
26 | /** @file derive.h
27 | * Headers for clause derivation functions.
28 | */
29 |
30 |
31 | #ifndef DEFINED_DERIVE_H
32 | #define DEFINED_DERIVE_H
33 |
34 | /* ==== Includes ==== */
35 |
36 | #include "types.h"
37 | #include "glb.h"
38 |
39 | /* ==== Global defines ==== */
40 |
41 | /* ==== Protos ==== */
42 |
43 | void wr_process_resolve_result(glb* g, gint xatom, gptr xcl, gint yatom, gptr ycl);
44 | int wr_process_resolve_result_isrulecl(glb* g, gptr rptr, int rpos);
45 | void wr_process_resolve_result_setupsubst(glb* g);
46 | void wr_process_resolve_result_setupgivencopy(glb* g);
47 | void wr_process_resolve_result_setupquecopy(glb* g);
48 | void wr_process_resolve_result_setupclpickstackcopy(glb* g) ;
49 | void wr_process_resolve_result_cleanupsubst(glb* g);
50 | int wr_process_resolve_result_aux
51 | (glb* g, gptr cl, gint cutatom, int atomnr, gptr rptr, int* rpos);
52 | int wr_hyperres_satellite_cl(glb* g,gptr cl);
53 | int wr_hyperres_satellite_tmpres(glb* g,gptr tmpres, int respos);
54 |
55 | // void resolve_binary_all_active(gptr cl1);
56 |
57 | /*
58 | void resolve_binary(gptr cl1, gptr cl2);
59 | gptr factor_step(gptr incl);
60 | int simplify_cl_destr(gptr cl, int given_flag);
61 | int can_cut_lit(gptr litpt1, int unify_flag, int given_flag);
62 |
63 | void proc_derived_cl(gptr incl);
64 | void proc_derived_cl_binhist(gptr incl, gint clid1, gint clid2, gint litpos1, gint litpos2);
65 | void proc_input_cl(gptr incl);
66 | */
67 |
68 | #endif
69 |
--------------------------------------------------------------------------------
/Reasoner/mem.h:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Tanel Tammet 2004,2005,2006,2007,2008,2009,2010
6 | *
7 | * Contact: tanel.tammet@gmail.com
8 | *
9 | * This file is part of WhiteDB
10 | *
11 | * WhiteDB is free software: you can redistribute it and/or modify
12 | * it under the terms of the GNU General Public License as published by
13 | * the Free Software Foundation, either version 3 of the License, or
14 | * (at your option) any later version.
15 | *
16 | * WhiteDB is distributed in the hope that it will be useful,
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | * GNU General Public License for more details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with WhiteDB. If not, see .
23 | *
24 | */
25 |
26 |
27 | /** @file mem.h
28 | * Specific memory allocation functions: vectors etc.
29 | *
30 | */
31 |
32 |
33 | #ifndef DEFINED_MEM_H
34 | #define DEFINED_MEM_H
35 |
36 |
37 | #ifdef _WIN32
38 | #include "../config-w32.h"
39 | #else
40 | #include "../config.h"
41 | #endif
42 | #include "../Db/dballoc.h"
43 | #include "../Db/dbdata.h"
44 |
45 | #include "types.h"
46 | #include "glb.h"
47 |
48 | #define sys_malloc malloc ///< never use malloc: use sys_malloc as a last resort
49 | #define sys_free free ///< never use free: use sys_free as a last resort
50 | #define sys_realloc realloc ///< use sys_realloc instead of realloc
51 |
52 | #define OVER_MALLOC_BYTES 8 ///db),(offset))))
70 | #define rpto(g,realptr)((gint)(pto(((g)->db),(realptr))))
71 |
72 | /* ======= prototypes ===== */
73 |
74 | void* wr_malloc(glb* g, int bytes);
75 | void* wr_realloc(glb* g, void* p, int bytes);
76 | void wr_free(glb* g, void* p);
77 |
78 | vec wr_vec_new(glb* g, int len);
79 | cvec wr_cvec_new(glb* g,int len);
80 | void wr_vec_free(glb* g, vec v);
81 | void wr_vecstr_free(glb* g, vec v);
82 | void wr_vecvecstr_free(glb* g, vec v);
83 | vec wr_vec_realloc(glb* g, vec v, int i);
84 | vec wr_vec_store(glb* g, vec v, int i, gint e);
85 | cvec wr_cvec_store(glb* g,vec v, int i, gint e);
86 | cvec wr_cvec_push(glb* g,vec v, gint e);
87 |
88 | gptr wr_alloc_from_cvec(glb* g, cvec buf, gint gints);
89 |
90 | char* wr_str_new(glb* g, int len);
91 | void wr_str_guarantee_space(glb* g, char** stradr, int* strlenadr, int needed);
92 | void wr_str_free(glb* g, char* str);
93 | void wr_str_freeref(glb* g, char** strref);
94 |
95 |
96 | #endif
97 |
--------------------------------------------------------------------------------
/Reasoner/printerrutils.c:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Tanel Tammet 2004,2005,2006,2007,2008,2009,2010
6 | *
7 | * Contact: tanel.tammet@gmail.com
8 | *
9 | * This file is part of WhiteDB
10 | *
11 | * WhiteDB is free software: you can redistribute it and/or modify
12 | * it under the terms of the GNU General Public License as published by
13 | * the Free Software Foundation, either version 3 of the License, or
14 | * (at your option) any later version.
15 | *
16 | * WhiteDB is distributed in the hope that it will be useful,
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | * GNU General Public License for more details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with WhiteDB. If not, see .
23 | *
24 | */
25 |
26 | /** @file printerrutils.c
27 | * printing and err handling utils.
28 | *
29 | */
30 |
31 |
32 |
33 | /* ====== Includes =============== */
34 |
35 |
36 | #include
37 | #include
38 | #include
39 |
40 | #ifdef __cplusplus
41 | extern "C" {
42 | #endif
43 |
44 | #include "rincludes.h"
45 |
46 | /* ====== Private headers and defs ======== */
47 |
48 |
49 |
50 | /* ======= Private protos ================ */
51 |
52 |
53 | /* ====== Functions ============== */
54 |
55 |
56 | /* =========== debug printing ========================= */
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 | /* ======================= errors ================================= */
65 |
66 | /** Allocation error not requiring immediate exit.
67 | *
68 | */
69 |
70 | void* wr_alloc_err(glb* g, char* errstr) {
71 | if (g->print_flag) printf("Cannot allocate memory: %s.\n",errstr);
72 | return NULL;
73 | }
74 |
75 |
76 | /** Allocation error not requiring immediate exit.
77 | *
78 | */
79 |
80 | void* wr_alloc_err2(glb* g, char* errstr1, char* errstr2) {
81 | if (g->print_flag) printf("Cannot allocate memory: %s %s.\n",errstr1,errstr2);
82 | return NULL;
83 | }
84 |
85 |
86 | /** Allocation error not requiring immediate exit.
87 | *
88 | */
89 |
90 | void* wr_alloc_err2int(glb* g, char* errstr, int n) {
91 | if (g->print_flag) printf("Cannot allocate memory: %s %d.\n",errstr,n);
92 | return NULL;
93 | }
94 |
95 | /** Hard system error requiring immediate exit.
96 | *
97 | */
98 |
99 | void wr_sys_exiterr(glb* g, char* errstr) {
100 | printf("System error in wgdb reasoner, exiting: %s.\n",errstr);
101 | exit(1);
102 | }
103 |
104 |
105 | /** Hard system error requiring immediate exit.
106 | *
107 | */
108 |
109 | void wr_sys_exiterr2(glb* g, char* errstr1, char* errstr2) {
110 | printf("System error in wgdb reasoner, exiting: %s %s.\n",errstr1,errstr2);
111 | exit(1);
112 | }
113 |
114 |
115 | /** Hard system error requiring immediate exit.
116 | *
117 | */
118 |
119 | void wr_sys_exiterr2int(glb* g, char* errstr, int n) {
120 | printf("System error in wgdb reasoner, exiting: %s %d.\n",errstr,n);
121 | exit(1);
122 | }
123 |
124 |
125 |
126 | #ifdef __cplusplus
127 | }
128 | #endif
129 |
--------------------------------------------------------------------------------
/Reasoner/printerrutils.h:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Tanel Tammet 2004,2005,2006,2007,2008,2009,2010
6 | *
7 | * Contact: tanel.tammet@gmail.com
8 | *
9 | * This file is part of WhiteDB
10 | *
11 | * WhiteDB is free software: you can redistribute it and/or modify
12 | * it under the terms of the GNU General Public License as published by
13 | * the Free Software Foundation, either version 3 of the License, or
14 | * (at your option) any later version.
15 | *
16 | * WhiteDB is distributed in the hope that it will be useful,
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | * GNU General Public License for more details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with WhiteDB. If not, see .
23 | *
24 | */
25 |
26 | /** @file printerrutils.h
27 | * Headers for printing and err handling utils.
28 | *
29 | */
30 |
31 |
32 | #ifndef DEFINED_PRINTERRUTILS_H
33 | #define DEFINED_PRINTERRUTILS_H
34 |
35 | /* ==== Includes ==== */
36 |
37 |
38 | /* ==== Global defines ==== */
39 |
40 | #ifdef DPRINTF
41 | #define dprintf(fmt, ...) printf(fmt, ##__VA_ARGS__)
42 | #else
43 | #define dprintf(fmt,...) ;
44 | #endif
45 |
46 | /* ==== Protos ==== */
47 |
48 |
49 | void* wr_alloc_err(glb* g, char* errstr);
50 | void* wr_alloc_err2(glb* g, char* errstr1, char* errstr2);
51 | void* wr_alloc_err2int(glb* g, char* errstr, int n);
52 | void wr_sys_exiterr(glb* g, char* errstr);
53 | void wr_sys_exiterr2(glb* g, char* errstr1, char* errstr2);
54 | void wr_sys_exiterr2int(glb* g, char* errstr, int n);
55 |
56 |
57 | #endif
58 |
--------------------------------------------------------------------------------
/Reasoner/rgenloop.h:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Tanel Tammet 2004,2005,2006,2007,2008,2009,2010
6 | *
7 | * Contact: tanel.tammet@gmail.com
8 | *
9 | * This file is part of WhiteDB
10 | *
11 | * WhiteDB is free software: you can redistribute it and/or modify
12 | * it under the terms of the GNU General Public License as published by
13 | * the Free Software Foundation, either version 3 of the License, or
14 | * (at your option) any later version.
15 | *
16 | * WhiteDB is distributed in the hope that it will be useful,
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | * GNU General Public License for more details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with WhiteDB. If not, see .
23 | *
24 | */
25 |
26 | /** @file rgenloop.h
27 | * Procedures for reasoner top level search loops: given-clause, usable, sos etc.
28 | *
29 | */
30 |
31 | #ifndef DEFINED_RGENLOOP_H
32 | #define DEFINED_RGENLOOP_H
33 |
34 | #include "types.h"
35 | #include "glb.h"
36 |
37 | int wr_genloop(glb* g);
38 | gptr wr_pick_given_cl(glb* g, int* given_kept_flag);
39 | gptr wr_activate_passive_cl(glb* g, gptr picked_given_cl_cand);
40 | gptr wr_add_given_cl_active_list(glb* g, gptr given_cl);
41 | gptr wr_process_given_cl(glb* g, gptr given_cl_cand);
42 | void wr_resolve_binary_all_active(glb* g, gptr cl);
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/Reasoner/rincludes.h:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Tanel Tammet 2004,2005,2006,2007,2008,2009,2010
6 | *
7 | * Contact: tanel.tammet@gmail.com
8 | *
9 | * This file is part of WhiteDB
10 | *
11 | * WhiteDB is free software: you can redistribute it and/or modify
12 | * it under the terms of the GNU General Public License as published by
13 | * the Free Software Foundation, either version 3 of the License, or
14 | * (at your option) any later version.
15 | *
16 | * WhiteDB is distributed in the hope that it will be useful,
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | * GNU General Public License for more details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with WhiteDB. If not, see .
23 | *
24 | */
25 |
26 | /** @file rincludes.h
27 | * standard includes for reasoner c files
28 | */
29 |
30 |
31 | #ifndef DEFINED_RINCLUDES_H
32 | #define DEFINED_RINCLUDES_H
33 |
34 | /* ==== Includes ==== */
35 |
36 | #include
37 | #include
38 | #include
39 |
40 | #ifdef _WIN32
41 | #include "../config-w32.h"
42 | #else
43 | #include "../config.h"
44 | #endif
45 |
46 | #include "mem.h"
47 | #include "glb.h"
48 | #include "clterm.h"
49 | #include "unify.h"
50 | #include "build.h"
51 | #include "clstore.h"
52 | #include "subsume.h"
53 | #include "derive.h"
54 | #include "rgenloop.h"
55 | #include "rmain.h"
56 | #include "printerrutils.h"
57 | #include "../Db/dbutil.h"
58 | #include "../Printer/dbotterprint.h"
59 |
60 | /* ==== Global defines ==== */
61 |
62 | #define CP0 printf("CP0\n");
63 | #define CP1 printf("CP1\n");
64 | #define CP2 printf("CP2\n");
65 | #define CP3 printf("CP3\n");
66 | #define CP4 printf("CP4\n");
67 | #define CP5 printf("CP5\n");
68 | #define CP6 printf("CP6\n");
69 | #define CP7 printf("CP7\n");
70 | #define CP8 printf("CP8\n");
71 | #define CP9 printf("CP9\n");
72 |
73 | #define PRINT_LIMITS
74 |
75 | /* ==== Protos ==== */
76 |
77 | #endif
78 |
--------------------------------------------------------------------------------
/Reasoner/rmain.h:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Tanel Tammet 2004,2005,2006,2007,2008,2009,2010
6 | *
7 | * Contact: tanel.tammet@gmail.com
8 | *
9 | * This file is part of WhiteDB
10 | *
11 | * WhiteDB is free software: you can redistribute it and/or modify
12 | * it under the terms of the GNU General Public License as published by
13 | * the Free Software Foundation, either version 3 of the License, or
14 | * (at your option) any later version.
15 | *
16 | * WhiteDB is distributed in the hope that it will be useful,
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | * GNU General Public License for more details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with WhiteDB. If not, see .
23 | *
24 | */
25 |
26 |
27 | /** @file rmain.h
28 | * Reasoner top level: initialisation and startup.
29 | *
30 | */
31 |
32 |
33 | #ifndef DEFINED_RMAIN_H
34 | #define DEFINED_RMAIN_H
35 |
36 |
37 | #include "glb.h"
38 |
39 | int wg_run_reasoner(void *db, int argc, char **argv);
40 | int wg_import_otter_file(void *db, char* filename);
41 | int wg_import_prolog_file(void *db, char* filename);
42 | glb* wg_init_reasoner(void *db, int argc, char **argv);
43 | int wr_init_active_passive_lists_std(glb* g);
44 | void wr_show_stats(glb* g);
45 |
46 |
47 | #endif
48 |
--------------------------------------------------------------------------------
/Reasoner/subsume.h:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Tanel Tammet 2004,2005,2006,2007,2008,2009,2010
6 | *
7 | * Contact: tanel.tammet@gmail.com
8 | *
9 | * This file is part of WhiteDB
10 | *
11 | * WhiteDB is free software: you can redistribute it and/or modify
12 | * it under the terms of the GNU General Public License as published by
13 | * the Free Software Foundation, either version 3 of the License, or
14 | * (at your option) any later version.
15 | *
16 | * WhiteDB is distributed in the hope that it will be useful,
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | * GNU General Public License for more details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with WhiteDB. If not, see .
23 | *
24 | */
25 |
26 | /** @file subsume.h
27 | * Public headers for subsumption functions.
28 | *
29 | */
30 |
31 |
32 |
33 | #ifndef DEFINED_SUBSUME_H
34 | #define DEFINED_SUBSUME_H
35 |
36 | #include "glb.h"
37 |
38 | int wr_given_cl_subsumed(glb* g, gptr given_cl);
39 |
40 | gint wr_subsume_cl(glb* g, gptr cl1, gptr cl2, int uniquestrflag);
41 | gint wr_subsume_cl_aux(glb* g,gptr cl1vec, gptr cl2vec,
42 | gptr litpt1, gptr litpt2,
43 | int litind1, int litind2,
44 | int cllen1, int cllen2,
45 | int uniquestrflag);
46 |
47 | #endif
48 |
--------------------------------------------------------------------------------
/Reasoner/types.h:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Tanel Tammet 2004,2005,2006,2007,2008,2009,2010
6 | *
7 | * Contact: tanel.tammet@gmail.com
8 | *
9 | * This file is part of WhiteDB
10 | *
11 | * WhiteDB is free software: you can redistribute it and/or modify
12 | * it under the terms of the GNU General Public License as published by
13 | * the Free Software Foundation, either version 3 of the License, or
14 | * (at your option) any later version.
15 | *
16 | * WhiteDB is distributed in the hope that it will be useful,
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | * GNU General Public License for more details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with WhiteDB. If not, see .
23 | *
24 | */
25 |
26 |
27 | /** @file types.h
28 | * Various datatypes.
29 | *
30 | */
31 |
32 |
33 | #ifndef DEFINED_DATATYPES_H
34 | #define DEFINED_DATATYPES_H
35 |
36 |
37 | #ifdef _WIN32
38 | #include "../config-w32.h"
39 | #else
40 | #include "../config.h"
41 | #endif
42 | #include "../Db/dballoc.h"
43 | #include "../Db/dbdata.h"
44 |
45 |
46 | typedef gint* gptr;
47 | typedef gint* vec; /**< array with length: 0 contains len of array*/
48 | typedef gint* cvec; /**< array with length and freepos: 0 len of array, 1 first free pos */
49 |
50 | typedef gint veco; /**< offset of vec */
51 | typedef gint cveco; /**< offset of cvec */
52 |
53 |
54 |
55 | #endif
56 |
--------------------------------------------------------------------------------
/Reasoner/unify.h:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Tanel Tammet 2004,2005,2006,2007,2008,2009,2010
6 | *
7 | * Contact: tanel.tammet@gmail.com
8 | *
9 | * This file is part of WhiteDB
10 | *
11 | * WhiteDB is free software: you can redistribute it and/or modify
12 | * it under the terms of the GNU General Public License as published by
13 | * the Free Software Foundation, either version 3 of the License, or
14 | * (at your option) any later version.
15 | *
16 | * WhiteDB is distributed in the hope that it will be useful,
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | * GNU General Public License for more details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with WhiteDB. If not, see .
23 | *
24 | */
25 |
26 | /** @file unify.h
27 | * Unification functions.
28 | *
29 | */
30 |
31 |
32 |
33 | #ifndef DEFINED_UNIFY_H
34 | #define DEFINED_UNIFY_H
35 |
36 | #include "glb.h"
37 |
38 | #define UNASSIGNED WG_ILLEGAL // 0xff in dbata.h
39 |
40 | #define VARVAL(x,vb) (wr_varval(x,vb))
41 | #define VARVAL_F(x,vb) (tmp=vb[decode_var(x)], ((tmp==UNASSIGNED) ? x : (!isvar(tmp) ? tmp : wr_varval(tmp,vb))))
42 | #define VARVAL_DIRECT(x,vb) (vb[decode_var(x)])
43 | #define SETVAR(x,y,vb,vstk,vc) (vb[decode_var(x)]=y,vstk[*vc]=(gint)((gptr)vb+decode_var(x)),++(*vc))
44 |
45 | // WR_EQUAL_TERM is a faster version of the wr_equal_term function, doing exactly the same thing
46 | // NB! gint eqenc unused variable must be present to call the following macro, as well as valued uniquestrflag
47 |
48 | #define WR_EQUAL_TERM(g,x,y,uniquestrflag) \
49 | (((x)==(y)) ? 1 : \
50 | (eqencx=(x)&NORMALPTRMASK,\
51 | (((eqencx==LONGSTRBITS && uniquestrflag) || eqencx==SMALLINTBITS || eqencx==NORMALPTRMASK) ? 0 : \
52 | ((!isptr(x) || !isptr(y)) ? 0 : \
53 | ((((x)&NONPTRBITS)!=((y)&NONPTRBITS)) ? 0 : wr_equal_term_macroaux((g),(x),(y),(uniquestrflag)) )))))
54 |
55 |
56 | gint wr_unify_term(glb* g, gint x, gint y, int uniquestrflag);
57 | gint wr_unify_term_aux(glb* g, gint x, gint y, int uniquestrflag);
58 |
59 | gint wr_match_term_aux(glb* g, gint x, gint y, int uniquestrflag);
60 | gint wr_match_term(glb* g, gint x, gint y, int uniquestrflag);
61 |
62 | gint wr_equal_term(glb* g, gint x, gint y, int uniquestrflag);
63 | gint wr_equal_term_macroaux(glb* g, gint x, gint y, int uniquestrflag);
64 | int wr_equal_ptr_primitives(glb* g, gint a, gint b, int uniquestrflag);
65 |
66 | gint wr_varval(gint x, gptr vb);
67 | void wr_setvar(gint x, gint y, gptr vb, gptr vstk, gint* vc);
68 |
69 | void wr_clear_varstack(glb* g,vec vs);
70 | void wr_clear_varstack_topslice(glb* g, vec vs, int y);
71 | void wr_clear_all_varbanks(glb* g);
72 |
73 | void wr_print_vardata(glb* g);
74 | void wr_print_varbank(glb* g, gptr vb);
75 | void wr_print_varstack(glb* g, gptr vs);
76 | int wr_varbanks_are_clear(glb* g, gptr vb);
77 |
78 | #endif
79 |
--------------------------------------------------------------------------------
/Rexamples/luka.txt:
--------------------------------------------------------------------------------
1 |
2 | %list(usable).
3 | -P(i(?x,?y)) | -P(?x) | P(?y).
4 | %end_of_list.
5 |
6 | %list(sos).
7 | P(i(i(?x,?y),i(i(?y,?z),i(?x,?z)))). % CN1
8 | P(i(n(?x),i(?x,?x))). % CN2
9 | P(i(?x,i(n(?x),?y))). % CN3
10 | %end_of_list.
11 |
12 | %list(passive).
13 | %-P(i(a,a)). % | $Ans(CN_16).
14 | %-P(i(b,i(a,b))). % | $Ans(CN_18).
15 | -P(i(i(i(a,b),c),i(b,c))).% | $Ans(CN_19).
16 | %end_of_list.
17 |
--------------------------------------------------------------------------------
/Rexamples/luka2.txt:
--------------------------------------------------------------------------------
1 | -p(i(?X,?Y))
2 | | -p(?X)
3 | | p(?Y).
4 |
5 | p(i(i(?X,?Y),i(i(?Y,?Z),i(?X,?Z)))).
6 | p(i(i(n(?X),?X),?X)).
7 | p(i(?X,i(n(?X),?Y))).
8 |
9 | %-p(i(a,a)).
10 | -p(i(a,i(b,a))).
11 |
12 |
13 | /*
14 |
15 | -blocker(a).
16 | eats(a_caterpillar,caterpillar_food_of(a_caterpillar)) | blocker(a).
17 |
18 | %important(?Small_animal) | -eats(?Small_animal,?Other_plant).
19 | %-important(?Small_animal) | -eats(?Small_animal,?Other_plant).
20 |
21 | -eats(?Grain_eater,?Foo) |
22 | -animal(?Animal)| -animal(?Grain_eater)| -grain(?Grain)|
23 | -eats(?Animal,?Grain_eater)| -eats(?Grain_eater,?Grain).
24 |
25 | */
26 | /*
27 |
28 | animal(?X)| -wolf(?X).
29 | animal(?X)| -fox(?X).
30 | animal(?X)| -bird(?X).
31 | animal(?X)| -caterpillar(?X).
32 | animal(?X)| -snail(?X).
33 |
34 | wolf(a_wolf).
35 | fox(a_fox).
36 | bird(a_bird).
37 | caterpillar(a_caterpillar).
38 | snail(a_snail).
39 | grain(a_grain).
40 | plant(?X)| -grain(?X).
41 |
42 | eats(?Animal,?Plant)|eats(?Animal,?Small_animal)|
43 | -animal(?Animal)| -plant(?Plant)| -animal(?Small_animal)|
44 | -plant(?Other_plant)| -much_smaller(?Small_animal,?Animal)|
45 | -eats(?Small_animal,?Other_plant).
46 |
47 | much_smaller(?Catapillar,?Bird)| -caterpillar(?Catapillar)| -bird(?Bird).
48 | much_smaller(?Snail,?Bird)| -snail(?Snail)| -bird(?Bird).
49 | much_smaller(?Bird,?Fox)| -bird(?Bird)| -fox(?Fox).
50 | much_smaller(?Fox,?Wolf)| -fox(?Fox)| -wolf(?Wolf).
51 |
52 | -wolf(?Wolf)| -fox(?Fox)| -eats(?Wolf,?Fox).
53 | -wolf(?Wolf)| -grain(?Grain)| -eats(?Wolf,?Grain).
54 | eats(?Bird,?Catapillar)| -bird(?Bird)| -caterpillar(?Catapillar).
55 | -bird(?Bird)| -snail(?Snail)| -eats(?Bird,?Snail).
56 | plant(caterpillar_food_of(?Catapillar))| -caterpillar(?Catapillar).
57 | eats(?Catapillar,caterpillar_food_of(?Catapillar))| -caterpillar(?Catapillar).
58 | plant(snail_food_of(?Snail))| -snail(?Snail).
59 | eats(?Snail,snail_food_of(?Snail))| -snail(?Snail).
60 |
61 | -animal(?Animal)| -animal(?Grain_eater)| -grain(?Grain)|
62 | -eats(?Animal,?Grain_eater)| -eats(?Grain_eater,?Grain).
63 |
64 | */
65 |
--------------------------------------------------------------------------------
/Rexamples/otter.txt:
--------------------------------------------------------------------------------
1 | /*
2 | animal(?X)| -wolf(?X).
3 | animal(?X)| -fox(?X).
4 | animal(?X)| -bird(?X).
5 | animal(?X)| -caterpillar(?X).
6 | animal(?X)| -snail(?X).
7 |
8 | wolf(a_wolf).
9 | fox(a_fox).
10 | bird(a_bird).
11 | caterpillar(a_caterpillar).
12 | snail(a_snail).
13 | grain(a_grain).
14 | plant(?X)| -grain(?X).
15 |
16 | eats(?Animal,?Plant)|eats(?Animal,?Small_animal)|
17 | -animal(?Animal)| -plant(?Plant)| -animal(?Small_animal)|
18 | -plant(?Other_plant)| -much_smaller(?Small_animal,?Animal)|
19 | -eats(?Small_animal,?Other_plant).
20 |
21 | much_smaller(?Catapillar,?Bird)| -caterpillar(?Catapillar)| -bird(?Bird).
22 | much_smaller(?Snail,?Bird)| -snail(?Snail)| -bird(?Bird).
23 | much_smaller(?Bird,?Fox)| -bird(?Bird)| -fox(?Fox).
24 | much_smaller(?Fox,?Wolf)| -fox(?Fox)| -wolf(?Wolf).
25 |
26 | -wolf(?Wolf)| -fox(?Fox)| -eats(?Wolf,?Fox).
27 | -wolf(?Wolf)| -grain(?Grain)| -eats(?Wolf,?Grain).
28 | eats(?Bird,?Catapillar)| -bird(?Bird)| -caterpillar(?Catapillar).
29 | -bird(?Bird)| -snail(?Snail)| -eats(?Bird,?Snail).
30 | plant(caterpillar_food_of(?Catapillar))| -caterpillar(?Catapillar).
31 | eats(?Catapillar,caterpillar_food_of(?Catapillar))| -caterpillar(?Catapillar).
32 | plant(snail_food_of(?Snail))| -snail(?Snail).
33 | eats(?Snail,snail_food_of(?Snail))| -snail(?Snail).
34 |
35 | -animal(?Animal)| -animal(?Grain_eater)| -grain(?Grain)|
36 | -eats(?Animal,?Grain_eater)| -eats(?Grain_eater,?Grain).
37 |
38 | */
39 |
40 |
41 |
42 | -m(f(?X)) | -p(f(?X)) | -r(f(?X)) | s(?X).
43 |
44 | p(f(a)).
45 | r(f(a)).
46 | m(f(a)).
47 |
48 | -t(f(?X)) | -s(?X).
49 |
50 | t(f(a)).
51 |
52 |
53 |
54 | /*
55 | -p(i(?X,?Y))
56 | | -p(?X)
57 | | p(?Y).
58 |
59 | p(i(i(?X,?Y),i(i(?Y,?Z),i(?X,?Z)))).
60 | p(i(i(n(?X),?X),?X)).
61 | p(i(?X,i(n(?X),?Y))).
62 |
63 | -p(i(a,a)).
64 | %-p(i(a,i(b,a))).
65 |
66 | %-p(i(?2000,i(?2001,?2002))) | p(i(i(i(i(?2002,?2003),i(?2001,?2003)),?2004),i(?2000,?2004))).
67 | % p(i(i(?1000,?1001),i(i(n(i(n(?1000),?1000)),i(n(?1000),?1000)),?1001))).
68 |
69 |
70 | %p(i(?X,i(n(?X),?Y))).
71 | %-p(i(a,i(b,a)))
72 |
73 | */
74 |
75 |
76 | /*
77 |
78 | animal(?X)| -wolf(?X).
79 | animal(?X)| -fox(?X).
80 | animal(?X)| -bird(?X).
81 | animal(?X)| -caterpillar(?X).
82 | animal(?X)| -snail(?X).
83 |
84 | wolf(a_wolf).
85 | fox(a_fox).
86 | bird(a_bird).
87 | caterpillar(a_caterpillar).
88 | snail(a_snail).
89 | grain(a_grain).
90 | plant(?X)| -grain(?X).
91 |
92 | eats(?Animal,?Plant)|eats(?Animal,?Small_animal)|
93 | -animal(?Animal)| -plant(?Plant)| -animal(?Small_animal)|
94 | -plant(?Other_plant)| -much_smaller(?Small_animal,?Animal)|
95 | -eats(?Small_animal,?Other_plant).
96 |
97 | much_smaller(?Catapillar,?Bird)| -caterpillar(?Catapillar)| -bird(?Bird).
98 | much_smaller(?Snail,?Bird)| -snail(?Snail)| -bird(?Bird).
99 | much_smaller(?Bird,?Fox)| -bird(?Bird)| -fox(?Fox).
100 | much_smaller(?Fox,?Wolf)| -fox(?Fox)| -wolf(?Wolf).
101 |
102 | -wolf(?Wolf)| -fox(?Fox)| -eats(?Wolf,?Fox).
103 | -wolf(?Wolf)| -grain(?Grain)| -eats(?Wolf,?Grain).
104 | eats(?Bird,?Catapillar)| -bird(?Bird)| -caterpillar(?Catapillar).
105 | -bird(?Bird)| -snail(?Snail)| -eats(?Bird,?Snail).
106 | plant(caterpillar_food_of(?Catapillar))| -caterpillar(?Catapillar).
107 | eats(?Catapillar,caterpillar_food_of(?Catapillar))| -caterpillar(?Catapillar).
108 | plant(snail_food_of(?Snail))| -snail(?Snail).
109 | eats(?Snail,snail_food_of(?Snail))| -snail(?Snail).
110 |
111 | -animal(?Animal)| -animal(?Grain_eater)| -grain(?Grain)|
112 | -eats(?Animal,?Grain_eater)| -eats(?Grain_eater,?Grain).
113 |
114 |
115 | */
116 |
117 |
--------------------------------------------------------------------------------
/Rexamples/otter1.txt:
--------------------------------------------------------------------------------
1 | p(1).
2 |
3 | - p(?X) | r(?X).
4 |
5 | -r(1).
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Rexamples/otter2.txt:
--------------------------------------------------------------------------------
1 | - p(1,?X).
2 |
3 |
4 | m(a,b) | s(t).
5 |
6 | kk(f(aa),b12).
7 |
--------------------------------------------------------------------------------
/Rexamples/otter4.txt:
--------------------------------------------------------------------------------
1 | # p(1,1).
2 |
3 | # p(?X,?X).
4 |
5 | # p(2,f(2)).
6 |
7 | -p(?X,?Y) | p(3,3).
8 |
9 | #-r(1).
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Rexamples/otter5.txt:
--------------------------------------------------------------------------------
1 |
2 |
3 | -p(?X) | -p(f(?X)).
4 | p(f(?X)) | p(?X).
5 | -p(?X) | p(f(?X)).
6 |
7 |
--------------------------------------------------------------------------------
/Rexamples/otter7.txt:
--------------------------------------------------------------------------------
1 |
2 | p(2).
3 | r(2.0).
4 | -p(?X) | -r(?Y) | m(+(?X,?Y)).
5 | -m(4.0).
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Rexamples/otter_parse_test.txt:
--------------------------------------------------------------------------------
1 |
2 |
3 | p(X,f(b)) | -r(X) | -m(X).
4 | p(a,f(b)).
5 | -s(a,2,"2").
6 |
7 | % ((("p" "X" ("f" "b")) ("not" ("r" "X")) ("not" ("m" "X"))) (("p" "a" ("f" "b"))) (("not" ("s" "a" 2 "2"))) )
8 |
--------------------------------------------------------------------------------
/Rexamples/p1.otter:
--------------------------------------------------------------------------------
1 |
2 | r(a).
3 | m(b).
4 |
5 | %-r(a) | -m(b).
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Rexamples/rrun:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | ../Main/wgdb free
4 | ../Main/wgdb importotter $1
5 | ../Main/wgdb runreasoner
6 |
7 |
--------------------------------------------------------------------------------
/Rexamples/rules.txt:
--------------------------------------------------------------------------------
1 | %aasas
2 | k(a).
3 | r(X) :- k(X).
4 | -r(a).
5 |
6 | %m(X,Y) :- m(Y,X).
7 | %m(Y,X) :- r(X,Y).
8 |
9 | r(X,Y) :- b(X,Y,a), b(Y,X,c).
10 |
11 | % #command(me,keepaway) :- #attachedTo(X,fragile).
12 | % #attachedTo(X,fragile) :- #attachedTo(X,glass).
13 |
14 | % ----------
15 |
16 | %playsound(me,"0") :- velocity(me,X).
17 | %#command(me,clean) :- "found-tag"(me,tag1).
18 | %#command(me,clean) :- #attachedTo(X,fragile).
19 |
20 | % ---------------
21 |
--------------------------------------------------------------------------------
/Rexamples/steam.txt:
--------------------------------------------------------------------------------
1 |
2 |
3 | animal(?X)| -wolf(?X).
4 | animal(?X)| -fox(?X).
5 | animal(?X)| -bird(?X).
6 | animal(?X)| -caterpillar(?X).
7 | animal(?X)| -snail(?X).
8 |
9 | wolf(a_wolf).
10 | fox(a_fox).
11 | bird(a_bird).
12 | caterpillar(a_caterpillar).
13 | snail(a_snail).
14 | grain(a_grain).
15 | plant(?X)| -grain(?X).
16 |
17 | eats(?Animal,?Plant)|eats(?Animal,?Small_animal)|
18 | -animal(?Animal)| -plant(?Plant)| -animal(?Small_animal)|
19 | -plant(?Other_plant)| -much_smaller(?Small_animal,?Animal)|
20 | -eats(?Small_animal,?Other_plant).
21 |
22 | much_smaller(?Catapillar,?Bird)| -caterpillar(?Catapillar)| -bird(?Bird).
23 | much_smaller(?Snail,?Bird)| -snail(?Snail)| -bird(?Bird).
24 | much_smaller(?Bird,?Fox)| -bird(?Bird)| -fox(?Fox).
25 | much_smaller(?Fox,?Wolf)| -fox(?Fox)| -wolf(?Wolf).
26 |
27 | -wolf(?Wolf)| -fox(?Fox)| -eats(?Wolf,?Fox).
28 | -wolf(?Wolf)| -grain(?Grain)| -eats(?Wolf,?Grain).
29 | eats(?Bird,?Catapillar)| -bird(?Bird)| -caterpillar(?Catapillar).
30 | -bird(?Bird)| -snail(?Snail)| -eats(?Bird,?Snail).
31 | plant(caterpillar_food_of(?Catapillar))| -caterpillar(?Catapillar).
32 | eats(?Catapillar,caterpillar_food_of(?Catapillar))| -caterpillar(?Catapillar).
33 | plant(snail_food_of(?Snail))| -snail(?Snail).
34 | eats(?Snail,snail_food_of(?Snail))| -snail(?Snail).
35 |
36 | -animal(?Animal)| -animal(?Grain_eater)| -grain(?Grain)|
37 | -eats(?Animal,?Grain_eater)| -eats(?Grain_eater,?Grain).
38 |
--------------------------------------------------------------------------------
/Rexamples/viga.txt:
--------------------------------------------------------------------------------
1 |
2 | m(a).
3 |
4 | p(((
5 |
6 | k.
7 |
8 |
--------------------------------------------------------------------------------
/Server/Makefile:
--------------------------------------------------------------------------------
1 | # Makefile for building dserve, dservehttps and nsmeasure
2 | #
3 | # dserve: database http tool as a standalone http server or cgi
4 | # dservehttps: database https tool as a standalone https server or cgi
5 | # nsmeasure: utility for speed testing the server over http
6 | #
7 | # This makefile assumes you have built and installed the whitedb library.
8 | #
9 | # Alternatively compile directly against the whitedb library as:
10 | #
11 | # gcc dserve.c dserve_util.c dserve_net.c -o dserve -O2 -lwgdb -lpthread
12 | # gcc -DUSE_OPENSSL dserve.c dserve_util.c dserve_net.c -o dservehttps -O2 -lwgdb -lpthread -lssl -lcrypto
13 | # gcc nsmeasure.c -o nsmeasure -O2 -lpthread
14 | #
15 | # or use compile.sh directly against the whitedb source without building a library first.
16 | #
17 | # dserve can be also compiled to work as a cgi or command line tool only
18 | # without using pthreads by:
19 | # - removing #define SERVEROPTION from dserve.h
20 | # - compiling by gcc dserve.c dserve_util.c -o dserve -O2 -lwgdb
21 | #
22 | # Compiling under windows:
23 | # copy the files dbapi.h and wgdb.lib into the same folder where you compile, then build
24 | # server version:
25 | # cl /Ox /I"." Server\dserve.c Server\dserve_util.c Server\dserve_net.c wgdb.lib
26 | # cl /Ox /I"." Server\dserve.c Server\dserve_util.c wgdb.lib
27 | # or a non-server version
28 |
29 |
30 |
31 | CFLAGS = -O2 -c
32 | CFLAGSHTTPS = -O2 -DUSE_OPENSSL -Wall -c
33 | CC = gcc
34 |
35 | all: dserve dservehttps nsmeasure
36 |
37 | dserve: dserve.o dserve_util.o dserve_net.o yajl_all.o
38 | $(CC) dserve.o dserve_net.o dserve_util.o yajl_all.o -o dserve -lpthread -lwgdb
39 |
40 | dservehttps: dservehttps.o dserve_utilhttps.o dserve_nethttps.o yajl_all.o
41 | $(CC) dservehttps.o dserve_nethttps.o dserve_utilhttps.o yajl_all.o -o dservehttps -lpthread -lwgdb -lssl -lcrypto
42 |
43 | nsmeasure: nsmeasure.o
44 | $(CC) nsmeasure.o -o nsmeasure -lpthread
45 |
46 | dserve.o: dserve.h dserve.c
47 | $(CC) $(CFLAGS) dserve.c
48 |
49 | dservehttps.o: dserve.h dserve.c
50 | $(CC) $(CFLAGSHTTPS) dserve.c -o dservehttps.o
51 |
52 | dserve_net.o: dserve.h dserve_net.c
53 | $(CC) $(CFLAGS) dserve_net.c
54 |
55 | dserve_nethttps.o: dserve.h dserve_net.c
56 | $(CC) $(CFLAGSHTTPS) dserve_net.c -o dserve_nethttps.o
57 |
58 | dserve_util.o: dserve.h dserve_util.c
59 | $(CC) $(CFLAGS) dserve_util.c
60 |
61 | dserve_utilhttps.o: dserve.h dserve_util.c
62 | $(CC) $(CFLAGSHTTPS) dserve_util.c -o dserve_utilhttps.o
63 |
64 | yajl_all.o: ../json/yajl_all.h ../json/yajl_all.c
65 | $(CC) $(CFLAGS) ../json/yajl_all.c -o yajl_all.o
66 |
67 | nsmeasure.o: nsmeasure.c
68 | $(CC) $(CFLAGS) nsmeasure.c
69 |
70 | clean: nsmeasure.c
71 | rm *.o *dserve dservehttps nsmeasure *.gch
72 |
73 |
--------------------------------------------------------------------------------
/Server/Manifest:
--------------------------------------------------------------------------------
1 | Manifest:
2 |
3 | - dserve.h: header for dserve.c, dserve_net.c, dserve_util.c
4 | - dserve.c: main file for dserve/dservehttps
5 | - dserve_net.c: networking, only needed for running as a server
6 | - dserve_util.c: printing, error handling and text utilities
7 |
8 | - nsmeasure.c: server speed measurement tool
9 |
10 | - Makefile: compile dserve, dservehttps, nsmeasure against compiled whitedb
11 | - compile.sh: compile dserve, dservehttps, nsmeasure without compiling whitedb
12 | - compile.bat: compile dserve, nsmeasure for Windows
13 |
14 | - conf_example.txt: example for an optional configuration file
15 |
16 | - example
--------------------------------------------------------------------------------
/Server/README:
--------------------------------------------------------------------------------
1 | dserve README
2 | ==============
3 |
4 | dserve is a tool for performing REST queries from WhiteDB using a cgi
5 | protocol over http. Results are given in the json or csv format.
6 |
7 | dservehttps is a version of dserve using https instead of http.
8 |
9 | nsmeasure is a tool for measuring server speed.
10 |
11 | For details see http://whitedb.org/server/
12 |
13 | Run dserver in one of three ways:
14 |
15 | * a cgi program under a web server, connecting like
16 | http://myhost.com/dserve?op=search&from=0&count=5
17 | * as a standalone http(s) server, passing a port number as a single argument, like
18 | dserve 8080
19 | and connecting like
20 | http://localhost:8080/dserve?op=search&from=0&count=5
21 | or, for dservehttps compiled with USE_OPENSSL
22 | dservehttps 8081 conf.txt
23 | https://localhost:8081/dserve?op=search&from=0&count=5
24 | * from the command line, passing a cgi-format, urlencoded query string
25 | as a single argument, like
26 | dserve 'op=search&from=0&count=5'
27 |
28 | Use the provided Makefile or compile.sh or compile.bat for compiling dserve.
29 |
30 | Use and modify the code for creating your own data servers for WhiteDB.
31 |
32 | Copyright (c) 2013, Tanel Tammet
33 |
34 | This software is under MIT licence:
35 | --------
36 | Permission is hereby granted, free of charge, to any person obtaining
37 | a copy of this software and associated documentation files (the "Software"),
38 | to deal in the Software without restriction, including without limitation
39 | the rights to use, copy, modify, merge, publish, distribute, sublicense,
40 | and/or sell copies of the Software, and to permit persons to whom the
41 | Software is furnished to do so, subject to the following conditions:
42 |
43 | The above copyright notice and this permission notice shall be included
44 | in all copies or substantial portions of the Software.
45 |
46 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
47 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
48 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
49 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
50 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
51 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
52 | OR OTHER DEALINGS IN THE SOFTWARE.
53 | ------
54 |
55 | NB! Observe that the dserve source is under a more permissive licence than
56 | the WhiteDB library: the latter is by default under GPLv3. Thus the
57 | linked dserve is under GPLv3 unless a free commercial licence is used
58 | (see whitedb.org for details).
59 |
60 | It is OK to use the MIT licence when using this code or parts of it in
61 | other projects without linking to the whitedb library.
62 |
63 |
--------------------------------------------------------------------------------
/Server/compile.bat:
--------------------------------------------------------------------------------
1 | @rem Windows compilation script for the dserve tool.
2 | @rem First compile whitedb in the parent folder, using compile.bat there!
3 |
4 | @rem copy two necessary files (created by compiling the parent) here
5 |
6 | copy ..\db\dbapi.h .
7 | copy ..\wgdb.lib .
8 | copy ..\wgdb.dll .
9 |
10 | @rem compile a server version of dserve
11 | @rem dserve.h must contain #define SERVEROPTION (does so by default) for this
12 |
13 | cl /Ox /I"." dserve.c dserve_util.c dserve_net.c wgdb.lib
14 |
15 | @rem or alternatively compile a non-server version of dserve
16 | @rem remove #define SERVEROPTION from dserve.h before using this alternative
17 | @rem cl /Ox /I"." dserve.c dserve_util.c wgdb.lib
--------------------------------------------------------------------------------
/Server/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # alternative to compiling dserve and dservehttps with automake/make:
4 | # just run it in the Server folder
5 |
6 | [ -z "$CC" ] && CC="cc"
7 |
8 | if [ -z "$(which $CC 2>/dev/null)" ]; then
9 | echo "Error: No compiler found"
10 | exit 1
11 | fi
12 |
13 | # copy config.h to the current folder
14 | [ -f config.h ] || cp ../config-gcc.h config.h
15 | if [ ../config-gcc.h -nt ../config.h ]; then
16 | echo "Warning: config.h is older than config-gcc.h, consider updating it"
17 | fi
18 |
19 | # run unite.sh if needed
20 | if [ ! -f ../whitedb.c ]; then
21 | cd ..; ./unite.sh; cd "$OLDPWD"
22 | fi
23 |
24 | # compile dserve
25 | $CC -O2 -Wall -I.. -o dserve dserve.c dserve_util.c dserve_net.c \
26 | ../whitedb.c -lm -lpthread
27 | # compile dservehttps
28 | $CC -O2 -Wall -I.. -DUSE_OPENSSL -o dservehttps dserve.c dserve_util.c dserve_net.c \
29 | ../whitedb.c -lm -lpthread -lssl -lcrypto
30 |
--------------------------------------------------------------------------------
/Server/conf.txt:
--------------------------------------------------------------------------------
1 | # Optional configuration file for dserve: use as
2 | # dserve
3 | #
4 | # The configuration file is required for dservehttps,
5 | # since key_file and cert_file must be given.
6 | #
7 | # Set multiple values by writing them to lines following
8 | # a def, one item per line, with a leading whitespace, like this:
9 | # admin_tokens=token1
10 | # token2
11 | # token3
12 | #
13 | # all ops creating and deleting databases are considered admin ops.
14 | # all ops adding, updating or deleting data are considered write ops.
15 | # ops not changing any databases are considered read ops.
16 |
17 | # -------------
18 | # Defaults and limits for creating new databases: all numeric.
19 | # default_dbase: a dbase name in case none given in request:
20 | # overrides the DEFAULT_DATABASE=1000 macro in dserve.h
21 | # default_dbase_size: default size if none given in request:
22 | # overrides the DEFAULT_DATABASE_SIZE=10000000 macro in dserve.h
23 | # set this to 0 to inhibit automatic database creation upon insert
24 | # max_dbase_size: limit for new database size:
25 | # overrides the MAX_DATABASE_SIZE=10000000000 macro in dserve.h
26 | # set this to 0 to inhibit any database creation
27 |
28 | default_dbase=1000
29 | default_dbase_size=1000000 #0
30 | max_dbase_size=100000000
31 |
32 | # -------------
33 | # Limit access to these databases only: no limit by default
34 |
35 | dbases=1000
36 | 1001
37 | 1003
38 |
39 | # -------------
40 | # Limit access from these IP addresses only: no limit by default.
41 | # Use 127.0.0.1 for localhost.
42 | # You can give a first part of the IP address like 127.0: this
43 | # will match all IP addresses with this prefix.
44 | # admin ips get also write and read permissions
45 | # write ips get also read permissions.
46 | # If you set a read or write ips, be sure to set
47 | # stronger ip as well (possibly to 127.0.0.1),
48 | # otherwise the requirement is not enforced.
49 | # If any of these is not defined, there are no ip limits
50 | # for this and weaker kinds of operations.
51 | # Multiple values are accepted.
52 |
53 | admin_ips=127.0.0.1
54 | write_ips=127.0.0.2
55 | read_ips=127.0.0.3
56 |
57 | # -------------
58 | # Access limiting tokens:
59 | # if tokens set, token=sometoken parameter required
60 | # with sometoken being in a set of tokens given here.
61 | # admin tokens give also write and read permissions
62 | # write tokens give also read permissions.
63 | # If you set a read or write token, be sure to set
64 | # stronger tokens as well (possibly to values not told
65 | # to anyone), otherwise the requirement is not enforced.
66 | # If any of these is not defined, there are no limits
67 | # for this and weaker kinds of operations.
68 | # Multiple values are accepted.
69 |
70 | #admin_tokens=ab
71 | #write_tokens=cd
72 | #read_tokens=ef
73 |
74 | # -------------
75 | # path to private key file for https: dservehttps only
76 | # example created by:
77 | # openssl req -x509 -nodes -days 365 -newkey rsa:2048
78 | # -keyout exampleprivatekey.key -out examplecertificate.crt
79 | # or from this by: openssl rsa -in exampleprivatekey.key -out exampleprivatekey.pem
80 |
81 | key_file=/home/tanel/whitedb/Server/exampleprivatekey.key
82 |
83 | # -------------
84 | # path to certificate key file for https: dservehttps only
85 | # example file created by the previous key/cert generation command
86 |
87 | cert_file=/home/tanel/whitedb/Server/examplecertificate.crt
88 |
89 |
--------------------------------------------------------------------------------
/Server/conf_example.txt:
--------------------------------------------------------------------------------
1 | # Optional configuration file for dserve: use as
2 | # dserve
3 | #
4 | # The configuration file is required for dservehttps,
5 | # since key_file and cert_file must be given.
6 | #
7 | # Set multiple values by writing them to lines following
8 | # a def, one item per line, with a leading whitespace, like this:
9 | # admin_tokens=token1
10 | # token2
11 | # token3
12 | #
13 | # all ops creating and deleting databases are considered admin ops.
14 | # all ops adding, updating or deleting data are considered write ops.
15 | # ops not changing any databases are considered read ops.
16 |
17 | # -------------
18 | # Defaults and limits for creating new databases: all numeric.
19 | # default_dbase: a dbase name in case none given in request:
20 | # overrides the DEFAULT_DATABASE=1000 macro in dserve.h
21 | # default_dbase_size: default size if none given in request:
22 | # overrides the DEFAULT_DATABASE_SIZE=10000000 macro in dserve.h
23 | # set this to 0 to inhibit automatic database creation upon insert
24 | # max_dbase_size: limit for new database size:
25 | # overrides the MAX_DATABASE_SIZE=10000000000 macro in dserve.h
26 | # set this to 0 to inhibit any database creation
27 |
28 | #default_dbase=1000
29 | #default_dbase_size=1000000
30 | #max_dbase_size=100000000
31 |
32 | # -------------
33 | # Limit access to these databases only: no limit by default
34 |
35 | #dbases=1000
36 | # 1001
37 | # 1002
38 |
39 | # -------------
40 | # Limit access from these IP addresses only: no limit by default.
41 | # Use 127.0.0.1 for localhost.
42 | # You can give a first part of the IP address like 127.0: this
43 | # will match all IP addresses with this prefix.
44 | # admin ips get also write and read permissions
45 | # write ips get also read permissions.
46 | # If you set a read or write ips, be sure to set
47 | # stronger ip as well (possibly to 127.0.0.1),
48 | # otherwise the requirement is not enforced.
49 | # If any of these is not defined, there are no ip limits
50 | # for this and weaker kinds of operations.
51 | # Multiple values are accepted.
52 |
53 | #admin_ips=127.0.0.1
54 | #write_ips=127.0.0.1
55 | #read_ips=127.0.0.1
56 |
57 | # -------------
58 | # Limit access by secret tokens: no limit by default.
59 | # If tokens set, token=sometoken parameter required
60 | # with sometoken being in a set of tokens given here.
61 | # admin tokens give also write and read permissions
62 | # write tokens give also read permissions.
63 | # If you set a read or write token, be sure to set
64 | # stronger tokens as well (possibly to values not told
65 | # to anyone), otherwise the requirement is not enforced.
66 | # If any of these is not defined, there are no limits
67 | # for this and weaker kinds of operations.
68 | # Multiple values are accepted.
69 |
70 | #admin_tokens=secret1
71 | #write_tokens=secret1
72 | #read_tokens=secret1
73 |
74 | # -------------
75 | # path to private key file for https: needed for dservehttps only
76 | # example created by:
77 | # openssl req -x509 -nodes -days 365 -newkey rsa:2048
78 | # -keyout exampleprivatekey.key -out examplecertificate.crt
79 | # or from this by: openssl rsa -in exampleprivatekey.key -out exampleprivatekey.pem
80 |
81 | #key_file=/home/tanel/whitedb/Server/exampleprivatekey.key
82 |
83 | # -------------
84 | # path to certificate key file for https: needed for dservehttps only
85 | # example file created by the previous key/cert generation command
86 |
87 | #cert_file=/home/tanel/whitedb/Server/examplecertificate.crt
88 |
--------------------------------------------------------------------------------
/Server/examplecertificate.crt:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIID+zCCAuOgAwIBAgIJALHKYKuIz9gbMA0GCSqGSIb3DQEBBQUAMIGTMQswCQYD
3 | VQQGEwJFRTERMA8GA1UECAwISGFyanVtYWExEDAOBgNVBAcMB1RhbGxpbm4xEDAO
4 | BgNVBAoMB2V4YW1wbGUxEDAOBgNVBAsMB2V4YW1wbGUxFzAVBgNVBAMMDkV4YW1w
5 | bGUgUGVyc29uMSIwIAYJKoZIhvcNAQkBFhNleGFtcGxlQGV4YW1wbGUuY29tMB4X
6 | DTE0MDEwMzE0NTMxOVoXDTE1MDEwMzE0NTMxOVowgZMxCzAJBgNVBAYTAkVFMREw
7 | DwYDVQQIDAhIYXJqdW1hYTEQMA4GA1UEBwwHVGFsbGlubjEQMA4GA1UECgwHZXhh
8 | bXBsZTEQMA4GA1UECwwHZXhhbXBsZTEXMBUGA1UEAwwORXhhbXBsZSBQZXJzb24x
9 | IjAgBgkqhkiG9w0BCQEWE2V4YW1wbGVAZXhhbXBsZS5jb20wggEiMA0GCSqGSIb3
10 | DQEBAQUAA4IBDwAwggEKAoIBAQDBkjIsrlNOiW8RMMKmzj7WL1mr0vMrt4Pj/TIj
11 | isd+fgQck2v0pulTMv5r3N+u3/8cXjR8QpmcSXjkfYC6xWBwXRALKsVju/O5t3Zj
12 | GhHuv7PRtGnNgqiFDDLD2HdhoEojdXrirWnAe7YJDzfz2X28AJmGCH6RrZTL8EWs
13 | lgZd8ZA5XxQ3nXMd12lI6MECihbhQ5jc+dj1L7sA/Dd23eznwymQ0SwY+mkhca8D
14 | erX651DV3SwrXV0v3BN7gUg23CqKyUj/lgLRerKJb9yMQWdqZM5sTjxPxYr/JUFo
15 | pNFbm8hwv5dkpHdXtBrgq6Pxsge3/NIypjeNmnksZSsB4vkpAgMBAAGjUDBOMB0G
16 | A1UdDgQWBBRzNaHoRWvyMParvzh9sAZcusMheTAfBgNVHSMEGDAWgBRzNaHoRWvy
17 | MParvzh9sAZcusMheTAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4IBAQBL
18 | kdZsSHNo8LkRGlxIxK7YEsNgDEL0WChujO3ov05zgK7krLHY04HSCjtsjBobL/Z7
19 | setW70RRZMc6ymikX63SRqy6Dx+G2WJosNkczlLnbhorwpCmRpzf4BOptEpUd5xi
20 | fW7DMQVqzr2kND3Sc10HjIMWF+4bq9OAQnAa5HWURPNPZ5fDsnRC/A/TGvJizH6h
21 | jzchkYOvNegwQi6qos5MnVAb+LtI0lvUOxnUA1R2F07d+liJgknkt/Rw09IvN9hI
22 | PI2UohCghUvYaKSJt+LDUwVo/ihf+pBv/iWD8X7SYVxsmP9pyFGz/I2Q5utnR2yK
23 | bjMaHsGJgIcvav/YR4/f
24 | -----END CERTIFICATE-----
25 |
--------------------------------------------------------------------------------
/Server/exampleprivateKey.key:
--------------------------------------------------------------------------------
1 | -----BEGIN PRIVATE KEY-----
2 | MIIEwAIBADANBgkqhkiG9w0BAQEFAASCBKowggSmAgEAAoIBAQDp+yXGqevn9AFC
3 | YSQRAHibfb22PsUcvcpf17z8dDF/s5OO32PubXIRHuQYQPTDmA3kEAEDtP8rMQ4q
4 | GjvY7mI2/bJqVWpAGygVDXMzH6WAwaRWyozp8shefpyyI2aRoeOSVXOi4msaMs+2
5 | mbJv26318oNeqIpqd/Tbow52qvxd/9oCGJK1RBndw0zRpCg19ZFELs3A2M4EbQbR
6 | nRsmLKTh2+W6g482Zj0QEYhbgRoYr7WNPlav2/lCAs8ZNcAOhTOOJL+avAFiY27x
7 | 6FlfjTDoSQ2bl0CDpN5SDUod653ctSczsbYDWho8Zf4ED6O407ocpDkWJJgNmlam
8 | rK1Y9/T1AgMBAAECggEBAL8o7/ECDHlCEfFQee3mC6NFtMP7PoE/0eJB2OYMbBBf
9 | /3MfsX4vLp0sNsBV+WL/jIHCTYHg0wRPnLnrGvAdumIhHS3gwODFDxc8GN0wwr+R
10 | 9RjvfPb54pfJK24im/7pW4rHg6UVBNmvn6IYqf7XZKXmz0t7uTJI9OSor/1lrq9/
11 | 84uVya0xjFChkjIxLTTaUwNQfX66TD9rCNeMCgx60w6G37qgt5npwO6vwtvZzy1q
12 | +WQCP6UUVlT01Mi0VfCjzET1mHSTJDxLtrTATJrPagloOrxv9+7GtwG6/BZ6pjW4
13 | Fl5knpokce36aiaHl2zoMXZptAupidqfTwp0xZlsXvUCgYEA9fJ2GrNM/TSKrlZq
14 | AJMsTlbAxYt/HoPy9SPsapzygENOrJHjGu9zjRH9C1+YxCFVKNBmaruBkmiLIA1X
15 | PlDFauiai0AI1zJAFl88pjsj3oAGGoDz2AgQ6Ybz33GFIKzZjETSP5OyHGSw3Dvs
16 | 6kIc+orujrpRExZE1FrO0m7HzwsCgYEA84t5zar17H1SGVNyHe4N26aAxnmxoFjI
17 | LG5qkz5wrMWiMAikpqiQa41fyiFumffcG2FUAVH0cMw6QsmsPmN1FmPikF9eRUkq
18 | /ID8KTQ3zb+0JNlrWMSkJrT9tKkMy4yS0g2lEKZ2grNfn9HBtFmpCfFUAJ1ZkBE8
19 | 4LiygPIpy/8CgYEAtGxbAblZGEMMHVqdRrCwhwOTRRfReERZ3kWtMITUTQ2TUHtx
20 | PBg/D1UL6eUGP5MoUtmW2GOXaR0yOqAuyTMdsBDVFqQyGBPv+bmB13x5EseeMqE4
21 | wNkh9v6eNuOjQtYqfYEbL7KcrcGcEOQRJ8S6V33GBYRe536lnZbENJE6GQMCgYEA
22 | qaRTubEGEC7TCxUW/kYdnQyD0rxdwAVXmatnzRzHO3GGodLDbdsojeIyAQf8lH8T
23 | 8HaBH1JI5HE9e9wigGqi2m/FFy926Ogoay4ld0YKQOTxxGE15uVCOjwEJN1ELlzC
24 | wFIE0m5BSpVLXHWtacSyfFx/WNZB1ppLP3Un0a3c810CgYEAvTfrBMdEow0zNNOh
25 | /7M1YyCh6aVcR/ST9wdC/gkFyObBmBT+urep7LZzd8HAtjFwdHJQEyut5lM/9EXj
26 | 1eGJLGuKJqpz4jXSFGD2I5LlUvczlmK8ZM3o+XX2DYekH2rZF1oJ8/KGgnwAHZ4p
27 | ukAnif2J//s9GPdE0F2JEAEOjVE=
28 | -----END PRIVATE KEY-----
29 |
--------------------------------------------------------------------------------
/Server/exampleprivateKey.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN RSA PRIVATE KEY-----
2 | MIIEpgIBAAKCAQEA6fslxqnr5/QBQmEkEQB4m329tj7FHL3KX9e8/HQxf7OTjt9j
3 | 7m1yER7kGED0w5gN5BABA7T/KzEOKho72O5iNv2yalVqQBsoFQ1zMx+lgMGkVsqM
4 | 6fLIXn6csiNmkaHjklVzouJrGjLPtpmyb9ut9fKDXqiKanf026MOdqr8Xf/aAhiS
5 | tUQZ3cNM0aQoNfWRRC7NwNjOBG0G0Z0bJiyk4dvluoOPNmY9EBGIW4EaGK+1jT5W
6 | r9v5QgLPGTXADoUzjiS/mrwBYmNu8ehZX40w6EkNm5dAg6TeUg1KHeud3LUnM7G2
7 | A1oaPGX+BA+juNO6HKQ5FiSYDZpWpqytWPf09QIDAQABAoIBAQC/KO/xAgx5QhHx
8 | UHnt5gujRbTD+z6BP9HiQdjmDGwQX/9zH7F+Ly6dLDbAVfli/4yBwk2B4NMET5y5
9 | 6xrwHbpiIR0t4MDgxQ8XPBjdMMK/kfUY73z2+eKXyStuIpv+6VuKx4OlFQTZr5+i
10 | GKn+12Sl5s9Le7kySPTkqK/9Za6vf/OLlcmtMYxQoZIyMS002lMDUH1+ukw/awjX
11 | jAoMetMOht+6oLeZ6cDur8Lb2c8tavlkAj+lFFZU9NTItFXwo8xE9Zh0kyQ8S7a0
12 | wEyaz2oJaDq8b/fuxrcBuvwWeqY1uBZeZJ6aJHHt+momh5ds6DF2abQLqYnan08K
13 | dMWZbF71AoGBAPXydhqzTP00iq5WagCTLE5WwMWLfx6D8vUj7Gqc8oBDTqyR4xrv
14 | c40R/QtfmMQhVSjQZmq7gZJoiyANVz5QxWromotACNcyQBZfPKY7I96ABhqA89gI
15 | EOmG899xhSCs2YxE0j+TshxksNw77OpCHPqK7o66URMWRNRaztJux88LAoGBAPOL
16 | ec2q9ex9UhlTch3uDdumgMZ5saBYyCxuapM+cKzFojAIpKaokGuNX8ohbpn33Bth
17 | VAFR9HDMOkLJrD5jdRZj4pBfXkVJKvyA/Ck0N82/tCTZa1jEpCa0/bSpDMuMktIN
18 | pRCmdoKzX5/RwbRZqQnxVACdWZARPOC4soDyKcv/AoGBALRsWwG5WRhDDB1anUaw
19 | sIcDk0UX0XhEWd5FrTCE1E0Nk1B7cTwYPw9VC+nlBj+TKFLZlthjl2kdMjqgLskz
20 | HbAQ1RakMhgT7/m5gdd8eRLHnjKhOMDZIfb+njbjo0LWKn2BGy+ynK3BnBDkESfE
21 | uld9xgWEXud+pZ2WxDSROhkDAoGBAKmkU7mxBhAu0wsVFv5GHZ0Mg9K8XcAFV5mr
22 | Z80cxztxhqHSw23bKI3iMgEH/JR/E/B2gR9SSORxPXvcIoBqotpvxRcvdujoKGsu
23 | JXdGCkDk8cRhNeblQjo8BCTdRC5cwsBSBNJuQUqVS1x1rWnEsnxcf1jWQdaaSz91
24 | J9Gt3PNdAoGBAL036wTHRKMNMzTTof+zNWMgoemlXEf0k/cHQv4JBcjmwZgU/rq3
25 | qey2c3fBwLYxcHRyUBMrreZTP/RF49XhiSxriiaqc+I10hRg9iOS5VL3M5ZivGTN
26 | 6Pl19g2HpB9q2RdaCfPyhoJ8AB2eKbpAJ4n9if/7PRj3RNBdiRABDo1R
27 | -----END RSA PRIVATE KEY-----
28 |
--------------------------------------------------------------------------------
/Server/exampleprivatekey.key:
--------------------------------------------------------------------------------
1 | -----BEGIN PRIVATE KEY-----
2 | MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDBkjIsrlNOiW8R
3 | MMKmzj7WL1mr0vMrt4Pj/TIjisd+fgQck2v0pulTMv5r3N+u3/8cXjR8QpmcSXjk
4 | fYC6xWBwXRALKsVju/O5t3ZjGhHuv7PRtGnNgqiFDDLD2HdhoEojdXrirWnAe7YJ
5 | Dzfz2X28AJmGCH6RrZTL8EWslgZd8ZA5XxQ3nXMd12lI6MECihbhQ5jc+dj1L7sA
6 | /Dd23eznwymQ0SwY+mkhca8DerX651DV3SwrXV0v3BN7gUg23CqKyUj/lgLRerKJ
7 | b9yMQWdqZM5sTjxPxYr/JUFopNFbm8hwv5dkpHdXtBrgq6Pxsge3/NIypjeNmnks
8 | ZSsB4vkpAgMBAAECggEAF3Oi6I7mQOmdrzN9IcBzFHgAITUZiP5e2ExgurWhnc2e
9 | qeeieK2QLyhKcr77yrAQtFsleLiI68pq/yPFaNto57QesXupFoA68xErIq6R5Z8M
10 | Jif5eZCO4i+sJtYfAJDu6oTdMoFYAp36W/agDMcY2KIp93cn/nZNRLgDePlkJBVe
11 | NtHqqzqvn5FOwArBkiU5MmcGdRsWxABDzqTRJ3KHpF0JySdsEd+lT+A2tBWFl2Zz
12 | l2S1eBqI+G3KeRkQXITqOzwKctON8awMIQum/uKPGJc+NX5FgQXYPehsDGd+316V
13 | Sd+/Y5KP0xnKfjvsLvDrEGDpnwHwPG1iejMT507hUQKBgQDgQrMf04yOGZJZuVjV
14 | s6lR2S+Tr/yo+mhnzUSjj+AUDzyrfxoxxcncD6eKg1cMJstrPtRVZnS4TqcNUWjj
15 | qXHwpMwDLGZ8YCdZ+TVxsLpA8IZF6IiNo0Q1BbGTqQdtHMiznmqmioqwN5sNYqek
16 | N/IBm3vnuZfc9kgXrmOKw0LWdwKBgQDc95H79odz1vjlN0zN3+BGZdSKZQo3njYd
17 | My5c9CgMd+guKvQRoFI83gZJgSntw7qPH1feORuuMuIiL6fi46cjlQ257pdRp9CD
18 | 3HRzi6Wm020UravKz7v5pE/kRmZ5j8TfrB/D/kcQlUbp5X+Zv8aqX7I+8vG/XgIR
19 | zcl1F7d1XwKBgBodql56dFPYBoMMYpwAYCd382JvjCzhfGcaMHQbvSyY2affFV3W
20 | ert11zz6Lpjrq6TBnFiVpeIQxsN2R5C7mtk7V8bG1OiHCg4gR2kF+6q0V+6sNbrI
21 | 2JiUISng9Uxvna/NMv5SA/ShhRz58Cvfl/837CYAJv9EbwDS/iSauJ3hAoGBAIbq
22 | hnEQio3ZMSlLRZLiYd656DcEEGP7LtFPYbyRuy45vEMMKO/mMrBFZBNXURGCk5M1
23 | sQHXXqZTHS2AaYKoO3IHXVUsb6oEy9TnMxclqeQdbZnVnHH9uqlngPxBW+pXNP7Y
24 | 6qBRznQ6oQzI+ssWhCecvImg7qhIrvzN6HadH4ADAoGAAOR+db5U7qLVeE1voWpV
25 | 7g04EKF0GRsvNOQQ41bmVFaGvnpEGEY7OkytaN/hqomlWC2PHQVD7bUGj/z34eUF
26 | iYTx6BDZyTnKohdr/qTLxiO//dlE6/4G/M26A2a3wZFEruZbIrGRUkYLutBls6uX
27 | sp5A+W9NEbQAk1vBgNcEtD4=
28 | -----END PRIVATE KEY-----
29 |
--------------------------------------------------------------------------------
/Server/timecmd.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | @setlocal
3 |
4 | set start=%time%
5 |
6 | :: runs your command
7 | cmd /c %*
8 |
9 | set end=%time%
10 | set options="tokens=1-4 delims=:."
11 | for /f %options% %%a in ("%start%") do set start_h=%%a&set /a start_m=100%%b %% 100&set /a start_s=100%%c %% 100&set /a start_ms=100%%d %% 100
12 | for /f %options% %%a in ("%end%") do set end_h=%%a&set /a end_m=100%%b %% 100&set /a end_s=100%%c %% 100&set /a end_ms=100%%d %% 100
13 |
14 | set /a hours=%end_h%-%start_h%
15 | set /a mins=%end_m%-%start_m%
16 | set /a secs=%end_s%-%start_s%
17 | set /a ms=%end_ms%-%start_ms%
18 | if %hours% lss 0 set /a hours = 24%hours%
19 | if %mins% lss 0 set /a hours = %hours% - 1 & set /a mins = 60%mins%
20 | if %secs% lss 0 set /a mins = %mins% - 1 & set /a secs = 60%secs%
21 | if %ms% lss 0 set /a secs = %secs% - 1 & set /a ms = 100%ms%
22 | if 1%ms% lss 100 set ms=0%ms%
23 |
24 | :: mission accomplished
25 | set /a totalsecs = %hours%*3600 + %mins%*60 + %secs%
26 | echo command took %hours%:%mins%:%secs%.%ms% (%totalsecs%.%ms%s total)
--------------------------------------------------------------------------------
/Test/Makefile.am:
--------------------------------------------------------------------------------
1 | #
2 | # - - - - main db sources - - -
3 |
4 | noinst_LTLIBRARIES = libTest.la
5 | libTest_la_SOURCES = dbtest.c dbtest.h
6 |
7 | if REASONER
8 | libTest_la_SOURCES += rtest.c rtest.h
9 | endif
10 |
11 |
--------------------------------------------------------------------------------
/Test/common.test:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | Main/selftest common
4 | ERR=$?
5 | exit ${ERR}
6 |
7 |
--------------------------------------------------------------------------------
/Test/dbtest.h:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Tanel Tammet 2004,2005,2006,2007,2008,2009
6 | * Copyright (c) Priit Järv 2009,2010,2012,2013,2014
7 | *
8 | * Contact: tanel.tammet@gmail.com
9 | *
10 | * This file is part of WhiteDB
11 | *
12 | * WhiteDB is free software: you can redistribute it and/or modify
13 | * it under the terms of the GNU General Public License as published by
14 | * the Free Software Foundation, either version 3 of the License, or
15 | * (at your option) any later version.
16 | *
17 | * WhiteDB is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU General Public License
23 | * along with WhiteDB. If not, see .
24 | *
25 | */
26 |
27 | /** @file dbtest.h
28 | * Public headers for database testing procedures.
29 | */
30 |
31 | #ifndef DEFINED_DBTEST_H
32 | #define DEFINED_DBTEST_H
33 |
34 | #ifdef _WIN32
35 | #include "../config-w32.h"
36 | #else
37 | #include "../config.h"
38 | #endif
39 |
40 | /* ====== general typedefs and macros ======= */
41 |
42 | #define WG_TEST_COMMON 0x01
43 | #define WG_TEST_INDEX 0x02
44 | #define WG_TEST_QUERY 0x04
45 | #define WG_TEST_LOG 0x08
46 | #define WG_TEST_QUICK (WG_TEST_COMMON|WG_TEST_LOG)
47 | #define WG_TEST_FULL (WG_TEST_QUICK|WG_TEST_INDEX|WG_TEST_QUERY)
48 |
49 | /* ==== Protos ==== */
50 |
51 | int wg_run_tests(int tests, int printlevel);
52 | void wg_show_db_memsegment_header(void* db);
53 |
54 | int wg_genintdata_asc(void *db, int databasesize, int recordsize);
55 | int wg_genintdata_desc(void *db, int databasesize, int recordsize);
56 | int wg_genintdata_mix(void *db, int databasesize, int recordsize);
57 |
58 | void wg_debug_print_value(void *db, gint data);
59 |
60 | /* ------- testing ------------ */
61 |
62 | #endif /* DEFINED_DBTEST_H */
63 |
--------------------------------------------------------------------------------
/Test/log.test:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | Main/selftest log
4 | ERR=$?
5 | exit ${ERR}
6 |
7 |
--------------------------------------------------------------------------------
/Test/rtest.h:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Tanel Tammet 2004,2005,2006,2007,2008,2009,2010
6 | *
7 | * Contact: tanel.tammet@gmail.com
8 | *
9 | * This file is part of WhiteDB
10 | *
11 | * WhiteDB is free software: you can redistribute it and/or modify
12 | * it under the terms of the GNU General Public License as published by
13 | * the Free Software Foundation, either version 3 of the License, or
14 | * (at your option) any later version.
15 | *
16 | * WhiteDB is distributed in the hope that it will be useful,
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | * GNU General Public License for more details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with WhiteDB. If not, see .
23 | *
24 | */
25 |
26 | /** @file rtest.h
27 | * Reasoner testing functions.
28 | *
29 | */
30 |
31 |
32 | #ifndef DEFINED_RTEST_H
33 | #define DEFINED_RTEST_H
34 |
35 | #include "../Reasoner/glb.h"
36 |
37 | int wg_test_reasoner(int argc, char **argv);
38 | static int wr_test_subsume_cl(glb* g, cvec clvec, char* clstr, int expres, int p);
39 |
40 | #endif
41 |
--------------------------------------------------------------------------------
/compile.bat:
--------------------------------------------------------------------------------
1 | @rem current version does not build reasoner: added later
2 |
3 | @rem build DLL.
4 | @rem unlike gcc build, it is necessary to have all functions declared in
5 | @rem wgdb.def file. Make sure it's up to date (should list same functions as
6 | @rem Db/dbapi.h)
7 | cl /Ox /W3 /MT /Fewgdb /LD Db\dbmem.c Db\dballoc.c Db\dbdata.c Db\dblock.c DB\dbdump.c Db\dblog.c Db\dbhash.c Db\dbindex.c Db\dbcompare.c Db\dbquery.c Db\dbutil.c Db\dbmpool.c Db\dbjson.c Db\dbschema.c json\yajl_all.c /link /def:wgdb.def /incremental:no /MANIFEST:NO
8 |
9 | @rem Link executables against wgdb.dll
10 | @rem cl /Ox /W3 Main\stresstest.c wgdb.lib
11 | cl /Ox /W3 Main\wgdb.c wgdb.lib
12 | @rem cl /Ox /W3 Main\indextool.c wgdb.lib
13 |
14 | @rem Example of building without the DLL
15 | @rem the test module depends on many symbols not part of the API
16 | cl /Ox /W3 Main\selftest.c Db\dbmem.c Db\dballoc.c Db\dbdata.c Db\dblock.c Test\dbtest.c DB\dbdump.c Db\dblog.c Db\dbhash.c Db\dbindex.c Db\dbcompare.c Db\dbquery.c Db\dbutil.c Db\dbmpool.c Db\dbjson.c Db\dbschema.c json\yajl_all.c
17 |
--------------------------------------------------------------------------------
/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # alternative to compilation with automake/make: just run
4 |
5 | # current version does not build reasoner: added later
6 |
7 | [ -z "$CC" ] && CC="cc"
8 |
9 | if [ -z "$(which $CC 2>/dev/null)" ]; then
10 | echo "Error: No compiler found"
11 | exit 1
12 | fi
13 |
14 | [ -f config.h ] || cp config-gcc.h config.h
15 | if [ config-gcc.h -nt config.h ]; then
16 | echo "Warning: config.h is older than config-gcc.h, consider updating it"
17 | fi
18 | ${CC} -O2 -Wall -o Main/wgdb Main/wgdb.c Db/dbmem.c \
19 | Db/dballoc.c Db/dbdata.c Db/dblock.c Db/dbindex.c Db/dbdump.c \
20 | Db/dblog.c Db/dbhash.c Db/dbcompare.c Db/dbquery.c Db/dbutil.c Db/dbmpool.c \
21 | Db/dbjson.c Db/dbschema.c json/yajl_all.c -lm
22 | # debug and testing programs: uncomment as needed
23 | #$CC -O2 -Wall -o Main/indextool Main/indextool.c Db/dbmem.c \
24 | # Db/dballoc.c Db/dbdata.c Db/dblock.c Db/dbindex.c Db/dblog.c \
25 | # Db/dbhash.c Db/dbcompare.c Db/dbquery.c Db/dbutil.c Db/dbmpool.c \
26 | # Db/dbjson.c Db/dbschema.c json/yajl_all.c -lm
27 | #$CC -O2 -Wall -o Main/selftest Main/selftest.c Db/dbmem.c \
28 | # Db/dballoc.c Db/dbdata.c Db/dblock.c Db/dbindex.c Test/dbtest.c Db/dbdump.c \
29 | # Db/dblog.c Db/dbhash.c Db/dbcompare.c Db/dbquery.c Db/dbutil.c Db/dbmpool.c \
30 | # Db/dbjson.c Db/dbschema.c json/yajl_all.c -lm
31 |
--------------------------------------------------------------------------------
/config-gcc.h:
--------------------------------------------------------------------------------
1 | /*
2 | * XXX: put this file under license if needed
3 | *
4 | */
5 |
6 | /** @file config-gcc.h
7 | * Build configuration for gcc platform.
8 | *
9 | * Based on auto-generated config.h. Should be manually synced whenever
10 | * additional configuration parameters are added.
11 | */
12 |
13 | /* Use additional validation checks */
14 | #define CHECK 1
15 |
16 | /* Journal file directory */
17 | #define DBLOG_DIR "/tmp"
18 |
19 | /* Select locking protocol (undef to disable locking)
20 | * 1 - reader preference spinlock
21 | * 2 - writer preference spinlock
22 | * 3 - task-fair queued lock
23 | */
24 | #define LOCK_PROTO 1
25 |
26 | /* Encoded data is 64-bit */
27 | /* #undef HAVE_64BIT_GINT */
28 |
29 | /* Define if you have POSIX threads libraries and header files. */
30 | #define HAVE_PTHREAD 1
31 |
32 | /* Compile with raptor rdf library */
33 | /* #undef HAVE_RAPTOR */
34 |
35 | /* Define to 1 if your C compiler doesn't accept -c and -o together. */
36 | /* #undef NO_MINUS_C_MINUS_O */
37 |
38 | /* Name of package */
39 | #define PACKAGE "whitedb"
40 |
41 | /* Define to the address where bug reports for this package should be sent. */
42 | #define PACKAGE_BUGREPORT ""
43 |
44 | /* Define to the full name of this package. */
45 | #define PACKAGE_NAME "WhiteDB"
46 |
47 | /* Define to the full name and version of this package. */
48 | #define PACKAGE_STRING "WhiteDB 0.8-alpha"
49 |
50 | /* Define to the one symbol short name of this package. */
51 | #define PACKAGE_TARNAME "whitedb"
52 |
53 | /* Define to the version of this package. */
54 | #define PACKAGE_VERSION "0.8-alpha"
55 |
56 | /* Define to necessary symbol if this constant uses a non-standard name on
57 | your system. */
58 | /* #undef PTHREAD_CREATE_JOINABLE */
59 |
60 | /* String hash size (% of db size) */
61 | #define STRHASH_SIZE 2
62 |
63 | /* Use chained T-tree index nodes */
64 | #define TTREE_CHAINED_NODES 1
65 |
66 | /* Use single-compare T-tree mode */
67 | #define TTREE_SINGLE_COMPARE 1
68 |
69 | /* Use record banklinks */
70 | #define USE_BACKLINKING 1
71 |
72 | /* Enable child database support */
73 | /* #undef USE_CHILD_DB */
74 |
75 | /* Use dblog module for transaction logging */
76 | /* #undef USE_DBLOG */
77 |
78 | /* Use match templates for indexes */
79 | #define USE_INDEX_TEMPLATE 1
80 |
81 | /* Enable runtime diagnostics via error callback */
82 | #define USE_ERROR_CALLBACK 1
83 |
84 | /* Enable reasoner */
85 | /* #undef USE_REASONER */
86 |
87 | /* Version number of package */
88 | #define VERSION "0.8-alpha"
89 |
90 | /* Package major version */
91 | #define VERSION_MAJOR 0
92 |
93 | /* Package minor version */
94 | #define VERSION_MINOR 8
95 |
96 | /* Package revision number */
97 | #define VERSION_REV 0
98 |
--------------------------------------------------------------------------------
/config-w32.h:
--------------------------------------------------------------------------------
1 | /*
2 | * XXX: put this file under license if needed
3 | *
4 | */
5 |
6 | /** @file config-w32.h
7 | * Build configuration for Win32 platform.
8 | *
9 | * Based on auto-generated config.h. Should be manually synced whenever
10 | * additional configuration parameters are added.
11 | */
12 |
13 | /* Use additional validation checks */
14 | #define CHECK 1
15 |
16 | /* Journal file directory */
17 | #define DBLOG_DIR "c:\\windows\\temp"
18 |
19 | /* Select locking protocol (undef to disable locking)
20 | * 1 - reader preference spinlock
21 | * 2 - writer preference spinlock
22 | * 3 - task-fair queued lock
23 | */
24 | #define LOCK_PROTO 1
25 |
26 | /* Encoded data is 64-bit */
27 | /* #undef HAVE_64BIT_GINT */
28 |
29 | /* Define if you have POSIX threads libraries and header files. */
30 | /* #undef HAVE_PTHREAD */
31 |
32 | /* Compile with raptor rdf library */
33 | /* #undef HAVE_RAPTOR */
34 |
35 | /* Define to 1 if your C compiler doesn't accept -c and -o together. */
36 | /* #undef NO_MINUS_C_MINUS_O */
37 |
38 | /* Name of package */
39 | #define PACKAGE "whitedb"
40 |
41 | /* Define to the address where bug reports for this package should be sent. */
42 | #define PACKAGE_BUGREPORT ""
43 |
44 | /* Define to the full name of this package. */
45 | #define PACKAGE_NAME "WhiteDB"
46 |
47 | /* Define to the full name and version of this package. */
48 | #define PACKAGE_STRING "WhiteDB 0.8-alpha"
49 |
50 | /* Define to the one symbol short name of this package. */
51 | #define PACKAGE_TARNAME "whitedb"
52 |
53 | /* Define to the version of this package. */
54 | #define PACKAGE_VERSION "0.8-alpha"
55 |
56 | /* Define to necessary symbol if this constant uses a non-standard name on
57 | your system. */
58 | /* #undef PTHREAD_CREATE_JOINABLE */
59 |
60 | /* String hash size (% of db size) */
61 | #define STRHASH_SIZE 2
62 |
63 | /* Use chained T-tree index nodes */
64 | #define TTREE_CHAINED_NODES 1
65 |
66 | /* Use single-compare T-tree mode */
67 | #define TTREE_SINGLE_COMPARE 1
68 |
69 | /* Use record banklinks */
70 | #define USE_BACKLINKING 1
71 |
72 | /* Enable child database support */
73 | /* #undef USE_CHILD_DB */
74 |
75 | /* Use dblog module for transaction logging */
76 | /* #undef USE_DBLOG */
77 |
78 | /* Use match templates for indexes */
79 | #define USE_INDEX_TEMPLATE 1
80 |
81 | /* Enable runtime diagnostics via error callback */
82 | #define USE_ERROR_CALLBACK 1
83 |
84 | /* Enable reasoner */
85 | /* #undef USE_REASONER */
86 |
87 | /* Version number of package */
88 | #define VERSION "0.8-alpha"
89 |
90 | /* Package major version */
91 | #define VERSION_MAJOR 0
92 |
93 | /* Package minor version */
94 | #define VERSION_MINOR 8
95 |
96 | /* Package revision number */
97 | #define VERSION_REV 0
98 |
--------------------------------------------------------------------------------
/gendoc.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # run with ASCIIDOC_XSL=/path/to/stylesheets ./gendoc.sh [ destdir ]
4 | #
5 | # ASCIIDOC_XSL=/usr/share/asciidoc/docbook-xsl/ ./gendoc.sh
6 |
7 | # default stylesheets path
8 | [ "X${ASCIIDOC_XSL}" = "X" ] && ASCIIDOC_XSL="/etc/asciidoc/docbook-xsl"
9 |
10 | # destination directory
11 | DESTDIR=$1
12 | [ "X${DESTDIR}" = "X" ] && DESTDIR=Doc
13 |
14 | iconv -f latin1 -t utf-8 Doc/Manual.txt |\
15 | sed -f Doc/Manual2html.sed |\
16 | asciidoc -b docbook - |\
17 | xsltproc --nonet ${ASCIIDOC_XSL}/xhtml.xsl - > ${DESTDIR}/Manual.html
18 |
19 | iconv -f latin1 -t utf-8 Doc/python.txt |\
20 | sed -f Doc/python2html.sed |\
21 | asciidoc -b docbook - |\
22 | xsltproc --nonet ${ASCIIDOC_XSL}/xhtml.xsl - > ${DESTDIR}/python.html
23 |
24 | iconv -f latin1 -t utf-8 Doc/Tutorial.txt |\
25 | sed -f Doc/Tutorial2html.sed |\
26 | asciidoc -b docbook - |\
27 | xsltproc --nonet ${ASCIIDOC_XSL}/xhtml.xsl - > ${DESTDIR}/Tutorial.html
28 |
29 | iconv -f latin1 -t utf-8 Doc/Install.txt |\
30 | sed -f Doc/Install2html.sed |\
31 | asciidoc -b docbook - |\
32 | xsltproc --nonet ${ASCIIDOC_XSL}/xhtml.xsl - > ${DESTDIR}/Install.html
33 |
34 | iconv -f latin1 -t utf-8 Doc/Utilities.txt |\
35 | asciidoc -b docbook - |\
36 | xsltproc --nonet ${ASCIIDOC_XSL}/xhtml.xsl - > ${DESTDIR}/Utilities.html
37 |
38 | # add Doxygen / PyDoc generation here as needed
39 |
--------------------------------------------------------------------------------
/java/jni/Readme.txt:
--------------------------------------------------------------------------------
1 | WhiteDB JNI wrapper
2 | ===================
3 |
4 | The JNI wrapper provides the WhiteDB bindings for Java. It is still under
5 | development and not usable for general application.
6 |
7 | Compiling under Windows environment
8 | -----------------------------------
9 |
10 | Scripts should be executed in the order given here. Please run each script in the
11 | directory they are located. You may need to edit the scripts to adjust the paths
12 | to your environment; specific instructions below.
13 |
14 | `setEnv.bat`
15 |
16 | This file sets all needed paths and variables for compiling and running all jni classes.
17 | Line 1: `javac`, `javah` and `java` location in your computer will be added to path.
18 | Line 2: you will be directed to your working directory.
19 | Line 3: path to jni library (in windows, dll file) will be added to your path variable.
20 | Line 4: 'vcvarsall.bat' run. Its needed to use Visual Studios c compiler 'cl.exe'.
21 |
22 | `compileJava.bat`
23 |
24 | This script file compiles 'WhiteDB.java' source file and generates .h file for jni from compiled class file.
25 |
26 | `compileBridge.bat`
27 |
28 | This script will compile c source code ('cl.exe' flag '/LD') into dll file including java sdk's jni needed
29 | files ('cl.exe' flag '/I'). Change path of 'cl.exe' and java sdk includes to paths where they can be found in
30 | your computer. Copy 'config-w32.h' to 'java\jni' directory before running this script.
31 |
32 | `runJava.bat`
33 | This script runs WhiteDB class file.
34 |
35 | Compiling under Unix-like environment
36 | -------------------------------------
37 |
38 | Scripts should be executed in the order given here. Please run each script in the
39 | directory they are located. Set JAVA_HOME before executing the scripts.
40 |
41 | `compile_java.sh`
42 |
43 | This script file compiles 'WhiteDB.java' source file and generates the header file
44 | for jni from compiled class file.
45 |
46 | `compile_bridge.sh`
47 |
48 | Compile the shared library that wraps the WhiteDB functions for Java.
49 |
50 | `run_java.sh`
51 |
52 | Runs the tests in the WhiteDB class.
53 |
--------------------------------------------------------------------------------
/java/jni/classes/.gitignore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/priitj/whitedb/9d898103330695dd18db5839120e0d2522329154/java/jni/classes/.gitignore
--------------------------------------------------------------------------------
/java/jni/compileBridge.bat:
--------------------------------------------------------------------------------
1 | cd library
2 | "C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\cl.exe" /LD /I"C:\Program Files\Java\jdk1.7.0_25\include" /I"C:\Program Files\Java\jdk1.7.0_25\include\win32" /W3 ..\src\native\whitedbDriver.c ..\..\..\Db\dbmem.c ..\..\..\Db\dballoc.c ..\..\..\Db\dbdata.c ..\..\..\Db\dbindex.c ..\..\..\Db\dbquery.c ..\..\..\Db\dbutil.c ..\..\..\Db\dbmpool.c ..\..\..\Db\dblock.c ..\..\..\Db\dbcompare.c ..\..\..\Db\dbhash.c
3 | cd ..
4 |
--------------------------------------------------------------------------------
/java/jni/compileJava.bat:
--------------------------------------------------------------------------------
1 | javac -cp ./src -d classes src\whitedb\driver\WhiteDB.java
2 | javac -cp ./src -d classes src\whitedb\driver\tests.java
3 | javah -classpath ./classes -d src/native -jni whitedb.driver.WhiteDB
4 |
--------------------------------------------------------------------------------
/java/jni/compile_bridge.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | [ "X${JAVA_HOME}" = "X" ] && JAVA_HOME=/usr/lib/jvm/java-6-openjdk
4 | #DBDIR=../../../Db
5 |
6 | # run unite.sh if needed
7 | if [ ! -f ../../whitedb.c ]; then
8 | cd ../..; ./unite.sh; cd "$OLDPWD"
9 | fi
10 |
11 | cd library
12 | gcc -O2 -lm -fPIC -shared -I${JAVA_HOME}/include -I../../.. \
13 | ../src/native/whitedbDriver.c ../../../whitedb.c -o libwhitedbDriver.so
14 |
15 | #gcc -O2 -lm -fPIC -shared -I${JAVA_HOME}/include ../src/native/whitedbDriver.c ${DBDIR}/dbmem.c ${DBDIR}/dballoc.c ${DBDIR}/dbdata.c ${DBDIR}/dblock.c ${DBDIR}/dbindex.c ${DBDIR}/dblog.c ${DBDIR}/dbhash.c ${DBDIR}/dbcompare.c ${DBDIR}/dbquery.c ${DBDIR}/dbutil.c ${DBDIR}/dbmpool.c ${DBDIR}/dbschema.c ${DBDIR}/dbjson.c ${DBDIR}/../json/yajl_all.c -o libwhitedbDriver.so
16 |
17 |
--------------------------------------------------------------------------------
/java/jni/compile_java.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | javac -cp ./src -d classes src/whitedb/driver/WhiteDB.java
4 | javac -cp ./src -d classes src/whitedb/driver/tests.java
5 |
6 | javah -classpath ./classes -d src/native -jni whitedb.driver.WhiteDB
7 |
--------------------------------------------------------------------------------
/java/jni/config.h:
--------------------------------------------------------------------------------
1 | ../../config.h
--------------------------------------------------------------------------------
/java/jni/library/.gitignore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/priitj/whitedb/9d898103330695dd18db5839120e0d2522329154/java/jni/library/.gitignore
--------------------------------------------------------------------------------
/java/jni/runJava.bat:
--------------------------------------------------------------------------------
1 | java -classpath ./classes whitedb.driver.tests
2 |
--------------------------------------------------------------------------------
/java/jni/run_java.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | java -classpath ./classes -Djava.library.path=./library \
4 | whitedb.driver.tests
5 |
--------------------------------------------------------------------------------
/java/jni/setEnv.bat:
--------------------------------------------------------------------------------
1 | PATH=%PATH%;C:\Program Files\Java\jdk1.7.0_25\bin\;
2 | REM cd C:\path\to\whitedb\java\jni\
3 | PATH=%path%;./library
4 | "C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"
5 |
--------------------------------------------------------------------------------
/java/jni/src/whitedb/holder/Database.java:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Andres Puusepp 2009
6 | *
7 | * This file is part of WhiteDB
8 | *
9 | * WhiteDB is free software: you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation, either version 3 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * WhiteDB is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with WhiteDB. If not, see .
21 | *
22 | */
23 |
24 | /** @file Database.java
25 | * Database class for WhiteDB Java API.
26 | *
27 | */
28 |
29 | package whitedb.holder;
30 |
31 | public class Database {
32 | public long pointer;
33 | }
34 |
--------------------------------------------------------------------------------
/java/jni/src/whitedb/holder/Query.java:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Priit Järv 2013
6 | *
7 | * This file is part of WhiteDB
8 | *
9 | * WhiteDB is free software: you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation, either version 3 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * WhiteDB is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with WhiteDB. If not, see .
21 | *
22 | */
23 |
24 | /** @file Query.java
25 | * Query class for WhiteDB Java API.
26 | *
27 | */
28 |
29 | package whitedb.holder;
30 |
31 | public class Query {
32 | public long query;
33 | public long arglist;
34 | public int argc;
35 | }
36 |
--------------------------------------------------------------------------------
/java/jni/src/whitedb/holder/Record.java:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Andres Puusepp 2009
6 | *
7 | * This file is part of WhiteDB
8 | *
9 | * WhiteDB is free software: you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation, either version 3 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * WhiteDB is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with WhiteDB. If not, see .
21 | *
22 | */
23 |
24 | /** @file Record.java
25 | * Record class for WhiteDB Java API.
26 | *
27 | */
28 |
29 | package whitedb.holder;
30 |
31 | public class Record {
32 | public long pointer;
33 | }
34 |
--------------------------------------------------------------------------------
/java/jni/src/whitedb/holder/SampleObject.java:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Andres Puusepp 2009
6 | *
7 | * This file is part of WhiteDB
8 | *
9 | * WhiteDB is free software: you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation, either version 3 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * WhiteDB is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with WhiteDB. If not, see .
21 | *
22 | */
23 |
24 | /** @file SampleObject.java
25 | * ORM demo class for WhiteDB Java API.
26 | *
27 | */
28 |
29 | package whitedb.holder;
30 |
31 | public class SampleObject {
32 | public int weight;
33 | public int age;
34 |
35 | @Override
36 | public String toString() {
37 | return "SampleObject{" +
38 | "weight=" + weight +
39 | ", age=" + age +
40 | '}';
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/java/jni/src/whitedb/util/ArgListEntry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Priit Järv 2013
6 | *
7 | * This file is part of WhiteDB
8 | *
9 | * WhiteDB is free software: you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation, either version 3 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * WhiteDB is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with WhiteDB. If not, see .
21 | *
22 | */
23 |
24 | /** @file ArgListEntry.java
25 | * WhiteDB Query argument helper class.
26 | *
27 | */
28 |
29 | package whitedb.util;
30 |
31 | /* XXX: currently only allows int arguments */
32 | public class ArgListEntry {
33 | public int column;
34 | public int cond;
35 | public int value;
36 |
37 | public ArgListEntry(int column, int cond, int value) {
38 | this.column = column;
39 | this.cond = cond;
40 | this.value = value;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/java/jni/src/whitedb/util/FieldComparator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: $
3 | * $Version: $
4 | *
5 | * Copyright (c) Andres Puusepp 2009
6 | *
7 | * This file is part of WhiteDB
8 | *
9 | * WhiteDB is free software: you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation, either version 3 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * WhiteDB is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with WhiteDB. If not, see .
21 | *
22 | */
23 |
24 | /** @file FieldComparator.java
25 | * WhiteDB Java API ORM support code.
26 | *
27 | */
28 |
29 | package whitedb.util;
30 |
31 | import java.util.Comparator;
32 | import java.lang.reflect.Field;
33 |
34 | public class FieldComparator implements Comparator {
35 | public int compare(Field field1, Field field2) {
36 | return field1.getName().compareTo(field2.getName());
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/json/Makefile.am:
--------------------------------------------------------------------------------
1 | #
2 | # - - - - json parser sources - - -
3 |
4 | noinst_LTLIBRARIES = libjson.la
5 | libjson_la_SOURCES = yajl_api.h yajl_all.h yajl_all.c
6 |
7 |
--------------------------------------------------------------------------------
/unite.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | amal() {
4 | sed 's/#include\ "../\/\//' $1
5 | }
6 |
7 | [ -f config.h ] || cp config-gcc.h config.h
8 | if [ config-gcc.h -nt config.h ]; then
9 | echo "Warning: config.h is older than config-gcc.h, consider updating it"
10 | fi
11 |
12 | cat << EOT > whitedb.h
13 | #include
14 | $(amal config.h)
15 | $(amal json/yajl_api.h)
16 | $(amal json/yajl_all.h)
17 | $(amal Db/dballoc.h)
18 |
19 | $(amal Db/dbmem.h)
20 | $(amal Db/dbfeatures.h)
21 | $(amal Db/dbdata.h)
22 | $(amal Db/dblog.h)
23 | $(amal Db/dbdump.h)
24 | $(amal Db/dbhash.h)
25 | $(amal Db/dbindex.h)
26 | $(amal Db/dbcompare.h)
27 | $(amal Db/dbquery.h)
28 | $(amal Db/dbutil.h)
29 | $(amal Db/dbmpool.h)
30 | $(amal Db/dbjson.h)
31 | $(amal Db/dblock.h)
32 | $(amal Db/dbschema.h)
33 | EOT
34 |
35 | cat << EOT > whitedb.c
36 | #include
37 | $(amal Db/crc1.h)
38 |
39 | $(amal json/yajl_all.c)
40 | $(amal Db/dbmem.c)
41 | $(amal Db/dballoc.c)
42 | $(amal Db/dbdata.c)
43 | $(amal Db/dblog.c)
44 | $(amal Db/dbdump.c)
45 | $(amal Db/dbhash.c)
46 | $(amal Db/dbindex.c)
47 | $(amal Db/dbcompare.c)
48 | $(amal Db/dbquery.c)
49 | $(amal Db/dbutil.c)
50 | $(amal Db/dbmpool.c)
51 | $(amal Db/dbjson.c)
52 | $(amal Db/dbschema.c)
53 | $(amal Db/dblock.c)
54 | EOT
55 |
--------------------------------------------------------------------------------
/whitedb.pc.in:
--------------------------------------------------------------------------------
1 | # $Id$
2 | prefix=@prefix@
3 | exec_prefix=@exec_prefix@
4 | libdir=@libdir@
5 | includedir=@includedir@
6 |
7 | Name: whitedb
8 | Description: WhiteDB is a lightweight NoSQL database library written in C, operating fully in main memory.
9 | URL: http://whitedb.org
10 | Version: @VERSION@
11 | Libs: -L${libdir} -lwgdb
12 | Cflags: -I${includedir}
13 |
--------------------------------------------------------------------------------