MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / PPic_JumpToPilot

Function PPic_JumpToPilot

Descent3/PilotPicsAPI.cpp:629–703  ·  view source on GitHub ↗

------------------------------------------------- PPic_JumpToPilot Purpose: Returns an offset into the file to where the the first pilot that matches pilot_name is. -1 is returned if no match --------------------------------------------------

Source from the content-addressed store, hash-verified

627// is returned if no match
628// --------------------------------------------------
629int PPic_JumpToPilot(char *pilot_name) {
630 int lett_offset;
631 int let_pos;
632
633 if (isalpha(pilot_name[0])) {
634 let_pos = toupper(pilot_name[0]) - 'A';
635 } else {
636 let_pos = 26;
637 }
638
639 lett_offset = Alphabet_to_offset[let_pos];
640 if (lett_offset == -1) {
641 // no pilot names begin with this letter
642 return -1;
643 }
644
645 CFILE *file = PilotPic_database_index_handle;
646
647 // jump to that position of the file
648 cfseek(file, lett_offset, SEEK_SET);
649
650 // now try to find the pilot
651 bool done = false;
652 int file_pos;
653 char name_buffer[PILOT_STRING_SIZE];
654
655 while (!done) {
656
657 // save the file position
658 file_pos = cftell(file);
659
660 // first read in the pilot name
661 uint8_t name_size;
662 name_size = cf_ReadByte(file);
663 if (cfeof(file)) {
664 done = true;
665 continue;
666 }
667 cf_ReadBytes((uint8_t *)name_buffer, name_size, file);
668 name_buffer[name_size] = '\0';
669
670 // next read in pilot_id
671 uint16_t pilot_id;
672 pilot_id = (uint16_t)cf_ReadShort(file);
673
674 // next read past the bitmap name
675 uint8_t bmp_size;
676 bmp_size = cf_ReadByte(file);
677 cfseek(file, bmp_size, SEEK_CUR);
678
679 int strcmpret = stricmp(name_buffer, pilot_name);
680
681 switch (strcmpret) {
682 case 0:
683 // we found a match
684 cfseek(file, file_pos, SEEK_SET);
685 return file_pos;
686 default:

Callers 2

PPic_QueryPilotFunction · 0.85
PPic_FindFirstFunction · 0.85

Calls 6

cfseekFunction · 0.85
cftellFunction · 0.85
cf_ReadByteFunction · 0.85
cfeofFunction · 0.85
cf_ReadBytesFunction · 0.85
cf_ReadShortFunction · 0.85

Tested by

no test coverage detected