Index: trunk/MagicSoft/Mars/mbase/MEnv.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MEnv.cc	(revision 8695)
+++ trunk/MagicSoft/Mars/mbase/MEnv.cc	(revision 8716)
@@ -31,4 +31,14 @@
 // PrintUntouched()
 //
+// A new special resource is available. With the resource "Include"
+// you can include resources from other files, for example
+//
+//   Include: file1.rc file2.rc
+//
+// Including can be done recursively. Resources from the included files
+// have lower priority. This allows to write a resource file with your
+// default resources which then can be included in other files overwriting
+// some of the resources.
+//
 //////////////////////////////////////////////////////////////////////////////
 #include "MEnv.h"
@@ -58,10 +68,13 @@
     fChecked.SetOwner();
 
+    // If TEnv::TEnv has not set fRcName
     if (!IsValid())
         return;
 
+    // ExpandPathName (not done by TEnv::TEnv) and read again
     TString fname(name);
     gSystem->ExpandPathName(fname);
 
+    // Is file accessible
     if (gSystem->AccessPathName(fname, kFileExists))
         fname = "";
@@ -69,6 +82,99 @@
     SetRcName(fname);
 
-    if (GetEntries()<=0 && !fname.IsNull() && fname!=name)
-        ReadFile(fname, kEnvLocal);;
+    // No file found
+    if (fname.IsNull())
+        return;
+
+    // File has been already processed, but ReadInclude is part of a
+    // derived function, i.e. not yet executed.
+    if (GetEntries()>0 || fname==name)
+    {
+        if (ReadInclude()<0)
+            SetRcName("");
+        return;
+    }
+
+    // File not yet processed. Reread file.
+    if (ReadFile(fname, kEnvLocal)<0)
+        SetRcName("");
+}
+
+//---------------------------------------------------------------------------
+//
+// Process an Include directive and read the corresponding contents
+//
+Int_t MEnv::ReadInclude()
+{
+    // Check for "Include" resource
+    const TString incl = GetValue("Include", "");
+    if (incl.IsNull())
+        return 0;
+
+    // Tokenize the array into single files divided by a whitespace
+    TObjArray *arr = incl.Tokenize(" ");
+
+    // We have to rebuild the Include array from scratch to get the
+    // correct sorting for a possible rereading.
+    SetValue("Include", "");
+
+    // FIXME: Make sure that recursions don't crash the system!
+
+    for (int i=0; i<arr->GetEntries(); i++)
+    {
+        // Get file name to include
+        const char *fenv = (*arr)[i]->GetName();
+
+        // Read included file and check if its valid
+        const MEnv env(fenv);
+        if (!env.IsValid())
+        {
+            delete arr;
+            return -1;
+        }
+
+        // Add file name before its childs
+        SetValue("+Include", fenv);
+
+        // If it is valid add entries from include without overwriting,
+        // i.e. the included resources have lower priority
+        AddEnv(env, kFALSE);
+
+        // Get a possible child include from env
+        const TString incl2 = const_cast<MEnv&>(env).GetValue("Include", "");
+        if (!incl2.IsNull())
+            SetValue("+Include", incl2);
+    }
+
+    delete arr;
+
+    // Get final compiled resource
+    TString inc = GetValue("Include", "");
+
+    // Remove obsolete whitespaces for convinience
+    inc.ReplaceAll("  ", " ");
+    inc = inc.Strip(TString::kBoth);
+
+    // Set final resource, now as kEnvLocal (previously set as kEnvChnaged)
+    SetValue("Include", inc, kEnvLocal);
+
+    // FIXME: Remove douplets in the correct order
+
+    return 0;
+}
+
+//---------------------------------------------------------------------------
+//
+// Read and parse the resource file for a certain level.
+// Returns -1 on case of error, 0 in case of success.
+//
+// Check for an include directive
+//
+Int_t MEnv::ReadFile(const char *fname, EEnvLevel level)
+{
+    // First read the file via TEnv
+    if (TEnv::ReadFile(fname, level)<0)
+        return -1;
+
+    return ReadInclude();
 }
 
