Author: matt
Date: 2010-12-19 13:39:01 -0800 (Sun, 19 Dec 2010)
New Revision: 8064
Log:
Added fl_filename_relative which uses an additional parameter instead of the
current working directory. Now we can find a relative path without changing the
cwd.
Modified:
branches/branch-1.3/FL/filename.H
branches/branch-1.3/src/filename_absolute.cxx
branches/branch-1.3/src/numericsort.c
Modified: branches/branch-1.3/FL/filename.H
===================================================================
--- branches/branch-1.3/FL/filename.H 2010-12-19 21:20:10 UTC (rev 8063)
+++ branches/branch-1.3/FL/filename.H 2010-12-19 21:39:01 UTC (rev 8064)
@@ -63,6 +63,7 @@
FL_EXPORT int fl_filename_expand(char *to, int tolen, const char *from);
FL_EXPORT int fl_filename_absolute(char *to, int tolen, const char *from);
FL_EXPORT int fl_filename_relative(char *to, int tolen, const char *from);
+FL_EXPORT int fl_filename_relative(char *to, int tolen, const char *from,
const char *cwd);
FL_EXPORT int fl_filename_match(const char *name, const char *pattern);
FL_EXPORT int fl_filename_isdir(const char *name);
Modified: branches/branch-1.3/src/filename_absolute.cxx
===================================================================
--- branches/branch-1.3/src/filename_absolute.cxx 2010-12-19 21:20:10 UTC
(rev 8063)
+++ branches/branch-1.3/src/filename_absolute.cxx 2010-12-19 21:39:01 UTC
(rev 8064)
@@ -136,13 +136,34 @@
int // O - 0 if no change, 1 if changed
fl_filename_relative(char *to, // O - Relative filename
int tolen, // I - Size of "to" buffer
- const char *from) {// I - Absolute filename
- char *newslash; // Directory separator
+ const char *from) // I - Absolute filename
+{
+ char cwd_buf[FL_PATH_MAX]; // Current directory
+ // get the current directory and return if we can't
+ if (!fl_getcwd(cwd_buf, sizeof(cwd_buf))) {
+ strlcpy(to, from, tolen);
+ return 0;
+ }
+ return fl_filename_relative(to, tolen, from, cwd_buf);
+}
+
+
+/** Makes a filename relative to any other directory.
+ \param[out] to resulting relative filename
+ \param[in] tolen size of the relative filename buffer
+ \param[in] from absolute filename
+ \param[in] cwd relative to this absolute path
+ \return 0 if no change, non zero otherwise
+ */
+int // O - 0 if no change, 1 if changed
+fl_filename_relative(char *to, // O - Relative filename
+ int tolen, // I - Size of "to" buffer
+ const char *from, // I - Absolute filename
+ const char *cwd) { // I - Find path relative to this path
+
+ const char *newslash; // Directory separator
const char *slash; // Directory separator
- char cwd_buf[FL_PATH_MAX]; // Current directory
- char *cwd = cwd_buf;
-
// return if "from" is not an absolute path
#if defined(WIN32) || defined(__EMX__)
if (from[0] == '\0' ||
@@ -154,13 +175,19 @@
strlcpy(to, from, tolen);
return 0;
}
-
- // get the current directory and return if we can't
- if (!fl_getcwd(cwd_buf, sizeof(cwd_buf))) {
+
+ // return if "cwd" is not an absolute path
+#if defined(WIN32) || defined(__EMX__)
+ if (!cwd || cwd[0] == '\0' ||
+ (!isdirsep(*cwd) && !isalpha(*cwd) && cwd[1] != ':' &&
+ !isdirsep(cwd[2]))) {
+#else
+ if (!cwd || cwd[0] == '\0' || !isdirsep(*cwd)) {
+#endif // WIN32 || __EMX__
strlcpy(to, from, tolen);
return 0;
}
-
+
#if defined(WIN32) || defined(__EMX__)
// convert all backslashes into forward slashes
for (newslash = strchr(cwd, '\\'); newslash; newslash = strchr(newslash + 1,
'\\'))
Modified: branches/branch-1.3/src/numericsort.c
===================================================================
--- branches/branch-1.3/src/numericsort.c 2010-12-19 21:20:10 UTC (rev
8063)
+++ branches/branch-1.3/src/numericsort.c 2010-12-19 21:39:01 UTC (rev
8064)
@@ -33,8 +33,6 @@
#include <stdlib.h>
#include <sys/types.h>
-#include <FL/filename.H>
-
#if !defined(WIN32) || defined(__CYGWIN__)
# ifdef HAVE_DIRENT_H
# include <dirent.h>
_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit