aboutsummaryrefslogtreecommitdiff
path: root/src/atoi.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/atoi.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/atoi.c')
-rw-r--r--src/atoi.c98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/atoi.c b/src/atoi.c
new file mode 100644
index 0000000..2dcd325
--- /dev/null
+++ b/src/atoi.c
@@ -0,0 +1,98 @@
+/******************************************************
+ *
+ * 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>
+
+/*
+ * atoi : ascii to integer
+*/
+
+/* atoi :: ascii to integer */
+
+static t_class *atoi_class;
+
+typedef struct _atoi
+{
+ t_object x_obj;
+ int i;
+} t_atoi;
+static void atoi_bang(t_atoi *x)
+{
+ outlet_float(x->x_obj.ob_outlet, (t_float)x->i);
+}
+static void atoi_float(t_atoi *x, t_floatarg f)
+{
+ x->i = f;
+ outlet_float(x->x_obj.ob_outlet, (t_float)x->i);
+}
+static void atoi_symbol(t_atoi *x, t_symbol *s)
+{
+ int base=10;
+ const char* c = s->s_name;
+ if(c[0]=='0'){
+ base=8;
+ if (c[1]=='x')base=16;
+ }
+ x->i=strtol(c, 0, base);
+ outlet_float(x->x_obj.ob_outlet, (t_float)x->i);
+}
+static void atoi_list(t_atoi *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int base=10;
+ const char* c;
+
+ if (argv->a_type==A_FLOAT){
+ x->i=atom_getfloat(argv);
+ outlet_float(x->x_obj.ob_outlet, (t_float)x->i);
+ return;
+ }
+
+ if (argc>1){
+ base=atom_getfloat(argv+1);
+ if (base<2) {
+ error("atoi: setting base to 10");
+ base=10;
+ }
+ }
+ c=atom_getsymbol(argv)->s_name;
+ x->i=strtol(c, 0, base);
+ outlet_float(x->x_obj.ob_outlet, (t_float)x->i);
+}
+
+static void *atoi_new(void)
+{
+ t_atoi *x = (t_atoi *)pd_new(atoi_class);
+ outlet_new(&x->x_obj, gensym("float"));
+ return (x);
+}
+
+void atoi_setup(void)
+{
+ atoi_class = class_new(gensym("atoi"), (t_newmethod)atoi_new, 0,
+ sizeof(t_atoi), 0, A_DEFFLOAT, 0);
+
+ class_addbang(atoi_class, (t_method)atoi_bang);
+ class_addfloat(atoi_class, (t_method)atoi_float);
+ class_addlist(atoi_class, (t_method)atoi_list);
+ class_addsymbol(atoi_class, (t_method)atoi_symbol);
+ class_addanything(atoi_class, (t_method)atoi_symbol);
+
+ class_sethelpsymbol(atoi_class, gensym("zexy/atoi"));
+ zexy_register("atoi");
+}