This commit is contained in:
Murphy 2023-12-17 11:10:04 -05:00
parent 081bdb7062
commit e0eacfa977
No known key found for this signature in database
GPG key ID: 988032A5638EE799
22 changed files with 49 additions and 57 deletions

View file

@ -3,9 +3,11 @@ OUT = $(BIN)/out
INS = /usr/local/bin/nbtvis 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)) 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 = LDFLAGS =
CC = gcc CC = gcc

9
compile_flags.txt Normal file
View file

@ -0,0 +1,9 @@
-c
-std=gnu17
-Wall
-Wextra
-pedantic
-O2
-Ilib
-Inbt
-Isrc

View file

@ -1,7 +1,8 @@
#include "map.h"
#include "lib.h" #include "lib.h"
#include "tag.h" #include "nbt.h"
#include "map.h"
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>

View file

@ -2,14 +2,14 @@
#include <stdint.h> #include <stdint.h>
typedef struct tag_t tag_t; struct tag_t;
typedef struct { typedef struct {
uint32_t len; uint32_t len;
uint32_t capacity; uint32_t capacity;
tag_t *entries; struct tag_t *entries;
} map_t; } map_t;
void map_init(map_t *map); void map_init(map_t *map);
void map_free(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);

View file

@ -7,8 +7,6 @@
typedef struct { typedef struct {
FILE *__file; FILE *__file;
bool __alloc; bool __alloc;
char peakbuf[16];
int peakamt;
} stream_t; } stream_t;
stream_t stream_open(const char *path, const char* mode); stream_t stream_open(const char *path, const char* mode);

View file

@ -1,8 +1,8 @@
#include "json.h"
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include "nbt.h"
static char buf[1024]; static char buf[1024];
__attribute__((format(printf, 3, 4))) __attribute__((format(printf, 3, 4)))

View file

@ -1,12 +1,12 @@
#include "json.h"
#include "../lib.h"
#include <ctype.h> #include <ctype.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "nbt.h"
#include "lib.h"
static char ret = '\0'; static char ret = '\0';
typedef enum { typedef enum {

View file

@ -1,8 +1,5 @@
#include "tag.h" #include "nbt.h"
#include "map.h" #include "map.h"
#include "nbt/nbt.h"
#include "snbt/snbt.h"
#include "json/json.h"
#include <stdlib.h> #include <stdlib.h>

View file

@ -1,14 +1,13 @@
#pragma once #pragma once
#include "stream.h"
#include "map.h"
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#include "map.h"
#include "stream.h"
typedef enum: int8_t { typedef enum: int8_t {
TAG_END = 0, TAG_END = 0,
TAG_BYTE = 1, TAG_BYTE = 1,
@ -25,8 +24,6 @@ typedef enum: int8_t {
TAG_LONG_ARRAY = 12 TAG_LONG_ARRAY = 12
} tagtype_t ; } tagtype_t ;
struct tag_t;
typedef union { typedef union {
int8_t b; int8_t b;
int16_t s; int16_t s;
@ -72,6 +69,16 @@ typedef enum {
} format_t; } format_t;
void tag_free(tag_t *tag); void tag_free(tag_t *tag);
bool tag_read(tag_t *tag, const stream_t *stream, format_t format); 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 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);

View file

@ -1,5 +1,5 @@
#include "nbt.h" #include "nbt.h"
#include "../lib.h" #include "lib.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>

View file

@ -1,7 +1,8 @@
#include "snbt.h"
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include "nbt.h"
static char buf[1024]; static char buf[1024];
__attribute__((format(printf, 3, 4))) __attribute__((format(printf, 3, 4)))

View file

@ -1,10 +1,10 @@
#include "snbt.h"
#include "../lib.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "nbt.h"
#include "lib.h"
typedef enum { typedef enum {
TOK_RBRACE, TOK_RBRACE,
TOK_LBRACE, TOK_LBRACE,

View file

@ -2,6 +2,7 @@
#include "lib.h" #include "lib.h"
#include "stream.h" #include "stream.h"
#include <string.h>
#include <strings.h> #include <strings.h>
static format_t get_file_extension(char *path) { static format_t get_file_extension(char *path) {

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "tag.h" #include "nbt.h"
#include "stream.h" #include "stream.h"
typedef struct { typedef struct {

View file

@ -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);

View file

@ -1,20 +1,19 @@
#include "lib.h" #include "lib.h"
#include "stream.h" #include "stream.h"
#include "tag.h"
#include "flags.h" #include "flags.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
__attribute__((__noreturn__)) __attribute__((__noreturn__))
void version() { void version(void) {
fprintf(stderr, "nbtvis v0.0.1\n"); fprintf(stderr, "nbtvis v0.0.1\n");
fprintf(stderr, "Copyright (C) 2023 Freya Murphy\n"); fprintf(stderr, "Copyright (C) 2023 Freya Murphy\n");
exit(0); exit(0);
} }
__attribute__((__noreturn__)) __attribute__((__noreturn__))
void help() { void help(void) {
fprintf(stderr, "Usage: nbtvis [OPTION]... [INFILE] [OUTFILE]\n\n"); fprintf(stderr, "Usage: nbtvis [OPTION]... [INFILE] [OUTFILE]\n\n");
fprintf(stderr, "\t-j\tinput data is JSON\n"); fprintf(stderr, "\t-j\tinput data is JSON\n");
fprintf(stderr, "\t-s\tinput data is SNBT\n"); fprintf(stderr, "\t-s\tinput data is SNBT\n");

View file

@ -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);

View file

@ -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);