[PD-cvs] SF.net SVN: pure-data: [9779] branches/pd-extended/v0-40/pd/src/s_path.c
eighthave at users.sourceforge.net
eighthave at users.sourceforge.net
Sun May 11 01:00:45 CEST 2008
Revision: 9779
http://pure-data.svn.sourceforge.net/pure-data/?rev=9779&view=rev
Author: eighthave
Date: 2008-05-10 16:00:44 -0700 (Sat, 10 May 2008)
Log Message:
-----------
created sys_expandpath() to replace ~ with $HOME and expand env vars on
Windows. This function is then used in sys_trytoopenone() so that ~ works
with all opening operations.
Modified Paths:
--------------
branches/pd-extended/v0-40/pd/src/s_path.c
Modified: branches/pd-extended/v0-40/pd/src/s_path.c
===================================================================
--- branches/pd-extended/v0-40/pd/src/s_path.c 2008-05-10 18:54:22 UTC (rev 9778)
+++ branches/pd-extended/v0-40/pd/src/s_path.c 2008-05-10 23:00:44 UTC (rev 9779)
@@ -70,6 +70,30 @@
*to = 0;
}
+/* expand env vars and ~ at the beginning of a path and make a copy to return */
+static void sys_expandpath(const char *from, char *to)
+{
+ if ((strlen(from) == 1 && from[0] == '~') || (strncmp(from,"~/", 2) == 0))
+ {
+#ifdef MSW
+ const char *home = getenv("USERPROFILE");
+#else
+ const char *home = getenv("HOME");
+#endif
+ if(home)
+ {
+ strncpy(to, home, FILENAME_MAX - 1);
+ strncat(to, from + 1, FILENAME_MAX - strlen(from) - 2);
+ }
+ }
+ else
+ strncpy(to, from, FILENAME_MAX - 1);
+#ifdef MSW
+ char buf[FILENAME_MAX];
+ ExpandEnvironmentStrings(to, buf, FILENAME_MAX - 2);
+ strncpy(to, buf, FILENAME_MAX - 1);
+#endif
+}
/******************* Utility functions used below ******************/
/*!
@@ -199,7 +223,7 @@
int fd;
if (strlen(dir) + strlen(name) + strlen(ext) + 4 > size)
return (-1);
- strcpy(dirresult, dir);
+ sys_expandpath(dir, dirresult);
if (*dirresult && dirresult[strlen(dirresult)-1] != '/')
strcat(dirresult, "/");
strcat(dirresult, name);
@@ -251,9 +275,9 @@
int sys_open_absolute(const char *name, const char* ext,
char *dirresult, char **nameresult, unsigned int size, int bin, int *fdp)
{
- if (name[0] == '/'
+ if (name[0] == '/' || name[0] == '~'
#ifdef MSW
- || (name[1] == ':' && name[2] == '/')
+ || name[0] == '%' || (name[1] == ':' && name[2] == '/')
#endif
)
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Pd-cvs
mailing list