3 XCSoar Glide Computer - http://www.xcsoar.org/
4 Copyright (C) 2000-2013 The XCSoar Project
5 A detailed list of copyright holders can be found in the file "AUTHORS".
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "Logger/GRecord.hpp"
24 #include "OS/Args.hpp"
25 #include "IO/FileTransaction.hpp"
26 #include "IO/FileLineReader.hpp"
27 #include "IO/TextWriter.hpp"
34 FixGRecord(NLineReader
&reader
, TextWriter
&writer
)
39 char digest
[GRecord::DIGEST_LENGTH
+ 1];
40 grecord
.GetDigest(digest
);
43 while ((line
= reader
.ReadLine()) != nullptr) {
47 if (memcmp(line
, "HFFTYFRTYPE:XCSOAR,XCSOAR ", 26) == 0) {
48 char *v
= strstr(line
+ 25, " 6.5 ");
50 static char buffer
[1024], *p
= buffer
;
52 size_t n
= v
+ 4 - line
;
65 grecord
.AppendRecordToBuffer(line
);
67 if (!writer
.WriteLine(line
))
71 grecord
.FinalizeBuffer();
72 grecord
.WriteTo(writer
);
77 FixGRecord(NLineReader
&reader
, const TCHAR
*dest_path
)
79 TextWriter
writer(dest_path
);
80 return writer
.IsOpen() && FixGRecord(reader
, writer
) && writer
.Flush();
84 main(int argc
, char **argv
)
86 Args
args(argc
, argv
, "FILE.igc");
87 tstring path
= args
.ExpectNextT();
94 if (!grecord
.VerifyGRecordInFile(path
.c_str())) {
95 fprintf(stderr
, "Invalid G record\n");
100 printf("Valid G record found\n");
102 FileTransaction
transaction(path
.c_str());
105 FileLineReaderA
reader(path
.c_str());
106 if (reader
.error()) {
107 fprintf(stderr
, "Failed to open input file\n");
111 if (!FixGRecord(reader
, transaction
.GetTemporaryPath())) {
112 fprintf(stderr
, "Failed to write output file\n");
117 if (!transaction
.Commit()) {
118 fprintf(stderr
, "Failed to commit output file\n");
122 printf("New G record written\n");