[PD-cvs] externals/iemlib/src/iemlib2 mergefilename.c,1.3,1.4

musil tmusil at users.sourceforge.net
Wed Jan 4 02:04:48 CET 2006


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

Modified Files:
	mergefilename.c 
Log Message:
new malloc

Index: mergefilename.c
===================================================================
RCS file: /cvsroot/pure-data/externals/iemlib/src/iemlib2/mergefilename.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** mergefilename.c	8 Jul 2005 02:04:25 -0000	1.3
--- mergefilename.c	4 Jan 2006 01:04:46 -0000	1.4
***************
*** 26,29 ****
--- 26,31 ----
    t_object x_obj;
    char     x_sep[2];
+   char     *x_mem;
+   t_int    x_size;
  } t_mergefilename;
  
***************
*** 34,56 ****
      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
--- 36,60 ----
      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
***************
*** 59,68 ****
      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';
      }
--- 63,68 ----
      else if(IS_A_FLOAT(av, 0))
      {
!       t_int i=atom_getintarg(0, ac, av);
        
        x->x_sep[0] = (char)i + '0';
      }
***************
*** 74,82 ****
  static void mergefilename_float(t_mergefilename *x, t_floatarg f)
  {
!   char fbuf[30];
    
!   fbuf[0] = 0;
!   sprintf(fbuf, "%g", f);
!   outlet_symbol(x->x_obj.ob_outlet, gensym(fbuf));
  }
  
--- 74,82 ----
  static void mergefilename_float(t_mergefilename *x, t_floatarg f)
  {
!   char flt_buf[30];
    
!   flt_buf[0] = 0;
!   sprintf(flt_buf, "%g", f);
!   outlet_symbol(x->x_obj.ob_outlet, gensym(flt_buf));
  }
  
***************
*** 88,120 ****
  static void mergefilename_list(t_mergefilename *x, t_symbol *s, int ac, t_atom *av)
  {
!   char *cbeg, fbuf[30];
!   int size=400, i, len, cursize=0;
    
!   cbeg = (char *)getbytes(size * sizeof(char));
!   cbeg[0] = 0;
    if(ac > 0)
    {
      if(IS_A_SYMBOL(av, 0))
      {
!       len = strlen(av->a_w.w_symbol->s_name);
!       if((len + cursize) >= (size-1))
        {
!         cbeg = (char *)resizebytes(cbeg, size*sizeof(char), 2*(len + cursize)*sizeof(char));
!         size = 2*(len + cursize);
        }
!       strcat(cbeg, av->a_w.w_symbol->s_name);
!       cursize += len;
      }
      else if(IS_A_FLOAT(av, 0))
      {
!       sprintf(fbuf, "%g", av->a_w.w_float);
!       len = strlen(fbuf);
!       if((len + cursize) >= (size-1))
        {
!         cbeg = (char *)resizebytes(cbeg, size*sizeof(char), 2*(len + cursize)*sizeof(char));
!         size = 2*(len + cursize);
        }
!       strcat(cbeg, fbuf);
!       cursize += len;
      }
    }
--- 88,119 ----
  static void mergefilename_list(t_mergefilename *x, t_symbol *s, int ac, t_atom *av)
  {
!   char flt_buf[30];
!   t_int i, length, accu_size=0;
    
!   x->x_mem[0] = 0;
    if(ac > 0)
    {
      if(IS_A_SYMBOL(av, 0))
      {
!       length = strlen(av->a_w.w_symbol->s_name);
!       if((length + accu_size) >= (x->x_size-2))
        {
!         x->x_mem = (char *)resizebytes(x->x_mem, x->x_size*sizeof(char), 2*(length + accu_size)*sizeof(char));
!         x->x_size = 2*(length + accu_size);
        }
!       strcat(x->x_mem, av->a_w.w_symbol->s_name);
!       accu_size += length;
      }
      else if(IS_A_FLOAT(av, 0))
      {
!       sprintf(flt_buf, "%g", av->a_w.w_float);
!       length = strlen(flt_buf);
!       if((length + accu_size) >= (x->x_size-2))
        {
!         x->x_mem = (char *)resizebytes(x->x_mem, x->x_size*sizeof(char), 2*(length + accu_size)*sizeof(char));
!         x->x_size = 2*(length + accu_size);
        }
!       strcat(x->x_mem, flt_buf);
!       accu_size += length;
      }
    }
***************
*** 125,206 ****
      {
        av++;
!       strcat(cbeg, x->x_sep);
        if(IS_A_SYMBOL(av, 0))
        {
!         len = strlen(av->a_w.w_symbol->s_name);
!         if((len + cursize) >= (size-1))
          {
!           cbeg = (char *)resizebytes(cbeg, size*sizeof(char), 2*(len + cursize)*sizeof(char));
!           size = 2*(len + cursize);
          }
!         strcat(cbeg, av->a_w.w_symbol->s_name);
!         cursize += len;
        }
        else if(IS_A_FLOAT(av, 0))
        {
!         sprintf(fbuf, "%g", av->a_w.w_float);
!         len = strlen(fbuf);
!         if((len + cursize) >= (size-1))
          {
!           cbeg = (char *)resizebytes(cbeg, size*sizeof(char), 2*(len + cursize)*sizeof(char));
!           size = 2*(len + cursize);
          }
!         strcat(cbeg, fbuf);
!         cursize += len;
        }
      }
    }
!   outlet_symbol(x->x_obj.ob_outlet, gensym(cbeg));
!   freebytes(cbeg, size * sizeof(char));
  }
  
  static void mergefilename_anything(t_mergefilename *x, t_symbol *s, int ac, t_atom *av)
  {
!   char *cbeg, fbuf[30];
!   int size=400, i, len, cursize=0;
    
!   cbeg = (char *)getbytes(size * sizeof(char));
!   cbeg[0] = 0;
!   len = strlen(s->s_name);
!   if((len + cursize) >= (size-1))
    {
!     cbeg = (char *)resizebytes(cbeg, size*sizeof(char), 2*(len + cursize)*sizeof(char));
!     size = 2*(len + cursize);
    }
!   strcat(cbeg, s->s_name);
!   cursize += len;
    if(ac > 0)
    {
      for(i=0; i<ac; i++)
      {
!       strcat(cbeg, x->x_sep);
        if(IS_A_SYMBOL(av, 0))
        {
!         len = strlen(av->a_w.w_symbol->s_name);
!         if((len + cursize) >= (size-1))
          {
!           cbeg = (char *)resizebytes(cbeg, size*sizeof(char), 2*(len + cursize)*sizeof(char));
!           size = 2*(len + cursize);
          }
!         strcat(cbeg, av->a_w.w_symbol->s_name);
!         cursize += len;
        }
        else if(IS_A_FLOAT(av, 0))
        {
!         sprintf(fbuf, "%g", av->a_w.w_float);
!         len = strlen(fbuf);
!         if((len + cursize) >= (size-1))
          {
!           cbeg = (char *)resizebytes(cbeg, size*sizeof(char), 2*(len + cursize)*sizeof(char));
!           size = 2*(len + cursize);
          }
!         strcat(cbeg, fbuf);
!         cursize += len;
        }
        av++;
      }
    }
!   outlet_symbol(x->x_obj.ob_outlet, gensym(cbeg));
!   freebytes(cbeg, size * sizeof(char));
  }
  
