diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/file.c | 4 | ||||
-rw-r--r-- | src/lib/keytab.c | 8 | ||||
-rw-r--r-- | src/lib/mdb.h | 2 |
3 files changed, 12 insertions, 2 deletions
diff --git a/src/lib/file.c b/src/lib/file.c index c5eabb2..34086e0 100644 --- a/src/lib/file.c +++ b/src/lib/file.c @@ -6,6 +6,9 @@ static char *getpair(int *c, FILE *fp); +// readdb - reads the given file into a key table list +// if fp returns NULL it will return the empty list +// if readdb fails it will return NULL struct keytablist *readdb(char *filename) { int len = 2; @@ -48,6 +51,7 @@ struct keytablist *readdb(char *filename) return list; } +// writedb - writes a keytablist to a given file void writedb(char *filename, struct keytablist *list) { FILE *fp = fopen(filename, "wb"); diff --git a/src/lib/keytab.c b/src/lib/keytab.c index 5d0c7dd..74dc47f 100644 --- a/src/lib/keytab.c +++ b/src/lib/keytab.c @@ -5,10 +5,9 @@ #include "mdb.h" -static const struct keytablist empty; - static int hash(char *key); +// getkeys - gets every single key in a key table int *getkeys(struct keytablist *list, int id) { int len = 2; @@ -24,6 +23,8 @@ int *getkeys(struct keytablist *list, int id) return indexes; } +// getkey - gets a single key from a keytable +// if it can't find the key it will return an empty table index struct keytab getkey(struct keytablist *list, int id, char *key) { int idx = hash(key); @@ -37,6 +38,8 @@ struct keytab getkey(struct keytablist *list, int id, char *key) return list[id].tab[idx]; } +// setkey - adds the given pair to the given key table +// if setkey fails it will return 1 otherwise 0 int setkey(struct keytablist **list, int id, char *pair) { if (id >= (*list)[0].len) { @@ -87,6 +90,7 @@ int setkey(struct keytablist **list, int id, char *pair) return 0; } +// delkey - removes the given key from the given key table void delkey(struct keytablist *list, int id, char *key) { int idx = hash(key); diff --git a/src/lib/mdb.h b/src/lib/mdb.h index aafacf0..7408dc7 100644 --- a/src/lib/mdb.h +++ b/src/lib/mdb.h @@ -20,11 +20,13 @@ struct keytablist { struct keytab tab[TABLEN]; }; +// Table operations int *getkeys(struct keytablist *list, int id); struct keytab getkey(struct keytablist *list, int id, char *key); int setkey(struct keytablist **list, int id, char *pair); void delkey(struct keytablist *list, int id, char *key); +// file operations struct keytablist *readdb(char *filename); void writedb(char *filename, struct keytablist *list); |