Checksum: 24172 Path: utzoo!utgpu!mms From: mms@gpu.utcs.toronto.edu (John J. Chew III) Date: Fri, 22-Jan-88 01:43:56 EST Message-ID: <1988Jan22.014356.11779@gpu.utcs.toronto.edu> Organization: The Poslfit Committee Newsgroups: comp.sys.mac Subject: Re: Sorting resources and a question about the list manager References: <6577@jade.BERKELEY.EDU> <767@thorin.cs.unc.edu> Reply-To: mms@gpu.utcs.UUCP (John J. Chew III) In article <767@thorin.cs.unc.edu> steele@unc.UUCP (Oliver Steele) writes: > jmm@thoth8.berkeley.edu () writes: > >How do you sort resources? I'm using the names of the individual resources > >to fill a list, and I'd like to be able to sort the resources rather than > >sort the list every time it gets created. (The resource type is my own, and > >I'd like to reorganize the order that the individual resources appear in > >any way that I see fit, so I don't want to just sort by resource name.) > The cheap trick here is to use AddResMenu() to add them all to the > end of (empty) menu that you never draw (make one with NewMenu() and then > dispose it after you're done with it), and read the names of the > menu items from its data. Write me if you need source. A nicer way to sort things as you put them into a list is to use the LSearch() function: /* for each cell you want to add */ theCell.h=theCell.v=0; LSearch(dataPtr, dataLen, compareProc, &theCell, 1); LAddRow(1, theCell.v, 1); LSetCell(dataPtr, dataLen, theCell.1); ... where compareProc for a simple alpha sort would be: pascal int compareProc(ap, bp, al, bl) Byte *ap, *bp; int al, bl; { return IUMagString(ap, bp, al, bl)<=0; } However, to answer the original question of how to sort resources, the best way is to sort them before you create them and to create them in sorted order. The second best way is to decide what order they should be in, create a new resource fork and create copies of them in sorted order there. If you are determined to sort existing copies of resources, read the caveat in IM IV-16 and then: - obtain handles to all the resources to be sorted - call RsrcMapEntry on each to get the resource reference offset - sort the resource references (12 bytes located at the above-obtained offsets from TopMapHndl, assuming your resources are in the most-recently opened resource fork, which they had better be) - call ChangedResource() on one of your resource handles. jjc -- john j. chew (v3.0) poslfit@gpu.utcs.toronto.edu +1 416 463 5403 (300/1200 bps) poslfit@utorgpu.bitnet {cbosgd,decvax,mnetor,utai,utcsri,{allegra,linus}!utzoo}!utgpu!poslfit "Script-G for open, sub-delta for durchschnitt"