diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2024-11-14 19:35:45 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2024-11-14 19:35:45 +0100 |
commit | df5520aa2dae5b3ce7abf8733dcdd152898af163 (patch) | |
tree | 00d3047bfb14f682bfb5a21010c731ed649bfed7 /app/bin/paths.c | |
parent | df247efec654e512242e4f4f1b0212034f9e01fe (diff) | |
parent | ec3c0f6f6e7153fa797dc57a0e95779cbc63a23b (diff) |
Merge branch 'release/debian/1_5.3.0GA-1'debian/1_5.3.0GA-1
Diffstat (limited to 'app/bin/paths.c')
-rw-r--r-- | app/bin/paths.c | 181 |
1 files changed, 87 insertions, 94 deletions
diff --git a/app/bin/paths.c b/app/bin/paths.c index 6c6bb10..785ff6f 100644 --- a/app/bin/paths.c +++ b/app/bin/paths.c @@ -17,32 +17,20 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include <stdlib.h> -#include <string.h> -#include <assert.h> -#include <stdarg.h> - -#ifdef WINDOWS -#include <windows.h> -#endif - -#include <wlib.h> #include <dynstring.h> #include "track.h" #include "common.h" -#include "utility.h" #include "misc.h" -#include "i18n.h" #include "uthash.h" #include "paths.h" struct pathTable { - char type[ PATH_TYPE_SIZE]; /**< type of path */ - DynString path; /**< path */ - UT_hash_handle hh; /**< makes this structure hashable */ + char type[ PATH_TYPE_SIZE]; /**< type of path */ + DynString path; /**< path */ + UT_hash_handle hh; /**< makes this structure hashable */ }; static struct pathTable *paths; @@ -63,9 +51,9 @@ static struct pathTable *FindPath(const char *type); static struct pathTable * FindPath(const char *type) { - struct pathTable *entry; - HASH_FIND_STR(paths, type, entry); - return (entry); + struct pathTable *entry; + HASH_FIND_STR(paths, type, entry); + return (entry); } /** @@ -77,19 +65,23 @@ FindPath(const char *type) static void AddPath(const char *type, char*path) { - struct pathTable *tableEntry; - tableEntry = FindPath(type); - - if (tableEntry) { - DynStringClear(&(tableEntry->path)); - } else { - tableEntry = malloc(sizeof(struct pathTable)); - DynStringMalloc(&tableEntry->path, 16); - strcpy(tableEntry->type, type); - HASH_ADD_STR(paths, type, tableEntry); - } - - DynStringCatCStr(&(tableEntry->path), path); + struct pathTable *tableEntry; + tableEntry = FindPath(type); + + if (tableEntry) { + DynStringClear(&(tableEntry->path)); + } else { + tableEntry = malloc(sizeof(struct pathTable)); + DynStringMalloc(&tableEntry->path, 16); + strcpy(tableEntry->type, type); +#ifdef WINDOWS +#pragma warning( disable : 4267) +#endif + // This generates warning C4267 on windows + HASH_ADD_STR(paths, type, tableEntry); + } + + DynStringCatCStr(&(tableEntry->path), path); } /** @@ -104,23 +96,23 @@ AddPath(const char *type, char*path) */ void SetCurrentPath( - const char * pathType, - const char * fileName) + const char * pathType, + const char * fileName) { - char *path; - char *copy; - assert(fileName != NULL); - assert(pathType != NULL); - copy = strdup(fileName); - path = strrchr(copy, FILE_SEP_CHAR[0]); - - if (path) { - *path = '\0'; - AddPath(pathType, copy); - wPrefSetString(PATHS_SECTION, pathType, copy); - } - - free(copy); + char *path; + char *copy; + CHECK(fileName != NULL); + CHECK(pathType != NULL); + copy = strdup(fileName); + path = strrchr(copy, FILE_SEP_CHAR[0]); + + if (path) { + *path = '\0'; + AddPath(pathType, copy); + wPrefSetString(PATHS_SECTION, pathType, copy); + } + + free(copy); } /** @@ -136,29 +128,29 @@ void SetCurrentPath( */ char *GetCurrentPath( - const char *pathType) + const char *pathType) { - struct pathTable *currentPath; - const char *path; - assert(pathType != NULL); - currentPath = FindPath(pathType); + struct pathTable *currentPath; + const char *path; + CHECK(pathType != NULL); + currentPath = FindPath(pathType); - if (currentPath) { - return (DynStringToCStr(&(currentPath->path))); - } + if (currentPath) { + return (DynStringToCStr(&(currentPath->path))); + } - path = wPrefGetString(PATHS_SECTION, pathType); + path = wPrefGetString(PATHS_SECTION, pathType); - if (!path) { - path = wPrefGetString("file", "directory"); - } + if (!path) { + path = wPrefGetString("file", "directory"); + } - if (!path) { - path = wGetUserHomeDir(); - } + if (!path) { + path = wGetUserHomeDir(); + } - AddPath(pathType, (char *)path); - return ((char *)path); + AddPath(pathType, (char *)path); + return ((char *)path); } /** @@ -185,16 +177,16 @@ void ConvertPathForward(char *string) char *FindFilename(char *path) { - char *name; - name = strrchr(path, FILE_SEP_CHAR[0]); + char *name; + name = strrchr(path, FILE_SEP_CHAR[0]); - if (name) { - name++; - } else { - name = path; - } + if (name) { + name++; + } else { + name = path; + } - return (name); + return (name); } /** @@ -204,7 +196,8 @@ char *FindFilename(char *path) * \return pointer to the file extension part, empty string if no extension present */ -char *FindFileExtension(char *path) { +char *FindFileExtension(char *path) +{ char *ext; ext = strrchr(path, '.'); @@ -231,25 +224,25 @@ char *FindFileExtension(char *path) { void MakeFullpath(char **str, ...) { - va_list valist; - const char *part; - char *separator = FILE_SEP_CHAR; - char lastchar = '\0'; - DynString path; - DynStringMalloc(&path, 0); - va_start(valist, str); - - while ((part = va_arg(valist, const char *))) { - if (part[0] !=separator[0] && lastchar && lastchar != separator[0] && - lastchar != ':') { - DynStringNCatCStr(&path, 1, separator); - } - - DynStringCatCStr(&path, part); - lastchar = part[strlen(part) - 1]; - } - - *str = strdup(DynStringToCStr(&path)); - DynStringFree(&path); + va_list valist; + const char *part; + char *separator = FILE_SEP_CHAR; + char lastchar = '\0'; + DynString path; + DynStringMalloc(&path, 0); + va_start(valist, str); + + while ((part = va_arg(valist, const char *))) { + if (part[0] !=separator[0] && lastchar && lastchar != separator[0] && + lastchar != ':') { + DynStringNCatCStr(&path, 1, separator); + } + + DynStringCatCStr(&path, part); + lastchar = part[strlen(part) - 1]; + } + + *str = strdup(DynStringToCStr(&path)); + DynStringFree(&path); va_end(valist); } |