[PD-cvs] externals/mrpeach/str str.c,1.2,1.3

Martin Peach mrpeach at users.sourceforge.net
Wed Nov 7 21:26:13 CET 2007


Update of /cvsroot/pure-data/externals/mrpeach/str
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25016

Modified Files:
	str.c 
Log Message:
Now uses blobs instead of strings.


Index: str.c
===================================================================
RCS file: /cvsroot/pure-data/externals/mrpeach/str/str.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** str.c	11 Feb 2007 17:01:45 -0000	1.2
--- str.c	7 Nov 2007 20:26:11 -0000	1.3
***************
*** 7,11 ****
  #include "m_pd.h"
  
! #ifndef PD_STRINGS /* PD_STRINGS is not defined in m_pd.h: No PD string support: Make a dummy str object */
  typedef struct _str
  {
--- 7,11 ----
  #include "m_pd.h"
  
! #ifndef PD_BLOBS /* PD_BLOBS is not defined in m_pd.h: No PD blob support: Make a dummy str object */
  typedef struct _str
  {
***************
*** 31,35 ****
      str_class = class_new(gensym("str"), (t_newmethod)str_new, 0, sizeof(t_str), 0, 0);
  }
! #else //ifndef PD_STRINGS
  /* Make a _real_ str object: */
  
--- 31,35 ----
      str_class = class_new(gensym("str"), (t_newmethod)str_new, 0, sizeof(t_str), 0, 0);
  }
! #else //ifndef PD_BLOBS
  /* Make a _real_ str object: */
  
***************
*** 57,65 ****
      t_float         x_nsplit;
      str_function    x_function;
!     t_string        x_buf;
!     t_string        x_string_in1;
!     t_string        x_string_in2;
!     t_string        x_string_out1;
!     t_string        x_string_out2;
      t_atom          *x_atom_list;
      size_t          x_atom_list_end;
--- 57,65 ----
      t_float         x_nsplit;
      str_function    x_function;
!     t_blob        x_buf;
!     t_blob        x_string_in1;
!     t_blob        x_string_in2;
!     t_blob        x_string_out1;
!     t_blob        x_string_out2;
      t_atom          *x_atom_list;
      size_t          x_atom_list_end;
***************
*** 75,83 ****
  } t_str;
  
! //typedef struct _string /* pointer to a string */
  //{
! //   unsigned long s_length; /* length of string in bytes */
! //   unsigned char *s_data; /* pointer to 1st byte of string */
! //} t_string;
  
  static t_class *str_class;
--- 75,83 ----
  } t_str;
  
! //typedef struct _blob /* pointer to a blob */
  //{
! //   unsigned long s_length; /* length of blob in bytes */
! //   unsigned char *s_data; /* pointer to 1st byte of blob */
! //} t_blob;
  
  static t_class *str_class;
***************
*** 95,101 ****
  static void str_list(t_str *x, t_symbol *s, int argc, t_atom *argv);
  static void str_anything(t_str *x, t_symbol *s, int argc, t_atom *argv);
! static void str_string(t_str *x, t_string *st);
! static void str_set_string(t_string *dest, t_string *src, size_t *len);
! static void str_buf_to_string(t_str *x, t_string *dest);
  static void str_float_to_buf(t_str *x, t_float f);
  static void str_str_to_buf (t_str *x, t_atom *a);
--- 95,101 ----
  static void str_list(t_str *x, t_symbol *s, int argc, t_atom *argv);
  static void str_anything(t_str *x, t_symbol *s, int argc, t_atom *argv);
! static void str_string(t_str *x, t_blob *st);
! static void str_set_string(t_blob *dest, t_blob *src, size_t *len);
! static void str_buf_to_string(t_str *x, t_blob *dest);
  static void str_float_to_buf(t_str *x, t_float f);
  static void str_str_to_buf (t_str *x, t_atom *a);
***************
*** 105,109 ****
  static void str_fread(t_str *x, t_symbol *s, int argc, t_atom *argv);
  static void str_fwrite(t_str *x, t_symbol *s, int argc, t_atom *argv);
! static void str_set_second(t_str *x, t_string *st);
  static int str_equal(t_str *x);
  static void str_join(t_str *x);
--- 105,109 ----
  static void str_fread(t_str *x, t_symbol *s, int argc, t_atom *argv);
  static void str_fwrite(t_str *x, t_symbol *s, int argc, t_atom *argv);
! static void str_set_second(t_str *x, t_blob *st);
  static int str_equal(t_str *x);
  static void str_join(t_str *x);
