~ubuntu-branches/ubuntu/natty/pd-zexy/natty

« back to all changes in this revision

Viewing changes to src/atoi.c

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard, IOhannes m zmölnig, Jonas Smedegaard
  • Date: 2010-08-20 12:17:41 UTC
  • mfrom: (2.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100820121741-4kxozn8b9rhee9fr
Tags: 2.2.3-1
* New upstream version

[ IOhannes m zmölnig ]
* Adopt package, on behalf of Multimedia Team.
  Closes: #546964
* Simply debian/rules with CDBS, and don't unconditionally strip
  binaries.
  Closes: #437763
* Install into /usr/lib/pd/extra/zexy/. Document usage in REAME.Debian
  and warn about change in NEWS.
* git'ify package. Add Vcs-* stanzas to control file.
* Use dpkg source format 3.0 (quilt). Drop build-dependency on quilt.

[ Jonas Smedegaard ]
* Enable CDBS copyright-check routine.
* Add copyright and licensing header to debian/rules.
* Add myself as uploader.
* Rewrite debian/copyright using rev. 135 of draft DEP5 format.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************
 
2
 *
 
3
 * zexy - implementation file
 
4
 *
 
5
 * copyleft (c) IOhannes m zm�lnig
 
6
 *
 
7
 *   1999:forum::f�r::uml�ute:2004
 
8
 *
 
9
 *   institute of electronic music and acoustics (iem)
 
10
 *
 
11
 ******************************************************
 
12
 *
 
13
 * license: GNU General Public License v.2
 
14
 *
 
15
 ******************************************************/
 
16
 
 
17
 
 
18
#include "zexy.h"
 
19
#include <stdlib.h>
 
20
 
 
21
/*
 
22
 * atoi : ascii to integer
 
23
 */
 
24
 
 
25
/* atoi ::  ascii to integer */
 
26
 
 
27
static t_class *atoi_class;
 
28
 
 
29
typedef struct _atoi
 
30
{
 
31
  t_object x_obj;
 
32
  int i;
 
33
} t_atoi;
 
34
static void atoi_bang(t_atoi *x)
 
35
{
 
36
  outlet_float(x->x_obj.ob_outlet, (t_float)x->i);
 
37
}
 
38
static void atoi_float(t_atoi *x, t_floatarg f)
 
39
{
 
40
  x->i = f;
 
41
  outlet_float(x->x_obj.ob_outlet, (t_float)x->i);
 
42
}
 
43
static void atoi_symbol(t_atoi *x, t_symbol *s)
 
44
{
 
45
  int base=10;
 
46
  const char* c = s->s_name;
 
47
  if(c[0]=='0'){
 
48
    base=8;
 
49
    if (c[1]=='x')base=16;
 
50
  }
 
51
  x->i=strtol(c, 0, base);
 
52
  outlet_float(x->x_obj.ob_outlet, (t_float)x->i);
 
53
}
 
54
static void atoi_list(t_atoi *x, t_symbol *s, int argc, t_atom *argv)
 
55
{
 
56
  int base=10;
 
57
  const char* c;
 
58
  ZEXY_USEVAR(s);
 
59
 
 
60
  if (argv->a_type==A_FLOAT){
 
61
    x->i=atom_getfloat(argv);
 
62
    outlet_float(x->x_obj.ob_outlet, (t_float)x->i);
 
63
    return;
 
64
  }
 
65
 
 
66
  if (argc>1){
 
67
    base=atom_getfloat(argv+1);
 
68
    if (base<2) {
 
69
      error("atoi: setting base to 10");
 
70
      base=10;
 
71
    }
 
72
  }
 
73
  c=atom_getsymbol(argv)->s_name;
 
74
  x->i=strtol(c, 0, base);
 
75
  outlet_float(x->x_obj.ob_outlet, (t_float)x->i);
 
76
}
 
77
 
 
78
static void *atoi_new(void)
 
79
{
 
80
  t_atoi *x = (t_atoi *)pd_new(atoi_class);
 
81
  outlet_new(&x->x_obj, &s_float);
 
82
  return (x);
 
83
}
 
84
 
 
85
void atoi_setup(void)
 
86
{
 
87
  atoi_class = class_new(gensym("atoi"), (t_newmethod)atoi_new, 0,
 
88
                         sizeof(t_atoi), 0, A_DEFFLOAT, 0);
 
89
 
 
90
  class_addbang(atoi_class, (t_method)atoi_bang);
 
91
  class_addfloat(atoi_class, (t_method)atoi_float);
 
92
  class_addlist(atoi_class, (t_method)atoi_list);
 
93
  class_addsymbol(atoi_class, (t_method)atoi_symbol);
 
94
  class_addanything(atoi_class, (t_method)atoi_symbol);
 
95
 
 
96
  zexy_register("atoi");
 
97
}