diff --git a/Makefile b/Makefile index 9613a70..138719b 100644 --- a/Makefile +++ b/Makefile @@ -2,10 +2,12 @@ BIN = bin OUT = $(BIN)/out INS = /usr/local/bin/nbtvis -SRC = $(shell find src -type f -name "*.c") +SRC = $(shell find src -type f -name "*.c") +SRC += $(shell find lib -type f -name "*.c") +SRC += $(shell find nbt -type f -name "*.c") OBJ = $(patsubst %.c,$(BIN)/%.o, $(SRC)) -CCFLAGS = -Isrc -std=c2x -Wall -Wextra -pedantic -O0 -g +CCFLAGS = -Isrc -Ilib -Inbt -std=c2x -Wall -Wextra -pedantic -O0 -g LDFLAGS = CC = gcc diff --git a/compile_flags.txt b/compile_flags.txt new file mode 100644 index 0000000..579ea57 --- /dev/null +++ b/compile_flags.txt @@ -0,0 +1,9 @@ +-c +-std=gnu17 +-Wall +-Wextra +-pedantic +-O2 +-Ilib +-Inbt +-Isrc diff --git a/src/lib.c b/lib/lib.c similarity index 100% rename from src/lib.c rename to lib/lib.c diff --git a/src/lib.h b/lib/lib.h similarity index 100% rename from src/lib.h rename to lib/lib.h diff --git a/src/map.c b/lib/map.c similarity index 98% rename from src/map.c rename to lib/map.c index 0c6d4f2..71300fb 100644 --- a/src/map.c +++ b/lib/map.c @@ -1,7 +1,8 @@ -#include "map.h" #include "lib.h" -#include "tag.h" +#include "nbt.h" +#include "map.h" +#include #include #include #include diff --git a/src/map.h b/lib/map.h similarity index 64% rename from src/map.h rename to lib/map.h index 6672323..d2ab6f8 100644 --- a/src/map.h +++ b/lib/map.h @@ -2,14 +2,14 @@ #include -typedef struct tag_t tag_t; +struct tag_t; typedef struct { uint32_t len; uint32_t capacity; - tag_t *entries; + struct tag_t *entries; } map_t; void map_init(map_t *map); void map_free(map_t *map); -void map_put(map_t *map, tag_t *tag); +void map_put(map_t *map, struct tag_t *tag); diff --git a/src/stream.c b/lib/stream.c similarity index 100% rename from src/stream.c rename to lib/stream.c diff --git a/src/stream.h b/lib/stream.h similarity index 96% rename from src/stream.h rename to lib/stream.h index 7dc5407..d9a05ce 100644 --- a/src/stream.h +++ b/lib/stream.h @@ -7,8 +7,6 @@ typedef struct { FILE *__file; bool __alloc; - char peakbuf[16]; - int peakamt; } stream_t; stream_t stream_open(const char *path, const char* mode); diff --git a/src/json/print.c b/nbt/json/print.c similarity index 99% rename from src/json/print.c rename to nbt/json/print.c index ab154b9..3b7cdb3 100644 --- a/src/json/print.c +++ b/nbt/json/print.c @@ -1,8 +1,8 @@ -#include "json.h" - #include #include +#include "nbt.h" + static char buf[1024]; __attribute__((format(printf, 3, 4))) diff --git a/src/json/read.c b/nbt/json/read.c similarity index 99% rename from src/json/read.c rename to nbt/json/read.c index dbb246a..3316b55 100644 --- a/src/json/read.c +++ b/nbt/json/read.c @@ -1,12 +1,12 @@ -#include "json.h" -#include "../lib.h" - #include #include #include #include #include +#include "nbt.h" +#include "lib.h" + static char ret = '\0'; typedef enum { diff --git a/src/tag.c b/nbt/nbt.c similarity index 94% rename from src/tag.c rename to nbt/nbt.c index 8f1502c..a2a21d5 100644 --- a/src/tag.c +++ b/nbt/nbt.c @@ -1,8 +1,5 @@ -#include "tag.h" +#include "nbt.h" #include "map.h" -#include "nbt/nbt.h" -#include "snbt/snbt.h" -#include "json/json.h" #include diff --git a/src/tag.h b/nbt/nbt.h similarity index 74% rename from src/tag.h rename to nbt/nbt.h index 81d1950..97c4d3b 100644 --- a/src/tag.h +++ b/nbt/nbt.h @@ -1,14 +1,13 @@ -#pragma once - -#include "stream.h" -#include "map.h" +#pragma once #include #include #include -#include #include +#include "map.h" +#include "stream.h" + typedef enum: int8_t { TAG_END = 0, TAG_BYTE = 1, @@ -25,8 +24,6 @@ typedef enum: int8_t { TAG_LONG_ARRAY = 12 } tagtype_t ; -struct tag_t; - typedef union { int8_t b; int16_t s; @@ -72,6 +69,16 @@ typedef enum { } format_t; void tag_free(tag_t *tag); + bool tag_read(tag_t *tag, const stream_t *stream, format_t format); bool tag_print(tag_t *tag, const stream_t *stream, format_t format); +bool json_read(tag_t *tag, const stream_t *stream); +bool json_print(const tag_t *tag, const stream_t *stream); + +bool nbt_read(tag_t *tag, const stream_t *stream); +bool nbt_print(const tag_t *tag, const stream_t *stream); + +bool snbt_read(tag_t *tag, const stream_t *stream); +bool snbt_print(const tag_t *tag, const stream_t *stream); +bool snbt_allowed_ident(char c); diff --git a/src/nbt/print.c b/nbt/nbt/print.c similarity index 100% rename from src/nbt/print.c rename to nbt/nbt/print.c diff --git a/src/nbt/read.c b/nbt/nbt/read.c similarity index 99% rename from src/nbt/read.c rename to nbt/nbt/read.c index 38f8b14..9ed4f08 100644 --- a/src/nbt/read.c +++ b/nbt/nbt/read.c @@ -1,5 +1,5 @@ #include "nbt.h" -#include "../lib.h" +#include "lib.h" #include #include diff --git a/src/snbt/print.c b/nbt/snbt/print.c similarity index 99% rename from src/snbt/print.c rename to nbt/snbt/print.c index 9dec75c..c62cc0a 100644 --- a/src/snbt/print.c +++ b/nbt/snbt/print.c @@ -1,7 +1,8 @@ -#include "snbt.h" #include #include +#include "nbt.h" + static char buf[1024]; __attribute__((format(printf, 3, 4))) diff --git a/src/snbt/read.c b/nbt/snbt/read.c similarity index 99% rename from src/snbt/read.c rename to nbt/snbt/read.c index 231404a..0ee89d2 100644 --- a/src/snbt/read.c +++ b/nbt/snbt/read.c @@ -1,10 +1,10 @@ -#include "snbt.h" -#include "../lib.h" - #include #include #include +#include "nbt.h" +#include "lib.h" + typedef enum { TOK_RBRACE, TOK_LBRACE, diff --git a/src/flags.c b/src/flags.c index 9abe76c..55740e4 100644 --- a/src/flags.c +++ b/src/flags.c @@ -2,6 +2,7 @@ #include "lib.h" #include "stream.h" +#include #include static format_t get_file_extension(char *path) { diff --git a/src/flags.h b/src/flags.h index a14580b..95bb039 100644 --- a/src/flags.h +++ b/src/flags.h @@ -1,6 +1,6 @@ #pragma once -#include "tag.h" +#include "nbt.h" #include "stream.h" typedef struct { diff --git a/src/json/json.h b/src/json/json.h deleted file mode 100644 index 73b4f52..0000000 --- a/src/json/json.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include "../tag.h" -#include "../stream.h" - -bool json_read(tag_t *tag, const stream_t *stream); -bool json_print(const tag_t *tag, const stream_t *stream); diff --git a/src/main.c b/src/main.c index d49e5b6..010a262 100644 --- a/src/main.c +++ b/src/main.c @@ -1,20 +1,19 @@ #include "lib.h" #include "stream.h" -#include "tag.h" #include "flags.h" #include #include __attribute__((__noreturn__)) -void version() { +void version(void) { fprintf(stderr, "nbtvis v0.0.1\n"); fprintf(stderr, "Copyright (C) 2023 Freya Murphy\n"); exit(0); } __attribute__((__noreturn__)) -void help() { +void help(void) { fprintf(stderr, "Usage: nbtvis [OPTION]... [INFILE] [OUTFILE]\n\n"); fprintf(stderr, "\t-j\tinput data is JSON\n"); fprintf(stderr, "\t-s\tinput data is SNBT\n"); diff --git a/src/nbt/nbt.h b/src/nbt/nbt.h deleted file mode 100644 index 13c0606..0000000 --- a/src/nbt/nbt.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include "../tag.h" -#include "../stream.h" - -bool nbt_read(tag_t *tag, const stream_t *stream); -bool nbt_print(const tag_t *tag, const stream_t *stream); diff --git a/src/snbt/snbt.h b/src/snbt/snbt.h deleted file mode 100644 index 4b367bc..0000000 --- a/src/snbt/snbt.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include "../tag.h" -#include "../stream.h" - -bool snbt_read(tag_t *tag, const stream_t *stream); -bool snbt_print(const tag_t *tag, const stream_t *stream); - -bool snbt_allowed_ident(char c);