| 177 | |
| 178 | // |
| 179 | static std::string FetchLine(std::string filename, int lineno, int context) { |
| 180 | std::ostringstream ret; |
| 181 | std::string line; |
| 182 | |
| 183 | std::ifstream f(filename); |
| 184 | if (!f) { |
| 185 | return " (file/line not available)\n"; |
| 186 | } |
| 187 | |
| 188 | for (int curr = 1; std::getline(f, line) && curr <= lineno + context; |
| 189 | curr++) { |
| 190 | if (std::abs(curr - lineno) <= context) { |
| 191 | ret << " " << (curr == lineno ? "->" : " ") << " " << curr << ": " |
| 192 | << line << std::endl; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | return ret.str(); |
| 197 | } |
| 198 | |
| 199 | // Run an external command and return its standard output. |
| 200 | static std::string RunCommand(std::string cmd) { |