From 2b63d451d9f82c8598622714aba70dd33886292f Mon Sep 17 00:00:00 2001 From: bnnm Date: Thu, 29 Mar 2018 21:03:25 +0200 Subject: [PATCH] Minor tweaks to get_streamfile_name and co --- src/meta/txth.c | 11 +++++------ src/streamfile.c | 22 +++++++++------------- src/streamfile.h | 8 ++++---- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/meta/txth.c b/src/meta/txth.c index 030ca461..3923e08f 100644 --- a/src/meta/txth.c +++ b/src/meta/txth.c @@ -385,14 +385,14 @@ static STREAMFILE * open_txth(STREAMFILE * streamFile) { STREAMFILE * streamText; /* try "(path/)(name.ext).txth" */ - if (!get_streamfile_name(streamFile,filename,PATH_LIMIT)) goto fail; + get_streamfile_name(streamFile,filename,PATH_LIMIT); strcat(filename, ".txth"); streamText = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE); if (streamText) return streamText; /* try "(path/)(.ext).txth" */ - if (!get_streamfile_path(streamFile,filename,PATH_LIMIT)) goto fail; - if (!get_streamfile_ext(streamFile,fileext,PATH_LIMIT)) goto fail; + get_streamfile_path(streamFile,filename,PATH_LIMIT); + get_streamfile_ext(streamFile,fileext,PATH_LIMIT); strcat(filename,"."); strcat(filename, fileext); strcat(filename, ".txth"); @@ -400,14 +400,13 @@ static STREAMFILE * open_txth(STREAMFILE * streamFile) { if (streamText) return streamText; /* try "(path/).txth" */ - if (!get_streamfile_path(streamFile,filename,PATH_LIMIT)) goto fail; + get_streamfile_path(streamFile,filename,PATH_LIMIT); strcat(filename, ".txth"); streamText = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE); if (streamText) return streamText; -fail: /* not found */ - return 0; + return NULL; } /* Simple text parser of "key = value" lines. diff --git a/src/streamfile.c b/src/streamfile.c index a02c2ab8..0b6a87b6 100644 --- a/src/streamfile.c +++ b/src/streamfile.c @@ -772,7 +772,7 @@ STREAMFILE * open_stream_ext(STREAMFILE *streamFile, const char * ext) { return streamFile->open(streamFile,filename_ext,STREAMFILE_DEFAULT_BUFFER_SIZE); } -/* Opens an stream using the passed name (in the same folder) */ +/* Opens an stream using the passed name, in the same folder */ STREAMFILE * open_stream_name(STREAMFILE *streamFile, const char * name) { char foldername[PATH_LIMIT]; char filename[PATH_LIMIT]; @@ -871,9 +871,8 @@ fail: /** - * checks if the stream filename is one of the extensions (comma-separated, ex. "adx" or "adx,aix") - * - * returns 0 on failure + * Checks if the stream filename is one of the extensions (comma-separated, ex. "adx" or "adx,aix"). + * Empty is ok to accept files without extension ("", "adx,,aix"). Returns 0 on failure */ int check_extensions(STREAMFILE *streamFile, const char * cmp_exts) { char filename[PATH_LIMIT]; @@ -948,14 +947,15 @@ int find_chunk(STREAMFILE *streamFile, uint32_t chunk_id, off_t start_offset, in return 0; } -int get_streamfile_name(STREAMFILE *streamFile, char * buffer, size_t size) { +void get_streamfile_name(STREAMFILE *streamFile, char * buffer, size_t size) { streamFile->get_name(streamFile,buffer,size); - return 1; } -int get_streamfile_filename(STREAMFILE *streamFile, char * buffer, size_t size) { +/* copies the filename without path */ +void get_streamfile_filename(STREAMFILE *streamFile, char * buffer, size_t size) { char foldername[PATH_LIMIT]; const char *path; + streamFile->get_name(streamFile,foldername,sizeof(foldername)); //todo Windows CMD accepts both \\ and /, better way to handle this? @@ -971,9 +971,8 @@ int get_streamfile_filename(STREAMFILE *streamFile, char * buffer, size_t size) } else { strcpy(buffer, foldername); } - return 1; } -int get_streamfile_path(STREAMFILE *streamFile, char * buffer, size_t size) { +void get_streamfile_path(STREAMFILE *streamFile, char * buffer, size_t size) { const char *path; streamFile->get_name(streamFile,buffer,size); @@ -986,11 +985,8 @@ int get_streamfile_path(STREAMFILE *streamFile, char * buffer, size_t size) { } else { buffer[0] = '\0'; } - - return 1; } -int get_streamfile_ext(STREAMFILE *streamFile, char * filename, size_t size) { +void get_streamfile_ext(STREAMFILE *streamFile, char * filename, size_t size) { streamFile->get_name(streamFile,filename,size); strcpy(filename, filename_extension(filename)); - return 1; } diff --git a/src/streamfile.h b/src/streamfile.h index 2f920f85..53b2b8f6 100644 --- a/src/streamfile.h +++ b/src/streamfile.h @@ -177,8 +177,8 @@ int find_chunk_be(STREAMFILE *streamFile, uint32_t chunk_id, off_t start_offset, int find_chunk_le(STREAMFILE *streamFile, uint32_t chunk_id, off_t start_offset, int full_chunk_size, off_t *out_chunk_offset, size_t *out_chunk_size); int find_chunk(STREAMFILE *streamFile, uint32_t chunk_id, off_t start_offset, int full_chunk_size, off_t *out_chunk_offset, size_t *out_chunk_size, int size_big_endian, int zero_size_end); -int get_streamfile_name(STREAMFILE *streamFile, char * buffer, size_t size); -int get_streamfile_filename(STREAMFILE *streamFile, char * buffer, size_t size); -int get_streamfile_path(STREAMFILE *streamFile, char * buffer, size_t size); -int get_streamfile_ext(STREAMFILE *streamFile, char * filename, size_t size); +void get_streamfile_name(STREAMFILE *streamFile, char * buffer, size_t size); +void get_streamfile_filename(STREAMFILE *streamFile, char * buffer, size_t size); +void get_streamfile_path(STREAMFILE *streamFile, char * buffer, size_t size); +void get_streamfile_ext(STREAMFILE *streamFile, char * filename, size_t size); #endif