PackIt pitmain.c

/*
		pit main program

	This file contains the main program code for the pit program.

	© Copyright 1986 by Harry R. Chesley.
	All rights reserved.
*/

#include <quickdraw.h>
#include <window.h>
#include <event.h>
#include <menu.h>
#include <desk.h>
#include <toolutil.h>
#include <packages.h>
#include <resource.h>
#include <inits.h>
#include <syserr.h>

#define appOpen 0

#define RESFILE "\Pcaid:pit/pit.rsrc"

/* Globals: */

int quit;

/*	main()

	Function: Initialize everything. Then repeat the main event loop until quit becomes TRUE.

	Algorithm: Get events, decide between our events and those of other parts of the system,
	then handle ours and pass on the others.

	Comments: None.
*/

main()

{
	int openOrPrint;			/* Whether the Finder wants us to open or print. */
	int numberOfFiles;			/* Number of files to be printed. */

	/* Init the world. */
	MaxApplZone();
	MoreMasters(); MoreMasters(); MoreMasters(); MoreMasters();
	InitGraf(&thePort);
	InitFonts();
	InitWindows();
	FlushEvents(everyEvent,0);

	/* Open the application resource file -- left in in case we ever go back to a separate file. */
	/* if (OpenResFile(RESFILE) == -1) exit(); */

	TEInit();
	InitDialogs(0L);
	InitCursor();
	initAppl();

	/* Check what the Finder thought we should be doing. */
	CountAppFiles(&openOrPrint,&numberOfFiles);

	/* If there's stuff to do already, go to it. */
	if ((openOrPrint == appOpen) && (numberOfFiles > 0)) unpackApp(numberOfFiles);
	/* Otherwise, bring up the normal command loop. */
	else commandLoop();
}

/*	commandLoop()

	Function: Init the menus, then get and handle events from the user.

	Algorithm: Call menuSetUp(). Then repreatedly call GetNextEvent() and take the appropriate
	action.

	Comments: None.
*/

commandLoop()

{
	EventRecord myEvent;		/* Incoming events. */
	WindowPtr whichWindow;		/* Which window the mouse clicked in. */
	register int FWReturnCode;	/* FindWIndow() return code. */
	register int key;			/* keyDown event key code. */
	register long keyCommand;	/* MenuKey command identifier. */
	Point DIPt;					/* Where to put the disk init dialog. */

	/* Set up the menus. */
	menuSetUp();

	/* Let 'em know who we are. */
	displayAbout();

	quit = FALSE;

	/* Main event loop. */
	while (!quit) {

		/* Let the system do it's stuff. */
		SystemTask();

		/* Get an event; if none, continue. */
		if (!GetNextEvent(everyEvent,&myEvent)) continue;

		/* Switch on the event. */
		switch (myEvent.what) {

			case mouseDown:
				/* FInd out which window/window part it was in. */
				FWReturnCode = FindWindow(pass(myEvent.where),&whichWindow);
				/* Switch on the return code. */
				switch (FWReturnCode) {
					case inMenuBar:
						/* Do menu command. */
						doCommand(MenuSelect(pass(myEvent.where)));
						break;
					case inSysWindow:
						/* Let the system handle it. */
						SystemClick(&myEvent,whichWindow);
						break;
					/* No windows up, but cases left in for instructional value... */
					case inDrag:
					case inGrow:
					case inContent:
					case inGoAway:
						break;
				};
				break;

			case mouseUp:
				break;

			case keyDown:
				/* Check for keyboard command. */
				key = myEvent.message & 0xFF;
				if ((myEvent.modifiers & 0x100) && HiWord(keyCommand = MenuKey(key)))
					doCommand(keyCommand);
				break;

			case autoKey:
				break;

			case activateEvt:
				break;

			case updateEvt:
				break;

			case diskEvt:
				if (HiWord(myEvent.message) != noErr) {
					DIPt.h = 100; DIPt.v = 100;
					DIBadMount(&DIPt,myEvent.message);
				};
				break;
		};
	};
}