Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

cmt_parser.cxx File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "cmt_parser.h"
#include "cmt_version.h"
#include "cmt_database.h"
#include "cmt_include.h"
#include "cmt_script.h"
#include "cmt_generator.h"
#include "cmt_system.h"
#include "cmt.h"
#include "cmt_error.h"
#include "cmt_cvs.h"
#include "cmt_lock.h"
#include "cmt_triggers.h"
#include "cmt_model.h"

Include dependency graph for cmt_parser.cxx:

Include dependency graph

Go to the source code of this file.

Compounds

class  FileScanner::actor
class  FileScanner
class  PackageCollector
class  PackageSelector
class  PackageViewer

Functions

cmt_string get_best_form (const CmtSystem::cmt_string_vector& pwd, const cmt_string& path)


Function Documentation

cmt_string get_best_form ( const CmtSystem::cmt_string_vector & pwd,
const cmt_string & path ) [static]
 

Definition at line 7285 of file cmt_parser.cxx.

Referenced by Cmt::set_standard_macros().

07287 {
07288   static cmt_string fs = CmtSystem::file_separator ();
07289   cmt_string result;
07290 
07291     /*
07292     //if (CmtSystem::getenv ("CMTTESTPREFIX") != "")
07293     {
07294     */
07295 
07296     //
07297     //  If there is a common prefix between
07298     //  use->real_path and pwd
07299     //  we have 
07300     //  use->real_path = /<prefix>/aaa
07301     //  pwd            = /<prefix>/bbb
07302     //
07303     //  Then use->real_path may be expressed as:
07304     //  ../..../../aaa
07305     //   where ../..../../ moves up to /<prefix>
07306     //
07307     //   Then we try to find the shortest between
07308     //
07309     //     /<prefix> and ../..../..
07310     //
07311   cmt_string a = path;
07312   
07313   CmtSystem::cmt_string_vector va;
07314   
07315   va.clear ();
07316   
07317   CmtSystem::split (a, fs, va);
07318   
07319   int m = va.size ();
07320   if (pwd.size () < m) m = pwd.size ();
07321   
07322   int i;
07323   
07324     //cout << "Package " << use->package << endl;
07325   
07326   for (i = 0; i < m; i++)
07327     {
07328       const cmt_string& fa = va[i];
07329       const cmt_string& fb = pwd[i];
07330       
07331         //cout << "  fa=" << fa << " fb=" << fb << endl;
07332       
07333       if (fa != fb) break;
07334     }
07335   
07336   cmt_string ups = "";
07337   
07338   if (i > 0)
07339     {
07340         // We have the prefix.
07341         // if we count what remains from pwd, then 
07342         // we have the number of ../ required to 
07343         // move to /<prefix>
07344       int j;
07345       
07346       for (j = i; j < pwd.size (); j++)
07347         {
07348           if (j > i) ups += fs;
07349           ups += "..";
07350         }
07351 
07352       for (j = i; j < va.size (); j++)
07353         {
07354           ups += fs;
07355           ups += va[j];
07356         }
07357     }
07358   
07359     //
07360     // Here ups contains the ../..../../aaa form
07361     // for the use->real_path or is empty when there
07362     // were no common prefix.
07363     //
07364   
07365     //if (ups != "")
07366   if ((ups != "") &&
07367       (ups.size () < path.size ()))
07368     {
07369       result = ups;
07370     }
07371   else
07372     {
07373       result = path;
07374     }
07375 
07376   return (result);
07377 }


Generated at Thu Apr 11 16:50:06 2002 for CMT by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000