/*********************************************************************** * * FUNCTION: PrvCompareNameToTimeZoneEntry * * DESCRIPTION: Compare the string <searchData> to a TimeZoneEntryType * record pointed at by <arrayData>. * * PARAMETERS: * searchData -> Pointer to string. * arrayData -> Pointer to entry in TimeZoneEntryType array. * nameLen -> Unused data. * * RETURNED: * 0 if equal. * <1 if string sorts before entry name. * >1 if string sorts after entry name. * * HISTORY: * 08/01/00 kwk Created by Ken Krugler. * ***********************************************************************/ static Int16 PrvCompareNameToTimeZoneEntry(void const *searchData, void const *arrayData, Int32 nameLen) { const Char* tzName = (const Char*)searchData; const TimeZoneEntryType* tzEntry = (const TimeZoneEntryType*)arrayData; return(StrNCaselessCompare(tzName, tzEntry->tzName, nameLen)); } // PrvCompareNameToTimeZoneEntry
int osip_strncasecmp(const char *s1, const char *s2, size_t len) { #if defined(__VXWORKS_OS__) || defined( __PSOS__) if (len == 0) return OSIP_SUCCESS; while ((len > 0) && (tolower(*s1) == tolower(*s2))) { len--; if ((len == 0) || (*s1 == '\0') || (*s2 == '\0')) break; s1++; s2++; } return tolower(*s1) - tolower(*s2); #elif defined(__PALMOS__) && (__PALMOS__ < 0x06000000) return StrNCaselessCompare(s1, s2, len); #elif defined(__PALMOS__) || (!defined WIN32 && !defined _WIN32_WCE) return strncasecmp(s1, s2, len); #else return _strnicmp(s1, s2, len); #endif }
/* * function : ScanForWaypoints * * Scans for proximity waypoints. maxTicks specifies how long we're allowed * to run for. If stopOnEvent is true then an event in the PalmOS event * queue can interrupt the scan. * * Returns true if the scan reached the end of its cycle * */ static Boolean ScanForWaypoints(UInt16 maxTicks, Boolean stopOnEvent) { UInt32 startTime = PFGetTicks(); Waypoint *wp; double wpRange; double wpBearing, wpBearingFrom; double maxRange; UInt16 j; UInt16 runwayIcon = 0; static UInt32 lastScanTime; Int16 numScanned = 0; ShortWaypointType *swp; /* * scan state machine controls what we should do: * * scanning - obvious really! * * waiting - waiting for 8 seconds between scans * * starting - ready to start a new scan * */ LOGENTRY; if (scanState == waiting) { if (PFTimerHasExpired(lastScanTime, PFTicksPerSecond()*8)) { scanState = starting; } } if (scanState == starting) { newProxList->numWaypoints = 0; LOGTAG("Scan starting"); search = WDMInitProxScan(WPDataset, GPS.posn.lat32, GPS.posn.lon32, FMDS.noObstacles, searchMask); /* * No waypoints to search * */ if (!search) { scanState = waiting; lastScanTime=PFGetTicks(); LOGEXIT; return true; } scanState = scanning; } if (scanState != scanning) { LOGEXIT; return false; } /* * determine how far out we should look from current position. If all * of the prox lists are full then the max we should look is not beyond * the furthest waypoint, otherwise we default to 3000 nm. * */ if (newProxList->numWaypoints == MAX_PROXWAYPOINTS) { maxRange = newProxList->waypoints[MAX_PROXWAYPOINTS-1].range; } else { if (searchString[0] == 0) { maxRange = 3000.0/NM_PER_RADIAN; } else { /* * search string specified - search entire database * */ maxRange = 0.0; } } do { //LOGINT16((Int16) (maxRange*NM_PER_RADIAN)); //LOGINT32(RAD_TO_INT32(maxRange)); swp = WDMGetProxWaypoint(search, RAD_TO_INT32(maxRange)); if (swp == NULL) { /* * end of scanning cycle * */ LOGTAG("EOScan"); LOGINT16(numScanned); WDMFreeSearch(search); search = NULL; if (newProxList == &proxList) { newProxList = PFMalloc(sizeof(*newProxList)); } else { PFMemMove(&proxList, newProxList, sizeof(*newProxList)); } scanState = waiting; lastScanTime=PFGetTicks(); LOGEXIT; return true; } numScanned++; //LOGTAG("Considering:"); //LOGSTR(wp->ident); /* * discard based on ident-search * */ if (searchString[0] && identOnly) { char ident[6]; StrNCopy(ident, swp->extra, sizeof(ident)-1); ident[sizeof(ident)-1] = 0; if (StrNCaselessCompare(ident, searchString, StrLen(searchString)) != 0) { continue; } } wp = WDMGetWaypoint(WPDataset, swp->wpId); /* * discard based on search string * */ if (searchString[0]) { char s[20], d[100]; char *subStr; StrToLower(d, wp->ident); StrToLower(s, searchString); subStr = StrStr(d,s); /* if (identOnly && subStr != d) { PFMemFree((void*)wp); continue; } */ if (!subStr) { StrToLower(d, GetStringFromList(wp->ident,1)); if (!StrStr(d,s)) { PFMemFree(wp); continue; } } } /* * runway surface and dimension checks - discard any airfield * that doesn't meet these criteria * * NB We don't discard a waypoint based on runway dimensions * if a search string is specified. * */ if ( WDMGetWaypointType(wp) & wpAllAirfields ) { CpRunwayInfoType *runways; UInt16 numRunways; Boolean found = false; runways = CpGetRunwayInfo(GetStringFromList(wp->ident,2),&numRunways); if (runways) { UInt16 k; /* * there are 8 icons for the runways, to represent 180 * degrees, which gives 22.5 degrees of coverage per * icon. Quadrupling everything allows us to use whole * numbers for the calculation. * */ runwayIcon = ((runways[0].heading*10 + 5)*4 + 45) / 90; WRAPMAX(runwayIcon, 7); for (k=0;k<numRunways && runways[k].length >= Preferences.runwayLength;k++) { /* * if this runway's width and surface are appropriate, then * we'll use it's heading to determine which icon to * display * */ if (runways[k].width >= Preferences.runwayWidth && ( Preferences.runwaySurface == surfEither || ((Preferences.runwaySurface == surfHard && runways[k].hardSurface) || (Preferences.runwaySurface == surfGrass && !runways[k].hardSurface)))) { runwayIcon = ((runways[0].heading*10 + 5)*4 + 45) / 90; WRAPMAX(runwayIcon, 7); found = true; break; } } PFMemFree(runways); } else { runwayIcon = 8; if (Preferences.runwayWidth == 0 && Preferences.runwayLength == 0) found = true; } /* * NB We don't discard a waypoint based on runway dimensions if a * search string is specified. * */ if (!found && !searchString[0] && displayFilter != all) { /* * discard * */ PFMemFree(wp); continue; } } wpBearingFrom = AvCalcGreatCircleCourse(wp->latitude, wp->longitude, GPS.posn.latitude, GPS.posn.longitude, &wpRange); wpBearing = AvCalcGreatCircleCourse(GPS.posn.latitude, GPS.posn.longitude, wp->latitude, wp->longitude, &wpRange); /* * if we're using magnetic headings, convert the bearing * to use local magnetic variation * */ if (Preferences.useMagnetic) { wpBearing += DEG_TO_RAD((double)GPS.posn.magVarn); wpBearingFrom += wp->magVar; WRAPMAX(wpBearing,2*PI); WRAPMAX(wpBearingFrom,2*PI); } /* * look for the insertion position if necessary * */ if (newProxList->numWaypoints > 0) { /* * it's a good idea to look backwards through this * list, as waypoints are most likely to be added * at the end * */ for (j=newProxList->numWaypoints;j>0 && wpRange < newProxList->waypoints[j-1].range;j--); /* * if this triggers then we haven't found a place to * insert the waypoint - its range is beyond that of * the last waypoint in the list * */ if(j==newProxList->numWaypoints && newProxList->numWaypoints==MAX_PROXWAYPOINTS) { PFMemFree(wp); continue; } } else { j = 0; } /* * j is pointing to the insertion position * * Don't bother shuffling other records if we're adding to the * end of the list * */ if (j<newProxList->numWaypoints) { /* * move the waypoints down the list , set the change * flag to mark them as having been updated. * */ PFMemMove(&newProxList->waypoints[j+1], &newProxList->waypoints[j], sizeof(ProxWaypointType)*(MAX_PROXWAYPOINTS-1-j)); } LOGTAG("Adding:"); LOGSTR(wp->ident); newProxList->waypoints[j].id=swp->wpId; newProxList->waypoints[j].type=WDMGetWaypointType(wp); newProxList->waypoints[j].range=wpRange; newProxList->waypoints[j].bearing=(Int16) round(RAD_TO_DEG(wpBearing)); newProxList->waypoints[j].bearingFrom=(Int16) round(RAD_TO_DEG(wpBearingFrom)); newProxList->waypoints[j].runwayIcon = runwayIcon; StrCopy(newProxList->waypoints[j].ident,wp->ident); StrNCopy(newProxList->waypoints[j].name, GetStringFromList(wp->ident,1), MAX_NAMECHARS-1); newProxList->waypoints[j].name[MAX_NAMECHARS-1] = 0; if (newProxList->numWaypoints<MAX_PROXWAYPOINTS) { /* * we haven't filled the list, so this waypoint *must* * be a new entry in the list. * */ newProxList->numWaypoints++; } PFMemFree(wp); } while (!(stopOnEvent && PFEventAvailable()) && !PFTimerHasExpired(startTime, maxTicks)); LOGINT16(numScanned); LOGEXIT; return false; }