#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:
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) |
|
Definition at line 7315 of file cmt_parser.cxx. Referenced by Cmt::set_standard_macros(). 07317 { 07318 static cmt_string fs = CmtSystem::file_separator (); 07319 cmt_string result; 07320 07321 /* 07322 //if (CmtSystem::getenv ("CMTTESTPREFIX") != "") 07323 { 07324 */ 07325 07326 // 07327 // If there is a common prefix between 07328 // use->real_path and pwd 07329 // we have 07330 // use->real_path = /<prefix>/aaa 07331 // pwd = /<prefix>/bbb 07332 // 07333 // Then use->real_path may be expressed as: 07334 // ../..../../aaa 07335 // where ../..../../ moves up to /<prefix> 07336 // 07337 // Then we try to find the shortest between 07338 // 07339 // /<prefix> and ../..../.. 07340 // 07341 cmt_string a = path; 07342 07343 CmtSystem::cmt_string_vector va; 07344 07345 va.clear (); 07346 07347 CmtSystem::split (a, fs, va); 07348 07349 int m = va.size (); 07350 if (pwd.size () < m) m = pwd.size (); 07351 07352 int i; 07353 07354 //cout << "Package " << use->package << endl; 07355 07356 for (i = 0; i < m; i++) 07357 { 07358 const cmt_string& fa = va[i]; 07359 const cmt_string& fb = pwd[i]; 07360 07361 //cout << " fa=" << fa << " fb=" << fb << endl; 07362 07363 if (fa != fb) break; 07364 } 07365 07366 cmt_string ups = ""; 07367 07368 if (i > 0) 07369 { 07370 // We have the prefix. 07371 // if we count what remains from pwd, then 07372 // we have the number of ../ required to 07373 // move to /<prefix> 07374 int j; 07375 07376 for (j = i; j < pwd.size (); j++) 07377 { 07378 if (j > i) ups += fs; 07379 ups += ".."; 07380 } 07381 07382 for (j = i; j < va.size (); j++) 07383 { 07384 ups += fs; 07385 ups += va[j]; 07386 } 07387 } 07388 07389 // 07390 // Here ups contains the ../..../../aaa form 07391 // for the use->real_path or is empty when there 07392 // were no common prefix. 07393 // 07394 07395 //if (ups != "") 07396 if ((ups != "") && 07397 (ups.size () < path.size ())) 07398 { 07399 result = ups; 07400 } 07401 else 07402 { 07403 result = path; 07404 } 07405 07406 return (result); 07407 } |