scandsp/src/dspparser.cxx
// ===========================================================================
// static member function
// Visual Studio is permissive regarding the ocurrence of \..\..
// in source file names.  If the current directory is the root, then
// .. also refers to the root.
//
// This function elminates such anomalous use of .. from a file name,
// so that it can be used readily during the model build.  The 'dir'
// parameter is the absolute pathname of the directory within which
// the name 'file' is interpreted.
//
static member function
Visual Studio is permissive regarding the ocurrence of \..\
in source file names.  If the current directory is the root, then
also refers to the root.

This function elminates such anomalous use of .. from a file name,
so that it can be used readily during the model build.  The 'dir'
parameter is the absolute pathname of the directory within which
the name 'file' is interpreted.
static member function Visual Studio is permissive regarding the ocurrence of \ .. \ in source file names . If the current directory is the root then also refers to the root . This function elminates such anomalous use of .. from a file name so that it can be used readily during the model build . The ' dir ' parameter is the absolute pathname of the directory within which the name ' file ' is interpreted .
void DSPParser::filterSpuriousDotDots(const string &dir, string &file)
{
    if (!isAbsolute(file.c_str()) && isAbsolute(dir.c_str())) {
        int dir_nesting = 0;
	bool at_separator = false;
	int dir_len = dir.length();
	for (int i = 0; i < dir_len; i += 1) {
	    char ch = dir.at(i);
	    if (isPathSep(ch)) {
		at_separator = true;
	    }
	    else if (at_separator) {
		at_separator = false;
		dir_nesting += 1;
	    }
	}
	at_separator = true;
	int index = 0;
	while (index < file.length()) {
	    if (at_separator && file.length() > index + 3
		&& file.at(index) == '.'
		&& file.at(index + 1) == '.'
	        && isPathSep(file.at(index + 2))) {
		if (dir_nesting == 0) {
		    file.erase(index, 3);
		}
		else {
		    dir_nesting -= 1;
		    index += 3;
		}
	    }
	    else if (at_separator && file.length() > index + 2
		&& file.at(index) == '.'
	        && isPathSep(file.at(index + 1))) {
	        index += 2;
	    }
	    else {
		if (isPathSep(file.at(index))) {
		    at_separator = true;
		}
		else if (at_separator) {
		    at_separator = false;
		    dir_nesting += 1;
		}
		index += 1;
	    }
	}		
    }
}
void DSPParser :: filterSpuriousDotDots ( const string & dir , string & file ) { if ( ! isAbsolute ( file . c_str ( ) ) && isAbsolute ( dir . c_str ( ) ) ) { int dir_nesting = 0 ; bool at_separator = false ; int dir_len = dir . length ( ) ; for ( int i = 0 ; i < dir_len ; i += 1 ) { char ch = dir . at ( i ) ; if ( isPathSep ( ch ) ) { at_separator = true ; } else if ( at_separator ) { at_separator = false ; dir_nesting += 1 ; } } at_separator = true ; int index = 0 ; while ( index < file . length ( ) ) { if ( at_separator && file . length ( ) > index + 3 && file . at ( index ) == ' ' && file . at ( index + 1 ) == ' ' && isPathSep ( file . at ( index + 2 ) ) ) { if ( dir_nesting == 0 ) { file . erase ( index , 3 ) ; } else { dir_nesting -= 1 ; index += 3 ; } } else if ( at_separator && file . length ( ) > index + 2 && file . at ( index ) == ' ' && isPathSep ( file . at ( index + 1 ) ) ) { index += 2 ; } else { if ( isPathSep ( file . at ( index ) ) ) { at_separator = true ; } else if ( at_separator ) { at_separator = false ; dir_nesting += 1 ; } index += 1 ; } } } }
static member function
Visual Studio is permissive regarding the ocurrence of \..\..
in source file names.
static member function Visual Studio is permissive regarding the ocurrence of \ .. \ .. in source file names .
// Count the number of nested directory names in dir. // Now go through 'file', tracking the directory nesting // and eliminating occurrences of .. which go too far.