diff options
author | Freya Murphy <freya@freyacat.org> | 2023-12-15 23:02:45 -0500 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2023-12-15 23:02:45 -0500 |
commit | 42d1c82a0bfa615b832f5ecc2652edc290bf6e9c (patch) | |
tree | 09223f3ca9b54fc3cd5a7cb45180542cc3a8a1ba /src/main.c | |
parent | fix printing arrays (diff) | |
download | nbtvis-42d1c82a0bfa615b832f5ecc2652edc290bf6e9c.tar.gz nbtvis-42d1c82a0bfa615b832f5ecc2652edc290bf6e9c.tar.bz2 nbtvis-42d1c82a0bfa615b832f5ecc2652edc290bf6e9c.zip |
add json support and other things
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 54 |
1 files changed, 42 insertions, 12 deletions
@@ -1,24 +1,54 @@ -#include "tag.h" #include "lib.h" +#include "tag.h" +#include "flags.h" + #include <stdio.h> +#include <stdlib.h> + +__attribute__((__noreturn__)) +void version() { + fprintf(stderr, "nbtvis v0.0.1\n"); + fprintf(stderr, "Copyright (C) 2023 Freya Murphy\n"); + exit(0); +} + +__attribute__((__noreturn__)) +void help() { + 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"); + fprintf(stderr, "\t-n\tinput data is NBT\n"); + fprintf(stderr, "\t-J\toutput data is JSON\n"); + fprintf(stderr, "\t-S\toutput data is SNBT\n"); + fprintf(stderr, "\t-N\toutput data is NBT\n\n"); + fprintf(stderr, "\t-h --help\tprint the help message\n"); + fprintf(stderr, "\t-v --version\tprint the version\n"); + fprintf(stderr, "\t--in=<file>\tset input file name\n"); + fprintf(stderr, "\t--out=<file>\tset output file name\n"); + exit(0); +} + +int main(int argc, char **argv) { -int main (int argc, char** argv) { + flags_t flags; + parse_flags(&flags, argc, argv); - if (argc != 2) { - printf("usage: nbtvis file.nbt\n"); - return 0; - } + if (flags.help) + help(); - stream_t stream = stream_open(argv[1], "rb"); + if (flags.version) + version(); tag_t tag; - if (tag_read(&tag, &stream, true) == false) - error_and_die("failed to read tag\n"); + if (tag_read(&tag, &flags.in, flags.fin) == false) + error_and_die("error: failed to read tag\n"); if (tag.type != TAG_COMPOUND) - error_and_die("root tag is not of type compound\n"); + error_and_die("error: nbt tag not a valid compound tag\n"); - tag_print(&tag); + if (tag_print(&tag, &flags.out, flags.fout) == false) + error_and_die("error: failed to write tag\n"); + tag_free(&tag); - stream_close(&stream); + return 0; } |