home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 2 / MacMania 2.toast / Demo's / Tools&Utilities / Programming / Paths ƒ / Paths.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-06  |  7.9 KB  |  210 lines  |  [TEXT/KAHL]

  1. /*******************************************************************************
  2.  * Paths.h
  3.  *
  4.  * Miscellaneous routines for Think C to convert volume and directory
  5.  * information from ids to names, names to ids, find folders/files, etc.
  6.  *
  7.  * Append_File_To_Path        Insert directory/file name at end of path name
  8.  * DirId_To_Path            Returns a path name given a volume and directory id
  9.  * Find_File                Searches a volume for a file or directory name
  10.  * Get_Preferences_Folder    Returns a volume and directory id for the active
  11.  *                            Preferences folder
  12.  * Get_Root_Vol_Info        Returns ref. number and name of default root volume
  13.  * Get_SystemFolder_Path    Returns a path name to the active System Folder
  14.  * Last_File_In_Path        Returns the last file or directory name in a path
  15.  * Path_To_DirId            Returns a volume and directory id for a path name
  16.  * Prepend_Dir_To_Path        Insert directory/volume name in front of path name
  17.  * SFGetDirectory            A standard file dialog to select a directory
  18.  *
  19.  * Version 1.0 • June 1994
  20.  * ©1994 T&T Software • by Tad Woods • 70312,3552 on CompuServe
  21.  *
  22.  * You may use these routines in your own applications. They have been
  23.  * tested but the author will not be responsible for any unforseen damage
  24.  * caused by using these routines. Send problem reports or comments to
  25.  * the address above.
  26.  * Include MacTraps and MacTraps2 in your project.
  27.  *
  28.  *******************************************************************************/
  29.  
  30. #pragma once
  31.  
  32.  
  33.  
  34. /*******************************************************************************
  35.  * Append_File_To_Path
  36.  *
  37.  *  -> fileName        pascal string to append to pathName
  38.  *  -> pathName        pascal string
  39.  * <-  fullFilePath    pascal string containing pathName + : + fileName
  40.  *                    (fullFilePath may be the same string as pathName)
  41.  *
  42.  * Appends a : and fileName to the end of pathName. If pathName is empty,
  43.  * the : is not inserted.
  44.  *
  45.  *******************************************************************************/
  46. void Append_File_To_Path(Str32 fileName, Str255 pathName, Str255 fullFilePath);
  47.  
  48.  
  49.  
  50. /*******************************************************************************
  51.  * DirId_To_Path
  52.  *
  53.  *  -> vRefNum        volume reference number
  54.  *  -> dirId        directory id (0 if vRefNum is a working directory id)
  55.  * <-  rootVolName    on exit, name of the root volume
  56.  * <-  pathToDir    on exit, path name to the directory w/o the root volume name
  57.  *
  58.  * Returns 0 or an error code.
  59.  *
  60.  * Converts vRefNum and dirId to a corresponding path name.
  61.  * After DirId_To_Path, call Prepend_Dir_To_Path(rootVolName, pathToDir,
  62.  * pathToDir) to build the full path name.
  63.  *
  64.  *******************************************************************************/
  65. short DirId_To_Path(short vRefNum, long dirId, Str32 rootVolName, Str255 pathToDir);
  66.  
  67.  
  68.  
  69. /*******************************************************************************
  70.  * Find_File
  71.  *
  72.  *  -> findFile        Pascal string of file or directory name to find
  73.  * <-> vRefNum        on entry, volume ref. number to search (normally 0)
  74.  *                    on exit, volume ref. number where file/directory was found
  75.  * <-> dirId        on entry, directory id to start search (normally 2)
  76.  *                    on exit, directory id where file was found or directory id
  77.  *                    of directory found
  78.  * <-> index        on entry, index in directory to start search (normally 1)
  79.  *                    on exit, index in directory where file/directory was found
  80.  *  -> searchDepth    number of sub-folders deep to search; -1 to search all
  81.  *                    sub-folders and sub-folders within folder; 0 to search
  82.  *                    no sub-folders
  83.  * <-> findDirs        on entry, TRUE to comapre directory names otherwise FALSE
  84.  *                    on exit, TRUE if file found was a directory otherwise FALSE
  85.  * <-> findFiles    on entry, TRUE to compare file names otherwise FALSE
  86.  *                    on exit, TRUE if file found was a file otherwise FALSE
  87.  *
  88.  * Returns an error code or 0 if file or directory was found.
  89.  *
  90.  *******************************************************************************/
  91. short Find_File(Str32 findFile, short *vRefNum, long *dirId, short *index, short searchDepth,
  92.                 Boolean *findDirs, Boolean *findFiles);
  93.  
  94.  
  95.  
  96. /*******************************************************************************
  97.  * Get_Preferences_Folder
  98.  *
  99.  * <-  vRefNum        on exit, volume reference number where Preferences folder
  100.  *                    was found
  101.  * <-  dirId        on exit, directory id where Preferences folder was found
  102.  *
  103.  * Returns 0 or an error code.
  104.  *
  105.  * For System 7 and later vRefNum and dirId refer to the Preferences folder
  106.  * within the System Folder. For System 6 and eariler, they refer to the
  107.  * System Folder itself.
  108.  *
  109.  *******************************************************************************/
  110. short Get_Preferences_Folder(short *vRefNum, long *dirId);
  111.  
  112.  
  113.  
  114. /*******************************************************************************
  115.  * Get_Root_Vol_Info
  116.  *
  117.  * <-  rootVolNum    on entry, pointer to short or NULL
  118.  *                    on exit the volume ref. of the default root volume
  119.  * <-  rootVolName    on entry, string pointer or NULL
  120.  *                    on exit the name of the default root volume
  121.  *
  122.  * Returns 0 or an error code.
  123.  *
  124.  *******************************************************************************/
  125. short Get_Root_Vol_Info(short *rootVolNum, Str32 rootVolName);
  126.  
  127.  
  128.  
  129. /*******************************************************************************
  130.  * Get_SystemFolder_Path
  131.  *
  132.  * <-  rootVolName    on exit, name of the root volume
  133.  * <-  pathToSysDir    on exit, path name to the system folder
  134.  *
  135.  * Returns 0 or an error code.
  136.  *
  137.  *******************************************************************************/
  138. short Get_SystemFolder_Path(Str32 rootVolName, Str255 pathToSysDir);
  139.  
  140.  
  141.  
  142. /*******************************************************************************
  143.  * Last_File_In_Path
  144.  *
  145.  *  -> fullFilePath    pascal string containing full path to a file name
  146.  * <-  fileName        pascal string containing just fileName
  147.  *                    (fileName may be the same string as fullFilePath)
  148.  *
  149.  * Extracts the last directory/file name from a full path name.
  150.  *
  151.  *******************************************************************************/
  152. void Last_File_In_Path(Str255 fullFilePath, Str32 fileName);
  153.  
  154.  
  155.  
  156. /*******************************************************************************
  157.  * Path_To_DirId
  158.  *
  159.  *  -> rootVolName    name of the root volume,
  160.  *                    or "\p" if full path name is already in pathToDir
  161.  *  -> pathToDir    path name to the directory without the root volume name
  162.  * <-  vRefNum        on exit, volume reference number
  163.  * <-  dirId        on exit, directory id
  164.  *
  165.  * Returns 0 or an error code.
  166.  *
  167.  * Converts rootVolName and pathToDir to corresponding vRefNum and dirId.
  168.  *
  169.  *******************************************************************************/
  170. short Path_To_DirId(Str32 rootVolName, Str255 pathToDir, short *vRefNum, long *dirId);
  171.  
  172.  
  173.  
  174. /*******************************************************************************
  175.  * Prepend_Dir_To_Path
  176.  *
  177.  *  -> dirName        pascal string to insert before pathName
  178.  *  -> pathName        pascal string
  179.  * <-  fullDirPath    pascal string containing dirName + : + pathName
  180.  *                    (fullFilePath may be the same string as pathName)
  181.  *
  182.  * Inserts dirName plus a : in front of pathName. If pathName is empty,
  183.  * the : is not inserted.
  184.  *
  185.  *******************************************************************************/
  186. void Prepend_Dir_To_Path(Str32 dirName, Str255 pathName, Str255 fullDirPath);
  187.  
  188.  
  189.  
  190. /*******************************************************************************
  191.  * SFGetDirectory
  192.  *
  193.  *  -> where        global point to display dialog
  194.  *  -> dlogID        resource ID of dialog box to use (this custom resource
  195.  *                    must be in your application's resource file)
  196.  * <-  vRefNum        on exit, volume reference number of folder in view
  197.  * <-  dirId        on exit, directory id of folder in view
  198.  *
  199.  * Returns TRUE if the user selected a directory or FALSE if the user
  200.  * pressed Cancel.
  201.  *
  202.  * Calls SFPGetFile with a custom dialog resource to get the user to
  203.  * select a directory.
  204.  *
  205.  *******************************************************************************/
  206. Boolean SFGetDirectory(Point where, short dlogID, short *vRefNum, long *dirId);
  207.  
  208.  
  209.  
  210.