home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / suntar1.cpt / StdFile.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-12  |  3.3 KB  |  136 lines

  1.  
  2. /*----------------------------------------------
  3. #
  4. #    Apple Macintosh Developer Technical Support
  5. #
  6. #    Standard File Sample Application
  7. #
  8. #    StdFile
  9. #
  10. #    StdFile.c    -    C Source
  11. #
  12. #    Copyright ⌐ 1989 Apple Computer, Inc.
  13. #    All rights reserved.
  14. #
  15. #    Versions:
  16. #                1.00                04/89
  17. ------------------------------------------------
  18. */
  19.  
  20. #include "PB_sync.h"
  21.  
  22. void pStrcat(unsigned char *,unsigned char *);
  23. void pStrcpy(unsigned char *,unsigned char *);
  24. OSErr PathNameFromDirID(long,short,char*);
  25. void doForceDirectory(WDPBRec*);
  26. void SetRadioButton(DialogPtr,short,short);
  27. void error_message(char *);
  28.  
  29. void pStrcat(s,t)
  30.     unsigned char *s;
  31.     register unsigned char *t;
  32. {
  33.     register unsigned char *s2;
  34.     register short tLen;
  35.  
  36.     
  37.     s2 = s + *s;
  38.     *s += (tLen = *t);
  39.     if(tLen>255) error_message("Error: Pascal string overflow\n");
  40.     for (++tLen; --tLen; s2[tLen] = t[tLen]);
  41. }
  42.  
  43. void pStrcpy(s,t)
  44.     register unsigned char *s, *t;
  45. {
  46.     register short    tLen;
  47.  
  48.     for (tLen = *t + 1; tLen--; s[tLen] = t[tLen]);
  49. }
  50.  
  51. /** PathNameFromDirID *********************************************************/
  52. /*
  53. /*    Given a DirID and real vRefnum, this routine will create and return the
  54. /*    full pathname that corresponds to it. It does this by calling PBGetCatInfo
  55. /*    for the given directory, and finding out its name and the DirID of its
  56. /*    parent. It the performs the same operation on the parent, sticking ITS
  57. /*    name onto the beginning of the first directory. This whole process is
  58. /*    carried out until we have processed the root directory (identified with
  59. /*    a DirID of 2.
  60. /*
  61. /******************************************************************************/
  62.  
  63. #if 0            /* no more used... */
  64. OSErr PathNameFromDirID(DirID, vRefNum, s)
  65.     long    DirID;
  66.     short    vRefNum;
  67.     char    *s;
  68. {
  69.     CInfoPBRec    block;
  70.     Str255        directoryName;
  71.     OSErr err;
  72.  
  73.     *s = 0;
  74.     block.dirInfo.ioNamePtr = directoryName;
  75.     block.dirInfo.ioDrParID = DirID;
  76.  
  77.     do {
  78.         block.dirInfo.ioVRefNum = vRefNum;
  79.         block.dirInfo.ioFDirIndex = -1;
  80.         block.dirInfo.ioDrDirID = block.dirInfo.ioDrParID;
  81.  
  82.         err = PBGetCatInfoSync(&block);
  83.         if(err!=noErr) return err;
  84.             /* Append a Macintosh style colon (':') */
  85.         pStrcat(directoryName,"\p:");
  86.         pStrcat(directoryName,s);
  87.         pStrcpy(s,directoryName);
  88.     } while (block.dirInfo.ioDrDirID != 2);
  89.  
  90.     return noErr;
  91. }
  92. #endif
  93.  
  94. /** doForceDirectory **********************************************************/
  95. /*
  96. /*    This is a quick sample that shows how to set the initial directory that
  97. /*    Standard File comes up with. Basically, this is done by storing appropriate
  98. /*    values into SFSaveDisk and CurDirStore. 
  99. /*
  100. /******************************************************************************/
  101.  
  102.  
  103. void doForceDirectory(pb)
  104. WDPBRec    *pb;
  105. {
  106.     /* Str255    s; */
  107.  
  108.     pb->ioWDIndex = 0;
  109.     pb->ioWDProcID = 0;
  110.     PBGetWDInfoSync(pb);
  111.  
  112.     CurDirStore = pb->ioWDDirID;
  113.     SFSaveDisk = -pb->ioWDVRefNum;
  114. }
  115.  
  116. /** SetRadioButton ************************************************************/
  117. /*
  118. /*    Handy routine for setting the value of a radio button. Given a dialog
  119. /*    pointer, and item number, and a state, this routine will take care of
  120. /*    the rest.
  121. /*
  122. /******************************************************************************/
  123.  
  124. void SetRadioButton(dialog,item,state)
  125.     DialogPtr    dialog;
  126.     short        item;
  127.     short        state;
  128. {
  129.     short        kind;
  130.     Handle        h;
  131.     Rect        r;
  132.  
  133.     GetDItem(dialog,item,&kind,&h,&r);
  134.     SetCtlValue((ControlHandle)h,state);
  135. }
  136.