File indexing completed on 2024-05-05 04:38:45

0001 /*
0002     SPDX-FileCopyrightText: 2016 Anton Anikin <anton.anikin@htower.ru>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "kdevformatfile.h"
0008 
0009 #include <QFileInfo>
0010 
0011 int main(int argc, char** argv)
0012 {
0013     using namespace KDevelop;
0014 
0015     if (argc == 1) {
0016         qStdOut() << "Usage: " << argv[0] << " ORIGFILE [TMPFILE]\n\n";
0017         qStdOut() << "Where ORIGFILE represents the original location of the formatted contents,\n";
0018         qStdOut() << "and TMPFILE is used as the actual, potentially different,\n";
0019         qStdOut() << "contents of the file.\n";
0020         return EXIT_FAILURE;
0021     }
0022 
0023     QFileInfo origFileInfo(QString::fromLocal8Bit(argv[1]));
0024     if (!origFileInfo.exists()) {
0025         qStdOut() << "orig file \"" << origFileInfo.absoluteFilePath() << "\" does not exist\n";
0026         return EXIT_FAILURE;
0027     }
0028 
0029     QString origFilePath = origFileInfo.canonicalFilePath();
0030     QString tempFilePath;
0031 
0032     if (argc > 2)
0033         tempFilePath = QFileInfo(QString::fromLocal8Bit(argv[2])).canonicalFilePath();
0034     else {
0035         tempFilePath = origFilePath;
0036         qStdOut() << "no temp file given, formatting the original file\n";
0037     }
0038 
0039     KDevFormatFile formatFile(origFilePath, tempFilePath);
0040 
0041     if (!formatFile.find())
0042         return EXIT_FAILURE;
0043 
0044     if (!formatFile.read())
0045         return EXIT_FAILURE;
0046 
0047     if (!formatFile.apply())
0048         return EXIT_FAILURE;
0049 
0050     return EXIT_SUCCESS;
0051 }