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

« back to all changes in this revision

Viewing changes to src/makesymbol.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
/* 
 
19
(l) 1210:forum::f�r::uml�ute:1999
 
20
 
 
21
"makesymbol" is something between "symbol" and "makefilename", 
 
22
   thus storing and creating (formatted) symbols...
 
23
 
 
24
 
 
25
   TODO:
 
26
    the use of only "%s" is really not very satisfying   
 
27
   LATER: 
 
28
   split the entire format string into subformats with only 
 
29
   one format-placeholder ("%[^%]*[diufFgGxXoscpn]") .
 
30
   split the entire format string into subformats with only one format-placeholder,
 
31
   store the types
 
32
   when a list comes in, evaluate each subformat (with prior type-conversion)
 
33
 
 
34
*/
 
35
 
 
36
#include "zexy.h"
 
37
 
 
38
#include <string.h>
 
39
#include <stdio.h>
 
40
 
 
41
#define MAXSTRINGARGS 10
 
42
#define MAXSTRINGLENG MAXPDSTRING
 
43
 
 
44
/* ----------------------- makesymbol --------------------- */
 
45
 
 
46
static t_class *makesymbol_class;
 
47
 
 
48
typedef struct _makesymbol
 
49
{
 
50
        t_object x_obj;
 
51
        t_symbol *x_sym;
 
52
 
 
53
        char* mask;
 
54
        char* buf;
 
55
} t_makesymbol;
 
56
 
 
57
static void reset_mask(t_makesymbol *x, t_symbol *s)
 
58
{
 
59
        if (*s->s_name) {
 
60
                x->mask = s->s_name;
 
61
                x->x_sym = s;
 
62
        } else {
 
63
                x->mask = "%s%s%s%s%s%s%s%s%s%s";
 
64
                x->x_sym = gensym("");
 
65
        }
 
66
}
 
67
 
 
68
typedef char cstring[MAXSTRINGLENG];
 
69
 
 
70
static t_symbol* list2symbol(char *masque, int argc, t_atom *argv)
 
71
{
 
72
  cstring*buf=(cstring*)getbytes(MAXSTRINGARGS*sizeof(cstring));
 
73
        cstring buffer;
 
74
        int i;
 
75
 
 
76
        for(i=0; i<MAXSTRINGARGS; i++)*buf[i]=0;
 
77
 
 
78
        for (i=0; i<argc; i++) {
 
79
                atom_string(argv+i, buf[i], MAXSTRINGLENG);
 
80
        }
 
81
 
 
82
        sprintf(buffer,
 
83
                masque,
 
84
                buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[8], buf[9]);
 
85
 
 
86
        freebytes(buf, MAXSTRINGARGS*sizeof(cstring));
 
87
        return (gensym(buffer));
 
88
}
 
89
 
 
90
static void makesymbol_list(t_makesymbol *x, t_symbol *s, int argc, t_atom *argv)
 
91
{
 
92
        ZEXY_USEVAR(s);
 
93
        x->x_sym = list2symbol(x->mask, argc, argv);
 
94
        outlet_symbol(x->x_obj.ob_outlet, x->x_sym);
 
95
}
 
96
 
 
97
static void makesymbol_bang(t_makesymbol *x)
 
98
{
 
99
        outlet_symbol(x->x_obj.ob_outlet, x->x_sym);
 
100
}
 
101
 
 
102
 
 
103
static void *makesymbol_new(t_symbol *s, int argc, t_atom *argv)
 
104
{
 
105
        t_makesymbol *x = (t_makesymbol *)pd_new(makesymbol_class);
 
106
        ZEXY_USEVAR(s);
 
107
 
 
108
        x->buf = (char *)getbytes(MAXSTRINGLENG * sizeof(char));
 
109
 
 
110
        x->mask  = x->buf;
 
111
 
 
112
        if (argc) {
 
113
                atom_string(argv, x->buf, MAXSTRINGLENG);
 
114
                x->x_sym = gensym(x->buf);
 
115
        } else {
 
116
                x->mask = "%s%s%s%s%s%s%s%s%s%s";
 
117
                x->x_sym = gensym("");
 
118
        }
 
119
 
 
120
        outlet_new(&x->x_obj, &s_symbol);
 
121
        inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("symbol"), gensym("sym1"));
 
122
 
 
123
        return (x);
 
124
}
 
125
 
 
126
static void makesymbol_free(t_makesymbol *x)
 
127
{
 
128
        freebytes(x->buf, MAXSTRINGLENG*sizeof(char));
 
129
}
 
130
 
 
131
 
 
132
static void makesymbol_helper(t_makesymbol *x)
 
133
{
 
134
  ZEXY_USEVAR(x);
 
135
        post("\n%c makesymbol :: create a formatted symbol", HEARTSYMBOL);
 
136
        post("<list of anything>\t: glue up to 10 list-elements to 1 formatted symbol\n"
 
137
                "'bang'\t\t\t: re-output\n"
 
138
                "'help'\t\t\t: view this"
 
139
                "\ninlet2 : <format-string>: new format-string (symbol !)"
 
140
                "\noutlet : <symbol>\t: formatted concatenation");
 
141
        post("\ncreation:\"makesymbol [<format-string>]\": C-style format-string (%s only)", "%s");
 
142
}
 
143
 
 
144
void makesymbol_setup(void)
 
145
{
 
146
        makesymbol_class = class_new(gensym("makesymbol"),
 
147
        (t_newmethod)makesymbol_new, (t_method)makesymbol_free,
 
148
                sizeof(t_makesymbol), 0, A_GIMME, 0);
 
149
 
 
150
        class_addlist(makesymbol_class, makesymbol_list);
 
151
        class_addbang(makesymbol_class, makesymbol_bang);
 
152
 
 
153
        class_addmethod(makesymbol_class, (t_method)reset_mask, gensym("sym1"), A_SYMBOL, 0);
 
154
 
 
155
        class_addmethod(makesymbol_class, (t_method)makesymbol_helper, gensym("help"), 0);
 
156
  zexy_register("makesymbol");
 
157
}