1 /* 2 This file is part of the Kate project. 3 SPDX-FileCopyrightText: 2010 Christoph Cullmann <cullmann@kde.org> 4 SPDX-FileCopyrightText: 2010-2018 Dominik Haumann <dhaumann@kde.org> 5 6 SPDX-License-Identifier: LGPL-2.0-or-later 7 */ 8 9 #include "katetextbuffer.h" 10 #include <kateglobal.h> 11 12 #include <QCoreApplication> 13 main(int argc,char * argv[])14int main(int argc, char *argv[]) 15 { 16 // construct core app 17 QCoreApplication app(argc, argv); 18 19 // test mode 20 KTextEditor::EditorPrivate::enableUnitTestMode(); 21 22 // get arguments 23 QString encoding = app.arguments().at(1); 24 QString inFile = app.arguments().at(2); 25 QString outFile = app.arguments().at(3); 26 27 Kate::TextBuffer buffer(nullptr); 28 29 // set codec 30 buffer.setFallbackTextCodec(QTextCodec::codecForName("ISO 8859-15")); 31 buffer.setTextCodec(QTextCodec::codecForName(encoding.toLatin1())); 32 33 // switch to Mac EOL, this will test eol detection, as files are normal unix or dos 34 buffer.setEndOfLineMode(Kate::TextBuffer::eolMac); 35 36 // load file 37 bool encodingErrors = false; 38 bool tooLongLines = false; 39 int longestLineLoaded; 40 if (!buffer.load(inFile, encodingErrors, tooLongLines, longestLineLoaded, false) || encodingErrors) { 41 return 1; 42 } 43 44 // save file 45 if (!buffer.save(outFile)) { 46 return 1; 47 } 48 49 return 0; 50 } 51