***************
*** 272,276 ****
      for (j = 0; j < n; ++j)
      { /* concatenate all arguments into a single string */
!         if (a[j].a_type == A_STRING)
          { /* already a string */
              str_str_to_buf(x, &a[j]);
--- 272,276 ----
      for (j = 0; j < n; ++j)
      { /* concatenate all arguments into a single string */
!         if (a[j].a_type == A_BLOB)
          { /* already a string */
              str_str_to_buf(x, &a[j]);
***************
*** 293,300 ****
      size_t len, limit, i, j;
      char *cP = (char *)x->x_buf.s_data + x->x_buf_end;
!     t_string *str = atom_getstring(a);
      if (str == NULL)
      {
!         post ("str_str_to_buf: null string. Need a string to point to....");
          return;
      }
--- 293,300 ----
      size_t len, limit, i, j;
      char *cP = (char *)x->x_buf.s_data + x->x_buf_end;
!     t_blob *str = atom_getblob(a);
      if (str == NULL)
      {
!         post ("str_str_to_buf: null blob. Need a blob to point to....");
          return;
      }
***************
*** 310,314 ****
  * increment x->x_buf_end by the number of chars added to x->x_buf.s_data*/
  {                                                                                                                               char *cP = (char *)x->x_buf.s_data + x->x_buf_end;
!     atom_string(a, cP, x->x_buf.s_length-x->x_buf_end);
      x->x_buf_end += strlen(cP);
  }
--- 310,314 ----
  * increment x->x_buf_end by the number of chars added to x->x_buf.s_data*/
  {                                                                                                                               char *cP = (char *)x->x_buf.s_data + x->x_buf_end;
!     atom_blob(a, cP, x->x_buf.s_length-x->x_buf_end);
      x->x_buf_end += strlen(cP);
  }
***************
*** 335,339 ****
   }
  
! static void str_buf_to_string(t_str *x, t_string *dest)
  /* copy x->x_buf_end bytes of x->x_buf.s_data into dest */
  {
--- 335,339 ----
   }
  
! static void str_buf_to_string(t_str *x, t_blob *dest)
  /* copy x->x_buf_end bytes of x->x_buf.s_data into dest */
  {
***************
*** 351,355 ****
  }
  
! static void str_set_string(t_string *dest, t_string *src, size_t *len)
  /* Copy src into dest up to the shorter of dest->s_length and src->s_length
  *  and set len to number of bytes copied */
--- 351,355 ----
  }
  
! static void str_set_string(t_blob *dest, t_blob *src, size_t *len)
  /* Copy src into dest up to the shorter of dest->s_length and src->s_length
  *  and set len to number of bytes copied */
***************
*** 458,463 ****
  }
  
! static void str_set_second(t_str *x, t_string *st)
! { /* Inlet 2 accepts strings only: Set string_in2 */
      /*post("x=%p str_set_second(%p): %s %p %lu",
          x, &str_set_second, str_function_names[x->x_function], st, st->s_length);*/
--- 458,463 ----
  }
  
! static void str_set_second(t_str *x, t_blob *st)
! { /* Inlet 2 accepts blobs only: Set string_in2 */
      /*post("x=%p str_set_second(%p): %s %p %lu",
          x, &str_set_second, str_function_names[x->x_function], st, st->s_length);*/
***************
*** 466,472 ****
  }
  
! static void str_string(t_str *x, t_string *st)
  {
!     /*post("x=%p str_string (%p) string %p %lu", x, &str_string, st, st->s_length);*/
      str_set_string(&x->x_string_in1, st, &x->x_string_in1_end);
      if (x->x_function == drip) x->x_nsplit = 0L;
--- 466,472 ----
  }
  
! static void str_string(t_str *x, t_blob *st)
  {
!     /*post("x=%p str_string (%p) blob %p %lu", x, &str_string, st, st->s_length);*/
      str_set_string(&x->x_string_in1, st, &x->x_string_in1_end);
      if (x->x_function == drip) x->x_nsplit = 0L;
***************
*** 533,537 ****
      x->x_string_in1.s_length = x->x_string_in1_end;
  //    post("str_do_out0: x->x_string_in1.s_data[0] = %d", x->x_string_in1.s_data[0]);
!     outlet_string(x->x_outlet_1, &x->x_string_in1);
      x->x_string_in1.s_length = true_length;
  }
--- 533,537 ----
      x->x_string_in1.s_length = x->x_string_in1_end;
  //    post("str_do_out0: x->x_string_in1.s_data[0] = %d", x->x_string_in1.s_data[0]);
!     outlet_blob(x->x_outlet_1, &x->x_string_in1);
      x->x_string_in1.s_length = true_length;
  }
