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

« back to all changes in this revision

Viewing changes to src/strcmp.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
#include "zexy.h"
 
18
#include <stdlib.h>
 
19
#include <string.h>
 
20
 
 
21
/*
 
22
 * strcmp    : compare 2 lists as if they were strings
 
23
*/
 
24
 
 
25
/* ------------------------- strcmp ------------------------------- */
 
26
 
 
27
/* compare 2 lists ( == for lists) */
 
28
 
 
29
static t_class *strcmp_class;
 
30
static t_class *strcmp_proxy_class;
 
31
 
 
32
 
 
33
typedef struct _strcmp
 
34
{
 
35
  t_object x_obj;
 
36
  struct _strcmp_proxy  *x_proxy;
 
37
 
 
38
  t_binbuf *bbuf1, *bbuf2;
 
39
  char *str1, *str2;
 
40
  int n1, n2;
 
41
} t_strcmp;
 
42
 
 
43
typedef struct _strcmp_proxy
 
44
{
 
45
  t_pd  p_pd;
 
46
  t_strcmp    *p_master;
 
47
  t_inlet *p_in;
 
48
} t_strcmp_proxy;
 
49
 
 
50
static void strcmp_bang(t_strcmp *x)
 
51
{
 
52
  int result = 0;
 
53
  if(x->str1){
 
54
    if(x->str2)
 
55
      result = strcmp(x->str1, x->str2);
 
56
    else
 
57
      result = *x->str1;
 
58
  } else {
 
59
    if(x->str2)
 
60
      result = -*x->str2;
 
61
    else
 
62
      result = 0;
 
63
  }
 
64
 
 
65
  outlet_float(x->x_obj.ob_outlet, result);
 
66
}
 
67
 
 
68
static void list2binbuf(t_binbuf**bbuf, int *n, char**str, int argc, t_atom*argv)
 
69
{
 
70
  int i=0;
 
71
  char*s=0;
 
72
  if(*str&&*n)freebytes(*str, *n);
 
73
 
 
74
  binbuf_clear(*bbuf);
 
75
  binbuf_add(*bbuf, argc, argv);
 
76
  binbuf_gettext(*bbuf, str, n);
 
77
  i=*n;
 
78
  s=*str;
 
79
 
 
80
  if(' '==s[i])s[i]=0;
 
81
}
 
82
 
 
83
static void strcmp_list(t_strcmp *x, t_symbol *s, int argc, t_atom *argv)
 
84
{
 
85
  ZEXY_USEVAR(s);
 
86
  list2binbuf(&x->bbuf1, &x->n1, &x->str1, argc, argv);
 
87
  strcmp_bang(x);
 
88
}
 
89
static void strcmp_symbol(t_strcmp *x, t_symbol *s)
 
90
{
 
91
  if(x->str1&&x->n1)freebytes(x->str1, x->n1);
 
92
  x->n1=0;
 
93
  x->str1=s->s_name;
 
94
  strcmp_bang(x);
 
95
}
 
96
 
 
97
static void strcmp_secondlist(t_strcmp *x, t_symbol *s, int argc, t_atom *argv)
 
98
{
 
99
  ZEXY_USEVAR(s);
 
100
  list2binbuf(&x->bbuf2, &x->n2, &x->str2, argc, argv);
 
101
}
 
102
static void strcmp_secondsymbol(t_strcmp *x, t_symbol *s)
 
103
{
 
104
  if(x->str2&&x->n2)freebytes(x->str2, x->n2);
 
105
  x->n2=0;
 
106
  x->str2=s->s_name;
 
107
}
 
108
 
 
109
static void strcmp_proxy_list(t_strcmp_proxy *y, t_symbol *s, int argc, t_atom *argv)
 
110
{
 
111
  strcmp_secondlist(y->p_master, s, argc, argv);
 
112
}
 
113
static void strcmp_proxy_symbol(t_strcmp_proxy *y, t_symbol *s)
 
114
{
 
115
  if(s)strcmp_secondsymbol(y->p_master, s);
 
116
}
 
117
 
 
118
static void *strcmp_new(t_symbol *s, int argc, t_atom *argv)
 
119
{
 
120
  t_strcmp *x = (t_strcmp *)pd_new(strcmp_class);
 
121
  ZEXY_USEVAR(s);
 
122
 
 
123
  x->x_proxy=(t_strcmp_proxy*)pd_new(strcmp_proxy_class);
 
124
  x->x_proxy->p_master = x;
 
125
  x->x_proxy->p_in = inlet_new ((t_object*)x, (t_pd*)x->x_proxy, 0,0);
 
126
 
 
127
  outlet_new(&x->x_obj, 0);
 
128
 
 
129
  x->bbuf1 = binbuf_new();
 
130
  x->bbuf2 = binbuf_new();
 
131
 
 
132
  x->str1=0;
 
133
  x->str2=0;
 
134
  x->n1=0;
 
135
  x->n2=0;
 
136
 
 
137
  if(argc)strcmp_secondlist(x, gensym("list"), argc, argv);
 
138
 
 
139
  return (x);
 
140
}
 
141
 
 
142
static void strcmp_free(t_strcmp *x)
 
143
{
 
144
  binbuf_free(x->bbuf1);
 
145
  binbuf_free(x->bbuf2);
 
146
  if(x->str1&&x->n1)freebytes(x->str1, x->n1);
 
147
  if(x->str2&&x->n2)freebytes(x->str2, x->n2);
 
148
 
 
149
  inlet_free(x->x_proxy->p_in);
 
150
  x->x_proxy->p_master=0;
 
151
  pd_free(&x->x_proxy->p_pd);
 
152
}
 
153
 
 
154
 
 
155
static void strcmp_help(t_strcmp*x)
 
156
{
 
157
  post("\n%c strcmp\t\t:: compare to lists as strings", HEARTSYMBOL);
 
158
}
 
159
 
 
160
 
 
161
void strcmp_setup(void)
 
162
{
 
163
  strcmp_class = class_new(gensym("strcmp"), (t_newmethod)strcmp_new, 
 
164
                         (t_method)strcmp_free, sizeof(t_strcmp), 0, A_GIMME, 0);
 
165
 
 
166
  class_addbang    (strcmp_class, strcmp_bang);
 
167
  class_addsymbol  (strcmp_class, strcmp_symbol);
 
168
  class_addlist    (strcmp_class, strcmp_list);
 
169
 
 
170
  strcmp_proxy_class = class_new(gensym("strcmp proxy"), 0, 0,
 
171
                                 sizeof(t_strcmp_proxy),
 
172
                                 CLASS_PD | CLASS_NOINLET, 0);
 
173
  class_addsymbol(strcmp_proxy_class, strcmp_proxy_symbol);
 
174
  class_addlist(strcmp_proxy_class, strcmp_proxy_list);
 
175
  class_addmethod(strcmp_class, (t_method)strcmp_help, gensym("help"), A_NULL);
 
176
  zexy_register("strcmp");
 
177
}