diff options
author | Freya Murphy <freya@freyacat.org> | 2023-12-17 11:10:04 -0500 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2023-12-17 11:10:04 -0500 |
commit | e0eacfa9773c83850ed5169d1e889ff845180581 (patch) | |
tree | 9f8bb433404ce7e4dda1b86ca4dd5d5a2fba10e9 | |
parent | snbt (diff) | |
download | nbtvis-e0eacfa9773c83850ed5169d1e889ff845180581.tar.gz nbtvis-e0eacfa9773c83850ed5169d1e889ff845180581.tar.bz2 nbtvis-e0eacfa9773c83850ed5169d1e889ff845180581.zip |
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | compile_flags.txt | 9 | ||||
-rw-r--r-- | lib/lib.c (renamed from src/lib.c) | 0 | ||||
-rw-r--r-- | lib/lib.h (renamed from src/lib.h) | 0 | ||||
-rw-r--r-- | lib/map.c (renamed from src/map.c) | 5 | ||||
-rw-r--r-- | lib/map.h (renamed from src/map.h) | 6 | ||||
-rw-r--r-- | lib/stream.c (renamed from src/stream.c) | 0 | ||||
-rw-r--r-- | lib/stream.h (renamed from src/stream.h) | 2 | ||||
-rw-r--r-- | nbt/json/print.c (renamed from src/json/print.c) | 4 | ||||
-rw-r--r-- | nbt/json/read.c (renamed from src/json/read.c) | 6 | ||||
-rw-r--r-- | nbt/nbt.c (renamed from src/tag.c) | 5 | ||||
-rw-r--r-- | nbt/nbt.h (renamed from src/tag.h) | 21 | ||||
-rw-r--r-- | nbt/nbt/print.c (renamed from src/nbt/print.c) | 0 | ||||
-rw-r--r-- | nbt/nbt/read.c (renamed from src/nbt/read.c) | 2 | ||||
-rw-r--r-- | nbt/snbt/print.c (renamed from src/snbt/print.c) | 3 | ||||
-rw-r--r-- | nbt/snbt/read.c (renamed from src/snbt/read.c) | 6 | ||||
-rw-r--r-- | src/flags.c | 1 | ||||
-rw-r--r-- | src/flags.h | 2 | ||||
-rw-r--r-- | src/json/json.h | 7 | ||||
-rw-r--r-- | src/main.c | 5 | ||||
-rw-r--r-- | src/nbt/nbt.h | 7 | ||||
-rw-r--r-- | src/snbt/snbt.h | 9 |
22 files changed, 49 insertions, 57 deletions
@@ -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 @@ -1,7 +1,8 @@ -#include "map.h" #include "lib.h" -#include "tag.h" +#include "nbt.h" +#include "map.h" +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -2,14 +2,14 @@ #include <stdint.h> -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 index 6780d02..6780d02 100644 --- a/src/stream.c +++ b/lib/stream.c diff --git a/src/stream.h b/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 index ab154b9..3b7cdb3 100644 --- a/src/json/print.c +++ b/nbt/json/print.c @@ -1,8 +1,8 @@ -#include "json.h" - #include <stdarg.h> #include <stdio.h> +#include "nbt.h" + static char buf[1024]; __attribute__((format(printf, 3, 4))) diff --git a/src/json/read.c b/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 <ctype.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> +#include "nbt.h" +#include "lib.h" + static char ret = '\0'; typedef enum { @@ -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 <stdlib.h> @@ -1,14 +1,13 @@ -#pragma once - -#include "stream.h" -#include "map.h" +#pragma once #include <stdint.h> #include <stdbool.h> #include <arpa/inet.h> -#include <string.h> #include <unistd.h> +#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 index 3f687dc..3f687dc 100644 --- a/src/nbt/print.c +++ b/nbt/nbt/print.c diff --git a/src/nbt/read.c b/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 <stdio.h> #include <stdlib.h> diff --git a/src/snbt/print.c b/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 <stdarg.h> #include <stdio.h> +#include "nbt.h" + static char buf[1024]; __attribute__((format(printf, 3, 4))) diff --git a/src/snbt/read.c b/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 <stdio.h> #include <stdlib.h> #include <string.h> +#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 <string.h> #include <strings.h> 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); @@ -1,20 +1,19 @@ #include "lib.h" #include "stream.h" -#include "tag.h" #include "flags.h" #include <stdio.h> #include <stdlib.h> __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); |