[PD-cvs] externals/hcs folder_list.c, 1.4, 1.5 folder_list-help.pd, 1.3, 1.4

Hans-Christoph Steiner eighthave at users.sourceforge.net
Mon Mar 27 01:32:26 CEST 2006


Update of /cvsroot/pure-data/externals/hcs
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31618

Modified Files:
	folder_list.c folder_list-help.pd 
Log Message:
ported to windows, and some UNIX-side cleanups and fixes as well.  Now its time to test it on Mac OS X and try to get envvar expansion working

Index: folder_list-help.pd
===================================================================
RCS file: /cvsroot/pure-data/externals/hcs/folder_list-help.pd,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** folder_list-help.pd	26 Mar 2006 21:26:04 -0000	1.3
--- folder_list-help.pd	26 Mar 2006 23:32:24 -0000	1.4
***************
*** 1,51 ****
! #N canvas 254 219 504 539 10;
! #X msg 74 72 bang;
! #X msg 101 320 bang;
! #X obj 124 267 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
! -1;
! #X obj 85 385 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
! -1;
! #X msg 235 218 symbol /usr/*;
! #X text 36 25 Get a listing of files based on a "glob" pattern.;
! #X text 110 74 list current directory;
! #X text 219 200 set pattern without no output;
! #X text 241 111 all files with a dot in your Home;
! #X obj 101 351 folder_list;
! #X obj 142 243 folder_list /*;
! #X obj 143 278 print;
! #X text 34 49 left/hot inlet gives immediate output using stored path
! ;
! #X text 49 298 For UNIX people \, [folder_list] behaves just like "ls
! -d1A";
! #X obj 102 384 print;
! #X msg 142 109 symbol ~/*.*;
! #X text 153 381 WARNING: the default will change in the future!;
! #X text 156 131 patterns default to path Pd launched from;
! #X msg 156 148 symbol *;
! #X text 258 174 relative paths work;
! #X msg 173 175 symbol ../*;
! #X obj 51 440 getdir;
! #X obj 51 482 folder_list;
! #X msg 51 420 bang;
! #X obj 51 504 print;
! #X obj 51 460 makefilename %s/*;
! #X symbolatom 186 456 0 0 0 0 - - -;
! #X symbolatom 186 476 0 0 0 0 - - -;
! #X text 128 425 What's in the same folder as this patch?;
! #X text 186 350 defaults to /;
! #X connect 0 0 10 0;
! #X connect 1 0 9 0;
! #X connect 4 0 10 1;
! #X connect 9 0 3 0;
! #X connect 9 0 14 0;
! #X connect 10 0 2 0;
! #X connect 10 0 11 0;
! #X connect 15 0 10 0;
! #X connect 18 0 10 0;
! #X connect 20 0 10 0;
! #X connect 21 0 25 0;
! #X connect 21 0 26 0;
! #X connect 22 0 24 0;
! #X connect 23 0 21 0;
! #X connect 25 0 22 0;
! #X connect 25 0 27 0;
--- 1,58 ----
! #N canvas 254 219 528 563 10;
! #X msg 19 48 bang;
! #X msg 101 320 bang;
! #X obj 64 267 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
! -1;
! #X obj 85 385 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
! -1;
! #X msg 175 218 symbol /usr/*;
! #X text 30 5 Get a listing of files based on a "glob" pattern.;
! #X text 55 50 list current directory;
! #X text 159 200 set pattern without no output;
! #X obj 101 351 folder_list;
! #X obj 82 243 folder_list /*;
! #X obj 83 278 print;
! #X text 28 29 left/hot inlet gives immediate output using stored path
! ;
! #X text 49 298 For UNIX people \, [folder_list] behaves just like "ls
! -d1A";
! #X obj 102 384 print;
! #X msg 91 126 symbol ~/*.*;
! #X text 153 381 WARNING: the default will change in the future!;
! #X text 153 151 patterns default to path Pd launched from;
! #X msg 97 153 symbol *;
! #X text 187 177 relative paths work;
! #X msg 102 178 symbol ../*;
! #X obj 51 440 getdir;
! #X obj 51 482 folder_list;
! #X msg 51 420 bang;
! #X obj 51 504 print;
! #X obj 51 460 makefilename %s/*;
! #X symbolatom 186 456 0 0 0 0 - - -;
! #X symbolatom 186 476 0 0 0 0 - - -;
! #X text 128 425 What's in the same folder as this patch?;
! #X text 186 350 defaults to /;
! #X text 144 97 drive letters work on ReactOS/Windows;
! #X msg 69 97 symbol C:/*;
! #X text 190 128 all files with a dot in your home;
! #X msg 47 73 symbol %USERPROFILE%/*;
! #X text 185 73 On ReactOS/Windows you can use Environment variables
! ;
! #X connect 0 0 9 0;
! #X connect 1 0 8 0;
! #X connect 4 0 9 1;
! #X connect 8 0 3 0;
! #X connect 8 0 13 0;
! #X connect 9 0 2 0;
! #X connect 9 0 10 0;
! #X connect 14 0 9 0;
! #X connect 17 0 9 0;
! #X connect 19 0 9 0;
! #X connect 20 0 24 0;
! #X connect 20 0 25 0;
! #X connect 21 0 23 0;
! #X connect 22 0 20 0;
! #X connect 24 0 21 0;
! #X connect 24 0 26 0;
! #X connect 30 0 9 0;
! #X connect 32 0 9 0;

