// This is converting DAT Winpilot int ParseDAT(TCHAR *String,WAYPOINT *Temp) { TCHAR ctemp[(COMMENT_SIZE*2)+1]; // 101102 BUGFIX, we let +1 for safety TCHAR *Number; TCHAR *pWClast = NULL; TCHAR *pToken; TCHAR TempString[READLINE_LENGTH]; _tcscpy(TempString, String); // 20060513:sgi added wor on a copy of the string, do not modify the // source string, needed on error messages Temp->Visible = true; // default all waypoints visible at start Temp->FarVisible = true; Temp->Format = LKW_DAT; Temp->FileNum = globalFileNum; // ExtractParameter(TempString,ctemp,0); if ((pToken = _tcstok_r(TempString, TEXT(","), &pWClast)) == NULL) return FALSE; Temp->Number = _tcstol(pToken, &Number, 10); //ExtractParameter(TempString,ctemp,1); //Latitude if ((pToken = _tcstok_r(NULL, TEXT(","), &pWClast)) == NULL) return FALSE; Temp->Latitude = CalculateAngle(pToken); if((Temp->Latitude > 90) || (Temp->Latitude < -90)) { return FALSE; } //ExtractParameter(TempString,ctemp,2); //Longitude if ((pToken = _tcstok_r(NULL, TEXT(","), &pWClast)) == NULL) return FALSE; Temp->Longitude = CalculateAngle(pToken); if((Temp->Longitude > 180) || (Temp->Longitude < -180)) { return FALSE; } //ExtractParameter(TempString,ctemp,3); //Altitude if ((pToken = _tcstok_r(NULL, TEXT(","), &pWClast)) == NULL) return FALSE; Temp->Altitude = ReadAltitude(pToken); if (Temp->Altitude == -9999){ return FALSE; } //ExtractParameter(TempString,ctemp,4); //Flags if ((pToken = _tcstok_r(NULL, TEXT(","), &pWClast)) == NULL) return FALSE; Temp->Flags = CheckFlags(pToken); //ExtractParameter(TempString,ctemp,5); // Name if ((pToken = _tcstok_r(NULL, TEXT(",\n\r"), &pWClast)) == NULL) return FALSE; // guard against overrun if (_tcslen(pToken)>NAME_SIZE) { pToken[NAME_SIZE-1]= _T('\0'); } _tcscpy(Temp->Name, pToken); int i; for (i=_tcslen(Temp->Name)-1; i>1; i--) { if (Temp->Name[i]==' ') { Temp->Name[i]=0; } else { break; } } //ExtractParameter(TempString,ctemp,6); // Comment // DAT Comment if ((pToken = _tcstok_r(NULL, TEXT("\n\r"), &pWClast)) != NULL){ LK_tcsncpy(ctemp, pToken, COMMENT_SIZE); //@ 101102 BUGFIX bad. ctemp was not sized correctly! if (_tcslen(ctemp) >0 ) { if (Temp->Comment) { free(Temp->Comment); } Temp->Comment = (TCHAR*)malloc((_tcslen(ctemp)+1)*sizeof(TCHAR)); if (Temp->Comment) _tcscpy(Temp->Comment, ctemp); } } else { Temp->Comment = NULL; // useless } if(Temp->Altitude <= 0) { WaypointAltitudeFromTerrain(Temp); } if (Temp->Details) { free(Temp->Details); } return TRUE; }
bool ParseCOMPEWayPointString(TCHAR *String,WAYPOINT *Temp) { TCHAR tComment[(COMMENT_SIZE*2)+1]; // must be bigger than COMMENT_SIZE! TCHAR tString[READLINE_LENGTH+1]; TCHAR tName[NAME_SIZE+1]; unsigned int slen; //int flags=0; bool ok; unsigned int startpoint=3; // default unsigned int i, j; #define MAXCOMPENAME 16 slen=_tcslen(String); if (slen<65) { #ifdef COMPEDEBUG if (slen>0) { StartupStore(_T("TOO SHORT LINE:<%s> slen<65%s"),String,NEWLINE); } #endif return false; } LK_tcsncpy(tString, String,READLINE_LENGTH); // only handle W field, format: W__NAME if (tString[0] != 'W') { #ifdef COMPEDEBUG StartupStore(_T("COMPE IN:<%s> missing leading W%s"),tString,NEWLINE); #endif return false; } if (tString[1] != ' ') { #ifdef COMPEDEBUG StartupStore(_T("COMPE IN:<%s> missing space after W%s"),tString,NEWLINE); #endif return false; } // W wptname if (tString[2]!=' ') { startpoint=2; // third char } // W wptname if (tString[2]==' ') { if ( tString[3] == ' ' ) { #ifdef COMPEDEBUG StartupStore(_T("COMPE IN:<%s> missing character after W__%s"),tString,NEWLINE); #endif return false; } startpoint=3; // fourth char } Temp->Visible = true; // default all waypoints visible at start Temp->FarVisible = true; Temp->Format = LKW_COMPE; Temp->Number = NumberOfWayPoints; Temp->FileNum = globalFileNum; #ifdef COMPEDEBUG StartupStore(_T("COMPE IN:<%s>%s"),tString,NEWLINE); #endif // Name starts at position 3 or 4, index 2 or 3 . Search for space at the end of name (<=) for (i=startpoint, j=0, ok=false; i<= startpoint+MAXCOMPENAME; i++) { if (tString[i] != _T(' ')) {; j++; continue; } ok=true; break; } if (j<1) { #ifdef COMPEDEBUG StartupStore(_T("Name is empty ! %s"),NEWLINE); #endif return false; } if (!ok) { #ifdef COMPEDEBUG StartupStore(_T("Name too long! %s"),NEWLINE); #endif return false; } // i now point to first space after name LK_tcsncpy(tName,&tString[startpoint],j); #ifdef COMPEDEBUG StartupStore(_T("WP NAME size=%d: <%s>%s"),j,tName,NEWLINE); #endif if (tString[++i] != _T('A')) { #ifdef COMPEDEBUG StartupStore(_T("Missing A field! %s"),NEWLINE); #endif return false; } if (tString[++i] != _T(' ')) { #ifdef COMPEDEBUG StartupStore(_T("Missing space after A field! %s"),NEWLINE); #endif return false; } i++; // we are now on the first digit of latitude /* // aaaaaaaahhhhh f**k unicode TCHAR tdeg[5]; char sdeg[5]; sprintf(sdeg,"%c",0xBA); _stprintf(tdeg,_T("%s"),sdeg); */ TCHAR cDeg = _T('\xBA'); unsigned int p; // search for cDeg delimiter for (p=i, ok=false; p<(i+20);p++) { if (tString[p] == cDeg) { ok=true; break; } } if (!ok) { #ifdef COMPEDEBUG StartupStore(_T("Missing delimiter in latitude %s"),NEWLINE); #endif return false; } // p points to delimiter // latitude from i to i+12, starting from i counts 13 TCHAR tLatitude[16]; if ( (p-i)>15 ) { #ifdef COMPEDEBUG StartupStore(_T("latitude p-i exceed 15%s"),NEWLINE); #endif return false; } LK_tcsncpy(tLatitude,&tString[i],p-i); i=p+1; // i points to NS bool north=false; TCHAR tNS = tString[i]; TCHAR NS[]=_T("NS"); if ( (tNS != NS[0]) && (tNS != NS[1])) { #ifdef COMPEDEBUG StartupStore(_T("Wrong NS latitude! %s"),NEWLINE); #endif return false; } if ( tNS == NS[0] ) north=true; #ifdef COMPEDEBUG StartupStore(_T("WP LATITUDE : <%s> N1S0=%d%s"),tLatitude,north,NEWLINE); #endif // We are now on the space after latitude if (tString[++i] != _T(' ')) { #ifdef COMPEDEBUG StartupStore(_T("Missing space after latitude %s"),NEWLINE); #endif return false; } i++; // we are now on the first digit of longitude // search for cDeg delimiter for (p=i, ok=false; p<(i+20);p++) { if (tString[p] == cDeg) { ok=true; break; } } if (!ok) { #ifdef COMPEDEBUG StartupStore(_T("Missing delimiter in longitude %s"),NEWLINE); #endif return false; } // p points to delimiter TCHAR tLongitude[16]; if ( (p-i)>15 ) { #ifdef COMPEDEBUG StartupStore(_T("longitude p-i exceed 15%s"),NEWLINE); #endif return false; } LK_tcsncpy(tLongitude,&tString[i],p-i); i=p+1; // i points to EW bool east=false; TCHAR tEW = tString[i]; TCHAR EW[]=_T("EW"); if ( (tEW != EW[0]) && (tEW != EW[1])) { #ifdef COMPEDEBUG StartupStore(_T("Wrong EW longitude! %s"),NEWLINE); #endif return false; } if ( tEW == EW[0] ) east=true; #ifdef COMPEDEBUG StartupStore(_T("WP LONGITUDE : <%s> E1W0=%d%s"),tLongitude,east,NEWLINE); #endif // We are now on the space after longitude if (tString[++i] != _T(' ')) { #ifdef COMPEDEBUG StartupStore(_T("Missing space after longitude %s"),NEWLINE); #endif return false; } i++; // point to beginning of date of recording // we are now on the first digit of DATE // search for space delimiter for (p=i, ok=false; p<slen;p++) { if (tString[p] == _T(' ')) { ok=true; break; } } if (!ok) { #ifdef COMPEDEBUG StartupStore(_T("Missing space after DATE%s"),NEWLINE); #endif return false; } // p points to space after DATE // i points to the presumed first character of TIME i = p+1; if (i>=slen || tString[i] == _T(' ')) { #ifdef COMPEDEBUG StartupStore(_T("No TIME found%s"),NEWLINE); #endif return false; } // we are now on the first digit of DATE // search for space delimiter for (p=i, ok=false; p<slen;p++) { if (tString[p] == _T(' ')) { ok=true; break; } } if (!ok) { #ifdef COMPEDEBUG StartupStore(_T("Missing space after TIME%s"),NEWLINE); #endif return false; } // p points to space after TIME // i points to the presumed first character of ALTITUDE i = p+1; if (i>=slen || tString[i] == _T(' ')) { #ifdef COMPEDEBUG StartupStore(_T("No ALTITUDE found%s"),NEWLINE); #endif return false; } // i now points to first digit of altitude, minim 8 chars // this check can be avoided if ( slen < (i+8) ) { #ifdef COMPEDEBUG StartupStore(_T("Line overflow before altitude%s"),NEWLINE); #endif return false; } // we are now on the first digit of altitude // search for space delimiter for (p=i, ok=false; p<slen;p++) { if (tString[p] == _T(' ')) { ok=true; break; } } if (!ok) { #ifdef COMPEDEBUG StartupStore(_T("Missing space after altitude%s"),NEWLINE); #endif return false; } // p points to space after altitude TCHAR tAltitude[16]; if ( (p-i)>15 ) { #ifdef COMPEDEBUG StartupStore(_T("altitude p-i exceed 15%s"),NEWLINE); #endif return false; } LK_tcsncpy(tAltitude,&tString[i-1],p-i); #ifdef COMPEDEBUG StartupStore(_T("WP ALTITUDE : <%s>%s"),tAltitude,NEWLINE); #endif i=p+1; // we are now on first char of comment // search for line termination for (p=i, ok=false; p<slen;p++) { if ( (tString[p] == _T('\n')) || (tString[p] == _T('\r')) ) { ok=true; break; } } if (!ok) { #ifdef COMPEDEBUG StartupStore(_T("Missing CRLF after comment%s"),NEWLINE); #endif return false; } // p points to CR or LF after comment if ( (p-i)>((COMMENT_SIZE*2)-1) ) { #ifdef COMPEDEBUG StartupStore(_T("Comment too long%s"),NEWLINE); #endif return false; } LK_tcsncpy(tComment,&tString[i],p-i); #ifdef COMPEDEBUG StartupStore(_T("WP COMMENT : <%s>%s"),tComment,NEWLINE); #endif if (_tcslen(tName) > NAME_SIZE ) tName[NAME_SIZE-1]=_T('\0'); _tcscpy(Temp->Name,tName); Temp->Latitude = _tcstod(tLatitude,NULL); if (!north) Temp->Latitude *= -1; // 100218 if((Temp->Latitude > 90) || (Temp->Latitude < -90)) { return false; } Temp->Longitude = _tcstod(tLongitude,NULL); if (!east) Temp->Longitude *= -1; if((Temp->Longitude > 180) || (Temp->Longitude < -180)) { return false; } Temp->Altitude = ReadAltitude(tAltitude); if (Temp->Altitude == -9999) return false; Temp->Flags = TURNPOINT; if (_tcslen(tComment) >COMMENT_SIZE) { tComment[COMMENT_SIZE-1]=_T('\0'); } if (_tcslen(tComment) >0 ) { if (Temp->Comment) { free(Temp->Comment); } Temp->Comment = (TCHAR*)malloc((_tcslen(tComment)+1)*sizeof(TCHAR)); if (Temp->Comment) _tcscpy(Temp->Comment,tComment); } else Temp->Comment=NULL; //@ 101104 return true; }
static bool ParseLine(AirspaceDatabase &airspace_database, int nLineType, unsigned &NumberOfAirspacePoints, unsigned &NumberOfAirspaceAreas, unsigned &NumberOfAirspaceCircles) { int nIndex; switch (nLineType) { case k_nLtAC: if (bFillMode) { if (!bWaiting) AddArea(airspace_database, &TempArea, NumberOfAirspaceAreas); TempArea.NumPoints = 0; TempArea.Type = OTHER; for (nIndex = 0; nIndex < k_nAreaCount; nIndex++) { if (StartsWith(&TempString[3], k_strAreaStart[nIndex])) { TempArea.Type = k_nAreaType[nIndex]; break; } } Rotation = +1; } else if (!bWaiting) // Don't count circles JG 10-Nov-2005 NumberOfAirspaceAreas++; Rotation = +1; bWaiting = false; break; case k_nLtAN: if (bFillMode) { TempString[NAME_SIZE] = '\0'; _tcscpy(TempArea.Name, &TempString[3]); } break; case k_nLtAL: if (bFillMode) ReadAltitude(&TempString[3], &TempArea.Base); break; case k_nLtAH: if (bFillMode) ReadAltitude(&TempString[3],&TempArea.Top); break; case k_nLtV: // Need to set these while in count mode, or DB/DA will crash if (StartsWith(&TempString[2], _T("X=")) || StartsWith(&TempString[2], _T("x="))) { if (ReadCoords(&TempString[4],&CenterX, &CenterY)) break; } else if (StartsWith(&TempString[2], _T("D=-")) || StartsWith(&TempString[2], _T("d=-"))) { Rotation = -1; break; } else if (StartsWith(&TempString[2], _T("D=+")) || StartsWith(&TempString[2], _T("d=+"))) { Rotation = +1; break; } else if (StartsWith(&TempString[2], _T("Z")) || StartsWith(&TempString[2], _T("z"))) { // ToDo Display Zool Level break; } else if (StartsWith(&TempString[2], _T("W")) || StartsWith(&TempString[2], _T("w"))) { // ToDo width of an airway break; } else if (StartsWith(&TempString[2], _T("T")) || StartsWith(&TempString[2], _T("t"))) { // ----- JMW THIS IS REQUIRED FOR LEGACY FILES break; } goto OnError; case k_nLtDP: /* if (bFillMode) { ReadCoords(&TempString[3],&TempPoint.Longitude , &TempPoint.Latitude ); AddPoint(&TempPoint); } else NumberOfAirspacePoints++; */ // if (bFillMode) if (!ReadCoords(&TempString[3],&TempPoint.Longitude , &TempPoint.Latitude)) goto OnError; AddPoint(airspace_database, &TempPoint, &TempArea.NumPoints, NumberOfAirspacePoints); // TempArea.NumPoints++; break; case k_nLtDB: CalculateArc(airspace_database, TempString, NumberOfAirspacePoints); break; case k_nLtDA: CalculateSector(airspace_database, TempString, NumberOfAirspacePoints); break; case k_nLtDC: if (bFillMode) { double Radius = _tcstod(&TempString[2], NULL); Radius = (Radius * NAUTICALMILESTOMETRES); AddAirspaceCircle(airspace_database, &TempArea, CenterX, CenterY, Radius, NumberOfAirspaceCircles); } else NumberOfAirspaceCircles++; bWaiting = true; break; default: break; } return(true); OnError: if (!bFillMode){ TCHAR sTmp[MAX_PATH]; _stprintf(sTmp, TEXT("%s: %d\r\n\"%s\"\r\n%s."), gettext(TEXT("Parse Error at Line")), LineCount, TempString, gettext(TEXT("Line skipped."))); if (MessageBoxX(sTmp, gettext(TEXT("Airspace")), MB_OKCANCEL) == IDCANCEL){ return(false); } } return(true); }
bool NMEAParser::GGA(NMEAInputLine &line, NMEAInfo &info) { /* * $--GGA,hhmmss.ss,llll.ll,a,yyyyy.yy,a,x,xx,x.x,x.x,M,x.x,M,x.x,xxxx*hh * * Field Number: * 1) Universal Time Coordinated (UTC) * 2) Latitude * 3) N or S (North or South) * 4) Longitude * 5) E or W (East or West) * 6) GPS Quality Indicator, * 0 - fix not available, * 1 - GPS fix, * 2 - Differential GPS fix * (values above 2 are 2.3 features) * 3 = PPS fix * 4 = Real Time Kinematic * 5 = Float RTK * 6 = estimated (dead reckoning) * 7 = Manual input mode * 8 = Simulation mode * 7) Number of satellites in view, 00 - 12 * 8) Horizontal Dilution of precision (meters) * 9) Antenna Altitude above/below mean-sea-level (geoid) (in meters) * 10) Units of antenna altitude, meters * 11) Geoidal separation, the difference between the WGS-84 earth * ellipsoid and mean-sea-level (geoid), "-" means mean-sea-level * below ellipsoid * 12) Units of geoidal separation, meters * 13) Age of differential GPS data, time in seconds since last SC104 * type 1 or 9 update, null field when DGPS is not used * 14) Differential reference station ID, 0000-1023 * 15) Checksum */ GPSState &gps = info.gps; fixed this_time; if (!ReadTime(line, info.date_time_utc, this_time)) return true; GeoPoint location; bool valid_location = ReadGeoPoint(line, location); unsigned fix_quality; if (line.ReadChecked(fix_quality)) { gps.fix_quality = (FixQuality)fix_quality; gps.fix_quality_available.Update(info.clock); } unsigned satellites_used; if (line.ReadChecked(satellites_used)) { info.gps.satellites_used = satellites_used; info.gps.satellites_used_available.Update(info.clock); } if (!TimeHasAdvanced(this_time, info)) return true; (void)valid_location; /* JMW: note ignore location updates from GGA -- definitive frame is GPRMC sentence if (!gpsValid) info.LocationAvailable.Clear(); else if (valid_location) info.LocationAvailable.Update(info.clock); if (valid_location) info.Location = location; */ info.gps.real = real; #if defined(ANDROID) || defined(__APPLE__) info.gps.nonexpiring_internal_gps = false; #endif gps.hdop = line.Read(fixed(0)); bool altitude_available = ReadAltitude(line, info.gps_altitude); if (altitude_available) info.gps_altitude_available.Update(info.clock); else info.gps_altitude_available.Clear(); fixed geoid_separation; if (ReadAltitude(line, geoid_separation)) { // No real need to parse this value, // but we do assume that no correction is required in this case if (!altitude_available) { /* Some devices, such as the "LG Incite Cellphone" seem to be severely bugged, and report the GPS altitude in the Geoid column. That sucks! */ info.gps_altitude = geoid_separation; info.gps_altitude_available.Update(info.clock); } } else { // need to estimate Geoid Separation internally (optional) // FLARM uses MSL altitude // // Some others don't. // // If the separation doesn't appear in the sentence, // we can assume the GPS unit is giving ellipsoid height // if (use_geoid) { // JMW TODO really need to know the actual device.. geoid_separation = EGM96::LookupSeparation(info.location); info.gps_altitude -= geoid_separation; } } return true; }
//#define CUPDEBUG bool ParseCUPWayPointString(TCHAR *String,WAYPOINT *Temp) { TCHAR ctemp[(COMMENT_SIZE*2)+1]; // must be bigger than COMMENT_SIZE! TCHAR *pToken; TCHAR TempString[READLINE_LENGTH+1]; TCHAR OrigString[READLINE_LENGTH+1]; TCHAR Tname[NAME_SIZE+1]; int flags=0; unsigned int i, j; bool ishome=false; // 100310 // strtok does not return empty fields. we create them here with special char #define DUMCHAR '|' Temp->Visible = true; // default all waypoints visible at start Temp->FarVisible = true; Temp->Format = LKW_CUP; Temp->Number = WayPointList.size(); Temp->FileNum = globalFileNum; #if BUGSTOP // This should never happen LKASSERT(_tcslen(String) < sizeof(OrigString)); #endif LK_tcsncpy(OrigString, String,READLINE_LENGTH); // if string is too short do nothing if (_tcslen(OrigString)<11) return false; #ifdef CUPDEBUG StartupStore(_T("OLD:<%s>%s"),OrigString,NEWLINE); #endif for (i=0,j=0; i<_tcslen(OrigString); i++) { // skip last comma, and avoid overruning the end if ( (i+1)>= _tcslen(OrigString)) break; if ( (OrigString[i] == _T(',')) && (OrigString[i+1] == _T(',')) ) { TempString[j++] = _T(','); TempString[j++] = _T(DUMCHAR); continue; } /* we need terminations for comments if ( OrigString[i] == _T('\r') ) continue; if ( OrigString[i] == _T('\n') ) continue; */ TempString[j++] = OrigString[i]; } TempString[j] = _T('\0'); #ifdef CUPDEBUG StartupStore(_T("NEW:<%s>%s"),TempString,NEWLINE); #endif // ---------------- NAME ---------------- pToken = _tcstok(TempString, TEXT(",")); if (pToken == NULL) return false; if (_tcslen(pToken)>NAME_SIZE) { pToken[NAME_SIZE-1]= _T('\0'); } _tcscpy(Temp->Name, pToken); CleanCupCode(Temp->Name); #ifdef CUPDEBUG StartupStore(_T(" CUP NAME=<%s>%s"),Temp->Name,NEWLINE); #endif // ---------------- CODE ------------------ pToken = _tcstok(NULL, TEXT(",")); if (pToken == NULL) return false; if (_tcslen(pToken)>CUPSIZE_CODE) { pToken[CUPSIZE_CODE-1]= _T('\0'); } _tcscpy(Temp->Code, pToken); for (i=_tcslen(Temp->Code)-1; i>1; i--) { if (Temp->Code[i]==' ') { Temp->Code[i]=0; } else { break; } } _tcscpy(Tname,Temp->Code); for (j=0, i=0; i<_tcslen(Tname); i++) { //if (Tname[i]!='\"') Temp->Code[j++]=Tname[i]; if ( (Tname[i]!='\"') && (Tname[i]!=DUMCHAR) ){ Temp->Code[j++]=Tname[i]; } } Temp->Code[j]= _T('\0'); if (_tcslen(Temp->Code)>5) { // 100310 if ( _tcscmp(Temp->Code,_T("LKHOME")) == 0 ) { StartupStore(_T(". Found LKHOME inside CUP waypoint <%s>%s"),Temp->Name,NEWLINE); ishome=true; } } #ifdef CUPDEBUG StartupStore(_T(" CUP CODE=<%s>%s"),Temp->Code,NEWLINE); #endif // ---------------- COUNTRY ------------------ pToken = _tcstok(NULL, TEXT(",")); if (pToken == NULL) return false; LK_tcsncpy(Temp->Country,pToken,CUPSIZE_COUNTRY); if (_tcslen(Temp->Country)>3) { Temp->Country[3]= _T('\0'); } if ((_tcslen(Temp->Country) == 1) && Temp->Country[0]==DUMCHAR) Temp->Country[0]=_T('\0'); #ifdef CUPDEBUG StartupStore(_T(" CUP COUNTRY=<%s>%s"),Temp->Country,NEWLINE); #endif // ---------------- LATITUDE ------------------ pToken = _tcstok(NULL, TEXT(",")); if (pToken == NULL) return false; Temp->Latitude = CUPToLat(pToken); if((Temp->Latitude > 90) || (Temp->Latitude < -90)) { return false; } #ifdef CUPDEBUG StartupStore(_T(" CUP LATITUDE=<%f>%s"),Temp->Latitude,NEWLINE); #endif // ---------------- LONGITUDE ------------------ pToken = _tcstok(NULL, TEXT(",")); if (pToken == NULL) return false; Temp->Longitude = CUPToLon(pToken); if((Temp->Longitude > 180) || (Temp->Longitude < -180)) { return false; } #ifdef CUPDEBUG StartupStore(_T(" CUP LONGITUDE=<%f>%s"),Temp->Longitude,NEWLINE); #endif // ---------------- ELEVATION ------------------ pToken = _tcstok(NULL, TEXT(",")); if (pToken == NULL) return false; Temp->Altitude = ReadAltitude(pToken); #ifdef CUPDEBUG StartupStore(_T(" CUP ELEVATION=<%f>%s"),Temp->Altitude,NEWLINE); #endif if (Temp->Altitude == -9999){ Temp->Altitude=0; } // ---------------- STYLE ------------------ pToken = _tcstok(NULL, TEXT(",")); if (pToken == NULL) return false; Temp->Style = (int)_tcstol(pToken,NULL,10); switch(Temp->Style) { case STYLE_AIRFIELDGRASS: // airfield grass case STYLE_GLIDERSITE: // glider site case STYLE_AIRFIELDSOLID: // airfield solid flags = AIRPORT; flags += LANDPOINT; break; case STYLE_OUTLANDING: // outlanding flags = LANDPOINT; break; default: flags = TURNPOINT; break; } if (ishome) flags += HOME; Temp->Flags = flags; #ifdef CUPDEBUG StartupStore(_T(" CUP STYLE=<%d> flags=%d %s"),Temp->Style,Temp->Flags,NEWLINE); #endif // ---------------- RWY DIRECTION ------------------ pToken = _tcstok(NULL, TEXT(",")); if (pToken == NULL) return false; if ((_tcslen(pToken) == 1) && (pToken[0]==DUMCHAR)) Temp->RunwayDir=-1; else Temp->RunwayDir = (int)AngleLimit360(_tcstol(pToken, NULL, 10)); #ifdef CUPDEBUG StartupStore(_T(" CUP RUNWAY DIRECTION=<%d>%s"),Temp->RunwayDir,NEWLINE); #endif // ---------------- RWY LENGTH ------------------ pToken = _tcstok(NULL, TEXT(",")); if (pToken == NULL) return false; if ((_tcslen(pToken) == 1) && (pToken[0]==DUMCHAR)) Temp->RunwayLen = -1; else Temp->RunwayLen = (int)ReadLength(pToken); #ifdef CUPDEBUG StartupStore(_T(" CUP RUNWAY LEN=<%d>%s"),Temp->RunwayLen,NEWLINE); #endif // ---------------- AIRPORT FREQ ------------------ pToken = _tcstok(NULL, TEXT(",")); if (pToken == NULL) return false; if (_tcslen(pToken)>CUPSIZE_FREQ) pToken[CUPSIZE_FREQ-1]= _T('\0'); _tcscpy(Temp->Freq, pToken); TrimRight(Temp->Freq); _tcscpy(Tname,Temp->Freq); for (j=0, i=0; i<_tcslen(Tname); i++) if ( (Tname[i]!='\"') && (Tname[i]!=DUMCHAR) ) Temp->Freq[j++]=Tname[i]; Temp->Freq[j]= _T('\0'); #ifdef CUPDEBUG StartupStore(_T(" CUP FREQ=<%s>%s"),Temp->Freq,NEWLINE); #endif // ---------------- COMMENT ------------------ pToken = _tcstok(NULL, TEXT("\n\r")); if (pToken != NULL) { if (_tcslen(pToken)>=COMMENT_SIZE) pToken[COMMENT_SIZE-1]= _T('\0'); // remove trailing spaces and CR LF _tcscpy(ctemp, pToken); for (i=_tcslen(ctemp)-1; i>1; i--) { if ( (ctemp[i]==' ') || (ctemp[i]=='\r') || (ctemp[i]=='\n') ) ctemp[i]=0; else break; } // now remove " " (if there) for (j=0, i=0; i<_tcslen(ctemp); i++) if (ctemp[i]!='\"') ctemp[j++]=ctemp[i]; ctemp[j]= _T('\0'); if (_tcslen(ctemp) >0 ) { if (Temp->Comment) { free(Temp->Comment); } Temp->Comment = (TCHAR*)malloc((_tcslen(ctemp)+1)*sizeof(TCHAR)); if (Temp->Comment) _tcscpy(Temp->Comment, ctemp); } #ifdef CUPDEBUG StartupStore(_T(" CUP COMMENT=<%s>%s"),Temp->Comment,NEWLINE); #endif } else { Temp->Comment=NULL; // useless } if(Temp->Altitude <= 0) { WaypointAltitudeFromTerrain(Temp); } if (Temp->Details) { free(Temp->Details); } return true; }
static bool ParseLineTNP(Airspaces &airspace_database, TCHAR *line, TempAirspaceType &temp_area, bool &ignore) { // Strip comments TCHAR *comment = _tcschr(line, _T('*')); if (comment != nullptr) *comment = _T('\0'); const TCHAR* parameter; if ((parameter = StringAfterPrefixCI(line, _T("INCLUDE="))) != nullptr) { if (StringStartsWithIgnoreCase(parameter, _T("YES"))) ignore = false; else if (StringStartsWithIgnoreCase(parameter, _T("NO"))) ignore = true; return true; } if (ignore) return true; if ((parameter = StringAfterPrefixCI(line, _T("POINT="))) != nullptr) { GeoPoint temp_point; if (!ParseCoordsTNP(parameter, temp_point)) return false; temp_area.points.push_back(temp_point); } else if ((parameter = StringAfterPrefixCI(line, _T("CIRCLE "))) != nullptr) { if (!ParseCircleTNP(parameter, temp_area)) return false; temp_area.AddCircle(airspace_database); temp_area.ResetTNP(); } else if ((parameter = StringAfterPrefixCI(line, _T("CLOCKWISE "))) != nullptr) { temp_area.rotation = 1; if (!ParseArcTNP(parameter, temp_area)) return false; } else if ((parameter = StringAfterPrefixCI(line, _T("ANTI-CLOCKWISE "))) != nullptr) { temp_area.rotation = -1; if (!ParseArcTNP(parameter, temp_area)) return false; } else if ((parameter = StringAfterPrefixCI(line, _T("TITLE="))) != nullptr) { temp_area.AddPolygon(airspace_database); temp_area.ResetTNP(); temp_area.name = parameter; } else if ((parameter = StringAfterPrefixCI(line, _T("TYPE="))) != nullptr) { temp_area.AddPolygon(airspace_database); temp_area.ResetTNP(); temp_area.type = ParseTypeTNP(parameter); } else if ((parameter = StringAfterPrefixCI(line, _T("CLASS="))) != nullptr) { temp_area.type = ParseClassTNP(parameter); } else if ((parameter = StringAfterPrefixCI(line, _T("TOPS="))) != nullptr) { ReadAltitude(parameter, temp_area.top); } else if ((parameter = StringAfterPrefixCI(line, _T("BASE="))) != nullptr) { ReadAltitude(parameter, temp_area.base); } else if ((parameter = StringAfterPrefixCI(line, _T("RADIO="))) != nullptr) { temp_area.radio = parameter; } else if ((parameter = StringAfterPrefixCI(line, _T("ACTIVE="))) != nullptr) { if (StringIsEqualIgnoreCase(parameter, _T("WEEKEND"))) temp_area.days_of_operation.SetWeekend(); else if (StringIsEqualIgnoreCase(parameter, _T("WEEKDAY"))) temp_area.days_of_operation.SetWeekdays(); else if (StringIsEqualIgnoreCase(parameter, _T("EVERYDAY"))) temp_area.days_of_operation.SetAll(); } return true; }
static bool ParseLine(Airspaces &airspace_database, TCHAR *line, TempAirspaceType &temp_area) { const TCHAR *value; // Strip comments TCHAR *comment = _tcschr(line, _T('*')); if (comment != nullptr) *comment = _T('\0'); // Only return expected lines switch (line[0]) { case _T('D'): case _T('d'): switch (line[1]) { case _T('P'): case _T('p'): value = ValueAfterSpace(line + 2); if (value == nullptr) break; { GeoPoint temp_point; if (!ReadCoords(value, temp_point)) return false; temp_area.points.push_back(temp_point); break; } case _T('C'): case _T('c'): temp_area.radius = Units::ToSysUnit(fixed(ParseDouble(&line[2])), Unit::NAUTICAL_MILES); temp_area.AddCircle(airspace_database); temp_area.Reset(); break; case _T('A'): case _T('a'): ParseArcBearings(line, temp_area); break; case _T('B'): case _T('b'): return ParseArcPoints(line, temp_area); default: return true; } break; case _T('V'): case _T('v'): // Need to set these while in count mode, or DB/DA will crash if ((value = StringAfterPrefixCI(SkipSpaces(line + 1), _T("X="))) != nullptr) { if (!ReadCoords(value, temp_area.center)) return false; } else if (StringAfterPrefixCI(SkipSpaces(line + 1), _T("D=-"))) { temp_area.rotation = -1; } else if (StringAfterPrefixCI(SkipSpaces(line + 1), _T("D=+"))) { temp_area.rotation = +1; } break; case _T('A'): case _T('a'): switch (line[1]) { case _T('C'): case _T('c'): value = ValueAfterSpace(line + 2); if (value == nullptr) break; temp_area.AddPolygon(airspace_database); temp_area.Reset(); temp_area.type = ParseType(value); break; case _T('N'): case _T('n'): value = ValueAfterSpace(line + 2); if (value != nullptr) temp_area.name = value; break; case _T('L'): case _T('l'): value = ValueAfterSpace(line + 2); if (value != nullptr) ReadAltitude(value, temp_area.base); break; case _T('H'): case _T('h'): value = ValueAfterSpace(line + 2); if (value != nullptr) ReadAltitude(value, temp_area.top); break; case _T('R'): case _T('r'): value = ValueAfterSpace(line + 2); if (value != nullptr) temp_area.radio = value; break; default: return true; } break; } return true; }
static bool ParseLineTNP(Airspaces &airspace_database, const TCHAR *line, TempAirspaceType &temp_area, bool &ignore) { const TCHAR* parameter; if ((parameter = string_after_prefix_ci(line, _T("INCLUDE="))) != NULL) { if (_tcsicmp(parameter, _T("YES")) == 0) ignore = false; else if (_tcsicmp(parameter, _T("NO")) == 0) ignore = true; return true; } if (ignore) return true; if ((parameter = string_after_prefix_ci(line, _T("TITLE="))) != NULL) { temp_area.Name = parameter; } else if ((parameter = string_after_prefix_ci(line, _T("RADIO="))) != NULL) { temp_area.Radio = parameter; } else if ((parameter = string_after_prefix_ci(line, _T("ACTIVE="))) != NULL) { if (_tcsicmp(parameter, _T("WEEKEND")) == 0) temp_area.days_of_operation.set_weekend(); else if (_tcsicmp(parameter, _T("WEEKDAY")) == 0) temp_area.days_of_operation.set_weekdays(); else if (_tcsicmp(parameter, _T("EVERYDAY")) == 0) temp_area.days_of_operation.set_all(); } else if ((parameter = string_after_prefix_ci(line, _T("TYPE="))) != NULL) { if (!temp_area.Waiting) temp_area.AddPolygon(airspace_database); temp_area.reset(); temp_area.Type = ParseTypeTNP(parameter); temp_area.Waiting = false; } else if ((parameter = string_after_prefix_ci(line, _T("CLASS="))) != NULL) { if (temp_area.Type == OTHER) temp_area.Type = ParseClassTNP(parameter); } else if ((parameter = string_after_prefix_ci(line, _T("TOPS="))) != NULL) { ReadAltitude(parameter, &temp_area.Top); } else if ((parameter = string_after_prefix_ci(line, _T("BASE="))) != NULL) { ReadAltitude(parameter, &temp_area.Base); } else if ((parameter = string_after_prefix_ci(line, _T("POINT="))) != NULL) { GeoPoint TempPoint; if (!ParseCoordsTNP(parameter, TempPoint)) return false; temp_area.points.push_back(TempPoint); } else if ((parameter = string_after_prefix_ci(line, _T("CIRCLE "))) != NULL) { if (!ParseCircleTNP(parameter, temp_area)) return false; temp_area.AddCircle(airspace_database); } else if ((parameter = string_after_prefix_ci(line, _T("CLOCKWISE "))) != NULL) { temp_area.Rotation = 1; if (!ParseArcTNP(parameter, temp_area)) return false; } else if ((parameter = string_after_prefix_ci(line, _T("ANTI-CLOCKWISE "))) != NULL) { temp_area.Rotation = -1; if (!ParseArcTNP(parameter, temp_area)) return false; } return true; }
static bool ParseLine(Airspaces &airspace_database, const TCHAR *line, TempAirspaceType &temp_area) { const TCHAR *value; // Only return expected lines switch (line[0]) { case _T('A'): case _T('a'): switch (line[1]) { case _T('C'): case _T('c'): value = value_after_space(line + 2); if (value == NULL) break; if (!temp_area.Waiting) temp_area.AddPolygon(airspace_database); temp_area.reset(); temp_area.Type = ParseType(value); temp_area.Waiting = false; break; case _T('N'): case _T('n'): value = value_after_space(line + 2); if (value != NULL) temp_area.Name = value; break; case _T('R'): case _T('r'): value = value_after_space(line + 2); if (value != NULL) temp_area.Radio = value; break; case _T('L'): case _T('l'): value = value_after_space(line + 2); if (value != NULL) ReadAltitude(value, &temp_area.Base); break; case _T('H'): case _T('h'): value = value_after_space(line + 2); if (value != NULL) ReadAltitude(value, &temp_area.Top); break; default: return true; } break; case _T('D'): case _T('d'): switch (line[1]) { case _T('A'): case _T('a'): CalculateSector(line, temp_area); break; case _T('B'): case _T('b'): CalculateArc(line, temp_area); break; case _T('C'): case _T('c'): temp_area.Radius = Units::ToSysUnit(fixed(_tcstod(&line[2], NULL)), unNauticalMiles); temp_area.AddCircle(airspace_database); temp_area.reset(); break; case _T('P'): case _T('p'): value = value_after_space(line + 2); if (value == NULL) break; { GeoPoint TempPoint; if (!ReadCoords(value, TempPoint)) return false; temp_area.points.push_back(TempPoint); break; } default: return true; } break; case _T('V'): case _T('v'): // Need to set these while in count mode, or DB/DA will crash if (string_after_prefix_ci(&line[2], _T("X="))) { if (!ReadCoords(&line[4],temp_area.Center)) return false; } else if (string_after_prefix_ci(&line[2], _T("D=-"))) { temp_area.Rotation = -1; } else if (string_after_prefix_ci(&line[2], _T("D=+"))) { temp_area.Rotation = +1; } break; } return true; }