--- 124,207 ----
      {
        av++;
!       strcat(x->x_mem, x->x_sep);
        if(IS_A_SYMBOL(av, 0))
        {
!         length = strlen(av->a_w.w_symbol->s_name);
!         if((length + accu_size) >= (x->x_size-2))
          {
!           x->x_mem = (char *)resizebytes(x->x_mem, x->x_size*sizeof(char), 2*(length + accu_size)*sizeof(char));
!           x->x_size = 2*(length + accu_size);
          }
!         strcat(x->x_mem, av->a_w.w_symbol->s_name);
!         accu_size += length;
        }
        else if(IS_A_FLOAT(av, 0))
        {
!         sprintf(flt_buf, "%g", av->a_w.w_float);
!         length = strlen(flt_buf);
!         if((length + accu_size) >= (x->x_size-2))
          {
!           x->x_mem = (char *)resizebytes(x->x_mem, x->x_size*sizeof(char), 2*(length + accu_size)*sizeof(char));
!           x->x_size = 2*(length + accu_size);
          }
!         strcat(x->x_mem, flt_buf);
!         accu_size += length;
        }
      }
    }
!   outlet_symbol(x->x_obj.ob_outlet, gensym(x->x_mem));
  }
  
  static void mergefilename_anything(t_mergefilename *x, t_symbol *s, int ac, t_atom *av)
  {
!   char flt_buf[30];
!   t_int i, length, accu_size=0;
    
!   x->x_mem[0] = 0;
!   length = strlen(s->s_name);
!   if((length + accu_size) >= (x->x_size-2))
    {
!     x->x_mem = (char *)resizebytes(x->x_mem, x->x_size*sizeof(char), 2*(length + accu_size)*sizeof(char));
!     x->x_size = 2*(length + accu_size);
    }
!   strcat(x->x_mem, s->s_name);
!   accu_size += length;
    if(ac > 0)
    {
      for(i=0; i<ac; i++)
      {
!       strcat(x->x_mem, x->x_sep);
        if(IS_A_SYMBOL(av, 0))
        {
!         length = strlen(av->a_w.w_symbol->s_name);
!         if((length + accu_size) >= (x->x_size-2))
          {
!           x->x_mem = (char *)resizebytes(x->x_mem, x->x_size*sizeof(char), 2*(length + accu_size)*sizeof(char));
!           x->x_size = 2*(length + accu_size);
          }
!         strcat(x->x_mem, av->a_w.w_symbol->s_name);
!         accu_size += length;
        }
        else if(IS_A_FLOAT(av, 0))
        {
!         sprintf(flt_buf, "%g", av->a_w.w_float);
!         length = strlen(flt_buf);
!         if((length + accu_size) >= (x->x_size-2))
          {
!           x->x_mem = (char *)resizebytes(x->x_mem, x->x_size*sizeof(char), 2*(length + accu_size)*sizeof(char));
!           x->x_size = 2*(length + accu_size);
          }
!         strcat(x->x_mem, flt_buf);
!         accu_size += length;
        }
        av++;
      }
    }
!   outlet_symbol(x->x_obj.ob_outlet, gensym(x->x_mem));
! }
! 
! static void mergefilename_free(t_mergefilename *x)
! {
!   freebytes(x->x_mem, x->x_size*sizeof(char));
  }
  
***************
*** 213,216 ****
--- 214,219 ----
    if(ac > 0)
      mergefilename_separator(x, s, ac, av);
+   x->x_size = 400;
+   x->x_mem = (char *)getbytes(x->x_size*sizeof(char));
    outlet_new(&x->x_obj, &s_symbol);
    return (x);





More information about the Pd-cvs mailing list