home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Carousel Volume 2 #1
/
carousel.iso
/
mactosh
/
util
/
startups.sit
/
Stupcr1.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-05-06
|
5KB
|
247 lines
/* This is the help session compiler */
/* (C) 1986 by Bill Woody, all rights reserved */
#include <control.h>
#include <desk.h>
#include <dialog.h>
#include <event.h>
#include <font.h>
#include <fnctl.h>
#include <menu.h>
#include <mem.h>
#include <qd.h>
#include <qdvars.h>
#include <stdio.h>
#include <win.h>
#include <pack.h>
#include <file.h>
#include "stupcr.h"
/******************************************************************************/
/* Globals */
menuhandle applmenuh,filemenuh,editmenuh;
int quitflag;
char *memch;
extern int errno;
/******************************************************************************/
/* Code */
initworld()
{
extern int exittoshell();
long restype = 'DRVR';
initgraf(&theport); /* Initialize the quickdraw stuff */
initfonts(); /* Initialize my ability to draw text */
initwindows(); /* Now, initialize windows */
initmenus(); /* and menus */
teinit(); /* and the text editor (for dialogs!) */
initdialogs(exittoshell); /* When a bomb occures, drop me into finder! */
flushevents(everyevent,0); /* Flush all pending events */
initcursor(); /* Give me a mouse cursor */
busyflag();
applmenuh = getmenu(APPLMENU);
addresmenu(applmenuh,&restype);
insertmenu(applmenuh,0);
filemenuh = getmenu(FILEMENU);
insertmenu(filemenuh,0);
editmenuh = getmenu(EDITMENU);
insertmenu(editmenuh,0);
drawmenubar();
readyflag();
if ((memch = newptr(65536L)) == NULL) {
errmsg(OUTOFMEM,_memerr); /* Error message */
quitflag = 1;
} else quitflag = 0;
}
busyflag() /* Call this when going into a heavy processing loop */
{ /* And you want the user to wait instead of enter input */
getcursor(4);
}
readyflag() /* Call this when ready to accept user input */
{
initcursor();
}
int getfile(l) /* Do the equivalent of an OPEN command on file */
long l; /* with flags set for READ */
{
point where;
sfreply reply;
paramblockrec pb;
where.a.v = 150;
where.a.h = 75;
sfgetfile(&where,"Compile what file?",NULL,1,&l,NULL,&reply);
if (reply.good == 0) return(-1);
pb.ionameptr = &reply.fname;
pb.iovrefnum = reply.vrefnum;
pb.paramunion.ioparam.ioversnum = reply.version;
pb.paramunion.ioparam.iopermssn = O_RDONLY & 4095;
pb.paramunion.ioparam.iomisc = NULL;
if (errno = pbopen(&pb,0)) return -1;
else {
_binadd(pb.paramunion.ioparam.iorefnum, O_BINARY);
return pb.paramunion.ioparam.iorefnum;
}
}
int putfile(l,o,def) /* Do the equivalent of an OPEN command on file */
long l,o; /* with flags set for WRITE */
char *def;
{
point where;
sfreply reply;
paramblockrec pb;
int refnum;
where.a.v = 175;
where.a.h = 80;
sfputfile(&where,"Save startup file as:",def,NULL,&reply);
if (reply.good == 0) return -2;
create(&reply.fname,reply.vrefnum,&o,&l);
pb.ionameptr = &reply.fname;
pb.iovrefnum = reply.vrefnum;
pb.paramunion.ioparam.ioversnum = 0;
pb.paramunion.ioparam.iopermssn = 2;
pb.paramunion.ioparam.iomisc = NULL;
pbopen(&pb,0);
refnum = pb.paramunion.ioparam.iorefnum;
if (errno = pb.ioresult) {
return -1;
}
else {
seteof(refnum,0L);
_binadd(refnum,O_BINARY);
return refnum;
}
}
doeventloop() /* Call this to execute the event loop once */
{
eventrecord theevent;
systemtask(); /* Give time to the desk accessories */
if (getnextevent(everyevent,&theevent)) {
switch (theevent.what) {
case mousedown: /* Well, he pressed the (mouse) button */
domouseevent(&theevent);
break;
case keydown:
case autokey:
dokeyevent(&theevent);
break;
}
}
}
domouseevent(foo)
eventrecord *foo;
{
int type;
long dimens;
int part;
point pt;
windowptr whichwin;
controlhandle ctrl;
if (0 == (type = findwindow(&(foo->where),&whichwin))) return;
if ((whichwin != NULL) && (whichwin != frontwindow()))
selectwindow(whichwin);
else switch (type) {
case inmenubar:
domenu(menuselect(&(foo->where)));
break;
case insyswindow:
systemclick(foo,whichwin);
break;
}
}
domenu(foo)
long foo;
{
int highword,loword,accnum;
char buffer[255];
highword = foo >> 16;
loword = foo & 0x0FFFF;
switch (highword) {
case APPLMENU:
if (loword == ABOUTSUBM) {
doaboutme();
break;
} else {
getitem(applmenuh,loword,buffer); /* Get the deskacc */
accnum = opendeskacc(buffer); /* and open it */
}
break;
case FILEMENU:
switch (loword) {
case QUITSUBM:
endprogram(); /* QUIT option */
break;
case FTOSSUBM:
docompile(); /* file -> startup */
break;
case STOFSUBM:
dodecomp(); /* startup -> file */
break;
}
break;
case EDITMENU:
if (!systemedit(loword - 1)) /* Is it a desk cmd? */
sysbeep(10); /* Unimplemented edit */
break;
}
hilitemenu(0); /* Unhighlite the entire menu bar */
}
dokeyevent(foo)
eventrecord *foo;
{
char c;
c = foo->message & 0x0FF; /* Get key code */
if ((foo->modifiers & 0x0100) && (foo->what == keydown)) domenu(menukey(c));
}
doaboutme()
{
if (2 == alert(ABOUTMEID,NULL))
alert(MISCALRT,NULL); /* Post the about alert */
}
endprogram()
{
quitflag = 1;
}
errmsg(i,j)
int i,j;
{
char buffer[256],buf2[256];
getindstring(buffer,ERRMSG,i);
numtostring((long)j,buf2); /* Error code */
paramtext(buffer,buf2,NULL,NULL);
stopalert(ERRORALRT,NULL);
}
main()
{
initworld();
while (quitflag == 0) doeventloop();
}