Index: folder_list.c
===================================================================
RCS file: /cvsroot/pure-data/externals/hcs/folder_list.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** folder_list.c	26 Mar 2006 21:30:28 -0000	1.4
--- folder_list.c	26 Mar 2006 23:32:24 -0000	1.5
***************
*** 1,4 ****
--- 1,12 ----
  #include <m_pd.h>
+ 
+ #ifdef _WIN32
+ #define _WIN32_WINNT 0x0400
+ #include <windows.h>
+ #include <stdio.h>
+ #else
+ #include <stdlib.h>
  #include <glob.h>
+ #endif
  
  static char *version = "$Revision$";
***************
*** 13,19 ****
  
  typedef struct _folder_list {
! 	t_object            x_obj;
! 	t_symbol            *x_pattern;
! 	glob_t              x_glob;
  } t_folder_list;
  
--- 21,26 ----
  
  typedef struct _folder_list {
! 	  t_object            x_obj;
!       t_symbol            *x_pattern;
  } t_folder_list;
  
***************
*** 22,50 ****
   */
  
  
  static void folder_list_output(t_folder_list* x)
  {
  	DEBUG(post("folder_list_output"););
- 	unsigned int i;
  
  	DEBUG(post("globbing %s",x->x_pattern->s_name););
! 	switch( glob( x->x_pattern->s_name, GLOB_TILDE, NULL, &(x->x_glob) ) )
  	{
! 	case GLOB_NOSPACE: 
! 		error("[folder_list] out of memory"); break;
! 	case GLOB_ABORTED: 
! 		error("[folder_list] aborted"); break;
! 	case GLOB_NOMATCH: 
! 		error("[folder_list] no match"); break;
  	}
! 	for(i = 0; i < x->x_glob.gl_pathc; i++)
! 		outlet_symbol( x->x_obj.ob_outlet, gensym(x->x_glob.gl_pathv[i]) );
! }
! 
! 
! static void folder_list_symbol(t_folder_list *x, t_symbol *s) 
! {
! 	x->x_pattern = s;
! 	folder_list_output(x);
  }
  
--- 29,93 ----
   */
  
