diff options
-rw-r--r-- | classpath-help.pd | 13 | ||||
-rw-r--r-- | classpath.c | 135 |
2 files changed, 148 insertions, 0 deletions
diff --git a/classpath-help.pd b/classpath-help.pd new file mode 100644 index 0000000..e59a92a --- /dev/null +++ b/classpath-help.pd @@ -0,0 +1,13 @@ +#N canvas 375 22 462 312 10; +#X obj 85 99 classpath; +#X msg 82 68 bang; +#X obj 99 145 print; +#X symbolatom 74 182 0 0 0 0 - - -; +#X obj 146 120 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 +-1 -1; +#X msg 124 71 rewind; +#X connect 0 0 2 0; +#X connect 0 0 3 0; +#X connect 0 1 4 0; +#X connect 1 0 0 0; +#X connect 5 0 0 0; diff --git a/classpath.c b/classpath.c new file mode 100644 index 0000000..223460b --- /dev/null +++ b/classpath.c @@ -0,0 +1,135 @@ +/* --------------------------------------------------------------------------*/ +/* */ +/* This object outputs the search path for finding objects using a similar */ +/* interface as [textfile] and [qlist] */ +/* */ +/* Copyright (c) 2006 Hans-Christoph Steiner */ +/* */ +/* This program is free software; you can redistribute it and/or */ +/* modify it under the terms of the GNU General Public License */ +/* as published by the Free Software Foundation; either version 2 */ +/* of the License, or (at your option) any later version. */ +/* */ +/* See file LICENSE for further informations on licensing terms. */ +/* */ +/* This program is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with this program; if not, write to the Free Software Foundation, */ +/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* */ +/* --------------------------------------------------------------------------*/ + +#include <m_pd.h> +#include <s_stuff.h> + +#ifdef _WIN32 +#define _WIN32_WINNT 0x0400 +#include <windows.h> +#include <stdio.h> +#else +#include <stdlib.h> +#endif + +#include <string.h> + +static char *version = "$Revision: 1.1 $"; + +t_int classpath_instance_count; + +#define DEBUG(x) +//#define DEBUG(x) x + +/*------------------------------------------------------------------------------ + * CLASS DEF + */ +static t_class *classpath_class; + +typedef struct _classpath { + t_object x_obj; + t_namelist *x_top; + t_namelist *x_current; + t_outlet *x_data_outlet; + t_outlet *x_status_outlet; +} t_classpath; + +/*------------------------------------------------------------------------------ + * IMPLEMENTATION + */ + +static void classpath_output(t_classpath* x) +{ + DEBUG(post("classpath_output");); + + if(x->x_current) + { + outlet_symbol( x->x_data_outlet, gensym(x->x_current->nl_string) ); + x->x_current = x->x_current->nl_next; + } + else + outlet_bang(x->x_status_outlet); +} + + +static void classpath_rewind(t_classpath* x) +{ + DEBUG(post("classpath_output");); + + x->x_current = x->x_top; +} + + +static void classpath_add(t_classpath* x, t_symbol *s) +{ + DEBUG(post("classpath_add");); +} + + +static void *classpath_new() +{ + DEBUG(post("classpath_new");); + + t_classpath *x = (t_classpath *)pd_new(classpath_class); + t_symbol *currentdir; + char buffer[MAXPDSTRING]; + + if(!classpath_instance_count) + { + post("[classpath] %s",version); + post("\twritten by Hans-Christoph Steiner <hans@at.or.at>"); + post("\tcompiled on "__DATE__" at "__TIME__ " "); + } + classpath_instance_count++; + + x->x_top = namelist_append_files(NULL,sys_libdir->s_name); + x->x_top->nl_next = sys_searchpath; + x->x_current = x->x_top; + + x->x_data_outlet = outlet_new(&x->x_obj, &s_symbol); + x->x_status_outlet = outlet_new(&x->x_obj, 0); + + return (x); +} + +void classpath_setup(void) +{ + DEBUG(post("classpath_setup");); + classpath_class = class_new(gensym("classpath"), + (t_newmethod)classpath_new, + 0, + sizeof(t_classpath), + 0, + 0); + /* add inlet datatype methods */ + class_addbang(classpath_class,(t_method) classpath_output); + + /* add inlet message methods */ + class_addmethod(classpath_class,(t_method) classpath_rewind, + gensym("rewind"), 0); + class_addmethod(classpath_class,(t_method) classpath_add,gensym("add"), + A_DEFSYMBOL, 0); +} + |