scanjpr/Windows/JprParseMain.cpp
// Return true if any file in the current directory is a valid
// .java source file of the package given by the pkgs list.
Return true if any file in the current directory is a valid
.java source file of the package given by the pkgs list.
Return true if any file in the current directory is a valid . java source file of the package given by the pkgs list .
static bool dir_valid_in_class_path(string dir, vector<string> &pkgs, string &reason)
{
    WIN32_FIND_DATA FileData; 
    HANDLE hSearch; 
    char *file_pattern = new char[dir.size() + 10];
    strcpy(file_pattern, dir.c_str());
    PathAppend(file_pattern, "*.java");
    hSearch = FindFirstFile(file_pattern, &FileData);
    bool found_valid = false;
    if (hSearch != INVALID_HANDLE_VALUE) {
	for (;;) { 
	    char *file_path = new char[dir.size() + strlen(FileData.cFileName) + 4];
	    strcpy(file_path, dir.c_str());
	    PathAppend(file_path, FileData.cFileName);
	    found_valid = is_of_pkg(file_path, pkgs, false);
	    if (found_valid) {
		reason = "Found ";
		reason.append(file_path);
		reason.append(".");
	    }
	    else {
		reason.append(", examined ");
		reason.append(file_path);
	    }
	    delete [] file_path;
	    if (found_valid) {
		break;
	    }
	    if (!FindNextFile(hSearch, &FileData)) {
		break;
	    }
	} 
	FindClose(hSearch);
    }
    delete [] file_pattern;
    if (found_valid) {
	return true;
    }
    file_pattern = new char[dir.size() + 5];
    strcpy(file_pattern, dir.c_str());
    PathAppend(file_pattern, "*.*");
    hSearch = FindFirstFile(file_pattern, &FileData);
    if (hSearch != INVALID_HANDLE_VALUE) {
	for (;;) { 
	    if (FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY
		&& strcmp(FileData.cFileName, ".") != 0
		&& strcmp(FileData.cFileName, "..") != 0) {
		pkgs.push_back(string(FileData.cFileName));
		char *nested_dir = new char[dir.size() + strlen(FileData.cFileName) + 4];
		strcpy(nested_dir, dir.c_str());
		PathAppend(nested_dir, FileData.cFileName);
		found_valid = dir_valid_in_class_path(nested_dir, pkgs, reason);
		pkgs.pop_back();
		delete [] nested_dir;
		if (found_valid) {
		    break;
		}
	    }
	    if (!FindNextFile(hSearch, &FileData)) {
		break;
	    }
	} 
	FindClose(hSearch);
    }
    delete [] file_pattern;
    return found_valid;
}
static bool dir_valid_in_class_path ( string dir , vector < string > & pkgs , string & reason ) { WIN32_FIND_DATA FileData ; HANDLE hSearch ; char * file_pattern = new char [ dir . size ( ) + 10 ] ; strcpy ( file_pattern , dir . c_str ( ) ) ; PathAppend ( file_pattern , " " ) ; hSearch = FindFirstFile ( file_pattern , & FileData ) ; bool found_valid = false ; if ( hSearch != INVALID_HANDLE_VALUE ) { for ( ; ; ) { char * file_path = new char [ dir . size ( ) + strlen ( FileData . cFileName ) + 4 ] ; strcpy ( file_path , dir . c_str ( ) ) ; PathAppend ( file_path , FileData . cFileName ) ; found_valid = is_of_pkg ( file_path , pkgs , false ) ; if ( found_valid ) { reason = " " ; reason . append ( file_path ) ; reason . append ( " " ) ; } else { reason . append ( " " ) ; reason . append ( file_path ) ; } delete [ ] file_path ; if ( found_valid ) { break ; } if ( ! FindNextFile ( hSearch , & FileData ) ) { break ; } } FindClose ( hSearch ) ; } delete [ ] file_pattern ; if ( found_valid ) { return true ; } file_pattern = new char [ dir . size ( ) + 5 ] ; strcpy ( file_pattern , dir . c_str ( ) ) ; PathAppend ( file_pattern , " " ) ; hSearch = FindFirstFile ( file_pattern , & FileData ) ; if ( hSearch != INVALID_HANDLE_VALUE ) { for ( ; ; ) { if ( FileData . dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY && strcmp ( FileData . cFileName , " " ) != 0 && strcmp ( FileData . cFileName , " " ) != 0 ) { pkgs . push_back ( string ( FileData . cFileName ) ) ; char * nested_dir = new char [ dir . size ( ) + strlen ( FileData . cFileName ) + 4 ] ; strcpy ( nested_dir , dir . c_str ( ) ) ; PathAppend ( nested_dir , FileData . cFileName ) ; found_valid = dir_valid_in_class_path ( nested_dir , pkgs , reason ) ; pkgs . pop_back ( ) ; delete [ ] nested_dir ; if ( found_valid ) { break ; } } if ( ! FindNextFile ( hSearch , & FileData ) ) { break ; } } FindClose ( hSearch ) ; } delete [ ] file_pattern ; return found_valid ; }
Return true if any file in the current directory is a valid
.java source file of the package given by the pkgs list.
Return true if any file in the current directory is a valid . java source file of the package given by the pkgs list .
// Search for .java files in the current directory.  // FileData.cFileName is the local (relative) name. // Close the search handle.  // Search nested directories. // FileData.cFileName is the local (relative) name. // Close the search handle. 