home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWFiles / Sources / SLFileSp.cpp < prev    next >
Encoding:
Text File  |  1996-04-25  |  23.5 KB  |  789 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                SLFileSp.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWSOMENV_H
  13. #include "FWSOMEnv.h"
  14. #endif
  15.  
  16. #ifndef FWFILESY_H
  17. #include "FWFileSy.h"
  18. #endif
  19.  
  20. #ifndef FWEXCLIB_H
  21. #include "FWExcLib.h"
  22. #endif
  23.  
  24. #ifndef SLFILPAR_H
  25. #include "SLFilPar.h"
  26. #endif
  27.  
  28. #ifndef FWBNDSTR_H
  29. #include "FWBndStr.h"
  30. #endif
  31.  
  32. #ifndef SLFILESY_H
  33. #include "SLFileSy.h"
  34. #endif
  35.  
  36. #ifndef FWPRIDEB_H
  37. #include "FWPriDeb.h"
  38. #endif
  39.  
  40. #if defined(FW_BUILD_MAC) && !defined(__ERRORS__)
  41. #include <Errors.h>
  42. #endif
  43.  
  44. #if defined(FW_BUILD_MAC) && !defined(__FINDER__)
  45. #include <Finder.h>
  46. #endif
  47.  
  48. #if defined(FW_BUILD_WIN) && !defined(__IO_H)
  49. #include <io.h>
  50. #endif
  51.  
  52. /*
  53.  *  This file was generated by the SOM Compiler.
  54.  *  Generated using: 
  55.  *      SOM Emitter emitxtm.dll: 2.33
  56.  */
  57.  
  58. #define FW_OFileSpecification_Class_Source
  59. #define FW_ODirectorySpecification_Class_Source
  60. class FW_CPrivFileSpecification;
  61. #include "SLFileSp.xih"
  62.  
  63.  
  64. #if defined(__MWERKS__) && GENERATING68K
  65. // A hack to work around a bug
  66. #pragma import list somPrintf,somParentNumResolve,somNewObjectInstance
  67. #endif
  68.  
  69. #ifdef FW_BUILD_MAC
  70. #pragma segment File
  71. #endif
  72.  
  73. //----------------------------------------------------------------------------------------
  74. // Forward definitions
  75. //----------------------------------------------------------------------------------------
  76.  
  77. static void failOnError(short theError);
  78.  
  79.  
  80. //========================================================================================
  81. // FW_CPrivFileSpecification
  82. //    This struct contains the private implementation for FW_OFileSpecification
  83. //========================================================================================
  84.  
  85. class FW_CPrivFileSpecification
  86. {
  87. #ifdef FW_BUILD_WIN
  88. public:
  89.     FW_DECLARE_AUTO(FW_CPrivFileSpecification);
  90.  
  91.     FW_CString fFileInfo;
  92. #endif
  93.  
  94. #ifdef FW_BUILD_MAC
  95. public:
  96.     FW_CPrivFileSpecification() :
  97.         fFileType(FW_kDefaultFileType), 
  98.         fCreatorType(FW_kDefaultCreatorType)
  99.     {
  100.         fFileInfo.vRefNum = 0;
  101.         fFileInfo.parID = 0;
  102.         fFileInfo.name[0] = 0;
  103.     }
  104.  
  105.     FSSpec fFileInfo;
  106.     OSType fFileType;
  107.     OSType fCreatorType;
  108. #endif 
  109. };
  110.  
  111.  
  112. #ifdef FW_BUILD_WIN
  113. FW_DEFINE_AUTO(FW_CPrivFileSpecification);
  114. #endif 
  115.  
  116.  
  117.  
  118. //========================================================================================
  119. //    class FW_OFileSpecification
  120. //========================================================================================
  121.  
  122.  
  123. //----------------------------------------------------------------------------------------
  124. //    FW_OFileSpecification__InitFromFileName
  125. //  Create a file specification from a full or partial pathname.  In the case of
  126. //    a partial pathname, the specification will use the current default
  127. //    directory to build a full pathname.
  128. //----------------------------------------------------------------------------------------
  129.  
  130. SOM_Scope void  SOMLINK FW_OFileSpecification__InitFromFileName(FW_OFileSpecification *somSelf, Environment *ev,
  131.         FW_HString fileNameRep)
  132. {
  133.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  134.  
  135.     FW_SOM_TRY
  136.     {
  137.         FW_CPrivFileSpecification& rep = *somThis->fRep;
  138.         FW_CString fileName(fileNameRep);
  139.  
  140. #ifdef FW_BUILD_WIN
  141.         rep.fFileInfo = fileName;
  142.         FW_PrivFileSystemParser_WinExpandPartialPath(rep.fFileInfo);
  143.  
  144.         // Verify that path exists.
  145.         FW_CString tempString;
  146.         if (!FW_PrivFileSystemParser_WinGetPathName(rep.fFileInfo, tempString))
  147.             failOnError(FW_kPathNotFound);
  148.  
  149.         FW_SOMEnvironment ev;
  150.         if (!FW_PrivFileSystem_WinPathExists(ev, tempString))
  151.             failOnError(FW_kPathNotFound);
  152. #endif
  153.  
  154. #ifdef FW_BUILD_MAC
  155.         FW_PlatformError theError = FW_xNoError;
  156.         Str255 macFileName;
  157.     
  158.         rep.fFileType = FW_kDefaultFileType; 
  159.         rep.fCreatorType = FW_kDefaultCreatorType;
  160.  
  161.         fileName.ExportPascal(macFileName);
  162.  
  163.         theError = ::FSMakeFSSpec(0, 0, macFileName, &rep.fFileInfo);
  164.         if ((theError != FW_xNoError) && (theError != FW_xNoFileFound))
  165.         {
  166.             rep.fFileInfo.vRefNum = 0;
  167.             rep.fFileInfo.parID = 0;
  168.             FW_ASSERT(fileName.GetByteLength() < 64);
  169.             fileName.ExportPascal(rep.fFileInfo.name);
  170.             FW_Failure(theError);
  171.         }
  172.     #endif
  173.     }
  174.     FW_SOM_CATCH
  175. }
  176.  
  177.  
  178. //----------------------------------------------------------------------------------------
  179. //    FW_OFileSpecification__InitFromDirectoryAndName
  180. //  Create a file specification from a directory and a file name.  The file name
  181. //    should include any extensions that might be necessary.
  182. //----------------------------------------------------------------------------------------
  183.  
  184. SOM_Scope void  SOMLINK FW_OFileSpecification__InitFromDirectoryAndName(FW_OFileSpecification *somSelf, Environment *ev,
  185.         FW_ODirectorySpecification* directory,
  186.         FW_HString fileNameRep)
  187. {
  188.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  189.  
  190.     FW_SOM_TRY
  191.     {
  192.         FW_CString fileName(fileNameRep);
  193.         FW_CPrivFileSpecification& rep = *somThis->fRep;
  194.  
  195. #ifdef FW_BUILD_WIN
  196.         directory->GetFullPath(ev, rep.fFileInfo);
  197.  
  198.         if (fileName.GetByteLength() > 0)
  199.             FW_PrivFileSystemParser_AddDelimiter(rep.fFileInfo);
  200.  
  201.         rep.fFileInfo += fileName;
  202.  
  203.         // Verify that path exists.
  204.         FW_CString tempString;
  205.         if (!FW_PrivFileSystemParser_WinGetPathName(rep.fFileInfo, tempString))
  206.             failOnError(FW_kPathNotFound);
  207.  
  208.         FW_SOMEnvironment ev;
  209.         if (!FW_PrivFileSystem_WinPathExists(ev, tempString))
  210.             failOnError(FW_kPathNotFound);
  211. #endif
  212.  
  213. #ifdef FW_BUILD_MAC
  214.         FW_PlatformError theError = FW_xNoError;
  215.         Str255 macFileName;
  216.         FW_CString255 partialPathName;
  217.  
  218.         rep.fFileType = FW_kDefaultFileType; 
  219.         rep.fCreatorType = FW_kDefaultCreatorType;
  220.  
  221.         directory->MacGetFSSpec(ev, &rep.fFileInfo);
  222.         partialPathName.ReplaceAll((FW_PascalChar*)&rep.fFileInfo.name);
  223.         partialPathName.Prepend(&FW_kPathDelimiter, 1);
  224.  
  225.         FW_PrivFileSystemParser_AddDelimiter(partialPathName);
  226.         partialPathName += fileName;
  227.         partialPathName.ExportPascal(macFileName);
  228.  
  229.         theError = ::FSMakeFSSpec(rep.fFileInfo.vRefNum, rep.fFileInfo.parID, macFileName, &rep.fFileInfo);
  230.         if ((theError != FW_xNoError) && (theError != FW_xNoFileFound))
  231.         {
  232.             FSSpec dirFSSpec;
  233.             directory->MacGetFSSpec(ev, &dirFSSpec);
  234.             
  235.             rep.fFileInfo.vRefNum = dirFSSpec.vRefNum;
  236.             rep.fFileInfo.parID = dirFSSpec.parID;
  237.             
  238.             FW_ASSERT(fileName.GetByteLength() < 64);
  239.             partialPathName.ExportPascal(rep.fFileInfo.name);
  240.             
  241.             FW_Failure(theError);
  242.         }
  243. #endif
  244.     }
  245.     FW_SOM_CATCH
  246. }
  247.  
  248.  
  249. //----------------------------------------------------------------------------------------
  250. //    FW_OFileSpecification__GetName
  251. //  Get the name of the file.
  252. //----------------------------------------------------------------------------------------
  253.  
  254. SOM_Scope void  SOMLINK FW_OFileSpecification__GetName(FW_OFileSpecification *somSelf, Environment *ev,
  255.         FW_HString* fileNameRep)
  256. {
  257.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  258.  
  259.     FW_SOM_TRY
  260.     {
  261.         FW_CString fileName(*fileNameRep);
  262.         FW_CPrivFileSpecification& rep = *somThis->fRep;
  263. //        FW_PlatformError theError = FW_xNoError;
  264.  
  265. #ifdef FW_BUILD_WIN
  266.         FW_CString parsedName;
  267.  
  268.         if (FW_PrivFileSystemParser_GetFileName(rep.fFileInfo, parsedName))
  269.             fileName = parsedName;
  270.         else
  271.             failOnError(FW_kBadFileName);
  272. #endif
  273.  
  274. #ifdef FW_BUILD_MAC
  275.         fileName.ReplaceAll(rep.fFileInfo.name);
  276. #endif
  277.     }
  278.     FW_SOM_CATCH
  279. }
  280.  
  281.  
  282. //----------------------------------------------------------------------------------------
  283. //    FW_OFileSpecification__GetParentDirectory
  284. //  Returns the path information for this file.
  285. //----------------------------------------------------------------------------------------
  286.  
  287. SOM_Scope FW_ODirectorySpecification*  SOMLINK FW_OFileSpecification__GetParentDirectory(FW_OFileSpecification *somSelf, Environment *ev)
  288. {
  289.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  290.  
  291.     FW_SOM_TRY
  292.     {
  293.         FW_CPrivFileSpecification& rep = *somThis->fRep;
  294.         FW_ODirectorySpecification* returnDirectory = new FW_ODirectorySpecification;
  295.  
  296. #ifdef FW_BUILD_WIN
  297.         FW_CString tempPathName;
  298.  
  299.         if (FW_PrivFileSystemParser_WinGetPathName(rep.fFileInfo, tempPathName))
  300.         {
  301.             returnDirectory->InitFromFileName(ev, tempPathName);
  302.         }
  303.         else
  304.         {
  305.             // Path should already have been verified.
  306.             failOnError(FW_kPathNotFound);
  307.         }
  308. #endif
  309.  
  310. #ifdef FW_BUILD_MAC    
  311.         failOnError(FW_PrivFileSystemParser_MacGenerateDirectory(rep.fFileInfo.vRefNum, rep.fFileInfo.parID, returnDirectory));
  312. #endif
  313.  
  314.         return returnDirectory;
  315.     }
  316.     FW_SOM_CATCH
  317.     return 0;
  318. }
  319.  
  320.  
  321. //----------------------------------------------------------------------------------------
  322. //    FW_OFileSpecification__GetFullPath
  323. //  Returns the fully qualified path and file name for this file.  The user should
  324. //    pass in a dynamic string so as to guarantee that the path will fit inside
  325. //    it.
  326. //----------------------------------------------------------------------------------------
  327.  
  328. SOM_Scope void  SOMLINK FW_OFileSpecification__GetFullPath(FW_OFileSpecification *somSelf, Environment *ev,
  329.         FW_HString* fullPathNameRep)
  330. {
  331.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  332.  
  333.     FW_SOM_TRY
  334.     {
  335.         FW_CString fullPathName(*fullPathNameRep);
  336.         FW_CPrivFileSpecification& rep = *somThis->fRep;
  337.  
  338. #ifdef FW_BUILD_WIN
  339.         fullPathName = rep.fFileInfo;
  340. #endif
  341.  
  342. #ifdef FW_BUILD_MAC
  343.         fullPathName.ReplaceAll(rep.fFileInfo.name);
  344.         FW_PlatformError theError = FW_xNoError;
  345.     
  346.         theError = FW_PrivFileSystemParser_MacGenerateFullPathName(rep.fFileInfo.vRefNum, rep.fFileInfo.parID, fullPathName);
  347.         failOnError(theError);
  348. #endif
  349.     }
  350.     FW_SOM_CATCH
  351. }
  352.  
  353.  
  354. //----------------------------------------------------------------------------------------
  355. //    FW_OFileSpecification__IsSameAs
  356. //  Does this file represent the same file as theOtherFile.
  357. //----------------------------------------------------------------------------------------
  358.  
  359. SOM_Scope FW_Boolean  SOMLINK FW_OFileSpecification__IsSameAs(FW_OFileSpecification *somSelf, Environment *ev,
  360.         FW_OFileSpecification* theOtherFile)
  361. {
  362.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  363.  
  364.     FW_SOM_TRY
  365.     {
  366.         FW_CPrivFileSpecification& rep = *somThis->fRep;
  367.         FW_CPrivFileSpecification& otherRep = *FW_OFileSpecificationGetData(theOtherFile)->fRep;
  368.  
  369. #ifdef FW_BUILD_WIN
  370.         FW_CString tempString1(rep.fFileInfo);
  371.         FW_CString tempString2(otherRep.fFileInfo);
  372.     
  373.         tempString1.ToUpper();
  374.         tempString2.ToUpper();
  375.         return (tempString1 == tempString2);
  376. #endif
  377.  
  378. #ifdef FW_BUILD_MAC
  379.         if ((rep.fFileInfo.vRefNum == otherRep.fFileInfo.vRefNum) && (rep.fFileInfo.parID == otherRep.fFileInfo.parID))
  380.         {
  381.             if (rep.fFileType == otherRep.fFileType && rep.fCreatorType == otherRep.fCreatorType)
  382.             {
  383.                 // [jkp] this is a clumsy way to do the comparison.  Can the strings be inited 
  384.                 // with the fFileInfo.name fields?
  385.                 FW_CString fileName1;
  386.                 FW_CString fileName2;
  387.         
  388.                 fileName1.ReplaceAll((FW_PascalChar*)&rep.fFileInfo.name);
  389.                 fileName2.ReplaceAll((FW_PascalChar*)&otherRep.fFileInfo.name);
  390.         
  391.                 fileName1.ToUpper();
  392.                 fileName2.ToUpper();
  393.                 return (fileName1 == fileName2);
  394.             }
  395.         }
  396.     
  397.         return (FALSE);
  398. #endif
  399.     }
  400.     FW_SOM_CATCH
  401.     return 0;
  402. }
  403.  
  404.  
  405. //----------------------------------------------------------------------------------------
  406. //    FW_OFileSpecification__AssignOFileSpecification
  407. //  Copy all of the file information from theOtherFile so that this file spec
  408. //    represents the same file.
  409. //----------------------------------------------------------------------------------------
  410.  
  411. SOM_Scope void  SOMLINK FW_OFileSpecification__AssignOFileSpecification(FW_OFileSpecification *somSelf, Environment *ev,
  412.         FW_OFileSpecification* theOtherFile)
  413. {
  414.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  415.  
  416.     FW_SOM_TRY
  417.     {
  418.         FW_CPrivFileSpecification& rep = *somThis->fRep;
  419.         FW_CPrivFileSpecification& otherRep = *FW_OFileSpecificationGetData(theOtherFile)->fRep;
  420.  
  421.         rep.fFileInfo = otherRep.fFileInfo;
  422. #ifdef FW_BUILD_MAC
  423.         rep.fFileType = otherRep.fFileType;
  424.         rep.fCreatorType = otherRep.fCreatorType;
  425. #endif
  426.     }
  427.     FW_SOM_CATCH
  428. }
  429.  
  430.  
  431. //----------------------------------------------------------------------------------------
  432. //    FW_OFileSpecification__AssignFileName
  433. //  Change the name of this file to fileName.  fileName may be a partial pathName.
  434. //  This does not change any of the existing path information.
  435. //----------------------------------------------------------------------------------------
  436.  
  437. SOM_Scope void  SOMLINK FW_OFileSpecification__AssignFileName(FW_OFileSpecification *somSelf, Environment *ev,
  438.         FW_HString fileNameRep)
  439. {
  440.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  441.  
  442.     FW_SOM_TRY
  443.     {
  444.         FW_CString fileName(fileNameRep);
  445.         FW_CPrivFileSpecification& rep = *somThis->fRep;
  446. #ifdef FW_BUILD_WIN
  447.         FW_CString tempPathName;
  448.  
  449.         if (FW_PrivFileSystemParser_WinGetPathName(rep.fFileInfo, tempPathName))
  450.         {
  451.             FW_PrivFileSystemParser_AddDelimiter(tempPathName);
  452.             rep.fFileInfo = tempPathName;
  453.         }
  454.  
  455.         rep.fFileInfo += fileName;
  456.     
  457.         // Verify that path exists.
  458.         FW_CString tempString;
  459.         if (!FW_PrivFileSystemParser_WinGetPathName(rep.fFileInfo, tempString))
  460.             failOnError(FW_kPathNotFound);
  461.  
  462.         FW_SOMEnvironment ev;
  463.         if (!FW_PrivFileSystem_WinPathExists(ev, tempString))
  464.             failOnError(FW_kPathNotFound);
  465. #endif
  466.  
  467. #ifdef FW_BUILD_MAC
  468.         FW_PlatformError theError = FW_xNoError;
  469.         short vRefNum = rep.fFileInfo.vRefNum;
  470.         long dirID = rep.fFileInfo.parID;
  471.         Str255 macFileName;
  472.     
  473.         rep.fFileType = FW_kDefaultFileType; 
  474.         rep.fCreatorType = FW_kDefaultCreatorType;
  475.  
  476.         fileName.ExportPascal(macFileName);
  477.  
  478.         theError = ::FSMakeFSSpec(vRefNum, dirID, macFileName, &rep.fFileInfo);
  479.         if ((theError != FW_xNoError) && (theError != FW_xNoFileFound))
  480.         {
  481.             rep.fFileInfo.vRefNum = vRefNum;
  482.             rep.fFileInfo.parID = dirID;
  483.             FW_ASSERT(fileName.GetByteLength() < 64);
  484.             fileName.ExportPascal(rep.fFileInfo.name);
  485.             FW_Failure(theError);
  486.         }
  487. #endif
  488.     }
  489.     FW_SOM_CATCH
  490. }
  491.  
  492.  
  493. #ifdef FW_BUILD_WIN
  494. //----------------------------------------------------------------------------------------
  495. //    FW_OFileSpecification__WinGetDrive
  496. //----------------------------------------------------------------------------------------
  497.  
  498. SOM_Scope char  SOMLINK FW_OFileSpecification__WinGetDrive(FW_OFileSpecification *somSelf, Environment *ev)
  499. {
  500.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  501.  
  502.     FW_SOM_TRY
  503.     {
  504.         FW_CPrivFileSpecification& rep = *somThis->fRep;
  505.         FW_CharacterPosition colonPosition = -1;
  506.         FW_CString driveName;
  507.         FW_Char driveLetter = '\0';
  508.  
  509.         // If there's no drive information in the path, get the default drive information.
  510.         if (!FW_PrivFileSystemParser_WinGetDrivePath(rep.fFileInfo, driveName))
  511.             failOnError(FW_kBadFileName);
  512.  
  513.         if (!driveName.FindCharacter(FW_kDriveDelimiter, colonPosition))
  514.             failOnError(FW_kNoSuchVolume);
  515.  
  516.         if (colonPosition > 1)
  517.             failOnError(FW_kNoSuchVolume);
  518.         
  519.         driveName.ToLower();
  520.     
  521.         driveLetter = (char) driveName[(FW_CharacterPosition)(colonPosition - 1)];
  522.  
  523.         if ((driveLetter < 'a') || (driveLetter > 'z'))
  524.             failOnError(FW_kBadFileName);
  525.  
  526.         return (driveLetter);
  527.     }
  528.     FW_SOM_CATCH
  529.     return 0;
  530. }
  531. #endif
  532.  
  533.  
  534. #ifdef FW_BUILD_WIN
  535. //----------------------------------------------------------------------------------------
  536. //    FW_OFileSpecification__WinGetExtension
  537. //----------------------------------------------------------------------------------------
  538.  
  539. SOM_Scope void  SOMLINK FW_OFileSpecification__WinGetExtension(FW_OFileSpecification *somSelf, Environment *ev,
  540.         FW_HString* extensionRep)
  541. {
  542.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  543.  
  544.     FW_SOM_TRY
  545.     {
  546.         FW_CString extension(*extensionRep);
  547.         FW_CPrivFileSpecification& rep = *somThis->fRep;
  548.  
  549.         if (!FW_PrivFileSystemParser_GetExtension(rep.fFileInfo, extension))
  550.             extension = "";
  551.     }
  552.     FW_SOM_CATCH
  553. }
  554. #endif
  555.  
  556.  
  557. #ifdef FW_BUILD_WIN
  558. //----------------------------------------------------------------------------------------
  559. //    FW_OFileSpecification__WinSetExtension
  560. //----------------------------------------------------------------------------------------
  561.  
  562. SOM_Scope void  SOMLINK FW_OFileSpecification__WinSetExtension(FW_OFileSpecification *somSelf, Environment *ev,
  563.         FW_HString extensionRep)
  564. {
  565.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  566.  
  567.     FW_SOM_TRY
  568.     {
  569.         FW_CString extension(extensionRep);
  570.         FW_CPrivFileSpecification& rep = *somThis->fRep;
  571.         FW_CString newFileInfo;
  572.  
  573.         FW_PrivFileSystemParser_ChangeExtension(rep.fFileInfo, extension, newFileInfo);
  574.         rep.fFileInfo = newFileInfo;
  575.     }
  576.     FW_SOM_CATCH
  577. }
  578. #endif
  579.  
  580.  
  581. #ifdef FW_BUILD_MAC
  582. //----------------------------------------------------------------------------------------
  583. //    FW_OFileSpecification__AssignFileSpec
  584. //  This specifier will now represent the file described by macSpec.
  585. //----------------------------------------------------------------------------------------
  586.  
  587. SOM_Scope void  SOMLINK FW_OFileSpecification__AssignFileSpec(FW_OFileSpecification *somSelf, Environment *ev,
  588.         FSSpec* macSpec)
  589. {
  590. FW_UNUSED(ev);
  591.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  592.     FW_CPrivFileSpecification& rep = *somThis->fRep;
  593.  
  594.     rep.fFileInfo = *macSpec;
  595.     rep.fFileType = FW_kDefaultFileType; 
  596.     rep.fCreatorType = FW_kDefaultCreatorType;
  597. }
  598. #endif
  599.  
  600.  
  601. #ifdef FW_BUILD_MAC
  602. //----------------------------------------------------------------------------------------
  603. //    FW_OFileSpecification__MacGetFSSpec
  604. //  Return a Macintosh FSSpec that points to this file.
  605. //----------------------------------------------------------------------------------------
  606.  
  607. SOM_Scope void  SOMLINK FW_OFileSpecification__MacGetFSSpec(FW_OFileSpecification *somSelf, Environment *ev,
  608.         FSSpec* macSpec)
  609. {
  610. FW_UNUSED(ev);
  611.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  612.     FW_CPrivFileSpecification& rep = *somThis->fRep;
  613.  
  614.     *macSpec = rep.fFileInfo;
  615. }
  616. #endif
  617.  
  618.  
  619. #ifdef FW_BUILD_MAC
  620. //----------------------------------------------------------------------------------------
  621. //    FW_OFileSpecification__MacSetTypeAndCreator
  622. //----------------------------------------------------------------------------------------
  623.  
  624. SOM_Scope void  SOMLINK FW_OFileSpecification__MacSetTypeAndCreator(FW_OFileSpecification *somSelf, Environment *ev,
  625.         FW_ResourceType aFileType,
  626.         FW_ResourceType aCreatorType)
  627. {
  628. FW_UNUSED(ev);
  629.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  630.     FW_CPrivFileSpecification& rep = *somThis->fRep;
  631.  
  632.     rep.fFileType = aFileType; 
  633.     rep.fCreatorType = aCreatorType;
  634. }
  635. #endif
  636.  
  637.  
  638. #ifdef FW_BUILD_MAC
  639. //----------------------------------------------------------------------------------------
  640. //    FW_OFileSpecification__MacGetTypeAndCreator
  641. //  Accessors to the type and creator of the file specification.
  642. //----------------------------------------------------------------------------------------
  643.  
  644. SOM_Scope void  SOMLINK FW_OFileSpecification__MacGetTypeAndCreator(FW_OFileSpecification *somSelf, Environment *ev,
  645.         FW_ResourceType* aFileType,
  646.         FW_ResourceType* aCreatorType)
  647. {
  648. FW_UNUSED(ev);
  649.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  650.     FW_CPrivFileSpecification& rep = *somThis->fRep;
  651.  
  652.     *aFileType = rep.fFileType; 
  653.     *aCreatorType = rep.fCreatorType;
  654. }
  655. #endif
  656.  
  657.  
  658. //----------------------------------------------------------------------------------------
  659. //    FW_OFileSpecification__somInit
  660. //----------------------------------------------------------------------------------------
  661.  
  662. SOM_Scope void  SOMLINK FW_OFileSpecification__somInit(FW_OFileSpecification *somSelf)
  663. {
  664.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  665.  
  666.     FW_OFileSpecification_parent_SOMObject_somInit(somSelf);
  667.  
  668.     somThis->fRep = new FW_CPrivFileSpecification;
  669. }
  670.  
  671.  
  672. //----------------------------------------------------------------------------------------
  673. //    FW_OFileSpecification__somUninit
  674. //----------------------------------------------------------------------------------------
  675.  
  676. SOM_Scope void  SOMLINK FW_OFileSpecification__somUninit(FW_OFileSpecification *somSelf)
  677. {
  678.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  679.  
  680.     FW_SOM_UNINIT_TRY
  681.     {
  682.         delete somThis->fRep;
  683.  
  684.         FW_OFileSpecification_parent_SOMObject_somUninit(somSelf);
  685.     }
  686.     FW_SOM_UNINIT_CATCH
  687. }
  688.  
  689.  
  690.  
  691. //========================================================================================
  692. //    class FW_ODirectorySpecification
  693. //========================================================================================
  694.  
  695.  
  696. //----------------------------------------------------------------------------------------
  697. //    FW_ODirectorySpecification__AppendDirectoryName
  698. //  Add directoryName to the end of this path.  This routine will add a path
  699. //    separator so that the user does not need to.  The remaining path information
  700. //    may specify a subdirectory or parent directory, but must start from this
  701. //    directory.
  702. //----------------------------------------------------------------------------------------
  703.  
  704. SOM_Scope void  SOMLINK FW_ODirectorySpecification__AppendDirectoryName(FW_ODirectorySpecification *somSelf, Environment *ev,
  705.         FW_HString directoryNameRep)
  706. {
  707.     /* FW_ODirectorySpecificationData *somThis = FW_ODirectorySpecificationGetData(somSelf); */
  708.     FW_ODirectorySpecificationMethodDebug("FW_ODirectorySpecification","FW_ODirectorySpecification__AppendDirectoryName");
  709.  
  710.     FW_SOM_TRY
  711.     {
  712.         FW_CString directoryName(directoryNameRep);
  713.         FW_CString tempName;
  714.  
  715.         // Get our current name
  716.         somSelf->GetName(ev, tempName);
  717.  
  718. #ifdef FW_BUILD_MAC
  719.         // Need to add a leading delimiter to indicate this is a partial path.
  720.         tempName.Prepend(&FW_kPathDelimiter, 1);
  721. #endif
  722.  
  723.         tempName += FW_kPathDelimiter;
  724.         tempName += directoryName;
  725.  
  726.         // Set the name to that new string
  727.         somSelf->AssignFileName(ev, tempName);
  728.     }
  729.     FW_SOM_CATCH
  730. }
  731.  
  732.  
  733. //----------------------------------------------------------------------------------------
  734. //    FW_ODirectorySpecification__GetFullPath
  735. //----------------------------------------------------------------------------------------
  736.  
  737. SOM_Scope void  SOMLINK FW_ODirectorySpecification__GetFullPath(FW_ODirectorySpecification *somSelf, Environment *ev,
  738.         FW_HString* fullPathNameRep)
  739. {
  740.     /* FW_ODirectorySpecificationData *somThis = FW_ODirectorySpecificationGetData(somSelf); */
  741.     FW_ODirectorySpecificationMethodDebug("FW_ODirectorySpecification","FW_ODirectorySpecification__GetFullPath");
  742.  
  743.     FW_SOM_TRY
  744.     {
  745.         FW_CString fullPathName(*fullPathNameRep);
  746.         FW_ODirectorySpecification_parent_FW_OFileSpecification_GetFullPath(somSelf,ev,fullPathName);
  747.         FW_PrivFileSystemParser_AddDelimiter(fullPathName);
  748.     }
  749.     FW_SOM_CATCH
  750. }
  751.  
  752.  
  753. //----------------------------------------------------------------------------------------
  754. //    FW_ODirectorySpecification__somInit
  755. //----------------------------------------------------------------------------------------
  756.  
  757. SOM_Scope void  SOMLINK FW_ODirectorySpecification__somInit(FW_ODirectorySpecification *somSelf)
  758. {
  759.     // FW_ODirectorySpecificationData *somThis = FW_ODirectorySpecificationGetData(somSelf);
  760.     FW_ODirectorySpecificationMethodDebug("FW_ODirectorySpecification","FW_ODirectorySpecification__somInit");
  761.  
  762.     FW_ODirectorySpecification_parent_FW_OFileSpecification_somInit(somSelf);
  763.  
  764.     // Assign the null directory to this item
  765.     FW_SOMEnvironment ev;
  766.  
  767.     FW_SOM_TRY
  768.     {
  769.         FW_CString nullPath;
  770.         somSelf->InitFromFileName(ev, nullPath);
  771.     }
  772.     FW_SOM_CATCH
  773. }
  774.  
  775.  
  776. //----------------------------------------------------------------------------------------
  777. //    failOnError
  778. //----------------------------------------------------------------------------------------
  779.  
  780. static void failOnError(short theError)
  781. {
  782.     // JEL: I don't know why kNoFileFound is not an error.
  783.     // Ideally, we should eliminate this method entirely, and just
  784.     // call FW_FailOnError directly, and only check for kNoFileFound
  785.     // where it is definitely not an error.
  786.     if (theError != FW_xNoFileFound)
  787.         FW_FailOnError(theError);
  788. }
  789.