bool WayPointFileWinPilot::parseLine(const TCHAR* line, const unsigned linenum, Waypoints &way_points, const RasterTerrain *terrain) { TCHAR ctemp[255]; const TCHAR *params[20]; size_t n_params; // If (end-of-file or comment) if (line[0] == '\0' || line[0] == 0x1a || _tcsstr(line, _T("**")) == line || _tcsstr(line, _T("*")) == line) // -> return without error condition return true; if (_tcslen(line) >= sizeof(ctemp) / sizeof(ctemp[0])) /* line too long for buffer */ return false; GeoPoint location; // Get fields n_params = extractParameters(line, ctemp, params, 20); if (n_params < 6) return false; // Latitude (e.g. 51:15.900N) if (!parseAngle(params[1], location.Latitude, true)) return false; // Longitude (e.g. 00715.900W) if (!parseAngle(params[2], location.Longitude, false)) return false; Waypoint new_waypoint(location); new_waypoint.FileNum = file_num; // Name (e.g. KAMPLI) if (!parseString(params[5], new_waypoint.Name)) return false; // Altitude (e.g. 458M) /// @todo configurable behaviour bool alt_ok = parseAltitude(params[3], new_waypoint.Altitude); check_altitude(new_waypoint, terrain, alt_ok); if (n_params > 6) { // Description (e.g. 119.750 Airport) parseString(params[6], new_waypoint.Comment); } // Waypoint Flags (e.g. AT) parseFlags(params[4], new_waypoint.Flags); add_waypoint(way_points, new_waypoint); return true; }
bool WayPointFileZander::parseLine(const TCHAR* line, const unsigned linenum, Waypoints &way_points, const RasterTerrain *terrain) { // If (end-of-file or comment) if (line[0] == '\0' || line[0] == 0x1a || _tcsstr(line, _T("**")) == line || _tcsstr(line, _T("*")) == line) // -> return without error condition return true; // Determine the length of the line size_t len = _tcslen(line); // If less then 34 characters -> something is wrong -> cancel if (len < 34) return false; GeoPoint location; // Latitude (Characters 13-20 // DDMMSS(N/S)) if (!parseAngle(line + 13, location.Latitude, true)) return false; // Longitude (Characters 21-29 // DDDMMSS(E/W)) if (!parseAngle(line + 21, location.Longitude, false)) return false; Waypoint new_waypoint(location); new_waypoint.FileNum = file_num; // Name (Characters 0-12) if (!parseString(line, new_waypoint.Name)) return false; // Altitude (Characters 30-34 // e.g. 1561 (in meters)) /// @todo configurable behaviour bool alt_ok = parseAltitude(line + 30, new_waypoint.Altitude); check_altitude(new_waypoint, terrain, alt_ok); // Description (Characters 35-44) if (len > 35) parseString(line + 35, new_waypoint.Comment); // Flags (Characters 45-49) if (len > 45) parseFlags(line + 45, new_waypoint.Flags); add_waypoint(way_points, new_waypoint); return true; }
bool WayPointFileSeeYou::parseLine(const TCHAR* line, const unsigned linenum, Waypoints &way_points, const RasterTerrain *terrain) { TCHAR ctemp[255]; const TCHAR *params[20]; size_t n_params; static unsigned iName = 0, iCode = 1, iCountry = 2; static unsigned iLatitude = 3, iLongitude = 4, iElevation = 5; static unsigned iStyle = 6, iRWDir = 7, iRWLen = 8; static unsigned iFrequency = 9, iDescription = 10; static bool ignore_following = false; // If (end-of-file or comment) if (line[0] == '\0' || line[0] == 0x1a || _tcsstr(line, _T("**")) == line || _tcsstr(line, _T("*")) == line) // -> return without error condition return true; if (_tcslen(line) >= sizeof(ctemp) / sizeof(ctemp[0])) /* line too long for buffer */ return false; // Parse first line holding field order /// @todo linenum == 0 should be the first /// (not ignored) line, not just line 0 if (linenum == 0) { // Get fields n_params = extractParameters(line, ctemp, params, 20); // Iterate through fields and save the field order for (unsigned i = 0; i < n_params; i++) { const TCHAR* value = params[i]; if (!_tcscmp(value, _T("name"))) iName = i; else if (!_tcscmp(value, _T("code"))) iCode = i; else if (!_tcscmp(value, _T("country"))) iCountry = i; else if (!_tcscmp(value, _T("lat"))) iLatitude = i; else if (!_tcscmp(value, _T("lon"))) iLongitude = i; else if (!_tcscmp(value, _T("elev"))) iElevation = i; else if (!_tcscmp(value, _T("style"))) iStyle = i; else if (!_tcscmp(value, _T("rwdir"))) iRWDir = i; else if (!_tcscmp(value, _T("rwlen"))) iRWLen = i; else if (!_tcscmp(value, _T("freq"))) iFrequency = i; else if (!_tcscmp(value, _T("desc"))) iDescription = i; } ignore_following = false; return true; } // If task marker is reached ignore all following lines if (_tcsstr(line, _T("-----Related Tasks-----")) == line) ignore_following = true; if (ignore_following) return true; // Get fields n_params = extractParameters(line, ctemp, params, 20); // Check if the basic fields are provided if (iName >= n_params) return false; if (iLatitude >= n_params) return false; if (iLongitude >= n_params) return false; GeoPoint location; // Latitude (e.g. 5115.900N) if (!parseAngle(params[iLatitude], location.Latitude, true)) return false; // Longitude (e.g. 00715.900W) if (!parseAngle(params[iLongitude], location.Longitude, false)) return false; Waypoint new_waypoint(location); new_waypoint.FileNum = file_num; // Name (e.g. "Some Turnpoint", with quotes) if (!parseString(params[iName], new_waypoint.Name)) return false; // Elevation (e.g. 458.0m) /// @todo configurable behaviour bool alt_ok = iElevation < n_params && parseAltitude(params[iElevation], new_waypoint.Altitude); check_altitude(new_waypoint, terrain, alt_ok); // Description (e.g. "Some Turnpoint", with quotes) /// @todo include frequency and rwdir/len if (iDescription < n_params) parseString(params[iDescription], new_waypoint.Comment); // Style (e.g. 5) /// @todo include peaks with peak symbols etc. if (iStyle < n_params) parseStyle(params[iStyle], new_waypoint.Flags); // If the Style attribute did not state that this is an airport if (!new_waypoint.Flags.Airport) { // -> parse the runway length fixed rwlen; // Runway length (e.g. 546.0m) if (iRWLen < n_params && parseAltitude(params[iRWLen], rwlen)) { // If runway length is between 100m and 300m -> landpoint if (rwlen > fixed(100) && rwlen <= fixed(300)) new_waypoint.Flags.LandPoint = true; // If runway length is higher then 300m -> airport if (rwlen > fixed(300)) new_waypoint.Flags.Airport = true; } } add_waypoint(way_points, new_waypoint); return true; }