summaryrefslogtreecommitdiff
path: root/src/table.c
diff options
context:
space:
mode:
authorjakob <jakob@memeware.net>2017-02-19 10:57:47 -0500
committerjakob <jakob@memeware.net>2017-02-19 10:57:47 -0500
commit32fb7b11d83138cc288d62c1f1674d95cc94e8de (patch)
tree290c5a27b58e24bb82bd46decba0aa5e1282e003 /src/table.c
parent1fc6cc323dbaa5387d84630615c0d4cab0c1c5ba (diff)
Implemented table linked list, decompression and encryption. Tests have been improved.
Diffstat (limited to 'src/table.c')
-rw-r--r--src/table.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/table.c b/src/table.c
new file mode 100644
index 0000000..84ab77f
--- /dev/null
+++ b/src/table.c
@@ -0,0 +1,73 @@
+/* table.c -- Code for handling the archive's table section.
+
+ Copyright (C) 2017 Jakob Tsar-Fox, All Rights Reserved.
+
+ This file is part of Nekopack.
+
+ Nekopack is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation, either version 3 of the License, or (at
+ your option) any later version.
+
+ Nekopack is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Nekopack. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+#include "io.h"
+#include "table.h"
+
+#define ELIF_MAGIC 0x46696c65
+#define FILE_MAGIC 0x656c6946
+#define HNFN_MAGIC 0x6e666e68
+#define NEKO_MAGIC 0x6f6b656e
+
+
+/* Returns the root of a linked list containing all of the files listed
+ in the archive's table section. */
+struct table_entry *parse_table(struct stream *s) {
+ struct table_entry *cur, *root = calloc(sizeof(struct table_entry), 1);
+
+ bool ended = false;
+ uint32_t magic;
+ uint64_t size;
+
+ do {
+ stream_read(&magic, s, sizeof(uint32_t));
+ stream_read(&size, s, sizeof(uint64_t));
+
+ switch (magic) {
+ case ELIF_MAGIC:
+ case HNFN_MAGIC:
+ case NEKO_MAGIC:
+ break;
+ case FILE_MAGIC:
+ break;
+ default:
+ ended = 1;
+ }
+ } while (!ended);
+}
+
+
+/* Inserts `e` to the end of the linked list specified by `root`. */
+void entry_append(struct table_entry *root, struct table_entry *e) {
+ struct table_entry *cur;
+ for (cur = root; cur->next != NULL; cur = cur->next);
+ cur->next = e;
+}
+
+
+/* Frees every entry in the linked list specified by `cur`. */
+void entry_free(struct table_entry *cur) {
+ if (cur->next != NULL)
+ entry_free(cur->next);
+ free(cur);
+}