![]() ![]() |
![]() |
File: [Pegasus] / pegasus / src / utils / mu / Dependency.cpp
(download)
Revision: 1.4, Wed Jul 11 21:54:19 2007 UTC (16 years, 11 months ago) by runfang.zhou Branch: MAIN CVS Tags: TASK_PEP328_SOLARIS_NEVADA_PORT, TASK-PEP328_SOLARIS_NEVADA_PORT-root, TASK-PEP328_SOLARIS_NEVADA_PORT-branch, TASK-PEP328_SOLARIS_IX86_CC_PORT-root, TASK-PEP328_SOLARIS_IX86_CC_PORT-branch-v2, TASK-PEP328_SOLARIS_IX86_CC_PORT-branch, TASK-PEP305_VXWORKS-root, TASK-PEP305_VXWORKS-branch-pre-solaris-port, TASK-PEP305_VXWORKS-branch-post-solaris-port, TASK-PEP305_VXWORKS-branch-beta2, TASK-PEP305_VXWORKS-branch, TASK-PEP305_VXWORKS-2008-10-23, TASK-BUG7240-root, TASK-BUG7240-branch, TASK-BUG7146_SqlRepositoryPrototype-root, TASK-BUG7146_SqlRepositoryPrototype-merged_out_to_branch, TASK-BUG7146_SqlRepositoryPrototype-merged_out_from_trunk, TASK-BUG7146_SqlRepositoryPrototype-merged_in_to_trunk, TASK-BUG7146_SqlRepositoryPrototype-merged_in_from_branch, TASK-BUG7146_SqlRepositoryPrototype-branch, RELEASE_2_8_2-RC1, RELEASE_2_8_2, RELEASE_2_8_1-RC1, RELEASE_2_8_1, RELEASE_2_8_0_BETA, RELEASE_2_8_0-RC2, RELEASE_2_8_0-RC1, RELEASE_2_8_0-FC, RELEASE_2_8_0, RELEASE_2_8-root, RELEASE_2_8-branch, RELEASE_2_7_3-RC1, RELEASE_2_7_3, RELEASE_2_7_2-RC1, RELEASE_2_7_2, RELEASE_2_7_1-RC1, RELEASE_2_7_1, RELEASE_2_7_0-RC1, RELEASE_2_7_0-BETA, RELEASE_2_7_0, RELEASE_2_7-root, RELEASE_2_7-branch, RELEASE_2_6_1 Changes since 1.3: +17 -88 lines BUG#: 6624 TITLE: Improve 'mu' to resolve relative path DESCRIPTION: This is further 'mu' improvement. So 'mu' can resolve relative path in both header files and in source files. |
//%2006//////////////////////////////////////////////////////////////////////// // // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems. // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.; // IBM Corp.; EMC Corporation, The Open Group. // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.; // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group. // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.; // EMC Corporation; VERITAS Software Corporation; The Open Group. // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.; // EMC Corporation; Symantec Corporation; The Open Group. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // //============================================================================== // //%///////////////////////////////////////////////////////////////////////////// #include "Files.h" #include <utils/mu/Dependency.h> #include <cstdio> #include <cstddef> #include <Pegasus/Common/PegasusAssert.h> void ErrorExit(const char* programName, const string& message) { fprintf(stderr, "%s: Error: %s\n", programName, message.c_str()); exit(1); } void Warning(const char* programName, string& message) { fprintf(stderr, "%s: Warning: %s\n", programName, message.c_str()); } void PrintVector(const vector<string>& v) { for (size_t i = 0; i < v.size(); i++) { printf("%s\n", v[i].c_str()); } } //////////////////////////////////////////////////////////////////////////////// // // GetIncludePath(): // // Get the include path from an #include directive. // //////////////////////////////////////////////////////////////////////////////// bool GetIncludePath( const string& fileName, size_t lineNumber, const char* line, string& path, char& openDelim) { if (line[0] == '#') { const char* p = line + 1; // Skip whitespace: while (isspace(*p)) { p++; } // Check for "include" keyword: const char INCLUDE[] = "include"; if (memcmp(p, INCLUDE, sizeof(INCLUDE) - 1) == 0) { // Advance past "include" keyword: p += sizeof(INCLUDE) - 1; // Skip whitespace: while (isspace(*p)) { p++; } // Expect opening '"' or '<': if (*p != '"' && *p != '<') { return false; #if 0 // ATTN: noticed that "#include /**/ <path>" style not // handle so just returning silently when this situration // encountered! char message[64]; sprintf(message, "corrupt #include directive at %s(%d)", fileName.c_str(), lineNumber); ErrorExit(message); #endif } openDelim = *p++; // Skip whitespace: while (isspace(*p)) { p++; } // Store pointer to start of path: const char* start = p; // Look for closing '"' or '>': while (*p && *p != '"' && *p != '>') { p++; } if (*p != '"' && *p != '>') { return false; #if 0 char message[64]; sprintf(message, "corrupt #include directive at %s(%d)", fileName.c_str(), lineNumber); ErrorExit(message); #endif } // Find end of the path (go backwards, skipping whitespace // between the closing delimiter and the end of the path: if (p == start) { return false; #if 0 char message[64]; sprintf(message, "empty path in #include directive at %s(%d)", fileName.c_str(), lineNumber); ErrorExit(message); #endif } p--; while (isspace(*p)) { p--; } if (p == start) { return false; #if 0 char message[64]; sprintf(message, "empty path in #include directive at %s(%d)", fileName.c_str(), lineNumber); ErrorExit(message); #endif } path.assign(start, p - start + 1); return true; } } return false; } FILE* FindFile( const vector<string>& includePath, const string& prependDir, const string& path, char openDelim, string& fullPath) { // If the opening delimiter was '"', then check the current // directory first: if (openDelim == '"') { if (prependDir.size()) { GetFileFullPath(prependDir, path, fullPath); } else { fullPath = path; } FILE* fp = fopen(fullPath.c_str(), "rb"); if (fp) { return fp; } } // Search the include path for the file: vector<string>::const_iterator first = includePath.begin(); vector<string>::const_iterator last = includePath.end(); for (; first != last; first++) { fullPath = *first; fullPath += '/'; fullPath += path; FILE* fp = fopen(fullPath.c_str(), "rb"); if (fp) { return fp; } } return NULL; } void ProcessFile( const string& fileName, const char* programName, FILE* fp, const vector<string>& includePath, string& prependDir, size_t nesting, set<string, less<string> >& cache, PrintFunc printFunc, bool& warn) { printFunc(fileName); if (nesting == 100) { ErrorExit(programName, "Infinite include file recursion? nesting level reached 100"); } PEGASUS_ASSERT(fp != NULL); // For each line in the file: char line[4096]; size_t lineNumber = 1; for (; fgets(line, sizeof(line), fp) != NULL; lineNumber++) { // Check for include directive: string path; char openDelim; if (line[0] == '#' && GetIncludePath(fileName, lineNumber, line, path, openDelim)) { // ATTN: danger! not distinguising between angle brack delimited // and quote delimited paths! set<string, less<string> >::const_iterator pos = cache.find(path); if (pos != cache.end()) { continue; } cache.insert(path); string fullPath; FILE* fp = FindFile(includePath, prependDir, path, openDelim, fullPath); if (!fp) { if (warn) { string message = "header file not found: " + path + " included from " + fileName; Warning(programName, message); } } else { ProcessFile(fullPath,programName, fp, includePath, prependDir, nesting + 1, cache, printFunc, warn); } } } fclose(fp); }
No CVS admin address has been configured |
Powered by ViewCVS 0.9.2 |