home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / Information / CSMP Digest / volume 1 / csmp-v1-195.txt < prev    next >
Encoding:
Text File  |  1994-12-08  |  36.7 KB  |  1,055 lines  |  [TEXT/R*ch]

  1. C.S.M.P. Digest             Tue, 20 Oct 92       Volume 1 : Issue 195
  2.  
  3. Today's Topics:
  4.  
  5.     CopyBits question
  6.     LockPixels() before every CopyBits()?
  7.     Many Questions about _Launch, but few answers...
  8.     Finding file/dir size using it's FSSpec
  9.     How to <<Readln>> from a text referenced by a handle??
  10.     Temporary heaps
  11.     ThC 5.0.3 address reg allocation
  12.  
  13.  
  14.  
  15. The Comp.Sys.Mac.Programmer Digest is moderated by Michael A. Kelly.
  16.  
  17. The digest is a collection of article threads from the internet newsgroup
  18. comp.sys.mac.programmer.  It is designed for people who read c.s.m.p. semi-
  19. regularly and want an archive of the discussions.  If you don't know what a
  20. newsgroup is, you probably don't have access to it.  Ask your systems
  21. administrator(s) for details.  (This means you can't post questions to the
  22. digest.)
  23.  
  24. Each issue of the digest contains one or more sets of articles (called
  25. threads), with each set corresponding to a 'discussion' of a particular
  26. subject.  The articles are not edited; all articles included in this digest
  27. are in their original posted form (as received by our news server at
  28. cs.uoregon.edu).  Article threads are not added to the digest until the last
  29. article added to the thread is at least one month old (this is to ensure that
  30. the thread is dead before adding it to the digest).  Article threads that
  31. consist of only one message are generally not included in the digest.
  32.  
  33. The entire digest is available for anonymous ftp from ftp.cs.uoregon.edu
  34. [128.223.8.8] in the directory /pub/mac/csmp-digest.  Be sure to read the
  35. file /pub/mac/csmp-digest/README before downloading any files.  The most
  36. recent issues are available from sumex-aim.stanford.edu [36.44.0.6] in the
  37. directory /info-mac/digest/csmp.  If you don't have ftp capability, the sumex
  38. archive has a mail server; send a message with the text '$MACarch help' (no
  39. quotes) to LISTSERV@ricevm1.rice.edu for more information.
  40.  
  41. The digest is also available via email.  Just send a note saying that you
  42. want to be on the digest mailing list to mkelly@cs.uoregon.edu, and you will
  43. automatically receive each new issue as it is created.  Sorry, back issues
  44. are not available through the mailing list.
  45.  
  46. Send administrative mail to mkelly@cs.uoregon.edu.
  47.  
  48.  
  49. -------------------------------------------------------
  50.  
  51. From: csuley@cs.cornell.edu (Christopher Suley)
  52. Subject: CopyBits question
  53. Date: 11 Sep 92 00:14:09 GMT
  54. Organization: Cornell Univ. CS Dept, Ithaca NY 14853
  55.  
  56. I have a color image residing in an offscreen pixmap that I want to
  57. CopyBits to the screen.  Not too hard, but there's a catch.  I want
  58. all of the white pixels in the offscreen image to become a certain
  59. color when they appear on the screen.
  60.  
  61. Using transparent mode doesn't work, because it leaves what was on
  62. the screen beforehand in place, and that isn't what I want.  I
  63. suppose I could just do a FillRect with the color I want, and then
  64. a CopyBits in transparent mode, but I was hoping to be able to do
  65. everything in one step.  (it's an animated image, so filling the
  66. rectangle then copying would introduce some flickering as the area
  67. was cleared, then redrawn each time)
  68.  
  69. Setting the background color to the color I want would work, but it
  70. would colorize the rest of the image. (right?  I am programming on
  71. an SE, so this color stuff is mostly a mental experiment until I
  72. run up the massive hill to school and test it on a color computer
  73. there... talk about an expensive code/compile/run cycle. ;)
  74.  
  75. +++++++++++++++++++++++++++
  76.  
  77. From: ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University)
  78. Date: 12 Sep 92 06:46:24 GMT
  79. Organization: University of Waikato, Hamilton, New Zealand
  80.  
  81. In article <1992Sep11.001409.13276@cs.cornell.edu>, csuley@cs.cornell.edu (Christopher Suley) writes:
  82. > I have a color image residing in an offscreen pixmap that I want to
  83. > CopyBits to the screen.  Not too hard, but there's a catch.  I want
  84. > all of the white pixels in the offscreen image to become a certain
  85. > color when they appear on the screen.
  86.  
  87. This is easy, provided the offscreen pixmap is an indexed one. In an indexed
  88. pixmap, a pixel represents white because it indexes into a CLUT entry containing
  89. white. Want that pixel value to represent a colour other than white? Just
  90. change the CLUT entry!
  91.  
  92. > Setting the background color to the color I want would work, but it
  93. > would colorize the rest of the image. (right?  I am programming on
  94. > an SE, so this color stuff is mostly a mental experiment until I
  95. > run up the massive hill to school and test it on a color computer
  96. > there... talk about an expensive code/compile/run cycle. ;)
  97.  
  98. Aye, that it would. Also remember that the colouring effect is different
  99. between System 6 and System 7; the effect under System 6 is dependent on
  100. a whole bunch of other entries in the CLUT (the gory details are in TN 163),
  101. whereas System 7 interpolates between the foreground and background colours.
  102.  
  103. Lawrence D'Oliveiro                       fone: +64-7-856-2889
  104. Computer Services Dept                     fax: +64-7-838-4066
  105. University of Waikato            electric mail: ldo@waikato.ac.nz
  106. Hamilton, New Zealand    37^ 47' 26" S, 175^ 19' 7" E, GMT+12:00
  107. I don't claim to be consistent. Yes I do!
  108.  
  109. +++++++++++++++++++++++++++
  110.  
  111. From: Joe.Francis@dartmouth.edu (Joe Francis)
  112. Date: 13 Sep 92 23:49:31 GMT
  113. Organization: Dartmouth College, Hanover, NH
  114.  
  115. In article <1992Sep11.184624.10765@waikato.ac.nz>
  116. ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University) writes:
  117.  
  118. > This is easy, provided the offscreen pixmap is an indexed one. In an indexed
  119. > pixmap, a pixel represents white because it indexes into a CLUT entry containing
  120. > white. Want that pixel value to represent a colour other than white? Just
  121. > change the CLUT entry!
  122.  
  123. But if that also happens to be the CLUT of the current gDevice, and
  124. white happens to be the background color of the current gDevice, won't
  125. this technique cause the entire CopyBits result to be colorized?
  126.  
  127. +++++++++++++++++++++++++++
  128.  
  129. From: janrune@ccwf.cc.utexas.edu (Jan Rune Andreassen)
  130. Date: 17 Sep 92 02:18:29 GMT
  131. Organization: The University of Texas at Austin, Austin TX
  132.  
  133.  
  134.    As the header say's I'm looking a translator, preferably a 
  135. PD or Shareware kind. If anyone knows where I can get it or
  136. an FTP source where it might be it would be very helpful.
  137.    Any hints or tips will be grately appriciated.
  138.     Later 
  139.         JR
  140.  
  141. P.S.  I'm posting this for a friend, I'm not much of a Mac
  142. person (I play on IBM's...).
  143.  janrune@ccwf.cc.utexas.edu
  144.  
  145. ---------------------------
  146.  
  147. From: rae@Alias.com (Reid Ellis)
  148. Subject: LockPixels() before every CopyBits()?
  149. Date: 11 Sep 92 21:32:20 GMT
  150. Organization: Alias Research, Inc., Toronto ON Canada
  151.  
  152. Inside Mac V says that LockPixels() must be called before drawing into
  153. an offscreen GWorld.  And yet the examples within the next few pages
  154. don't call LockPixels()!  What's the scoop here?
  155.  
  156. I think I've tracked down a bug in our program where it crashes on a
  157. Quadra 700 but not on a IIci during a call to CopyBits().  On the
  158. Quadra, the baseAddr of one of the bitmaps was F9001000, which was way
  159. out of line with other addresses.  I would guess it's either invalid
  160. or the address of the built-in VRAM.  I can't find any doc that says
  161. "The 32-bit address of the Quadra's VRAM is xxxx".
  162.  
  163. Assuming that the address is okay, I noticed that we don't call
  164. LockPixels() before CopyBits().  After inserting calls to LockPixels()
  165. and UnlockPixels(), it looks something like this:
  166.  
  167.     HLock((Handle) pixHandle1);
  168.     HLock((Handle) pixHandle2);
  169.     LockPixels(pixHandle1);
  170.     LockPixels(pixHandle2);
  171.     CopyBits((BitMap *)*pixHandle1, (BitMap *)*pixHandle2, ...);
  172.     UnlockPixels(pixHandle2);
  173.     UnlockPixels(pixHandle1);
  174.     HUnlock((Handle) pixHandle2);
  175.     HUnlock((Handle) pixHandle1);
  176.  
  177. Now this seems to be a bit much for every call to CopyBits.  Is this
  178. trip really necessary?  Would it be quicker to check to see is each
  179. PixMapHandle is offscreen?
  180.  
  181. I'm off now to try it out.  I'm kind of hoping the address is just
  182. invalid and not in VRAM :-)..
  183.  
  184. Reid
  185. - --
  186. Reid Ellis                                            
  187. rae@utcs.utoronto.ca        ||           rae@Alias.com
  188. CDA0610@applelink.apple.com ||  +1 416 362 9181 [work]
  189.  
  190. +++++++++++++++++++++++++++
  191.  
  192. From: krk@itl.itd.umich.edu (Kenneth Knight)
  193. Organization: Instructional Technology Laboratory, University of Michigan
  194. Date: Sat, 12 Sep 1992 22:25:27 GMT
  195.  
  196. In article <1992Sep11.213220.23039@alias.com> Reid Ellis <rae@Alias.com> writes:
  197. >Inside Mac V says that LockPixels() must be called before drawing into
  198. >an offscreen GWorld.  And yet the examples within the next few pages
  199. >don't call LockPixels()!  What's the scoop here?
  200. >
  201. >I think I've tracked down a bug in our program where it crashes on a
  202. >Quadra 700 but not on a IIci during a call to CopyBits().  On the
  203. >Quadra, the baseAddr of one of the bitmaps was F9001000, which was way
  204. >out of line with other addresses.  I would guess it's either invalid
  205. >or the address of the built-in VRAM.  I can't find any doc that says
  206. >"The 32-bit address of the Quadra's VRAM is xxxx".
  207. >
  208. >Assuming that the address is okay, I noticed that we don't call
  209. >LockPixels() before CopyBits().  After inserting calls to LockPixels()
  210. >and UnlockPixels(), it looks something like this:
  211. >
  212. >    HLock((Handle) pixHandle1);
  213. >    HLock((Handle) pixHandle2);
  214. >    LockPixels(pixHandle1);
  215. >    LockPixels(pixHandle2);
  216. >    CopyBits((BitMap *)*pixHandle1, (BitMap *)*pixHandle2, ...);
  217. >    UnlockPixels(pixHandle2);
  218. >    UnlockPixels(pixHandle1);
  219. >    HUnlock((Handle) pixHandle2);
  220. >    HUnlock((Handle) pixHandle1);
  221. >
  222. >Now this seems to be a bit much for every call to CopyBits.  Is this
  223. >trip really necessary?  Would it be quicker to check to see is each
  224. >PixMapHandle is offscreen?
  225.  
  226. You can remove the HLock/HUnlcok calls certainly. I'd keep the LockPixels/
  227. UnlockPixels() calls in place. 
  228.  
  229.   ** Ken **
  230.  
  231.  
  232. +++++++++++++++++++++++++++
  233.  
  234. From: jmatthews@desire.wright.edu
  235. Date: 13 Sep 92 04:22:33 GMT
  236. Organization: Wright State University
  237.  
  238. > Assuming that the address is okay, I noticed that we don't call
  239. > LockPixels() before CopyBits().  After inserting calls to LockPixels()
  240. > and UnlockPixels(), it looks something like this:
  241. >     HLock((Handle) pixHandle1);
  242. >     HLock((Handle) pixHandle2);
  243. >     LockPixels(pixHandle1);
  244. >     LockPixels(pixHandle2);
  245. >     CopyBits((BitMap *)*pixHandle1, (BitMap *)*pixHandle2, ...);
  246. >     UnlockPixels(pixHandle2);
  247. >     UnlockPixels(pixHandle1);
  248. >     HUnlock((Handle) pixHandle2);
  249. >     HUnlock((Handle) pixHandle1);
  250. > Now this seems to be a bit much for every call to CopyBits.
  251.  
  252. LockPixels and UnlockPixels should be suffucient; the HLock and
  253. HUnlock aren't needed. I think you may need to be calling
  254. GetGWorldPixMap instead of getting the pixMap directly (except
  255. under ColorQD version 1.2 where it's broken (see the Q & A stack)).
  256.  
  257. IM VI just says use GetGWorldPixMap without much explanation. I've
  258. imagined this makes a difference with GWorlds on graphic accelerators
  259. or temporary memory, but I don't really know.
  260.  
  261. Any thoughts?
  262.  
  263. o----------------------------------------------------------------------------o
  264. | John B. Matthews, jmatthews@desire.wright.edu, disclaimer:= myViews <> WSU |
  265. |      "Whom the gods would destroy, they first invite to program in C"      |
  266. o----------------------------------------------------------------------------o
  267.  
  268. +++++++++++++++++++++++++++
  269.  
  270. From: us277614@mmm.serc.3m.com (Dave T. Berquist)
  271. Organization: 3M Company
  272. Date: Sun, 13 Sep 92 22:39:55 GMT
  273.  
  274. In article <1992Sep12.232233.4076@desire.wright.edu> jmatthews@desire.wright.edu writes:
  275. >> Assuming that the address is okay, I noticed that we don't call
  276. >> LockPixels() before CopyBits().  After inserting calls to LockPixels()
  277. >> and UnlockPixels(), it looks something like this:
  278. >> 
  279. >>     HLock((Handle) pixHandle1);
  280. >>     HLock((Handle) pixHandle2);
  281. >>     LockPixels(pixHandle1);
  282. >>     LockPixels(pixHandle2);
  283. >>     CopyBits((BitMap *)*pixHandle1, (BitMap *)*pixHandle2, ...);
  284. >>     UnlockPixels(pixHandle2);
  285. >>     UnlockPixels(pixHandle1);
  286. >>     HUnlock((Handle) pixHandle2);
  287. >>     HUnlock((Handle) pixHandle1);
  288. >> 
  289. >> Now this seems to be a bit much for every call to CopyBits.
  290. >
  291. >LockPixels and UnlockPixels should be suffucient; the HLock and
  292. >HUnlock aren't needed. I think you may need to be calling
  293. >GetGWorldPixMap instead of getting the pixMap directly (except
  294. >under ColorQD version 1.2 where it's broken (see the Q & A stack)).
  295. >
  296. >IM VI just says use GetGWorldPixMap without much explanation. I've
  297. >imagined this makes a difference with GWorlds on graphic accelerators
  298. >or temporary memory, but I don't really know.
  299. >
  300. >Any thoughts?
  301. >
  302.  
  303. GetGWorldPixMap should be used if system 7 is available, otherwise get
  304. the pixmap right from the gworld for system 6.  (GetGWorldPixMap does
  305. not work under system 6 - I know, I have tried it).
  306.  
  307. - - Dave Berquist
  308.  
  309.  
  310. +++++++++++++++++++++++++++
  311.  
  312. From: lari@bach.cs.unc.edu (Humayun Lari)
  313. Date: 16 Sep 92 00:07:10 GMT
  314. Organization: The University of North Carolina at Chapel Hill
  315.  
  316. In article <1992Sep12.232233.4076@desire.wright.edu> jmatthews@desire.wright.edu writes:
  317. >IM VI just says use GetGWorldPixMap without much explanation. I've
  318. >imagined this makes a difference with GWorlds on graphic accelerators
  319. >or temporary memory, but I don't really know.
  320.  
  321. I seem to remember reading somewhere that GetGWorldPixMap is recommended
  322. so that your code works on machines that do not have Color Quickdraw
  323. (e.g. Classics under 7.x), since a GWorldPtr on such machines points to an
  324. extended GrafPort rather than a CGrafPort.
  325.  
  326. Humayun Lari
  327. (lari@cs.unc.edu)
  328.  
  329. ---------------------------
  330.  
  331. From: mezrich@aramis.rutgers.edu (Reuben Mezrich)
  332. Subject: Many Questions about _Launch, but few answers...
  333. Date: 14 Sep 92 20:35:56 GMT
  334. Organization: Rutgers Univ., New Brunswick, N.J.
  335.  
  336.  
  337.      I think that the _Launch command must be one of the greatest
  338. mysteries (sp?) of the pre-system 7 toolbox.  Does anybody have any
  339. idea how to properly use this trap ?  I've have a fair amount of
  340. success in using it, but have run into the difficulty that, under
  341. System 6, multifinder does not seem to use it at all.  I've used the
  342. _Launch command successfully under system 6 running the finder, and
  343. under system 7, but have had no success under system 6 running multifinder.
  344. It does launch the application, but it does not behave as it should
  345. (it clears the screen and closes other background applications).  
  346.      Does anyone out there have any idea how system 6 multifinder
  347. launches an application, or know where I might seek this information ?
  348. I've seen several questions about the _Launch command posted, but
  349. there does not seem to be a wealth of information available.  I am
  350. writing an INIT which will allow executing applications with a single
  351. key stroke (or key combination), and hope to make it available when
  352. (or if) I am able to finish it.
  353.      Please do not respond to this message using Email, as this is not
  354. my account.  It is a friends and I am just using it until my account
  355. comes up.  I do not check the mail.  Please respond on this newsgroup.
  356.  
  357.                                          Much Thanks,
  358.                                                 Dave Grossberg
  359.  
  360. +++++++++++++++++++++++++++
  361.  
  362. From: mxmora@unix.sri.com (Matthew Xavier Mora)
  363. Date: 14 Sep 92 22:34:17 GMT
  364. Organization: SRI International
  365.  
  366. In article <Sep.14.16.35.56.1992.3303@aramis.rutgers.edu>,
  367. mezrich@aramis.rutgers.edu (Reuben Mezrich) wrote:
  368.  
  369.  
  370. >      I think that the _Launch command must be one of the greatest
  371. > mysteries (sp?) of the pre-system 7 toolbox.  Does anybody have any
  372. > idea how to properly use this trap ?  I've have a fair amount of
  373. > success in using it, but have run into the difficulty that, under
  374. > System 6, multifinder does not seem to use it at all.  I've used the
  375. > _Launch command successfully under system 6 running the finder, and
  376. > under system 7, but have had no success under system 6 running multifinder.
  377. > It does launch the application, but it does not behave as it should
  378. > (it clears the screen and closes other background applications).
  379.  
  380. Its not a great mystery, your just not supposed to use it. 
  381. You probably have the wrong flags set.
  382.   
  383. I have used the version supplied in the technote # 126
  384. "Sublaunching:Playing the shell Game" and it worked for me. Show us your
  385. code and maybe we can see what you are doing wrong. Don't forget the you
  386. need to set both high bits
  387. (Launchflags := $C000000) to sublaunch.
  388.  
  389. Matt
  390.  
  391. +++++++++++++++++++++++++++
  392.  
  393. From: time@ice.com (Tim Endres)
  394. Date: 16 Sep 92 16:51:49 GMT
  395. Organization: ICE Engineering, Inc.
  396.  
  397.  
  398. In article <Sep.14.16.35.56.1992.3303@aramis.rutgers.edu> (mezrich@aramis.rutgers.edu), you write:
  399. >      I think that the _Launch command must be one of the greatest
  400. > mysteries (sp?) of the pre-system 7 toolbox.  Does anybody have any
  401. > idea how to properly use this trap ?  I've have a fair amount of
  402. > success in using it, but have run into the difficulty that, under
  403. > System 6, multifinder does not seem to use it at all.  I've used the
  404. > _Launch command successfully under system 6 running the finder, and
  405. > under system 7, but have had no success under system 6 running multifinder.
  406. > It does launch the application, but it does not behave as it should
  407. > (it clears the screen and closes other background applications).  
  408. >      Does anyone out there have any idea how system 6 multifinder
  409. > launches an application, or know where I might seek this information ?
  410. > I've seen several questions about the _Launch command posted, but
  411. > there does not seem to be a wealth of information available.  I am
  412. > writing an INIT which will allow executing applications with a single
  413. > key stroke (or key combination), and hope to make it available when
  414. > (or if) I am able to finish it.
  415. >      Please do not respond to this message using Email, as this is not
  416. > my account.  It is a friends and I am just using it until my account
  417. > comes up.  I do not check the mail.  Please respond on this newsgroup.
  418.  
  419. The difficulty arises in the sense that under Multi-Finder System-6
  420. Launch can RETURN! You must bre prepared for the call to return and
  421. for it not to return. This is a PAIN! In essence, you are *forced*
  422. to come up with a method of determining if MultiFinder is running
  423. (which Apple still claims you can not do) if your code depends upon
  424. knowing if launch returns.
  425.  
  426. My code did, since I had to close files if not under MultiFinder.
  427.  
  428. Anyways....
  429.  
  430. Here's some code.
  431.  
  432. Some Assembler:
  433.  
  434. ;
  435. ; Written by Tim Endres.
  436. ;
  437.  
  438. ;
  439. ; OSErr Launchit(pb_launch)
  440. ;     PBLaunch        *pb_launch;
  441. ;     extern
  442. ;
  443.  
  444.     INCLUDE 'traps.a'
  445.     CASE    OBJECT
  446.     
  447. Launchit    PROC    EXPORT
  448.     move.l        4(sp), a0    ; Get pointer to prameter block
  449.     _Launch
  450.     
  451.     ; NOTE: We *can return* under MultiFinder...
  452.     
  453.     move.l        (sp)+, a0    ; Get return address off stack
  454.     addq        #$4, sp        ; dump the parameter
  455.     jmp            (a0)        ; return to caller
  456.     
  457.     ENDP
  458.     
  459.     END
  460.     
  461. Some C code:
  462.  
  463. /*
  464. **
  465. ** Written by Tim Endres.
  466. */
  467.  
  468. /* $$FILE UniLaunch.c
  469. ** UniLaunch.c contains the routine which launches applications.
  470. ** UniLaunch causes applications to be ru, just like the Finder does,
  471. ** as well as allowing documents to be opened at launch time.
  472. */
  473.  
  474. #include <types.h>
  475. #include <memory.h>
  476. #include <files.h>
  477. #include <errors.h>
  478.  
  479. extern short    launch_returns;
  480. extern short    app_done;
  481.  
  482. typedef struct {
  483.     char    *app_name;
  484.     short    param;
  485.     char    LC[2];
  486.     long    ext_blk_len;
  487.     short    finder_flags;
  488.     long    launch_flags;
  489.     } PBLaunch;
  490.  
  491. static char        pascal_app_name[256];
  492.  
  493. #define AppParmHandle    (* (Handle *) 0x0AEC)
  494.  
  495. #define ALERT_ALERT        1
  496.  
  497. extern pascal Boolean RunStateFilter();
  498.  
  499. typedef struct {
  500.     short    message;
  501.     short    number;
  502.     short    vrefnum;
  503.     long    type;
  504.     unsigned char version;
  505.     unsigned char unused;
  506.     char    document[1];
  507.     } AppParms;
  508.  
  509. /* $$FUNCTION LaunchDoc
  510. ** Launch a Macintosh application with an associated document (or not).
  511. ** 'app_name' is the name of the application to be launched.
  512. ** 'vrefnum' is the working directory the application file can be located with.
  513. ** 'doc_name' is the name of a document to be opened with the application launch.
  514. ** If 'doc_name' is NULL, then no document is opened. If 'doc_name' is not NULL,
  515. ** then doc_type is the Finder file type (e.g. 'TEXT') of the file 'doc_name,
  516. ** with the four type characters represented by the bytes in the long integer.
  517. ** For Full Details, See Technical Note #126
  518. */
  519. LaunchDoc(app_name, app_vrefnum, doc_name, doc_vrefnum, doc_type)
  520. char    *app_name;
  521. int        app_vrefnum;
  522. char    *doc_name;
  523. int        doc_vrefnum;
  524. long    doc_type;
  525. {
  526. short        err;
  527. PBLaunch    pbl;
  528. CInfoPBRec    cpb;
  529. AppParms    *parm_ptr;
  530. Handle        parm_handle;
  531. THz            save_zone;
  532.  
  533.     strcpy(&pascal_app_name[1], app_name);
  534.     pascal_app_name[0] = (unsigned char) strlen(app_name);
  535.     cpb.hFileInfo.ioNamePtr = pascal_app_name;
  536.     cpb.hFileInfo.ioVRefNum = app_vrefnum;
  537.     cpb.hFileInfo.ioFDirIndex = 0;
  538.     cpb.hFileInfo.ioDirID = 0;
  539.  
  540.     err = PBGetCatInfo(&cpb, false);
  541.     if (err != noErr)
  542.         {
  543.         message_alert("Error #%d trying to find file '%s'!\n", err, app_name);
  544.         }
  545.     else {
  546.         /*
  547.         ** First, if the document 'doc_name' is not NULL, then
  548.         ** establish the Application Parameters.
  549.         */
  550.         parm_handle = AppParmHandle;
  551.         if (parm_handle != NULL)
  552.             DisposHandle(parm_handle);
  553.         AppParmHandle = NULL;
  554.         
  555.         if (doc_name != NULL)
  556.             {
  557.             parm_handle = AppParmHandle;
  558.             if (parm_handle != NULL)
  559.                 DisposHandle(parm_handle);
  560.  
  561.             save_zone = GetZone();
  562.             SetZone(SystemZone());
  563.             /*
  564.             ** Don't worry about this handle. :-)
  565.             ** _Launch appears to be smart enough to
  566.             ** copy it into the launched application's
  567.             ** heap and then toss it.
  568.             */
  569.             parm_handle = NewHandle(sizeof(AppParms) + strlen(doc_name) + 2);
  570.             SetZone(save_zone);
  571.             if (parm_handle != NULL)
  572.                 {
  573.                 parm_ptr = (AppParms *) *parm_handle;
  574.                 parm_ptr->message = 0;
  575.                 parm_ptr->number = 1;
  576.                 parm_ptr->vrefnum = doc_vrefnum;
  577.                 parm_ptr->type = doc_type;
  578.                 parm_ptr->version = 0;
  579.                 parm_ptr->unused = 0;
  580.                 parm_ptr->document[0] = strlen(doc_name);
  581.                 strncpy(&parm_ptr->document[1], doc_name, parm_ptr->document[0]);
  582.                 AppParmHandle = parm_handle;
  583.                 }
  584.             }
  585.         
  586.         /*
  587.         ** Now, launch the application.
  588.         */
  589.         SetVol(NULL, app_vrefnum);
  590.         pbl.app_name = pascal_app_name;
  591.         pbl.param = 0;
  592.         pbl.LC[0] = 'L';
  593.         pbl.LC[1] = 'C';
  594.         pbl.ext_blk_len = 6;
  595.         pbl.finder_flags = cpb.hFileInfo.ioFlFndrInfo.fdFlags;
  596.         pbl.launch_flags = 0xC0000000;
  597.         err = Launchit(&pbl);
  598.         if (err < 0)
  599.             {
  600.             if (err == -10)    /* Not really sure why, but I *think* I've seen this with OLD ROMs! */
  601.                 message_alert("Error #%d launching '%s'.\015Probably due to insufficient memory.",
  602.                                 err, app_name);
  603.             else if (err == fnfErr)
  604.                 message_alert("Could not find application '%s'!", app_name);
  605.             else if (err == memFullErr)
  606.                 message_alert("Not enough memory available to launch '%s'!", app_name);
  607.             else
  608.                 message_alert("Error #%d launching '%s'!", err, app_name);
  609.             }
  610.  
  611.         }
  612.     
  613.     }
  614.  
  615.  
  616. tim endres - time@ice.com  -or- tbomb!time
  617. ICE Engineering, Inc - 8840 Main St, Whitmore Lake, MI 48189
  618. Phone (313) 449 8288 - FAX (313) 449-9208
  619. USENET - a slow moving self parody... ph
  620.  
  621. ---------------------------
  622.  
  623. From: liran@bimacs.BITNET (Eshel Liran)
  624. Subject: Finding file/dir size using it's FSSpec
  625. Date: 16 Sep 92 12:02:46 GMT
  626. Organization: Math & CS, BarIlan U, Ramat-Gan, Israel
  627.  
  628. How can I find the size of a file or a folder using it's FSSpec record ?
  629.  
  630. Liran Eshel
  631. liran@bimacs.cs.biu.ac.il
  632.  
  633. +++++++++++++++++++++++++++
  634.  
  635. From: leonardr@netcom.com (Leonard Rosenthol)
  636. Date: Wed, 16 Sep 92 18:47:29 GMT
  637. Organization: Netcom - Online Communication Services  (408 241-9760 guest) 
  638.  
  639. In article <4191@bimacs.BITNET> liran@bimacs.BITNET (Eshel Liran) writes:
  640. >How can I find the size of a file or a folder using it's FSSpec record ?
  641. >
  642.     Finding the size of a file is easy - just use the information in
  643. the FSSpec to setup an HParamBlockRec and call PBHGetFInfo.  Two of ther
  644. returned fields are ioFlPyLen & ioFlRPyLen which is the physical size (amount
  645. of disk space used) of the data & resource forks (respectively) of a file.
  646.  
  647.     In the case of a folder, you will have to recursively walk the hier-
  648. archy using PBGetCatInfo calls and then add up the above info on each file
  649. found.
  650.  
  651.     One thing of note - if the user has a transparent compression product
  652. installed, the information returned may not be exactly what you expect - in
  653. the case of StuffIt SpaceSaver (and AutoDoubler 2.0, I believe) the physical
  654. sizes are the "compressord" sizes since that is the size on disk, while the 
  655. logical sizes are the "expanded" sizes since that is the real amount of data.
  656. Howevever, in the case of More Disk Space, it returns the compressed sizes
  657. for both the logical & physical (you can't get the expanded size of a file
  658. w/o opening it first!).
  659.  
  660. - -- 
  661. - -----------------------------------------------------------------------------
  662. Leonard Rosenthol            Internet:     leonardr@netcom.com
  663. Director of Advanced Technology        AppleLink:    MACgician
  664. Aladdin Systems, Inc.            GEnie:        MACgician
  665.  
  666.  
  667. +++++++++++++++++++++++++++
  668.  
  669. From: peirce@outpost.SF-Bay.org (Michael Peirce)
  670. Date: 16 Sep 92 21:40:57 GMT
  671. Organization: Peirce Software
  672.  
  673.  
  674. In article <4191@bimacs.BITNET> (comp.sys.mac.programmer), liran@bimacs.BITNET (Eshel Liran) writes:
  675. > How can I find the size of a file or a folder using it's FSSpec record ?
  676.  
  677. How about PBGetCatInfo?  If you are going to be doing nay file stuff you
  678. really should read the Inside Macintosh chapters on the File Manager.
  679.  
  680. - --  Michael Peirce      --   peirce@outpost.SF-Bay.org
  681. - --  Peirce Software     --   Suite 301, 719 Hibiscus Place
  682. - --                      --   San Jose, California USA 95117
  683. - --  Makers of...        --   voice: (408) 244-6554 fax: (408) 244-6882
  684. - --            SMOOTHIE  --   AppleLink: peirce & America Online: AFC Peirce
  685.  
  686. +++++++++++++++++++++++++++
  687.  
  688. From: ksand@apple.com (Kent Sandvik)
  689. Date: 17 Sep 92 02:28:58 GMT
  690. Organization: Apple
  691.  
  692. In article <4191@bimacs.BITNET>, liran@bimacs.BITNET (Eshel Liran) wrote:
  693. > How can I find the size of a file or a folder using it's FSSpec record ?
  694. > Liran Eshel
  695. > liran@bimacs.cs.biu.ac.il
  696.  
  697. PBGetCatInfo should return information for defining the size of
  698. the data fork, as in:
  699.  
  700. theSize = theCPB.hFileInfo.ioFlLgLen - theCPB.hFileInfo.ioFlStBlk;
  701.  
  702. You could call PBGetCatInfo, as in:
  703.  
  704.  theCPB.hFileInfo.ioFDirIndex = -1;
  705.     theCPB.hFileInfo.ioVRefNum = VRefNum;
  706.     theCPB.hFileInfo.ioDirID = DirID;
  707.     theCPB.hFileInfo.ioNamePtr = (StringPtr) &FileName;
  708.  
  709.  PBGetCatInfo( &theCPB, nil );
  710.  
  711. This all is ad hoc programming, so it's untested. 
  712.  
  713. Cheers,
  714. Kent/DTS
  715. "I would rather have a thousands idiots attacking my position, than
  716. have one idiot helping to defend it."    [Paraphrased from Voltaire]
  717. - -------------------
  718. Kent Sandvik (UUCP: ....!apple!ksand; INTERNET: ksand@apple.com)
  719. DISCLAIMER: Private activities on the Net.
  720.  
  721. ---------------------------
  722.  
  723. From: czychi@bernina.ethz.ch (Gary Czychi)
  724. Subject: How to <<Readln>> from a text referenced by a handle??
  725. Date: 15 Sep 92 07:44:58 GMT
  726. Organization: Swiss Federal Institute of Technology (ETH), Zurich, CH
  727.  
  728. Hi!
  729.  
  730. I have been told that the Mac (in fact any computer) is very slow reading
  731. textual input from a file line by line.
  732.  
  733. nd in my application, I have already read in the text of a file in one big
  734. chunk and pass the handle to the place where I process the data.
  735.  
  736. Now, is there any way for me, to read some of the lines in this handle? I
  737. only need about 10 lines from the top and separate it from the rest, which
  738. is being diplayed in a window as one big part.
  739.  
  740. I've tried to type coerce the handle to a str255 handle, but then I get a
  741. range error (of course).
  742.  
  743. If there is no obvious or easy solution, how could I access the data in my
  744. handle byte for byte and then put everything into a Str255 until the next CR
  745. is detected?
  746.  
  747. As you might want to know, I'm using TH Pascal.
  748.  
  749. Thanks a lot for any help.
  750.  
  751.   Gary
  752.  
  753.     Gary T. Czychi          University of St.Gallen
  754.  
  755.        czychi@alpha.unisg.ch (preferred host)
  756.          czychi at csghsg52   (=bitnet)
  757.            czychi@bernina.ethz.ch
  758.              Switzerland
  759.               -
  760.  
  761. +++++++++++++++++++++++++++
  762.  
  763. From: peter@cujo.curtin.edu.au (Peter N Lewis)
  764. Date: 16 Sep 92 01:32:12 GMT
  765. Organization: NCRPDA, Curtin University
  766.  
  767. In article <1992Sep15.074458.6297@bernina.ethz.ch>, czychi@bernina.ethz.ch
  768. (Gary Czychi) wrote:
  769.  
  770. > nd in my application, I have already read in the text of a file in one big
  771. > chunk and pass the handle to the place where I process the data.
  772.  
  773. {$R-}
  774. procedure ReadALine(h:handle; var s:str255);
  775. var
  776.   p:ptr;
  777.   size,len:longInt;
  778. begin
  779.   p:=h^;
  780.   size:=GetHandleSize(h);
  781.   len:=0;
  782.   while (size>0) & (p^ <> 13) do begin
  783.     p:=ptr(ord(p)+1);
  784.     size:=size-1;
  785.     len:=len+1;
  786.   end;
  787.   if len>255 then len:=255;
  788.   s[0]:=chr(len);
  789.   BlockMove(h^,@s[1],len);
  790.   if size>0 then begin
  791.     p:=ptr(ord(p)+1); { Skip over the <cr> }
  792.     size:=size-1;
  793.     BlockMove(p,h^,size);
  794.   end;
  795.   SetHandleSize(h,size);
  796. end;
  797.  
  798. I tested this code, it seems to work ok.  Note, if you were going to read
  799. lots of lines, you'd be better keeping an offset, and avoiding the block
  800. move all the time, but the above will work ok, and isn't *that* inefficent,
  801. it depends how many times you want to call ReadALine, if its 10 or 20, no
  802. problem, if its 10 or 20 thousand, then some rethinking would be
  803. necessary...
  804.    Peter.
  805.  
  806. _______________________________________________________________________
  807. Peter N Lewis, NCRPDA, Curtin University       peter@cujo.curtin.edu.au
  808. GPO Box U1987, Perth WA 6001, AUSTRALIA             FAX: +61 9 367 8141
  809.  
  810. +++++++++++++++++++++++++++
  811.  
  812. From: gurhs@uniwa.uwa.edu.au (Rhys Hollow)
  813. Date: 16 Sep 1992 11:23:15 +0800
  814. Organization: The University of Westrn Australia
  815.  
  816. peter@cujo.curtin.edu.au (Peter N Lewis) gives a useful example of
  817. implementing a Readln with a handle-referenced block of text :
  818.  
  819. >{$R-}
  820.  
  821. But wait!  What is this?? Turning Rangechecking off?  I wonder what that
  822. could be for?  What's that you say?  Think Pascal will range check if
  823. you try to set the length byte of the string?  Think Pascal will range
  824. check if you access the string s[x] where x is greater than Length(s)?
  825. You're kidding right?  Think Pascal couldn't possibly be that stupid
  826. surely?  Oh dear, I think it is.
  827.  
  828. <Rhys bangs head against the wall <bang> <bang> <bang> >
  829.  
  830. >procedure ReadALine(h:handle; var s:str255);
  831. [Body of procedure deleted]
  832. >end;
  833.  
  834.  
  835. Hmm, don't forget to turn Range Checking back on Pete!
  836.  
  837. Rhys.
  838. - --
  839. Rhys Hollow (gurhs@uniwa.uwa.oz.au) "ee'er by gum he's a bad'un!" -DangerMouse.
  840.  
  841. +++++++++++++++++++++++++++
  842.  
  843. From: David.T.Greenfield@dartmouth.edu (David T. Greenfield)
  844. Date: 18 Sep 92 17:50:28 GMT
  845. Organization: Dartmouth College, Hanover, NH
  846.  
  847. In article <peter-160992091557@134.7.50.3>
  848. peter@cujo.curtin.edu.au (Peter N Lewis) writes:
  849.  
  850. > procedure ReadALine(h:handle; var s:str255);
  851. > var
  852. >   p:ptr;
  853. >   size,len:longInt;
  854. > begin
  855. >   p:=h^;
  856. >   size:=GetHandleSize(h);
  857. >   len:=0;
  858. >   while (size>0) & (p^ <> 13) do begin
  859. >     p:=ptr(ord(p)+1);
  860. >     size:=size-1;
  861. >     len:=len+1;
  862. >   end;
  863. >   if len>255 then len:=255;
  864. >   s[0]:=chr(len);
  865. >   BlockMove(h^,@s[1],len);
  866. >   if size>0 then begin
  867. >     p:=ptr(ord(p)+1); { Skip over the <cr> }
  868. >     size:=size-1;
  869. >     BlockMove(p,h^,size);
  870. >   end;
  871. >   SetHandleSize(h,size);
  872. > end;
  873.  
  874.  
  875. Will this work for scripts that use 2 byte characters?
  876.  
  877.  
  878. David
  879. david.t.greenfield@dartmouth.edu
  880.  
  881. ---------------------------
  882.  
  883. From: jeremyr@dcs.qmw.ac.uk (Jeremy Roussak)
  884. Subject: Temporary heaps
  885. Date: 16 Sep 92 22:57:33 GMT
  886. Organization: Computer Science Dept, QMW, University of London
  887.  
  888. I'm having a problem with something I had thought rather clever. It seems
  889. I am less intelligent than I thought.
  890.  
  891. I have written an INIT. To save memory, the INIT keeps most of its code
  892. on disk, rather than resident. When needed, the resource file is opened,
  893. the code loaded and run and the resource file closed. Since some apps
  894. run with little space in their heaps, there sometimes isn't enough room
  895. to load and run these modules, so I have been putting up an alert to
  896. that effect. This seems inelegant at best, so I tried the following
  897. solution.
  898.  
  899. 1. Allocate a temporary memory handle large enough for the code
  900.    resource and plenty of spare memory.
  901.  
  902. 2. Lock it and set it up as a heap zone
  903.  
  904. 3. Open the resource file, do various things, close the resource file
  905.  
  906. 4. Reset the current zone and dispose of the temporary handle.
  907.  
  908. This works most of the time, but I have been getting a lot of random
  909. crashes, some a good many minutes after the procedure above. Sometimes
  910. the new heap is corrupt at the end of the procedure (although the code
  911. never corrupts the application heap if it's run there). Hacking with
  912. MacsBug indicates that sometimes (but not always), the heap is OK before
  913. _CloseResFile and corrupt afterwards.
  914.  
  915. So, is there a problem with the resource manager? In his notes to
  916. Disinfectant source, John Norstad makes a point about a comment in IM II
  917. that the current zone should be the same as the resource's zone before
  918. _ReleaseResource. Could the releasing of resources which goes with
  919. _CloseResFile be responsible? Has anyone out there tried to do
  920. anything as weird as this? Am I an isolated pervert?
  921.  
  922. Jeremy
  923.  
  924. code follows: no comments on layout, please!
  925.  
  926. #define zoneSize 0x18000        /* 96k: easily large enough */
  927.  
  928. static Handle TempZone(void)
  929.  {  Ptr zone;
  930.     short err;
  931.     Handle result;
  932.  
  933.     unless ((result = TempNewHandle(zoneSize, &err))==nil)
  934.      {  HLock(result);
  935.         zone = StripAddress(*result);
  936.         InitZone(nil, 64, zone+zoneSize, zone);
  937.      }
  938.  
  939.     return result;
  940.  }
  941.  
  942.  
  943. main()
  944.  {  THz oldZone;
  945.     Handle newZone;
  946.  
  947.     oldZone = TheZone;
  948.     newZone = TempZone();
  949.  
  950. /* then OpenResFile, do various things, CloseResFile */
  951.  
  952.     if (newZone!=nil)
  953.      {  TheZone = oldZone;
  954.         DisposHandle(newZone);
  955.      }
  956.  }
  957.  
  958. Running under system 7, 24-bit, no VM.
  959.  
  960. +++++++++++++++++++++++++++
  961.  
  962. From: leonardr@netcom.com (Leonard Rosenthol)
  963. Date: 17 Sep 92 06:32:59 GMT
  964. Organization: Netcom - Online Communication Services  (408 241-9760 guest)
  965.  
  966. In article <1992Sep16.225733.7072@dcs.qmw.ac.uk> jeremyr@dcs.qmw.ac.uk (Jeremy Roussak) writes:
  967. >I have written an INIT. To save memory, the INIT keeps most of its code
  968. >on disk, rather than resident. When needed, the resource file is opened,
  969. >the code loaded and run and the resource file closed. Since some apps
  970. >run with little space in their heaps, there sometimes isn't enough room
  971. >to load and run these modules, so I have been putting up an alert to
  972. >that effect. This seems inelegant at best, so I tried the following
  973. >solution.
  974. >
  975. > [Details of setting up own heap]
  976. >
  977. >This works most of the time, but I have been getting a lot of random
  978. >crashes, some a good many minutes after the procedure above. Sometimes
  979. >the new heap is corrupt at the end of the procedure (although the code
  980. >never corrupts the application heap if it's run there). Hacking with
  981. >MacsBug indicates that sometimes (but not always), the heap is OK before
  982. >_CloseResFile and corrupt afterwards.
  983. >
  984.     One thing that I have found in doing this (creating your own heap
  985. in an INIT) is that there are some trap calls which set low memory globals
  986. which will try to rference data back into your no longer existant heap. The
  987. BEST example of this is ParamText, but there are others...
  988.  
  989. - -- 
  990. - -----------------------------------------------------------------------------
  991. Leonard Rosenthol            Internet:     leonardr@netcom.com
  992. Director of Advanced Technology        AppleLink:    MACgician
  993. Aladdin Systems, Inc.            GEnie:        MACgician
  994.  
  995. ---------------------------
  996.  
  997. From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
  998. Subject: ThC 5.0.3 address reg allocation
  999. Organization: Kalamazoo College
  1000. Date: Thu, 17 Sep 1992 15:44:20 GMT
  1001.  
  1002. I'm playing around, making a code segment, and there's a short bit where
  1003. I need four address registers.  Turns out I only get two!  If I
  1004. understand correctly, A7, A6, and A5 are the system's;  A4 is my
  1005. globals, and A0 and A1 are reserved for scratch use.
  1006.  
  1007. It seems kinda silly to me that I can't force it to give me A0 and A1
  1008. without specifically specifying them.  (And, consequently, saving and
  1009. restoring them on the stack whenever I mix assembly and C code in the
  1010. same function.  Ick.)  Has ThC always done this, or is this new to
  1011. version 5.0.3?
  1012.  
  1013. Just wondering...
  1014. - -- 
  1015.  Jamie McCarthy      Internet: k044477@kzoo.edu      AppleLink: j.mccarthy
  1016.  "It's bad enough to send a rude message to another via such an anonymous
  1017.   channel [as email].  To flame someone on an open forum is, to me, the
  1018.   height of insensitivity."                                 - P.J. Plauger
  1019.  
  1020. +++++++++++++++++++++++++++
  1021.  
  1022. From: tree@kira.uvm.edu (Tom Emerson)
  1023. Date: 17 Sep 92 20:11:24 GMT
  1024. Organization: University of Vermont, EMBA Computer Facility
  1025.  
  1026. In article <1992Sep17.154420.8390@hobbes.kzoo.edu> k044477@hobbes.kzoo.edu (Jamie R. McCarthy) writes:
  1027.  
  1028.    I'm playing around, making a code segment, and there's a short bit where
  1029.    I need four address registers.  Turns out I only get two!  If I
  1030.    understand correctly, A7, A6, and A5 are the system's;  A4 is my
  1031.    globals, and A0 and A1 are reserved for scratch use.
  1032.  
  1033. You can use registers A0 and A1 without saving them in your function. However
  1034. they are used for scratch, like you said, so you can't save them. As far as I
  1035. know, THC has always used this technique. You could also use A2 and A3, though
  1036. these are sometimes used by the compiler/optimizer. In general it would be
  1037. safest to save them on the stack first. Or define those registers as register
  1038. variables and let the compiler take care of it for you.
  1039.  
  1040. Tom
  1041. - --
  1042.    Tom Emerson                                    Technical Support
  1043.    Language Products Group                     Symantec Corporation
  1044.             Internet: tree@uvm.edu
  1045.  
  1046. ---------------------------
  1047.  
  1048. End of C.S.M.P. Digest
  1049. **********************
  1050.