aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans-Christoph Steiner <eighthave@users.sourceforge.net>2010-07-08 21:04:19 +0000
committerHans-Christoph Steiner <eighthave@users.sourceforge.net>2010-07-08 21:04:19 +0000
commitb6e15bfea4f6400018f337fe123d4f25a65ea6f0 (patch)
tree730975c5b6e89f8523582319476ab23d66d72b40
parent1ba8af86e09cd23be8e91522b1716dc477227680 (diff)
implemented a meta info API
svn path=/trunk/externals/ezfile/; revision=13696
-rw-r--r--TODO2
-rw-r--r--getfilenames-help.pd85
-rw-r--r--getfilenames.c89
3 files changed, 137 insertions, 39 deletions
diff --git a/TODO b/TODO
new file mode 100644
index 0000000..00614f3
--- /dev/null
+++ b/TODO
@@ -0,0 +1,2 @@
+
+- make some version of basename/dirname or split_path-help.pd
diff --git a/getfilenames-help.pd b/getfilenames-help.pd
index ca2759b..d1857f6 100644
--- a/getfilenames-help.pd
+++ b/getfilenames-help.pd
@@ -1,31 +1,22 @@
-#N canvas 341 57 529 471 10;
+#N canvas 201 48 531 544 10;
#X msg 19 73 bang;
-#X msg 29 387 bang;
+#X msg 29 447 bang;
#X obj 172 363 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
-1;
-#X obj 12 435 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
--1;
-#X obj 29 409 getfilenames;
+#X obj 29 469 getfilenames;
#X obj 85 341 getfilenames /*;
-#X obj 85 362 print;
-#X obj 29 434 print;
#X text 234 259 relative paths work;
-#X text 211 186 drive letters work on ReactOS/Windows;
#X text 237 210 all files with a dot in your home;
-#X text 263 161 ReactOS/Windows environment variables work;
#X text 309 280 nested wildcards work on UNIX;
#X text 220 235 patterns default to path that Pd launched from;
-#X text 8 5 Get a listing of files based on a wildcard pattern. On
-UNIX \, it follows glob rules \, on ReactOS/Windows it follows the
-cmd.exe rules.;
-#X text 117 403 With no argument \, it defaults to the contents of
+#X text 117 463 With no argument \, it defaults to the contents of
the folder of the current patch \, i.e. "/path/to/current/patch/*".
;
#X text 54 73 get next file;
#X msg 34 99 rewind;
#X text 81 98 go back to the beginning of the file list;
#X obj 51 128 hsl 128 15 0 127 0 0 empty empty empty -2 -8 0 10 -262144
--1 -1 1000 1;
+-1 -1 3800 1;
#X text 186 128 or choose by position;
#X floatatom 62 149 5 0 0 0 - - -;
#X msg 149 260 symbol ../*;
@@ -35,19 +26,53 @@ the folder of the current patch \, i.e. "/path/to/current/patch/*".
#X msg 138 208 symbol ~/*.*;
#X msg 124 185 symbol C:/*;
#X msg 100 160 symbol %USERPROFILE%/*;
-#X connect 0 0 5 0;
-#X connect 1 0 4 0;
-#X connect 4 0 3 0;
-#X connect 4 0 7 0;
-#X connect 5 0 6 0;
-#X connect 5 1 2 0;
-#X connect 17 0 5 0;
-#X connect 19 0 5 0;
-#X connect 19 0 21 0;
-#X connect 22 0 5 1;
-#X connect 23 0 5 1;
-#X connect 24 0 5 1;
-#X connect 25 0 5 1;
-#X connect 26 0 5 1;
-#X connect 27 0 5 1;
-#X connect 28 0 5 1;
+#X text 8 5 Get a listing of files based on a wildcard pattern. On
+UNIX \, it follows glob rules \, on Windows/ReactOS it follows the
+cmd.exe rules.;
+#X text 211 186 drive letters work on Windows/ReactOS;
+#X text 263 161 Windows/ReactOS environment variables work;
+#X symbolatom 85 412 0 0 0 0 - - -;
+#X obj 170 386 print INFO;
+#X obj 95 385 print FILES;
+#X symbolatom 29 508 0 0 0 0 - - -;
+#X obj 98 488 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
+-1;
+#N canvas 0 22 450 300 INFO 0;
+#X text 41 17 You can also request the meta information that is output
+whenever a new glob pattern is parsed. Use the same symbol to request
+the information as is used when that information is output from the
+info outlet. For example \, if you want to know how many matches there
+are for the current pattern \, send the [matches( message.;
+#X obj 89 250 outlet;
+#X msg 88 140 info;
+#X msg 102 164 matches;
+#X msg 112 189 pattern;
+#X text 132 138 output all meta info from the second info outlet;
+#X text 154 163 output how many matches for the current pattern;
+#X text 166 187 output the currently active pattern;
+#X msg 122 218 position;
+#X text 176 216 output the current position number;
+#X connect 2 0 1 0;
+#X connect 3 0 1 0;
+#X connect 4 0 1 0;
+#X connect 8 0 1 0;
+#X restore 95 305 pd INFO;
+#X connect 0 0 4 0;
+#X connect 1 0 3 0;
+#X connect 3 0 29 0;
+#X connect 3 2 30 0;
+#X connect 4 0 26 0;
+#X connect 4 0 28 0;
+#X connect 4 1 27 0;
+#X connect 4 2 2 0;
+#X connect 11 0 4 0;
+#X connect 13 0 4 0;
+#X connect 13 0 15 0;
+#X connect 16 0 4 1;
+#X connect 17 0 4 1;
+#X connect 18 0 4 1;
+#X connect 19 0 4 1;
+#X connect 20 0 4 1;
+#X connect 21 0 4 1;
+#X connect 22 0 4 1;
+#X connect 31 0 4 0;
diff --git a/getfilenames.c b/getfilenames.c
index 55c3d29..31f2f87 100644
--- a/getfilenames.c
+++ b/getfilenames.c
@@ -40,6 +40,9 @@
#define DEBUG(x)
//#define DEBUG(x) x
+// TODO check out what happens with [getfilesnames $1] and empty args
+// TODO using an A_GIMME to support floats, etc as file names
+
/*------------------------------------------------------------------------------
* CLASS DEF
*/
@@ -57,10 +60,18 @@ typedef struct _getfilenames {
unsigned int current_glob_position;
#endif
t_outlet *data_outlet;
- t_outlet *status_outlet;
+ t_outlet *info_outlet;
+ t_outlet *endoflist_outlet;
} t_getfilenames;
/*------------------------------------------------------------------------------
+ * GLOBAL VARIABLES
+ */
+
+/* pre-generated symbols */
+t_symbol *ps_info, *ps_matches, *ps_pattern, *ps_position, *ps_rewind;
+
+/*------------------------------------------------------------------------------
* IMPLEMENTATION
*/
@@ -112,6 +123,38 @@ static void normalize_path(t_getfilenames* x, char *normalized, const char *orig
}
}
+/* functions for implementing the querying methods */
+
+static void getfilenames_matches(t_getfilenames *x)
+{
+ t_atom output_atom;
+ SETFLOAT(&output_atom, (t_float)x->glob_buffer.gl_matchc);
+ outlet_anything(x->info_outlet, ps_matches, 1, &output_atom);
+}
+
+static void getfilenames_pattern(t_getfilenames *x)
+{
+ t_atom output_atom;
+ SETSYMBOL(&output_atom, x->x_pattern);
+ outlet_anything(x->info_outlet, ps_pattern, 1, &output_atom);
+}
+
+static void getfilenames_position(t_getfilenames *x)
+{
+ t_atom output_atom;
+ SETFLOAT(&output_atom, x->current_glob_position);
+ outlet_anything(x->info_outlet, ps_position, 1, &output_atom);
+}
+
+static void getfilenames_info(t_getfilenames *x)
+{
+ getfilenames_matches(x);
+ getfilenames_pattern(x);
+ getfilenames_position(x);
+}
+
+/* working functions */
+
static void getfilenames_rewind(t_getfilenames* x)
{
DEBUG(post("getfilenames_rewind"););
@@ -189,7 +232,7 @@ static void getfilenames_rewind(t_getfilenames* x)
# endif
# ifdef GLOB_NOMATCH
case GLOB_NOMATCH:
- pd_error(x,"[getfilenames] nothing found for \"%s\"",normalized_path);
+ verbose(4, "[getfilenames] nothing found for \"%s\"",normalized_path);
break;
# endif
}
@@ -201,17 +244,19 @@ static void getfilenames_bang(t_getfilenames *x)
if(x->x_pattern != x->active_pattern)
{
x->active_pattern = x->x_pattern;
- post("x->active_pattern %s x->x_pattern %s", x->active_pattern->s_name, x->x_pattern->s_name);
+// post("x->active_pattern %s x->x_pattern %s", x->active_pattern->s_name, x->x_pattern->s_name);
getfilenames_rewind(x);
+ getfilenames_info(x); /* after opening new glob, output meta info */
}
if(x->current_glob_position < x->glob_buffer.gl_pathc)
{
- outlet_symbol( x->data_outlet,
- gensym(x->glob_buffer.gl_pathv[x->current_glob_position]) );
+ getfilenames_position(x);
+ outlet_symbol(x->data_outlet,
+ gensym(x->glob_buffer.gl_pathv[x->current_glob_position]));
x->current_glob_position++;
}
else
- outlet_bang(x->status_outlet);
+ outlet_bang(x->endoflist_outlet);
}
static void getfilenames_float(t_getfilenames *x, t_float f)
@@ -220,10 +265,19 @@ static void getfilenames_float(t_getfilenames *x, t_float f)
if(x->current_glob_position != position)
{
x->current_glob_position = position;
- getfilenames_bang(x);
+ if(x->current_glob_position < x->glob_buffer.gl_pathc)
+ {
+ getfilenames_position(x);
+ outlet_symbol(x->data_outlet,
+ gensym(x->glob_buffer.gl_pathv[x->current_glob_position]));
+ }
+ else
+ outlet_bang(x->endoflist_outlet);
}
}
+/* the core guts that make a pd object */
+
static void *getfilenames_new(t_symbol *s)
{
DEBUG(post("getfilenames_new"););
@@ -236,7 +290,8 @@ static void *getfilenames_new(t_symbol *s)
symbolinlet_new(&x->x_obj, &x->x_pattern);
x->data_outlet = outlet_new(&x->x_obj, &s_symbol);
- x->status_outlet = outlet_new(&x->x_obj, 0);
+ x->info_outlet = outlet_new(&x->x_obj, 0);
+ x->endoflist_outlet = outlet_new(&x->x_obj, &s_bang);
/* set to the value from the object argument, if that exists */
if (s != &s_)
@@ -270,7 +325,7 @@ void getfilenames_setup(void)
(t_newmethod)getfilenames_new,
(t_method)getfilenames_free,
sizeof(t_getfilenames),
- 0,
+ 0,
A_DEFSYMBOL,
0);
/* add inlet datatype methods */
@@ -280,5 +335,21 @@ void getfilenames_setup(void)
/* add inlet message methods */
class_addmethod(getfilenames_class, (t_method) getfilenames_rewind,
gensym("rewind"), 0);
+ /* querying methods */
+ class_addmethod(getfilenames_class, (t_method) getfilenames_info,
+ gensym("info"), 0);
+ class_addmethod(getfilenames_class, (t_method) getfilenames_matches,
+ gensym("matches"), 0);
+ class_addmethod(getfilenames_class, (t_method) getfilenames_pattern,
+ gensym("pattern"), 0);
+ class_addmethod(getfilenames_class, (t_method) getfilenames_position,
+ gensym("position"), 0);
+
+ /* pre-generate often used symbols */
+ ps_rewind = gensym("rewind");
+ ps_info = gensym("info");
+ ps_matches = gensym("matches");
+ ps_pattern = gensym("pattern");
+ ps_position = gensym("position");
}