home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / util / develope / blesser.sit / BlessFolder.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-07-23  |  2.5 KB  |  116 lines

  1. /*
  2.  *    BlessFolder.c, vers 0.1, 890718, Ragnar Sundblad, ragge@nada.kth.se
  3.  *    
  4.  *    usage:    BlessFolder    <directory name>
  5.  *    
  6.  *    BlessFolder puts the given directory's id in the Finder Info Parameter no 0
  7.  *    on the directory's volume. That's about it.
  8.  *
  9.  *    ⌐1989 Ragnar Sundblad
  10.  *    May be used bot not sold, or in any other way be made profit on or with.
  11.  *    But please hand it to everyone who wants it. I sometimes find it very handy myself.
  12.  *
  13.  */
  14.  
  15. #include <types.h>
  16. #include <files.h>
  17. #include <stdio.h>
  18.  
  19. #define    HFSSIGN    0x4244
  20.  
  21. int c2pstr(char *c, Str255 p);
  22.  
  23. main(int argc, char *argv[])
  24. {
  25.     OSErr err;
  26.     HParamBlockRec    pbr;
  27.     CInfoPBRec    cir;
  28.     Str255    path;
  29.     
  30.     if(argc != 2) {
  31.         fprintf(stderr, "usage: %s <directory path>\n", argv[0]);
  32.         exit(0);
  33.     }
  34.     
  35.     if(c2pstr(argv[1], path)) {
  36.         fprintf(stderr, "%s: Path name to long, max 255 characters. Extremely sorry.\n", argv[0]);
  37.         exit(1);
  38.     }        
  39.     
  40.     /* Get directory id! */
  41.     
  42.     cir.dirInfo.ioNamePtr = &path;    /* Path */
  43.     cir.dirInfo.ioVRefNum = 0;    /* we don't know */
  44.     cir.dirInfo.ioFDirIndex = 0;    /* nope, we don't want to use this indexing feature */
  45.     cir.dirInfo.ioDrDirID = 0;    /* looks informative, ey? */
  46.     
  47.     
  48.     err = PBGetCatInfo(&cir, false);
  49.     
  50.     if(err) {
  51.         fprintf(stderr, "%s: Error while getting file/directory info: %d\n", argv[0], err);
  52.         exit(1);
  53.     }
  54.     
  55.     if((cir.dirInfo.ioFlAttrib & 0x10) == 0) {
  56.         fprintf(stderr, "%s: Specified path is not a directory!\n", argv[0]);
  57.         exit(1);
  58.     }
  59.     
  60.     /* Now go for the volume information */
  61.     
  62.     pbr.volumeParam.ioVolIndex = -1;    /* Use named path instead */
  63.     pbr.volumeParam.ioNamePtr = &path;    /* path */
  64.     pbr.volumeParam.ioVRefNum = 0;        /* we don't know this */
  65.     
  66.     err = PBHGetVInfo(&pbr, false);
  67.     
  68.     if(err) {
  69.         fprintf(stderr, "%s: Error while getting volume info: %d\n", argv[0], err);
  70.         exit(1);
  71.     }
  72.     
  73.     if(pbr.volumeParam.ioVSigWord != HFSSIGN) {
  74.         fprintf(stderr, "%s: Not a HFS volume!\n", argv[0]);
  75.         exit(1);
  76.     }
  77.     
  78.     /* Ok, put the to-be-blessed-folder's id in finder parameter no 0 */
  79.     
  80.     pbr.volumeParam.ioVFndrInfo[0] = cir.dirInfo.ioDrDirID;
  81.     
  82.     /* Write new volume information down! */
  83.     
  84.     err = PBSetVInfo(&pbr, false);
  85.     
  86.     if(err) {
  87.         fprintf(stderr, "%s: Error while setting volume info: %d\n", argv[0], err);
  88.         exit(1);
  89.     }
  90.     
  91.     /* Yeah! */
  92.     
  93.     exit(0);
  94. }
  95.  
  96. /* c2pstr - copy c string to pascal string, return 0 if ok and 1 if to long */
  97.  
  98. int c2pstr(char *c, Str255 p)
  99. {
  100.     int i;
  101.     
  102.     i = 0;
  103.     do {
  104.         p[i+1] = c[i];
  105.         i++;
  106.     } while((i < 256) && (c[i] != '\0'));
  107.     
  108.     if(i >= 256) {
  109.         return(1);
  110.     }
  111.     
  112.     p[0] = i;
  113.         
  114.     return(0);
  115. }
  116.