[PD-cvs] externals/iemlib/src/iemlib2 splitfilename.c,1.6,1.7

musil tmusil at users.sourceforge.net
Wed Jan 4 02:05:19 CET 2006


Update of /cvsroot/pure-data/externals/iemlib/src/iemlib2
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30386/iemlib/src/iemlib2

Modified Files:
	splitfilename.c 
Log Message:
new malloc

Index: splitfilename.c
===================================================================
RCS file: /cvsroot/pure-data/externals/iemlib/src/iemlib2/splitfilename.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** splitfilename.c	3 Sep 2005 08:28:41 -0000	1.6
--- splitfilename.c	4 Jan 2006 01:05:17 -0000	1.7
***************
*** 25,154 ****
  typedef struct _splitfilename
  {
! 	t_object x_obj;
! 	char     x_sep[2];
! 	void     *x_outpath;
! 	void     *x_outfile;
  } t_splitfilename;
  
  static void splitfilename_separator(t_splitfilename *x, t_symbol *s, int ac, t_atom *av)
  {
! 	if(ac > 0)
! 	{
! 		if(IS_A_SYMBOL(av, 0))
! 		{
! 			if(strlen(av->a_w.w_symbol->s_name) == 1)
! 				x->x_sep[0] = av->a_w.w_symbol->s_name[0];
! 			else if(!strcmp(av->a_w.w_symbol->s_name, "backslash"))
! 				x->x_sep[0] = '\\';
! 			else if(!strcmp(av->a_w.w_symbol->s_name, "slash"))
! 				x->x_sep[0] = '/';
! 			else if(!strcmp(av->a_w.w_symbol->s_name, "blank"))
! 				x->x_sep[0] = ' ';
! 			else if(!strcmp(av->a_w.w_symbol->s_name, "space"))
! 				x->x_sep[0] = ' ';
! 			else if(!strcmp(av->a_w.w_symbol->s_name, "dollar"))
! 				x->x_sep[0] = '$';
! 			else if(!strcmp(av->a_w.w_symbol->s_name, "comma"))
! 				x->x_sep[0] = ',';
! 			else if(!strcmp(av->a_w.w_symbol->s_name, "semi"))
! 				x->x_sep[0] = ';';
! 			else if(!strcmp(av->a_w.w_symbol->s_name, "leftbrace"))
! 				x->x_sep[0] = '{';
! 			else if(!strcmp(av->a_w.w_symbol->s_name, "rightbrace"))
! 				x->x_sep[0] = '}';
! 			else
! 				x->x_sep[0] = '/';
! 		}
! 		else if(IS_A_FLOAT(av, 0))
! 		{
! 			int i;
! 			float f=fabs(av->a_w.w_float);
! 			
! 			while(f >= 10.0)
! 				f *= 0.1;
! 			i = (int)f;
! 			x->x_sep[0] = (char)i + '0';
! 		}
! 	}
! 	else
! 		x->x_sep[0] = 0;
  }
  
  static void splitfilename_symbol(t_splitfilename *x, t_symbol *s)
  {
! 	int len = strlen(s->s_name);
! 	
! 	if(len)
! 	{
! 		if(x->x_sep[0] != 0)
! 		{
! 			char *str_path = (char *)getbytes(len*sizeof(char));
! 			char *str_file = (char *)getbytes(len*sizeof(char));
! 			char *cpp, *cpf;
! 			
! 			strcpy(str_path, s->s_name);
! 			strcpy(str_file, s->s_name);
! 			cpp = strrchr(str_path, x->x_sep[0]);
! 			cpf = strrchr(str_file, x->x_sep[0]);
! 			if(!cpp) /* JMZ: 20050701 */
! 			{
! 				outlet_symbol(x->x_outfile, gensym(str_file));
! 				outlet_symbol(x->x_outpath, &s_);			  
! 			} 
! 			else if (!cpf) /* JMZ: 20050701 */
! 			{
! 				outlet_symbol(x->x_outfile, &s_);
! 				outlet_symbol(x->x_outpath, gensym(str_path));
! 			}
! 			else if((cpp - str_path) < 0) /* JMZ:removed typecast (char*) to (int); this is not portable */
! 			  {
! 				outlet_symbol(x->x_outfile, gensym(str_file));
! 				outlet_symbol(x->x_outpath, &s_);
! 			  }
! 			else if((cpp - str_path) >= len) /* JMZ: removed typecast (char*) to (int) */
! 			    {
! 				outlet_symbol(x->x_outfile, &s_);
! 				outlet_symbol(x->x_outpath, gensym(str_path));
! 			  }
! 			  else
! 			  {
! 				*cpp = 0;
! 				cpf++;
! 				outlet_symbol(x->x_outfile, gensym(cpf));
! 				outlet_symbol(x->x_outpath, gensym(str_path));
! 			  }
! 			freebytes(str_file, len*sizeof(char));
! 			freebytes(str_path, len*sizeof(char));
! 		}
! 		else
! 		{
! 			outlet_symbol(x->x_outfile, &s_);
! 			outlet_symbol(x->x_outpath, s);
! 		}
! 	}
  }
  
  static void *splitfilename_new(t_symbol *s, int ac, t_atom *av)
  {
! 	t_splitfilename *x = (t_splitfilename *)pd_new(splitfilename_class);
! 	
! 	x->x_sep[0] = 0;
! 	x->x_sep[1] = 0;
! 	if(ac == 0)
! 		x->x_sep[0] = '/';
! 	else
! 		splitfilename_separator(x, s, ac, av);
! 	x->x_outpath = outlet_new(&x->x_obj, &s_symbol);
! 	x->x_outfile = outlet_new(&x->x_obj, &s_symbol);
! 	return (x);
  }
  
  void splitfilename_setup(void)
  {
! 	splitfilename_class = class_new(gensym("splitfilename"), (t_newmethod)splitfilename_new,
! 		0, sizeof(t_splitfilename), 0, A_GIMME, 0);
! 	class_addsymbol(splitfilename_class, splitfilename_symbol);
! 	class_addmethod(splitfilename_class, (t_method)splitfilename_separator, gensym("separator"), A_GIMME, 0);
! 	class_addmethod(splitfilename_class, (t_method)splitfilename_separator, gensym("sep"), A_GIMME, 0);
! 	class_sethelpsymbol(splitfilename_class, gensym("iemhelp/help-splitfilename"));
  }
