aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas O Fredericks <mrtof@users.sourceforge.net>2009-10-07 20:06:41 +0000
committerThomas O Fredericks <mrtof@users.sourceforge.net>2009-10-07 20:06:41 +0000
commit9728c280040625fd4eff572b71b3cb6c8495206b (patch)
treea8570fd6580501499a646fafd3df4632df6fb665
parentcd658ffed1329080f06f84e890dcda4302ca5864 (diff)
fixed a problem having to do with absolute and relative paths
svn path=/trunk/externals/tof/; revision=12555
-rw-r--r--src/Makefile2
-rw-r--r--src/paramCustom.c4
-rw-r--r--src/path.c45
-rw-r--r--src/tof.h23
4 files changed, 47 insertions, 27 deletions
diff --git a/src/Makefile b/src/Makefile
index e1d67f9..31b2c9f 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,6 +1,6 @@
default:
-PARAM: param paramDump paramRoute paramFile
+PARAM: param paramDump paramRoute paramFile paramCustom paramId
current:
echo make class
diff --git a/src/paramCustom.c b/src/paramCustom.c
index 834b32f..20144ba 100644
--- a/src/paramCustom.c
+++ b/src/paramCustom.c
@@ -92,7 +92,7 @@ static void paramCustom_save(t_paramCustom *x, t_binbuf* bb) {
x->bb = bb;
// TRIGGER OUTPUT
- outlet_bang(x->outlet2);
+ outlet_bang(x->outlet);
x->bb = NULL;
} else {
@@ -122,7 +122,7 @@ static void paramClass_GUI(t_paramClass *x, int* ac, t_atom** av) {
static void paramCustom_receive_anything(t_paramCustom_receive *r, t_symbol *s, int ac, t_atom *av){
- outlet_anything(r->owner->outlet,s,ac,av);
+ outlet_anything(r->owner->outlet2,s,ac,av);
}
diff --git a/src/path.c b/src/path.c
index d0dc7ef..f8b20e4 100644
--- a/src/path.c
+++ b/src/path.c
@@ -17,6 +17,22 @@ typedef struct _path {
} t_path;
+
+static int path_is_absolute(char *dir, int length)
+{
+ if ((length && dir[0] == '/') || (dir[0] == '~')
+#ifdef MSW
+ || dir[0] == '%' || (length > 2 && (dir[1] == ':' && dir[2] == '/'))
+#endif
+ )
+ {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+
// Code from http://www.codeguru.com/cpp/misc/misc/fileanddirectorynaming/article.php/c263#more
static void getRelativeFilename(char* relativeFilename, char *currentDirectory, char *absoluteFilename)
{
@@ -82,11 +98,14 @@ static void getRelativeFilename(char* relativeFilename, char *currentDirectory,
i++;
if(currentDirectory[i] != '\0')
{
+
levels++;
}
}
}
-
+
+
+
// move the absolute filename marker back to the start of the directory name
// that it has stopped in.
while(afMarker > 0 && absoluteFilename[afMarker-1] != SLASH)
@@ -134,7 +153,7 @@ static void path_anything(t_path *x, t_symbol *s, int ac, t_atom* av) {
// Is this a relative path?
// Checks for a starting / or a : as second character
- if ( tof_path_is_absolute(tof_buf_temp_a,length )) {
+ if ( path_is_absolute(tof_buf_temp_a,length )) {
getRelativeFilename(tof_buf_temp_b,x->dir->s_name,tof_buf_temp_a);
result = gensym(tof_buf_temp_b);
} else {
@@ -146,12 +165,25 @@ static void path_anything(t_path *x, t_symbol *s, int ac, t_atom* av) {
// TRANFORM RELATIVE PATHS TO ABSOLUTE PATHS
// Is this a relative path?
- if ( tof_path_is_absolute(tof_buf_temp_a,length) ) {
+ if ( path_is_absolute(tof_buf_temp_a,length) ) {
result = gensym(tof_buf_temp_a);
} else {
+ // remove extra ../
strcpy(tof_buf_temp_b,x->dir->s_name);
- strcat(tof_buf_temp_b,tof_buf_temp_a);
- result = gensym(tof_buf_temp_b);
+ char* dir = tof_buf_temp_b;
+ char* p;
+ int l = strlen(dir);
+ if (dir[l-1] = '/') dir[l-1] = '\0';
+ char* file = tof_buf_temp_a;
+ while( strncmp(file,"../",3) == 0 ) {
+ file = file + 3;
+ p = strrchr(dir,'/');
+ if (p) *p = '\0';
+ }
+
+ strcat(dir,"/");
+ strcat(dir,file);
+ result = gensym(dir);
}
}
@@ -211,7 +243,8 @@ void *path_new(t_symbol *s, int argc, t_atom *argv)
}
strcpy(tof_buf_temp_a,x->dir->s_name);
- strcat(tof_buf_temp_a,"/");
+
+ //strcat(tof_buf_temp_a,"/");
x->dir = gensym(tof_buf_temp_a);
/*
diff --git a/src/tof.h b/src/tof.h
index 2f51630..3698b52 100644
--- a/src/tof.h
+++ b/src/tof.h
@@ -39,21 +39,6 @@ static t_symbol* tof_get_dollarzero(t_canvas* canvas) {
}
-static int tof_path_is_absolute(char *dir, int length)
-{
- if ((length && dir[0] == '/') || (dir[0] == '~')
-#ifdef MSW
- || dir[0] == '%' || (length > 2 && (dir[1] == ':' && dir[2] == '/'))
-#endif
- )
- {
- return 1;
- } else {
- return 0;
- }
-}
-
-
static int tof_canvas_is_not_subpatch(t_canvas* canvas) {
return canvas_isabstraction(canvas);
@@ -281,13 +266,15 @@ static void tof_send_anything_prepend(t_symbol* target,t_symbol* s, int ac, t_at
static t_symbol* tof_remove_extension(t_symbol* s) {
- t_symbol* newsymbol;
+ t_symbol* newsymbol = s;
int length = strlen(s->s_name) + 1;
char* newstring = getbytes(length * sizeof(*newstring));
strcpy(newstring,s->s_name);
char* last = strrchr( newstring, '.');
- *last = '\0';
- newsymbol = gensym(newstring);
+ if (last != NULL) {
+ *last = '\0';
+ newsymbol = gensym(newstring);
+ }
freebytes(newstring,length * sizeof(*newstring));
return newsymbol;
}