aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-02-20 19:04:21 +0100
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-03-30 08:20:21 +0200
commit4765653cb3af905a9b20f1e5f2277e50d801c43b (patch)
tree9c9f914e5ea9b19f2312cd43221df37d19dec2f3 /tools
parentc9754ac4300abad20d942ad18bc5bf611a0b3a2e (diff)
downloadjancity-4765653cb3af905a9b20f1e5f2277e50d801c43b.tar.gz
Add metadata header to media files
The following properties are supported: - Sound: "loop". Must be either 0 or 1 - Images: "transparent". Must be either 0 or 1 These headers are only used for non-PS1 builds, since .TIM and .VAG files do already implement such information.
Diffstat (limited to 'tools')
-rw-r--r--tools/CMakeLists.txt5
-rw-r--r--tools/add-header.c67
2 files changed, 71 insertions, 1 deletions
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
index 946eed7..843301d 100644
--- a/tools/CMakeLists.txt
+++ b/tools/CMakeLists.txt
@@ -1,4 +1,7 @@
cmake_minimum_required(VERSION 3.0)
project(utils)
add_executable(container "container.c")
-target_compile_options(container PUBLIC -g3)
+add_executable(add-header "add-header.c")
+set(cflags -Wall -g3)
+target_compile_options(container PUBLIC ${cflags})
+target_compile_options(add-header PUBLIC ${cflags})
diff --git a/tools/add-header.c b/tools/add-header.c
new file mode 100644
index 0000000..75f7458
--- /dev/null
+++ b/tools/add-header.c
@@ -0,0 +1,67 @@
+#include <errno.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main(int argc, char **const argv)
+{
+ int ret = EXIT_FAILURE;
+ FILE *in = NULL, *out = NULL;
+
+ if (argc < 3)
+ {
+ fprintf(stderr, "%s [arg ...] <in-file> <out-file>\n", *argv);
+ goto end;
+ }
+
+ const char *const in_path = argv[argc - 2],
+ *const out_path = argv[argc - 1];
+
+ if (!(out = fopen(out_path, "wb")))
+ {
+ fprintf(stderr, "could not open %s: %s\n", out_path, strerror(errno));
+ goto end;
+ }
+ else if (!(in = fopen(in_path, "rb")))
+ {
+ fprintf(stderr, "could not open %s: %s\n", in_path, strerror(errno));
+ goto end;
+ }
+
+ for (int i = 1; i < argc - 2; i++)
+ {
+ if (fprintf(out, "%s", argv[i]) < 0
+ || putc('\0', out) == EOF
+ || ferror(out))
+ {
+ fprintf(stderr, "failed writing to %s\n", out_path);
+ goto end;
+ }
+ }
+
+ while (!feof(in))
+ {
+ char c;
+
+ if ((!fread(&c, sizeof c, 1, in)
+ || !fwrite(&c, sizeof c, 1, out))
+ && (ferror(in) || ferror(out)))
+ {
+ fprintf(stderr, "ferror(%s)=%d, ferror(%s)=%d\n",
+ in_path, ferror(in), out_path, ferror(out));
+ goto end;
+ }
+ }
+
+ ret = EXIT_SUCCESS;
+
+end:
+ if (out)
+ fclose(out);
+
+ if (in)
+ fclose(in);
+
+ return ret;
+}