added basename since windows doesn't have it

Tue, 21 May 2013 14:24:10 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Tue, 21 May 2013 14:24:10 +0300
changeset 234
79b120b0aa51
parent 233
524cb0833027
child 235
bb0a7bcca7eb

added basename since windows doesn't have it

src/file.cpp file | annotate | diff | comparison | revisions
src/file.h file | annotate | diff | comparison | revisions
--- a/src/file.cpp	Tue May 21 14:21:26 2013 +0300
+++ b/src/file.cpp	Tue May 21 14:24:10 2013 +0300
@@ -124,6 +124,19 @@
 }
 
 // =============================================================================
+str basename (str path) {
+	long lastpos; // FIXME: why doesn't str::last () work here?
+	for (lastpos = path.len () - 1; lastpos >= 0; --lastpos)
+		if (path[(size_t) lastpos] == DIRSLASH_CHAR)
+			break;
+	
+	if (lastpos < (log) path.len () - 1)
+		return path.substr (lastpos + 1, -1);
+	
+	return "";
+}
+
+// =============================================================================
 FILE* openLDrawFile (str relpath, bool subdirs) {
 	printf ("%s: Try to open %s\n", __func__, relpath.c ());
 #ifndef WIN32
--- a/src/file.h	Tue May 21 14:21:26 2013 +0300
+++ b/src/file.h	Tue May 21 14:24:10 2013 +0300
@@ -126,4 +126,6 @@
 extern vector<LDOpenFile*> g_loadedFiles;
 extern vector<partListEntry> g_PartList;
 
+str basename (str path);
+
 #endif // FILE_H
\ No newline at end of file

mercurial