From: John Tsiombikas Date: Sun, 23 Sep 2018 05:49:24 +0000 (+0300) Subject: asscat example X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=assman;a=commitdiff_plain;h=782e5db5669270f2b3046aafc2e909ac3e749393 asscat example --- diff --git a/examples/asscat/Makefile b/examples/asscat/Makefile new file mode 100644 index 0000000..6a41b75 --- /dev/null +++ b/examples/asscat/Makefile @@ -0,0 +1,13 @@ +obj = asscat.o +bin = asscat +root = ../.. + +CFLAGS = -pedantic -Wall -g -I$(root)/src +LDFLAGS = -L$(root) -Wl,-rpath=$(root) -lassman + +$(bin): $(obj) + $(CC) -o $@ $(obj) $(LDFLAGS) + +.PHONY: clean +clean: + rm -f $(obj) $(bin) diff --git a/examples/asscat/asscat.c b/examples/asscat/asscat.c new file mode 100644 index 0000000..799b6b0 --- /dev/null +++ b/examples/asscat/asscat.c @@ -0,0 +1,62 @@ +#include +#include +#include "assman.h" + +void print_usage(const char *argv0); + +int main(int argc, char **argv) +{ + int i, rdsz; + const char *prefix = 0; + ass_file *fp; + static char buf[1024]; + + for(i=1; i 0) { + fwrite(buf, 1, rdsz, stdout); + } + fflush(stdout); + ass_fclose(fp); + } + } + + return 0; +} + +void print_usage(const char *argv0) +{ + printf("Usage: %s [options] ... \n"); + printf("Options:\n"); + printf(" -prefix sets the path prefix to match for subsequent asset sources\n"); + printf(" -path filesystem asset source\n"); + printf(" -archive archive asset source\n"); + printf(" -url url asset source\n"); + printf(" -h,-help print usage and exit\n"); +} diff --git a/src/assman.c b/src/assman.c index 2e263e6..735cc16 100644 --- a/src/assman.c +++ b/src/assman.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "assman_impl.h" static int add_fop(const char *prefix, int type, struct ass_fileops *fop); @@ -108,11 +109,12 @@ ass_file *ass_fopen(const char *fname, const char *mode) void *mfile; ass_file *file; FILE *fp; + const char *after_prefix; m = mlist; while(m) { - if(match_prefix(fname, m->prefix)) { - if((mfile = m->fop->open(fname, m->fop->udata))) { + if((after_prefix = match_prefix(fname, m->prefix))) { + if((mfile = m->fop->open(after_prefix, m->fop->udata))) { if(!(file = malloc(sizeof *file))) { perror("assman: ass_fopen failed to allocate file structure"); m->fop->close(mfile, m->fop->udata); @@ -139,6 +141,7 @@ ass_file *ass_fopen(const char *fname, const char *mode) /* nothing matched, or failed to open, try the filesystem */ if((fp = fopen(fname, mode))) { if(!(file = malloc(sizeof *file))) { + ass_errno = errno; perror("assman: ass_fopen failed to allocate file structure"); fclose(fp); return 0; @@ -153,6 +156,7 @@ ass_file *ass_fopen(const char *fname, const char *mode) } return file; } + ass_errno = errno; return 0; } diff --git a/src/mod_path.c b/src/mod_path.c index 1a680e6..fa01776 100644 --- a/src/mod_path.c +++ b/src/mod_path.c @@ -53,12 +53,12 @@ void ass_free_path(struct ass_fileops *fop) static void *fop_open(const char *fname, void *udata) { - const char *prefix = (char*)udata; + const char *asspath = (char*)udata; char *path; FILE *fp; - path = alloca(strlen(prefix) + strlen(fname) + 2); - sprintf(path, "%s/%s", path, fname); + path = alloca(strlen(asspath) + strlen(fname) + 2); + sprintf(path, "%s/%s", asspath, fname); if(!(fp = fopen(path, "rb"))) { ass_errno = errno; diff --git a/src/mod_url.c b/src/mod_url.c index f254b68..c8c62cb 100644 --- a/src/mod_url.c +++ b/src/mod_url.c @@ -66,5 +66,13 @@ static long fop_read(void *fp, void *buf, long size, void *udata) } #else -int ass_mod_url_disabled; +struct ass_fileops *ass_alloc_url(const char *url) +{ + fprintf(stderr, "assman: compiled without URL asset source support\n"); + return 0; +} + +void ass_free_url(struct ass_fileops *fop) +{ +} #endif