summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--README.md33
-rw-r--r--src/main.c11
3 files changed, 41 insertions, 5 deletions
diff --git a/.gitignore b/.gitignore
index 46c80fd..4569b8d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,7 +2,7 @@
*.db
*.db~
-# compiled files
+# build files
target/
# lsp
diff --git a/README.md b/README.md
index c66b005..d68cf2d 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,33 @@
# mdb
-mdb is a embedded key-value database written in C
+mdb is a simple embedded key-value database written in C.
+
+## Table of Contents
+- [Installation](##Installation)
+- [Reference](##Reference)
+- [Removal](##Removal)
+- [License](./LICENSE)
+
+## Installation
+In order to install mdb clone this repository then run:
+```sudo make install```
+
+## Reference
+There are four basic commands in mdb:
+- exit: exits the program
+- GET: gets a given key from a given object
+- SET: sets a given key-value pair in a given object
+- DEL: deletes a given key-value pair from a given object
+### API Reference
+There are six functions in mdb.h
+- readdb: reads a database from a given file
+- writedb: writes a database to a given file
+- getkeys: gets every key-value pair from a given object
+- getkey: gets a single key-value pair from a given object
+- setkey: sets a given key-value pair in a given object
+- delkey: deletes a given key-value pair from a given object
+
+## Removal
+In order to remove mdb run:
+```sudo make remove```
+or
+```sudo make uninstall```
diff --git a/src/main.c b/src/main.c
index 040f8e2..9b7de68 100644
--- a/src/main.c
+++ b/src/main.c
@@ -12,9 +12,13 @@ void delkeys(struct keytablist *list, int id, char **keys, int klen);
int main(int argc, char **argv)
{
- if (argc != 2)
+ if (argc > 2) {
+ printf("usage: %s [db file]\n", argv[0]);
exit(1);
- char *filename = argv[1];
+ }
+ char *filename = NULL;
+ if (argc == 2)
+ filename = argv[1];
struct keytablist *list = readdb(filename);
char *cmd = calloc(1024, sizeof(char));
@@ -62,7 +66,8 @@ int main(int argc, char **argv)
}
free(cmd);
- writedb(filename, list);
+ if (filename != NULL)
+ writedb(filename, list);
for (int i = 0; i < list[0].len; ++i) {
int *indexes = getkeys(list, i);
for (int j = 0; indexes[j]; ++j)