Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/wolfpld/tracy.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/public
diff options
context:
space:
mode:
authorBartosz Taudul <wolf@nereid.pl>2022-09-02 02:23:14 +0300
committerBartosz Taudul <wolf@nereid.pl>2022-09-02 02:23:14 +0300
commit8cc43284bd3518981adb2132d119bfc702b64a9c (patch)
treec71d05cdceb10bba16faf2162a15d5e46ced6f02 /public
parent165cc22115fc806ad9da447fc16fb4ab65e70f5f (diff)
Add path normalization function.
Diffstat (limited to 'public')
-rw-r--r--public/client/TracyCallstack.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/public/client/TracyCallstack.cpp b/public/client/TracyCallstack.cpp
index a8d9b6f5..3a96fe5e 100644
--- a/public/client/TracyCallstack.cpp
+++ b/public/client/TracyCallstack.cpp
@@ -699,6 +699,62 @@ static void InitKernelSymbols()
}
#endif
+char* NormalizePath( const char* path )
+{
+ if( path[0] != '/' ) return nullptr;
+
+ const char* ptr = path;
+ const char* end = path;
+ while( *end ) end++;
+
+ char* res = (char*)tracy_malloc( end - ptr + 1 );
+ size_t rsz = 0;
+
+ while( ptr < end )
+ {
+ const char* next = ptr;
+ while( next < end && *next != '/' ) next++;
+ size_t lsz = next - ptr;
+ switch( lsz )
+ {
+ case 2:
+ if( memcmp( ptr, "..", 2 ) == 0 )
+ {
+ const char* back = res + rsz - 1;
+ while( back > res && *back != '/' ) back--;
+ rsz = back - res;
+ ptr = next + 1;
+ continue;
+ }
+ break;
+ case 1:
+ if( *ptr == '.' )
+ {
+ ptr = next + 1;
+ continue;
+ }
+ break;
+ case 0:
+ ptr = next + 1;
+ continue;
+ }
+ if( rsz != 1 ) res[rsz++] = '/';
+ memcpy( res+rsz, ptr, lsz );
+ rsz += lsz;
+ ptr = next + 1;
+ }
+
+ if( rsz == 0 )
+ {
+ memcpy( res, "/", 2 );
+ }
+ else
+ {
+ res[rsz] = '\0';
+ }
+ return res;
+}
+
void InitCallstackCritical()
{
}