***************
*** 543,547 ****
      x->x_string_out1.s_length = x->x_string_out1_end;
  //    post("str_do_out1: x->x_string_out1.s_data[0] = %d", x->x_string_out1.s_data[0]);
!     outlet_string(x->x_outlet_1, &x->x_string_out1);
      x->x_string_out1.s_length = true_length;
  }
--- 543,547 ----
      x->x_string_out1.s_length = x->x_string_out1_end;
  //    post("str_do_out1: x->x_string_out1.s_data[0] = %d", x->x_string_out1.s_data[0]);
!     outlet_blob(x->x_outlet_1, &x->x_string_out1);
      x->x_string_out1.s_length = true_length;
  }
***************
*** 553,557 ****
      x->x_string_out2.s_length = x->x_string_out2_end;
  //    post("str_do_out2: x->x_string_out2.s_data[0] = %d", x->x_string_out2.s_data[0]);
!     outlet_string(x->x_outlet_2, &x->x_string_out2);
      x->x_string_out2.s_length = true_length;
  }
--- 553,557 ----
      x->x_string_out2.s_length = x->x_string_out2_end;
  //    post("str_do_out2: x->x_string_out2.s_data[0] = %d", x->x_string_out2.s_data[0]);
!     outlet_blob(x->x_outlet_2, &x->x_string_out2);
      x->x_string_out2.s_length = true_length;
  }
***************
*** 564,568 ****
      size_t  true_length = x->x_string_in2.s_length;
      x->x_string_in2.s_length = x->x_string_in2_end;
!     outlet_string(x->x_outlet_1, &x->x_string_in2);
      x->x_string_in2.s_length = true_length;
  }
--- 564,568 ----
      size_t  true_length = x->x_string_in2.s_length;
      x->x_string_in2.s_length = x->x_string_in2_end;
!     outlet_blob(x->x_outlet_1, &x->x_string_in2);
      x->x_string_in2.s_length = true_length;
  }
***************
*** 683,687 ****
      if (argv[0].a_type == A_SYMBOL)
      { /* the first argument may be a selector */
!         atom_string(&argv[0], (char *)x->x_buf.s_data, MAXPDSTRING);
          for (i = 0; i < n_functions; ++i)
          {
--- 683,687 ----
      if (argv[0].a_type == A_SYMBOL)
      { /* the first argument may be a selector */
!         atom_blob(&argv[0], (char *)x->x_buf.s_data, MAXPDSTRING);
          for (i = 0; i < n_functions; ++i)
          {
***************
*** 713,717 ****
      else if ((x->x_function == join)||(x->x_function == compare)||(x->x_function == add))
      { /* argument goes to string_in2, add a string inlet */
!         x->x_inlet_2 = inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_string, gensym("")); /* gensym("string") */
          str_list_to_buf(x, &argv[next], argc-next);
          x->x_string_in2_end = x->x_buf_end;
--- 713,717 ----
      else if ((x->x_function == join)||(x->x_function == compare)||(x->x_function == add))
      { /* argument goes to string_in2, add a string inlet */
!         x->x_inlet_2 = inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_blob, gensym("")); /* gensym("blob") */
          str_list_to_buf(x, &argv[next], argc-next);
          x->x_string_in2_end = x->x_buf_end;
***************
*** 738,748 ****
      class_addlist(str_class, str_list);
      class_addanything(str_class, str_anything);
!     class_addstring(str_class, str_string);
      class_addmethod(str_class, (t_method)str_set, gensym("set"), A_GIMME, 0);
      class_addmethod(str_class, (t_method)str_fread, gensym("file_read"), A_GIMME, 0);
      class_addmethod(str_class, (t_method)str_fwrite, gensym("file_write"), A_GIMME, 0);
!     class_addmethod(str_class, (t_method)str_set_second, gensym(""), A_STRING, 0);
  }
! #endif // ifndef PD_STRINGS
  /* end str.c */
  
--- 738,748 ----
      class_addlist(str_class, str_list);
      class_addanything(str_class, str_anything);
!     class_addblob(str_class, str_string);
      class_addmethod(str_class, (t_method)str_set, gensym("set"), A_GIMME, 0);
      class_addmethod(str_class, (t_method)str_fread, gensym("file_read"), A_GIMME, 0);
      class_addmethod(str_class, (t_method)str_fwrite, gensym("file_write"), A_GIMME, 0);
!     class_addmethod(str_class, (t_method)str_set_second, gensym(""), A_BLOB, 0);
  }
! #endif // ifndef PD_BLOBS
  /* end str.c */
  





More information about the Pd-cvs mailing list