--- 25,145 ----
  typedef struct _splitfilename
  {
!   t_object x_obj;
!   char     x_sep[2];
!   char     *x_mem;
!   t_int    x_size;
!   t_outlet *x_outpath;
!   t_outlet *x_outfile;
  } t_splitfilename;
  
  static void splitfilename_separator(t_splitfilename *x, t_symbol *s, int ac, t_atom *av)
  {
!   if(ac > 0)
!   {
!     if(IS_A_SYMBOL(av, 0))
!     {
!       char *name=av->a_w.w_symbol->s_name;
! 
!       if(strlen(name) == 1)
!         x->x_sep[0] = name[0];
!       else if(!strcmp(name, "backslash"))
!         x->x_sep[0] = '\\';
!       else if(!strcmp(name, "slash"))
!         x->x_sep[0] = '/';
!       else if(!strcmp(name, "blank"))
!         x->x_sep[0] = ' ';
!       else if(!strcmp(name, "space"))
!         x->x_sep[0] = ' ';
!       else if(!strcmp(name, "dollar"))
!         x->x_sep[0] = '$';
!       else if(!strcmp(name, "comma"))
!         x->x_sep[0] = ',';
!       else if(!strcmp(name, "semi"))
!         x->x_sep[0] = ';';
!       else if(!strcmp(name, "leftbrace"))
!         x->x_sep[0] = '{';
!       else if(!strcmp(name, "rightbrace"))
!         x->x_sep[0] = '}';
!       else
!         x->x_sep[0] = '/';
!     }
!     else if(IS_A_FLOAT(av, 0))
!     {
!       t_int i=atom_getintarg(0, ac, av);
! 
!       x->x_sep[0] = (char)i + '0';/* you can set any separator-char by setting a number between -32 ... 223 */
!     }
!   }
!   else
!     x->x_sep[0] = 0;
  }
  
  static void splitfilename_symbol(t_splitfilename *x, t_symbol *s)
  {
!   t_int length = strlen(s->s_name);
!   
!   if(length)
!   {
!     if(x->x_sep[0])
!     {
!       char *sep_ptr=x->x_mem;
!       
!       if(length > x->x_size)
!       {
!         x->x_mem = (char *)resizebytes(x->x_mem, x->x_size*sizeof(char), (length+100)*sizeof(char));
!         x->x_size = length + 100;
!       }
!       strcpy(x->x_mem, s->s_name);
!       sep_ptr = strrchr(x->x_mem, x->x_sep[0]);/* points to the leftest separator-char-index of string */
!       if((!sep_ptr) || ((sep_ptr - x->x_mem) < 0) || ((sep_ptr - x->x_mem) >= length))
!       { /* JMZ: 20050701 : removed typecast (char*) to (int); this is not portable */
!         outlet_symbol(x->x_outfile, &s_);
!         outlet_symbol(x->x_outpath, gensym(x->x_mem));
!       }
!       else
!       {
!         *sep_ptr = 0;
!         sep_ptr++;
!         outlet_symbol(x->x_outfile, gensym(sep_ptr));
!         outlet_symbol(x->x_outpath, gensym(x->x_mem));
!       }
!     }
!     else
!     {
!       outlet_symbol(x->x_outfile, &s_);
!       outlet_symbol(x->x_outpath, s);
!     }
!   }
! }
! 
! static void splitfilename_free(t_splitfilename *x)
! {
!   freebytes(x->x_mem, x->x_size*sizeof(char));
  }
  
  static void *splitfilename_new(t_symbol *s, int ac, t_atom *av)
  {
!   t_splitfilename *x = (t_splitfilename *)pd_new(splitfilename_class);
!   
!   x->x_sep[0] = 0;
!   x->x_sep[1] = 0;
!   if(ac == 0)
!     x->x_sep[0] = '/';
!   else
!     splitfilename_separator(x, s, ac, av);
!   x->x_size = 400;
!   x->x_mem = (char *)getbytes(x->x_size*sizeof(char));
!   x->x_outpath = (t_outlet *)outlet_new(&x->x_obj, &s_symbol);
!   x->x_outfile = (t_outlet *)outlet_new(&x->x_obj, &s_symbol);
!   return (x);
  }
  
  void splitfilename_setup(void)
  {
!   splitfilename_class = class_new(gensym("splitfilename"), (t_newmethod)splitfilename_new,
!     0, sizeof(t_splitfilename), 0, A_GIMME, 0);
!   class_addsymbol(splitfilename_class, splitfilename_symbol);
!   class_addmethod(splitfilename_class, (t_method)splitfilename_separator, gensym("separator"), A_GIMME, 0);
!   class_addmethod(splitfilename_class, (t_method)splitfilename_separator, gensym("sep"), A_GIMME, 0);
!   class_sethelpsymbol(splitfilename_class, gensym("iemhelp/help-splitfilename"));
  }





More information about the Pd-cvs mailing list