if (isRelative && inSpec) { outSpec->vRefNum = inSpec->vRefNum; outSpec->parID = inSpec->parID;  if (inSpec->name[0] != 0) { long theDirID;  err = FSpGetDirectoryID(inSpec, &theDirID, &isDirectory);  if (err == noErr  &&  isDirectory) outSpec->parID = theDirID; }  } else { outSpec->vRefNum = 0; outSpec->parID = 0; }   if (inLength < 255) {    myPLstrcpy(ppath, filePath); err = ::FSMakeFSSpec(outSpec->vRefNum, outSpec->parID, ppath, &tempSpec); if (err == noErr || err == fnfErr) *outSpec = tempSpec; } else if (!isRelative) { err = ::FSpLocationFromFullPath(inLength, filePath, outSpec); } else {   err = bdNamErr; }   if (err == noErr) return err;    if (err == dirNFErr || err == bdNamErr) { const char* path = filePath;  if (!isRelative) { outSpec->vRefNum = 0; outSpec->parID = 0; }
if (isRelative && inSpec) { outSpec->vRefNum = inSpec->vRefNum; outSpec->parID = inSpec->parID;  if (inSpec->name[0] != 0) { long theDirID;  err = FSpGetDirectoryID(inSpec, &theDirID, &isDirectory);  if (err == noErr  &&  isDirectory) outSpec->parID = theDirID; else if (err == fnfErr && createDirs) { err = FSpDirCreate(inSpec, smCurrentScript, &theDirID); if (err == noErr) outSpec->parID = theDirID; else if (err == fnfErr) err = dirNFErr; } } } else { outSpec->vRefNum = 0; outSpec->parID = 0; }  if (err) return err;   if (inLength < 255) {    myPLstrcpy(ppath, filePath); err = ::FSMakeFSSpec(outSpec->vRefNum, outSpec->parID, ppath, &tempSpec); if (err == noErr || err == fnfErr) *outSpec = tempSpec; } else if (!isRelative) { err = ::FSpLocationFromFullPath(inLength, filePath, outSpec); } else {   err = bdNamErr; }   if (err == noErr) return err;    if (err == dirNFErr || err == bdNamErr) { const char* path = filePath;  if (!isRelative) { outSpec->vRefNum = 0; outSpec->parID = 0; }
static OSErr ResolvePathAndSpec(const char * filePath, FSSpec *inSpec, PRBool createDirs, FSSpec *outSpec){	OSErr	err = noErr;	size_t	inLength = strlen(filePath);	Boolean isRelative = (inSpec && (strchr(filePath, ':') == 0 || *filePath == ':'));	FSSpec  tempSpec;	Str255  ppath;    Boolean isDirectory;		if (isRelative && inSpec)	{		outSpec->vRefNum = inSpec->vRefNum;		outSpec->parID = inSpec->parID;				if (inSpec->name[0] != 0)		{		    long theDirID;		    			err = FSpGetDirectoryID(inSpec, &theDirID, &isDirectory);					if (err == noErr  &&  isDirectory)				outSpec->parID = theDirID;		}		}	else	{		outSpec->vRefNum = 0;		outSpec->parID = 0;	}		// Try making an FSSpec from the path	if (inLength < 255)	{		// Use tempSpec as dest because if FSMakeFSSpec returns dirNFErr, it		// will reset the dest spec and we'll lose what we determined above.				myPLstrcpy(ppath, filePath);		err = ::FSMakeFSSpec(outSpec->vRefNum, outSpec->parID, ppath, &tempSpec);		if (err == noErr || err == fnfErr)		    *outSpec = tempSpec;	}	else if (!isRelative)	{		err = ::FSpLocationFromFullPath(inLength, filePath, outSpec);	}	else	{	// If the path is relative and >255 characters we need to manually walk the		// path appending each node to the initial FSSpec so to reach that code we		// set the err to bdNamErr and fall into the code below		err = bdNamErr;	}		// If we successfully created a spec then leave	if (err == noErr)		return err;		// We get here when the directory hierarchy needs to be created or we're resolving	// a relative path >255 characters long	if (err == dirNFErr || err == bdNamErr)	{		const char* path = filePath;				if (!isRelative)    // If path is relative, we still need vRefNum & parID.		{		    outSpec->vRefNum = 0;		    outSpec->parID = 0;		}		do		{			// Locate the colon that terminates the node.			// But if we've a partial path (starting with a colon), find the second one.			const char* nextColon = strchr(path + (*path == ':'), ':');			// Well, if there are no more colons, point to the end of the string.			if (!nextColon)				nextColon = path + strlen(path);			// Make a pascal string out of this node.  Include initial			// and final colon, if any!			myPLstrncpy(ppath, path, nextColon - path + 1);						// Use this string as a relative path using the directory created			// on the previous round (or directory 0,0 on the first round).			err = ::FSMakeFSSpec(outSpec->vRefNum, outSpec->parID, ppath, outSpec);			// If this was the leaf node, then we are done.			if (!*nextColon)				break;			// Since there's more to go, we have to get the directory ID, which becomes			// the parID for the next round.			if (err == noErr)			{				// The directory (or perhaps a file) exists. Find its dirID.				long dirID;				err = ::FSpGetDirectoryID(outSpec, &dirID, &isDirectory);				if (!isDirectory)					err = dupFNErr; // oops! a file exists with that name.				if (err != noErr)					break;			// bail if we've got an error				outSpec->parID = dirID;			}			else if ((err == fnfErr) && createDirs)			{				// If we got "file not found" and we're allowed to create directories 				// then we need to create one				err = ::FSpDirCreate(outSpec, smCurrentScript, &outSpec->parID);				// For some reason, this usually returns fnfErr, even though it works.				if (err == fnfErr)					err = noErr;			}			if (err != noErr)				break;			path = nextColon; // next round		} while (true);	}		return err;}