| 91 | } |
| 92 | |
| 93 | static bool ReadWithPrefix(std::vector<std::string> const& args, |
| 94 | cmExecutionStatus& status) |
| 95 | { |
| 96 | // Make sure we have a prefix. |
| 97 | if (args.size() < 3) { |
| 98 | status.SetError("READ_WITH_PREFIX form must specify a prefix."); |
| 99 | return false; |
| 100 | } |
| 101 | |
| 102 | // Make sure the cache file exists. |
| 103 | std::string cacheFile = args[0] + "/CMakeCache.txt"; |
| 104 | if (!cmSystemTools::FileExists(cacheFile)) { |
| 105 | std::string e = "Cannot load cache file from " + cacheFile; |
| 106 | status.SetError(e); |
| 107 | return false; |
| 108 | } |
| 109 | |
| 110 | // Prepare the table of variables to read. |
| 111 | std::string const& prefix = args[2]; |
| 112 | std::set<std::string> const variablesToRead(args.begin() + 3, args.end()); |
| 113 | |
| 114 | // Read the cache file. |
| 115 | cmsys::ifstream fin(cacheFile.c_str()); |
| 116 | |
| 117 | cmMakefile& mf = status.GetMakefile(); |
| 118 | |
| 119 | // This is a big hack read loop to overcome a buggy ifstream |
| 120 | // implementation on HP-UX. This should work on all platforms even |
| 121 | // for small buffer sizes. |
| 122 | int const bufferSize = 4096; |
| 123 | char buffer[bufferSize]; |
| 124 | std::string line; |
| 125 | while (fin) { |
| 126 | // Read a block of the file. |
| 127 | fin.read(buffer, bufferSize); |
| 128 | if (fin.gcount()) { |
| 129 | // Parse for newlines directly. |
| 130 | char const* i = buffer; |
| 131 | char const* end = buffer + fin.gcount(); |
| 132 | while (i != end) { |
| 133 | char const* begin = i; |
| 134 | while (i != end && *i != '\n') { |
| 135 | ++i; |
| 136 | } |
| 137 | if (i == begin || *(i - 1) != '\r') { |
| 138 | // Include this portion of the line. |
| 139 | line += std::string(begin, i - begin); |
| 140 | } else { |
| 141 | // Include this portion of the line. |
| 142 | // Don't include the \r in a \r\n pair. |
| 143 | line += std::string(begin, i - 1 - begin); |
| 144 | } |
| 145 | if (i != end) { |
| 146 | // Completed a line. |
| 147 | CheckLine(mf, prefix, variablesToRead, line.c_str()); |
| 148 | line.clear(); |
| 149 | |
| 150 | // Skip the newline character. |
no test coverage detected
searching dependent graphs…