diff options
Diffstat (limited to 'apps/plugins/pdbox/PDa/src/m_atom.c')
-rw-r--r-- | apps/plugins/pdbox/PDa/src/m_atom.c | 128 |
1 files changed, 0 insertions, 128 deletions
diff --git a/apps/plugins/pdbox/PDa/src/m_atom.c b/apps/plugins/pdbox/PDa/src/m_atom.c index a4b08ff2cb..f2ed3a0b65 100644 --- a/apps/plugins/pdbox/PDa/src/m_atom.c +++ b/apps/plugins/pdbox/PDa/src/m_atom.c | |||
@@ -127,132 +127,4 @@ void atom_string(t_atom *a, char *buf, unsigned int bufsize) | |||
127 | bug("atom_string"); | 127 | bug("atom_string"); |
128 | } | 128 | } |
129 | } | 129 | } |
130 | /* Copyright (c) 1997-1999 Miller Puckette. | ||
131 | * For information on usage and redistribution, and for a DISCLAIMER OF ALL | ||
132 | * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ | ||
133 | |||
134 | #include "m_pd.h" | ||
135 | #include <stdio.h> | ||
136 | #include <string.h> | ||
137 | |||
138 | /* convenience routines for checking and getting values of | ||
139 | atoms. There's no "pointer" version since there's nothing | ||
140 | safe to return if there's an error. */ | ||
141 | |||
142 | t_float atom_getfloat(t_atom *a) | ||
143 | { | ||
144 | if (a->a_type == A_FLOAT) return (a->a_w.w_float); | ||
145 | else return (0); | ||
146 | } | ||
147 | |||
148 | t_int atom_getint(t_atom *a) | ||
149 | { | ||
150 | return (atom_getfloat(a)); | ||
151 | } | ||
152 | |||
153 | t_symbol *atom_getsymbol(t_atom *a) /* LATER think about this more carefully */ | ||
154 | { | ||
155 | char buf[30]; | ||
156 | if (a->a_type == A_SYMBOL) return (a->a_w.w_symbol); | ||
157 | else return (&s_float); | ||
158 | } | ||
159 | |||
160 | t_symbol *atom_gensym(t_atom *a) /* this works better for graph labels */ | ||
161 | { | ||
162 | char buf[30]; | ||
163 | if (a->a_type == A_SYMBOL) return (a->a_w.w_symbol); | ||
164 | else if (a->a_type == A_FLOAT) | ||
165 | sprintf(buf, "%g", a->a_w.w_float); | ||
166 | else strcpy(buf, "???"); | ||
167 | return (gensym(buf)); | ||
168 | } | ||
169 | |||
170 | t_float atom_getfloatarg(int which, int argc, t_atom *argv) | ||
171 | { | ||
172 | if (argc <= which) return (0); | ||
173 | argv += which; | ||
174 | if (argv->a_type == A_FLOAT) return (argv->a_w.w_float); | ||
175 | else return (0); | ||
176 | } | ||
177 | |||
178 | t_int atom_getintarg(int which, int argc, t_atom *argv) | ||
179 | { | ||
180 | return (atom_getfloatarg(which, argc, argv)); | ||
181 | } | ||
182 | |||
183 | t_symbol *atom_getsymbolarg(int which, int argc, t_atom *argv) | ||
184 | { | ||
185 | if (argc <= which) return (&s_); | ||
186 | argv += which; | ||
187 | if (argv->a_type == A_SYMBOL) return (argv->a_w.w_symbol); | ||
188 | else return (&s_); | ||
189 | } | ||
190 | |||
191 | /* convert an atom into a string, in the reverse sense of binbuf_text (q.v.) | ||
192 | * special attention is paid to symbols containing the special characters | ||
193 | * ';', ',', '$', and '\'; these are quoted with a preceding '\', except that | ||
194 | * the '$' only gets quoted at the beginning of the string. | ||
195 | */ | ||
196 | 130 | ||
197 | void atom_string(t_atom *a, char *buf, unsigned int bufsize) | ||
198 | { | ||
199 | char tbuf[30]; | ||
200 | switch(a->a_type) | ||
201 | { | ||
202 | case A_SEMI: strcpy(buf, ";"); break; | ||
203 | case A_COMMA: strcpy(buf, ","); break; | ||
204 | case A_POINTER: | ||
205 | strcpy(buf, "(pointer)"); | ||
206 | break; | ||
207 | case A_FLOAT: | ||
208 | sprintf(tbuf, "%g", a->a_w.w_float); | ||
209 | if (strlen(tbuf) < bufsize-1) strcpy(buf, tbuf); | ||
210 | else if (a->a_w.w_float < 0) strcpy(buf, "-"); | ||
211 | else strcat(buf, "+"); | ||
212 | break; | ||
213 | case A_SYMBOL: | ||
214 | { | ||
215 | char *sp; | ||
216 | unsigned int len; | ||
217 | int quote; | ||
218 | for (sp = a->a_w.w_symbol->s_name, len = 0, quote = 0; *sp; sp++, len++) | ||
219 | if (*sp == ';' || *sp == ',' || *sp == '\\' || | ||
220 | (*sp == '$' && sp == a->a_w.w_symbol->s_name && sp[1] >= '0' | ||
221 | && sp[1] <= '9')) | ||
222 | quote = 1; | ||
223 | if (quote) | ||
224 | { | ||
225 | char *bp = buf, *ep = buf + (bufsize-2); | ||
226 | sp = a->a_w.w_symbol->s_name; | ||
227 | while (bp < ep && *sp) | ||
228 | { | ||
229 | if (*sp == ';' || *sp == ',' || *sp == '\\' || | ||
230 | (*sp == '$' && bp == buf && sp[1] >= '0' && sp[1] <= '9')) | ||
231 | *bp++ = '\\'; | ||
232 | *bp++ = *sp++; | ||
233 | } | ||
234 | if (*sp) *bp++ = '*'; | ||
235 | *bp = 0; | ||
236 | /* post("quote %s -> %s", a->a_w.w_symbol->s_name, buf); */ | ||
237 | } | ||
238 | else | ||
239 | { | ||
240 | if (len < bufsize-1) strcpy(buf, a->a_w.w_symbol->s_name); | ||
241 | else | ||
242 | { | ||
243 | strncpy(buf, a->a_w.w_symbol->s_name, bufsize - 2); | ||
244 | strcpy(buf + (bufsize - 2), "*"); | ||
245 | } | ||
246 | } | ||
247 | } | ||
248 | break; | ||
249 | case A_DOLLAR: | ||
250 | sprintf(buf, "$%d", a->a_w.w_index); | ||
251 | break; | ||
252 | case A_DOLLSYM: | ||
253 | sprintf(buf, "$%s", a->a_w.w_symbol->s_name); | ||
254 | break; | ||
255 | default: | ||
256 | bug("atom_string"); | ||
257 | } | ||
258 | } | ||