aboutsummaryrefslogtreecommitdiff
path: root/src/strcmp.c
diff options
context:
space:
mode:
authorIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2005-03-22 20:58:25 +0000
committerIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2005-03-22 20:58:25 +0000
commit2b60d55c919e7588f5aff15936e83c300b3660bb (patch)
tree14d860de7f28083d3756ad91b627de70f26788f6 /src/strcmp.c
parentc500bc542cb7cc78d6dac3f7da3bff626056b1aa (diff)
zexy-2.0:
- use of abstractions for objects that allow it - some objects are build both as externals and abstractions (as slower fallbacks) - code-layout is now 1:1 c-file<->object (this should allow for building of zexy as a collection of externals instead as a big library) - matrix-objects have moved to iemmatrix !! svn path=/trunk/externals/zexy/; revision=2641
Diffstat (limited to 'src/strcmp.c')
-rw-r--r--src/strcmp.c103
1 files changed, 103 insertions, 0 deletions
diff --git a/src/strcmp.c b/src/strcmp.c
new file mode 100644
index 0000000..4bfeb8b
--- /dev/null
+++ b/src/strcmp.c
@@ -0,0 +1,103 @@
+/******************************************************
+ *
+ * zexy - implementation file
+ *
+ * copyleft (c) IOhannes m zmölnig
+ *
+ * 1999:forum::für::umläute:2004
+ *
+ * institute of electronic music and acoustics (iem)
+ *
+ ******************************************************
+ *
+ * license: GNU General Public License v.2
+ *
+ ******************************************************/
+
+#include "zexy.h"
+#include <stdlib.h>
+#include <string.h>
+
+/*
+ * strcmp : compare 2 lists as if they were strings
+*/
+
+/* ------------------------- strcmp ------------------------------- */
+
+/* compare 2 lists ( == for lists) */
+
+static t_class *strcmp_class;
+
+typedef struct _strcmp
+{
+ t_object x_obj;
+
+ t_binbuf *bbuf1, *bbuf2;
+} t_strcmp;
+
+static void strcmp_bang(t_strcmp *x)
+{
+ char *str1=0, *str2=0;
+ int n1=0, n2=0;
+ int result = 0;
+
+ binbuf_gettext(x->bbuf1, &str1, &n1);
+ binbuf_gettext(x->bbuf2, &str2, &n2);
+
+ result = strcmp(str1, str2);
+
+ freebytes(str1, n1);
+ freebytes(str2, n2);
+
+ outlet_float(x->x_obj.ob_outlet, result);
+}
+
+static void strcmp_secondlist(t_strcmp *x, t_symbol *s, int argc, t_atom *argv)
+{
+ binbuf_clear(x->bbuf2);
+ binbuf_add(x->bbuf2, argc, argv);
+}
+
+static void strcmp_list(t_strcmp *x, t_symbol *s, int argc, t_atom *argv)
+{
+ binbuf_clear(x->bbuf1);
+ binbuf_add(x->bbuf1, argc, argv);
+
+ strcmp_bang(x);
+}
+
+static void *strcmp_new(t_symbol *s, int argc, t_atom *argv)
+{
+ t_strcmp *x = (t_strcmp *)pd_new(strcmp_class);
+
+ outlet_new(&x->x_obj, 0);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("list"), gensym("lst2"));
+
+ x->bbuf1 = binbuf_new();
+ x->bbuf2 = binbuf_new();
+
+
+ strcmp_secondlist(x, gensym("list"), argc, argv);
+
+ return (x);
+}
+
+static void strcmp_free(t_strcmp *x)
+{
+ binbuf_free(x->bbuf1);
+ binbuf_free(x->bbuf2);
+}
+
+
+void strcmp_setup(void)
+{
+ strcmp_class = class_new(gensym("strcmp"), (t_newmethod)strcmp_new,
+ (t_method)strcmp_free, sizeof(t_strcmp), 0, A_GIMME, 0);
+
+ class_addbang (strcmp_class, strcmp_bang);
+ class_addlist (strcmp_class, strcmp_list);
+ class_addmethod (strcmp_class, (t_method)strcmp_secondlist, gensym("lst2"), A_GIMME, 0);
+
+ class_sethelpsymbol(strcmp_class, gensym("zexy/strcmp"));
+ zexy_register("strcmp");
+}