[comp.sys.mac.programmer] Writing INITs, Part 2: Making Life Easier.

jmunkki@santra.UUCP (Juri Munkki) (04/22/88)

/*
		Fixer.c
		April 22, 1988
		Written by Juri Munkki

		This source code is in the public domain.
		The author makes no guarantees.

Instructions

	Fixer is a very small application that I wrote to faciliate writing
	INIT and other code resources in Lightspeed C.

What Does It Do?

	Lightspeed C always makes code resources purgeable and places them in
	the application heap. The code files are created by '????' and their
	type is '????'. To make an init resource work, I had to launch ResEdit,
	get info for the file and edit the file type to 'INIT', open the file
	and set the "System Heap" flag of the init resource. The last step is
	not always necessary, but if you're going to patch the system, it's the
	simplest way to do it. I wouldn't recommending placing system patches
	into the application heap.
	
	Fixer looks at a data structure in its resource fork. The file to
	modify should be in the same folder as the fixer application, or
	the name should be a path to the file. It then looks at the type
	and creator fields in the structure and changes the file type and
	creator accordingly.
	
	The FIXE 1000 resource also contains list of resources to be changed.
	Fixer looks for any resources mentioned in the list (the resource type
	and number are significant) and changes the resource attributes and
	name.
	
How To Use?

	First copy the TMPL resource from the Fixer application to your copy
	of ResEdit. Then open the Fixer application with ResEdit and edit
	the FIXE 1000 resource. Close and save changes.
	
	Compile your INIT into the same folder as the Fixer application and
	transfer to Fixer. You should soon find yourself in the Finder. Your
	resource file should now be correctly set up and you can just place
	the init file into your system folder and boot.
	
Disclaimer

	This piece of code was a quick hack written in order to get some work
	done with minimum bother. I wrote the program while chatting with
	several people on the Macintosh Relay Chat in BITNET. The chat is
	every Tuesday at 22 GMT. It worked on the first time I tried it, but
	I can't make any guarantees on it working with your mac. I take no
	responsibility on any damage caused directly or indirectly by either
	the Fixer application or the Sample Init.
	
	If you can't understand the source for this program, you probably
	shouldn't be using it. (I admit that it isn't "GoodCode", but it is
	so short that you should be able to understand it, if you're going to
	write INIT resources or stuff like that.)
	
Please:

	If you like the program, let me know.

	Juri Munkki
	Helsinki University of Technology Computing Centre

	jmunkki@santra.hut.fi
	jmunkki@fingate.bitnet
	
	Otakaari 1, Room Y250A
	SF02150 Espoo, Finland
	
*/

#include <MacTypes.h>
#include <ResourceMgr.h>
#include <FileMgr.h>
#include <ToolboxUtil.h>

void	main()
{
			Handle		FixHandle;

			FInfo		Fi;

			int		resFileID;
	register	int		i;
	register	Ptr		w;

	register	Handle		it;
	register	int		num;
	register	long		type;
			int		resattr;

	FixHandle=GetResource('FIXE',1000);
	HLock(FixHandle);
	w=(Ptr)StripAddress(*FixHandle);

	GetFInfo(w+8,0,&Fi);
	BlockMove(w,&Fi,8);
	SetFInfo(w+8,0,&Fi);
	w+=8;
	resFileID=OpenResFile(w);
	w+=*w+1;
	w+=((long) w) & 1;

		SetResLoad(0);
		i=*(int *)w;
		w+=2;
		while(i--)
		{	/*	Action			Advance pointer */
			type=*(long *)w;		w+=4;
			num=*(int *)w;			w+=2;
			resattr=*(unsigned char *)w;	w+=1;
			it=GetResource(type,num);
			SetResAttrs(it,resattr);
			SetResInfo(it,num,w);		w+=*w+1;
							w+= ((long) w)&1;
			ChangedResource(it);
		}
		SetResLoad(-1);

	CloseResFile(resFileID);
}
/*	The resources for the Fixer application follow:

(This file must be converted with BinHex 4.0)

:#NCTH'9b,R*cFQ-!FR0bBe*6483!N!J#4YFQ!*!%!3#3!`(l!*!$q`#3!dX(8%j
84`!*!*!%4&C63bX!N!-"5801)`!&!!&YX!!##NCTH'9b,R*cFQ0b!J#3!h*cFQ0
58d9%!3!!0J&!!*!%FR0bBe*6483"!!!f!8!!!#`3!*!1RT'3!&)!N!B#4J*`$i!
#)!#!!J$!J!)"J)!#!3#!!JlJJ!)Im)!#(m#!!Kr!J!)Im)!#(r#!!JrJJ!)'`)!
#!!#!!J!!J(rrrrb!!!!#J!!$qS!!!rU!!!!#J!!!!S!!!!+IrrrbP9998TUUUV+
99995QUUUXRrrrr`$rrJ!!rrm!!2rrJ!$rrm!!rm!N!2*"&4jF'986N&0"d0bC@&
dEh*86N&0#djKE@8J+&"KG'JT49088J9$Eh9ZG%p$6P3&+T!&6&083`48HA"P9%j
"63C1G@eLCA*%9e*%#&*PFf9bGQ9N3N**9!G6HA0)C@&`3N**9!P3GA*RC@&LE'9
#3NP8"Na[BfYPC%*#593(8(*[G'9MG%*#593(8(*PE'pKC%*#593,9A"NBA4PC#!
S-#P#3NP8#N&dG()JFR0bGQ4#3NP8"%jKE@928e45"5f3"8a69%8!N!-U58j*9%j
26N8,8f&YF'aP)%PZDA3!!8P1593!Bd!,8f&YF'aP)%PZDA3!N!-"!*!$!IX!N!2
l!*!$5`!&eNJ%DJ#3!a`!4J!"9%e36!#3!a*'59K&!*!$(J2S!*!+!qMrr`#3!md
!"NN%"%C*@%9j%3:

			End of File! */