Revision: 9613 http://pure-data.svn.sourceforge.net/pure-data/?rev=9613&view=rev Author: eighthave Date: 2008-03-20 10:48:23 -0700 (Thu, 20 Mar 2008)
Log Message: ----------- Fixed bug #1836108 on Windows. Stupid string handling on my part ended up with mangled string reassembly.
Modified Paths: -------------- trunk/externals/hcs/folder_list-help.pd trunk/externals/hcs/folder_list.c
Modified: trunk/externals/hcs/folder_list-help.pd =================================================================== --- trunk/externals/hcs/folder_list-help.pd 2008-03-20 15:57:09 UTC (rev 9612) +++ trunk/externals/hcs/folder_list-help.pd 2008-03-20 17:48:23 UTC (rev 9613) @@ -17,7 +17,6 @@ -d1A"; #X obj 28 419 print; #X msg 91 146 symbol ~/*.*; -#X msg 97 173 symbol *; #X text 187 197 relative paths work; #X msg 102 198 symbol ../*; #X text 164 124 drive letters work on ReactOS/Windows; @@ -27,7 +26,7 @@ #X text 203 99 ReactOS/Windows environment variables work; #X text 262 218 nested wildcards work on UNIX; #X msg 119 219 symbol /var/*/*.log; -#X text 165 172 patterns default to path that Pd launched from; +#X text 173 173 patterns default to path that Pd launched from; #X text 329 464 released under the GNU GPL; #X text 15 449 (C) Copyright 2006 Hans-Christoph Steiner hans@at.or.at ; @@ -37,6 +36,7 @@ #X text 115 380 With no argument , it defaults to the contents of the folder of the current patch , i.e. "/path/to/current/patch/*". ; +#X msg 97 173 symbol *.pd; #X connect 0 0 8 0; #X connect 1 0 7 0; #X connect 4 0 8 1; @@ -45,8 +45,8 @@ #X connect 8 0 2 0; #X connect 8 0 9 0; #X connect 13 0 8 0; -#X connect 14 0 8 0; -#X connect 16 0 8 0; -#X connect 18 0 8 0; -#X connect 20 0 8 0; -#X connect 23 0 8 0; +#X connect 15 0 8 0; +#X connect 17 0 8 0; +#X connect 19 0 8 0; +#X connect 22 0 8 0; +#X connect 28 0 8 0;
Modified: trunk/externals/hcs/folder_list.c =================================================================== --- trunk/externals/hcs/folder_list.c 2008-03-20 15:57:09 UTC (rev 9612) +++ trunk/externals/hcs/folder_list.c 2008-03-20 17:48:23 UTC (rev 9613) @@ -40,8 +40,8 @@
t_int folder_list_instance_count;
-#define DEBUG(x) -//#define DEBUG(x) x +//#define DEBUG(x) +#define DEBUG(x) x
/*------------------------------------------------------------------------------ * CLASS DEF @@ -69,14 +69,14 @@ HANDLE hFind; DWORD errorNumber; LPVOID lpErrorMessage; - char fullPathNameBuffer[MAX_PATH+1] = ""; - char unbashBuffer[MAX_PATH+1] = ""; - char pathBuffer[MAX_PATH+1] = ""; - int length; + char fullPathNameBuffer[MAX_PATH] = ""; + char unbashBuffer[MAX_PATH] = ""; + char outputBuffer[MAX_PATH] = ""; + char *pathBuffer;
// arg, looks perfect, but only in Windows Vista // GetFinalPathNameByHandle(hFind,fullPathNameBuffer,MAX_PATH,FILE_NAME_NORMALIZED); - GetFullPathName(x->x_pattern->s_name,MAX_PATH,fullPathNameBuffer,NULL); + GetFullPathName(x->x_pattern->s_name, MAX_PATH, fullPathNameBuffer, NULL); sys_unbashfilename(fullPathNameBuffer,unbashBuffer); hFind = FindFirstFile(x->x_pattern->s_name, &findData); @@ -85,35 +85,37 @@ errorNumber = GetLastError(); switch (errorNumber) { - case ERROR_FILE_NOT_FOUND: - case ERROR_PATH_NOT_FOUND: - error("[folder_list] nothing found for "%s"",x->x_pattern->s_name); - break; - default: - FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM, - NULL, - errorNumber, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR) &lpErrorMessage, - 0, NULL ); - error("[folder_list] %s", lpErrorMessage); + case ERROR_FILE_NOT_FOUND: + case ERROR_PATH_NOT_FOUND: + pd_error(x,"[folder_list] nothing found for "%s"",x->x_pattern->s_name); + break; + default: + FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + errorNumber, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR) &lpErrorMessage, + 0, NULL ); + pd_error(x,"[folder_list] %s", (char *)lpErrorMessage); } return; } + char* unbashBuffer_position = strrchr(unbashBuffer, '/'); + if(unbashBuffer_position) + { + pathBuffer = getbytes(MAX_PATH+1); + strncpy(pathBuffer, unbashBuffer, unbashBuffer_position - unbashBuffer); + } do { - if( strcmp(findData.cFileName, ".") && strcmp(findData.cFileName, "..") ) + // skip "." and ".." + if( strcmp(findData.cFileName, ".") && strcmp(findData.cFileName, "..") ) { - length = strlen(unbashBuffer); - do - { - length--; - } while ( *(unbashBuffer + length) == '/' ); - strncpy(pathBuffer, unbashBuffer, length); - pathBuffer[length] = '\0'; - strcat(pathBuffer,findData.cFileName); - outlet_symbol( x->x_obj.ob_outlet, gensym(pathBuffer) ); + strncpy(outputBuffer, pathBuffer, MAX_PATH); + strcat(outputBuffer,"/"); + strcat(outputBuffer,findData.cFileName); + outlet_symbol( x->x_obj.ob_outlet, gensym(outputBuffer) ); } } while (FindNextFile(hFind, &findData) != 0); FindClose(hFind); @@ -124,19 +126,19 @@ DEBUG(post("globbing %s",x->x_pattern->s_name);); switch( glob( x->x_pattern->s_name, GLOB_TILDE, NULL, &glob_buffer ) ) { - case GLOB_NOSPACE: - error("[folder_list] out of memory for "%s"",x->x_pattern->s_name); - break; -#ifdef GLOB_ABORTED - case GLOB_ABORTED: - error("[folder_list] aborted "%s"",x->x_pattern->s_name); - break; -#endif -#ifdef GLOB_NOMATCH - case GLOB_NOMATCH: - error("[folder_list] nothing found for "%s"",x->x_pattern->s_name); - break; -#endif + case GLOB_NOSPACE: + pd_error(x,"[folder_list] out of memory for "%s"",x->x_pattern->s_name); + break; +# ifdef GLOB_ABORTED + case GLOB_ABORTED: + pd_error(x,"[folder_list] aborted "%s"",x->x_pattern->s_name); + break; +# endif +# ifdef GLOB_NOMATCH + case GLOB_NOMATCH: + pd_error(x,"[folder_list] nothing found for "%s"",x->x_pattern->s_name); + break; +# endif } for(i = 0; i < glob_buffer.gl_pathc; i++) outlet_symbol( x->x_obj.ob_outlet, gensym(glob_buffer.gl_pathv[i]) ); @@ -148,13 +150,25 @@ static void folder_list_set(t_folder_list* x, t_symbol *s) { DEBUG(post("folder_list_set");); + char *patternBuffer; + char envVarBuffer[MAX_PATH]; #ifdef _WIN32 - char string_buffer[MAX_PATH]; - ExpandEnvironmentStrings(s->s_name, string_buffer, MAX_PATH); - x->x_pattern = gensym(string_buffer); + if( (s->s_name[0] == '~') && (s->s_name[1] == '/')) + { + patternBuffer = getbytes(MAX_PATH); + strcpy(patternBuffer,"%USERPROFILE%"); + strncat(patternBuffer, s->s_name + 1, MAX_PATH - 1); + post("set: %s", patternBuffer); + } + else + { + patternBuffer = s->s_name; + } + ExpandEnvironmentStrings(patternBuffer, envVarBuffer, MAX_PATH - 2); + x->x_pattern = gensym(envVarBuffer); #else x->x_pattern = s; -#endif +#endif }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.