Commit Diff


commit - 1347c0741ba71526bb8e8aa4884d97b28ef7f3c0
commit + 63e79490c901009e46f3786cab44d4544fcff5de
blob - 3820021db84bdf0cd368b3343489d948258b4796
blob + eb9ff48e900de198c0092a95db2ef24c2de033ba
--- .gitignore
+++ .gitignore
@@ -1,6 +1,2 @@
 cmake-build*
-.cache
-build
-compile_commands.json
-test
 .idea
blob - 881aa99011bb10aab88cd733c397443922afcd34
blob + 98c11f89c5b349fed511ecc7aa41e3f5c1365e26
--- .gitlab-ci.yml
+++ .gitlab-ci.yml
@@ -6,3 +6,22 @@ test:
     - cmake .. 
     - make
     - ./test
+
+docs:
+  image: polinux/mkdocs
+  timeout: 5 minutes
+  rules:
+    - if: $CI_COMMIT_BRANCH == 'master'
+  script:
+    - apk add openssh-client
+    - mkdir -p ~/.ssh
+    - ssh-keyscan -H fputs.com >> ~/.ssh/known_hosts
+    - echo "$ssh_key" >> ~/.ssh/id_rsa
+    - chmod -R 700 ~/.ssh
+    - eval "$(ssh-agent -s)"
+    - ssh-add ~/.ssh/id_rsa
+    - mkdocs build
+    - ssh debian@fputs.com rm -rf /var/www/fputs/docs/spitwad
+    - ssh debian@fputs.com mkdir -p /var/www/fputs.com/docs/spitwad
+    - ssh debian@fputs.com chmod 755 /var/www/fputs.com/docs/spitwad
+    - scp -r ./site/* debian@fputs.com:/var/www/fputs.com/docs/spitwad/
blob - 4b899adf1583e4bebba39b85a578e14586e3eed3
blob + 32651074cfff77e8fa77957ca220106ac85d939e
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -1,7 +1,7 @@
 cmake_minimum_required(VERSION 3.25)
 project(spitwad C)
 
-set(CMAKE_C_STANDARD 11)
+set(CMAKE_C_STANDARD 99)
 
 add_library(spitwad STATIC spitwad.c)
 if(${CMAKE_PROJECT_NAME} STREQUAL spitwad)
blob - 0193223d3fd55a028cd6d07ebb9b32824fc768f8
blob + a9e26a92b4ea533f785837ef6cc73f7feb765fdd
--- spitwad.c
+++ spitwad.c
@@ -19,7 +19,6 @@ static uint16_t getshort(const unsigned char* data, si
 static char* getstring(const unsigned char* data, size_t offset) {
     char* s = malloc(sizeof(char) * 9);
     strncpy(s, data + offset, 8);
-    s[8] = '\0';
     return s;
 }
 
@@ -62,7 +61,8 @@ int new_WAD(struct WAD* wad, const unsigned char* data
         wad->directory[j].length = getlong(data, i + 4);
 
         char *s = getstring(data, i + 8);
-        strcpy(wad->directory[j].name, s);
+        strncpy(wad->directory[j].name, s, 8);
+        wad->directory[j].name[8] = '\0';
         free(s);
     }
 
@@ -107,9 +107,17 @@ void destroy_WAD(struct WAD* wad) {
     free(wad->data);
     free(wad->directory);
     free(wad);
-    wad = NULL;
 }
 
+
 int write_to_file(struct WAD* wad, const char* path) {
-
+    FILE *fp = NULL;
+    fp = fopen(path, "wb");
+    if (fp == NULL) {
+        fprintf(stderr, "Failed to open %s\n", path);
+        return 1;
+    }
+    fwrite(wad->data, sizeof(unsigned char), wad->data_sz, fp);
+    fclose(fp);
+    return 0;
 }
blob - /dev/null
blob + c7a257db334ba1e0016097bff67da846c8847c19 (mode 644)
--- /dev/null
+++ docs/index.md
@@ -0,0 +1,15 @@
+# spitwad
+
+`spitwad` is a library for interacting with WAD files, popularized by ID games like DOOM and Quake. The "defining"
+feature is for WADs to be transmitted as data over the network and transformed to/from JSON (still working on that part!)
+
+Originally built as a joke between some friends after we laughed about how it would be easier to use WADs to send data 
+between applications then JSON, then the idea for a WAD library that could transform WADs to/from JSON was born.
+
+## Requirements
+
+Should work on any POSIX platform out of the box
+
+## Usage
+
+Docs are a work in progress!
\ No newline at end of file
blob - f8c126d3463dec98a4e19c992cec4a115a6968f4
blob + 3bd7f733e85e9ee7d265a5f09d0fd7e3654e5a5b
--- spitwad.h
+++ spitwad.h
@@ -1,5 +1,5 @@
-#ifndef SPITWAD_SPITWAD_H
-#define SPITWAD_SPITWAD_H
+#ifndef SPITWAD_H
+#define SPITWAD_H
 
 #include <stdint.h>
 #include <stdlib.h>
@@ -29,4 +29,4 @@ int new_WAD_from_file(struct WAD* wad, const char* pat
 void destroy_WAD(struct WAD* wad);
 int write_to_file(struct WAD* wad, const char* path);
 
-#endif //SPITWAD_SPITWAD_H
+#endif //SPITWAD_H
blob - /dev/null
blob + 9127b893dd48e64a6564fcd143fc9fe0dfea7116 (mode 644)
--- /dev/null
+++ mkdocs.yml
@@ -0,0 +1,6 @@
+site_name: spitwad
+site_url: https://fputs.com/docs/spitwad
+theme:
+  name: readthedocs
+nav:
+  - 'index.md'
\ No newline at end of file
blob - 53accdcca7dd11c8a981c9209a35865ccab0d733
blob + fd787e23c487a32031b5cede1f970877bd3c81e6
--- test.c
+++ test.c
@@ -1,18 +1,45 @@
 #include <stdlib.h>
 #include <assert.h>
 #include <string.h>
+#include <stdio.h>
 
 #include "spitwad.h"
 
-int main() {
-    struct WAD *wad = malloc(sizeof(struct WAD));
-    assert(new_WAD_from_file(wad, "DOOM1.WAD") == 0);
-
-    // Values from manually inspecting DOOM1.WAD with a third-party tool
+// Values from manually inspecting DOOM1.WAD with a third-party tool
+void assert_doom1_wad(struct WAD *wad) {
     assert(wad->type == IWAD);
     assert(wad->dir_sz == 1264);
     assert(wad->dir_offset == 4175796);
     assert(wad->directory[0].offset == 12);
     assert(wad->directory[0].length == 10752);
     assert(strcmp(wad->directory[0].name, "PLAYPAL") == 0);
+}
+
+void basic_test() {
+    struct WAD *wad = malloc(sizeof(struct WAD));
+    assert(new_WAD_from_file(wad, "DOOM1.WAD") == 0);
+    assert_doom1_wad(wad);
+    destroy_WAD(wad);
+    wad = NULL;
+}
+
+void read_write_test() {
+    struct WAD *orig = malloc(sizeof(struct WAD));
+    assert(new_WAD_from_file(orig, "DOOM1.WAD") == 0);
+
+    assert(write_to_file(orig, "TEST.WAD") == 0);
+    struct WAD *new = malloc(sizeof(struct WAD));
+    assert(new_WAD_from_file(new, "TEST.WAD") == 0);
+    assert_doom1_wad(new);
+
+    destroy_WAD(orig);
+    orig = NULL;
+    destroy_WAD(new);
+    new = NULL;
+    remove("TEST.WAD");
+}
+
+int main() {
+    basic_test();
+    read_write_test();
 }
\ No newline at end of file