From 7ef1e577d31b33d798c284786f010fd982c9d9b0 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Thu, 17 Jun 2010 17:10:35 +0000 Subject: setup ezfile library starting with new textfile-style dir lister object based on folder_list svn path=/trunk/externals/ezfile/; revision=13668 --- Makefile | 283 +++++++++++++++++++++++++++++++++++++++++++++++ README.txt | 2 + debian/changelog | 5 + debian/compat | 1 + debian/control | 12 ++ debian/copyright | 14 +++ debian/rules | 16 +++ examples/bothtogether.pd | 16 +++ ezfile-meta.pd | 6 + getfilenames-help.pd | 52 +++++++++ getfilenames.c | 264 +++++++++++++++++++++++++++++++++++++++++++ manual/manual.txt | 4 + 12 files changed, 675 insertions(+) create mode 100644 Makefile create mode 100644 README.txt create mode 100644 debian/changelog create mode 100644 debian/compat create mode 100644 debian/control create mode 100644 debian/copyright create mode 100755 debian/rules create mode 100644 examples/bothtogether.pd create mode 100644 ezfile-meta.pd create mode 100644 getfilenames-help.pd create mode 100644 getfilenames.c create mode 100644 manual/manual.txt diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..15a2833 --- /dev/null +++ b/Makefile @@ -0,0 +1,283 @@ +## Pd library template version 1.0 +# For instructions on how to use this template, see: +# http://puredata.info/docs/developer/MakefileTemplate +LIBRARY_NAME = template + +# add your .c source files to the SOURCES variable, help files will be +# included automatically +SOURCES = mycobject.c + +# For objects that only build on certain platforms, add those to the SOURCES +# line for the right platforms. +SOURCES_android = +SOURCES_cygwin = +SOURCES_macosx = +SOURCES_iphoneos = +SOURCES_linux = +SOURCES_windows = + +# list all pd objects (i.e. myobject.pd) files here, and their helpfiles will +# be included automatically +PDOBJECTS = mypdobject.pd + +# example patches and related files, in the 'examples' subfolder +EXAMPLES = bothtogether.pd + +# manuals and related files, in the 'manual' subfolder +MANUAL = manual.txt + +# if you want to include any other files in the source and binary tarballs, +# list them here. This can be anything from header files, example patches, +# documentation, etc. README.txt and LICENSE.txt are required and therefore +# automatically included +EXTRA_DIST = + + + +#------------------------------------------------------------------------------# +# +# you shouldn't need to edit anything below here, if we did it right :) +# +#------------------------------------------------------------------------------# + +# get library version from meta file +LIBRARY_VERSION = $(shell sed -n 's|^\#X text [0-9][0-9]* [0-9][0-9]* VERSION \(.*\);|\1|p' $(LIBRARY_NAME)-meta.pd) + +# where Pd lives +PD_PATH = ../../pd +# where to install the library +prefix = /usr/local +libdir = $(prefix)/lib +pkglibdir = $(libdir)/pd-externals +objectsdir = $(pkglibdir) + + +INSTALL = install +INSTALL_FILE = $(INSTALL) -p -m 644 +INSTALL_DIR = $(INSTALL) -p -m 755 -d + +CFLAGS = -DPD -I$(PD_PATH)/src -Wall -W -g +LDFLAGS = +LIBS = +ALLSOURCES := $(SOURCES) $(SOURCES_android) $(SOURCES_cygwin) $(SOURCES_macosx) \ + $(SOURCES_iphoneos) $(SOURCES_linux) $(SOURCES_windows) + +UNAME := $(shell uname -s) +ifeq ($(UNAME),Darwin) + CPU := $(shell uname -p) + ifeq ($(CPU),arm) # iPhone/iPod Touch + SOURCES += $(SOURCES_iphoneos) + EXTENSION = pd_darwin + OS = iphoneos + IPHONE_BASE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin + CC=$(IPHONE_BASE)/gcc + CPP=$(IPHONE_BASE)/cpp + CXX=$(IPHONE_BASE)/g++ + ISYSROOT = -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk + IPHONE_CFLAGS = -miphoneos-version-min=3.0 $(ISYSROOT) -arch armv6 + OPT_CFLAGS = -fast -funroll-loops -fomit-frame-pointer + CFLAGS := $(IPHONE_CFLAGS) $(OPT_CFLAGS) $(CFLAGS) \ + -I/Applications/Pd-extended.app/Contents/Resources/include + LDFLAGS += -arch armv6 -bundle -undefined dynamic_lookup $(ISYSROOT) + LIBS += -lc + STRIP = strip -x + DISTDIR=$(LIBRARY_NAME)-$(LIBRARY_VERSION) + DISTBINDIR=$(DISTDIR)-$(OS) + else # Mac OS X + SOURCES += $(SOURCES_macosx) + EXTENSION = pd_darwin + OS = macosx + OPT_CFLAGS = -ftree-vectorize -ftree-vectorizer-verbose=2 -fast +# build universal 32-bit on 10.4 and 32/64 on newer + ifeq ($(shell uname -r | sed 's|\([0-9][0-9]*\)\.[0-9][0-9]*\.[0-9][0-9]*|\1|'), 8) + FAT_FLAGS = -arch ppc -arch i386 -mmacosx-version-min=10.4 + else + FAT_FLAGS = -arch ppc -arch i386 -arch x86_64 -mmacosx-version-min=10.4 + SOURCES += $(SOURCES_iphoneos) + endif + CFLAGS += $(FAT_FLAGS) -fPIC -I/sw/include \ + -I/Applications/Pd-extended.app/Contents/Resources/include + LDFLAGS += $(FAT_FLAGS) -bundle -undefined dynamic_lookup -L/sw/lib + # if the 'pd' binary exists, check the linking against it to aid with stripping + LDFLAGS += $(shell test -e $(PD_PATH)/bin/pd && echo -bundle_loader $(PD_PATH)/bin/pd) + LIBS += -lc + STRIP = strip -x + DISTDIR=$(LIBRARY_NAME)-$(LIBRARY_VERSION) + DISTBINDIR=$(DISTDIR)-$(OS) +# install into ~/Library/Pd on Mac OS X since /usr/local isn't used much + pkglibdir=$(HOME)/Library/Pd + endif +endif +ifeq ($(UNAME),Linux) + SOURCES += $(SOURCES_linux) + EXTENSION = pd_linux + OS = linux + OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer + CFLAGS += -fPIC + LDFLAGS += -Wl,--export-dynamic -shared -fPIC + LIBS += -lc + STRIP = strip --strip-unneeded -R .note -R .comment + DISTDIR=$(LIBRARY_NAME)-$(LIBRARY_VERSION) + DISTBINDIR=$(DISTDIR)-$(OS)-$(shell uname -m) +endif +ifeq (CYGWIN,$(findstring CYGWIN,$(UNAME))) + SOURCES += $(SOURCES_cygwin) + EXTENSION = dll + OS = cygwin + OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer + CFLAGS += + LDFLAGS += -Wl,--export-dynamic -shared -L$(PD_PATH)/src + LIBS += -lc -lpd + STRIP = strip --strip-unneeded -R .note -R .comment + DISTDIR=$(LIBRARY_NAME)-$(LIBRARY_VERSION) + DISTBINDIR=$(DISTDIR)-$(OS) +endif +ifeq (MINGW,$(findstring MINGW,$(UNAME))) + SOURCES += $(SOURCES_windows) + EXTENSION = dll + OS = windows + OPT_CFLAGS = -O3 -funroll-loops -fomit-frame-pointer -march=i686 -mtune=pentium4 + CFLAGS += -mms-bitfields + LDFLAGS += -s -shared -Wl,--enable-auto-import + LIBS += -L$(PD_PATH)/src -L$(PD_PATH)/bin -L$(PD_PATH)/obj -lpd -lwsock32 -lkernel32 -luser32 -lgdi32 + STRIP = strip --strip-unneeded -R .note -R .comment + DISTDIR=$(LIBRARY_NAME)-$(LIBRARY_VERSION) + DISTBINDIR=$(DISTDIR)-$(OS) +endif + +CFLAGS += $(OPT_CFLAGS) + + +.PHONY = install libdir_install single_install install-doc install-exec install-examples install-manual clean dist etags + +all: $(SOURCES:.c=.$(EXTENSION)) + +%.o: %.c + $(CC) $(CFLAGS) -o "$*.o" -c "$*.c" + +%.$(EXTENSION): %.o + $(CC) $(LDFLAGS) -o "$*.$(EXTENSION)" "$*.o" $(LIBS) + chmod a-x "$*.$(EXTENSION)" + +# this links everything into a single binary file +$(LIBRARY_NAME): $(SOURCES:.c=.o) $(LIBRARY_NAME).o + $(CC) $(LDFLAGS) -o $(LIBRARY_NAME).$(EXTENSION) $(SOURCES:.c=.o) $(LIBRARY_NAME).o $(LIBS) + chmod a-x $(LIBRARY_NAME).$(EXTENSION) + + +install: libdir_install + +# The meta and help files are explicitly installed to make sure they are +# actually there. Those files are not optional, then need to be there. +libdir_install: $(SOURCES:.c=.$(EXTENSION)) install-doc install-examples install-manual + $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) + $(INSTALL_FILE) $(LIBRARY_NAME)-meta.pd \ + $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) + test -z "$(strip $(SOURCES))" || (\ + $(INSTALL_FILE) $(SOURCES:.c=.$(EXTENSION)) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) && \ + $(STRIP) $(addprefix $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/,$(SOURCES:.c=.$(EXTENSION)))) + test -z "$(strip $(PDOBJECTS))" || \ + $(INSTALL_FILE) $(PDOBJECTS) \ + $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) + +# install library linked as single binary +single_install: $(LIBRARY_NAME) install-doc install-exec + $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) + $(INSTALL_FILE) $(LIBRARY_NAME).$(EXTENSION) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) + $(STRIP) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/$(LIBRARY_NAME).$(EXTENSION) + +install-doc: + $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) + test -z "$(strip $(SOURCES))" || \ + $(INSTALL_FILE) $(SOURCES:.c=-help.pd) \ + $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) + test -z "$(strip $(PDOBJECTS))" || \ + $(INSTALL_FILE) $(PDOBJECTS:.pd=-help.pd) \ + $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) + $(INSTALL_FILE) README.txt $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/README.txt + $(INSTALL_FILE) LICENSE.txt $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/LICENSE.txt + +install-examples: + test -z "$(strip $(EXAMPLES))" || \ + $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/examples && \ + for file in $(EXAMPLES); do \ + $(INSTALL_FILE) examples/$$file $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/examples; \ + done + +install-manual: + test -z "$(strip $(MANUAL))" || \ + $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/manual && \ + for file in $(MANUAL); do \ + $(INSTALL_FILE) manual/$$file $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/manual; \ + done + + +clean: + -rm -f -- $(SOURCES:.c=.o) + -rm -f -- $(SOURCES:.c=.$(EXTENSION)) + -rm -f -- $(LIBRARY_NAME).o + -rm -f -- $(LIBRARY_NAME).$(EXTENSION) + +distclean: clean + -rm -f -- $(DISTBINDIR).tar.gz + -rm -rf -- $(DISTBINDIR) + -rm -f -- $(DISTDIR).tar.gz + -rm -rf -- $(DISTDIR) + + +$(DISTBINDIR): + $(INSTALL_DIR) $(DISTBINDIR) + +libdir: all $(DISTBINDIR) + $(INSTALL_FILE) $(LIBRARY_NAME)-meta.pd $(DISTBINDIR) + $(INSTALL_FILE) $(SOURCES) $(DISTBINDIR) + $(INSTALL_FILE) $(SOURCES:.c=-help.pd) $(DISTBINDIR) + test -z "$(strip $(EXTRA_DIST))" || \ + $(INSTALL_FILE) $(EXTRA_DIST) $(DISTBINDIR) +# tar --exclude-vcs -czpf $(DISTBINDIR).tar.gz $(DISTBINDIR) + +$(DISTDIR): + $(INSTALL_DIR) $(DISTDIR) + +dist: $(DISTDIR) + $(INSTALL_FILE) Makefile $(DISTDIR) + $(INSTALL_FILE) README.txt $(DISTDIR) + $(INSTALL_FILE) LICENSE.txt $(DISTDIR) + $(INSTALL_FILE) $(LIBRARY_NAME)-meta.pd $(DISTDIR) + test -z "$(strip $(ALLSOURCES))" || \ + $(INSTALL_FILE) $(ALLSOURCES) $(DISTDIR) + test -z "$(strip $(ALLSOURCES))" || \ + $(INSTALL_FILE) $(ALLSOURCES:.c=-help.pd) $(DISTDIR) + test -z "$(strip $(PDOBJECTS))" || \ + $(INSTALL_FILE) $(PDOBJECTS) $(DISTDIR) + test -z "$(strip $(PDOBJECTS))" || \ + $(INSTALL_FILE) $(PDOBJECTS:.pd=-help.pd) $(DISTDIR) + test -z "$(strip $(EXTRA_DIST))" || \ + $(INSTALL_FILE) $(EXTRA_DIST) $(DISTDIR) + test -z "$(strip $(EXAMPLES))" || \ + $(INSTALL_DIR) $(DISTDIR)/examples && \ + for file in $(EXAMPLES); do \ + $(INSTALL_FILE) examples/$$file $(DISTDIR)/examples; \ + done + test -z "$(strip $(MANUAL))" || \ + $(INSTALL_DIR) $(DISTDIR)/manual && \ + for file in $(MANUAL); do \ + $(INSTALL_FILE) manual/$$file $(DISTDIR)/manual; \ + done + tar --exclude-vcs -czpf $(DISTDIR).tar.gz $(DISTDIR) + + +etags: + etags *.h $(SOURCES) ../../pd/src/*.[ch] /usr/include/*.h /usr/include/*/*.h + +showsetup: + @echo "PD_PATH: $(PD_PATH)" + @echo "objectsdir: $(objectsdir)" + @echo "LIBRARY_NAME: $(LIBRARY_NAME)" + @echo "LIBRARY_VERSION: $(LIBRARY_VERSION)" + @echo "SOURCES: $(SOURCES)" + @echo "PDOBJECTS: $(PDOBJECTS)" + @echo "ALLSOURCES: $(ALLSOURCES)" + @echo "UNAME: $(UNAME)" + @echo "CPU: $(CPU)" + @echo "pkglibdir: $(pkglibdir)" diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..b370029 --- /dev/null +++ b/README.txt @@ -0,0 +1,2 @@ + +This is the beginnings of a library of objects for easy manipulations of files diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..9d53a4c --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +pd-template (0.0-1) unstable; urgency=low + + * Initial release (Closes: #nnnn) + + -- Hans-Christoph Steiner Thu, 21 Jan 2010 23:27:04 -0500 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..7f8f011 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +7 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..7435c85 --- /dev/null +++ b/debian/control @@ -0,0 +1,12 @@ +Source: pd-template +Section: sound +Priority: optional +Maintainer: Paul Brossier +Build-Depends: debhelper (>= 7.0.50~), puredata (>= 0.42.5-3.1~) +Standards-Version: 3.8.3 +Homepage: http://puredata.info + +Package: pd-template +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, pd +Description: diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..21debdf --- /dev/null +++ b/debian/copyright @@ -0,0 +1,14 @@ +Debianized-By: Hans-Christoph Steiner +Debianized-Date: Sat, 3 Apr 2010 17:14:25 -0400 +Files: * +Copyright: 2001-2003, Free Software Foundation + +License: GPL-2+ + This package 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. + . + On Debian systems, the complete text of the GNU General Public License + version 2 can be found in file "/usr/share/common-licenses/GPL-2". + diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..0c273a4 --- /dev/null +++ b/debian/rules @@ -0,0 +1,16 @@ +#!/usr/bin/make -f + +LIBRARY_NAME = template +PACKAGE = pd-$(LIBRARY_NAME) +pkglibdir = /usr/lib/pd/extra + +%: + dh $@ + +override_dh_auto_install: + make DESTDIR=$(CURDIR)/debian/$(PACKAGE) pkglibdir=$(pkglibdir) install + +override_dh_shlibdeps: + dpkg-shlibdeps $(CURDIR)/debian/$(PACKAGE)$(pkglibdir)/$(LIBRARY_NAME)/*.pd_linux \ + -T$(CURDIR)/debian/$(PACKAGE).substvars + diff --git a/examples/bothtogether.pd b/examples/bothtogether.pd new file mode 100644 index 0000000..0522e8d --- /dev/null +++ b/examples/bothtogether.pd @@ -0,0 +1,16 @@ +#N canvas 419 387 450 300 10; +#X declare -path ..; +#X obj 102 172 mypdobject; +#X obj 101 199 print; +#X msg 102 142 bang; +#X obj 319 30 declare -path ..; +#X text 51 84 this is an example of how to use the 'template' library's +two objects: mycobject and mypdobject; +#X obj 201 170 mycobject; +#X msg 201 140 rats; +#X obj 243 139 hsl 128 15 0 127 0 0 empty empty empty -2 -8 0 10 -262144 +-1 -1 0 1; +#X connect 0 0 1 0; +#X connect 2 0 0 0; +#X connect 6 0 5 0; +#X connect 7 0 5 0; diff --git a/ezfile-meta.pd b/ezfile-meta.pd new file mode 100644 index 0000000..2718900 --- /dev/null +++ b/ezfile-meta.pd @@ -0,0 +1,6 @@ +#N canvas 15 49 200 200 10; +#N canvas 25 49 420 300 META 1; +#X text 13 41 NAME template; +#X text 10 25 AUTHOR example@fsf.org; +#X text 10 10 VERSION 0.0; +#X restore 10 10 pd META; diff --git a/getfilenames-help.pd b/getfilenames-help.pd new file mode 100644 index 0000000..ed1a4aa --- /dev/null +++ b/getfilenames-help.pd @@ -0,0 +1,52 @@ +#N canvas 536 89 539 485 10; +#X msg 19 73 bang; +#X msg 27 355 bang; +#X obj 64 300 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 11 420 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X msg 176 255 symbol /usr/*; +#X text 54 73 list current directory; +#X text 160 237 set pattern without no output; +#X obj 27 386 folder_list; +#X obj 83 277 folder_list /*; +#X obj 83 298 print; +#X text 8 49 left/hot inlet gives immediate output using stored path +; +#X text 19 325 For UNIX people \, [folder_list] behaves just like "ls +-d1A"; +#X obj 28 419 print; +#X msg 91 146 symbol ~/*.*; +#X text 187 197 relative paths work; +#X msg 102 198 symbol ../*; +#X text 164 124 drive letters work on ReactOS/Windows; +#X msg 77 123 symbol C:/*; +#X text 190 148 all files with a dot in your home; +#X msg 40 98 symbol %USERPROFILE%/*; +#X text 203 99 ReactOS/Windows environment variables work; +#X text 262 218 nested wildcards work on UNIX; +#X msg 119 219 symbol /var/*/*.log; +#X text 173 173 patterns default to path that Pd launched from; +#X text 329 464 released under the GNU GPL; +#X text 15 449 (C) Copyright 2006 Hans-Christoph Steiner +; +#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 115 380 With no argument \, it defaults to the contents of +the folder of the current patch \, i.e. "/path/to/current/patch/*". +; +#X msg 97 173 symbol *.pd; +#X connect 0 0 8 0; +#X connect 1 0 7 0; +#X connect 4 0 8 1; +#X connect 7 0 3 0; +#X connect 7 0 12 0; +#X connect 8 0 2 0; +#X connect 8 0 9 0; +#X connect 13 0 8 0; +#X connect 15 0 8 0; +#X connect 17 0 8 0; +#X connect 19 0 8 0; +#X connect 22 0 8 0; +#X connect 28 0 8 0; diff --git a/getfilenames.c b/getfilenames.c new file mode 100644 index 0000000..fe47692 --- /dev/null +++ b/getfilenames.c @@ -0,0 +1,264 @@ +/* --------------------------------------------------------------------------*/ +/* */ +/* object for getting file listings using wildcard patterns */ +/* Written by Hans-Christoph Steiner */ +/* */ +/* 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 3 */ +/* 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 + +#ifdef _WIN32 +#define _WIN32_WINNT 0x0400 +#include +#else +#include +#include +#endif + +#include +#include + +static char *version = "$Revision: 1.12 $"; + +#define DEBUG(x) +//#define DEBUG(x) x + +/*------------------------------------------------------------------------------ + * CLASS DEF + */ +static t_class *folder_list_class; + +typedef struct _folder_list { + t_object x_obj; + t_symbol* x_pattern; + t_canvas* x_canvas; +} t_folder_list; + +/*------------------------------------------------------------------------------ + * IMPLEMENTATION + */ + +// TODO: make FindFirstFile display when its just a dir + +static void normalize_path(t_folder_list* x, char *normalized, const char *original) +{ + char buf[FILENAME_MAX]; + t_symbol *cwd = canvas_getdir(x->x_canvas); +#ifdef _WIN32 + sys_unbashfilename(original, buf); +#else + strncpy(buf, original, FILENAME_MAX); +#endif + if(sys_isabsolutepath(buf)) { + strncpy(normalized, buf, FILENAME_MAX); + return; + } + strncpy(normalized, cwd->s_name, FILENAME_MAX); + if(normalized[(strlen(normalized)-1)] != '/') { + strncat(normalized, "/", 1); + } + if(buf[0] == '.') { + if(buf[1] == '/') { + strncat(normalized, buf + 2, + FILENAME_MAX - strlen(normalized)); + } else if(buf[1] == '.' && buf[2] == '/') { + strncat(normalized, buf, + FILENAME_MAX - strlen(normalized)); + } + } else if(buf[0] != '/') { + strncat(normalized, buf, + FILENAME_MAX - strlen(normalized)); + } else { + strncpy(normalized, buf, FILENAME_MAX); + } +} + +static void folder_list_output(t_folder_list* x) +{ + DEBUG(post("folder_list_output");); + char normalized_path[FILENAME_MAX] = ""; + + normalize_path(x, normalized_path, x->x_pattern->s_name); +#ifdef _WIN32 + WIN32_FIND_DATA findData; + HANDLE hFind; + DWORD errorNumber; + LPVOID lpErrorMessage; + char fullPathNameBuffer[FILENAME_MAX] = ""; + char unbashBuffer[FILENAME_MAX] = ""; + char outputBuffer[FILENAME_MAX] = ""; + char *pathBuffer; + +// arg, looks perfect, but only in Windows Vista +// GetFinalPathNameByHandle(hFind,fullPathNameBuffer,FILENAME_MAX,FILE_NAME_NORMALIZED); + GetFullPathName(normalized_path, FILENAME_MAX, fullPathNameBuffer, NULL); + sys_unbashfilename(fullPathNameBuffer,unbashBuffer); + + hFind = FindFirstFile(fullPathNameBuffer, &findData); + if (hFind == INVALID_HANDLE_VALUE) + { + errorNumber = GetLastError(); + switch (errorNumber) + { + case ERROR_FILE_NOT_FOUND: + case ERROR_PATH_NOT_FOUND: + pd_error(x,"[folder_list] nothing found for \"%s\"",x->x_pattern->s_name); + break; + default: + FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + errorNumber, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR) &lpErrorMessage, + 0, NULL ); + pd_error(x,"[folder_list] %s", (char *)lpErrorMessage); + } + return; + } + char* unbashBuffer_position = strrchr(unbashBuffer, '/'); + if(unbashBuffer_position) + { + pathBuffer = getbytes(FILENAME_MAX+1); + strncpy(pathBuffer, unbashBuffer, unbashBuffer_position - unbashBuffer); + } + do { + // skip "." and ".." + if( strcmp(findData.cFileName, ".") && strcmp(findData.cFileName, "..") ) + { + strncpy(outputBuffer, pathBuffer, FILENAME_MAX); + strcat(outputBuffer,"/"); + strcat(outputBuffer,findData.cFileName); + outlet_symbol( x->x_obj.ob_outlet, gensym(outputBuffer) ); + } + } while (FindNextFile(hFind, &findData) != 0); + FindClose(hFind); +#else + unsigned int i; + glob_t glob_buffer; + + DEBUG(post("globbing %s",normalized_path);); + switch( glob( normalized_path, GLOB_TILDE, NULL, &glob_buffer ) ) + { + case GLOB_NOSPACE: + pd_error(x,"[folder_list] out of memory for \"%s\"",normalized_path); + break; +# ifdef GLOB_ABORTED + case GLOB_ABORTED: + pd_error(x,"[folder_list] aborted \"%s\"",normalized_path); + break; +# endif +# ifdef GLOB_NOMATCH + case GLOB_NOMATCH: + pd_error(x,"[folder_list] nothing found for \"%s\"",normalized_path); + break; +# endif + } + for(i = 0; i < glob_buffer.gl_pathc; i++) + outlet_symbol( x->x_obj.ob_outlet, gensym(glob_buffer.gl_pathv[i]) ); + globfree( &(glob_buffer) ); +#endif +} + + +static void folder_list_set(t_folder_list* x, t_symbol *s) +{ + DEBUG(post("folder_list_set");); +#ifdef _WIN32 + char *patternBuffer; + char envVarBuffer[FILENAME_MAX]; + if( (s->s_name[0] == '~') && (s->s_name[1] == '/')) + { + patternBuffer = getbytes(FILENAME_MAX); + strcpy(patternBuffer,"%USERPROFILE%"); + strncat(patternBuffer, s->s_name + 1, FILENAME_MAX - 1); + post("set: %s", patternBuffer); + } + else + { + patternBuffer = s->s_name; + } + ExpandEnvironmentStrings(patternBuffer, envVarBuffer, FILENAME_MAX - 2); + x->x_pattern = gensym(envVarBuffer); +#else // UNIX + // TODO translate env vars to a full path + x->x_pattern = s; +#endif /* _WIN32 */ +} + + +static void folder_list_symbol(t_folder_list *x, t_symbol *s) +{ + folder_list_set(x,s); + folder_list_output(x); +} + + +static void *folder_list_new(t_symbol *s) +{ + DEBUG(post("folder_list_new");); + + t_folder_list *x = (t_folder_list *)pd_new(folder_list_class); + t_symbol *currentdir; + char buffer[MAXPDSTRING]; + + x->x_canvas = canvas_getcurrent(); + + symbolinlet_new(&x->x_obj, &x->x_pattern); + outlet_new(&x->x_obj, &s_symbol); + + /* set to the value from the object argument, if that exists */ + if (s != &s_) + { + x->x_pattern = s; + } + else + { + currentdir = canvas_getcurrentdir(); + strncpy(buffer,currentdir->s_name,MAXPDSTRING); + strncat(buffer,"/*",MAXPDSTRING); + x->x_pattern = gensym(buffer); + post("setting pattern to default: %s",x->x_pattern->s_name); + } + + return (x); +} + +void folder_list_setup(void) +{ + DEBUG(post("folder_list_setup");); + folder_list_class = class_new(gensym("folder_list"), + (t_newmethod)folder_list_new, + 0, + sizeof(t_folder_list), + 0, + A_DEFSYMBOL, + 0); + /* add inlet datatype methods */ + class_addbang(folder_list_class,(t_method) folder_list_output); + class_addsymbol(folder_list_class,(t_method) folder_list_symbol); + + /* add inlet message methods */ + class_addmethod(folder_list_class,(t_method) folder_list_set,gensym("set"), + A_DEFSYMBOL, 0); +} + diff --git a/manual/manual.txt b/manual/manual.txt new file mode 100644 index 0000000..66cddd7 --- /dev/null +++ b/manual/manual.txt @@ -0,0 +1,4 @@ + +This is the manual for the 'template' library example. The manual can be in +just about any form from plain text to PDF. Recommended formats are: plain +text, HTML, PDF. -- cgit v1.2.1