Ignore:
Timestamp:
08/28/07 11:57:31 (17 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mbase/MEnv.cc

    r8695 r8716  
    3131// PrintUntouched()
    3232//
     33// A new special resource is available. With the resource "Include"
     34// you can include resources from other files, for example
     35//
     36//   Include: file1.rc file2.rc
     37//
     38// Including can be done recursively. Resources from the included files
     39// have lower priority. This allows to write a resource file with your
     40// default resources which then can be included in other files overwriting
     41// some of the resources.
     42//
    3343//////////////////////////////////////////////////////////////////////////////
    3444#include "MEnv.h"
     
    5868    fChecked.SetOwner();
    5969
     70    // If TEnv::TEnv has not set fRcName
    6071    if (!IsValid())
    6172        return;
    6273
     74    // ExpandPathName (not done by TEnv::TEnv) and read again
    6375    TString fname(name);
    6476    gSystem->ExpandPathName(fname);
    6577
     78    // Is file accessible
    6679    if (gSystem->AccessPathName(fname, kFileExists))
    6780        fname = "";
     
    6982    SetRcName(fname);
    7083
    71     if (GetEntries()<=0 && !fname.IsNull() && fname!=name)
    72         ReadFile(fname, kEnvLocal);;
     84    // No file found
     85    if (fname.IsNull())
     86        return;
     87
     88    // File has been already processed, but ReadInclude is part of a
     89    // derived function, i.e. not yet executed.
     90    if (GetEntries()>0 || fname==name)
     91    {
     92        if (ReadInclude()<0)
     93            SetRcName("");
     94        return;
     95    }
     96
     97    // File not yet processed. Reread file.
     98    if (ReadFile(fname, kEnvLocal)<0)
     99        SetRcName("");
     100}
     101
     102//---------------------------------------------------------------------------
     103//
     104// Process an Include directive and read the corresponding contents
     105//
     106Int_t MEnv::ReadInclude()
     107{
     108    // Check for "Include" resource
     109    const TString incl = GetValue("Include", "");
     110    if (incl.IsNull())
     111        return 0;
     112
     113    // Tokenize the array into single files divided by a whitespace
     114    TObjArray *arr = incl.Tokenize(" ");
     115
     116    // We have to rebuild the Include array from scratch to get the
     117    // correct sorting for a possible rereading.
     118    SetValue("Include", "");
     119
     120    // FIXME: Make sure that recursions don't crash the system!
     121
     122    for (int i=0; i<arr->GetEntries(); i++)
     123    {
     124        // Get file name to include
     125        const char *fenv = (*arr)[i]->GetName();
     126
     127        // Read included file and check if its valid
     128        const MEnv env(fenv);
     129        if (!env.IsValid())
     130        {
     131            delete arr;
     132            return -1;
     133        }
     134
     135        // Add file name before its childs
     136        SetValue("+Include", fenv);
     137
     138        // If it is valid add entries from include without overwriting,
     139        // i.e. the included resources have lower priority
     140        AddEnv(env, kFALSE);
     141
     142        // Get a possible child include from env
     143        const TString incl2 = const_cast<MEnv&>(env).GetValue("Include", "");
     144        if (!incl2.IsNull())
     145            SetValue("+Include", incl2);
     146    }
     147
     148    delete arr;
     149
     150    // Get final compiled resource
     151    TString inc = GetValue("Include", "");
     152
     153    // Remove obsolete whitespaces for convinience
     154    inc.ReplaceAll("  ", " ");
     155    inc = inc.Strip(TString::kBoth);
     156
     157    // Set final resource, now as kEnvLocal (previously set as kEnvChnaged)
     158    SetValue("Include", inc, kEnvLocal);
     159
     160    // FIXME: Remove douplets in the correct order
     161
     162    return 0;
     163}
     164
     165//---------------------------------------------------------------------------
     166//
     167// Read and parse the resource file for a certain level.
     168// Returns -1 on case of error, 0 in case of success.
     169//
     170// Check for an include directive
     171//
     172Int_t MEnv::ReadFile(const char *fname, EEnvLevel level)
     173{
     174    // First read the file via TEnv
     175    if (TEnv::ReadFile(fname, level)<0)
     176        return -1;
     177
     178    return ReadInclude();
    73179}
    74180
Note: See TracChangeset for help on using the changeset viewer.