From 879f22e8cc5ac396dc7037212c15f7bec0eba17b Mon Sep 17 00:00:00 2001 From: bpc2003 Date: Fri, 14 Mar 2025 14:55:08 -0400 Subject: Update README.md --- .gitignore | 2 +- README.md | 33 ++++++++++++++++++++++++++++++++- src/main.c | 11 ++++++++--- 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) -- cgit v1.2.3