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

Function mod_FindRealFileNameCaseInsenstive

module/module.cpp:579–709  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

577}
578
579bool mod_FindRealFileNameCaseInsenstive(const char *directory, const char *fname, char *new_filename) {
580 bool use_dir = false;
581 char dir_to_use[_MAX_PATH];
582 char file_to_use[_MAX_PATH];
583
584 char *real_dir, *real_file;
585
586 if (directory) {
587 // there is a directory for this path
588 use_dir = true;
589 real_dir = (char *)directory;
590 real_file = (char *)fname;
591 } else {
592 // there may be a directory in the path (*sigh*)
593 char t_ext[256];
594 char t_dir[_MAX_PATH];
595 char t_filename[_MAX_PATH];
596
597 dd_SplitPath(fname, t_dir, t_filename, t_ext);
598 if (strlen(t_dir) > 0) {
599 use_dir = true;
600 strcpy(dir_to_use, t_dir);
601 real_dir = (char *)dir_to_use;
602 strcpy(file_to_use, t_filename);
603 strcat(file_to_use, t_ext);
604 real_file = (char *)file_to_use;
605
606 mprintf(1, "MOD: Found directory \"%s\" in filename, new filename is \"%s\"\n", real_dir, real_file);
607 } else {
608 use_dir = false;
609 real_dir = NULL;
610 real_file = (char *)fname;
611 }
612 }
613
614 // build up a list of filenames in the current directory that begin with the lowercase and
615 // upper case first letter of the filename
616
617 // do the case of the first letter to start
618 int case_val;
619 char wildcard_pattern[_MAX_PATH];
620 int iterations = 1;
621 bool found_match = false;
622
623 if ((real_file[0] >= 'a' && real_file[0] <= 'z') || (real_file[0] >= 'A' && real_file[0] <= 'Z')) {
624 // alpha first letter...we need to do 2 iterations
625 iterations = 2;
626 }
627
628 for (case_val = 0; case_val < iterations; case_val++) {
629 if (case_val) {
630 // do the opposite case of the first letter
631 char first_letter;
632 first_letter = real_file[0];
633 if (first_letter >= 'a' && first_letter <= 'z') {
634 // we need to uppercase the letter
635 first_letter = toupper(first_letter);
636 } else {

Callers 1

mod_LoadModuleFunction · 0.85

Calls 5

dd_SplitPathFunction · 0.85
dd_MakePathFunction · 0.85
StartMethod · 0.45
NextMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected