#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 "cmt_awk.h"Include dependency graph for cmt_parser.cxx:

Go to the source code of this file.
Compounds | |
| class | FileScanner::actor |
| class | AwkActor |
| class | FileScanner |
| class | PackageCollector |
| class | PackageSelector |
| class | PackageViewer |
| class | SequenceRunner |
| class | StandardMacroBuilder |
Functions | |
| cmt_string | get_best_form (const CmtSystem::cmt_string_vector& pwd, const cmt_string& path) |
|
|
Definition at line 7811 of file cmt_parser.cxx. Referenced by StandardMacroBuilder::fill_for_package(), and StandardMacroBuilder::fill_for_use_root(). 07813 {
07814 static cmt_string fs = CmtSystem::file_separator ();
07815 cmt_string result;
07816
07817 /*
07818 //if (CmtSystem::getenv ("CMTTESTPREFIX") != "")
07819 {
07820 */
07821
07822 //
07823 // If there is a common prefix between
07824 // use->real_path and pwd
07825 // we have
07826 // use->real_path = /<prefix>/aaa
07827 // pwd = /<prefix>/bbb
07828 //
07829 // Then use->real_path may be expressed as:
07830 // ../..../../aaa
07831 // where ../..../../ moves up to /<prefix>
07832 //
07833 // Then we try to find the shortest between
07834 //
07835 // /<prefix> and ../..../..
07836 //
07837 cmt_string a = path;
07838
07839 CmtSystem::cmt_string_vector va;
07840
07841 va.clear ();
07842
07843 CmtSystem::split (a, fs, va);
07844
07845 int m = va.size ();
07846 if (pwd.size () < m) m = pwd.size ();
07847
07848 int i;
07849
07850 //cout << "Package " << use->package << endl;
07851
07852 for (i = 0; i < m; i++)
07853 {
07854 const cmt_string& fa = va[i];
07855 const cmt_string& fb = pwd[i];
07856
07857 //cout << " fa=" << fa << " fb=" << fb << endl;
07858
07859 if (fa != fb) break;
07860 }
07861
07862 cmt_string ups = "";
07863
07864 if (i > 0)
07865 {
07866 // We have the prefix.
07867 // if we count what remains from pwd, then
07868 // we have the number of ../ required to
07869 // move to /<prefix>
07870 int j;
07871
07872 for (j = i; j < pwd.size (); j++)
07873 {
07874 if (j > i) ups += fs;
07875 ups += "..";
07876 }
07877
07878 for (j = i; j < va.size (); j++)
07879 {
07880 ups += fs;
07881 ups += va[j];
07882 }
07883 }
07884
07885 //
07886 // Here ups contains the ../..../../aaa form
07887 // for the use->real_path or is empty when there
07888 // were no common prefix.
07889 //
07890
07891 //if (ups != "")
07892 if ((ups != "") &&
07893 (ups.size () < path.size ()))
07894 {
07895 result = ups;
07896 }
07897 else
07898 {
07899 result = path;
07900 }
07901
07902 return (result);
07903 }
|
1.2.3 written by Dimitri van Heesch,
© 1997-2000