File indexing completed on 2023-05-30 09:06:29
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2012 Torsten Rahn <tackat@kde.org> 0004 // 0005 0006 0007 #include <QCoreApplication> 0008 #include <QDataStream> 0009 #include <QFile> 0010 #include <QDebug> 0011 0012 int main(int argc, char *argv[]) 0013 { 0014 QCoreApplication app(argc, argv); 0015 0016 qDebug( " Syntax: pntdel [-i pnt-sourcefile -o pnt-targetfile -id idNumber] " ); 0017 0018 QString inputFilename("PDIFFBORDERS.PNT"); 0019 int inputIndex = app.arguments().indexOf("-i"); 0020 if (inputIndex > 0 && inputIndex + 1 < argc ) 0021 inputFilename = app.arguments().at( inputIndex + 1 ); 0022 0023 QString outputFilename("NEW.PNT"); 0024 int outputIndex = app.arguments().indexOf("-o"); 0025 if (outputIndex > 0 && outputIndex + 1 < argc ) 0026 outputFilename = app.arguments().at( outputIndex + 1 ); 0027 0028 int delIndex = -1; 0029 int idIndex = app.arguments().indexOf("-id"); 0030 if (idIndex > 0 && idIndex + 1 < argc ) 0031 delIndex = app.arguments().at( idIndex + 1 ).toInt(); 0032 0033 0034 qDebug() << "input filename:" << inputFilename; 0035 qDebug() << "output filename:" << outputFilename; 0036 qDebug() << "remove index:" << delIndex; 0037 0038 // INPUT 0039 QFile file( inputFilename ); 0040 0041 if ( file.open( QIODevice::ReadOnly ) ) { 0042 QDataStream stream( &file ); // read the data serialized from the file 0043 stream.setByteOrder( QDataStream::LittleEndian ); 0044 0045 // OUTPUT 0046 QFile data(outputFilename); 0047 0048 if (data.open(QFile::WriteOnly | QFile::Truncate)) { 0049 QDataStream out(&data); 0050 out.setByteOrder( QDataStream::LittleEndian ); 0051 0052 short header; 0053 short iLat; 0054 short iLon; 0055 0056 bool skip = false; 0057 0058 while( !stream.atEnd() ){ 0059 stream >> header >> iLat >> iLon; 0060 if ( header == delIndex ) { 0061 skip = true; 0062 } 0063 else if ( header > 5 ) 0064 skip = false; 0065 0066 if ( !skip ) 0067 out << header << iLat << iLon; 0068 } 0069 data.close(); 0070 } 0071 else { 0072 qDebug() << "ERROR: Couldn't write output file to disc!"; 0073 } 0074 file.close(); 0075 } 0076 else { 0077 qDebug() << "ERROR: Source file not found!"; 0078 } 0079 0080 app.exit(); 0081 }