--------------------------------------------------------- PPic_FindFirst Purpose: Given a pilot callsign it will return the first pilot that matches the search. Returns true on success, false if it couldn't find any pilots matching. It returns the pilot id. ----------------------------------------------------------
| 267 | // the pilot id. |
| 268 | // ---------------------------------------------------------- |
| 269 | bool PPic_FindFirst(char *pilot_name, uint16_t *pilot_id) { |
| 270 | if (!PilotPic_init) |
| 271 | return false; |
| 272 | |
| 273 | *pilot_id = 65535; |
| 274 | |
| 275 | int letter_offset = PPic_JumpToPilot(pilot_name); |
| 276 | if (letter_offset == -1) |
| 277 | return false; |
| 278 | |
| 279 | strcpy(PilotPic_find_name, pilot_name); |
| 280 | |
| 281 | char name_buffer[PILOT_STRING_SIZE]; |
| 282 | CFILE *file = PilotPic_database_index_handle; |
| 283 | |
| 284 | // first read in the pilot name |
| 285 | uint8_t name_size; |
| 286 | name_size = cf_ReadByte(file); |
| 287 | if (cfeof(file)) { |
| 288 | return false; |
| 289 | } |
| 290 | cf_ReadBytes((uint8_t *)name_buffer, name_size, file); |
| 291 | name_buffer[name_size] = '\0'; |
| 292 | |
| 293 | // next read in pilot_id |
| 294 | uint16_t pid; |
| 295 | pid = (uint16_t)cf_ReadShort(file); |
| 296 | |
| 297 | // next read past the bitmap name |
| 298 | uint8_t bmp_size; |
| 299 | bmp_size = cf_ReadByte(file); |
| 300 | cfseek(file, bmp_size, SEEK_CUR); |
| 301 | |
| 302 | if (stricmp(name_buffer, pilot_name)) { |
| 303 | return false; // weird |
| 304 | } |
| 305 | |
| 306 | *pilot_id = pid; |
| 307 | PilotPic_find_offset = cftell(file); |
| 308 | |
| 309 | return true; |
| 310 | } |
| 311 | |
| 312 | // ---------------------------------------------------------- |
| 313 | // PPic_FindNext |
no test coverage detected