# HG changeset patch # User Santeri Piippo # Date 1369135450 -10800 # Node ID 79b120b0aa51f3b4f40921d69d5540b3524b8bd8 # Parent 524cb083302775cb7d3cca836396a2ace8a4ac09 added basename since windows doesn't have it diff -r 524cb0833027 -r 79b120b0aa51 src/file.cpp --- 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 diff -r 524cb0833027 -r 79b120b0aa51 src/file.h --- 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 g_loadedFiles; extern vector g_PartList; +str basename (str path); + #endif // FILE_H \ No newline at end of file