[PD-cvs] externals/moocow/readdir/src Makefile.am, NONE, 1.1 readdir-help.pd, NONE, 1.1 readdir-test.pd, NONE, 1.1 readdir.c, NONE, 1.1
Bryan Jurish
mukau at users.sourceforge.net
Thu Feb 2 13:47:33 CET 2006
- Previous message: [PD-cvs] externals/moocow/readdir/config Makefile.am,NONE,1.1
- Next message: [PD-cvs] externals/moocow/readdir COPYING, NONE, 1.1 Changes, NONE, 1.1 Makefile.am, NONE, 1.1 README.cvs, NONE, 1.1 README.pod, NONE, 1.1 autogen.sh, NONE, 1.1 configure.in, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/pure-data/externals/moocow/readdir/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23994/src
Added Files:
Makefile.am readdir-help.pd readdir-test.pd readdir.c
Log Message:
initial cvs import
--- NEW FILE: readdir-help.pd ---
#N canvas 356 19 535 566 10;
#X msg 89 227 close;
#X msg 52 79 bang;
#X msg 83 160 tell;
#X obj 38 322 print dir-entry;
#X obj 82 294 print end-of-directory;
#X text 130 8 readdir : simple directory accessor;
#X text 231 543 Bryan Jurish <moocow at ling.uni-potsdam.de>;
#X text 157 46 open DIR : opens the directory DIR;
#X text 185 75 bang : outlet next directory entry;
#X text 185 91 next : ditto;
#X msg 59 101 next;
#X msg 71 137 rewind;
#X text 173 137 rewind : return to beginning of directory;
#X text 188 158 tell : output current position;
#X text 146 182 seek FLOAT : goto position FLOAT;
#X msg 86 184 seek 0;
#X text 181 223 close : close directory;
#X text 258 295 2nd outlet bangs at end of directory;
#X text 260 325 Directory entries go to 1st outlet;
#X text 39 370 Directory entries appear as messages of the form TYPE
NAME \, where NAME is the name of the entry \, and TYPE is one of the
following:;
#X text 65 515 unknown : something else;
#X text 87 419 file : regular file;
#X text 93 434 dir : subdirectory;
#X text 86 450 fifo : named pipe;
#X text 85 466 sock : local-domain socket;
#X text 71 482 chrdev : character device;
#X text 71 498 blkdev : block device;
#X obj 38 267 readdir;
#X msg 39 47 open /tmp;
#X connect 0 0 27 0;
#X connect 1 0 27 0;
#X connect 2 0 27 0;
#X connect 10 0 27 0;
#X connect 11 0 27 0;
#X connect 15 0 27 0;
#X connect 27 0 3 0;
#X connect 27 1 4 0;
#X connect 28 0 27 0;
--- NEW FILE: Makefile.am ---
# File: ./src/Makefile.am
# Package: readdir
# Description:
# + src-level automake file
#
# Process this file with Automake to create Makefile.in.
#-----------------------------------------------------------------------
#-----------------------------------------------------------------------
# Options & Subdirectories
#-----------------------------------------------------------------------
## --- recursion subdirectories
#SUBDIRS =
## --- pseudo-deps for '.SUFFIXES'
SUFFIXES = . at PDEXT@
#-----------------------------------------------------------------------
# Flags and variables
#-----------------------------------------------------------------------
PDEXT = @PDEXT@
EXEEXT = . at PDEXT@
#-----------------------------------------------------------------------
# pd externals (hacked _PROGRAMS target)
#-----------------------------------------------------------------------
## --- externals
pdexterns_PROGRAMS = @PD_OBJECT_EXTERNALS@
## --- possible externals
EXTRA_PROGRAMS = \
readdir
## --- patches
pdexterns_DATA =
## --- documentation
pddoc_DATA = readdir-help.pd
#-----------------------------------------------------------------------
# sources
#-----------------------------------------------------------------------
readdir_SOURCES = \
readdir.c
#-----------------------------------------------------------------------
# external compilation : flags
#-----------------------------------------------------------------------
DEFS = @DEFS@
AFLAGS = @AFLAGS@
DFLAGS = @DFLAGS@
IFLAGS = @IFLAGS@
LFLAGS = @LFLAGS@
OFLAGS = @OFLAGS@
WFLAGS = -Wall -Winline
#GLIB_IFLAGS = @GLIB_IFLAGS@
#GLIB_LFLAGS = @GLIB_LFLAGS@
AM_CPPFLAGS = $(IFLAGS) $(GLIB_IFLAGS) $(DFLAGS)
AM_CFLAGS = $(OFLAGS) $(WFLAGS) $(AFLAGS)
readdir_LDFLAGS = $(LFLAGS)
readdir_LDADD = $(GLIB_LFLAGS)
#-----------------------------------------------------------------------
# Variables: cleanup
#-----------------------------------------------------------------------
## --- mostlyclean: built by 'make' & commonly rebuilt
#MOSTLYCLEANFILES =
## --- clean: built by 'make'
CLEANFILES = *$(EXEEXT)
## --- distclean: built by 'configure'
DISTCLEANFILES = \
config.log \
config.cache \
config.status
## -- maintainerclean: built by maintainer / by hand
MAINTAINERCLEANFILES = *~ \
$(PODS:.pod=.txt) \
Makefile Makefile.in \
aclocal.m4 \
configure \
install-sh \
stamp-h.in \
config.h.in
maintainer-clean-local:
rm -rf autom4te.cache
#CVSCLEAN_SUBDIRS = $(SUBDIRS)
#CVSCLEANFILES = Makefile.in Makefile
#-----------------------------------------------------------------------
# Variables: distribution
#-----------------------------------------------------------------------
## --- extra distribution files
EXTRA_DIST = \
$(pddoc_DATA) \
$(pdexterns_DATA)
## --- recursion subdirectories for 'make dist'
DIST_SUBDIRS = $(SUBDIRS)
## --- dist-hook: when another 'Makefile.am' is overkill
#DISTHOOK_DIRS = foo
#DISTHOOK_FILES = foo/bar.txt foo/baz.txt
#dist-hook:
# for d in $(DISTHOOK_DIRS); do\
# mkdir -p $(distdir)/$$d ;\
# done
# for f in $(DISTHOOK_FILES); do\
# cp -p $(srcdir)/$$f $(distdir)/$$f ;\
# done
#dist-bz2: dist-bzip2 ;
#-----------------------------------------------------------------------
# Rules: cleanup
#-----------------------------------------------------------------------
.PHONY: cvsclean cvsclean-hook
cvsclean: maintainer-clean ;
--- NEW FILE: readdir.c ---
/* -*- Mode: C -*- */
/*=============================================================================*\
* File: readdir.c
* Author: Bryan Jurish <moocow at ling.uni-potsdam.de>
* Description: general directory access object
*
* Copyright (c) 2003 Bryan Jurish.
*
* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
*
* 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 <dirent.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <m_pd.h>
/* black magic */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
/*--------------------------------------------------------------------
* DEBUG
*--------------------------------------------------------------------*/
//#define READDIR_DEBUG 1
/*=====================================================================
* Constants
*=====================================================================*/
#ifdef READDIR_DEBUG
// error-message buffer
#define EBUFSIZE 256
static char readdir_errbuf[EBUFSIZE];
#endif
/*=====================================================================
* Structures and Types
*=====================================================================*/
static char *readdir_banner = "\nreaddir version %s by Bryan Jurish : simple directory accessor";
static t_class *readdir_class;
typedef struct _readdir
{
t_object x_obj;
DIR *x_dir; //-- current directory
t_symbol *x_dirname; //-- current directory name
//struct dirent *x_dirent; //-- current entry of current directory
t_atom x_eatom; //-- current output atom (symbol)
t_outlet *x_ent_outlet; //-- entry outlet
t_outlet *x_eod_outlet; //-- end-of-directory outlet
} t_readdir;
/*=====================================================================
* Constants
*=====================================================================*/
static t_symbol *sp_none;
static t_symbol *sp_unknown;
static t_symbol *sp_file;
static t_symbol *sp_dir;
static t_symbol *sp_fifo;
static t_symbol *sp_sock;
static t_symbol *sp_chrdev;
static t_symbol *sp_blkdev;
/*--------------------------------------------------------------------
* close
*/
static void readdir_close(t_readdir *x)
{
if (!x->x_dir) return;
if (0 != closedir(x->x_dir)) {
error("readdir: cannot close %s: %s", x->x_dirname->s_name, strerror(errno));
return;
}
x->x_dir = NULL;
x->x_dirname = sp_none;
}
/*--------------------------------------------------------------------
* open DIR
*/
static void readdir_open(t_readdir *x, t_symbol *dirname)
{
#ifdef READDIR_DEBUG
post("readdir: got message: open %s", dirname->s_name);
#endif
if (x->x_dir) readdir_close(x);
if ( !(x->x_dir = opendir(dirname->s_name)) ) {
error("readdir: cannot open %s: %s", dirname->s_name, strerror(errno));
return;
}
x->x_dirname = dirname;
}
/*--------------------------------------------------------------------
* next : get next entry
*/
static void readdir_next(t_readdir *x)
{
t_symbol *sel = sp_unknown;
struct dirent *result = NULL;
if ( !x->x_dir || !(result = readdir(x->x_dir)) ) {
if (errno == EBADF) {
//-- real error
error("readdir: cannot read from %s: %s", x->x_dirname->s_name, strerror(errno));
}
else {
//-- end of directory
outlet_bang(x->x_eod_outlet);
}
return;
}
//-- get type
switch (result->d_type)
{
case DT_REG:
sel = sp_file;
break;
case DT_DIR:
sel = sp_dir;
break;
case DT_FIFO:
sel = sp_fifo;
break;
case DT_SOCK:
sel = sp_sock;
break;
case DT_CHR:
sel = sp_chrdev;
break;
case DT_BLK:
sel = sp_blkdev;
break;
default:
sel = sp_unknown;
break;
}
x->x_eatom.a_w.w_symbol = gensym(result->d_name);
outlet_anything(x->x_ent_outlet, sel, 1, &x->x_eatom);
}
/*--------------------------------------------------------------------
* rewind
*/
static void readdir_rewind(t_readdir *x)
{
if (x->x_dir) rewinddir(x->x_dir);
}
/*--------------------------------------------------------------------
* tell
*/
static void readdir_tell(t_readdir *x)
{
off_t off = 0;
if (x->x_dir) off = telldir(x->x_dir);
outlet_float(x->x_ent_outlet, (t_float)off);
}
/*--------------------------------------------------------------------
* seek FLOAT
*/
static void readdir_seek(t_readdir *x, t_floatarg pos)
{
if (!x->x_dir) {
error("readdir: seek %f: no directory opened!", pos);
return;
}
seekdir(x->x_dir, (off_t)pos);
}
/*--------------------------------------------------------------------
* new
*/
static void *readdir_new(void)
{
t_readdir *x = (t_readdir *)pd_new(readdir_class);
//-- defaults
x->x_dir = NULL;
x->x_dirname = sp_none;
SETSYMBOL(&x->x_eatom, sp_none);
//-- outlets
x->x_ent_outlet = outlet_new(&x->x_obj, &s_symbol);
x->x_eod_outlet = outlet_new(&x->x_obj, &s_bang);
return (void *)x;
}
/*--------------------------------------------------------------------
* free
*/
static void readdir_free(t_readdir *x)
{
readdir_close(x);
outlet_free(x->x_ent_outlet);
outlet_free(x->x_eod_outlet);
return;
}
/*--------------------------------------------------------------------
* setup
*/
void readdir_setup(void)
{
post(readdir_banner, PACKAGE_VERSION);
#ifdef READDIR_DEBUG
post("readdir : debugging enabled");
#endif
//-- constants
sp_none = gensym("none");
sp_unknown = gensym("unknown");
sp_file = gensym("file");
sp_dir = gensym("dir");
sp_fifo = gensym("fifo");
sp_sock = gensym("sock");
sp_chrdev = gensym("chrdev");
sp_blkdev = gensym("blkdev");
//-- class
readdir_class = class_new(gensym("readdir"),
(t_newmethod)readdir_new,
(t_method)readdir_free,
sizeof(t_readdir),
CLASS_DEFAULT,
0);
//-- methods
class_addmethod(readdir_class, (t_method)readdir_open, gensym("open"), A_DEFSYMBOL, 0);
class_addmethod(readdir_class, (t_method)readdir_close, gensym("close"), 0);
class_addmethod(readdir_class, (t_method)readdir_next, gensym("next"), 0);
class_addbang(readdir_class, (t_method)readdir_next);
class_addmethod(readdir_class, (t_method)readdir_rewind, gensym("rewind"), 0);
class_addmethod(readdir_class, (t_method)readdir_tell, gensym("tell"), 0);
class_addmethod(readdir_class, (t_method)readdir_seek, gensym("seek"), A_DEFFLOAT, 0);
//-- help symbol
class_sethelpsymbol(readdir_class, gensym("readdir-help.pd"));
}
--- NEW FILE: readdir-test.pd ---
#N canvas 468 56 337 420 10;
#X obj 64 274 readdir;
#X msg 141 236 close;
#X obj 108 301 print end-of-directory;
#X msg 85 119 bang;
#X msg 64 93 open \$1;
#X msg 64 37 .;
#X msg 101 37 test;
#X msg 144 37 foo;
#X obj 64 69 symbol;
#X obj 64 328 print entry;
#X msg 109 166 tell;
#X msg 105 142 rewind;
#X msg 148 202 seek \$1;
#X floatatom 147 183 5 0 0;
#X connect 0 0 9 0;
#X connect 0 1 2 0;
#X connect 1 0 0 0;
#X connect 3 0 0 0;
#X connect 4 0 0 0;
#X connect 5 0 8 0;
#X connect 6 0 8 0;
#X connect 7 0 8 0;
#X connect 8 0 4 0;
#X connect 10 0 0 0;
#X connect 11 0 0 0;
#X connect 12 0 0 0;
#X connect 13 0 12 0;
- Previous message: [PD-cvs] externals/moocow/readdir/config Makefile.am,NONE,1.1
- Next message: [PD-cvs] externals/moocow/readdir COPYING, NONE, 1.1 Changes, NONE, 1.1 Makefile.am, NONE, 1.1 README.cvs, NONE, 1.1 README.pod, NONE, 1.1 autogen.sh, NONE, 1.1 configure.in, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Pd-cvs
mailing list