From c7bf5111c7db05dc5b1750ff285e343849293dd3 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 10 Dec 2012 21:18:46 +0100 Subject: core: path: run uncrustify Even if this is not so bad as other files, I need to add some stuff so... why not!? `uncrustify -l C -c TOOLS/uncrustify.cfg --no-backup --replace core/path.h` `uncrustify -l C -c TOOLS/uncrustify.cfg --no-backup --replace core/path.c` The header was unchanged by the tool. --- core/path.c | 166 +++++++++++++++++++++++++++++++----------------------------- 1 file changed, 86 insertions(+), 80 deletions(-) diff --git a/core/path.c b/core/path.c index 0e8d5e4614..3a2d4c09ba 100644 --- a/core/path.c +++ b/core/path.c @@ -48,98 +48,102 @@ #include "osdep/io.h" -char *get_path(const char *filename){ - char *homedir; - char *buff; +char *get_path(const char *filename) +{ + char *homedir; + char *buff; #ifdef __MINGW32__ - static char *config_dir = "/mpv"; + static char *config_dir = "/mpv"; #else - static char *config_dir = "/.mpv"; + static char *config_dir = "/.mpv"; #endif #if defined(__MINGW32__) || defined(__CYGWIN__) - char exedir[260]; + char exedir[260]; #endif - int len; + int len; #ifdef CONFIG_MACOSX_BUNDLE - struct stat dummy; - CFIndex maxlen=256; - CFURLRef res_url_ref=NULL; - CFURLRef bdl_url_ref=NULL; - char *res_url_path = NULL; - char *bdl_url_path = NULL; + struct stat dummy; + CFIndex maxlen = 256; + CFURLRef res_url_ref = NULL; + CFURLRef bdl_url_ref = NULL; + char *res_url_path = NULL; + char *bdl_url_path = NULL; #endif - if ((homedir = getenv("MPV_HOME")) != NULL) - config_dir = ""; - else if ((homedir = getenv("HOME")) == NULL) + if ((homedir = getenv("MPV_HOME")) != NULL) + config_dir = ""; + else if ((homedir = getenv("HOME")) == NULL) #if defined(__MINGW32__) || defined(__CYGWIN__) - /* Hack to get fonts etc. loaded outside of Cygwin environment. */ - { - int i,imax=0; - len = (int)GetModuleFileNameA(NULL, exedir, 260); - for (i=0; i < len; i++) - if (exedir[i] =='\\') - {exedir[i]='/'; imax=i;} - exedir[imax]='\0'; - homedir = exedir; - } + /* Hack to get fonts etc. loaded outside of Cygwin environment. */ + { + int i, imax = 0; + len = (int)GetModuleFileNameA(NULL, exedir, 260); + for (i = 0; i < len; i++) + if (exedir[i] == '\\') { + exedir[i] = '/'; + imax = i; + } + exedir[imax] = '\0'; + homedir = exedir; + } #else - return NULL; + return NULL; #endif - len = strlen(homedir) + strlen(config_dir) + 1; - if (filename == NULL) { - if ((buff = malloc(len)) == NULL) - return NULL; - sprintf(buff, "%s%s", homedir, config_dir); - } else { - len += strlen(filename) + 1; - if ((buff = malloc(len)) == NULL) - return NULL; - sprintf(buff, "%s%s/%s", homedir, config_dir, filename); - } + len = strlen(homedir) + strlen(config_dir) + 1; + if (filename == NULL) { + if ((buff = malloc(len)) == NULL) + return NULL; + sprintf(buff, "%s%s", homedir, config_dir); + } else { + len += strlen(filename) + 1; + if ((buff = malloc(len)) == NULL) + return NULL; + sprintf(buff, "%s%s/%s", homedir, config_dir, filename); + } #ifdef CONFIG_MACOSX_BUNDLE - if (stat(buff, &dummy)) { - - res_url_ref=CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle()); - bdl_url_ref=CFBundleCopyBundleURL(CFBundleGetMainBundle()); - - if (res_url_ref&&bdl_url_ref) { - - res_url_path=malloc(maxlen); - bdl_url_path=malloc(maxlen); - - while (!CFURLGetFileSystemRepresentation(res_url_ref, true, res_url_path, maxlen)) { - maxlen*=2; - res_url_path=realloc(res_url_path, maxlen); - } - CFRelease(res_url_ref); - - while (!CFURLGetFileSystemRepresentation(bdl_url_ref, true, bdl_url_path, maxlen)) { - maxlen*=2; - bdl_url_path=realloc(bdl_url_path, maxlen); - } - CFRelease(bdl_url_ref); - - if (strcmp(res_url_path, bdl_url_path) == 0) - res_url_path = NULL; - } - - if (res_url_path&&filename) { - if ((strlen(filename)+strlen(res_url_path)+2)>maxlen) { - maxlen=strlen(filename)+strlen(res_url_path)+2; - } - free(buff); - buff = malloc(maxlen); - strcpy(buff, res_url_path); - - strcat(buff,"/"); - strcat(buff, filename); - } - } + if (stat(buff, &dummy)) { + + res_url_ref = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle()); + bdl_url_ref = CFBundleCopyBundleURL(CFBundleGetMainBundle()); + + if (res_url_ref && bdl_url_ref) { + + res_url_path = malloc(maxlen); + bdl_url_path = malloc(maxlen); + + while (!CFURLGetFileSystemRepresentation(res_url_ref, true, + res_url_path, maxlen)) { + maxlen *= 2; + res_url_path = realloc(res_url_path, maxlen); + } + CFRelease(res_url_ref); + + while (!CFURLGetFileSystemRepresentation(bdl_url_ref, true, + bdl_url_path, maxlen)) { + maxlen *= 2; + bdl_url_path = realloc(bdl_url_path, maxlen); + } + CFRelease(bdl_url_ref); + + if (strcmp(res_url_path, bdl_url_path) == 0) + res_url_path = NULL; + } + + if (res_url_path && filename) { + if ((strlen(filename) + strlen(res_url_path) + 2) > maxlen) + maxlen = strlen(filename) + strlen(res_url_path) + 2; + free(buff); + buff = malloc(maxlen); + strcpy(buff, res_url_path); + + strcat(buff, "/"); + strcat(buff, filename); + } + } #endif - mp_msg(MSGT_GLOBAL,MSGL_V,"get_path('%s') -> '%s'\n",filename,buff); - return buff; + mp_msg(MSGT_GLOBAL, MSGL_V, "get_path('%s') -> '%s'\n", filename, buff); + return buff; } char *mp_basename(const char *path) @@ -160,7 +164,9 @@ char *mp_basename(const char *path) struct bstr mp_dirname(const char *path) { - struct bstr ret = {(uint8_t *)path, mp_basename(path) - path}; + struct bstr ret = { + (uint8_t *)path, mp_basename(path) - path + }; if (ret.len == 0) return bstr0("."); return ret; @@ -185,7 +191,7 @@ char *mp_path_join(void *talloc_ctx, struct bstr p1, struct bstr p2) int endchar1 = p1.start[p1.len - 1]; #if HAVE_DOS_PATHS have_separator = endchar1 == '/' || endchar1 == '\\' - || p1.len == 2 && endchar1 == ':'; // "X:" only + || p1.len == 2 && endchar1 == ':'; // "X:" only #else have_separator = endchar1 == '/'; #endif -- cgit v1.2.3