| 9 | #include <QFileInfo> |
| 10 | |
| 11 | int main(int argc, char** argv) |
| 12 | { |
| 13 | using namespace KDevelop; |
| 14 | |
| 15 | if (argc == 1) { |
| 16 | qStdOut() << "Usage: " << argv[0] << " ORIGFILE [TMPFILE]\n\n"; |
| 17 | qStdOut() << "Where ORIGFILE represents the original location of the formatted contents,\n"; |
| 18 | qStdOut() << "and TMPFILE is used as the actual, potentially different,\n"; |
| 19 | qStdOut() << "contents of the file.\n"; |
| 20 | return EXIT_FAILURE; |
| 21 | } |
| 22 | |
| 23 | QFileInfo origFileInfo(QString::fromLocal8Bit(argv[1])); |
| 24 | if (!origFileInfo.exists()) { |
| 25 | qStdOut() << "orig file \"" << origFileInfo.absoluteFilePath() << "\" does not exist\n"; |
| 26 | return EXIT_FAILURE; |
| 27 | } |
| 28 | |
| 29 | QString origFilePath = origFileInfo.canonicalFilePath(); |
| 30 | QString tempFilePath; |
| 31 | |
| 32 | if (argc > 2) |
| 33 | tempFilePath = QFileInfo(QString::fromLocal8Bit(argv[2])).canonicalFilePath(); |
| 34 | else { |
| 35 | tempFilePath = origFilePath; |
| 36 | qStdOut() << "no temp file given, formatting the original file\n"; |
| 37 | } |
| 38 | |
| 39 | KDevFormatFile formatFile(origFilePath, tempFilePath); |
| 40 | |
| 41 | if (!formatFile.find()) |
| 42 | return EXIT_FAILURE; |
| 43 | |
| 44 | if (!formatFile.read()) |
| 45 | return EXIT_FAILURE; |
| 46 | |
| 47 | if (!formatFile.apply()) |
| 48 | return EXIT_FAILURE; |
| 49 | |
| 50 | return EXIT_SUCCESS; |
| 51 | } |