bool WaypointReaderCompeGPS::VerifyFormat(TLineReader &reader) const { TCHAR* line = reader.read(); if (line == NULL) return false; // Ignore optional line with encoding information if (line[0] == _T('B') && line[1] == _T(' ')) if ((line = reader.read()) == NULL) return false; return (_tcsstr(line, _T("G WGS 84")) == line); }
void StatusMessageList::LoadFile(TLineReader &reader) { int ms; // Found ms for delay const TCHAR **location; // Where to put the data bool some_data; // Did we find some in the last loop... // Init first entry _init_Status(StatusMessageData_Size); some_data = false; /* Read from the file */ TCHAR *buffer; const TCHAR *key, *value; while ((StatusMessageData_Size < MAXSTATUSMESSAGECACHE) && (buffer = reader.read()) != 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 (some_data) { StatusMessageData_Size++; some_data = false; _init_Status(StatusMessageData_Size); } } else { location = NULL; if (_tcscmp(key, _T("key")) == 0) { some_data = true; // Success, we have a real entry location = &StatusMessageData[StatusMessageData_Size].key; } else if (_tcscmp(key, _T("sound")) == 0) { StatusMessageData[StatusMessageData_Size].doSound = true; location = &StatusMessageData[StatusMessageData_Size].sound; } else if (_tcscmp(key, _T("delay")) == 0) { TCHAR *endptr; ms = _tcstol(value, &endptr, 10); if (endptr > value) StatusMessageData[StatusMessageData_Size].delay_ms = ms; } else if (_tcscmp(key, _T("hide")) == 0) { if (_tcscmp(value, _T("yes")) == 0) StatusMessageData[StatusMessageData_Size].doStatus = false; } // Do we have somewhere to put this && // is it currently empty ? (prevent lost at startup) if (location && (_tcscmp(*location, _T("")) == 0)) { // TODO code: this picks up memory lost from no entry, but not duplicates - fix. if (*location) { // JMW fix memory leak free((void*)*location); } *location = StringMallocParse(value); } } } // How many we really got (blank next just in case) StatusMessageData_Size++; _init_Status(StatusMessageData_Size); }
/** * 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; long filesize = std::max(reader.size(), 1l); operation.SetProgressRange(100); TCHAR *line; while ((line = reader.read()) != 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.push_back(filename); } else if ((filename = StringAfterPrefixCI(line, _T("file="))) != NULL) { #ifdef ANDROID files_external.push_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\n")); return; } TCHAR Details[MAXDETAILS]; TCHAR Name[100]; bool inDetails = false; int i; Details[0] = 0; Name[0] = 0; TCHAR *TempString; while ((TempString = reader->read()) != NULL) { // Look for start if (TempString[0] == '[') { if (inDetails) { addChecklist(Name, Details); Details[0] = 0; 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 _tcsncat(Details, TempString, MAXDETAILS - 2); _tcscat(Details, _T("\n")); // TODO code: check the string is not too long } } delete reader; if (inDetails) { addChecklist(Name, Details); } }
bool WaypointReaderFS::VerifyFormat(TLineReader &reader) { TCHAR* line = reader.read(); if (line == NULL) return false; return StringStartsWith(line, _T("$FormatUTM")) || StringStartsWith(line, _T("$FormatGEO")); }
bool WaypointReaderFS::VerifyFormat(TLineReader &reader) const { TCHAR* line = reader.read(); if (line == NULL) return false; return (_tcsstr(line, _T("$FormatUTM")) == line || _tcsstr(line, _T("$FormatGEO")) == line); }
/** * Parses the data provided by the airfield details file handle */ static void ParseAirfieldDetails(Waypoints &way_points, TLineReader &reader) { tstring Details; TCHAR Name[201]; Name[0] = 0; bool inDetails = false; int i; long filesize = std::max(reader.size(), 1l); ProgressGlue::SetRange(100); TCHAR *TempString; while ((TempString = reader.read()) != NULL) { if (TempString[0] == '[') { // Look for start if (inDetails) SetAirfieldDetails(way_points, Name, Details); Details.clear(); // extract name for (i = 1; i < 201; i++) { if (TempString[i] == ']') break; Name[i - 1] = TempString[i]; } Name[i - 1] = 0; inDetails = true; ProgressGlue::SetValue(reader.tell() * 100 / filesize); } else { // append text to details string if (!string_is_empty(TempString)) { Details += TempString; Details += _T('\n'); } } } if (inDetails) { SetAirfieldDetails(way_points, Name, Details); Details.clear(); } }
static void LoadSecondaryFile(TLineReader &reader) { TCHAR *line; while ((line = reader.read()) != NULL) { TCHAR *endptr; FlarmId id; id.parse(line, &endptr); if (endptr > line && endptr[0] == _T('=') && endptr[1] != _T('\0')) { TCHAR *Name = endptr + 1; TrimRight(Name); if (!FlarmDetails::AddSecondaryItem(id, Name)) break; // cant add anymore items ! } } }
void WaypointReaderBase::Parse(Waypoints &way_points, TLineReader &reader, OperationEnvironment &operation) { long filesize = std::max(reader.size(), 1l); operation.SetProgressRange(100); // Read through the lines of the file TCHAR *line; for (unsigned i = 0; (line = reader.read()) != NULL; i++) { // and parse them ParseLine(line, i, way_points); if ((i & 0x3f) == 0) operation.SetProgressPosition(reader.tell() * 100 / filesize); } }
void StatusMessageList::LoadFile(TLineReader &reader) { int ms; // Found ms for delay const TCHAR **location; // Where to put the data bool some_data; // Did we find some in the last loop... // Init first entry StatusMessageSTRUCT current; _init_Status(current); some_data = false; /* Read from the file */ TCHAR *buffer; const TCHAR *key, *value; while ((buffer = reader.read()) != 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 (some_data) { StatusMessageData.append(current); some_data = false; _init_Status(current); if (StatusMessageData.full()) break; } } else { location = NULL; if (_tcscmp(key, _T("key")) == 0) { some_data = true; // Success, we have a real entry location = ¤t.key; } else if (_tcscmp(key, _T("sound")) == 0) { current.doSound = true; location = ¤t.sound; } else if (_tcscmp(key, _T("delay")) == 0) { TCHAR *endptr; ms = _tcstol(value, &endptr, 10); if (endptr > value) current.delay_ms = ms; } else if (_tcscmp(key, _T("hide")) == 0) { if (_tcscmp(value, _T("yes")) == 0) current.doStatus = false; } // Do we have somewhere to put this && // is it currently empty ? (prevent lost at startup) if (location && (_tcscmp(*location, _T("")) == 0)) { // TODO code: this picks up memory lost from no entry, but not duplicates - fix. if (*location) { // JMW fix memory leak free((void*)const_cast<TCHAR *>(*location)); } *location = UnescapeBackslash(value); } } } if (some_data) StatusMessageData.append(current); }
void ParseInputFile(InputConfig &config, TLineReader &reader) { // TODO code - Safer sizes, strings etc - use C++ (can scanf restrict length?) TCHAR *new_label = NULL; // Init first entry // Did we find some in the last loop... bool some_data = false; // Multiple modes (so large string) TCHAR d_mode[1024] = _T(""); TCHAR d_type[256] = _T(""); TCHAR d_data[256] = _T(""); unsigned event_id = 0; TCHAR d_label[256] = _T(""); int d_location = 0; TCHAR d_event[256] = _T(""); TCHAR d_misc[256] = _T(""); int line = 0; // Read from the file // TODO code: What about \r - as in \r\n ? // TODO code: Note that ^# does not allow # in key - might be required (probably not) // Better way is to separate the check for # and the scanf TCHAR *buffer; while ((buffer = reader.read()) != 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 && _tcscmp(buffer, _T("#CLEAR")) == 0) { config.clear_all_events(); } else if (buffer[0] == _T('\0')) { // Check valid line? If not valid, assume next record (primative, but works ok!) // General checks before continue... if (some_data && (d_mode != NULL) && (_tcscmp(d_mode, _T("")) != 0)) { TCHAR *token; // For each mode token = _tcstok(d_mode, _T(" ")); // General errors - these should be true assert(d_location >= 0); assert(d_location < 1024); // Scott arbitrary limit assert(d_mode != NULL); assert(d_type != NULL); assert(d_label != NULL); // These could indicate bad data - thus not an ASSERT (debug only) // assert(_tcslen(d_mode) < 1024); // assert(_tcslen(d_type) < 1024); // assert(_tcslen(d_label) < 1024); while (token != NULL) { // All modes are valid at this point int mode_id = config.make_mode(token); assert(mode_id >= 0); // Make label event // TODO code: Consider Reuse existing entries... if (d_location > 0) { // Only copy this once per object - save string space if (!new_label) { new_label = StringMallocParse(d_label); } config.append_menu(mode_id, new_label, d_location, event_id); } // Make key (Keyboard input) // key - Hardware key or keyboard if (_tcscmp(d_type, _T("key")) == 0) { // Get the int key (eg: APP1 vs 'a') unsigned key = InputEvents::findKey(d_data); if (key > 0) config.Key2Event[mode_id][key] = event_id; else LogStartUp(_T("Invalid key data: %s at %i"), d_data, line); // Make gce (Glide Computer Event) // GCE - Glide Computer Event } else if (_tcscmp(d_type, _T("gce")) == 0) { // Get the int key (eg: APP1 vs 'a') int key = InputEvents::findGCE(d_data); if (key >= 0) config.GC2Event[mode_id][key] = event_id; else LogStartUp(_T("Invalid GCE data: %s at %i"), d_data, line); // Make ne (NMEA Event) // NE - NMEA Event } else if (_tcscmp(d_type, _T("ne")) == 0) { // Get the int key (eg: APP1 vs 'a') int key = InputEvents::findNE(d_data); if (key >= 0) config.N2Event[mode_id][key] = event_id; else LogStartUp(_T("Invalid GCE data: %s at %i"), d_data, line); // label only - no key associated (label can still be touch screen) } else if (_tcscmp(d_type, _T("label")) == 0) { // Nothing to do here... } else { LogStartUp(_T("Invalid type: %s at %i"), d_type, line); } token = _tcstok(NULL, _T(" ")); } } // Clear all data. some_data = false; _tcscpy(d_mode, _T("")); _tcscpy(d_type, _T("")); _tcscpy(d_data, _T("")); event_id = 0; _tcscpy(d_label, _T("")); d_location = 0; new_label = NULL; } else if (string_is_empty(buffer) || buffer[0] == _T('#')) { // Do nothing - we probably just have a comment line // JG removed "void;" - causes warning (void is declaration and needs variable) // NOTE: Do NOT display buffer to user as it may contain an invalid stirng ! } else if (parse_assignment(buffer, key, value)) { if (_tcscmp(key, _T("mode")) == 0) { if (_tcslen(value) < 1024) { some_data = true; // Success, we have a real entry _tcscpy(d_mode, value); } } else if (_tcscmp(key, _T("type")) == 0) { if (_tcslen(value) < 256) _tcscpy(d_type, value); } else if (_tcscmp(key, _T("data")) == 0) { if (_tcslen(value) < 256) _tcscpy(d_data, value); } else if (_tcscmp(key, _T("event")) == 0) { if (_tcslen(value) < 256) { _tcscpy(d_event, _T("")); _tcscpy(d_misc, _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 // TODO code: Can't use token here - breaks // other token - damn C - how about // C++ String class ? // TCHAR *eventtoken; // eventtoken = _tcstok(value, _T(" ")); // d_event = token; // eventtoken = _tcstok(value, _T(" ")); if ((ef == 1) || (ef == 2)) { // TODO code: Consider reusing existing identical events pt2Event event = InputEvents::findEvent(d_event); if (event) { TCHAR *allocated = StringMallocParse(d_misc); event_id = config.append_event(event, allocated, event_id); /* not freeing the string, because InputConfig::append_event() 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 { LogStartUp(_T("Invalid event type at %i"), line); } } } else if (_tcscmp(key, _T("label")) == 0) { _tcscpy(d_label, value); } else if (_tcscmp(key, _T("location")) == 0) { d_location = _ttoi(value); } else { LogStartUp(_T("Invalid key/value pair %s=%s at %i"), key, value, line); } } else { LogStartUp(_T("Invalid line at %i"), line); } } // end while }
bool ReadAirspace(Airspaces &airspace_database, TLineReader &reader) { int LineCount = 0; bool ignore = false; // Create and init ProgressDialog ProgressGlue::SetRange(1024); long file_size = reader.size(); TempAirspaceType temp_area; asFileType filetype = ftUnknown; TCHAR *line; TCHAR *comment; // Iterate through the lines while ((line = reader.read()) != NULL) { // Increase line counter LineCount++; // Strip comments comment = _tcschr(line, _T('*')); if (comment != NULL) *comment = _T('\0'); // Skip empty line if (string_is_empty(line)) continue; if (filetype == ftUnknown) { filetype = DetectFileType(line); if (filetype == ftUnknown) continue; } // Parse the line if (filetype == ftOpenAir) if (!ParseLine(airspace_database, line, temp_area) && !ShowParseWarning(LineCount, line)) return false; if (filetype == ftTNP) if (!ParseLineTNP(airspace_database, line, temp_area, ignore) && !ShowParseWarning(LineCount, line)) return false; // Update the ProgressDialog if ((LineCount & 0xff) == 0) ProgressGlue::SetValue(reader.tell() * 1024 / file_size); } if (LineCount == 0) return false; if (filetype == ftUnknown) { MessageBoxX(_("Unknown Filetype."), _("Airspace"), MB_OK); return false; } // Process final area (if any) if (!temp_area.Waiting) temp_area.AddPolygon(airspace_database); return true; }