[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [45552] trunk/blender: code cleanup: utfconv library had some quite confusing formatting, also cleared som warnings.
Campbell Barton
ideasman42 at gmail.com
Thu Apr 12 04:15:35 CEST 2012
Revision: 45552
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=45552
Author: campbellbarton
Date: 2012-04-12 02:15:33 +0000 (Thu, 12 Apr 2012)
Log Message:
-----------
code cleanup: utfconv library had some quite confusing formatting, also cleared som warnings.
Modified Paths:
--------------
trunk/blender/intern/CMakeLists.txt
trunk/blender/intern/SConscript
trunk/blender/intern/ghost/intern/GHOST_SystemPathsWin32.cpp
trunk/blender/intern/ghost/intern/GHOST_SystemPathsWin32.h
trunk/blender/intern/ghost/intern/GHOST_SystemWin32.cpp
trunk/blender/intern/utfconv/CMakeLists.txt
trunk/blender/intern/utfconv/utf_winfunc.c
trunk/blender/intern/utfconv/utfconv.c
trunk/blender/intern/utfconv/utfconv.h
trunk/blender/source/blender/blenlib/intern/fileops.c
trunk/blender/source/blender/blenlib/intern/storage.c
trunk/blender/source/creator/creator.c
Modified: trunk/blender/intern/CMakeLists.txt
===================================================================
--- trunk/blender/intern/CMakeLists.txt 2012-04-12 00:15:02 UTC (rev 45551)
+++ trunk/blender/intern/CMakeLists.txt 2012-04-12 02:15:33 UTC (rev 45552)
@@ -66,8 +66,7 @@
add_subdirectory(cycles)
endif()
-
-#Only Windows needs utf16 converter
+# only windows needs utf16 converter
if(WIN32)
add_subdirectory(utfconv)
endif()
Modified: trunk/blender/intern/SConscript
===================================================================
--- trunk/blender/intern/SConscript 2012-04-12 00:15:02 UTC (rev 45551)
+++ trunk/blender/intern/SConscript 2012-04-12 02:15:33 UTC (rev 45552)
@@ -3,7 +3,7 @@
SConscript(['audaspace/SConscript',
'string/SConscript',
- 'utfconv/SConscript',
+ 'utfconv/SConscript', # XXX - why use this on UNIX?
'ghost/SConscript',
'guardedalloc/SConscript',
'moto/SConscript',
Modified: trunk/blender/intern/ghost/intern/GHOST_SystemPathsWin32.cpp
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_SystemPathsWin32.cpp 2012-04-12 00:15:02 UTC (rev 45551)
+++ trunk/blender/intern/ghost/intern/GHOST_SystemPathsWin32.cpp 2012-04-12 02:15:33 UTC (rev 45552)
@@ -114,10 +114,10 @@
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);
}
Modified: trunk/blender/intern/ghost/intern/GHOST_SystemPathsWin32.h
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_SystemPathsWin32.h 2012-04-12 00:15:02 UTC (rev 45551)
+++ trunk/blender/intern/ghost/intern/GHOST_SystemPathsWin32.h 2012-04-12 02:15:33 UTC (rev 45552)
@@ -85,7 +85,7 @@
/**
* 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__
Modified: trunk/blender/intern/ghost/intern/GHOST_SystemWin32.cpp
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_SystemWin32.cpp 2012-04-12 00:15:02 UTC (rev 45551)
+++ trunk/blender/intern/ghost/intern/GHOST_SystemWin32.cpp 2012-04-12 02:15:33 UTC (rev 45552)
@@ -724,20 +724,26 @@
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 = 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>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';
event = new GHOST_EventKey(system->getMilliSeconds(), keyDown ? GHOST_kEventKeyDown: GHOST_kEventKeyUp, window, key, ascii, utf8_char);
@@ -1253,7 +1259,6 @@
if ( IsClipboardFormatAvailable(CF_UNICODETEXT) && OpenClipboard(NULL) ) {
wchar_t *buffer;
- size_t len = 0;
HANDLE hData = GetClipboardData( CF_UNICODETEXT );
if (hData == NULL) {
CloseClipboard();
Modified: trunk/blender/intern/utfconv/CMakeLists.txt
===================================================================
--- trunk/blender/intern/utfconv/CMakeLists.txt 2012-04-12 00:15:02 UTC (rev 45551)
+++ trunk/blender/intern/utfconv/CMakeLists.txt 2012-04-12 02:15:33 UTC (rev 45552)
@@ -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
.
)
Modified: trunk/blender/intern/utfconv/utf_winfunc.c
===================================================================
--- trunk/blender/intern/utfconv/utf_winfunc.c 2012-04-12 00:15:02 UTC (rev 45551)
+++ trunk/blender/intern/utfconv/utf_winfunc.c 2012-04-12 02:15:33 UTC (rev 45552)
@@ -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 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 @@
UTF16_UN_ENCODE(pathname);
- return r?0:-1;
+ return r ? 0 : -1;
}
char * u_alloc_getenv(const char *varname)
@@ -104,8 +108,10 @@
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 @@
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 */
Modified: trunk/blender/intern/utfconv/utfconv.c
===================================================================
--- trunk/blender/intern/utfconv/utfconv.c 2012-04-12 00:15:02 UTC (rev 45551)
+++ trunk/blender/intern/utfconv/utfconv.c 2012-04-12 02:15:33 UTC (rev 45552)
@@ -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;
+ 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;
+ 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;
+ size_t count = 0;
+ char u;
+ char type = 0;
+ unsigned int u32 = 0;
- if(!string8) return 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
- {
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list