From 8f81d41771343b8084fa80b95c9031349993ee0f Mon Sep 17 00:00:00 2001
From: Bertrand Bellenot <Bertrand.Bellenot@cern.ch>
Date: Thu, 15 Mar 2012 11:20:38 +0000
Subject: [PATCH] - Solve a problem when the directory name is similar to
 $ROOTSYS (e.g. /home/user/rootdev and /home/user/root, only "dev" was
 displayed, stripping off $ROOTSYS) - Properly handle backslashes as directory
 separators on Windows

git-svn-id: http://root.cern.ch/svn/root/trunk@43362 27541ba8-7e3a-0410-8455-c3a389f83636
---
 gui/gui/src/TGFSComboBox.cxx | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/gui/gui/src/TGFSComboBox.cxx b/gui/gui/src/TGFSComboBox.cxx
index a6a14f8a28a..c0c7daa7d2b 100644
--- a/gui/gui/src/TGFSComboBox.cxx
+++ b/gui/gui/src/TGFSComboBox.cxx
@@ -36,6 +36,7 @@
 #include "TGPicture.h"
 #include "TSystem.h"
 #include "Riostream.h"
+#include <stdlib.h>
 
 const TGFont *TGTreeLBEntry::fgDefaultFont = 0;
 TGGC         *TGTreeLBEntry::fgDefaultGC = 0;
@@ -222,7 +223,9 @@ TGFSComboBox::TGFSComboBox(const TGWindow *parent, Int_t id, UInt_t options,
 
    const char *homeDir = gSystem->HomeDirectory();
 #ifndef ROOTPREFIX
-   const char *rootSys = gSystem->Getenv("ROOTSYS");
+   const char *rootsys = gSystem->Getenv("ROOTSYS");
+   char *rootSys = (char *)calloc(strlen(rootsys)+1, sizeof(char));
+   sprintf(rootSys, "%s/", rootsys);
 #else
    // const char *rootSys = ROOTPREFIX;
 #endif
@@ -401,6 +404,7 @@ TGFSComboBox::TGFSComboBox(const TGWindow *parent, Int_t id, UInt_t options,
       }
    }
    SetWindowName();
+   free(rootSys);
 }
 
 //______________________________________________________________________________
@@ -434,11 +438,12 @@ void TGFSComboBox::Update(const char *path)
    }
 
    if (tailpath && *tailpath) {
-      if (*tailpath == '/') ++tailpath;
+      if ((*tailpath == '/') || (*tailpath == '\\')) ++tailpath;
       if (*tailpath)
          while (1) {
             const char *picname;
             const char *semi = strchr(tailpath, '/');
+            if (semi == 0) semi = strchr(tailpath, '\\');
             if (semi == 0) {
                strlcpy(dirname, tailpath, 1024);
                picname = "ofolder_t.xpm";
@@ -446,8 +451,10 @@ void TGFSComboBox::Update(const char *path)
                strlcpy(dirname, tailpath, (semi-tailpath)+1);
                picname = "folder_t.xpm";
             }
-            if (mpath[strlen(mpath)-1] != '/') 
+            if ((mpath[strlen(mpath)-1] != '/') && 
+                (mpath[strlen(mpath)-1] != '\\')) {
                strlcat(mpath, "/", 1024-strlen(mpath));
+            }
             strlcat(mpath, dirname, 1024-strlen(mpath));
             int indent = 4 + (indent_lvl * 10);
             const TGPicture *pic = fClient->GetPicture(picname);
-- 
GitLab