platform/os2.c
changeset 420 8869f1432112
parent 416 eadb08626c80
child 423 524e087944b4
equal deleted inserted replaced
419:5bbbb82ec525 420:8869f1432112
   220 
   220 
   221     return(retval);
   221     return(retval);
   222 } /* os2err */
   222 } /* os2err */
   223 
   223 
   224 
   224 
       
   225 /* (be gentle, this function isn't very robust.) */
       
   226 static void cvt_path_to_correct_case(char *buf)
       
   227 {
       
   228     char *fname = buf + 3;            /* point to first element. */
       
   229     char *ptr = strchr(fname, '\\');  /* find end of first element. */
       
   230 
       
   231     buf[0] = toupper(buf[0]);  /* capitalize drive letter. */
       
   232 
       
   233     /*
       
   234      * Go through each path element, and enumerate its parent dir until
       
   235      *  a case-insensitive match is found. If one is (and it SHOULD be)
       
   236      *  then overwrite the original element with the correct case.
       
   237      * If there's an error, or the path has vanished for some reason, it
       
   238      *  won't hurt to have the original case, so we just keep going.
       
   239      */
       
   240     while (fname != NULL)
       
   241     {
       
   242         char spec[CCHMAXPATH];
       
   243         FILEFINDBUF3 fb;
       
   244         HDIR hdir = HDIR_CREATE;
       
   245         ULONG count = 1;
       
   246         APIRET rc;
       
   247 
       
   248         *(fname - 1) = '\0';  /* isolate parent dir string. */
       
   249 
       
   250         strcpy(spec, buf);      /* copy isolated parent dir... */
       
   251         strcat(spec, "\\*.*");  /*  ...and add wildcard search spec. */
       
   252 
       
   253         if (ptr != NULL)  /* isolate element to find (fname is the start). */
       
   254             *ptr = '\0';
       
   255 
       
   256         rc = DosFindFirst(spec, &hdir, FILE_DIRECTORY,
       
   257                           &fb, sizeof (fb), &count, FIL_STANDARD);
       
   258         if (rc == NO_ERROR)
       
   259         {
       
   260             while (count == 1)  /* while still entries to enumerate... */
       
   261             {
       
   262                 if (__PHYSFS_platformStricmp(fb.achName, fname) == 0)
       
   263                 {
       
   264                     strcpy(fname, fb.achName);
       
   265                     break;  /* there it is. Overwrite and stop searching. */
       
   266                 } /* if */
       
   267 
       
   268                 DosFindNext(hdir, &fb, sizeof (fb), &count);
       
   269             } /* while */
       
   270             DosFindClose(hdir);
       
   271         } /* if */
       
   272 
       
   273         *(fname - 1) = '\\';   /* unisolate parent dir. */
       
   274         fname = ptr;           /* point to next element. */
       
   275         if (ptr != NULL)
       
   276         {
       
   277             *ptr = '\\';       /* unisolate element. */
       
   278             ptr = strchr(++fname, '\\');  /* find next element. */
       
   279         } /* if */
       
   280     } /* while */
       
   281 } /* cvt_file_to_correct_case */
       
   282 
       
   283 
   225 static char *baseDir = NULL;
   284 static char *baseDir = NULL;
   226 
   285 
   227 int __PHYSFS_platformInit(void)
   286 int __PHYSFS_platformInit(void)
   228 {
   287 {
   229     char buf[CCHMAXPATH];
   288     char buf[CCHMAXPATH];
   247         } /* if */
   306         } /* if */
   248     } /* for */
   307     } /* for */
   249 
   308 
   250     assert(len > 0);  /* should have been a "x:\\" on the front on string. */
   309     assert(len > 0);  /* should have been a "x:\\" on the front on string. */
   251 
   310 
       
   311     /* The string is capitalized! Figure out the REAL case... */
       
   312     cvt_path_to_correct_case(buf);
       
   313 
   252     baseDir = (char *) malloc(len + 1);
   314     baseDir = (char *) malloc(len + 1);
   253     BAIL_IF_MACRO(baseDir == NULL, ERR_OUT_OF_MEMORY, 0);
   315     BAIL_IF_MACRO(baseDir == NULL, ERR_OUT_OF_MEMORY, 0);
   254     strcpy(baseDir, buf);
   316     strcpy(baseDir, buf);
   255 
       
   256     return(1);  /* success. */
   317     return(1);  /* success. */
   257 } /* __PHYSFS_platformInit */
   318 } /* __PHYSFS_platformInit */
   258 
   319 
   259 
   320 
   260 int __PHYSFS_platformDeinit(void)
   321 int __PHYSFS_platformDeinit(void)