From 2a654f25e8d428b885387517394640eeb56e7bf1 Mon Sep 17 00:00:00 2001 From: a dinosaur Date: Wed, 2 Oct 2019 12:26:12 +1000 Subject: [PATCH] move main to a new source file, update makefile to support multiple sources --- neotools/autoextract.c | 18 ++++++++++++++++++ neotools/neoadpcmextract.Makefile | 21 ++++++++++++++++----- neotools/neoadpcmextract.c | 17 ++++++----------- 3 files changed, 40 insertions(+), 16 deletions(-) create mode 100644 neotools/autoextract.c diff --git a/neotools/autoextract.c b/neotools/autoextract.c new file mode 100644 index 0000000..7d59615 --- /dev/null +++ b/neotools/autoextract.c @@ -0,0 +1,18 @@ +#include +#include "neoadpcmextract.h" + + +int main(int argc, char** argv) +{ + if (argc != 2) + return 1; + + // Open file. + FILE* file = fopen(argv[1], "rb"); + if (!file) + return 1; + + int err = vgmExtractSamples(file); + fclose(file); + return err; +} diff --git a/neotools/neoadpcmextract.Makefile b/neotools/neoadpcmextract.Makefile index a73fd7b..e6fe428 100644 --- a/neotools/neoadpcmextract.Makefile +++ b/neotools/neoadpcmextract.Makefile @@ -1,12 +1,23 @@ TARGET := neoadpcmextract -SOURCE := neoadpcmextract.c +SOURCE := autoextract.c neoadpcmextract.c CFLAGS := -std=c99 -O2 -pipe -Wall -Wextra -pedantic +LDFLAGS := $(CFLAGS) + +OBJECT := $(SOURCE:%.c=%.o) +DEPEND := $(OBJECT:%.o=%.d) + +.PHONY: default all clean +default: $(TARGET) all: $(TARGET) -$(TARGET): $(SOURCE) - $(CC) $(CFLAGS) $< -o $@ +$(TARGET): $(OBJECT) + $(CC) $(LDFLAGS) $^ -o $@ + +%.o: %.c + $(CC) $(CFLAGS) -MMD -c $< -o $@ + +-include: $(DEPEND) -.PHONY: clean clean: - rm -f $(TARGET) + rm -f $(TARGET) $(OBJECT) $(DEPEND) diff --git a/neotools/neoadpcmextract.c b/neotools/neoadpcmextract.c index 457731c..77a4750 100644 --- a/neotools/neoadpcmextract.c +++ b/neotools/neoadpcmextract.c @@ -61,22 +61,18 @@ int DecodeSample(FILE* fin, const char* name, Buffer* buf) return 0; } -int main(int argc, char** argv) +int vgmExtractSamples(FILE* file) { - if (argc != 2) - return 1; - - // Open file. - FILE* file = fopen(argv[1], "rb"); - if (!file) - return 1; - - // Search for pcm headers. Buffer smpBytes = {NULL, 0}; char namebuf[32]; int smpaCount = 0, smpbCount = 0; + + // Scan for pcm headers. while (!feof(file) && !ferror(file)) { + // Patterns to match (in hex): + // 67 66 82 - ADPCM-A + // 67 66 83 - ADPCM-B if (fgetc(file) != 0x67 || fgetc(file) != 0x66) continue; @@ -98,6 +94,5 @@ int main(int argc, char** argv) } free(smpBytes.data); - fclose(file); return 0; }