home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / out-of-phase-102-c / OutOfPhase 1.02 Source / OutOfPhase Folder / Level 0 Macintosh 29Sep94 / Files.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-23  |  7.4 KB  |  168 lines  |  [TEXT/KAHL]

  1. /* Files.h */
  2.  
  3. #ifndef Included_Files_h
  4. #define Included_Files_h
  5.  
  6. /* Files module depends on: */
  7. /* MiscInfo.h */
  8. /* Audit */
  9. /* Debug */
  10. /* Definitions */
  11. /* Memory */
  12. /* Array */
  13.  
  14. struct FileSpec;
  15. typedef struct FileSpec FileSpec;
  16.  
  17. /* refnum for files that have been opened */
  18. struct FileType;
  19. typedef struct FileType FileType;
  20.  
  21. /* modes that an existing file can be opened as */
  22. typedef enum {eReadOnly EXECUTE(= -7541), eReadAndWrite} FileModesType;
  23.  
  24. /* initialize the file subsystem.  should only be called from Screen */
  25. MyBoolean                        Eep_InitializeFiles(void);
  26.  
  27. /* shutdown the file subsystem. */
  28. void                                Eep_ShutdownFiles(void);
  29.  
  30. /* this is an internal routine -- do not use */
  31. #if DEBUG
  32.     MyBoolean                    Eep_RegisterFileSpec(FileSpec* Spec);
  33.     void                            ValidateFileSpec(FileSpec* Spec);
  34. #else
  35.     #define Eep_RegisterFileSpec(stupid) (True)
  36.     #define ValidateFileSpec(dumb) ((void)0)
  37. #endif
  38.  
  39. /* this routine validates a file specification to make sure it exists */
  40. #if DEBUG
  41.     void                            ValidateFileSpec(FileSpec* Spec);
  42. #else
  43.     #define ValidateFileSpec(dumb) ((void)0)
  44. #endif
  45.  
  46. /* make a copy of a file specification */
  47. /* this routine does not perform operations on file descriptors. */
  48. FileSpec*                        DuplicateFileSpec(FileSpec* Original);
  49.  
  50. /* dispose of a file specification thing */
  51. void                                DisposeFileSpec(FileSpec* Spec);
  52.  
  53. /* create a new temporary file with a known unique name, and return a specification */
  54. /* leading to it.  the creator and filetype codes may or may not be used by */
  55. /* the implementation; the Macintosh does use them.  The file is actually created. */
  56. /* this routine does not perform operations on file descriptors. */
  57. FileSpec*                        NewTempFileSpec(unsigned long Creator, unsigned long FileType);
  58.  
  59. /* create a file spec leading to a named preference file.  The location of preference */
  60. /* files are implementation defined:  UNIX may put them in the user's home directory */
  61. /* with a leading period; Macintosh puts them in a "Preferences" folder.  The file */
  62. /* is actually created unless it already exists.  PrefsFileName is a null terminated */
  63. /* string. */
  64. /* this routine does not perform operations on file descriptors. */
  65. FileSpec*                        NewPrefsFileSpec(char* PrefsFileName, unsigned long Creator,
  66.                                             unsigned long FileType);
  67.  
  68. /* present a dialog box allowing the user to select where to create a new file. */
  69. /* If the file will overwrite an existing file, verify this with the user and then */
  70. /* delete the existing file before returning. DefaultFileName is a null terminated */
  71. /* string. */
  72. /* this routine does not perform operations on file descriptors. */
  73. FileSpec*                        PutFile(char* DefaultFileName);
  74.  
  75. /* let the user find a file with the specified list of types.  Whether the types */
  76. /* are actually used is implementation defined.  The Macintosh uses up to 4 types. */
  77. /* returns NIL if the operation was cancelled. */
  78. /* this routine does not perform operations on file descriptors. */
  79. FileSpec*                        GetFileStandard(long NumFileTypes, unsigned long* ArrayOfFileTypes);
  80.  
  81. /* get any file.  like GetFileStandard except it shows all possible files */
  82. /* this routine does not perform operations on file descriptors. */
  83. FileSpec*                        GetFileAny(void);
  84.  
  85. /* return a pointer containing a non-null-terminated string which is the filename. */
  86. /* this routine does not perform operations on file descriptors. */
  87. char*                                ExtractFileName(FileSpec* Spec);
  88.  
  89. /* create a file.  Returns True if the creation succeeded.  Whether or not */
  90. /* the Creator and FileType codes are used is implementation defined.  The Macintosh */
  91. /* does use them. */
  92. /* this routine does not perform operations on file descriptors. */
  93. MyBoolean                        CreateFile(FileSpec* FileLocation, unsigned long Creator,
  94.                                             unsigned long FileType);
  95.  
  96. /* delete a file.  The file must not be in use.  Returns True if successful */
  97. /* this routine does not perform operations on file descriptors. */
  98. MyBoolean                        DeleteFile(FileSpec* FileLocation);
  99.  
  100. /* Open a file for the specified access.  Returns True if successful. */
  101. /* this routine DOES perform operations on file descriptors. */
  102. MyBoolean                        OpenFile(FileSpec* FileLocation, FileType** FileRefOut,
  103.                                             FileModesType FileAccessMode);
  104.  
  105. /* close a file.  The file must have been open.  Implicitly calls FlushLocalBuffers. */
  106. /* this routine DOES perform operations on file descriptors. */
  107. void                                CloseFile(FileType* FileRef);
  108.  
  109. /* make sure all data associated with a file gets written out */
  110. /* this routine DOES perform operations on file descriptors. */
  111. void                                FlushLocalBuffers(FileType* FileRef);
  112.  
  113. /* write a block of data to the file.  Returns the number of bytes which could */
  114. /* not be written or 0 if all were written. */
  115. /* This is the only function that calls "FSWrite" */
  116. /* this routine DOES perform operations on file descriptors. */
  117. long                                WriteToFile(FileType* FileRef, char* Buffer, long NumBytes);
  118.  
  119. /* read a block of data from the file.  Returns the number of bytes which */
  120. /* could not be read, or 0 if all were read. */
  121. /* This is the only function that calls "FSRead" */
  122. /* this routine DOES perform operations on file descriptors. */
  123. long                                ReadFromFile(FileType* FileRef, char* Buffer, long NumBytesDesired);
  124.  
  125. /* get the current index into the specified file */
  126. /* this routine DOES perform operations on file descriptors. */
  127. long                                GetFilePosition(FileType* FileRef);
  128.  
  129. /* move to a new location within the specified file */
  130. /* if the new location is past the EOF, the EOF will be extended to the new location */
  131. /* this routine DOES perform operations on file descriptors. */
  132. MyBoolean                        SetFilePosition(FileType* FileRef, long NewLocation);
  133.  
  134. /* get the length of the specified file */
  135. /* this routine DOES perform operations on file descriptors. */
  136. long                                GetFileLength(FileType* FileRef);
  137.  
  138. /* set the length of the specified file. */
  139. /* returns True if everything went well or False if there was an error */
  140. /* If the file could not be extended due to lack of disk space, the EOF */
  141. /* remains unchanged */
  142. /* this routine DOES perform operations on file descriptors. */
  143. MyBoolean                        SetFileLength(FileType* FileRef, long NewFileLength);
  144.  
  145. /* copy the entire contents of one file to another.  Data overwrites destination */
  146. /* this routine does not perform operations on file descriptors. */
  147. MyBoolean                        CopyFile(FileType* Original, FileType* Destination);
  148.  
  149. /* create a temporary file in the directory.  the file is actually created so it */
  150. /* exists (so nobody can grab it out from under you). */
  151. /* this routine DOES perform operations on file descriptors. */
  152. FileSpec*                        NewTempFileInTheSameDirectory(FileSpec* SameDirectoryAsThis);
  153.  
  154. /* this operation swaps the data forks for two files.  this is used for safe */
  155. /* saving (i.e. write data before clobbering so that the old file still exists */
  156. /* if the write fails).  You create a new file and write the data to it.  Then you */
  157. /* pass the location of the new file in NewFile and the location of the old */
  158. /* file in OldFile.  The routine swaps the data in the files and the last modified */
  159. /* dates.  If successful, the NewFile (temporary file) will be deleted and the */
  160. /* OldFileRef reference will be updated (it will NOT be the same) and the NewFileRef */
  161. /* will be closed. */
  162. /* NOTE:  the files should be created in the same directory. */
  163. /* this routine DOES perform operations on file descriptors. */
  164. MyBoolean                        SwapFileDataForks(FileSpec* NewAndTempFile, FileSpec* OldFile,
  165.                                             FileType* NewFileRef, FileType** OldFileRef);
  166.  
  167. #endif
  168.