bool WaypointReaderCompeGPS::VerifyFormat(TLineReader &reader) { const TCHAR *line = reader.ReadLine(); if (line == NULL) return false; // Ignore optional line with encoding information if (StringStartsWith(line, _T("B "))) if ((line = reader.ReadLine()) == NULL) return false; return StringStartsWith(line, _T("G WGS 84")); }
/** * Parses the data provided by the airfield details file handle */ static void ParseAirfieldDetails(Waypoints &way_points, TLineReader &reader, OperationEnvironment &operation) { tstring details; std::vector<tstring> files_external, files_embed; TCHAR name[201]; const TCHAR *filename; name[0] = 0; bool in_details = false; int i; const long filesize = std::max(reader.GetSize(), 1l); operation.SetProgressRange(100); TCHAR *line; while ((line = reader.ReadLine()) != NULL) { if (line[0] == _T('[')) { // Look for start if (in_details) SetAirfieldDetails(way_points, name, details, files_external, files_embed); details.clear(); files_external.clear(); files_embed.clear(); // extract name for (i = 1; i < 201; i++) { if (line[i] == _T(']')) break; name[i - 1] = line[i]; } name[i - 1] = 0; in_details = true; operation.SetProgressPosition(reader.Tell() * 100 / filesize); } else if ((filename = StringAfterPrefixCI(line, _T("image="))) != NULL) { files_embed.emplace_back(filename); } else if ((filename = StringAfterPrefixCI(line, _T("file="))) != NULL) { #ifdef ANDROID files_external.emplace_back(filename); #endif } else { // append text to details string if (!StringIsEmpty(line)) { details += line; details += _T('\n'); } } } if (in_details) SetAirfieldDetails(way_points, name, details, files_external, files_embed); }
static void LoadChecklist() { nLists = 0; free(ChecklistText[0]); ChecklistText[0] = NULL; free(ChecklistTitle[0]); ChecklistTitle[0] = NULL; TLineReader *reader = OpenDataTextFile(_T(XCSCHKLIST)); if (reader == NULL) { addChecklist(_("No checklist loaded"), _("Create xcsoar-checklist.txt")); return; } StaticString<MAXDETAILS> Details; TCHAR Name[100]; bool inDetails = false; int i; Details.clear(); Name[0] = 0; TCHAR *TempString; while ((TempString = reader->ReadLine()) != NULL) { // Look for start if (TempString[0] == '[') { if (inDetails) { addChecklist(Name, Details); Details.clear(); Name[0] = 0; } // extract name for (i = 1; i < MAXTITLE; i++) { if (TempString[i] == ']') break; Name[i - 1] = TempString[i]; } Name[i - 1] = 0; inDetails = true; } else { // append text to details string Details.append(TempString); Details.Append(_T('\n')); } } delete reader; if (inDetails) { addChecklist(Name, Details); } }
bool WaypointReaderOzi::VerifyFormat(TLineReader &reader) { const TCHAR *line = reader.ReadLine(); if (line == nullptr) return false; return StringStartsWith(line, _T("OziExplorer Waypoint File")); }
bool WaypointReaderFS::VerifyFormat(TLineReader &reader) { const TCHAR *line = reader.ReadLine(); if (line == nullptr) return false; return StringStartsWith(line, _T("$FormatUTM")) || StringStartsWith(line, _T("$FormatGEO")); }
bool AirspaceParser::Parse(TLineReader &reader, OperationEnvironment &operation) { bool ignore = false; // Create and init ProgressDialog operation.SetProgressRange(1024); const long file_size = reader.GetSize(); TempAirspaceType temp_area; AirspaceFileType filetype = AFT_UNKNOWN; TCHAR *line; // Iterate through the lines for (unsigned line_num = 1; (line = reader.ReadLine()) != NULL; line_num++) { // Skip empty line if (StringIsEmpty(line)) continue; if (filetype == AFT_UNKNOWN) { filetype = DetectFileType(line); if (filetype == AFT_UNKNOWN) continue; } // Parse the line if (filetype == AFT_OPENAIR) if (!ParseLine(airspaces, line, temp_area) && !ShowParseWarning(line_num, line, operation)) return false; if (filetype == AFT_TNP) if (!ParseLineTNP(airspaces, line, temp_area, ignore) && !ShowParseWarning(line_num, line, operation)) return false; // Update the ProgressDialog if ((line_num & 0xff) == 0) operation.SetProgressPosition(reader.Tell() * 1024 / file_size); } if (filetype == AFT_UNKNOWN) { operation.SetErrorMessage(_("Unknown airspace filetype")); return false; } // Process final area (if any) if (!temp_area.points.empty()) temp_area.AddPolygon(airspaces); return true; }
void WaypointReaderBase::Parse(Waypoints &way_points, TLineReader &reader, OperationEnvironment &operation) { const long filesize = std::max(reader.GetSize(), 1l); operation.SetProgressRange(100); // Read through the lines of the file TCHAR *line; for (unsigned i = 0; (line = reader.ReadLine()) != nullptr; i++) { // and parse them ParseLine(line, i, way_points); if ((i & 0x3f) == 0) operation.SetProgressPosition(reader.Tell() * 100 / filesize); } }
void LoadFlarmNameFile(TLineReader &reader, FlarmNameDatabase &db) { TCHAR *line; while ((line = reader.ReadLine()) != NULL) { TCHAR *endptr; FlarmId id = FlarmId::Parse(line, &endptr); if (!id.IsDefined()) /* ignore malformed records */ continue; if (endptr > line && endptr[0] == _T('=') && endptr[1] != _T('\0')) { TCHAR *Name = endptr + 1; TrimRight(Name); if (!db.Set(id, Name)) break; // cant add anymore items ! } } }
void StatusMessageList::LoadFile(TLineReader &reader) { // Init first entry StatusMessage current; current.Clear(); /* Read from the file */ TCHAR *buffer; const TCHAR *key, *value; while ((buffer = reader.ReadLine()) != NULL) { // Check valid line? If not valid, assume next record (primative, but works ok!) if (*buffer == _T('#') || !parse_assignment(buffer, key, value)) { // Global counter (only if the last entry had some data) if (!current.IsEmpty()) { list.append(current); current.Clear(); if (list.full()) break; } } else { if (_tcscmp(key, _T("key")) == 0) { if (current.key == NULL) current.key = UnescapeBackslash(value); } else if (_tcscmp(key, _T("sound")) == 0) { if (current.sound == NULL) current.sound = UnescapeBackslash(value); } else if (_tcscmp(key, _T("delay")) == 0) { TCHAR *endptr; unsigned ms = ParseUnsigned(value, &endptr); if (endptr > value) current.delay_ms = ms; } else if (_tcscmp(key, _T("hide")) == 0) { if (_tcscmp(value, _T("yes")) == 0) current.visible = false; } } } if (!current.IsEmpty()) list.append(current); }
void ParseInputFile(InputConfig &config, TLineReader &reader) { // TODO code - Safer sizes, strings etc - use C++ (can scanf restrict length?) // Multiple modes (so large string) EventBuilder current; current.clear(); int line = 0; // Read from the file TCHAR *buffer; while ((buffer = reader.ReadLine()) != NULL) { TrimRight(buffer); line++; const TCHAR *key, *value; // experimental: if the first line is "#CLEAR" then the whole default config is cleared // and can be overwritten by file if (line == 1 && StringIsEqual(buffer, _T("#CLEAR"))) { config.SetDefaults(); } else if (buffer[0] == _T('\0')) { // Check valid line? If not valid, assume next record (primative, but works ok!) // General checks before continue... current.commit(config, line); // Clear all data. current.clear(); } else if (StringIsEmpty(buffer) || buffer[0] == _T('#')) { // Do nothing - we probably just have a comment line // NOTE: Do NOT display buffer to user as it may contain an invalid stirng ! } else if (parse_assignment(buffer, key, value)) { if (StringIsEqual(key, _T("mode"))) { current.mode = value; } else if (StringIsEqual(key, _T("type"))) { current.type = value; } else if (StringIsEqual(key, _T("data"))) { current.data = value; } else if (StringIsEqual(key, _T("event"))) { if (_tcslen(value) < 256) { TCHAR d_event[256] = _T(""); TCHAR d_misc[256] = _T(""); int ef; #if defined(__BORLANDC__) memset(d_event, 0, sizeof(d_event)); memset(d_misc, 0, sizeof(d_event)); if (_tcschr(value, ' ') == NULL) { _tcscpy(d_event, value); } else { #endif ef = _stscanf(value, _T("%[^ ] %[A-Za-z0-9 \\/().,]"), d_event, d_misc); #if defined(__BORLANDC__) } #endif if ((ef == 1) || (ef == 2)) { // TODO code: Consider reusing existing identical events pt2Event event = InputEvents::findEvent(d_event); if (event) { TCHAR *allocated = UnescapeBackslash(d_misc); current.event_id = config.AppendEvent(event, allocated, current.event_id); /* not freeing the string, because InputConfig::AppendEvent() stores the string point without duplicating it; strictly speaking, this is a memory leak, but the input file is only loaded once at startup, so this is acceptable; in return, we don't have to duplicate the hard-coded defaults, which saves some memory */ //free(allocated); } else { LogStartUp(_T("Invalid event type: %s at %i"), d_event, line); } } else { LogFormat("Invalid event type at %i", line); } } } else if (StringIsEqual(key, _T("label"))) { current.label = value; } else if (StringIsEqual(key, _T("location"))) { current.location = ParseUnsigned(value); } else { LogStartUp(_T("Invalid key/value pair %s=%s at %i"), key, value, line); } } else { LogFormat("Invalid line at %i", line); } } current.commit(config, line); }