#pragma once #define MAC #define ADD0 #include "maclip.h" #include "extval.h" #define WNEnumber 0xA860 #define SDInumber 0xAA68 #define Unimplemented 0xA89F void main() /* The main program is responsible for initiation and the main system loop */ { short code,k;/*code is window part hit by mouse click, k a counter*/ // long count; MaxApplZone(); /*Allot maximum amount of space*/ initMac(); /*Standard MAC manager initialization*/ #include "lextab" /*Relates lexeme names to lexeme numbers*/ initlip(); /*Initialization required for MacLIP itself*/ for (;;) { /*Main loop with Multifinder checking*/ checkCursor(); /*For IBar cursor when in EditText item*/ if (WNE) DoIt = WaitNextEvent(everyEvent,&myEvent,sleeep,0L); else { SystemTask(); DoIt = GetNextEvent(everyEvent, &myEvent); } if (IsDialogEvent(&myEvent)) { /*If main dialog event*/ SetPort(myDialog); /*On activation of the dialog, we must resize the rectangle for scrolling if needed, select the Edit text, and update the Menu bar*/ /* if (myEvent.modifiers&1) { */ if (myEvent.what == activateEvt) { /* outlin(PARSEBUT,myDialog); */ ResizePRect(myDialog); SelectDialogItemText(myDialog,TXT,0,32767); DrawMenuBar(); } /* Outline the default button during update events. JPJ */ /* Note: A real window would need BeginUpdate(), DrawMyStuff(), EndUpdate() */ /* We are letting the Dialog Manager do all of that. */ if (myEvent.what == updateEvt) { outlin(PARSEBUT,myDialog); } itemHit = 0; /*We don't want an event carryover*/ /*On a key-down check for Return and Enter, and treat as a PARSEBUT if hit Then process a hit in the dialog, if any*/ if(myEvent.what == keyDown) { if (myEvent.modifiers & cmdKey) { docommand(MenuKey((char)myEvent.message)); continue; } else { k = myEvent.message&0xFF; if(k==CR || k==ENTER) itemHit = PARSEBUT; } } if(!itemHit) DialogSelect (&myEvent, &whichDialog, &itemHit); if(itemHit) { switch(itemHit){ case MY: /*Console text entry*/ radioset(0); /*Select the radio button*/ HiliteControl((ControlHandle)itemHdl[SENTBYSENT], 255); /*Disable Text buttons*/ HiliteControl((ControlHandle)itemHdl[TEXTFAST], 255); break; case TEXTSW: /*Entry will be by textfile*/ radioset(0); /*Select the radio button*/ HiliteControl((ControlHandle)itemHdl[SENTBYSENT], 0); /*Enable the texfile choices*/ HiliteControl((ControlHandle)itemHdl[TEXTFAST],0); break; case TEXTFAST: case SENTBYSENT: radioset(2); /*Select the chosen textfile*/ break; case FULL: /*Select the chosen parse type*/ case SHORT: case GROUP: case GPandLX: case LEXEMES: case MACHINE: radioset(1); break; case ECHOON: /*Process a parse save check box hit*/ checkout(ECHOON,"\pTEXTOUT",poutfile); break; case SAVECHK: /*Process a text save check box hit*/ checkout(SAVECHK,"\pNEWTEXT",savefile); break; case PARSEBUT: /*Parse the specimen*/ badparse = 0; doparse(); break; case SAVEBUT: /*Save a (modified) sentence*/ dosave(); break; case HELPBUT: /*Show the help window*/ ShowWindow(helpWindow); SelectWindow(helpWindow); break; case QUITBUT: doClose(); /*We are finished with everything*/ break; default: break; } itemHit = 0; /*Cancel the item hit*/ } } else switch(myEvent.what) { /*Not a dialog event. Process it*/ case kHighLevelEvent: if (AEProcessAppleEvent(&myEvent)!=noErr) alert(0,1); break; case mouseDown: code = FindWindow(myEvent.where, &whichWindow); switch (code) { case inMenuBar: /*A menu item was selected*/ docommand(MenuSelect(myEvent.where)); break; case inSysWindow: /* A desk accessory operation*/ SystemClick(&myEvent, whichWindow); EnableItem(myMenus[2],0); DisableItem(myMenus[3],0); break; case inDrag: /*A window move event*/ DragWindow(whichWindow, myEvent.where, &dragRect); break; case inGoAway: /*A window close event*/ if (TrackGoAway(whichWindow,myEvent.where)) { HideWindow(whichWindow); DisableItem(myMenus[3],0); DisableItem(myMenus[2],0); DrawMenuBar(); } if (whichWindow==myDialog) doClose(); break; case inZoomOut: case inZoomIn: if (whichWindow == FrontWindow()) { if (TrackBox(whichWindow,myEvent.where,code)){ EraseRect(&whichWindow->portRect); ZoomWindow(whichWindow,code,TRUE); EraseRect(&whichWindow->portRect); InvalRect(&whichWindow->portRect); if (whichWindow==parseWindow) { MoveScrollBars(parseWindow,pvScroll,hScroll); ResizePRect(parseWindow); BlitRect = pRect; OffsetRect(&BlitRect,-pRect.left,-pRect.top); } } } break; case inGrow: /*A window resizing event*/ if (whichWindow == FrontWindow()) GrowWnd(whichWindow); else SelectWindow(whichWindow); break; case inContent: /*Activate if not already activated*/ if (whichWindow != FrontWindow()) { SelectWindow(whichWindow); SetPort(whichWindow); } else { /*Find location of mouse click in window*/ SetPort(whichWindow); GlobalToLocal(&myEvent.where); ResizePRect(whichWindow); /*Full window*/ if (!PtInRect(myEvent.where,&pRect)) { myControl = FindControl(myEvent.where, whichWindow, &whichControl); if (myControl) { /*Process a scroll event*/ if (whichControl==hScroll) winht=pRect.right-pRect.left; else winht = pRect.bottom-pRect.top; } switch(myControl) { case kControlDownButtonPart: TrackControl(whichControl, myEvent.where,NewControlActionProc((ProcPtr)ScrollDown)); break; case kControlUpButtonPart: TrackControl(whichControl, myEvent.where,NewControlActionProc((ProcPtr)ScrollUp)); break; case kControlPageUpPart: PageScroll(myControl,12-winht); break; case kControlPageDownPart: PageScroll(myControl,winht-12); break; case kControlIndicatorPart: TrackControl(whichControl, myEvent.where,0); ScrollBits(); break; default: if(whichWindow == parseWindow) { HideWindow(whichWindow); DisableItem(myMenus[3],0); DrawMenuBar(); } } } } } break; case keyDown: /*If a menu equivalent key, process*/ case autoKey: if (myEvent.modifiers & cmdKey) docommand(MenuKey((char)myEvent.message)); else { k = myEvent.message & 0xFF; if ((k==CR || k==ENTER) && (FrontWindow() == parseWindow)) { if (k==ENTER) dosave(); /*Save modified text*/ SetControlMaximum(pvScroll,10); /*Return to main dialog*/ SetControlMaximum(hScroll,10); DrawMenuBar(); SetControlValue(pvScroll,0); SetControlValue(hScroll,0); HideWindow(parseWindow); } } break; case activateEvt: whichWindow = (WindowPtr) myEvent.message; if (whichWindow == helpWindow) { /*Activate help window*/ SetPort(helpWindow); DisableItem(myMenus[2],0); DisableItem(myMenus[3],0); DrawGrowIcon(helpWindow); if (myEvent.modifiers&1) { TEActivate(hTE); ShowControl(vScroll); InvalRect(&whichWindow->portRect); } else { /*or deactivate it as appropriate*/ TEDeactivate(hTE); HideControl(vScroll); HideWindow(helpWindow); EnableItem(myMenus[2],0); } } else if (whichWindow == parseWindow) { /*Setup parse window*/ SetPort(parseWindow); DisableItem(myMenus[2],0); EnableItem(myMenus[3],0); DrawGrowIcon(parseWindow); if (myEvent.modifiers&1) { ShowControl(pvScroll); ShowControl(hScroll); InvalRect(&whichWindow->portRect); } else { /*Or deactivate it, as appropriate*/ SetControlValue(pvScroll,0); SetControlValue(hScroll,0); HideControl(pvScroll); HideControl(hScroll); HideWindow(parseWindow); DisableItem(myMenus[3],0); EnableItem(myMenus[2],0); DrawMenuBar(); } } break; case updateEvt:/*Process an update event*/ whichWindow = (WindowPtr) myEvent.message; GetPort(&savePort); InvalRect(&whichWindow->portRect); BeginUpdate(whichWindow); if (whichWindow == parseWindow){ /*Draw from offscreen*/ OffsetRect(&BlitRect,-BlitRect.left,-BlitRect.top); tpOrigin.v = tpOrigin.h = thOrigin.v = 0; DrawWindow(whichWindow,0,0); } if(whichWindow==helpWindow) DrawWindow(whichWindow,0,0); EndUpdate(whichWindow); DrawGrowIcon(whichWindow); SetPort(savePort); break; case diskEvt: /*Process a disk insertion*/ if (myEvent.message) DIBadMount(Origin,myEvent.message); break; } } } void AdjustControl(Point penpos) /*This is a fairly standard sort of routine to adjust the scroll bars according to the pen position and window dimensions. It disables the scroll bars if all the text is in the window. Its parameter is the pen position in the grafport*/ { short windowHeight,windowWidth; windowHeight = pRect.bottom - pRect.top; windowWidth = pRect.right - pRect.left; if (penpos.v > GetControlMaximum(pvScroll)) SetControlMaximum(pvScroll,penpos.v); if (GetControlMaximum(pvScroll) > windowHeight) HiliteControl(pvScroll,0); else HiliteControl(pvScroll,255); if (penpos.h > GetControlMaximum(hScroll)) SetControlMaximum(hScroll,penpos.h); if (GetControlMaximum(hScroll) > windowWidth) HiliteControl(hScroll,0); else HiliteControl(hScroll,255); } void alert(short n,short m) /* This puts up an alert box of type n, with message m */ { message(n,m,0L); } void checkCursor(void) /*This routine puts up an Ibeam cursor whenever the cursor is in the edit text box of the main dialog, else shows the standard error cursor*/ { Point temp; if (FrontWindow() != myDialog) return; GetMouse(&temp); if (PtInRect(temp,&radBox)) SetCursor(*iBeam); else SetCursor(&(qd.arrow)); } void checkout(short item, unsigned char *name, short fileno) /* On entry item is the check button hit, name is the file name, and fileno is its number. The check button is turned on, and if the file is not already open, it calls openout to open it. If the file is open, it is closed and the button is turned off */ { GetDialogItem (myDialog, item, &theType,&itemHdl[0],&itemBox); SetControlValue((ControlHandle)itemHdl[0],BTNON); if(!fileref[fileno]) openout((ControlHandle)itemHdl[0],name,fileno); else { if (fileno == poutfile) wallp = 0; SetControlValue((ControlHandle)itemHdl[0],BTNOFF); IClose(fileno,1); } } void control(short ctrlno, short ctlval, short set) /* On entry ctrlno is the number of the dialog item hit, ctlval is the desired setting, and set is the set number affected. The default button in the appropriate radioset is activated */ { HiliteControl((ControlHandle)itemHdl[ctrlno],ctlval); if (!radSet[set].defaultOn) { radSet[set].defaultOn = ctrlno; radSet[set].nowOn = ctrlno; SetControlValue((ControlHandle)itemHdl[ctrlno], BTNON); } } void doClose(void) /*This winds up operations by closing all the files, hiding the windows, getting rid of space allocation, and exiting*/ { IClose (pinfile,0); IClose (poutfile,1); IClose (tabfile,0); IClose (savefile,1); HideWindow(myDialog); ClosePort(myPtr); DisposePtr(OffScreen.baseAddr); DisposePtr (Aspace); ReleaseResource((*hTE)->hText); exit(0); } void docommand(unsigned long mResult) /*This routine processes Menu requests. The menu and item are in mResult*/ { char name[30]; short theMenu, theItem; // long ticks; theMenu = mResult >> 16; /*Separate menu and menu item*/ theItem = mResult; switch(theMenu) { case appleMenu: GetMenuItemText(myMenus[0], theItem, (unsigned char *)name); if(theItem==1) { /*Show the about Dialog*/ abDialog = GetNewDialog(aboutID,&abRecord,(WindowPtr)-1L); SetPort(abDialog); outlin(1,abDialog); ShowWindow(abDialog); ModalDialog(0L, &itemHit); if (itemHit==2) { /*Help if help button, else return*/ ShowWindow(helpWindow); SelectWindow(helpWindow); } CloseDialog(abDialog); } else { /*If not about item, it is a Desk Accessory*/ DrawMenuBar(); OpenDeskAcc((unsigned char *)name); } break; case editMenu: switch(theItem) { /*Used for editing dialog edit Text items*/ case UNDO: SelectDialogItemText(myDialog,TXT,inpos,(*dlgTE)->selStart); DialogDelete(myDialog); DialogPaste(myDialog); DisableItem(myMenus[2],1); break; case ECUT: DialogCut(myDialog); resultCode = ZeroScrap(); IOCheck(resultCode); resultCode = TEToScrap(); IOCheck(resultCode); break; case ECOPY: DialogCopy(myDialog); resultCode = ZeroScrap(); IOCheck(resultCode); resultCode = TEToScrap(); IOCheck(resultCode); break; case EPASTE: resultCode = TEFromScrap(); IOCheck(resultCode); DialogPaste(myDialog); break; default: break; } break; case fileMenu: switch(theItem) { case MOPEN: opentext(); /*Open a text file, and disable open item*/ DisableItem(myMenus[1],MOPEN); break; case MCLOSE: IClose (pinfile,0); /*Close the open file and enable open*/ inReply.fName[0] = 0; EnableItem(myMenus[1],MOPEN); break; case MQUIT: doClose(); /*Close files and return to finder*/ break; default: break; } break; case parseMenu: /*Set the parse type, scrolling and offscreen bit map, and open parse window*/ ptype = theItem+12; if (ptype==13) ptype = 19; TextFace(0); TextSize(12); SetControlMaximum(pvScroll,0); SetControlMaximum(hScroll,0); OffsetRect(&BlitRect,-BlitRect.left,-BlitRect.top); tpOrigin.v = tpOrigin.h = thOrigin.v = 0; DrawWindow(parseWindow,0,0); break; default: break; } HiliteMenu(0); } /* void domulti() // This is essentially adapted from a MacTutor routine for handling Multifinder events { WindowPtr ResumeWindow,SuspendWindow; WindowPeek RPeek,SPeek; short sysresult; if (myEvent.message & 1) { // Resume ResumeWindow = FrontWindow(); RPeek = (WindowPeek) ResumeWindow; if (ResumeWindow==parseWindow || ResumeWindow==helpWindow) { SetPort(ResumeWindow); InvalRect(&ResumeWindow->portRect); DrawGrowIcon(ResumeWindow); } else if (ResumeWindow) { if (RPeek->windowKind < 0) { myEvent.what = activateEvt; myEvent.modifiers |= 31; sysresult = SystemEvent(&myEvent); } outlin(PARSEBUT,myDialog); } } else { //Suspend SuspendWindow = FrontWindow(); SPeek = (WindowPeek) SuspendWindow; if (SuspendWindow==parseWindow || SuspendWindow==helpWindow) { SetPort(SuspendWindow); InvalRect(&SuspendWindow->portRect); DrawGrowIcon(SuspendWindow); } else if (SuspendWindow) { if (SPeek->windowKind < 0) { myEvent.what = activateEvt; myEvent.modifiers &= 0xFFE0; sysresult = SystemEvent(&myEvent); } } } } */ void DoOffScreen(Rect *Offrect) /*This routine builds an offscreen bitmap for more rapid and even scrolling. It is usually larger than the screen, so only a portion can be shown at any time. The parameter Offrect is the rectangle for the bitmap*/ { OffScreen.bounds.top = Offrect->top; OffScreen.bounds.left = Offrect->left; OffScreen.bounds.bottom = Offrect->bottom; OffScreen.bounds.right = Offrect->right; ResizePRect(parseWindow); BlitRect = pRect; OffsetRect(&BlitRect,-pRect.left,-pRect.top); OffRowBytes = (((OffScreen.bounds.right-OffScreen.bounds.left-1)/16)+1)*2; OffScreen.rowBytes = OffRowBytes; SizeofOff = (long)OffRowBytes * (OffScreen.bounds.bottom - OffScreen.bounds.top); OffScreen.baseAddr = NewPtr(SizeofOff); } void doparse(void) /*This routine handles the actual parsing. It sets up the parse type, opens input files if required*/ { char cline[BIGLIN]; ptype = radSet[1].nowOn; /*Set up parse type*/ switch(radSet[0].nowOn) { case MY: /*Sentence entered at console*/ if (itemHit==PARSEBUT) parseline(); SetCursor(&qd.arrow); /*Restore arrow cursor*/ break; case TEXTSW: switch(radSet[2].nowOn) { /*Set up file type*/ case TEXTFAST: /*All-at-once parsing*/ consp = 0; if (!fileref[pinfile]) opentext(); if (!fileref[pinfile]) break; if (!wallp) checkout(ECHOON,"\pTEXTOUT",poutfile); SetCursor(*Watch); while (GetLine((char *)&iline)){ /*iline is a Ç string*/ badparse = 0; ic = iline; nfputs((unsigned char *)iline,0); Parse(); nfputc(CR); WriteParse(); } alert(1,23); /*Notify that parse is complete*/ SetCursor(&(qd.arrow)); IClose(pinfile,0); /*Close the input file*/ inReply.fName[0] = 0; break; case SENTBYSENT: /*Parse one sentence at a time*/ SetCursor(&(qd.arrow)); cline[0] = 0; /* Get an input file if on text and none yet */ if (!fileref[pinfile]) opentext(); if (!fileref[pinfile]) break; /*Read the display into cline */ GetDialogItemText (itemHdl[TXT],(unsigned char *)cline); /*cline is a P string*/ /*If a string, and not terminated with period, add one and redisplay*/ if(cline[0]) { if (cline[cline[0]] != '.') { cline[++cline[0]] = '.'; SetDialogItemText(itemHdl[TXT],(unsigned char *)cline); } } PtoCstr((unsigned char *)cline); /*Make it a C string*/ /* if new line void, or identical to previous line, get a new line*/ if (!cline[0] || !strcmp(cline,iline)) { if(!GetLine((char *)&iline)){ /*If end of file, say so and close*/ HideWindow(parseWindow); DrawMenuBar(); SetDialogItemText(itemHdl[TXT],(unsigned char *)"\0"); alert(1,23); IClose(pinfile,0); inReply.fName[0] = 0; break; } ic = iline; /*Else set a pointer to it, display and parse*/ SetDialogItemText (itemHdl[TXT],CtoPstr(iline)); /*iline is a P string now*/ } parseline(); break; default: break; } default: break; } } void dosave(void) /*When a change is made to a parse sentence, it can be saved in a save file. Useful for composing sentences. Saving is initiated either with the enter button or the dialog save button. Style 4 is used to direct the saving to the appropriate file.*/ {// long count; if (!fileref[savefile]) checkout(SAVECHK,"\pNEWTEXT",savefile); GetDialogItemText (itemHdl[TXT], (unsigned char *)iline); PtoCstr((unsigned char *)iline); nfputs((unsigned char *)iline,4); /*Save it with a period and two spaces*/ nfputs((unsigned char *)" ",4); } void DrawWindow(WindowPtr theWindow,short hpos,short vpos) /*On entry this routine contains a Window pointer and a horizontal and vertical scroll position. It is used on update to draw the window. If it is the parse window, the origin, and clipping are set, the window is erased, the parse is written, if necessary, to the offscreen bit map and copied to the parse window. Otherwise the help window is updated through the TextEdit routines*/ { Point penpos; penpos.h = penpos.v = 0; ResizePRect(theWindow); AdjustControl(penpos); if (theWindow == parseWindow){ SetPort(myPtr); SetOrigin(hpos,vpos); ClipRect(&myPtr->portBits.bounds); EraseRect(&myPtr->portBits.bounds); ShowWindow(parseWindow); DrawMenuBar(); consp = 1; penx = 20; peny = 20; MoveTo(penx,peny); WriteParse(); SetPort(parseWindow); CopyBits(&myPtr->portBits,&theWindow->portBits,&BlitRect, &pRect,srcCopy,0L); } else { SetPort(helpWindow); ClipRect(&theWindow->portRect); EraseRect(&theWindow->portRect); TEUpdate(&theWindow->portRect, hTE); } DrawControls(theWindow); DrawGrowIcon(theWindow); } Boolean GetLine(char *str) /*On entry str is the address of a buffer to hold the string. A line is read from the input file. If end of file is reached, return FALSE. It is used for reading from text files, rather than corpus-type and table files.*/ { long count; short i; count = 1L; for (i=0; i0)? ToolTrap : OSTrap; } void GrowWnd(WindowPtr whichWindow) /*This is a standard routine for changing the size of the window represented by the pointer whichWindow. Some special care must be taking with the parse window to ensure the proper part of the offscreen bitmap is copied. Scroll bars if any must be resized.*/ { long longResult; short height, width; // Rect temrect; SetPort(whichWindow); longResult = GrowWindow(whichWindow, myEvent.where, &growRect); if (longResult == 0) return; height = longResult >> 16; width = longResult; SizeWindow(whichWindow, width, height, TRUE); if (whichWindow==parseWindow) { MoveScrollBars(parseWindow,pvScroll,hScroll); ResizePRect(parseWindow); BlitRect = pRect; OffsetRect(&BlitRect,-pRect.left,-pRect.top); } else { MoveScrollBars(helpWindow,vScroll,0L); ResizePRect(helpWindow); ClipRect(&pRect); (*hTE)->viewRect = pRect; (*hTE)->destRect.right = pRect.right; TECalText(hTE); whichControl = vScroll; setscroll(); InvalRect(&whichWindow->portRect); } } void IClose(short refno, short flag) /* This is the routine which actually closes an input file. Refno give the input file reference, and flag if TRUE indicates that it is a write file, and end-of-file must be set. Menu items and other flags are adjusted accordingly */ { long count; if (!fileref[refno]) return; if (flag) { resultCode = GetFPos(fileref[refno],&count); IOCheck(resultCode); resultCode = SetEOF(fileref[refno],count); IOCheck(resultCode); } else DisableItem(myMenus[1],MCLOSE); resultCode = FSClose(fileref[refno]); fileref[refno] = 0; IOCheck(resultCode); } Boolean INextLine(short refno) /* A line is read from the input file refno into the stack, and ultimately to iline. If end of file is reached, return FALSE. This routine is used by the original parse program. The routine GetLine is slightly different and was added for reading from text files, which are organized slightly differently as a rule.*/ { long count; short i; char rchr; ic = iline; for (i = 0; itextH; Origin.h = 50; Origin.v = 50; setupdialogs(); parseWindow = GetNewWindow(pwindID,&pRecord,(WindowPtr)-1L); SystemTask(); SetPort(parseWindow); TextFont(3); TextSize(12); pvScroll = GetNewControl(257,parseWindow); hScroll = GetNewControl(258,parseWindow); MoveScrollBars(parseWindow,pvScroll,hScroll); SetRect(&BlitRect,0,0,512,342); SetRect(&OffScreen.bounds,0,0,1024,1368); DoOffScreen(&OffScreen.bounds); if (!OffScreen.baseAddr) { SetRect(&OffScreen.bounds,0,0,512,1368); DoOffScreen(&OffScreen.bounds); } if (!OffScreen.baseAddr) { SetRect(&OffScreen.bounds,0,0,512,684); DoOffScreen(&OffScreen.bounds); } if (!OffScreen.baseAddr) DoOffScreen(&BlitRect); if (!OffScreen.baseAddr) alert(0,6); myPtr = &myPort; OpenPort(myPtr); TextFont(3); SetPortBits(&OffScreen); PortSize(OffScreen.bounds.right,OffScreen.bounds.bottom); ClipRect(&OffScreen.bounds); RectRgn(myPtr->visRgn,&OffScreen.bounds); helpWindow = GetNewWindow(hwindID,&hRecord,(WindowPtr)-1L); SetPort(helpWindow); TextFont(2); TextSize(10); vScroll = GetNewControl(256, helpWindow); MoveScrollBars(helpWindow,vScroll,0L); ResizePRect(helpWindow); hTE = TENew(&pRect, &pRect); (*hTE)->hText = GetResource('TEXT',1); (*hTE)->teLength = GetResourceSizeOnDisk((*hTE)->hText); TECalText(hTE); whichControl = vScroll; setscroll(); ShowWindow(myDialog); SelectWindow(myDialog); /*Disable file menu except quit*/ for (k = 1; k < FILEITEMS+2; ++k) DisableItem (myMenus[1],k); EnableItem(myMenus[1],MOPEN); for (i = 0; i<4; ++i) fileref[i] = 0; Init(); } Boolean AppleEventsInstalled () { OSErr err; long result; err = Gestalt (gestaltAppleEventsAttr, &result); return (!err && ((result >> gestaltAppleEventsPresent) & 0x0001)); // return TRUE if there is no // error and the proper bit of // result is set } void initMac(void) /*This is a standard setup for the various Mac managers*/ { Boolean aEvents; // OSErr err; InitGraf(&qd.thePort); InitFonts(); FlushEvents(everyEvent, 0); InitWindows(); TEInit(); InitDialogs(0); InitCursor(); dragRect = (*GetGrayRgn())->rgnBBox; InsetRect(&dragRect, 4, 4); // JPJ: init hasGestalt before calling initdict() WNE = TrapAvailable(WNEnumber); hasGestalt = TrapAvailable(0xa1ad); // _Gestalt = 0xA1AD ascript = FALSE; sleeep = 20; aEvents = AppleEventsInstalled(); gSDI = TrapAvailable (SDInumber); if (aEvents) { if (AEInstallEventHandler (kCoreEventClass, kAEOpenApplication, NewAEEventHandlerProc(MyHandleOAPP),0,FALSE)) alert (0,1); if (AEInstallEventHandler (kCoreEventClass, kAEOpenDocuments, NewAEEventHandlerProc(MyHandleODOC),0,FALSE)) alert (0,1); if (AEInstallEventHandler (kCoreEventClass, kAEPrintDocuments, NewAEEventHandlerProc(MyHandlePDOC),0,FALSE)) alert (0,1); if (AEInstallEventHandler (kCoreEventClass, kAEQuitApplication, NewAEEventHandlerProc(MyHandleQUIT),0,FALSE)) alert (0,1); if (AEInstallEventHandler('Lips', 'Pars',NewAEEventHandlerProc(HandleAEParse), 0, FALSE)) alert (0,1); } myType[0] = 'TEXT'; } void initRects(void) /* A fairly standard routine for initializing the drag and grow rectangles for windows*/ { short mBarHeight,MinHeight,MinWidth; Rect screen; MinHeight = 30; MinWidth = 30; mBarHeight = 21; screen = qd.screenBits.bounds; SetRect(&dragRect,screen.left + 4,screen.top+mBarHeight+4, screen.right - 4,screen.bottom - 4); SetRect(&growRect,screen.left + MinWidth, screen.top + mBarHeight + MinHeight,screen.right - 8,screen.bottom - 8); } void message(short n,short m, unsigned char *txt) /* Display an alert window of type n, with resource message m, and text txt */ { Handle strtext; strtext = GetResource('STR ',m); ParamText((unsigned char *)*strtext, (unsigned char *)txt, NULL,NULL); SetCursor(&(qd.arrow)); switch(n) { case 0: theType = StopAlert(alertID, NULL); break; case 1: theType = NoteAlert(alertID, NULL); break; case 2: theType = CautionAlert(alertID, NULL); break; } if (theType==2) doClose(); } void MoveScrollBars(WindowPtr thisWindow, ControlHandle tvscroll,ControlHandle thscroll) /* Move the scroll bars with handles tvscroll and thscroll in window pointer thisWindow to the right and bottom edges after a window is resized */ { register Rect *rp; rp = &thisWindow->portRect; if (tvscroll) { HideControl(tvscroll); MoveControl(tvscroll, rp->right-15, rp->top-1); SizeControl(tvscroll, 16, rp->bottom-rp->top-13); ShowControl(tvscroll); } if (thscroll) { HideControl(thscroll); MoveControl(thscroll, rp->left, rp->bottom-15); SizeControl(thscroll, rp->right-rp->left-13,16); ShowControl(thscroll); } } pascal OSErr MyGotRequiredParams(AppleEvent *theAppleEvent) { DescType returnedType; Size actualSize; resultCode = AEGetAttributePtr (theAppleEvent, keyMissedKeywordAttr, typeWildCard, &returnedType, NULL, 0,&actualSize); if (resultCode == errAEDescNotFound) return noErr; if (resultCode==noErr) return errAEParamMissed; return resultCode; } pascal OSErr MyHandleOAPP (AppleEvent *theAppleEvent, AppleEvent *, long ) { return MyGotRequiredParams(theAppleEvent); } pascal OSErr MyHandleODOC (AppleEvent *theAppleEvent,AppleEvent *,long ) { AEDescList docList; long i, items; Size actualSize,maxsize; AEKeyword keywd; DescType retType; FSSpec myFSS; OSErr iErr; if (!AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList,&docList)) alert(0,1); if ((iErr = !MyGotRequiredParams(theAppleEvent)) != 0) { alert (0,1); doClose(); return iErr; } resultCode = AECountItems (&docList,&items); maxsize = sizeof(myFSS); for (i=0; iportRect; pRect.left += 4; pRect.right -= 20; pRect.bottom -= 20; } void ScrollBits(void) /* If the new position is entirely inside the offscreen bit map, scroll by offsetting the position of the view rectangle on the offscreen map. Otherwise redraw the offscreen map and window from a new origin. If it is the help window scroll with TEScroll */ { Point oldOrigin,theOrigin; // Rect temp; short dh, dv,r; long maxht; GetPort(&whichWindow); ResizePRect(whichWindow); maxht = GetControlMaximum(whichControl); winht = (whichControl==hScroll) ? pRect.right - pRect.left : pRect.bottom - pRect.top; oldOrigin = theOrigin = (whichControl==vScroll) ? thOrigin : tpOrigin; if (whichControl==pvScroll || whichControl==vScroll) theOrigin.v = (GetControlValue(whichControl) * (maxht-winht))/maxht; else theOrigin.h = (GetControlValue(whichControl) * (maxht-winht))/maxht; dh = oldOrigin.h - theOrigin.h; dv = oldOrigin.v - theOrigin.v; if (whichControl==vScroll) thOrigin = theOrigin; else tpOrigin = theOrigin; factor = (maxht*1000)/(maxht-winht); if (whichWindow == parseWindow) { OffsetRect(&BlitRect,-dh,-dv); if (BlitRect.bottom>myPtr->portBits.bounds.bottom) { DrawWindow(parseWindow,tpOrigin.h-BlitRect.left,tpOrigin.v); } else if (BlitRect.right>myPtr->portBits.bounds.right) { DrawWindow(parseWindow,tpOrigin.h,tpOrigin.v-BlitRect.top); } else if (BlitRect.topportBits.bounds.top) { r = OffScreen.bounds.bottom - BlitRect.bottom; DrawWindow(parseWindow,tpOrigin.h-BlitRect.left, -r); } else if (BlitRect.leftportBits.bounds.left) { r = OffScreen.bounds.right - BlitRect.right; DrawWindow(parseWindow,-r,tpOrigin.v-BlitRect.top); } else CopyBits(&myPtr->portBits,&parseWindow->portBits,&BlitRect, &pRect,srcCopy,0L); return; } else if (whichWindow == helpWindow) { TEScroll(dh, dv, hTE); } } pascal void ScrollDown(ControlHandle whichControl, short theCode) /* Scroll down one line height if the click was in the down button */ { if (theCode == kControlDownButtonPart) { SetControlValue(whichControl, GetControlValue(whichControl) + (*hTE)->lineHeight); (whichControl==vScroll)?ScrollBits():ScrollBits(); } } pascal void ScrollUp(ControlHandle whichControl, short theCode) /* Scroll up one line height if the click was in the up button */ { if (theCode == kControlUpButtonPart) { SetControlValue(whichControl, GetControlValue(whichControl) - (*hTE)->lineHeight); (whichControl==vScroll)?ScrollBits():ScrollBits(); } } void setupdialogs(void) /* Set the default radio buttons in the main dialog, and disable the text entry buttons (until text entry is selected) */ { control(GROUP,0,1); control(MY,0,0); control(SENTBYSENT,0,2); HiliteControl((ControlHandle)itemHdl[SENTBYSENT],255); HiliteControl((ControlHandle)itemHdl[TEXTFAST],255); } void setupmenu(void) /* Get the menu resources and draw the menu bar */ { short i; InitMenus(); myMenus[0] = GetMenu(appleMenu); AppendResMenu(myMenus[0], 'DRVR'); myMenus[1] = GetMenu(fileMenu); myMenus[2] = GetMenu(editMenu); myMenus[3] = GetMenu(parseMenu); for (i=0;inLines * (*hTE)->lineHeight; if (maxl<=winht) { HiliteControl(vScroll,255); } else HiliteControl(vScroll,0); SetControlMaximum(vScroll,maxl); ScrollBits(); } Boolean TrapAvailable(short theTrap) { TrapType tType; tType = GetTrapType(theTrap); if (tType==ToolTrap) if ((theTrap&&0x7ff)>=NumToolboxTraps()) theTrap=Unimplemented; return NGetTrapAddress(theTrap,tType) != NGetTrapAddress(Unimplemented,ToolTrap); } void WriteParse(void) /*Write the appropriate type of parse, or a failure message in the Parse Window and to any selected output files */ { if (badparse){ nfputc(CR); nfputs ((unsigned char *)"THIS EXPRESSION DOES NOT PARSE",0); nfputc(CR); // sprintf (oline,"Failure at token %d and at state %d",curword,yystate); // nfputs((unsigned char *)oline,0); nfputc(CR); if (!fullprs[0] && ptype !=LEXEMES) return; } switch(ptype) { case GROUP: WriteString(humactprs,0); break; case FULL: DspString(fullprs,2); break; case MACHINE: WriteString(actualprs,0); nfputc(CR); WriteString (actualprs,1); break; case LEXEMES: LexWrite(); break; case GPandLX: WriteString (humactprs,0); nfputc(CR); WriteString (humactprs,2); break; case SHORT: DspString(fullprs,TRUE); break; default: WriteString (humactprs,0); break; } nfputc(CR); nfputc(CR); } // Additional routines added Mar 95 for Scripting Purposes /* Parse a line of Loglan text in one of many forms */ OSErr DoAEParse(AEDesc *ptrToTheResult,char *iline) { long len; OSErr err; char *result; result = (char *) OffScreen.baseAddr; oc = result; badparse = 0; ic = iline; Parse(); WriteParse(); *oc = 0; len = strlen(result); err = AECreateDesc('TEXT',result,len,ptrToTheResult); if (!len) alert(0,2); if (err) alert(0,1); return err; } pascal OSErr HandleAEParse(const AppleEvent *theAppleEvent, const AppleEvent *theReply, long ) { OSErr err; DescType typeCode; long actualSize; AEDesc theResult = {typeNull, nil}; enum {LP=14,HP,MP,WG,PT,PP}; long type; ascript = TRUE; consp = TRUE; err = AEGetParamPtr(theAppleEvent,keyDirectObject,typeWildCard,&typeCode,iline,1000,&actualSize); iline[(short)actualSize] = 0; if (err) goto CleanUp; err = AEGetParamPtr(theAppleEvent,'form',typeWildCard,&typeCode,&type,4,&actualSize); if (err == errAEDescNotFound) { ptype = LP; } else { if (err) goto CleanUp; switch (type){ case 'LP ': ptype = 14; break; case 'HP ': ptype = 15; break; case 'MP ': ptype = 16; break; case 'PT ': ptype = 17; break; case 'WG ': ptype = 18; break; case 'PP ': ptype = 19; break; default: ptype = 14; break; } } /* We check to see if we missed any parameter from the client */ if (AESizeOfAttribute(theAppleEvent, keyMissedKeywordAttr, &typeCode, &actualSize) != errAEDescNotFound) { err = errAEParamMissed; goto CleanUp; }; err = DoAEParse(&theResult,iline); if (err) goto CleanUp; if ((*theReply).dataHandle) err = AEPutKeyDesc((AppleEvent *)theReply, keyDirectObject,&theResult); CleanUp: AEDisposeDesc(&theResult); ascript = FALSE; return err; }