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

  1. /*******************************************************************************
  2.  * Sample Paths.c
  3.  *
  4.  * This file demonstrates a few of the "Paths" calls.
  5.  * See the Paths.h file for detailed descriptions of each call.
  6.  *
  7.  *******************************************************************************/
  8.  
  9. #include "Paths.h"
  10. #include <stdio.h>
  11.  
  12.  
  13. // local prototypes
  14.  
  15. void InitToolbox(void);
  16. unsigned char * ptocstr(Str255 p, unsigned char *c);
  17.  
  18.  
  19.  
  20. /*******************************************************************************
  21.  * InitToolbox
  22.  *******************************************************************************/
  23.  
  24. void InitToolbox()
  25. {
  26.     InitGraf((Ptr) &qd.thePort);
  27.     InitFonts();
  28.     InitWindows();
  29.     InitMenus();
  30.     FlushEvents(everyEvent,0);
  31.     TEInit();
  32.     InitDialogs(0L);
  33.     InitCursor();
  34. } // InitToolbox
  35.  
  36.  
  37.  
  38. /*******************************************************************************
  39.  * ptocstr
  40.  *******************************************************************************/
  41.  
  42. unsigned char * ptocstr(Str255 p, unsigned char *c)
  43. {
  44.     BlockMove((Ptr)(p + 1), (Ptr)c, p[0]);
  45.     c[p[0]] = '\0';
  46.     return c;
  47. } // ptocstr
  48.  
  49.  
  50.  
  51. /*******************************************************************************
  52.  * main
  53.  *******************************************************************************/
  54.  
  55. main(void)
  56. {
  57.     short            vRefNum;
  58.     long            dirId;
  59.     short            index;
  60.     Boolean            findDirs, findFiles;
  61.     Str32            rootVolName;
  62.     Str255            pathName;
  63.     unsigned char    cstr[256];
  64.     Point            where;
  65.     OSErr            err;
  66.     
  67.     InitToolbox();
  68.     
  69.     
  70.     // get root information
  71.     
  72.     err = Get_Root_Vol_Info(&vRefNum, rootVolName);
  73.     printf("%-30s %s\n\n", "Root Volume:", ptocstr(rootVolName, cstr));
  74.     
  75.     
  76.     // get system folder information
  77.     
  78.     err = Get_SystemFolder_Path(rootVolName, pathName);
  79.     Prepend_Dir_To_Path(rootVolName, pathName, pathName);
  80.     printf("%-30s %s\n\n", "System Folder Path:", ptocstr(pathName, cstr));
  81.  
  82.  
  83.     // get preferences folder information
  84.     
  85.     err = Get_Preferences_Folder(&vRefNum, &dirId);
  86.     DirId_To_Path(vRefNum, dirId, rootVolName, pathName);
  87.     Prepend_Dir_To_Path(rootVolName, pathName, pathName);
  88.     printf("%-30s %s\n\n", "Preferences Folder Path:", ptocstr(pathName, cstr));
  89.  
  90.  
  91.     // find TeachText
  92.     
  93.     vRefNum = 0;
  94.     dirId = fsRtDirID;
  95.     index = 1;
  96.     findDirs = FALSE;
  97.     findFiles = TRUE;
  98.     printf("Searching...\r");
  99.     err = Find_File("\pTeachText", &vRefNum, &dirId, &index, -1, &findDirs, &findFiles);
  100.     if (err == noErr)
  101.     {
  102.         DirId_To_Path(vRefNum, dirId, rootVolName, pathName);
  103.         Prepend_Dir_To_Path(rootVolName, pathName, pathName);
  104.         printf("%-30s %s\n\n", "TeachText found in:", ptocstr(pathName, cstr));
  105.     }
  106.     else
  107.         printf("%-30s\n\n", "TeachText not found.");
  108.     
  109.     
  110.     // get information about a user-selected directory
  111.     
  112.     where.h = where.v = 0;
  113.     if (!SFGetDirectory(where, -4000, &vRefNum, &dirId))
  114.         return 0;
  115.     DirId_To_Path(vRefNum, dirId, rootVolName, pathName);
  116.     Prepend_Dir_To_Path(rootVolName, pathName, pathName);
  117.     printf("%-30s %s\n\n", "User-selected Folder:", ptocstr(pathName, cstr));
  118.         
  119.         
  120.     printf("Click Mouse To Exit.\n");
  121.     while (!Button());
  122.     return 0;
  123. } // main
  124.  
  125.