Update of /cvsroot/pure-data/externals/mrpeach/str
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29872
Modified Files:
str.c
Log Message:
Modified str.c to build a dummy object if pd is not patched for string type.
Index: str.c
===================================================================
RCS file: /cvsroot/pure-data/externals/mrpeach/str/str.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** str.c 28 Jan 2007 21:21:59 -0000 1.1
--- str.c 11 Feb 2007 17:01:45 -0000 1.2
***************
*** 1,5 ****
! /* str.c by Martin Peach, started 20061227 */
/* version 20070101 no more resizing memory */
- /* The str object uses the t_string type */
#include <stdio.h>
#include <stdlib.h>
--- 1,4 ----
! /* str.c MP 20061227 */
/* version 20070101 no more resizing memory */
#include <stdio.h>
#include <stdlib.h>
***************
*** 8,14 ****
#include "m_pd.h"
! #ifndef t_string
! #error "str needs t_string support in pd source"
! #endif
typedef enum
--- 7,36 ----
#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
! {
! t_object x_obj;
! } t_str;
! static t_class *str_class;
!
! void str_setup(void);
! static void *str_new(t_symbol *s, int argc, t_atom *argv);
!
! static void *str_new(t_symbol *s, int argc, t_atom *argv)
! {
! t_str *x;
!
! x = (t_str *)pd_new(str_class);
! if (x == NULL) return (x);
! post("This str is a dummy str.");
! return (x);
! }
!
! void str_setup(void)
! {
! 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: */
typedef enum
***************
*** 53,63 ****
} 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 _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;
***************
*** 322,331 ****
limit = (dest->s_length < x->x_buf.s_length)? dest->s_length: x->x_buf.s_length;
if (limit > x->x_buf_end) limit = x->x_buf_end;/* normally the case */
! /* post("str_buf_to_string: limit %lu", limit); */
for (i = 0; i < limit; ++i)
{
dest->s_data[i] = x->x_buf.s_data[i];
}
! /* post("str_buf_to_string: new length %lu", dest->s_length); */
return;
}
--- 342,351 ----
limit = (dest->s_length < x->x_buf.s_length)? dest->s_length: x->x_buf.s_length;
if (limit > x->x_buf_end) limit = x->x_buf_end;/* normally the case */
! // post("str_buf_to_string: limit %lu", limit);
for (i = 0; i < limit; ++i)
{
dest->s_data[i] = x->x_buf.s_data[i];
}
! // post("str_buf_to_string: new length %lu", dest->s_length);
return;
}
***************
*** 456,460 ****
static void str_anything(t_str *x, t_symbol *s, int argc, t_atom *argv)
{
! /* post("str_anything"); */
x->x_buf_end = sprintf((char *)x->x_buf.s_data, "%s", s->s_name); /* the selector is just another word... */
str_list_to_buf(x, argv, argc);
--- 476,480 ----
static void str_anything(t_str *x, t_symbol *s, int argc, t_atom *argv)
{
! // post("str_anything");
x->x_buf_end = sprintf((char *)x->x_buf.s_data, "%s", s->s_name); /* the selector is just another word... */
str_list_to_buf(x, argv, argc);
***************
*** 467,471 ****
static void str_list(t_str *x, t_symbol *s, int argc, t_atom *argv)
{
! /* post("str_list"); */
x->x_buf_end = 0L;
str_list_to_buf(x, argv, argc);
--- 487,491 ----
static void str_list(t_str *x, t_symbol *s, int argc, t_atom *argv)
{
! // post("str_list");
x->x_buf_end = 0L;
str_list_to_buf(x, argv, argc);
***************
*** 478,482 ****
static void str_symbol(t_str *x, t_symbol *s)
{
! /* post("str_symbol");*/
x->x_buf_end = sprintf((char *)x->x_buf.s_data, "%s", s->s_name);
x->x_string_in1_end = x->x_buf_end;
--- 498,502 ----
static void str_symbol(t_str *x, t_symbol *s)
{
! // post("str_symbol");
x->x_buf_end = sprintf((char *)x->x_buf.s_data, "%s", s->s_name);
x->x_string_in1_end = x->x_buf_end;
***************
*** 490,494 ****
x->x_buf_end = 0L;
! /* post("str_float");*/
str_float_to_buf(x, f);
x->x_string_in1_end = x->x_buf_end;
--- 510,514 ----
x->x_buf_end = 0L;
! // post("str_float");
str_float_to_buf(x, f);
x->x_string_in1_end = x->x_buf_end;
***************
*** 500,504 ****
static void str_bang(t_str *x)
{
! /* post("str_bang");*/
if((x->x_function == add) && (x->x_string_in2_end != 0))str_do_out3(x);
else str_do_string(x);
--- 520,524 ----
static void str_bang(t_str *x)
{
! // post("str_bang");
if((x->x_function == add) && (x->x_string_in2_end != 0))str_do_out3(x);
else str_do_string(x);
***************
*** 512,516 ****
size_t true_length = x->x_string_in1.s_length;
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;
--- 532,536 ----
size_t true_length = x->x_string_in1.s_length;
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;
***************
*** 522,526 ****
size_t true_length = x->x_string_out1.s_length;
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;
--- 542,546 ----
size_t true_length = x->x_string_out1.s_length;
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;
***************
*** 532,536 ****
size_t true_length = x->x_string_out2.s_length;
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;
--- 552,556 ----
size_t true_length = x->x_string_out2.s_length;
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;
***************
*** 619,623 ****
static void str_free(t_str *x)
{
! /* post("str_free");*/
freebytes(x->x_string_out1.s_data, x->x_string_out1.s_length);
freebytes(x->x_string_out2.s_data, x->x_string_out2.s_length);
--- 639,643 ----
static void str_free(t_str *x)
{
! // post("str_free");
freebytes(x->x_string_out1.s_data, x->x_string_out1.s_length);
freebytes(x->x_string_out2.s_data, x->x_string_out2.s_length);
***************
*** 669,673 ****
{
x->x_function = i;
! /* post("str_new: x_function is %s", str_function_names[x->x_function]);*/
next = 1;
if ((x->x_function == nsplit) || (x->x_function == csplit))
--- 689,693 ----
{
x->x_function = i;
! // post("str_new: x_function is %s", str_function_names[x->x_function]);
next = 1;
if ((x->x_function == nsplit) || (x->x_function == csplit))
***************
*** 724,727 ****
--- 744,748 ----
class_addmethod(str_class, (t_method)str_set_second, gensym(""), A_STRING, 0);
}
+ #endif // ifndef PD_STRINGS
/* end str.c */