home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / csmpdigest / csmp-digest-v3-059 < prev    next >
Text File  |  2010-09-21  |  87KB  |  2,615 lines

  1. Received-Date: Mon, 19 Sep 1994 11:51:29 +0200
  2. From: pottier@clipper.ens.fr (Francois Pottier)
  3. Subject: csmp-digest-v3-059
  4. To: csmp-digest@ens.fr
  5. Date: Mon, 19 Sep 1994 11:51:20 +0200 (MET DST)
  6. X-Mailer: ELM [version 2.4 PL23]
  7. Mime-Version: 1.0
  8. Content-Type: text/plain; charset=ISO-8859-1
  9. Content-Transfer-Encoding: 8bit
  10. Errors-To: listman@ens.fr
  11. Reply-To: pottier@clipper.ens.fr
  12. X-Sequence: 64
  13.  
  14. C.S.M.P. Digest             Mon, 19 Sep 94       Volume 3 : Issue 59
  15.  
  16. Today's Topics:
  17.  
  18.         AppleGuide script examples anyone?
  19.         Crazy error alert messages?
  20.         Goto Pro's and Con's
  21.         Need help with saving-writing structs to a file.
  22.         PBCatSearch-catChangedErr
  23.         PixToPic
  24.         Slashed Progress Bar
  25.  
  26.  
  27.  
  28. The Comp.Sys.Mac.Programmer Digest is moderated by Francois Pottier
  29. (pottier@clipper.ens.fr).
  30.  
  31. The digest is a collection of article threads from the internet newsgroup
  32. comp.sys.mac.programmer.  It is designed for people who read c.s.m.p. semi-
  33. regularly and want an archive of the discussions.  If you don't know what a
  34. newsgroup is, you probably don't have access to it.  Ask your systems
  35. administrator(s) for details.  If you don't have access to news, you may
  36. still be able to post messages to the group by using a mail server like
  37. anon.penet.fi (mail help@anon.penet.fi for more information).
  38.  
  39. Each issue of the digest contains one or more sets of articles (called
  40. threads), with each set corresponding to a 'discussion' of a particular
  41. subject.  The articles are not edited; all articles included in this digest
  42. are in their original posted form (as received by our news server at
  43. nef.ens.fr).  Article threads are not added to the digest until the last
  44. article added to the thread is at least two weeks old (this is to ensure that
  45. the thread is dead before adding it to the digest).  Article threads that
  46. consist of only one message are generally not included in the digest.
  47.  
  48. The digest is officially distributed by two means, by email and ftp.
  49.  
  50. If you want to receive the digest by mail, send email to listserv@ens.fr
  51. with no subject and one of the following commands as body:
  52.     help                        Sends you a summary of commands
  53.     subscribe csmp-digest Your Name    Adds you to the mailing list
  54.     signoff csmp-digest            Removes you from the list
  55. Once you have subscribed, you will automatically receive each new
  56. issue as it is created.
  57.  
  58. The official ftp info is //ftp.dartmouth.edu/pub/csmp-digest.
  59. Questions related to the ftp site should be directed to
  60. scott.silver@dartmouth.edu. Currently no previous volumes of the CSMP
  61. digest are available there.
  62.  
  63. Also, the digests are available to WAIS users.  To search back issues
  64. with WAIS, use comp.sys.mac.programmer.src. With Mosaic, use
  65. http://www.wais.com/wais-dbs/comp.sys.mac.programmer.html.
  66.  
  67.  
  68. -------------------------------------------------------
  69.  
  70. >From d.a.davies@bham.ac.uk (David Davies)
  71. Subject: AppleGuide script examples anyone?
  72. Date: Thu, 01 Sep 1994 14:27:20 +0000
  73. Organization: Birmingham University, UK.
  74.  
  75. Has anyone had a go at writing scripts for AppleGuide? Would anyone mind
  76. showing me just the simplest example if they have one. I've seen lots of
  77. compiled guides working but not seen the source for any as yet. I have a
  78. version of GuideMaker from one of the 7.5 beta CDs and I wanted to have a
  79. go at making a Guide myself...
  80.  
  81. Thanks,
  82.  
  83. -- 
  84. David Davies
  85.  
  86. Department of Physiology, University of Birmingham, UK.
  87.  
  88. Tel: 021 414 3255        Fax: 021 414 6924
  89.  
  90. http://medweb.bham.ac.uk/http/signatures/davies.html
  91.  
  92. +++++++++++++++++++++++++++
  93.  
  94. >From quinn@cs.uwa.edu.au (Quinn "The Eskimo!")
  95. Date: Fri, 02 Sep 1994 11:58:43 +0800
  96. Organization: Department of Computer Science, The University of Western Australia
  97.  
  98. In article <d.a.davies-0109941427200001@med262.bham.ac.uk>,
  99. d.a.davies@bham.ac.uk (David Davies) wrote:
  100.  
  101. >Has anyone had a go at writing scripts for AppleGuide?
  102.  
  103. Yes (:
  104.  
  105. >Would anyone mind showing me just the simplest example if they have one.
  106.  
  107. [Well it's not simple but it is comprehensive.]  I just posted the source
  108. code to the Anarchie Guide to MacGifts, so it should show up on UMich and
  109. Info-Mac mirrors soon.
  110.  
  111. Here are the blurb I attached to the MacGifts mailing...
  112.  
  113. >Attached is the Anarchie Guide source code distribution.  Anarchie Guide
  114. >is one of the first publically available guides and I decided to make its
  115. >source code available for two reasons.  Firstly itπs very hard to localise
  116. >a guide without source code. Secondly there is no publically available
  117. >guide source code and I thought it would be a good chance to rectify that.
  118. >
  119. >You need GuideMaker to be able to build this source however the source
  120. >code files are text files and you can browse them with any text editor.
  121.  
  122. For those of you too excited to wait, you can FTP it from...
  123.  
  124.   ftp://redback.cs.uwa.edu.au/Others/Quinn/
  125.  
  126. Share and Enjoy.
  127. -- 
  128. Quinn "The Eskimo!"        "Scout in a can. Simple, cheap, easy
  129.                             to use and it's expendable!"
  130.   Now if only Redback would stay up for more than 5 minutes, huh Pete?
  131.  
  132. ---------------------------
  133.  
  134. >From rtmd30@email.sps.mot.com (Greg Ferguson)
  135. Subject: Crazy error alert messages?
  136. Date: Tue, 23 Aug 1994 20:45:12 GMT
  137. Organization: Motorola, Inc.
  138.  
  139. Hi,
  140.  
  141. We're looking for some ideas for out-of-the-ordinary Alert messages.
  142.  
  143. My manager suggested the following one day:
  144.  
  145. I suggest that we use this as the standard unanticipated error message in
  146. all applications that we develop.  That is, after analyzing all know error
  147. conditions (which hopefully would present a relevant error message),
  148. display the following message as a last resort:
  149.  
  150. AN ERROR HAS JUST OCCURRED WHICH WAS PREVIOUSLY THOUGHT TO BE IMPOSSIBLE.
  151.  
  152. (taken from an old mainframe manual)
  153.  
  154. This is for those "we're going to crash if you do that again" type situations.
  155.  
  156. BTW, we can afford to be a bit frivolous as this is for in-house and test
  157. code. :-)
  158.  
  159. Thanks,
  160.  
  161. Greg
  162.  
  163. -- 
  164.  
  165. Greg Ferguson
  166. rtmd30@email.sps.mot.com
  167.  
  168. +++++++++++++++++++++++++++
  169.  
  170. >From Jeff Abrahamson <Jeff@purple.com>
  171. Date: Wed, 24 Aug 94 08:18:36 -0500
  172. Organization: Purple
  173.  
  174.  
  175. In article <rtmd30-2308941345120001@pangaea.sps.mot.com>, Greg Ferguson writes:
  176.  
  177. > We're looking for some ideas for out-of-the-ordinary Alert messages.
  178. > My manager suggested the following one day:
  179. > I suggest that we use this as the standard unanticipated error message in
  180. > all applications that we develop.  That is, after analyzing all know error
  181. > conditions (which hopefully would present a relevant error message),
  182. > display the following message as a last resort:
  183. > AN ERROR HAS JUST OCCURRED WHICH WAS PREVIOUSLY THOUGHT TO BE IMPOSSIBLE.
  184. > (taken from an old mainframe manual)
  185. > This is for those "we're going to crash if you do that again" type 
  186. situations.
  187. > BTW, we can afford to be a bit frivolous as this is for in-house and test
  188. > code. :-)
  189.  
  190. Well, then, how about:
  191.  
  192.     A subspace error (-129937) has occurred. Please check
  193.     this universe for consistency.
  194.  
  195. or
  196.  
  197.     An ATSM error has occurred. Please quit as soon as possible
  198.     to avoid previous crashes.
  199.  
  200. [ATSM is the Advanced Time Services Manager. It was discussed either here in a 
  201. previous thread or on the CW mailing list. Jens Alfke has most thoroughly 
  202. documented its use. :-) ]
  203.  
  204. -Jeff Abrahamson
  205.  clio!jeff@vu-vlsi.ee.vill.edu
  206.  
  207. +++++++++++++++++++++++++++
  208.  
  209. >From kenlong@netcom.com (Ken Long)
  210. Date: Wed, 24 Aug 1994 15:18:50 GMT
  211. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  212.  
  213. How about:
  214.  
  215. "Yours is the only Macintosh this error ever occurred on."
  216.    "Please report what you did to cause it to Apple."
  217.  
  218. or:
  219.  
  220. "It broke!"
  221.  
  222. or:
  223.  
  224. "Why should I tell YOU what there error number was?"
  225.       "You'll never be able to correct it!"
  226.  
  227. "Try that again and you'll be ordered to use IBM's
  228.                  for 6 months"
  229.  
  230. All seriousness aside...
  231.  
  232. -Ken-
  233.  
  234. +++++++++++++++++++++++++++
  235.  
  236. >From ogawa@teleport.com (Arthur Ogawa)
  237. Date: Wed, 24 Aug 94 21:25:02 GMT
  238. Organization: TeX Consultants
  239.  
  240. In Article <94082408183600240@purple.com>, Jeff Abrahamson <Jeff@purple.com>
  241. wrote:
  242. >
  243. >In article <rtmd30-2308941345120001@pangaea.sps.mot.com>, Greg Ferguson writes:
  244. >
  245. >> We're looking for some ideas for out-of-the-ordinary Alert messages.
  246. [deleted]
  247. Here's one from TeX, by Donald Knuth:
  248.  
  249. "This can't happen"
  250. Arthur Ogawa, TeX Consultants, Kaweah CA 93237-0051
  251. Ph: 209/561-4585, FAX: -4584
  252. PGP Key: finger -l ogawa@teleport.com
  253.  
  254. +++++++++++++++++++++++++++
  255.  
  256. >From spencerl@crl.com (Spencer Low)
  257. Date: Wed, 24 Aug 1994 16:45:44 -0800
  258. Organization: LowTek Creations
  259.  
  260. In article <94082408183600240@purple.com>, clio!jeff@vu-vlsi.ee.vill.edu wrote:
  261. >     A subspace error (-129937) has occurred. Please check
  262. >     this universe for consistency.
  263.  
  264. Of course, you could also include the following one (for you develop readers):
  265.  
  266.       A subspace error (-16.7 * 10^6) has occured. pi does *not*
  267.       equal 3.141592654. Please make sure your universe is in
  268.       existance.
  269.  
  270. Spencer
  271. ________________________________________________________________________
  272.   Spencer "MaxRAM" Low ------ LowTek Creations ----- spencerl@crl.com
  273.  
  274. +++++++++++++++++++++++++++
  275.  
  276. >From Manuel Veloso <veloso@netcom.com>
  277. Date: Fri, 26 Aug 1994 06:11:38 GMT
  278. Organization: Ibex Productions
  279.  
  280. In article <rtmd30-2308941345120001@pangaea.sps.mot.com> Greg Ferguson,
  281. rtmd30@email.sps.mot.com writes:
  282. >We're looking for some ideas for out-of-the-ordinary Alert messages.
  283.  
  284. Why not just use the simple, yet poignant,
  285.  
  286. "Whoops!"
  287.  
  288. or the more minimal message from mpw gcc
  289.  
  290. "Ack!"
  291.  
  292. or the ultimate testing message from Radiation,
  293.  
  294. "Warning! The radiation shield on your Macintosh has failed.
  295. Please step back 5 feet."
  296.  
  297. +++++++++++++++++++++++++++
  298.  
  299. >From goo@cwis.unomaha.edu (Kent Radek)
  300. Date: 27 Aug 94 03:19:27 GMT
  301. Organization: University of Nebraska Omaha
  302.  
  303. I once got a message like this in the CodeWarrior debugger:
  304.  
  305. "An error #-930 has occurred, because an error occurred."
  306.  
  307. goo
  308.  
  309. +++++++++++++++++++++++++++
  310.  
  311. >From reinder@neuretp.biol.ruu.nl (Reinder Verlinde)
  312. Date: Wed, 31 Aug 1994 14:41:13 GMT
  313. Organization: Rijksuniversiteit Utrecht
  314.  
  315. How about:
  316.  
  317.   "The item <name> could not be deleted because it doesn't exist"
  318.  
  319. (Macintosh Finder)
  320.  
  321. or:
  322.  
  323.   "numeric constant too long (> 255 characters)"
  324.  
  325. (MPW C++)
  326.  
  327.   "too many errors on one line. Use fewer"
  328.   "This union already has a perfectly good definition"
  329.   "This struct already has a perfectly good definition"
  330.   "This array has no size, and that's bad"
  331.   "Only one parameter per register please"
  332.   "a typedef name was a complete surprise to me at this point in your
  333. program"
  334.   "type in (cast) must be scalar; ANSI 3.3.4; page 39, lines 10-11 (I
  335. know
  336.    you don't care, I'm just trying to annoy you)"
  337.   "Call me paranoid but finding '/*' inside this comment makes me
  338. suspicious"
  339.   "Trailing comma not permitted in enum definition.  (This time I'm
  340. letting
  341.    you off with a warning)"
  342.   "This function has an explicit return type and deserves a return
  343. value"
  344.   "...And the lord said, 'lo, there shall only be case or default
  345. labels
  346.    inside a switch statement'"
  347.   "Symbol table full - fatal heap error; please go buy a RAM upgrade
  348. from
  349.    your local Apple dealer"
  350.   "String literal too long (I let you have 512 characters, that's 3
  351. more than
  352.    ANSI said I should)"
  353.   "This label is the target of a goto from outside of the block
  354. containing
  355.    this label AND this block has an automatic variable with an
  356. initializer
  357.    AND your window wasn't wide enough to read this whole error message"
  358.  
  359. (all from MPW C)
  360.  
  361. reinder@neuretp.biol.ruu.nl (Reinder Verlinde)
  362.  
  363. +++++++++++++++++++++++++++
  364.  
  365. >From deanp@zikzak.apana.org.au (Dean Perry)
  366. Date: 4 Sep 1994 04:29:15 GMT
  367. Organization: Zikzak public access UNIX, Melbourne Australia
  368.  
  369. Greg Ferguson (rtmd30@email.sps.mot.com) wrote:
  370.  
  371. : We're looking for some ideas for out-of-the-ordinary Alert messages.
  372.  
  373. This one, hijacked from an old (85?) BMUG newsletter (ish)
  374.  
  375. "Really spin the hard disk at 90000 rpm?"
  376.  
  377. <YES>   <MAYBE>
  378.  
  379.  
  380. dean
  381. --
  382.         Zikzak public access UNIX, Melbourne, Australia.
  383.  
  384. +++++++++++++++++++++++++++
  385.  
  386. >From deanp@zikzak.apana.org.au (Dean Perry)
  387. Date: 5 Sep 1994 14:22:48 GMT
  388. Organization: Zikzak public access UNIX, Melbourne Australia
  389.  
  390. Or this cutie, from MacApp this evening:
  391.  
  392. Could not complete the command "x" because "class", an internal component 
  393. is missing.  Call Apple for a secret decoder ring.
  394.  
  395. dean (again)
  396. --
  397.         Zikzak public access UNIX, Melbourne, Australia.
  398.  
  399. ---------------------------
  400.  
  401. >From steven.webber@digitec.co.za (Steven Webber) 
  402. Subject: Goto Pro's and Con's
  403. Date: 23 Aug 94 23:21:00 GMT
  404. Organization: Digitec Online
  405.  
  406. Hi there.
  407.  
  408. I've got a question for all you programmers out there. 
  409.  
  410. Do you use goto's in your code?  
  411.  
  412. Do you think using Goto's is a bad or good idea?
  413.  
  414. Why do you like/dislike using them?
  415.  
  416. Everybodies ideas would be most welcome.
  417.  
  418. Thanks 
  419. Steven.
  420.  
  421. Steven.Webber@Digitec.co.za
  422. ___ Blue Wave/QWK v2.12 OS/2
  423.  
  424. - --
  425. - - Digitec Online --- Johannesburg, South Africa --- tel +27 11 476-2008 ---
  426. - - You can TELNET Africa's biggest and most popular BBS on 196.11.62.106 ---
  427.  
  428. +++++++++++++++++++++++++++
  429.  
  430. >From s3026557@titanic.mpce.mq.edu.au (Duncan Anker)
  431. Date: 24 Aug 1994 10:04:44 GMT
  432. Organization: Macquarie University, School of Mathematics, Physics, Computing and Electronics
  433.  
  434. Steven Webber (steven.webber@digitec.co.za) wrote:
  435. : Hi there.
  436.  
  437. : I've got a question for all you programmers out there. 
  438.  
  439. : Do you use goto's in your code?  
  440.  
  441. : Do you think using Goto's is a bad or good idea?
  442.  
  443. : Why do you like/dislike using them?
  444.  
  445. : Everybodies ideas would be most welcome.
  446.  
  447. Thou shalt not use gotos. Neither shalt thou abolish them entirely.
  448.  
  449. Personally, I don't use them, although they can be useful when escaping
  450. from error situations in deeply nested code (or so I've heard).
  451.  
  452. If you find yourself using gotos, consider rewriting your functions. :-)
  453.  
  454. cheers.
  455.  
  456. --
  457. s3026557@titanic.mpce.mq.edu.au * Duncan Anker * e3026557@hardy.ocs.mq.edu.au
  458.  
  459. If you're a horse, and someone gets on you, and falls off, and then gets right
  460. back on you, I think you should buck him off right away.
  461.  
  462. +++++++++++++++++++++++++++
  463.  
  464. >From eascharf@u.washington.edu (Elizabeth Scharf)
  465. Date: 24 Aug 1994 13:59:22 GMT
  466. Organization: University of Washington, Seattle
  467.  
  468. I am fairly partial to break/continue statements for making loop 
  469. execution easier to read.  I also use goto for error handling in some 
  470. routines, but with several restrictions, like only one label per routine 
  471. called "CleanUp:" and only one return point which is after CleanUp.  I 
  472. try to write code that can determine its error state and what needs 
  473. cleaning up at the end so as to make the goto basically like the end of a 
  474. bunch of if statements, but without the code waterfall.  Other than that, 
  475. I try to avoid them because they make things harder to read and maintain.
  476.  
  477. Donald Knuth presents several examples where using gotos are beneficial, 
  478. usually for algorithm optomization (see Knuth, "Literate Programming")  A 
  479. good read in any case.
  480.  
  481. rmgw
  482.  
  483. This is not my account:  Please address replies to hawkfish@aol.com
  484.  
  485. Disclaimer:  All views expressed are entirely my own and do not reflect 
  486. the opinions of Elizabeth Scharf or the University of Washington.
  487.  
  488. - ---------------------------------------------------------------------------
  489. Richard Wesley             | "No, No No, 'Eureka' is Greek; it means 'This
  490. hawkfish@aol.com           |  bath is too hot'"
  491. 71062.1711@compuserve.com  |                      - Dr. Who
  492. - ---------------------------------------------------------------------------
  493.  
  494.  
  495. +++++++++++++++++++++++++++
  496.  
  497. >From dennis@mr2.ece.cmu.edu (Dennis J. Ciplickas)
  498. Date: 24 Aug 1994 14:25:39 GMT
  499. Organization: Electrical and Computer Engineering, Carnegie Mellon
  500.  
  501.  
  502. In article <300.310.uupcb@digitec.co.za> steven.webber@digitec.co.za (Steven Webber)  writes:
  503. >Hi there.
  504. >I've got a question for all you programmers out there. 
  505. >Do you use goto's in your code?  
  506. >Do you think using Goto's is a bad or good idea?
  507. >Why do you like/dislike using them?
  508.  
  509. (You didn't specify which language you were thinking about, but I'll
  510. assume C.)  I regularly use an "error exit" goto construct in my C
  511. code because it's just too damn difficult to unravel yourself at each
  512. point where you might need to exit.  A common example is in a routine
  513. that must allocate a few different items, and if any one of them fails
  514. you complain to the user and quit.  For example:
  515.  
  516. OSErr Allocater(void)
  517. {
  518.   OSErr err;
  519.   Handle h1,h2;
  520.   Ptr p1,p2;
  521.  
  522.   // null out our block pointers so that if we have to leave
  523.   // prematurely, only those that actually got allocated get
  524.   // deallocated.
  525.   h1 = h2 = NULL;
  526.   p1 = p2 = NULL;
  527.  
  528.   // now allocate all the blocks
  529.   if (!(h1 = NewHandle(10))) {
  530.     err = MemError();
  531.     showerror(1,"Memory Error %d allocating h1.");
  532.     goto errexit;
  533.     }
  534.  
  535.   if (!(h2 = NewHandle(20))) {
  536.     err = MemError();
  537.     showerror(1,"Memory Error %d allocating h2.");
  538.     goto errexit;
  539.     }
  540.  
  541.   if (!(p1 = NewPtr(10))) {
  542.     err = MemError();
  543.     showerror(1,"Memory Error %d allocating p1.");
  544.     goto errexit;
  545.     }
  546.  
  547.   if (!(p2 = NewPtr(10))) {
  548.     err = MemError();
  549.     showerror(1,"Memory Error %d allocating p2.");
  550.     goto errexit;
  551.     }
  552.  
  553.   // then do some work.
  554.   ...
  555.   if (err = DoSomethingElse(h1,h2)) goto errexit;
  556.   ...
  557.   err = noErr;
  558.  
  559.   // deallocate and leave
  560.  
  561. errexit:
  562.   if (h1) DisposHandle(h1);
  563.   if (h2) DisposHandle(h2);
  564.   if (p1) DisposPtr(p1);
  565.   if (p2) DisposPtr(p2);
  566.  
  567.   return err;
  568. }
  569.  
  570. -Dennis
  571.  
  572. +++++++++++++++++++++++++++
  573.  
  574. >From pcastine@prz.tu-berlin.de (Peter Castine)
  575. Date: Wed, 24 Aug 1994 15:24:35 GMT
  576. Organization: Process Control Center
  577.  
  578. In article <300.310.uupcb@digitec.co.za>, steven.webber@digitec.co.za
  579. (Steven Webber) wrote:
  580.  
  581. > Hi there.
  582. > I've got a question for all you programmers out there. 
  583. > Do you use goto's in your code?  
  584. > Do you think using Goto's is a bad or good idea?
  585. > Why do you like/dislike using them?
  586. > Everybodies ideas would be most welcome.
  587.  
  588. Haven't used a goto since I stopped programming in BASIC (which was when I
  589. bought my own Mac in '86). Actually, the last BASIC I used (BBC BASIC on
  590. an Acorn Beeb) let me avoid GOTOs _almost_ entirely, so add a few years.
  591.  
  592. The problems with GOTO are discussed thoroughly in Anthony Hoare's seminal
  593. paper ``GOTO cosidered dangerous'' (Sorry, I don't have the complete
  594. reference) and in every book on structured programming techniques written
  595. since.
  596.  
  597. Essentially, there is nothing you can do with GOTO you can't do with
  598. procedure calls, stuctured loops, and if-then-else constructs. Structured
  599. code is generally easier to read and understand (and, hence, easier to
  600. modify without causing it to stop working). There are some exceptional
  601. situations where GOTOs may make sense (C's break, continue, and exit
  602. statements are semi-structured GOTOs in disguise; in other languages you
  603. might use a GOTO where you'd see a break in C).
  604.  
  605. -- 
  606. Peter Castine               | C (n.): A programming language that is sort of
  607. pcastine@prz.tu-berlin.de   | like Pascal except more like assembly except
  608. Process Control Center      | that it isn't very much like either one, or
  609. Technical University Berlin | anything else.                  -- Ray Simard
  610.  
  611. +++++++++++++++++++++++++++
  612.  
  613. >From Darrin Cardani <Darrin.Cardani@AtlantaGA.NCR.COM>
  614. Date: Wed, 24 Aug 1994 13:31:38 GMT
  615. Organization: AT&T Global Information Solutions, Atlanta
  616.  
  617. >In article <300.310.uupcb@digitec.co.za> Steven Webber writes: 
  618. >Hi there.
  619. >
  620. >I've got a question for all you programmers out there. 
  621. >
  622. >Do you use goto's in your code?  
  623.  
  624. Occasionally. The only time I really use them (well, in non-BASIC programming ;)
  625. is for error handling. I often have a set of Sound Manager
  626. calls that look something like this:
  627.  
  628. {
  629.    SndError = SndManagerCall1 (blah);
  630.    if (SndError != noError)
  631.      goto Cleanup;
  632.  
  633.    SndError = SndManagerCall2 (blah);
  634.    if (SndError != noError)
  635.       goto Cleanup;
  636.  
  637. ..etc...
  638.  
  639.    return (noError);
  640.  
  641.    Cleanup:
  642.       <Several lines of cleanup code, and return an error>
  643. }
  644.  
  645. >Do you think using Goto's is a bad or good idea?
  646.  
  647. In general I use the control structures provided by the
  648. language since that's what they were made for. They're
  649. a bad idea if they obscure your code and don't add anything
  650. to it. I think in the above, it saves space and is pretty clear.
  651.  
  652. Darrin
  653.  
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  
  660. +++++++++++++++++++++++++++
  661.  
  662. >From jwbaxter@olympus.net (John W. Baxter)
  663. Date: Wed, 24 Aug 1994 08:17:32 -0700
  664. Organization: Internet for the Olympic Peninsula
  665.  
  666. In article <300.310.uupcb@digitec.co.za>, steven.webber@digitec.co.za
  667. (Steven Webber) wrote:
  668.  
  669. > Hi there.
  670. > I've got a question for all you programmers out there. 
  671. > Do you use goto's in your code?  
  672.  
  673. I use them when I feel they are the cleanest solution to a dirty problem. 
  674. As Sean mentioned, error handling can be one such, in a language such as
  675. see which doesn't provide something better.  C++ with exceptions offers
  676. something better...too bad it doesn't exist yet in many compilers.
  677.  
  678. > Do you think using Goto's is a bad or good idea?
  679. > Why do you like/dislike using them?
  680.  
  681. The cost of software is more in the maintenance than in the original
  682. coding.  Uncontrolled use of gotos usually makes the maintenance more
  683. expensive (and sometimes essentially impossible:  it's cheaper to start
  684. fresh), because it tends to make the code hard to read (for a human...the
  685. compiler does fine).  On the other hand, dirty tricks to avoid gotos has a
  686. similar effect...the code is hard to maintain.
  687.  
  688. But what do I know???...I've only been doing this since the late 1950s
  689. (and not continuously during that time).
  690.    --John
  691.  
  692. -- 
  693. John Baxter    Port Ludlow, WA, USA  [West shore, Puget Sound]
  694.    "Occasionally...astronomers add a second to either June 31 or
  695.     December 31..."   IM: OS Utilities, p 4-12
  696.    jwbaxter@pt.olympus.net
  697.  
  698. +++++++++++++++++++++++++++
  699.  
  700. >From h+@nada.kth.se (Jon W{tte)
  701. Date: Wed, 24 Aug 1994 23:10:27 +0200
  702. Organization: Royal Institute of Something or other
  703.  
  704. In article <300.310.uupcb@digitec.co.za>,
  705. steven.webber@digitec.co.za (Steven Webber)  wrote:
  706.  
  707. >Do you use goto's in your code?  
  708.  
  709. Yes.
  710.  
  711. >Do you think using Goto's is a bad or good idea?
  712. >Why do you like/dislike using them?
  713.  
  714. Sometimes they help structure code immensely, like when you 
  715. test for pre-conditions and want to take an early exit, but 
  716. still clean up stuff. Also for "retry" kinds of things it's 
  717. much simpler and easier on the eyes with a strategically-placed 
  718. goto.
  719.  
  720. C++ stack-based objects help reduce gotos, but not eliminate 
  721. them totally.
  722.  
  723. The controversy these days is on non-local gotos, like 
  724. longjmp() and C++ try/catch exceptions. I tend to like these as 
  725. well, but they _do_ add a need for careful structuring in order 
  726. to be used cleanly and effectively.
  727.  
  728.  
  729.  
  730.  
  731. --
  732.   Jon W‰tte (h+@nada.kth.se), Hagagatan 1, 113 48 Stockholm, Sweden
  733.  "Don't use the Layer Manager"
  734.  
  735.  
  736. +++++++++++++++++++++++++++
  737.  
  738. >From bootstrap1@aol.com (Bootstrap1)
  739. Date: 24 Aug 1994 17:40:16 -0400
  740. Organization: America Online, Inc. (1-800-827-6364)
  741.  
  742. In article <DENNIS.94Aug24102539@mr2.ece.cmu.edu>, dennis@mr2.ece.cmu.edu
  743. (Dennis J. Ciplickas) writes:
  744.  
  745. > I regularly use an "error exit" goto construct in my C
  746. > code because it's just too damn difficult to unravel yourself at each
  747. > point where you might need to exit.  A common example is in a routine
  748. > that must allocate a few different items, and if any one of them fails
  749. > you complain to the user and quit.  For example:
  750.  
  751. While I think it is fine to use a goto construct in a well structured way
  752. such as you illustrate in your example, I still never use them myself.  As
  753. with using continue and break in loops and return in the middle of
  754. functions, I find it makes the flow of a function more difficult to
  755. follow.  Knowing that a function starts executing at the top and falls
  756. straight through all the way to the bottom makes debugging and reading
  757. code much easier, at least for me.  And you can still avoid having to
  758. unravel on reaching an error conditions, as well as the dreaded "code
  759. waterfall" someone else mentioned, without using gotos, as the following
  760. edit of your sample shows
  761.  
  762. OSErr Allocater(void) {
  763.   OSErr err;
  764.   Handle h1,h2;
  765.   Ptr p1,p2;
  766.  
  767.   // null out our block pointers so that if we have to leave
  768.   // prematurely, only those that actually got allocated get
  769.   // deallocated.
  770.   h1 = h2 = NULL;
  771.   p1 = p2 = NULL;
  772.  
  773.   h1 = NewHandle(10);
  774.   if ((err = MemError()) != noErr)
  775.     showerror(1,"Memory Error %d allocating h1.");
  776.  
  777.   if (err == noErr) {
  778.     h2 = NewHandle(20);
  779.     if ((err = MemError()) != noErr)
  780.       showerror(1,"Memory Error %d allocating h2.");
  781.   }
  782.  
  783.   if (err == noErr) {
  784.     p1 = NewPtr(10);
  785.     if ((err = MemError()) != noErr)
  786.       showerror(1,"Memory Error %d allocating p1.");
  787.   }
  788.  
  789.   if (err == noErr) {
  790.     p2 = NewPtr(10);
  791.     if ((err = MemError()) != noErr)
  792.       showerror(1,"Memory Error %d allocating p2.");
  793.   }
  794.  
  795.   // then do some work.
  796.   ...
  797.   if (err == noErr)
  798.     err = DoSomethingElse(h1,h2);
  799.  
  800.   if (err != noErr) {
  801.     // deallocate
  802.  
  803.     if (h1) DisposHandle(h1);
  804.     if (h2) DisposHandle(h2);
  805.     if (p1) DisposPtr(p1);
  806.     if (p2) DisposPtr(p2);
  807.   }
  808.  
  809.   return err;
  810. }
  811.  
  812.  
  813. +++++++++++++++++++++++++++
  814.  
  815. >From howard@netcom.com (Howard Berkey)
  816. Date: Wed, 24 Aug 1994 22:42:04 GMT
  817. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  818.  
  819. In article <300.310.uupcb@digitec.co.za>,
  820. Steven Webber <steven.webber@digitec.co.za> wrote:
  821. >Hi there.
  822. >
  823. >I've got a question for all you programmers out there. 
  824. >
  825. >Do you use goto's in your code?  
  826. >
  827.  
  828. Oh, about as often as longjmp()  :-)
  829.  
  830.  
  831. >Do you think using Goto's is a bad or good idea?
  832. >
  833.  
  834. I can think of very few situations that require them, if any.  One
  835. might be removal of recursion in a routine that would be uglier to do
  836. in any other way.  *might* be.  99% of the time continue or break
  837. work as well or better in the remaining situations.
  838.  
  839. >Why do you like/dislike using them?
  840. >
  841.  
  842. It decreases readability of your code, complicates flow, is ugly, and
  843. makes your co-workers laugh at you.  It makes bugs potentially harder
  844. to find.  It is usually done as a quick hack or kludge (IOW it
  845. probably introduces a new bug).  
  846.  
  847.  
  848. -H-
  849.  
  850.  
  851.  
  852. -- 
  853. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  854. Howard Berkey                                             howard@netcom.com   
  855. Segmentation Fault (core dumped)
  856.  
  857. +++++++++++++++++++++++++++
  858.  
  859. >From hulburt@leland.stanford.edu (Greg Payne)
  860. Date: 25 Aug 1994 02:29:26 GMT
  861. Organization: Stanford University
  862.  
  863. In article <300.310.uupcb@digitec.co.za>
  864. steven.webber@digitec.co.za (Steven Webber)  writes:
  865.  
  866. > Hi there.
  867. > I've got a question for all you programmers out there. 
  868. > Do you use goto's in your code?  
  869. > Do you think using Goto's is a bad or good idea?
  870. > Why do you like/dislike using them?
  871. > Everybodies ideas would be most welcome.
  872. > Thanks 
  873. > Steven.
  874.  
  875. Well, here is my 2 cents:
  876.  
  877. I personally dont use gotos (too many people said they
  878. were bad in all my cs classes).  I supposed they have 
  879. their place, but they can really make code hard to 
  880. understand.  I translated an airfoil code from fortran
  881. to c, and it really wasn't documented too well.  I did
  882. know most of the general method, through, but it was
  883. a real pain going through goto-loops that wandered all over
  884. the place to do the same thing a switch or if then else
  885. in c.  Unless it is to get out of a deeply nest loop
  886. or for error-handling, I'd say they are probably bad 
  887. programming.
  888.  
  889. Greg Payne
  890. greg@aerometrics.com
  891.  
  892. +++++++++++++++++++++++++++
  893.  
  894. >From Bruce@hoult.actrix.gen.nz (Bruce Hoult)
  895. Date: Thu, 25 Aug 1994 19:18:17 +1200 (NZST)
  896. Organization: (none)
  897.  
  898. steven.webber@digitec.co.za (Steven Webber)  writes:
  899. > I've got a question for all you programmers out there. 
  900. > Do you use goto's in your code?  
  901.  
  902. In assembler: all the time.
  903. In C or Pascal:  I don't remember the last time.  10 years ago?  You
  904. don't need them.
  905.  
  906. -- Bruce
  907.  
  908. +++++++++++++++++++++++++++
  909.  
  910. >From radixinc@aol.com (RadixInc)
  911. Date: 25 Aug 1994 15:53:01 -0400
  912. Organization: America Online, Inc. (1-800-827-6364)
  913.  
  914. In article <2860687096@hoult.actrix.gen.nz>, Bruce@hoult.actrix.gen.nz
  915. (Bruce Hoult) writes:
  916.  
  917. <<I've got a question for all you programmers out there. 
  918.  
  919. Do you use goto's in your code? >>
  920.  
  921. In C, I use goto once in a while for one purpose only: to get out of a
  922. loop or deep if... structure when something awful happens. I used to write
  923. the gotos myself, but I've been using the exception-handling macros that
  924. were in a "d e v e l o p" article a few issues back, and they look like
  925. function calls, even though they turn into gotos. If I had real exception
  926. handling I wouldn't need to use goto at all, though there is something
  927. nice about having the error handling and recovery/cleanup code in the same
  928. function that generates the error.
  929.  
  930. I used gotos once before to write a state-machine parser, but again I had
  931. macros to hide the goto/label stuff. This technique was discussed in
  932. "Computer Language" magazine, May 1991, and it worked out very well.
  933.  
  934. There are times when goto is the best and cleanest way to do something,
  935. but you have to discipline yourself to use goto only when you are
  936. convinced that there is no cleaner way to go. I've yet to see a decent C
  937. programmer use goto in the offhand way a lot of BASIC programmers use it.
  938.  
  939. A lot of the anti-goto sentiment comes out of Wirth's article "GOTO
  940. considered harmful," and he was referring to languages current at the
  941. time: PL/I, Fortran, and most of all BASIC. The typical Pascal book
  942. (including Wirth's) rail against goto, but he also acknowledges the (rare)
  943. necessity of it, because Pascal does after all implement goto. For
  944. example, removing tail recursion from algorithms like Quicksort is
  945. arguably best done with a goto, even in Pascal. (Of course there are other
  946. ways to do this; please don't assail me with goto-less Quicksorts). Wirth
  947. is right about the careless and unnecessary use of goto common in Fortran,
  948. BASIC, and PL/I, but those languages don't (or didn't at the time) have
  949. the control structures needed to obviate the use of goto. In modern
  950. languages, and modern implementations of Fortran and BASIC, the goto is
  951. mostly unnecessary, as it is in C and Pascal.
  952.  
  953. Gregory Jorgensen
  954. Radix Consulting Inc.
  955.  
  956.  
  957. +++++++++++++++++++++++++++
  958.  
  959. >From alexr@apple.com (Alexander M. Rosenberg)
  960. Date: Thu, 25 Aug 1994 21:26:02 GMT
  961. Organization: Hackers Anonymous
  962.  
  963. In article <300.310.uupcb@digitec.co.za>, steven.webber@digitec.co.za
  964. (Steven Webber) wrote:
  965.  
  966. > I've got a question for all you programmers out there. 
  967. > Do you use goto's in your code?  
  968. > Do you think using Goto's is a bad or good idea?
  969. > Why do you like/dislike using them?
  970.  
  971. Read Literate Programming by Donald Knuth. It includes an updated version
  972. of an old paper of his on this topic. I think that it should answer your
  973. questions quite nicely. (And it explained all those stupid looping
  974. constructs that Pascal has.)
  975.  
  976. - -------------------------------------------------------------------------
  977. -  Alexander M. Rosenberg  - INTERNET: alexr@apple.com      - Yoyodyne    -
  978. -  330 Waverley St., Apt B - UUCP:ucbvax!apple!alexr        - Propulsion  -
  979. -  Palo Alto, CA 94301     -                                - Systems     -
  980. -  (415) 329-8463          - Nobody is my employer so       - :-)         -
  981. -  (408) 974-3110          - nobody cares what I say.       -             -
  982.  
  983. +++++++++++++++++++++++++++
  984.  
  985. >From Bruce@hoult.actrix.gen.nz (Bruce Hoult)
  986. Date: Fri, 26 Aug 1994 11:25:15 +1200 (NZST)
  987. Organization: (none)
  988.  
  989. bootstrap1@aol.com (Bootstrap1) writes:
  990. > While I think it is fine to use a goto construct in a well structured way
  991. > such as you illustrate in your example, I still never use them myself.  As
  992. > with using continue and break in loops and return in the middle of
  993. > functions, I find it makes the flow of a function more difficult to
  994. > follow.  Knowing that a function starts executing at the top and falls
  995. > straight through all the way to the bottom makes debugging and reading
  996. > code much easier, at least for me.  And you can still avoid having to
  997. > unravel on reaching an error conditions, as well as the dreaded "code
  998. > waterfall" someone else mentioned, without using gotos, as the following
  999. > edit of your sample shows
  1000.  
  1001. A agree with your points, but dislike all the extra testing of err (both in
  1002. error and normal situations) in your solution, and you're *still* obscuring
  1003. the main flow of control in the normal situation.
  1004.  
  1005. I much prefer a "block" that uses break to exit when there is an error.
  1006. Yes, I read your comment about break, and disagree.
  1007.  
  1008. Unfortunately, C and Pascal don't have a construct with this purpose, but
  1009. one can easily be faked using "repeat until true" or "do { } while (0)"...
  1010.  
  1011. To further mangle this eample code:
  1012.  
  1013. OSErr Allocater(void) {
  1014.   OSErr err;
  1015.   Handle h1,h2;
  1016.   Ptr p1,p2;
  1017.  
  1018.   // null out our block pointers so that if we have to leave
  1019.   // prematurely, only those that actually got allocated get
  1020.   // deallocated.
  1021.   h1 = h2 = NULL;
  1022.   p1 = p2 = NULL;
  1023.   
  1024.   do { // once only for error checking
  1025.  
  1026.     h1 = NewHandle(10);
  1027.     if ((err = MemError()) != noErr){
  1028.      showerror(1,"Memory Error %d allocating h1."); break;
  1029.     }
  1030.   
  1031.     h2 = NewHandle(20);
  1032.     if ((err = MemError()) != noErr){
  1033.       showerror(1,"Memory Error %d allocating h2."); break;
  1034.     }
  1035.   
  1036.     p1 = NewPtr(10);
  1037.     if ((err = MemError()) != noErr){
  1038.       showerror(1,"Memory Error %d allocating p1."); break;
  1039.     }
  1040.   
  1041.     p2 = NewPtr(10);
  1042.     if ((err = MemError()) != noErr){
  1043.       showerror(1,"Memory Error %d allocating p2."); break;
  1044.     }
  1045.   
  1046.     // then do some work.
  1047.     ...
  1048.     err = DoSomethingElse(h1,h2);
  1049.      
  1050.   } while (0);
  1051.  
  1052.   if (err != noErr) {
  1053.     // deallocate
  1054.  
  1055.     if (h1) DisposHandle(h1);
  1056.     if (h2) DisposHandle(h2);
  1057.     if (p1) DisposPtr(p1);
  1058.     if (p2) DisposPtr(p2);
  1059.   }
  1060.  
  1061.   return err;
  1062. }
  1063.  
  1064. +++++++++++++++++++++++++++
  1065.  
  1066. >From Jaeger@fquest.com (Brian Stern)
  1067. Date: 26 Aug 1994 03:40:36 GMT
  1068. Organization: The University of Texas at Austin, Austin, Texas
  1069.  
  1070. In article <DENNIS.94Aug24102539@mr2.ece.cmu.edu>, dennis@mr2.ece.cmu.edu
  1071. (Dennis J. Ciplickas) wrote:
  1072.  
  1073. > In article <300.310.uupcb@digitec.co.za> steven.webber@digitec.co.za
  1074. (Steven Webber)  writes:
  1075. > >Hi there.
  1076. > >I've got a question for all you programmers out there. 
  1077. > >Do you use goto's in your code?  
  1078. > >Do you think using Goto's is a bad or good idea?
  1079. > >Why do you like/dislike using them?
  1080. > (You didn't specify which language you were thinking about, but I'll
  1081. > assume C.)  I regularly use an "error exit" goto construct in my C
  1082. > code because it's just too damn difficult to unravel yourself at each
  1083. > point where you might need to exit.  A common example is in a routine
  1084. > that must allocate a few different items, and if any one of them fails
  1085. > you complain to the user and quit.  For example:
  1086. [code chopped]
  1087. > -Dennis
  1088.  
  1089. The fact is that memerrors aren't fatal.  there's nothing wrong with
  1090. something like the following:
  1091.  
  1092. OSErr Allocater(void)
  1093. {
  1094.   OSErr err;
  1095.   Handle h1,h2;
  1096.   Ptr p1,p2;
  1097.  
  1098.    h1 = NewHandle( 10 );
  1099.    h2 = NewHandle( 20 );
  1100.    p1 = NewPtr( 10 );
  1101.    p2 = NewPtr( 10 );
  1102.  
  1103.    if ( noErr != ( err = MemError() ) )
  1104.      {
  1105.          // then do some work.
  1106.      }
  1107.    else
  1108.    {
  1109.       //report your errors
  1110.    }
  1111.  
  1112.   if ( h1 ) DisposHandle( h1 );
  1113.   if ( h2 ) DisposHandle( h2 );
  1114.   if ( p1 ) DisposPtr( p1 );
  1115.   if ( p2 ) DisposPtr( p2 );
  1116.  
  1117.   return err;
  1118. }
  1119.  
  1120. While I won't categorically say that gotos are evil, I haven't used one
  1121. since I gave up Fortran.
  1122.  
  1123. -- 
  1124. Brian  Stern  :-{)}
  1125. Jaeger@fquest.com
  1126.  
  1127. +++++++++++++++++++++++++++
  1128.  
  1129. >From radixinc@aol.com (RadixInc)
  1130. Date: 26 Aug 1994 00:35:04 -0400
  1131. Organization: America Online, Inc. (1-800-827-6364)
  1132.  
  1133. In article <33isqt$sie@search01.news.aol.com>, radixinc@aol.com (RadixInc)
  1134. writes:
  1135.  
  1136. <<A lot of the anti-goto sentiment comes out of Wirth's article "GOTO
  1137. considered harmful,...>>
  1138.  
  1139. As one polite person pointed out to me by email, the paper "GOTO
  1140. Considered Harmful" was written be Edsger Dijkstra, not Niklaus Wirth. I
  1141. always get them confused--they both have unpronouncable last names. I
  1142. believe Dijkstra's paper appeared in the CACM, but I don't have it. My
  1143. point remains the same, only that perhaps Dijkstra is a bit more adamant
  1144. about not using GOTO than Wirth.
  1145.  
  1146. Gregory Jorgensen
  1147. Radix Consulting Inc.
  1148.  
  1149. +++++++++++++++++++++++++++
  1150.  
  1151. >From radixinc@aol.com (RadixInc)
  1152. Date: 26 Aug 1994 02:59:05 -0400
  1153. Organization: America Online, Inc. (1-800-827-6364)
  1154.  
  1155. In article <DENNIS.94Aug24102539@mr2.ece.cmu.edu>, dennis@mr2.ece.cmu.edu
  1156. (Dennis J. Ciplickas) wrote:
  1157.  
  1158. << I regularly use an "error exit" goto construct in my C code because
  1159. it's just too damn difficult to unravel yourself at each point where you
  1160. might need to exit.>>
  1161.  
  1162. There's a good article in "d e v e l o p," August 1992, called "Living In
  1163. An Exceptional World" by Sean Parent. He proposes an elegant mechanism for
  1164. handling exceptions with macros, including clean-up and recovery. His
  1165. technique uses macros that resolve to gotos, but it keeps the source code
  1166. clean. I've been using these macros for a year or so, and I haven't had to
  1167. use an actual goto since. Check it out.
  1168.  
  1169. Gregory Jorgensen
  1170. Radix Consulting Inc.
  1171.  
  1172. +++++++++++++++++++++++++++
  1173.  
  1174. >From dennis@mr2.ece.cmu.edu (Dennis J. Ciplickas)
  1175. Date: 26 Aug 1994 16:07:46 GMT
  1176. Organization: Electrical and Computer Engineering, Carnegie Mellon
  1177.  
  1178. In article <33geo0$5h3@search01.news.aol.com> bootstrap1@aol.com (Bootstrap1) writes:
  1179. >In article <DENNIS.94Aug24102539@mr2.ece.cmu.edu>, dennis@mr2.ece.cmu.edu
  1180. >(Dennis J. Ciplickas) writes:
  1181. >> I regularly use an "error exit" goto construct in my C
  1182. >> code because it's just too damn difficult to unravel yourself at each
  1183. >> point where you might need to exit.  A common example is in a routine
  1184. >> that must allocate a few different items, and if any one of them fails
  1185. >> you complain to the user and quit.  For example:
  1186. >>[code deleted]
  1187. >
  1188. >While I think it is fine to use a goto construct in a well structured way
  1189. >such as you illustrate in your example, I still never use them myself.  As
  1190. >with using continue and break in loops and return in the middle of
  1191. >functions, I find it makes the flow of a function more difficult to
  1192. >follow.  Knowing that a function starts executing at the top and falls
  1193. >straight through all the way to the bottom makes debugging and reading
  1194. >code much easier, at least for me.  And you can still avoid having to
  1195. >unravel on reaching an error conditions, as well as the dreaded "code
  1196. >waterfall" someone else mentioned, without using gotos, as the following
  1197. >edit of your sample shows
  1198. >[code removed]
  1199.  
  1200. I understand your desire to keep the code readable, but in all
  1201. honesty, the sample code you provided was difficult to read.  Not to
  1202. mention it relies on the compiler to optimize away all of the
  1203. redundant checks on the err vaiarble.
  1204.  
  1205. To the original poster: in my mind, it comes down to this.  If using a
  1206. goto will make the code MORE readable and MORE maintainable, then go
  1207. for it.  If it will obscure the flow of the code then don't.  FORTRAN
  1208. did not give programmers good methods for dealing with code structure
  1209. (e.g. break, continue, etc.), only giving them the infamous GOTO to
  1210. implement such a flow.  Misuse of GOTO ended up obscuring the program
  1211. flow.
  1212.  
  1213. If I were to go out on a limb, I'd say that improper indentation makes
  1214. code unreadable (and hence more difficult to maintain) more than the
  1215. goto construct I presented.  (Of course, FORTRAN had stringent column
  1216. requirements, too, so it was also bogus in this respect.)
  1217.  
  1218. Just my $0.02.
  1219.  
  1220. -Dennis
  1221.  
  1222. +++++++++++++++++++++++++++
  1223.  
  1224. >From Kevin.R.Boyce@gsfc.nasa.gov (Kevin R. Boyce)
  1225. Date: Fri, 26 Aug 1994 12:47:08 -0400
  1226. Organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA
  1227.  
  1228. In article <33jrdo$95h@search01.news.aol.com>,
  1229.  radixinc@aol.com (RadixInc) wrote:
  1230.  
  1231. >In article <33isqt$sie@search01.news.aol.com>, radixinc@aol.com (RadixInc)
  1232. >writes:
  1233. >
  1234. ><<A lot of the anti-goto sentiment comes out of Wirth's article "GOTO
  1235. >considered harmful,...>>
  1236. >
  1237. >As one polite person pointed out to me by email, the paper "GOTO
  1238. >Considered Harmful" was written be Edsger Dijkstra, not Niklaus Wirth. I
  1239. >always get them confused--they both have unpronouncable last names. I
  1240. >believe Dijkstra's paper appeared in the CACM, but I don't have it.
  1241.  
  1242. >From Jargon File 3.0.0:
  1243.  
  1244. :considered harmful: adj. Edsger W. Dijkstra's note in the
  1245.    March 1968 "Communications of the ACM", "Goto Statement
  1246.    Considered Harmful", fired the first salvo in the structured
  1247.    programming wars.  Amusingly, the ACM considered the resulting
  1248.    acrimony sufficiently harmful that it will (by policy) no longer
  1249.    print an article taking so assertive a position against a coding
  1250.    practice.  In the ensuing decades, a large number of both serious
  1251.    papers and parodies have borne titles of the form "X
  1252.    considered Y".  The structured-programming wars eventually blew
  1253.    over with the realization that both sides were wrong, but use of
  1254.    such titles has remained as a persistent minor in-joke (the
  1255.    `considered silly' found at various places in this lexicon is
  1256.    related).
  1257. -- 
  1258. Kevin      Kevin.R.Boyce@gsfc.nasa.gov
  1259. What may appear to the faint-hearted as a limitless expanse of God-forsaken wilderness is in reality a golden opportunity for ourselves, and our children, and our children's children, and the generations a-comin' to carve a new life out of the American Indian.  
  1260.       --Firesign Theatre
  1261.  
  1262. +++++++++++++++++++++++++++
  1263.  
  1264. >From walkerj@math.scarolina.edu (James W. Walker)
  1265. Date: 26 Aug 1994 17:25:30 GMT
  1266. Organization: Dept. of Mathematics, Univ. of South Carolina
  1267.  
  1268. In article <33k3rp$b4v@search01.news.aol.com>, radixinc@aol.com (RadixInc)
  1269. wrote:
  1270.  
  1271. > There's a good article in "d e v e l o p," August 1992, called "Living In
  1272. > An Exceptional World" by Sean Parent. He proposes an elegant mechanism for
  1273. > handling exceptions with macros, including clean-up and recovery. His
  1274. > technique uses macros that resolve to gotos, but it keeps the source code
  1275. > clean. I've been using these macros for a year or so, and I haven't had to
  1276. > use an actual goto since. Check it out.
  1277.  
  1278. I use those macros too.  However, I renamed his "nrequire" as "forbid".  I
  1279. find it easier to read actual English words.
  1280.  
  1281. -- 
  1282.  Jim Walker
  1283.  
  1284. +++++++++++++++++++++++++++
  1285.  
  1286. >From hanrek@cts.com (Mark Hanrek)
  1287. Date: 26 Aug 1994 18:31:38 GMT
  1288. Organization: The Information Workshop
  1289.  
  1290.  
  1291. If one is using a modern language, the "rule" to not use goto's is meaningless.
  1292.  
  1293. It was a rule meant to deter "spaghetti code", because it was so easy to
  1294. create a tangled web.  With today's languages, we create messes of a
  1295. different kind.
  1296.  
  1297. The right thing to do, regardless, is to imitate the constructs and
  1298. structuring we find in good example source code.
  1299.  
  1300. Whether we code a "break", a "try/catch", or "goto", we are doing it
  1301. because it is the appropriate thing to do.
  1302.  
  1303.  
  1304.  
  1305. Hope this helps.
  1306.  
  1307. Mark Hanrek
  1308.  
  1309. +++++++++++++++++++++++++++
  1310.  
  1311. >From urge@mcl.ucsb.edu (Scott Bronson)
  1312. Date: 27 Aug 1994 23:27:35 GMT
  1313. Organization: University of California, Santa Barbara
  1314.  
  1315. In <Jaeger-2508942242470001@slip-1-21.ots.utexas.edu> Jaeger@fquest.com (Brian Stern) writes:
  1316.  
  1317. >The fact is that memerrors aren't fatal.  there's nothing wrong with
  1318. >something like the following:
  1319.  
  1320. >   h1 = NewHandle( 10 );
  1321. >   h2 = NewHandle( 20 );
  1322. >   p1 = NewPtr( 10 );
  1323. >   p2 = NewPtr( 10 );
  1324.  
  1325. >   if ( noErr != ( err = MemError() ) ) { /* do something */ }
  1326.  
  1327.  
  1328. Well, there's nothing wrong with *your* code, but there's a serious
  1329. flaw in this technique.
  1330.  
  1331. What about this:
  1332.  
  1333. h1 = NewHandle( 30 ), h2 = NewHandle( 10 );
  1334.  
  1335. If there are 26 bytes of memory free, h2 will be a vaild handle and
  1336. MemError() is going to report noErr because the last memory allocation
  1337. succeeded.  However, h1 will be nil!  If you do your memory allocations
  1338. from smallest to largest, you will probably be OK.  However, heap
  1339. fragmentation can still cause some unexpected surprises when mixing
  1340. the allocation of pointers and handles.
  1341.  
  1342. So, even though this works, I hope that no programmers rely on it
  1343. unless they're sure they know EXACTLY what they're doing.  Personally,
  1344. I shun it--too much analysis on noncritical parts of my code gives me
  1345. a bad case of programmer burnout.
  1346.  
  1347.     - Scott                (urge@mcl.mcl.ucsb.edu)
  1348.  
  1349.  
  1350. +++++++++++++++++++++++++++
  1351.  
  1352. >From bb@lightside.com (Bob Bradley)
  1353. Date: Sat, 27 Aug 1994 02:24:40 -0800
  1354. Organization: SS Software Inc.
  1355.  
  1356. In <Jaeger-2508942242470001@slip-1-21.ots.utexas.edu> Jaeger@fquest.com
  1357. (Brian Stern) writes:
  1358.  
  1359. >The fact is that memerrors aren't fatal.  there's nothing wrong with
  1360. >something like the following:
  1361. >   h1 = NewHandle( 10 );
  1362. >   h2 = NewHandle( 20 );
  1363. >   p1 = NewPtr( 10 );
  1364. >   p2 = NewPtr( 10 );
  1365.  
  1366. >   if ( noErr != ( err = MemError() ) ) { /* do something */ }
  1367.  
  1368. If you don't have enough memory for the first one, you're still going to
  1369. try all the others. I would check for both the handle not being NULL and
  1370. that MemError() did not return anything but, noErr after each call to
  1371. NewHandle(...).
  1372.  
  1373. +++++++++++++++++++++++++++
  1374.  
  1375. >From ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University)
  1376. Date: 29 Aug 94 16:58:57 +1200
  1377. Organization: University of Waikato, Hamilton, New Zealand
  1378.  
  1379. In article <300.310.uupcb@digitec.co.za>, steven.webber@digitec.co.za (Steven Webber)  writes:
  1380. >
  1381. > Do you use goto's in your code?
  1382.  
  1383. Nope. I use Modula-2, which doesn't have goto's.
  1384.  
  1385. > Do you think using Goto's is a bad or good idea?
  1386.  
  1387. I think overall they're a poor idea, because it's so hard to spot any mistakes
  1388. that you make with them. But then, I also think exceptions are a poor idea--I
  1389. like being able to see the control flow in my program at a glance.
  1390.  
  1391. Modula-2 has this LOOP construct, which is basically an endless loop, within
  1392. which you have to put EXIT statements to exit, eg:
  1393.  
  1394.     LOOP
  1395.       (* do some cool stuff *)
  1396.     IF ExitCondition1 THEN
  1397.         EXIT
  1398.     END (*IF*);
  1399.       (* do more cool stuff *)
  1400.     IF ExitCondition2 THEN
  1401.         EXIT
  1402.     END (*IF*)
  1403.       (* and so on *)
  1404.     END (*LOOP*)
  1405.  
  1406. Modula-2 also has the usual WHILE, REPEAT and FOR loops, just like Pascal,
  1407. but I find that 90% of my loops are LOOP loops. This is because I frequently
  1408. need to check for error returns from system calls, and abort the loop if I
  1409. get one.
  1410.  
  1411. Furthermore, I frequently encounter the need to check for error returns during
  1412. a linear sequence of operations, not necessarily in a loop, and abort the
  1413. sequence at the point I hit the error. This gave me the idea for a loop-
  1414. statement-that-doesn't-loop. I fake this in Modula-2 something like this:
  1415.  
  1416.     InitStorage;
  1417.     LOOP (*once*)
  1418.     DoOSCall1;
  1419.     IF Err <> noErr THEN
  1420.         EXIT
  1421.     END (*IF*);
  1422.     DoOSCall2;
  1423.     IF Err <> noErr THEN
  1424.         EXIT
  1425.     END (*IF*);
  1426.       (* all done *)
  1427.     EXIT
  1428.     END (*LOOP*);
  1429.     DisposeStorage
  1430.  
  1431. "InitStorage" initializes all pointers to NIL, marks files as unopened etc,
  1432. and "DisposeStorage" goes through and disposes of all allocated pointers,
  1433. closes all open files and so on. By strictly adhering to this layout, it's
  1434. always easy to see where control will go in all situations.
  1435.  
  1436. Thought for the week: Testing is of limited help if you can't write correct
  1437. code to begin with.
  1438.  
  1439. Lawrence D'Oliveiro                       fone: +64-7-856-2889
  1440. Info & Tech Services Division              fax: +64-7-838-4066
  1441. University of Waikato            electric mail: ldo@waikato.ac.nz
  1442. Hamilton, New Zealand    37^ 47' 26" S, 175^ 19' 7" E, GMT+12:00
  1443.  
  1444. +++++++++++++++++++++++++++
  1445.  
  1446. >From dbenn@leven.appcomp.utas.edu.au (David Benn)
  1447. Date: Tue, 30 Aug 94 02:32:39 GMT
  1448. Organization: University of Tasmania
  1449.  
  1450. I don't know if anyone has mentioned this during the course of this thread,
  1451. but "The C Users Journal", June 1994 has an article called "Control
  1452. Structures" which discusses many of the issues that have cropped up in this
  1453. discussion.
  1454.  
  1455. The article is in on page 81 and is by Chuck Allison.
  1456.  
  1457. Rgds,
  1458.  
  1459. David Benn
  1460.  
  1461. -- 
  1462. D.Benn@appcomp.utas.edu.au - David Benn. University of Tasmania at Launceston.
  1463. The effort to understand the universe is one of the few things that lifts
  1464. human life above the level of farce, and gives it some of the grace of 
  1465. tragedy. (Steven Weinberg)
  1466.  
  1467. +++++++++++++++++++++++++++
  1468.  
  1469. >From dowdy@apple.com (Tom Dowdy)
  1470. Date: Wed, 31 Aug 1994 00:25:26 GMT
  1471. Organization: Apple Computer, Inc.
  1472.  
  1473. In article <33k3rp$b4v@search01.news.aol.com>, radixinc@aol.com (RadixInc)
  1474. wrote:
  1475.  
  1476. > In article <DENNIS.94Aug24102539@mr2.ece.cmu.edu>, dennis@mr2.ece.cmu.edu
  1477. > (Dennis J. Ciplickas) wrote:
  1478. > << I regularly use an "error exit" goto construct in my C code because
  1479. > it's just too damn difficult to unravel yourself at each point where you
  1480. > might need to exit.>>
  1481. > There's a good article in "d e v e l o p," August 1992, called "Living In
  1482. > An Exceptional World" by Sean Parent. He proposes an elegant mechanism for
  1483. > handling exceptions with macros, including clean-up and recovery. His
  1484. > technique uses macros that resolve to gotos, but it keeps the source code
  1485. > clean. I've been using these macros for a year or so, and I haven't had to
  1486. > use an actual goto since. Check it out.
  1487.  
  1488. I'd like to put another vote down for this style of handling...
  1489.  
  1490. Sean wrote these macros for us a *loooong* time ago, and they are
  1491. used in various parts of system software, including just about
  1492. all of the GX printing code.  In fact, a version of Exceptions.h
  1493. ships with the GX includes because we couldn't imagine the work
  1494. involved in un-"nrequire"ing the sample driver code.
  1495.  
  1496. These macros take a small amount to get used to, but once you've
  1497. got it, you'll find that you just about never fail to include some
  1498. level of error handling in your code (even if it's just simple
  1499. cleanup-exit type).
  1500.  
  1501. -- 
  1502.  Tom Dowdy                  Internet: dowdy@apple.COM
  1503.  Apple Computer MS:302-3KS  UUCP: {sun,voder,amdahl,decwrl}!apple!dowdy
  1504.  1 Infinite Loop            AppleLink: DOWDY1
  1505.  Cupertino, CA 95014       
  1506.  "The 'Ooh-Ah' Bird is so called because it lays square eggs."
  1507.  
  1508. +++++++++++++++++++++++++++
  1509.  
  1510. >From h+@nada.kth.se (Jon W{tte)
  1511. Date: Fri, 02 Sep 1994 09:18:45 +0200
  1512. Organization: Royal Institute of Something or other
  1513.  
  1514. In article <dowdy-3008941725260001@17.202.68.12>,
  1515. dowdy@apple.com (Tom Dowdy) wrote:
  1516.  
  1517. >all of the GX printing code.  In fact, a version of Exceptions.h
  1518. >ships with the GX includes because we couldn't imagine the work
  1519. >involved in un-"nrequire"ing the sample driver code.
  1520.  
  1521. Yes, and during the beta cycle, I pointed out that the name 
  1522. "Exceptions.h" collides with the same file name in the Think 
  1523. Class Library, and suggested changing the name to 
  1524. GXExceptions.h, since the Think Class Library is probably the 
  1525. most used Mac application framework.
  1526.  
  1527. THIS WAS PROMISED!
  1528.  
  1529. Of course it didn't happen.
  1530.  
  1531. Cheers,
  1532.  
  1533.                     / h+
  1534.  
  1535.  
  1536. --
  1537.   Jon W‰tte (h+@nada.kth.se), Hagagatan 1, 113 48 Stockholm, Sweden
  1538.  
  1539.   Reality exists only in your imagination.
  1540.  
  1541.  
  1542. ---------------------------
  1543.  
  1544. >From jcd7106@tamsun.tamu.edu (John C. Daub)
  1545. Subject: Need help with saving-writing structs to a file.
  1546. Date: 3 Sep 1994 16:08:55 -0500
  1547. Organization: Texas A&M University, College Station
  1548.  
  1549.  
  1550. Hi :)  I'm having some trouble with trying to write stuff to a file.
  1551.  
  1552. My program is, essentially, a database.  The information the user enters
  1553. is saved in a struct (and linked list).  To illustrate, here's the
  1554. struct:
  1555.  
  1556. struct SongInfo
  1557. {
  1558.     Str255        title;
  1559.     Str255        artist;
  1560.     unsigned short    songTime;
  1561.     short        tempo;
  1562.     Boolean        isOriginal;
  1563.     Str255        songComments;
  1564.     Boolean        fitsGenCrit;
  1565.     short        listGen;
  1566.     short        menuItem;
  1567.     struct SongInfo *next, *prev;
  1568. };
  1569. typedef struct SongInfo SongInfo *SongInfoPtr;
  1570.  
  1571.  
  1572. >From what i can tell with my entering/editing functions, there seems
  1573. to be no problems with entering information nor with editing that
  1574. information (and even removing an entry).
  1575.  
  1576. But, when i try to save this information/structs/linked-list to a file,
  1577. I get all sorts of weird things (I open up the data fork, raw, in 
  1578. something like BBEdit Lite).
  1579.  
  1580. Here's my basic routine for trying to save:
  1581.  
  1582. (skip all the stuff about FSOpen(), Create(), SetEOF(), SetFPos(), etc).
  1583.  
  1584.  
  1585.     curPtr = gFirstSongInfoPtr;
  1586.  
  1587.     err = FSWrite( fRefNum, &(sizeof(SongInfo)), &curPtr );
  1588.     if ( err != noErr )
  1589.         return( err );
  1590.  
  1591.     curPtr = curPtr->next;
  1592.  
  1593. I also have a global to hold the offset...start at the beginning of the
  1594. file, add the one song, increase the offset global by sizeof(SongInfo),
  1595. then go back and repeat this until you get to the end of it all.
  1596.  
  1597. Now, i wonder if i'm doing something wrong with checking for curPtr->next = NIL
  1598. and then letting this while loop for the FSWrite() go too long, or what.
  1599.  
  1600. I've seen sample source that does this same sort of thing, and it works
  1601. fine there, but why not here?
  1602.  
  1603. One time, i ended up with parts of the database info, then i got half of
  1604. a source file in there (don't ask me how).
  1605.  
  1606. Could it be something to do with using Pascal strings?  Would it help
  1607. to perhaps save each part of the struct on it's own...like convert
  1608. the pascal strings to C strings (read them into an array or something),
  1609. enter that, then move to the next struct member, write that, then the
  1610. next, write that...each time increasing the offest by sizeof(variable)?
  1611.  
  1612. Any help in writing structs to a file would be greatly appreaciated :)
  1613.  
  1614. pleae email to:  hsoi@tamu.edu
  1615.  
  1616. thanx, John
  1617.  
  1618. +++++++++++++++++++++++++++
  1619.  
  1620. >From decartwr@newstand.syr.edu (Dana Cartwright 3rd)
  1621. Date: 3 Sep 1994 22:10:46 GMT
  1622. Organization: Syracuse University, Syracuse NY, USA
  1623.  
  1624. John C. Daub (jcd7106@tamsun.tamu.edu) wrote:
  1625.  
  1626. : But, when i try to save this information/structs/linked-list to a file,
  1627. : I get all sorts of weird things (I open up the data fork, raw, in 
  1628. : something like BBEdit Lite).
  1629.  
  1630. I try to avoid writing structs directly to files.  For at least two
  1631. reasons.  First, structs are compiled differently by different
  1632. compilers...that is, the compiler is free to add padding here and
  1633. there in structs to maintain data alignment.  So if you write a
  1634. struct to a file, there's a goodly chance you're writing more bytes
  1635. than you might imagine just from a visual inspection of the
  1636. struct, and if you re-compile your code with a different compiler
  1637. (even from the same company), you might no longer be able to read
  1638. back your older files.
  1639.  
  1640. Second, if you want any kind of cross-platform compatibility, you
  1641. have "little-endian" versus "big-endian" (basically, the order of
  1642. bytes within multi-byte numbers) issues, which are most easily 
  1643. dealt with by exercising VERY tight control over the way data is
  1644. read/written.  Hard to do that when you let the compiler dictate 
  1645. how your data is laid out.
  1646.  
  1647. I'm guessing here, but I would not be at all surprised if structs
  1648. were sometimes different on 68K versus PPC compilers.
  1649.  
  1650. So one way to "solve" your problem would be to more precisely control
  1651. your file format, which would also probably resolve some of the
  1652. problems you mention in your post.
  1653.  
  1654.  
  1655. +++++++++++++++++++++++++++
  1656.  
  1657. >From afcjlloyd@aol.com (AFC JLloyd)
  1658. Date: 3 Sep 1994 18:50:03 -0400
  1659. Organization: America Online, Inc. (1-800-827-6364)
  1660.  
  1661. In article <34aol7$p4u@tamsun.tamu.edu>, jcd7106@tamsun.tamu.edu (John C.
  1662. Daub) writes:
  1663.  
  1664. >Hi :)  I'm having some trouble with trying to write stuff to a file.
  1665. >
  1666. >[ some stuff omitted ]
  1667. >
  1668. >Here's my basic routine for trying to save:
  1669. >
  1670. >(skip all the stuff about FSOpen(), Create(), SetEOF(), SetFPos(), etc).
  1671. >
  1672. > curPtr = gFirstSongInfoPtr;
  1673. >
  1674. > err = FSWrite( fRefNum, &(sizeof(SongInfo)), &curPtr );
  1675.  
  1676. This FSWrite statement has two problems.  You should rewrite it like this:
  1677.  
  1678. long bytesWritten = sizeof(SongInfo);
  1679. err = FSWrite( fRefNum, &bytesWritten, curPtr );
  1680.  
  1681. It's not a good idea to pass an address of a compiler generated constant
  1682. to a function that will write into the address.  And if you want to write
  1683. out a set of bytes starting at an address, pass the
  1684. value of that address, not the address of a pointer that points to the
  1685. desired address.
  1686.  
  1687. Jim Lloyd
  1688. afcjlloyd@aol.com
  1689.  
  1690.  
  1691. +++++++++++++++++++++++++++
  1692.  
  1693. >From bb@lightside.com (Bob Bradley)
  1694. Date: Fri, 02 Sep 1994 17:42:28 -0800
  1695. Organization: SS Software Inc.
  1696.  
  1697. In article <34as96$hh3@newstand.syr.edu>, decartwr@mailbox.syr.edu wrote:
  1698.  
  1699. > I try to avoid writing structs directly to files.  For at least two
  1700. > reasons.  First, structs are compiled differently by different
  1701. > compilers...that is, the compiler is free to add padding here and
  1702. > there in structs to maintain data alignment.  So if you write a
  1703. > struct to a file, there's a goodly chance you're writing more bytes
  1704. > than you might imagine just from a visual inspection of the
  1705. > struct, and if you re-compile your code with a different compiler
  1706. > (even from the same company), you might no longer be able to read
  1707. > back your older files.
  1708.  
  1709. I wasn't aware of the problems that can arise when reading/writing structs
  1710. to a file, how can I change my code to fix the problems?
  1711.  
  1712. I typically have something like:
  1713.  
  1714. typedef struct
  1715. {
  1716.     short               shortNumber;
  1717.     FSSpec              spec;
  1718.  
  1719. }   MyRecord;
  1720.  
  1721. And I write that whole structure to disk. In order to do things correctly
  1722. (to elminate the problems mentioned above) do I have to write each field
  1723. of the structure individually? I frequently have structures inside of
  1724. structures and I also save some Apple defined structures to disk, is there
  1725. any way to fix the problem when you don't actually know the format of the
  1726. structure (ie. I wouldn't be able to save each individual field)?
  1727.  
  1728. +++++++++++++++++++++++++++
  1729.  
  1730. >From vanderHarg@DIMES.TUDelft.NL (Arthur van der Harg)
  1731. Date: Sun, 4 Sep 1994 12:16:54 GMT
  1732. Organization: Hardly
  1733.  
  1734. In article <34as96$hh3@newstand.syr.edu>, decartwr@mailbox.syr.edu wrote:
  1735.  
  1736. > I'm guessing here, but I would not be at all surprised if structs
  1737. > were sometimes different on 68K versus PPC compilers.
  1738.  
  1739. Or between differently compiled versions on 68k. SC++ 7.x lets you choose
  1740. field alignment to 1, 2 or 4-byte boundaries. So if you have a field with
  1741. an odd or non-mod4 number of bytes, the structure will be aligned
  1742. differently for different compiler *settings*, let alone different
  1743. compilers or different architectures.
  1744.  
  1745. Arthur
  1746.  
  1747. -- 
  1748. This message (c) Arthur van der Harg <vanderHarg@DIMES.TUDelft.nl>
  1749.  
  1750. +++++++++++++++++++++++++++
  1751.  
  1752. >From parkb@bigbang.Stanford.EDU (Brian Park)
  1753. Date: 5 Sep 1994 07:31:25 GMT
  1754. Organization: Stanford University
  1755.  
  1756. Dana Cartwright 3rd <decartwr@mailbox.syr.edu> wrote:
  1757. >I try to avoid writing structs directly to files.  For at least two
  1758. >reasons.  First, structs are compiled differently by different
  1759. >compilers...
  1760. [...]
  1761. >Second, if you want any kind of cross-platform compatibility, you
  1762. >have "little-endian" versus "big-endian" 
  1763. [...]
  1764.  
  1765. Resource Manager writes structures to files... doesn't it?
  1766.  
  1767. --
  1768. Brian Park
  1769. parkb@bigbang.stanford.edu
  1770.  
  1771. +++++++++++++++++++++++++++
  1772.  
  1773. >From hanrek@cts.com (Mark Hanrek)
  1774. Date: Mon, 5 Sep 1994 08:08:27 GMT
  1775. Organization: The Information Worskhop
  1776.  
  1777. In article <34aol7$p4u@tamsun.tamu.edu>, jcd7106@tamsun.tamu.edu (John C.
  1778. Daub) wrote:
  1779.  
  1780. > Hi :)  I'm having some trouble with trying to write stuff to a file.
  1781. > My program is, essentially, a database.  The information the user enters
  1782. > is saved in a struct (and linked list).  
  1783. >
  1784. > [ stuff deleted ]
  1785. > From what i can tell with my entering/editing functions, there seems
  1786. > to be no problems with entering information nor with editing that
  1787. > information (and even removing an entry).
  1788. > But, when i try to save this information/structs/linked-list to a file,
  1789. > I get all sorts of weird things (I open up the data fork, raw, in 
  1790. > something like BBEdit Lite).
  1791.  
  1792. John,
  1793.  
  1794. You didn't mention exactly how you are determining that something is wrong.  
  1795.  
  1796. Do things appear "wierd" only when you look at it with BBEdit?  It should
  1797. look wierd because you are writing binary stuff, no to mention that the
  1798. unused portions of p-strings and any fields that have not had anything
  1799. stored in them will have random values in them.  You'll want to use a hex
  1800. editor like HexEdit.
  1801.  
  1802. If you mean "wierd things when you read it back in"... of course, you
  1803. cannot expect the links ( next/previous ) to be correct.  You will want to
  1804. read in a record's worth from disk, but copy to good stuff into a brand
  1805. new record you've just created, just as you do when entering a new
  1806. record.  I figure you know this, but just in case. :)
  1807.  
  1808. Also, perhaps you should use FlushVol() as well, to ensure that all of
  1809. your file writes actually get written to disk.
  1810.  
  1811. The gist of my message here is that so often, there isn't a problem with
  1812. what we are examining, but with the methods we are using to examine
  1813. things.  That's not a new comet you've discovered, it is just a dead gnat
  1814. stuck to the lens of the telescope. :)  I've been bit by this one many
  1815. times ( but not lately :).
  1816.  
  1817. Just maybe one of the above will help to "jiggle something free" for ya.
  1818.  
  1819.  
  1820. Mark Hanrek
  1821.  
  1822. +++++++++++++++++++++++++++
  1823.  
  1824. >From howard@netcom.com (Howard Berkey)
  1825. Date: Mon, 5 Sep 1994 17:59:13 GMT
  1826. Organization: Psychonaut Foundation
  1827.  
  1828.  
  1829. Short answer:  look in a computer science textbook.
  1830.  
  1831. Non-snide answer:
  1832.  
  1833. Essentially the best way to write a data structure to a file is to first 
  1834. flatten it into an array, changing the pointers to array indices.  For 
  1835. example, to write a binary tree, make the root node element 0 of the array, 
  1836. and change its left and right node pointers to 1 and 2, respectively.  Then 
  1837. put the nodes they pointed to into those array elements.  Go to array element 
  1838. 1 and repeat.  And so on.  Reading back in is easy.  I'll append some code
  1839. at the end of the message.
  1840.  
  1841. A list is even easier.
  1842.  
  1843. Now, one thing to make sure of is that you are using the same structure
  1844. alignment between builds.  I stupidly bit myself the other day by not 
  1845. checking the project prefs in CodeWarrior the other day... the app I had
  1846. generating the file was set to 68K struct alignment, and the one reading 
  1847. it in was set to 68K 4-byte.  This caused all sorts of problems.
  1848.  
  1849. Luckily on the mac you don't need to worry about the endian-ness of the 
  1850. machine.  
  1851.  
  1852. Anyway, here's a quick example in C++.  I cut and pasted this from 
  1853. something in progress so it may contain bugs but it will get the general 
  1854. idea across (Assume that CPolygon is defined somewhere else and knows how 
  1855. to write itself):
  1856.  
  1857.  
  1858. class CBSPTree {
  1859.  
  1860. private:
  1861.       CPolygon *rootPoly;
  1862.       CBSPTree *backChild;
  1863.       CBSPTree *frontChild;
  1864.       int nodes;
  1865.       
  1866.       struct treeFileFormat 
  1867.       {
  1868.          CPolygon *thePoly;
  1869.          int       frontChild;
  1870.          int       backChild;
  1871.          int       nodes;
  1872.       };
  1873.          
  1874. public:
  1875.       
  1876.       void flattenSubtree(int current, int nextFree, struct treeFileFormat
  1877. *theArray);
  1878.  
  1879.       void writeTree(short treeFile);
  1880.       void readTree(short treeFile);
  1881.       
  1882. };
  1883.  
  1884.  
  1885.  
  1886. void CBSPTree :: writeTree(short treeFile)
  1887. {
  1888.    long inOutCount=(long) sizeof(int);
  1889.    int i;
  1890.    treeFileFormat *theArray;
  1891.    
  1892.    theArray = new treeFileFormat[this->nodes];
  1893.       
  1894.    flattenSubtree(0, 1, theArray);
  1895.             
  1896.    i=this->nodes + 1;
  1897.    FSWrite(treeFile,&inOutCount,&i);   
  1898.  
  1899.    for(i=0;i<=this->nodes;i++)
  1900.    {
  1901.       theArray[i].thePoly->writePoly(treeFile);
  1902.       FSWrite(treeFile,&inOutCount, &theArray[i].nodes);   
  1903.       FSWrite(treeFile,&inOutCount,&theArray[i].frontChild);   
  1904.       FSWrite(treeFile,&inOutCount,&theArray[i].backChild);   
  1905.    }
  1906. }
  1907.  
  1908.  
  1909.  
  1910. void CBSPTree :: flattenSubtree(int current, int nextFree, treeFileFormat
  1911. *theArray)
  1912. {      
  1913.        int myIndex;
  1914.        
  1915.        myIndex=current;
  1916.        
  1917.         if(this->rootPoly != NULL)
  1918.         {    
  1919.                 theArray[myIndex].thePoly=this->rootPoly;
  1920.                 theArray[myIndex].nodes=this->nodes;
  1921.                 if(this->frontChild != NULL)
  1922.                 {
  1923.                      theArray[myIndex].frontChild=nextFree++;
  1924.                      current=theArray[myIndex].frontChild;
  1925.                      this->frontChild->flattenSubtree(current,
  1926. nextFree,            theArray);
  1927.  
  1928.                 }
  1929.                 else
  1930.                 {
  1931.                      theArray[myIndex].frontChild=-1;
  1932.                 }
  1933.                 
  1934.                 if(this->backChild != NULL)
  1935.                 {
  1936.                      theArray[myIndex].backChild=nextFree++;
  1937.                      current=theArray[myIndex].backChild;
  1938.                      this->backChild->flattenSubtree(current, nextFree,
  1939. theArray);
  1940.  
  1941.                 }
  1942.                 else
  1943.                 {
  1944.                       theArray[myIndex].backChild=-1;
  1945.                 }
  1946.  
  1947.         }
  1948. }
  1949.  
  1950.  
  1951. void CBSPTree :: readTree(short treeFile)
  1952. {
  1953.    struct treeFileFormat *treeArray;
  1954.    CBSPTree *BSPArray, *tmpTree;
  1955.    long inOutCount=(long) sizeof(int);
  1956.    int i, count;
  1957.     
  1958.  
  1959.    SetFPos(treeFile, fsFromStart, 0);
  1960.    FSRead(treeFile, &inOutCount, &count);
  1961.    
  1962.    treeArray=new treeFileFormat[count];
  1963.    BSPArray=new CBSPTree[count];
  1964.       
  1965.    for(i=0;i<count;i++) 
  1966.    {
  1967.       treeArray[i].thePoly = new CPolygon;
  1968.       treeArray[i].thePoly->readPoly(treeFile);
  1969.       FSRead(treeFile, &inOutCount, &treeArray[i].nodes);
  1970.       FSRead(treeFile, &inOutCount, &treeArray[i].frontChild);
  1971.       FSRead(treeFile, &inOutCount, &treeArray[i].backChild);
  1972.    }
  1973.  
  1974.    for(i=0;i<count;i++)
  1975.     {
  1976.       
  1977.       BSPArray[i].rootPoly=treeArray[i].thePoly;
  1978.       BSPArray[i].nodes=treeArray[i].nodes;
  1979.       if(treeArray[i].frontChild != -1) BSPArray[i].frontChild 
  1980.                                        = &BSPArray[treeArray[i].frontChild];
  1981.       if(treeArray[i].backChild != -1) BSPArray[i].backChild 
  1982.                                        =
  1983. &BSPArray[treeArray[i].backChild];                                    
  1984.       
  1985.     }
  1986.     
  1987.    *this=BSPArray[0];   
  1988.  
  1989. }
  1990.  
  1991. -- 
  1992. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  1993. Howard Berkey                                     howard@netcom.com
  1994. Segmentation Fault (core dumped)
  1995.  
  1996. ---------------------------
  1997.  
  1998. >From wdh@fresh.com (Bill Hofmann)
  1999. Subject: PBCatSearch-catChangedErr
  2000. Date: Sat, 3 Sep 1994 21:41:58 GMT
  2001. Organization: Fresh Software
  2002.  
  2003. OK, I've got PBCatSearch working, it's a little arcane, but what isn't
  2004. nowadays.    I use the results to scan certain files for certain resources
  2005. (ie, I do an FSpOpenResFile on the files returned).  But here's the
  2006. problem: AutoDoubler (and I suppose other utils of that ilk) modify the
  2007. catalog when I open the files, causing PBCatSearch to return catChangedErr
  2008. (-1304) on the next call to it.
  2009.  
  2010. So far, the only real solution seems to be a real humongous search (ie, so
  2011. that I only have to call PBCatSearch once).  Am I right?
  2012. -Bill
  2013. -- 
  2014. Bill Hofmann                                   wdh@fresh.com
  2015. Fresh Software and Instructional Design        voice: +1 510 524 0852
  2016. 1640 San Pablo Ave #C Berkeley CA 94702 USA    fax:   +1 510 524 0853
  2017.  
  2018. +++++++++++++++++++++++++++
  2019.  
  2020. >From jumplong@aol.com (Jump Long)
  2021. Date: 4 Sep 1994 12:01:05 -0400
  2022. Organization: America Online, Inc. (1-800-827-6364)
  2023.  
  2024. In article <wdh-0309941441580001@wdh.slip.netcom.com>, wdh@fresh.com (Bill
  2025. Hofmann) writes:
  2026.  
  2027. >OK, I've got PBCatSearch working, it's a little arcane, but what isn't
  2028. >nowadays.    I use the results to scan certain files for certain
  2029. resources
  2030. >(ie, I do an FSpOpenResFile on the files returned).  But here's the
  2031. >problem: AutoDoubler (and I suppose other utils of that ilk) modify the
  2032. >catalog when I open the files, causing PBCatSearch to return
  2033. catChangedErr
  2034. >(-1304) on the next call to it.
  2035. >
  2036. >So far, the only real solution seems to be a real humongous search (ie,
  2037. so
  2038. >that I only have to call PBCatSearch once).  Am I right?
  2039.  
  2040. You're right, you're best off finding all of your matches and then
  2041. processing them after the matches are found. However, this makes it
  2042. impossible to let the user cancel a long search -- you need to weigh that
  2043. against the need to get all matches.
  2044.  
  2045. BTW: Any call that writes to an HFS volume will result in a catSearchErr.
  2046. The HFS file system is a little brain dead in this respect because it
  2047. really only needs to return catSearchErr if the *catalog* changes, not
  2048. *any* write to the volume. Since the AppleShare and File Sharing file
  2049. servers use HFS's CatSearch to search on the server Macintosh, this makes
  2050. searches on AppleShare volumes fail with afpCatalogChanged even more often
  2051. (in which case, the error cannot be ignored and the search cannot be
  2052. resumed) because there will likely be multiple writers on an AppleShare
  2053. volume. I guess I should try to get HFS's CatSearch problems all fixed in
  2054. the next System Update...
  2055.  
  2056. - Jim Luther
  2057.  
  2058. ---------------------------
  2059.  
  2060. >From JFN@cmq.qc.ca (Jean-Francois Nadeau)
  2061. Subject: PixToPic
  2062. Date: 05 Sep 1994 14:48:08 GMT
  2063. Organization: Club Macintosh de Quebec
  2064.  
  2065. Hello!
  2066.  
  2067. How i can transform a PICT resource in a PixMapHandle?
  2068.  
  2069. Thanks!
  2070.  
  2071. JFN@cmq.upc.qc.ca
  2072. - -----------------------------------------------------------
  2073. Synapse -- Le serveur telematique du Club Macintosh de Quebec
  2074. vox: 418.527.0250    fax: 418.527.9304    net: info@cmq.qc.ca
  2075. - -----------------------------------------------------------
  2076.  
  2077. +++++++++++++++++++++++++++
  2078.  
  2079. >From Dmitry Boldyrev <dmitry@atlas.chem.utah.edu>
  2080. Date: 5 Sep 1994 21:49:03 GMT
  2081. Organization: University of Utah
  2082.  
  2083. In article <65502.4681425@cmq.cmq.qc.ca> Jean-Francois Nadeau, JFN@cmq.qc.ca
  2084. writes:
  2085. >Hello!
  2086. >
  2087. >How i can transform a PICT resource in a PixMapHandle?
  2088. >
  2089. >Thanks!
  2090.  
  2091. Hmm.. It shouldn't be very hard.. 
  2092. void CiconToPixmap(short res_id, PixMapPtr thebitmap)
  2093. {
  2094.     CIconHandle                theicon;
  2095.     short                    right, bottom;
  2096.     unsigned long            offRowBytes, sizeOfmap;
  2097.     sysinfo                    system;
  2098.     Ptr                        offBaseAddr = nil;
  2099.     Rect                    wbounds;
  2100.     
  2101.     GWorldPtr                 currPort;   
  2102.     GDHandle                 currDev;       
  2103.     short                     err;                 
  2104.     static Rect             dOffBounds;        // Bounds of OffScreen Graphics                                                    //
  2105. World
  2106.     static GWorldPtr         gMyOffG;        // Pointer to OffScreen Graphics World
  2107.     Boolean                    gblockAlloc;    // Variable to check the successful memoryblock
  2108. allocation
  2109.  
  2110.     
  2111.     InitSysinfo( &system );    
  2112.     theicon = GetCIcon( res_id );    
  2113.     right = ( (**theicon).iconBMap ).bounds.right;
  2114.     bottom =  ( (**theicon).iconBMap ).bounds.bottom;
  2115.     SetRect( &wbounds, 0, 0, GameResHr, GameResVr );
  2116.     SetRect( &dOffBounds, 0, 0, right, bottom );
  2117.  
  2118.     GetGWorld( &currPort, &currDev );        // Build Offscreen Graphics world
  2119.     err = NewGWorld( &gMyOffG, 0, &dOffBounds, nil, nil, 0 ); // Create Offscreen
  2120. Graphics worl
  2121.     if ( err != noErr )
  2122.     {
  2123.         /* ... */
  2124.     }
  2125.  
  2126.     // Lock down Pixels that we are drawing to so that memory will not
  2127.     // move
  2128.     gblockAlloc = LockPixels (gMyOffG->portPixMap);
  2129.     
  2130.     if ( !gblockAlloc )
  2131.     {
  2132.         /* ... */
  2133.     }
  2134.     
  2135.     // Setup drawing area to be our offscreen graphics world
  2136.     
  2137.     SetGWorld (gMyOffG, nil);
  2138.     
  2139.     //The drawing area
  2140.     
  2141.     PlotCIcon( &dOffBounds, theicon );
  2142.     
  2143.     // Done drawing, now reset Port etc.
  2144.  
  2145.     SetGWorld (currPort, currDev);
  2146.  
  2147.     // Initialize the PixMap for copying
  2148.     
  2149.     offRowBytes = ( ( ( system.PixelDepth * right ) + 31 ) / 32 ) * 4;
  2150.     sizeOfmap = bottom * offRowBytes;                                    
  2151.     offBaseAddr = NewPtr( sizeOfmap );
  2152.     if ( offBaseAddr = nil )
  2153.     {
  2154.         /* ... */
  2155.     }
  2156.  
  2157.  
  2158.     printf( "%d\n", offRowBytes );
  2159.     while( !Button() ){}
  2160.     thebitmap->baseAddr = offBaseAddr;
  2161.     thebitmap->rowBytes = offRowBytes;
  2162.     thebitmap->bounds = (**theicon).iconPMap.bounds;
  2163.     BlitPixie( *gMyOffG->portPixMap, thebitmap, &(**theicon).iconPMap.bounds,
  2164. &thebitmap->bounds, &wbounds ); 
  2165.     UnlockPixels( gMyOffG->portPixMap );
  2166. }
  2167.  
  2168.  
  2169. Oh, btw, use CopyBits instead of BlitPixie.. easy to modify..
  2170.  
  2171. Dmitry
  2172. (A friend of mine wrote it.. His name is John Whited)
  2173.  
  2174. +++++++++++++++++++++++++++
  2175.  
  2176. >From gurgle@dnai.com (Pete Gontier)
  2177. Date: Mon, 05 Sep 1994 16:27:52 -0800
  2178. Organization: Integer Poet Software
  2179.  
  2180. In article <65502.4681425@cmq.cmq.qc.ca>, JFN@cmq.qc.ca wrote:
  2181.  
  2182. > How i can transform a PICT resource in a PixMapHandle?
  2183.  
  2184. This question, puzzlingly, comes up pretty often, even though it has a
  2185. fairly obvious one-word answer:
  2186.  
  2187.     DrawPicture
  2188.  
  2189. There must be something about the topic that's inherently confusing, or it
  2190. wouldn't come up so often. Of course, you have to have a pixel map lying
  2191. around, but sample code for that is easy enough to find; here is the
  2192. canonical reference:
  2193.  
  2194.     ftp://ftp.apple.com/dts/mac/tn/quickdraw.qd/qd-13-principia-off-screen.hqx
  2195.  
  2196. I have also posted some sample code for TCL 1.1.3, called 'CPixMap'.
  2197.  
  2198.     ftp://ftp.dnai.com/users/gurgle/CPixMap.sit.bin
  2199.  
  2200. Now, you could be talking about grabbing a pixel map and putting it into a
  2201. picture. That has a three-word answer:
  2202.  
  2203.     OpenPicture
  2204.     CopyBits
  2205.     ClosePicture
  2206.  
  2207. In either case, you'll be needing a pixel map. :-)
  2208.  
  2209. -- 
  2210.  
  2211.  Pete Gontier // Integer Poet Software // gurgle@dnai.com
  2212.  
  2213.  "The need to be (or appear to be) sophisticated pervades the very
  2214.  atmosphere in which we, the Magazine Reading Class, move."
  2215.                   -- Eliis Weiner, Spy Magazine, 9/94
  2216.  
  2217. ---------------------------
  2218.  
  2219. >From bb@lightside.com (Bob Bradley)
  2220. Subject: Slashed Progress Bar
  2221. Date: Sat, 27 Aug 1994 02:25:15 -0800
  2222. Organization: SS Software Inc.
  2223.  
  2224. I'm trying to implement the Slashed Progress Bar just like Anarchie's when
  2225. it's trying to connect and similar to the Finder's when it's doing
  2226. something that it doesn't know how long it will take.
  2227.  
  2228. I've looked at Anarchie and it doesn't seem to use a PICT resource like
  2229. the Finder does. I'd like to do something similar to Anarchie but, am not
  2230. sure how. Anyone have any sample source or suggestions?
  2231.  
  2232. I'm writing a simple progress bar CDEF that will do progress bars ike
  2233. normal and support that moving slashed "Not sure how long it will take
  2234. but, I'm trying" look which I why I want to stay away from PICT's.
  2235.  
  2236. +++++++++++++++++++++++++++
  2237.  
  2238. >From trygve@netcom.com (Trygve Isaacson)
  2239. Date: Mon, 29 Aug 1994 00:51:29 GMT
  2240. Organization: Wall Data Incorporated
  2241.  
  2242. In article <bb-2708940225150001@user57.lightside.com>, bb@lightside.com
  2243. (Bob Bradley) wrote:
  2244.  
  2245. [ deletia ]
  2246. > I've looked at Anarchie and it doesn't seem to use a PICT resource like
  2247. > the Finder does. I'd like to do something similar to Anarchie but, am not
  2248. > sure how. Anyone have any sample source or suggestions?
  2249. > I'm writing a simple progress bar CDEF that will do progress bars ike
  2250. > normal and support that moving slashed "Not sure how long it will take
  2251. > but, I'm trying" look which I why I want to stay away from PICT's.
  2252.  
  2253. I prefer the term "meat grinder" for the unknown-duration effect :)
  2254.  
  2255. First, I'd suggest looking in the various source code archives on the net.
  2256. There's got to be a CDEF out there that already does this. If not...
  2257.  
  2258. You say you want to stay away from PICTs, but I don't see why. When you
  2259. know how long it's going to take, draw the two gauge parts yourself
  2260. (FillRect or PaintRect each rectangle). When you don't know how long it's
  2261. going to take, just cycle through the four meat grinder PICTs (roll your
  2262. own or just use the Finder's).
  2263.  
  2264. As for the gauge bar color values, here's what I'm using (I think I got
  2265. these by taking screen shots of the Finder's progress dialog and testing
  2266. the color values in Photoshop or something). I imagine there's some RGB
  2267. value that would work in all depths without require a depth test, but
  2268. these look right.
  2269.  
  2270. "Completed" gauge colors:
  2271. 8-bit, dark gray: r=g=b=17476
  2272. 2-bit, dark gray: r=g=b=21845
  2273. 1-bit, black    : r=g=b=0
  2274.  
  2275. "Uncompleted" gauge colors:
  2276. 8-bit, light purple: r=g=54248, b=65535
  2277. 2-bit, light gray  : r=g=b=43690
  2278. 1-bit, white       : r=g=b=65535
  2279.  
  2280. I rolled everything into a TGauge MacApp control class, but since you're
  2281. doing a CDEF, you might want to define special meaning to the control's
  2282. min/max/value to achieve the meat grinder effect. E.g.: if max<min, then
  2283. SetCtlValue cranks the meat grinder. Something like that.
  2284.  
  2285. ..........................................................................
  2286. Trygve Isaacson           trygve@netcom.com         Wall Data Incorporated
  2287. ..........................................................................
  2288.   "Books are burning in the main square
  2289.                         And I saw there the fire eating the text
  2290.      Books are burning in the still air
  2291.                      And you know where they burn books people are next"
  2292.                                                   -- Andy Partridge, XTC
  2293.  
  2294. +++++++++++++++++++++++++++
  2295.  
  2296. >From heathcot@bnr.ca (Graham Heathcote)
  2297. Date: Mon, 29 Aug 1994 00:29:35 GMT
  2298. Organization: BNR Australia
  2299.  
  2300. In article <bb-2708940225150001@user57.lightside.com>, bb@lightside.com
  2301. (Bob Bradley) wrote:
  2302.  
  2303. > I'm trying to implement the Slashed Progress Bar just like Anarchie's when
  2304. > it's trying to connect and similar to the Finder's when it's doing
  2305. > something that it doesn't know how long it will take.
  2306. > I've looked at Anarchie and it doesn't seem to use a PICT resource like
  2307. > the Finder does. I'd like to do something similar to Anarchie but, am not
  2308. > sure how. Anyone have any sample source or suggestions?
  2309. > I'm writing a simple progress bar CDEF that will do progress bars ike
  2310. > normal and support that moving slashed "Not sure how long it will take
  2311. > but, I'm trying" look which I why I want to stay away from PICT's.
  2312.  
  2313. I have just implemented a C++ class to perform the standard progress bar
  2314. and the slashed bar as you call it. I have a few things to finish off and
  2315. then will be placing the sources into c.s.m.
  2316.  
  2317. I thought about implementing the picture method of Finder, but this didn't
  2318. work for my implementation as I wanted the progress bar to be any size as
  2319. defined in the DITL, and the picture needs to be the same size as the user
  2320. item or it will be scalled, YUK. So I went with a pixel pattern (or infact
  2321. 16) and just filled the user item with each successive pattern. This gives
  2322. exactly the same effect as the finder, except since I am using 16 images
  2323. it is much smother than Finder.
  2324.  
  2325. e-mail me if you need any more details, or a preliminary copy of the
  2326. source and example app I have put together.
  2327.  
  2328. Regards,
  2329. Graham Heathcote.
  2330.  
  2331. -- 
  2332. Graham Heathcote
  2333. BNR Australia
  2334. email:   heathcot@bnr.ca
  2335.  
  2336. +++++++++++++++++++++++++++
  2337.  
  2338. >From Matt Slot <fprefect@engin.umich.edu>
  2339. Date: 29 Aug 1994 01:50:48 GMT
  2340. Organization: University of Michigan
  2341.  
  2342. Bob Bradley, bb@lightside.com writes:
  2343.  
  2344. >I'm trying to implement the Slashed Progress Bar just like Anarchie's when
  2345. >it's trying to connect and similar to the Finder's when it's doing
  2346. >something that it doesn't know how long it will take.
  2347. ...
  2348. >I'm writing a simple progress bar CDEF that will do progress bars ike
  2349. >normal and support that moving slashed "Not sure how long it will take
  2350. >but, I'm trying" look which I why I want to stay away from PICT's.
  2351.  
  2352. I downloaded a progress bar CDEF from the archives, one done by
  2353. Eddy J. Gurney from HP, and added the "barber-shop pole" idling effect.
  2354. I sent him a copy and his response was favorable. I will post this to
  2355. alt.sources.mac, with a tester for you to try out.
  2356.  
  2357. The basic idea is that the progress goes from 0 to n (begin -> end), and
  2358. to make it idle you cycle from -4 to -1 (well anything negative MOD 4).
  2359.  
  2360. I can't say its the fastest or best implementation, but it is satisfactory
  2361. for what I have used it in so far.
  2362.  
  2363. Matt
  2364.  
  2365. +++++++++++++++++++++++++++
  2366.  
  2367. >From giles@med.cornell.edu (Aaron Giles)
  2368. Date: 29 Aug 1994 02:14:59 GMT
  2369. Organization: Cornell University Medical College
  2370.  
  2371. In article <bb-2708940225150001@user57.lightside.com>, bb@lightside.com
  2372. (Bob Bradley) wrote:
  2373.  
  2374. > I've looked at Anarchie and it doesn't seem to use a PICT resource like
  2375. > the Finder does. I'd like to do something similar to Anarchie but, am not
  2376. > sure how. Anyone have any sample source or suggestions?
  2377.  
  2378. Well, here is some example code which I used in JPEGView.  Basically, it
  2379. involves setting the PenWidth to a wide pen and drawing some diagonal
  2380. lines.  It is implemented as a dialog user item; each time this user item
  2381. gets called, it increments the position of the bar.  I just do an
  2382. InvalRect() on the user item to get it move one notch.
  2383.  
  2384. // defined elsewhere in the application
  2385. static const RGBColor kBlack = { 0x0000, 0x0000, 0x0000 };
  2386.  
  2387. // draw an indefinite progress bar using the standard Finder colors
  2388. static pascal void UpdateBarIndef(DialogPtr theDialog, short theItem) 
  2389. {
  2390.    static RGBColor gBarBackground = { 0xcccc, 0xcccc, 0xffff };
  2391.    static RGBColor gBarForeground = { 0x4000, 0x4000, 0x4000 };
  2392.    static short gBarOffset = 0;
  2393.    Boolean useBW = !(((CGrafPtr)theDialog)->portVersion & 0xc000) || 
  2394.       (*((CGrafPtr)theDialog)->portPixMap)->pixelSize == 1;
  2395.    short itemType, left;
  2396.    Handle itemHandle;
  2397.    RgnHandle oldClip;
  2398.    GrafPtr oldPort;
  2399.    Rect itemRect;
  2400.    
  2401.    GetPort(oldPort);
  2402.    SetPort(theDialog);
  2403.    GetDItem(theDialog, theItem, &itemType, &itemHandle, &itemRect);
  2404.    if (oldClip = NewRgn()) {
  2405.       GetClip(oldClip);
  2406.       PenSize(1, 1);
  2407.       RGBForeColor(&kBlack);
  2408.       FrameRect(&itemRect);
  2409.       InsetRect(&itemRect, 1, 1);
  2410.       ClipRect(&itemRect);
  2411.       left = itemRect.left - (3 * Height(&itemRect)) + 
  2412.              (gBarOffset * Height(&itemRect) / 2);
  2413.       PenSize(Height(&itemRect), 1);
  2414.       while (left < itemRect.right) {
  2415.          RGBForeColor(&gBarForeground);
  2416.          MoveTo(left, itemRect.top);
  2417.          LineTo(left += Height(&itemRect), itemRect.bottom);
  2418.          if (useBW) RGBForeColor(&kWhite);
  2419.          else RGBForeColor(&gBarBackground);
  2420.          MoveTo(left, itemRect.top);
  2421.          LineTo(left += Height(&itemRect), itemRect.bottom);
  2422.       }
  2423.       PenSize(1, 1);
  2424.       SetClip(oldClip);
  2425.       DisposeRgn(oldClip);
  2426.       gBarOffset = (gBarOffset + 1) & 3;
  2427.    }
  2428.    RGBForeColor(&kBlack);
  2429.    SetPort(oldPort);
  2430. }
  2431. -- 
  2432. Aaron Giles (giles@med.cornell.edu)
  2433. Power Macintosh Developer, Cornell University Medical College
  2434. JPEGView home page: http://www.med.cornell.edu/jpegview.html
  2435. JPEGView FTP site:   ftp://ftp.med.cornell.edu/pub/aarong/jpegview/
  2436.  
  2437. +++++++++++++++++++++++++++
  2438.  
  2439. >From alexr@apple.com (Alex Rosenberg)
  2440. Date: Mon, 29 Aug 1994 07:59:37 GMT
  2441. Organization: Hackers Anonymous
  2442.  
  2443. In article <heathcot-2908941028320001@47.181.192.70>, heathcot@bnr.ca
  2444. (Graham Heathcote) wrote:
  2445.  
  2446. > In article <bb-2708940225150001@user57.lightside.com>, bb@lightside.com
  2447. > (Bob Bradley) wrote:
  2448. > > I'm trying to implement the Slashed Progress Bar just like Anarchie's when
  2449. > > it's trying to connect and similar to the Finder's when it's doing
  2450. > > something that it doesn't know how long it will take.
  2451. > > 
  2452. > > I've looked at Anarchie and it doesn't seem to use a PICT resource like
  2453. > > the Finder does. I'd like to do something similar to Anarchie but, am not
  2454. > > sure how. Anyone have any sample source or suggestions?
  2455. > > 
  2456. > > I'm writing a simple progress bar CDEF that will do progress bars ike
  2457. > > normal and support that moving slashed "Not sure how long it will take
  2458. > > but, I'm trying" look which I why I want to stay away from PICT's.
  2459. > I have just implemented a C++ class to perform the standard progress bar
  2460. > and the slashed bar as you call it. I have a few things to finish off and
  2461. > then will be placing the sources into c.s.m.
  2462. > I thought about implementing the picture method of Finder, but this didn't
  2463. > work for my implementation as I wanted the progress bar to be any size as
  2464. > defined in the DITL, and the picture needs to be the same size as the user
  2465. > item or it will be scalled, YUK. So I went with a pixel pattern (or infact
  2466. > 16) and just filled the user item with each successive pattern. This gives
  2467. > exactly the same effect as the finder, except since I am using 16 images
  2468. > it is much smother than Finder.
  2469.  
  2470. Instead of using multiple patterns, you can get the same effect by moving
  2471. the origin with a SetOrigin call. (As I do in XMODEM Tool 1.1.)
  2472.  
  2473. - -------------------------------------------------------------------------
  2474. -  Alexander M. Rosenberg  - INTERNET: alexr@apple.com      - Yoyodyne    -
  2475. -  330 Waverley St., Apt B - UUCP:ucbvax!apple!alexr        - Propulsion  -
  2476. -  Palo Alto, CA 94301     -                                - Systems     -
  2477. -  (415) 329-8463          - Nobody is my employer so       - :-)         -
  2478. -  (408) 974-3110          - nobody cares what I say.       -             -
  2479.  
  2480. +++++++++++++++++++++++++++
  2481.  
  2482. >From msguzzo@srqa01.jsc.nasa.gov (Michael Guzzo)
  2483. Date: Mon, 29 Aug 1994 15:20:45
  2484. Organization: Calspan/Space Shuttle Safety & Mission Assurance
  2485.  
  2486. In article <bb-2708940225150001@user57.lightside.com> bb@lightside.com (Bob Bradley) writes:
  2487. >From: bb@lightside.com (Bob Bradley)
  2488. >Subject: Slashed Progress Bar
  2489. >Date: Sat, 27 Aug 1994 02:25:15 -0800
  2490.  
  2491. >I'm trying to implement the Slashed Progress Bar just like Anarchie's when
  2492. >it's trying to connect and similar to the Finder's when it's doing
  2493. >something that it doesn't know how long it will take.
  2494.  
  2495. >I've looked at Anarchie and it doesn't seem to use a PICT resource like
  2496. >the Finder does. I'd like to do something similar to Anarchie but, am not
  2497. >sure how. Anyone have any sample source or suggestions?
  2498.  
  2499. >I'm writing a simple progress bar CDEF that will do progress bars ike
  2500. >normal and support that moving slashed "Not sure how long it will take
  2501. >but, I'm trying" look which I why I want to stay away from PICT's.
  2502.  
  2503. How about using two ppats? Set the pen height and width to the height of 
  2504. your progress bar using the ppat, draw a filled rect, and then switch to the 
  2505. other ppat.. continue until you're done. Draw the ppat to look like the 
  2506. barberpole is moving.
  2507.  
  2508. Just off the top of my head, I don't have any sample code...
  2509.  
  2510. ________________________________________________________________________
  2511. Michael S. Guzzo
  2512. msguzzo@srqa01.jsc.nasa.gov
  2513. You're gonna have to face it, you're addicted to Doom!
  2514.  
  2515. +++++++++++++++++++++++++++
  2516.  
  2517. >From Chris Ferris <chris@tycho.demon.co.uk>
  2518. Date: Sun, 4 Sep 1994 15:16:44 GMT
  2519. Organization: Tycho Consultants
  2520.  
  2521.  
  2522. In article <msguzzo.72.000F590A@srqa01.jsc.nasa.gov>, Michael Guzzo 
  2523. writes:
  2524.  
  2525. >
  2526. > In article <bb-2708940225150001@user57.lightside.com> 
  2527. bb@lightside.com (Bob Bradley) writes:
  2528. > >From: bb@lightside.com (Bob Bradley)
  2529. > >Subject: Slashed Progress Bar
  2530. > >Date: Sat, 27 Aug 1994 02:25:15 -0800
  2531. > >I'm trying to implement the Slashed Progress Bar...
  2532.  
  2533. [ Stuff cut ]
  2534.  
  2535. > How about using two ppats? Set the pen height and width to the 
  2536. height of 
  2537. > your progress bar using the ppat, draw a filled rect, and then 
  2538. switch to the 
  2539. > other ppat.. continue until you're done. Draw the ppat to look like 
  2540. the 
  2541. > barberpole is moving.
  2542.  
  2543.  
  2544. There is a simpler solution using only one ppat. Define a single ppat 
  2545. for the 'barbers pole' which is black and white separated diagonaly 
  2546.  
  2547. 11111111 = 0xFF
  2548. 01111111 = 0x7F
  2549. 00111111 = 0x3F
  2550. 00011111 = 0x1F
  2551. 00001111 = 0x0F
  2552. 00000111 = 0x07
  2553. 00000011 = 0x03
  2554. 00000001 = 0x01
  2555.  
  2556. Inside your progress bar function use SetOrigin to move the 
  2557. co-ordinate system used by QD patterns by one pixel horizontally for 
  2558. each update to the bar, resetting to 0 when you reach 8.
  2559.  
  2560. The pattern will appear to move along the progress bar, just remember 
  2561. to compensate for the change in co-ordinates before calling FillRect.
  2562.  
  2563.  
  2564.    ___       |                 chris@tycho.demon.co.uk
  2565.   /  ___     |             Chris Ferris, Tycho Consultants
  2566.  /__/_       |
  2567.    /         |  'The best way to predict the future is to invent it!'
  2568.   /          |                          Apple Computer Inc
  2569.  
  2570.  
  2571. ---------------------------
  2572.  
  2573. End of C.S.M.P. Digest
  2574. **********************
  2575.  
  2576.  
  2577.