From cc1259178b95d084a7ca9e83c90ef0ab97b7fa86 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 12 Apr 2012 02:15:33 +0000 Subject: code cleanup: utfconv library had some quite confusing formatting, also cleared som warnings. --- intern/CMakeLists.txt | 3 +- intern/SConscript | 2 +- intern/ghost/intern/GHOST_SystemPathsWin32.cpp | 8 +- intern/ghost/intern/GHOST_SystemPathsWin32.h | 2 +- intern/ghost/intern/GHOST_SystemWin32.cpp | 29 +-- intern/utfconv/CMakeLists.txt | 18 ++ intern/utfconv/utf_winfunc.c | 65 +++--- intern/utfconv/utfconv.c | 273 ++++++++++++++----------- intern/utfconv/utfconv.h | 28 +-- source/blender/blenlib/intern/fileops.c | 40 ++-- source/blender/blenlib/intern/storage.c | 22 +- source/creator/creator.c | 5 +- 12 files changed, 272 insertions(+), 223 deletions(-) diff --git a/intern/CMakeLists.txt b/intern/CMakeLists.txt index 8da41aab527..c85f0fddc34 100644 --- a/intern/CMakeLists.txt +++ b/intern/CMakeLists.txt @@ -66,8 +66,7 @@ if(WITH_CYCLES) add_subdirectory(cycles) endif() - -#Only Windows needs utf16 converter +# only windows needs utf16 converter if(WIN32) add_subdirectory(utfconv) endif() diff --git a/intern/SConscript b/intern/SConscript index 196a80433c9..71821bd9e99 100644 --- a/intern/SConscript +++ b/intern/SConscript @@ -3,7 +3,7 @@ Import ('env') SConscript(['audaspace/SConscript', 'string/SConscript', - 'utfconv/SConscript', + 'utfconv/SConscript', # XXX - why use this on UNIX? 'ghost/SConscript', 'guardedalloc/SConscript', 'moto/SConscript', diff --git a/intern/ghost/intern/GHOST_SystemPathsWin32.cpp b/intern/ghost/intern/GHOST_SystemPathsWin32.cpp index e3defddf367..0023ceb87f0 100644 --- a/intern/ghost/intern/GHOST_SystemPathsWin32.cpp +++ b/intern/ghost/intern/GHOST_SystemPathsWin32.cpp @@ -114,10 +114,10 @@ const GHOST_TUns8* GHOST_SystemPathsWin32::getBinaryDir() const return NULL; } -void GHOST_SystemPathsWin32::addToSystemRecentFiles(const char* filename) const +void GHOST_SystemPathsWin32::addToSystemRecentFiles(const char *filename) const { /* SHARD_PATH resolves to SHARD_PATHA for non-UNICODE build */ - UTF16_ENCODE(filename) - SHAddToRecentDocs(SHARD_PATHW,filename_16); - UTF16_UN_ENCODE(filename) + UTF16_ENCODE(filename); + SHAddToRecentDocs(SHARD_PATHW, filename_16); + UTF16_UN_ENCODE(filename); } diff --git a/intern/ghost/intern/GHOST_SystemPathsWin32.h b/intern/ghost/intern/GHOST_SystemPathsWin32.h index a56a2e07b96..f53b33da756 100644 --- a/intern/ghost/intern/GHOST_SystemPathsWin32.h +++ b/intern/ghost/intern/GHOST_SystemPathsWin32.h @@ -85,7 +85,7 @@ public: /** * Add the file to the operating system most recently used files */ - void addToSystemRecentFiles(const char* filename) const; + void addToSystemRecentFiles(const char *filename) const; }; #endif // __GHOST_SYSTEMPATHSWIN32_H__ diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp index b79185b1637..e6ac48fa6c8 100644 --- a/intern/ghost/intern/GHOST_SystemWin32.cpp +++ b/intern/ghost/intern/GHOST_SystemWin32.cpp @@ -724,19 +724,25 @@ GHOST_EventKey* GHOST_SystemWin32::processKeyEvent(GHOST_IWindow *window, RAWINP wchar_t utf16[3]={0}; BYTE state[256] ={0}; int r; - GetKeyboardState((PBYTE)state); + GetKeyboardState((PBYTE)state); - if(r = ToUnicodeEx(vk, 0, state, utf16, 2, 0, system->m_keylayout)) - - if((r>0 && r<3)){utf16[r]=0; - - conv_utf_16_to_8(utf16,utf8_char,6);} - else if (r==-1) utf8_char[0] = '\0'; - - + if(r = ToUnicodeEx(vk, 0, state, utf16, 2, 0, system->m_keylayout)) { + if((r>0 && r<3)){ + utf16[r]=0; + conv_utf_16_to_8(utf16,utf8_char,6); + } + else if (r==-1) { + utf8_char[0] = '\0'; + } + } - if(!keyDown) {utf8_char[0] = '\0'; ascii='\0';} - else ascii = utf8_char[0]& 0x80?'?':utf8_char[0]; + if(!keyDown) { + utf8_char[0] = '\0'; + ascii='\0'; + } + else { + ascii = utf8_char[0]& 0x80?'?' : utf8_char[0]; + } if(0x80&state[VK_MENU]) utf8_char[0]='\0'; @@ -1253,7 +1259,6 @@ GHOST_TUns8* GHOST_SystemWin32::getClipboard(bool selection) const if ( IsClipboardFormatAvailable(CF_UNICODETEXT) && OpenClipboard(NULL) ) { wchar_t *buffer; - size_t len = 0; HANDLE hData = GetClipboardData( CF_UNICODETEXT ); if (hData == NULL) { CloseClipboard(); diff --git a/intern/utfconv/CMakeLists.txt b/intern/utfconv/CMakeLists.txt index 76893d24a51..74b91fd0f2b 100644 --- a/intern/utfconv/CMakeLists.txt +++ b/intern/utfconv/CMakeLists.txt @@ -1,3 +1,21 @@ +# ***** BEGIN GPL LICENSE BLOCK ***** +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# ***** END GPL LICENSE BLOCK ***** + set(INC . ) diff --git a/intern/utfconv/utf_winfunc.c b/intern/utfconv/utf_winfunc.c index 5887b957e29..f48a9c2afaa 100644 --- a/intern/utfconv/utf_winfunc.c +++ b/intern/utfconv/utf_winfunc.c @@ -4,7 +4,7 @@ * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. + * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -17,7 +17,7 @@ * * The Original Code is Copyright (C) 2009 Blender Foundation. * All rights reserved. - * + * * Contributor(s): Alexandr Kuznetsov, Andrea Weikert * * ***** END GPL LICENSE BLOCK ***** @@ -37,19 +37,21 @@ FILE * ufopen(const char * filename, const char * mode) { - FILE * f = NULL; + FILE *f = NULL; UTF16_ENCODE(filename); UTF16_ENCODE (mode); - if(filename_16 && mode_16) f = _wfopen(filename_16, mode_16); + if(filename_16 && mode_16) { + f = _wfopen(filename_16, mode_16); + } UTF16_UN_ENCODE(mode); UTF16_UN_ENCODE(filename); - if(!f) - { - if(f=fopen(filename,mode)) + if (!f) { + if ((f = fopen(filename, mode))) { printf("WARNING: %s is not utf path. Please update it.\n",filename); + } } return f; @@ -60,14 +62,16 @@ int uopen(const char *filename, int oflag, int pmode) int f = -1; UTF16_ENCODE(filename); - if(filename_16) f = _wopen(filename_16, oflag, pmode); + if (filename_16) { + f = _wopen(filename_16, oflag, pmode); + } UTF16_UN_ENCODE(filename); - if(f==-1) - { - if((f=open(filename,oflag, pmode))!=-1) + if (f == -1) { + if ((f=open(filename,oflag, pmode)) != -1) { printf("WARNING: %s is not utf path. Please update it.\n",filename); + } } return f; @@ -96,7 +100,7 @@ int umkdir(const char *pathname) UTF16_UN_ENCODE(pathname); - return r?0:-1; + return r ? 0 : -1; } char * u_alloc_getenv(const char *varname) @@ -104,8 +108,10 @@ char * u_alloc_getenv(const char *varname) char * r = 0; wchar_t * str; UTF16_ENCODE(varname); - if(varname_16){ str = _wgetenv(varname_16); - r = alloc_utf_8_from_16(str,0);} + if (varname_16) { + str = _wgetenv(varname_16); + r = alloc_utf_8_from_16(str, 0); + } UTF16_UN_ENCODE(varname); return r; @@ -122,35 +128,30 @@ int uput_getenv(const char *varname, char * value, size_t buffsize) if(!buffsize) return r; UTF16_ENCODE(varname); - if(varname_16) - { - str = _wgetenv(varname_16); - conv_utf_16_to_8(str, value, buffsize); - r = 1; - } + if(varname_16) { + str = _wgetenv(varname_16); + conv_utf_16_to_8(str, value, buffsize); + r = 1; + } UTF16_UN_ENCODE(varname); - if(!r) value[0] = 0; + if (!r) value[0] = 0; return r; } - - int uputenv(const char *name, const char *value) { int r = -1; - UTF16_ENCODE(name) - UTF16_ENCODE(value) - if(name_16 && value_16) { - if(SetEnvironmentVariableW(name_16,value_16)!=0) - r =0; - else r = -1; + UTF16_ENCODE(name); + UTF16_ENCODE(value); + if(name_16 && value_16) { + r = (SetEnvironmentVariableW(name_16,value_16)!= 0) ? 0 : -1; } - UTF16_UN_ENCODE(value) - UTF16_UN_ENCODE(name) + UTF16_UN_ENCODE(value); + UTF16_UN_ENCODE(name); return r; } -#endif +#endif /* WIN32 */ diff --git a/intern/utfconv/utfconv.c b/intern/utfconv/utfconv.c index 4686b702626..c5181226f6e 100644 --- a/intern/utfconv/utfconv.c +++ b/intern/utfconv/utfconv.c @@ -25,208 +25,235 @@ #include "utfconv.h" -size_t count_utf_8_from_16(const wchar_t * string16) +size_t count_utf_8_from_16(const wchar_t *string16) { int i; size_t count = 0; wchar_t u = 0; - if(!string16) return 0; - - for(i=0;u = string16[i];i++) - { - if(u < 0x0080) count+=1; else - if(u < 0x0800) count+=2; else - if(u < 0xD800) count+=3; else - if(u < 0xDC00) { - i++; - if((u = string16[i])==0) break; - if(u >= 0xDC00 && u < 0xE000)count+=4; - } else - if(u < 0xE000) /*illigal*/; else - count+=3; + if (!string16) { + return 0; + } + + for (i = 0; u = string16[i]; i++) { + if (u < 0x0080) { + count += 1; + } + else { + if (u < 0x0800) { + count += 2; + } + else { + if (u < 0xD800) { + count += 3; + } + else { + if (u < 0xDC00) { + i++; + if ((u = string16[i]) == 0) { + break; + } + if (u >= 0xDC00 && u < 0xE000) { + count += 4; + } + } + else { + if (u < 0xE000) { + /*illigal*/; + } + else { + count += 3; + } + } + } + } + } } return ++count; } -size_t count_utf_16_from_8(const char * string8) +size_t count_utf_16_from_8(const char *string8) { - size_t count = 0; - char u; - char type = 0; - unsigned int u32 = 0; - - if(!string8) return 0; - - for(;(u = *string8);string8++) - { - if(type==0) - { - if((u&0x01<<7) == 0) {count++; u32 = 0; continue;} //1 utf-8 char - if((u&0x07<<5) == 0xC0) {type=1; u32 = u & 0x1F; continue;} //2 utf-8 char - if((u&0x0F<<4) == 0xE0) {type=2; u32 = u & 0x0F; continue;} //3 utf-8 char - if((u&0x1F<<3) == 0xF0) {type=3; u32 = u & 0x07; continue;} //4 utf-8 char - continue; - } else - { - if((u & 0xC0) == 0x80) {u32=(u32<<6) | (u&0x3F); type--;} else - {u32 = 0; type = 0;}; + size_t count = 0; + char u; + char type = 0; + unsigned int u32 = 0; + + if (!string8) return 0; + + for (; (u = *string8); string8++) { + if (type == 0) { + if ((u & 0x01 << 7) == 0) { count++; u32 = 0; continue; } //1 utf-8 char + if ((u & 0x07 << 5) == 0xC0) { type = 1; u32 = u & 0x1F; continue; } //2 utf-8 char + if ((u & 0x0F << 4) == 0xE0) { type = 2; u32 = u & 0x0F; continue; } //3 utf-8 char + if ((u & 0x1F << 3) == 0xF0) { type = 3; u32 = u & 0x07; continue; } //4 utf-8 char + continue; + } + else { + if ((u & 0xC0) == 0x80) { + u32 = (u32 << 6) | (u & 0x3F); + type--; } - if(type==0) - { - if((0 < u32 && u32 < 0xD800) || (0xE000 <= u32 && u32 < 0x10000)) count++; else - if(0x10000 <= u32 && u32 < 0x110000) count+=2; + else { u32 = 0; + type = 0; } + } + if (type == 0) { + if ((0 < u32 && u32 < 0xD800) || (0xE000 <= u32 && u32 < 0x10000)) count++; + else if (0x10000 <= u32 && u32 < 0x110000) count += 2; + u32 = 0; } + } return ++count; } - - -int conv_utf_16_to_8(const wchar_t * in16, char * out8, size_t size8) +int conv_utf_16_to_8(const wchar_t *in16, char *out8, size_t size8) { - char * out8end = out8+size8; + char *out8end = out8 + size8; wchar_t u = 0; int err = 0; - if(!size8 || !in16 || !out8) return UTF_ERROR_NULL_IN; + if (!size8 || !in16 || !out8) return UTF_ERROR_NULL_IN; out8end--; - for(; out8 < out8end && (u=*in16); in16++, out8++) - { - if(u < 0x0080) *out8 = u; else - if(u < 0x0800) { - if(out8 + 1 >= out8end) break; - *out8++=(0x3<<6) | (0x1F & (u>>6)); - *out8 =(0x1<<7) | (0x3F & (u)); - }else - if(u < 0xD800 || u >= 0xE000) { - if(out8 + 2 >= out8end) break; - *out8++=(0x7<<5) | (0xF & (u>>12)); - *out8++=(0x1<<7) | (0x3F & (u>>6));; - *out8 =(0x1<<7) | (0x3F & (u)); - }else - if(u < 0xDC00) { + for (; out8 < out8end && (u = *in16); in16++, out8++) { + if (u < 0x0080) { + *out8 = u; + } + else if (u < 0x0800) { + if (out8 + 1 >= out8end) break; + *out8++ = (0x3 << 6) | (0x1F & (u >> 6)); + *out8 = (0x1 << 7) | (0x3F & (u)); + } + else if (u < 0xD800 || u >= 0xE000) { + if (out8 + 2 >= out8end) break; + *out8++ = (0x7 << 5) | (0xF & (u >> 12)); + *out8++ = (0x1 << 7) | (0x3F & (u >> 6));; + *out8 = (0x1 << 7) | (0x3F & (u)); + } + else if (u < 0xDC00) { wchar_t u2 = *++in16; - if(!u2) break; - if(u2 >= 0xDC00 && u2 < 0xE000) - { - if(out8 + 3 >= out8end) break; else { - unsigned int uc = 0x10000 + (u2 - 0xDC00) + ((u - 0xD800)<<10); + if (!u2) break; + if (u2 >= 0xDC00 && u2 < 0xE000) { + if (out8 + 3 >= out8end) break; else { + unsigned int uc = 0x10000 + (u2 - 0xDC00) + ((u - 0xD800) << 10); - *out8++=(0xF<<4) | (0x7 & (uc>>18)); - *out8++=(0x1<<7) | (0x3F & (uc>>12)); - *out8++=(0x1<<7) | (0x3F & (uc>>6)); - *out8 =(0x1<<7) | (0x3F & (uc)); + *out8++ = (0xF << 4) | (0x7 & (uc >> 18)); + *out8++ = (0x1 << 7) | (0x3F & (uc >> 12)); + *out8++ = (0x1 << 7) | (0x3F & (uc >> 6)); + *out8 = (0x1 << 7) | (0x3F & (uc)); } - } else {out8--; err|=UTF_ERROR_ILLCHAR;}; - } else - if(u < 0xE000) {out8--; err|=UTF_ERROR_ILLCHAR;} - - + } + else { + out8--; err |= UTF_ERROR_ILLCHAR; + } + } + else if (u < 0xE000) { + out8--; err |= UTF_ERROR_ILLCHAR; + } } - *out8=*out8end=0; + *out8 = *out8end = 0; - if(*in16) err|=UTF_ERROR_SMALL; + if (*in16) err |= UTF_ERROR_SMALL; return err; } -int conv_utf_8_to_16(const char * in8, wchar_t * out16, size_t size16) +int conv_utf_8_to_16(const char *in8, wchar_t *out16, size_t size16) { char u; char type = 0; wchar_t u32 = 0; - wchar_t * out16end = out16+size16; + wchar_t *out16end = out16 + size16; int err = 0; - if(!size16 || !in8 || !out16) return UTF_ERROR_NULL_IN; + if (!size16 || !in8 || !out16) return UTF_ERROR_NULL_IN; out16end--; - for(;out16= out16end) break; - u32-=0x10000; + else { + if ((u & 0xC0) == 0x80) { + u32 = (u32 << 6) | (u & 0x3F); + type--; + } + else { + u32 = 0; type = 0; err |= UTF_ERROR_ILLSEQ; + } + } + if (type == 0) { + if ((0 < u32 && u32 < 0xD800) || (0xE000 <= u32 && u32 < 0x10000)) { + *out16 = u32; + out16++; + } + else if (0x10000 <= u32 && u32 < 0x110000) { + if (out16 + 1 >= out16end) break; + u32 -= 0x10000; *out16 = 0xD800 + (u32 >> 10); out16++; *out16 = 0xDC00 + (u32 & 0x3FF); out16++; - }; + } u32 = 0; } } - *out16=*out16end=0; + *out16 = *out16end = 0; - if(*in8) err|=UTF_ERROR_SMALL; + if (*in8) err |= UTF_ERROR_SMALL; return err; } -int is_ascii(const char * in8) +int is_ascii(const char *in8) { - for(in8; *in8; in8++) - if(0x80 & *in8) return 0; + for (; *in8; in8++) + if (0x80 & *in8) return 0; return 1; } -void utf_8_cut_end(char * inout8, size_t maxcutpoint) +void utf_8_cut_end(char *inout8, size_t maxcutpoint) { - const char * start = inout8; - char * cur = inout8 + maxcutpoint; + char *cur = inout8 + maxcutpoint; char cc; - if(!inout8) return; + if (!inout8) return; cc = *cur; - - - - } -char * alloc_utf_8_from_16(const wchar_t * in16, size_t add) +char *alloc_utf_8_from_16(const wchar_t *in16, size_t add) { size_t bsize = count_utf_8_from_16(in16); - char * out8 = NULL; - if(!bsize) return NULL; - out8 = (char*)malloc(sizeof(char) * (bsize + add)); - conv_utf_16_to_8(in16,out8, bsize); + char *out8 = NULL; + if (!bsize) return NULL; + out8 = (char *)malloc(sizeof(char) * (bsize + add)); + conv_utf_16_to_8(in16, out8, bsize); return out8; } -wchar_t * alloc_utf16_from_8(const char * in8, size_t add) +wchar_t *alloc_utf16_from_8(const char *in8, size_t add) { size_t bsize = count_utf_16_from_8(in8); - wchar_t * out16 = NULL; - if(!bsize) return NULL; - out16 =(wchar_t*) malloc(sizeof(wchar_t) * (bsize + add)); - conv_utf_8_to_16(in8,out16, bsize); + wchar_t *out16 = NULL; + if (!bsize) return NULL; + out16 = (wchar_t *) malloc(sizeof(wchar_t) * (bsize + add)); + conv_utf_8_to_16(in8, out16, bsize); return out16; } - diff --git a/intern/utfconv/utfconv.h b/intern/utfconv/utfconv.h index 30c0c8a9069..f5ab32cce3e 100644 --- a/intern/utfconv/utfconv.h +++ b/intern/utfconv/utfconv.h @@ -30,7 +30,7 @@ #ifdef __cplusplus -extern "C" { +extern "C" { #endif /** @@ -38,22 +38,22 @@ extern "C" { * @param string-16 pointer to working utf-16 string * @return How many bytes must be allocated includeng NULL. */ -size_t count_utf_8_from_16(const wchar_t * string16); +size_t count_utf_8_from_16(const wchar_t *string16); /** * Counts how many wchar_t (two byte) is requered for for future utf-16 string using utf-8 * @param string-8 pointer to working utf-8 string * @return How many bytes must be allocated includeng NULL. */ -size_t count_utf_16_from_8(const char * string8); +size_t count_utf_16_from_8(const char *string8); /** * conv_utf_*** errors */ -#define UTF_ERROR_NULL_IN 1<<0 /* Error occures when requered parameter is missing*/ -#define UTF_ERROR_ILLCHAR 1<<1 /* Error if character is in illigal UTF rage*/ -#define UTF_ERROR_SMALL 1<<2 /* Passed size is to small. It gives legal string with character missing at the end*/ -#define UTF_ERROR_ILLSEQ 1<<3 /* Error if sequence is broken and doesn't finish*/ +#define UTF_ERROR_NULL_IN 1 << 0 /* Error occures when requered parameter is missing*/ +#define UTF_ERROR_ILLCHAR 1 << 1 /* Error if character is in illigal UTF rage*/ +#define UTF_ERROR_SMALL 1 << 2 /* Passed size is to small. It gives legal string with character missing at the end*/ +#define UTF_ERROR_ILLSEQ 1 << 3 /* Error if sequence is broken and doesn't finish*/ /** * Converts utf-16 string to allocated utf-8 string @@ -62,7 +62,7 @@ size_t count_utf_16_from_8(const char * string8); * @params size8 the allocated size in bytes of out8 * @return Returns any errors occured during conversion. See the block above, */ -int conv_utf_16_to_8(const wchar_t * in16, char * out8, size_t size8); +int conv_utf_16_to_8(const wchar_t *in16, char *out8, size_t size8); /** * Converts utf-8 string to allocated utf-16 string @@ -71,7 +71,7 @@ int conv_utf_16_to_8(const wchar_t * in16, char * out8, size_t size8); * @params size16 the allocated size in wchar_t (two byte) of out16 * @return Returns any errors occured during conversion. See the block above, */ -int conv_utf_8_to_16(const char * in8, wchar_t * out16, size_t size16); +int conv_utf_8_to_16(const char *in8, wchar_t *out16, size_t size16); /** @@ -80,7 +80,7 @@ int conv_utf_8_to_16(const char * in8, wchar_t * out16, size_t size16); * @params add any additional size which will be allocated for new utf-8 string in bytes * @return New allocated and converted utf-8 string or NULL if in16 is 0. */ -char * alloc_utf_8_from_16(const wchar_t * in16, size_t add); +char *alloc_utf_8_from_16(const wchar_t *in16, size_t add); /** * Allocates and converts the utf-16 string from utf-8 @@ -88,14 +88,14 @@ char * alloc_utf_8_from_16(const wchar_t * in16, size_t add); * @params add any additional size which will be allocated for new utf-16 string in wchar_t (two bytes) * @return New allocated and converted utf-16 string or NULL if in8 is 0. */ -wchar_t * alloc_utf16_from_8(const char * in8, size_t add); +wchar_t *alloc_utf16_from_8(const char *in8, size_t add); /* Easy allocation and conversion of new utf-16 string. New string has _16 suffix. Must be deallocated with UTF16_UN_ENCODE in right order*/ -#define UTF16_ENCODE(in8str) if(1){\ - wchar_t * in8str ## _16 = alloc_utf16_from_8((char*)in8str, 0); +#define UTF16_ENCODE(in8str) if (1) { \ + wchar_t *in8str ## _16 = alloc_utf16_from_8((char *)in8str, 0) #define UTF16_UN_ENCODE(in8str) \ - free(in8str ## _16 ); }; + free(in8str ## _16); } (void)0 #ifdef __cplusplus } diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c index 576af23ed1b..1b734c674e2 100644 --- a/source/blender/blenlib/intern/fileops.c +++ b/source/blender/blenlib/intern/fileops.c @@ -184,14 +184,14 @@ int BLI_file_is_writable(const char *filename) int BLI_file_touch(const char *file) { - FILE *f = BLI_fopen(file,"r+b"); + FILE *f = BLI_fopen(file, "r+b"); if (f != NULL) { char c = getc(f); rewind(f); - putc(c,f); + putc(c, f); } else { - f = BLI_fopen(file,"wb"); + f = BLI_fopen(file, "wb"); } if (f) { fclose(f); @@ -250,7 +250,7 @@ int BLI_delete(const char *file, int dir, int recursive) { int err; - UTF16_ENCODE(file) + UTF16_ENCODE(file); if (recursive) { callLocalErrorCallBack("Recursive delete is unsupported on Windows"); @@ -265,7 +265,7 @@ int BLI_delete(const char *file, int dir, int recursive) if (err) callLocalErrorCallBack("Unable to delete file"); } - UTF16_UN_ENCODE(file) + UTF16_UN_ENCODE(file); return err; } @@ -286,11 +286,11 @@ int BLI_move(const char *file, const char *to) } } - UTF16_ENCODE(file) - UTF16_ENCODE(str) + UTF16_ENCODE(file); + UTF16_ENCODE(str); err= !MoveFileW(file_16, str_16); - UTF16_UN_ENCODE(str) - UTF16_UN_ENCODE(file) + UTF16_UN_ENCODE(str); + UTF16_UN_ENCODE(file); if (err) { callLocalErrorCallBack("Unable to move file"); @@ -317,11 +317,11 @@ int BLI_copy(const char *file, const char *to) } } - UTF16_ENCODE(file) - UTF16_ENCODE(str) - err= !CopyFileW(file_16,str_16,FALSE); - UTF16_UN_ENCODE(str) - UTF16_UN_ENCODE(file) + UTF16_ENCODE(file); + UTF16_ENCODE(str); + err = !CopyFileW(file_16, str_16, FALSE); + UTF16_UN_ENCODE(str); + UTF16_UN_ENCODE(file); if (err) { callLocalErrorCallBack("Unable to copy file!"); @@ -344,10 +344,10 @@ void BLI_dir_create_recursive(const char *dirname) char *lslash; char tmp[MAXPATHLEN]; - // First remove possible slash at the end of the dirname. - // This routine otherwise tries to create - // blah1/blah2/ (with slash) after creating - // blah1/blah2 (without slash) + /* First remove possible slash at the end of the dirname. + * This routine otherwise tries to create + * blah1/blah2/ (with slash) after creating + * blah1/blah2 (without slash) */ BLI_strncpy(tmp, dirname, sizeof(tmp)); lslash= BLI_last_slash(tmp); @@ -357,10 +357,10 @@ void BLI_dir_create_recursive(const char *dirname) } if (BLI_exists(tmp)) return; - + lslash= BLI_last_slash(tmp); if (lslash) { - /* Split about the last slash and recurse */ + /* Split about the last slash and recurse */ *lslash = 0; BLI_dir_create_recursive(tmp); } diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c index 01ebd1dce57..b0c0f106f06 100644 --- a/source/blender/blenlib/intern/storage.c +++ b/source/blender/blenlib/intern/storage.c @@ -224,16 +224,16 @@ static void bli_builddir(const char *dirname, const char *relname) return; } #else - UTF16_ENCODE(dirname) + UTF16_ENCODE(dirname); if (!SetCurrentDirectoryW(dirname_16)) { perror(dirname); free(dirname_16); return; } - UTF16_UN_ENCODE(dirname) + UTF16_UN_ENCODE(dirname); #endif - if ( (dir = (DIR *)opendir(".")) ) { + if ((dir = (DIR *)opendir("."))) { while ((fname = (struct dirent*) readdir(dir)) != NULL) { dlink = (struct dirlink *)malloc(sizeof(struct dirlink)); if (dlink) { @@ -247,13 +247,13 @@ static void bli_builddir(const char *dirname, const char *relname) if (newnum) { if (files) { - void *tmp= realloc(files, (totnum+newnum) * sizeof(struct direntry)); + void *tmp = realloc(files, (totnum+newnum) * sizeof(struct direntry)); if (tmp) { - files= (struct direntry *)tmp; + files = (struct direntry *)tmp; } else { /* realloc fail */ free(files); - files= NULL; + files = NULL; } } @@ -556,17 +556,17 @@ void BLI_file_free_lines(LinkNode *lines) int BLI_file_older(const char *file1, const char *file2) { -#if WIN32 +#ifdef WIN32 struct _stat st1, st2; - UTF16_ENCODE(file1) - UTF16_ENCODE(file2) + UTF16_ENCODE(file1); + UTF16_ENCODE(file2); if (_wstat(file1_16, &st1)) return 0; if (_wstat(file2_16, &st2)) return 0; - UTF16_UN_ENCODE(file2) - UTF16_UN_ENCODE(file1) + UTF16_UN_ENCODE(file2); + UTF16_UN_ENCODE(file1); #else struct stat st1, st2; diff --git a/source/creator/creator.c b/source/creator/creator.c index 516c50a01f9..308cdab9726 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -1169,7 +1169,7 @@ char **environ = NULL; #ifdef WIN32 -int main(int argc, const char **argv_c) /*Do not mess with const*/ +int main(int argc, const char **UNUSED(argv_c)) /* Do not mess with const */ #else int main(int argc, const char **argv) #endif @@ -1182,8 +1182,7 @@ int main(int argc, const char **argv) wchar_t **argv_16 = CommandLineToArgvW(GetCommandLineW(), &argc); int argci = 0; char **argv = MEM_mallocN(argc * sizeof(char *), "argv array"); - for (argci = 0; argci < argc; argci++) - { + for (argci = 0; argci < argc; argci++) { argv[argci] = alloc_utf_8_from_16(argv_16[argci], 0); } LocalFree(argv_16); -- cgit v1.2.3