platform/macclassic.c
changeset 335 1d4720c018c3
parent 316 29a4d12d1dc6
child 362 ac8c846a0a66
equal deleted inserted replaced
334:ad36d8a58b2b 335:1d4720c018c3
   264 
   264 
   265 static OSErr fnameToFSSpecNoAlias(const char *fname, FSSpec *spec)
   265 static OSErr fnameToFSSpecNoAlias(const char *fname, FSSpec *spec)
   266 {
   266 {
   267     OSErr err;
   267     OSErr err;
   268     Str255 str255;
   268     Str255 str255;
   269     int needColon = (strchr(fname, ':')  == NULL);
   269     int needColon = (strchr(fname, ':') == NULL);
   270     int len = strlen(fname) + ((needColon) ? 1 : 0);
   270     int len = strlen(fname) + ((needColon) ? 1 : 0);
   271     if (len > 255)
   271     if (len > 255)
   272         return(bdNamErr);
   272         return(bdNamErr);
   273 
   273 
   274     /* !!! FIXME: What happens with relative pathnames? */
   274     /* !!! FIXME: What happens with relative pathnames? */
   283     err = FSMakeFSSpec(0, 0, str255, spec);
   283     err = FSMakeFSSpec(0, 0, str255, spec);
   284     return(err);
   284     return(err);
   285 } /* fnameToFSSpecNoAlias */
   285 } /* fnameToFSSpecNoAlias */
   286 
   286 
   287 
   287 
   288 /* !!! FIXME: This code is pretty heinous. */
       
   289 static OSErr fnameToFSSpec(const char *fname, FSSpec *spec)
   288 static OSErr fnameToFSSpec(const char *fname, FSSpec *spec)
   290 {
   289 {
   291     Boolean alias = 0;
   290     Boolean alias = 0;
   292     Boolean folder = 0;
   291     Boolean folder = 0;
   293     OSErr err = fnameToFSSpecNoAlias(fname, spec);
   292     OSErr err = fnameToFSSpecNoAlias(fname, spec);
   311         err = fnameToFSSpecNoAlias(path, spec); /* get first dir. */
   310         err = fnameToFSSpecNoAlias(path, spec); /* get first dir. */
   312         BAIL_IF_MACRO(err != noErr, ERR_OS_ERROR, err);
   311         BAIL_IF_MACRO(err != noErr, ERR_OS_ERROR, err);
   313         start = ptr;
   312         start = ptr;
   314         ptr = strchr(start + 1, ':');
   313         ptr = strchr(start + 1, ':');
   315 
   314 
       
   315         /* Now check each element of the path for aliases... */
   316         do
   316         do
   317         {
   317         {
   318             CInfoPBRec infoPB;
   318             CInfoPBRec infoPB;
   319             memset(&infoPB, '\0', sizeof (CInfoPBRec));
   319             memset(&infoPB, '\0', sizeof (CInfoPBRec));
   320             infoPB.dirInfo.ioNamePtr = spec->name;
   320             infoPB.dirInfo.ioNamePtr = spec->name;
   321             infoPB.dirInfo.ioVRefNum = spec->vRefNum;
   321             infoPB.dirInfo.ioVRefNum = spec->vRefNum;
   322             infoPB.dirInfo.ioDrDirID = spec->parID;
   322             infoPB.dirInfo.ioDrDirID = spec->parID;
   323             infoPB.dirInfo.ioFDirIndex = 0;
   323             infoPB.dirInfo.ioFDirIndex = 0;
   324             err = PBGetCatInfoSync(&infoPB);
   324             err = PBGetCatInfoSync(&infoPB);
   325             if (err != noErr)  /* not an alias, really a bogus path. */
   325             if (err != noErr)  /* not an alias, really just a bogus path. */
   326                 return(fnameToFSSpecNoAlias(fname, spec)); /* reset */
   326                 return(fnameToFSSpecNoAlias(fname, spec)); /* reset */
   327 
   327 
   328             if ((infoPB.dirInfo.ioFlAttrib & kioFlAttribDirMask) != 0)
   328             if ((infoPB.dirInfo.ioFlAttrib & kioFlAttribDirMask) != 0)
   329                 spec->parID = infoPB.dirInfo.ioDrDirID;
   329                 spec->parID = infoPB.dirInfo.ioDrDirID;
   330 
   330 
   331             if (ptr != NULL)
   331             if (ptr != NULL)  /* terminate string after next element. */
   332                 *ptr = '\0';
   332                 *ptr = '\0';
       
   333 
   333             *start = strlen(start + 1);  /* make it a pstring. */
   334             *start = strlen(start + 1);  /* make it a pstring. */
   334             err = FSMakeFSSpec(spec->vRefNum, spec->parID,
   335             err = FSMakeFSSpec(spec->vRefNum, spec->parID,
   335                                (const unsigned char *) start, spec);
   336                                (const unsigned char *) start, spec);
   336             if (err != noErr)  /* not an alias, really a bogus path. */
   337             if (err != noErr)  /* not an alias, really a bogus path. */
   337                 return(fnameToFSSpecNoAlias(fname, spec)); /* reset */
   338                 return(fnameToFSSpecNoAlias(fname, spec)); /* reset */
   338 
   339 
   339             err = ResolveAliasFileWithMountFlags(spec, 1, &folder, &alias, 0);
   340             err = ResolveAliasFileWithMountFlags(spec, 1, &folder, &alias, 0);
   340             if (err != noErr)  /* not an alias, really a bogus path. */
   341             if (err != noErr)  /* not an alias, really a bogus path. */
   341                 return(fnameToFSSpecNoAlias(fname, spec)); /* reset */
   342                 return(fnameToFSSpecNoAlias(fname, spec)); /* reset */
   342             start = ptr;
   343 
       
   344             start = ptr;  /* move to the next element. */
   343             if (ptr != NULL)
   345             if (ptr != NULL)
   344                 ptr = strchr(start + 1, ':');                
   346                 ptr = strchr(start + 1, ':');                
   345         } while (start != NULL);
   347         } while (start != NULL);
   346     } /* if */
   348     } /* if */
   347 
   349