aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/hash_table.c11
-rw-r--r--src/helpers.c6
-rw-r--r--src/main.c4
-rw-r--r--src/opcodes.c6
-rw-r--r--src/tsv.c32
5 files changed, 53 insertions, 6 deletions
diff --git a/src/hash_table.c b/src/hash_table.c
new file mode 100644
index 0000000..cced194
--- /dev/null
+++ b/src/hash_table.c
@@ -0,0 +1,11 @@
+#include <hash_table.h>
+#include <stdlib.h>
+#include <helpers.h>
+
+ht_t *init_ht(size_t size) {
+ ht_t *ht = safe_calloc(1, sizeof(size));
+ size_t realsize = size == 0 ? DEFAULT_HT_SIZE : size;
+ ht->buckets = safe_calloc(realsize, sizeof(sll_t *));
+ ht->size = realsize;
+ return ht;
+}
diff --git a/src/helpers.c b/src/helpers.c
index ad7228e..8485dc6 100644
--- a/src/helpers.c
+++ b/src/helpers.c
@@ -3,6 +3,12 @@
#include <stdlib.h>
#include <string.h>
+void die_lz(int code, const char *msg) {
+ if (code < 0) {
+ die(msg);
+ }
+}
+
void die(const char *msg) {
fprintf(stderr, "panic: ");
perror(msg);
diff --git a/src/main.c b/src/main.c
index 8555da1..7a17966 100644
--- a/src/main.c
+++ b/src/main.c
@@ -14,6 +14,7 @@
#include <array.h>
#include <better_string.h>
+#include <hash_table.h>
#include <helpers.h>
#include <opcodes.h>
#include <protocol.h>
@@ -22,6 +23,9 @@ int PORT = DEFAULT_PORT;
int nfds = 1;
struct pollfd fds[MAX_CONNECTIONS * 2];
+ht_t *USERS;
+ht_t *CHAN;
+
void handle_sigint(int sig) {
for (int i = 0; i < nfds; i++) {
if (fds[i].fd >= 0) {
diff --git a/src/opcodes.c b/src/opcodes.c
index 66742db..8fc51f2 100644
--- a/src/opcodes.c
+++ b/src/opcodes.c
@@ -3,12 +3,6 @@
#include <helpers.h>
-void die_lz(int code, const char *msg) {
- if (code < 0) {
- die(msg);
- }
-}
-
char *decode_client_opcode(int op) {
return "implement me";
}
diff --git a/src/tsv.c b/src/tsv.c
new file mode 100644
index 0000000..9b1c2be
--- /dev/null
+++ b/src/tsv.c
@@ -0,0 +1,32 @@
+#include <stdlib.h>
+#include <stdbool.h>
+
+#include <tsv.h>
+#include <helpers.h>
+#include <better_string.h>
+
+tsv_t *init_tsv(char *source) {
+ tsv_t *tsv = safe_calloc(1, sizeof(tsv_t *));
+ tsv->source = source;
+ tsv->i = 0;
+ tsv->c = tsv->source[tsv->i];
+ return tsv;
+}
+
+void tsv_move(tsv_t *tsv) {
+ if (tsv->c != '\0') {
+ tsv->i++;
+ tsv->c = tsv->source[tsv->i];
+ }
+}
+
+string_t *tsv_next(tsv_t *tsv) {
+ string_t *s = init_string(NULL);
+ bool escape = false;
+ while (tsv->c != '\t' && !escape) {
+ if (tsv->c == '\0') break;
+ string_push(s, tsv->c);
+ tsv_move(tsv);
+ }
+ return s;
+}