home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / lisp / mcl / 1061 < prev    next >
Encoding:
Text File  |  1992-07-23  |  5.2 KB  |  144 lines

  1. Newsgroups: comp.lang.lisp.mcl
  2. Path: sparky!uunet!usc!sdd.hp.com!caen!destroyer!ubc-cs!unixg.ubc.ca!prodigy.bc.ca!news
  3. From: Steve Wart <swart@prodigy.bc.ca>
  4. Subject: Toolbox access with MCL (relatively long)
  5. Message-ID: <1992Jul22.220633.11051@prodigy.bc.ca>
  6. Summary: File Manager Problems
  7. Sender: news@prodigy.bc.ca
  8. Organization: PTC Vancouver
  9. X-Useragent: Nuntius v1.0
  10. Date: Wed, 22 Jul 1992 22:06:33 GMT
  11. Lines: 131
  12.  
  13.  
  14.  
  15. I've been trying to access the low-level file manager calls, with mixed
  16. results.  For example, I wrote functions to remedy what I saw as
  17. inconsistencies
  18. in the documentation in the MCL 2.0b1 reference manual.  First, there
  19. doesn't
  20. seem to be any built-in way to get the name of a volume, given that you
  21. have
  22. a valid volume number (compare (volume-number) on p. 290 to (drive-name)
  23. and
  24. (drive-number) on p. 292).  Second, there doesn't seem to be a way to
  25. find out
  26. which volumes are actually mounted when using the function calls on p.
  27. 290-291.
  28. I'd appreciate any comments on the following functions that I came up
  29. with:
  30.  
  31. (defun volume-name (vol)
  32.   ;;
  33.   ;;  This function will return the volume name of the volume specified
  34. by the
  35.   ;;  volume name or vrefnum passed as the argument specified by the
  36. parameter,
  37.   ;;  vol.
  38.   ;;
  39.   (with-returned-pstrs ((volume-name-str
  40.                            (cond ((typep vol 'pathname) (mac-namestring vol))
  41.                                  ((typep vol 'fixnum) "")
  42.                                  (t (error "Argument ~S is not of the required type."
  43. vol)))))
  44.     (let ((pb (make-record :HParamBlockRec
  45.                            :ioNamePtr volume-name-str
  46.                            :ioVRefNum (volume-number vol)
  47.                            :ioVolIndex 0)))
  48.       (unwind-protect
  49.         (cond ((eql (#_PBHGetVinfoSync pb) #$noErr)
  50.                (make-pathname :directory
  51.                                 (%get-string (rref pb
  52. (HParamBlockRec.ioNamePtr)))))
  53.               (t (error "No such volume.")))
  54.         (dispose-record pb :HParamBlockRec)))))
  55.  
  56. (defun scan-volumes ()
  57.   ;;
  58.   ;;  This function will return a list of mounted Macintosh volumes.
  59.   ;;  Each element of the list will contain the following information:
  60.   ;;     (first element) => volume name
  61.   ;;     (second element) => volume reference number
  62.   ;;     (third element) => drive number
  63.   ;;
  64.   (with-returned-pstrs ((volume-name ""))
  65.     (loop with pb  = (make-record :HParamBlockRec
  66.                                   :ioNamePtr volume-name
  67.                                   :ioVRefNum 0
  68.                                   :ioVolIndex 1)
  69.           while (eql (#_PBHGetVInfoSync pb) #$noErr)
  70.           collect (list
  71.                    (make-pathname :directory
  72.                                   (%get-string (rref pb
  73. (HParamBlockRec.ioNamePtr))))
  74.                    (rref pb (HParamBlockRec.ioVRefNum))
  75.                    (rref pb (HParamBlockRec.ioVDrvInfo)))
  76.           do (rset pb :HParamBlockRec.ioVolIndex
  77.                    (+ (rref pb (HParamBlockRec.ioVolIndex)) 1))
  78.           finally
  79.           (dispose-record pb :HParamBlockRec))))
  80.  
  81. My question is this:  will the release version of MCL provide higher
  82. level access
  83. to the toolbox than through deftrap?  This seems to be a slow way to get
  84. things
  85. done, and while it is much easier in Lisp than in C, allocating and
  86. deallocating
  87. records goes against my concept of "high level."  In particular, I've
  88. been trying
  89. to access some of the fields of the volume parameter block without
  90. success.  When
  91. I pass ioVCrDate and ioVModDate to the following function, I get "Fri,
  92. Jan 1, 1904"
  93. for every volume block I examine (in fact, it returns this value no
  94. matter what you
  95. pass as the argument for the parameter, seconds):
  96.  
  97. (defun secs2date (seconds)
  98.   ;;
  99.   ;;  Return a string representing the date of the argument, as specified
  100.   ;;  by the parameter, seconds.
  101.   ;;
  102.   (let* ((dr (make-record :LongDateRec))
  103.          (s (#_NewPtr 4))
  104.          (ignore-result (%put-long s seconds))            ;ignore-result causes a 
  105. compiler
  106.          (ignore-result (#_LongSecs2Date s dr))            ;warning...should this
  107. be a progn?
  108.          (day-of-week (rref dr (LongDateRec.DayOfWeek)))
  109.          (day (rref dr (LongDateRec.day)))
  110.          (month (rref dr (LongDateRec.month)))
  111.          (year (rref dr (LongDateRec.year))))
  112.     (dispose-record dr :LongDateRec)
  113.     (#_DisposPtr s)
  114.     (format nil "~[Sun~;Mon~;Tue~;Wed~;Thu~;Fri~;Sat~], ~
  115.                 
  116. ~[Jan~;Feb~;Mar~;Apr~;May~;Jun~;Jul~;Aug~;Sep~;Oct~;Nov~;Dec~] ~D, ~D"
  117.             (- day-of-week 1) (- month 1) day year)))
  118.             
  119. Some high-level date and time functions would be very nice (classes?
  120. what are classes?)
  121.  
  122. I guess the other problems I'm having are more or less related to Mac 
  123. programming in general than with MCL.  If anyone can point me to some 
  124. tech notes or provide solutions to the following questions, I'd 
  125. appreciate it, however:
  126.  
  127. 1> Is there an acceptable way to find out if a disk is ejectable?  i.e. 
  128. I'd like a function (ejectablep vol) that will tell me if I can pop out a 
  129. disk.  I've seen some sample code that scans the drive queue for the 
  130. drive number corresponding to vol, but doesn't that violate Apple's 
  131. programming guidelines?
  132.  
  133. 2> How do you find the icon associated with a particular volume?
  134.  
  135. Sorry this posting is so long.  I hope my problems are interesting enough 
  136. to provide me with some expert advice.
  137.  
  138. Thanks,
  139.  
  140. Steve Wart
  141. swart@prodigy.bc.ca
  142. PTC Vancouver
  143. (604) 687-4636
  144.