+ // TODO: regexp ~ to USERPROFILE for Windows
+ // TODO: make FindFirstFile display when its just a dir
  
  static void folder_list_output(t_folder_list* x)
  {
  	DEBUG(post("folder_list_output"););
  
+ #ifdef _WIN32
+ 	WIN32_FIND_DATA FindFileData;
+ 	HANDLE hFind;
+ 	DWORD errorNumber;
+ 	LPVOID lpErrorMessage;
+ 	
+ 	hFind = FindFirstFile(x->x_pattern->s_name, &FindFileData);
+ 	if (hFind == INVALID_HANDLE_VALUE) 
+ 	{
+ 	   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);
+ 	   }
+ 	   return;
+ 	} 
+ 	do {
+ 	   outlet_symbol( x->x_obj.ob_outlet, gensym(FindFileData.cFileName) );
+ 	} while (FindNextFile(hFind, &FindFileData) != 0);
+ 	FindClose(hFind);
+ #else
+ 	unsigned int i;
+ 	glob_t glob_buffer;
+ 	
  	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;
! 	   case GLOB_ABORTED: 
! 		  error("[folder_list] aborted \"%s\"",x->x_pattern->s_name); 
! 		  break;
! 	   case GLOB_NOMATCH: 
! 		  error("[folder_list] nothing found for \"%s\"",x->x_pattern->s_name); 
! 		  break;
  	}
! 	for(i = 0; i < glob_buffer.gl_pathc; i++)
! 		outlet_symbol( x->x_obj.ob_outlet, gensym(glob_buffer.gl_pathv[i]) );
! 	globfree( &(glob_buffer) );
! #endif
  }
  
***************
*** 53,65 ****
  {
  	DEBUG(post("folder_list_set"););
  	x->x_pattern = s;
  }
  
  
! static void folder_list_free(t_folder_list* x) 
  {
! 	DEBUG(post("folder_list_free"););
! 
! 	globfree( &(x->x_glob) );
  }
  
--- 96,113 ----
  {
  	DEBUG(post("folder_list_set"););
+ #ifdef _WIN32
+ 	char string_buffer[MAX_PATH];
+ 	ExpandEnvironmentStrings(s->s_name, string_buffer, MAX_PATH);
+ 	x->x_pattern = gensym(string_buffer);
+ #else
  	x->x_pattern = s;
+ #endif	
  }
  
  
! static void folder_list_symbol(t_folder_list *x, t_symbol *s) 
  {
!    folder_list_set(x,s);
!    folder_list_output(x);
  }
  
***************
*** 73,77 ****
  	post("[folder_list] %s, written by Hans-Christoph Steiner <hans at at.or.at>",version);  
  	/* TODO set current dir of patch as default */
! 	x->x_pattern = gensym("/");
  
      symbolinlet_new(&x->x_obj, &x->x_pattern);
--- 121,129 ----
  	post("[folder_list] %s, written by Hans-Christoph Steiner <hans at at.or.at>",version);  
  	/* TODO set current dir of patch as default */
! #ifdef _WIN32
! 	x->x_pattern = gensym(getenv("USERPROFILE"));
! #else
! 	x->x_pattern = gensym(getenv("HOME"));
! #endif
  
      symbolinlet_new(&x->x_obj, &x->x_pattern);
***************
*** 90,94 ****
  	folder_list_class = class_new(gensym("folder_list"), 
  								  (t_newmethod)folder_list_new, 
! 								  (t_method)folder_list_free,
  								  sizeof(t_folder_list), 
  								  0, 
--- 142,146 ----
  	folder_list_class = class_new(gensym("folder_list"), 
  								  (t_newmethod)folder_list_new, 
! 								  0,
  								  sizeof(t_folder_list), 
  								  0, 
***************
*** 96,100 ****
  								  0);
  	/* add inlet datatype methods */
- //	class_addfloat(folder_list_class,(t_method) glob_float);
  	class_addbang(folder_list_class,(t_method) folder_list_output);
  	class_addsymbol(folder_list_class,(t_method) folder_list_symbol);
--- 148,151 ----





More information about the Pd-cvs mailing list