home *** CD-ROM | disk | FTP | other *** search
- /***********main file for hAWK**************/
- /* This file contains the entry point for the code resource, and
- a bit of glue for the extension functions. From resource to resource
- all that varies is the name of the function called to do the real
- work - "InvokeHAWK" here. */
-
- /* Copyright © 1986,1988,1989,1991,1992 the Free Software Foundation, Inc.
- * This file is part of GAWK, the GNU implementation of the
- * AWK Progamming Language, modified for the Macintosh (also called hAWK).
- * GAWK is free software; you can redistribute or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 1, or any later version.
- * GAWK is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- * You should have received a copy of the GNU General Public License
- * along with GAWK; see the file "COPYING hAWK". If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- * Written for THINK C 4 on the Macintosh by Ken Earle (Dynabyte) Aug 1991.
- Revised May 1992: new setup/restore a4 strategy.
- Rev Apr 1995: converted over to Code Warrior
- */
-
- #ifdef powerc
- #include <CodeFragments.h>
- #else
- #include <A4Stuff.h>
- #endif
-
- #include <string.h>
- #include <stdlib.h>
- #include "AppCodeComm.h"
-
-
- #ifndef NULL
- #define NULL ((void *) 0)
- #endif
-
- /* Global copy of the AppCodeComm struct passed from the application
- to the code resource - gacc stands for Global Application-Code resource
- Communication. Gacc.*/
- AppCodeComm gacc;
-
- /* Global to indicate if calling app's event loop has been made
- available and should call it */
- Boolean gConcurrent;
-
- #ifndef powerc
- long _app_a4;
- #endif
- /* "main" call for the specific code resource */
- extern short InvokeHAWK(void); /* see Hawk_Interface.c */
-
- /* Protos for functions in this file */
- void main(ACCPtr ac);
- /* Callbacks, to be made available to other files */
- short InDictionary(char *tokenName);
- Boolean HasInDictionary(void);
- Handle GetFrontText(Boolean getItAll);
- Boolean HasGetFrontText(void);
- void GetNextMultiFile(short *panePtr, short *indexPtr,
- short *vRefNumPtr, char *fileName, Boolean clearFlag);
- Boolean HasGetNextMultiFile(void);
- short OKStopAlert(Ptr cstringPtr);
- Boolean HasOKStopAlert(void);
- void MemoryAlert(void);
- Boolean HasMemoryAlert(void);
- short GetScreenHeight(void);
- Boolean HasGetScreenHeight(void);
- short GetScreenWidth(void);
- Boolean HasGetScreenWidth(void);
- void SetWatchCursor(void);
- Boolean HasSetWatchCursor(void);
- void DoEventLoopOnce(void);
- Boolean HasDoEventLoopOnce(void);
- Handle GetTheClip(void);
- Boolean HasGetTheClip(void);
- short PutTheClip(char *newClipStr);
- Boolean HasPutTheClip(void);
-
- // Kludge required by CodeWarrior 6
- void (*__exit_proc__)(void);
-
- /* The "main" that is called from the running application. This file is
- kept small and in its own segment because lots of other things get piled
- into here as well - the jump table for the code resource, for example.
- So do the bare minimum - set up the global register reference, call the
- code resource main function, pass back a result code, and restore the
- a4 register. Functions below main() are the extension interface
- functions, which must be in this file to make use of the little functions
- above that save and restore a4. They all check to see that the extension
- in question has been passed from the application, and if not either return
- a zero or NULL or return a safe general value. No extension should be
- essential to the operation of the code resource.
- */
- /* results:
- <= -3 : counts as -1 at present
- -2 : show stderr
- -1 : user cancelled or error during dialog - no run
- 0 : run OK, do nothing special after
- 1 : show stdout
- 2 : show and select stdout
- > 2 : no action at present (counts as equivalent to 0)
- */
- void main(ACCPtr ac)
- {
- short result;
- #ifndef powerc
- long _app_a4 = SetCurrentA4(); //sets A4 to point to your code resources globals
- //it returns what's currently in A4 so you can restore it later
- //SetCurrentA4 and SetA4 are analogous to SetCurrentA5 and SetA5
- #endif
- extern short AWKmain(short argc, char **argv);
- extern void do_input(void);
- extern short Progress(char *msg, short msgLen);
-
- /* Uncomment this for a version "sanity check": **************
- if (ac->version < 0 || ac->version > 100)
- {
- OKStopAlert("Version number passed by calling application \
- is impossible. Please fix the application before trying again.");
- ac->result = -1;
- (void)SetA4(_app_a4);
- return;
- }
- ********** end version check */
-
- gacc = *ac; /* make a global copy */
-
- if (gacc.version <= 1)
- {
- gacc.DoEventLoopOnce_Ext = NULL;
- gacc.GetAppClip_Ext = NULL;
- }
- if (HasDoEventLoopOnce())
- gConcurrent = TRUE;
- else
- gConcurrent = FALSE;
-
- /* call 'true' main of code resource */
- result = InvokeHAWK();
- ac->result = result;
- #ifndef powerc
- //Reset A4 to what it was when we entered. The return value (which we ignore) is our
- //global pointing A4.
- (void)SetA4(_app_a4);
- /* return nothing - communication via (ga)ac->result */
- #endif
- }
-
- /* Extension functions. See Call_Resource.c for details
- on what these do. EnterAct supplies them all, but your application
- doesn't have to supply any of them, and your code resource should
- not rely on any of them being available.
-
- A Boolean companion function for each extension reports whether
- the extension is available for use.
- */
-
- short InDictionary(char *tokenName)
- {
- ACCPtr laccp = &gacc; /* must use a local pointer if 68K */
- short ret;
- #ifndef powerc
- long cura4 = SetA4(_app_a4);
- #endif
- if (laccp->InDictionary_Ext != NULL)
- ret = (*(laccp->InDictionary_Ext))(tokenName);
- else
- ret = 0;
- #ifndef powerc
- (void)SetA4(cura4);
- #endif
- return(ret);
- }
-
- Boolean HasInDictionary()
- {
- return(gacc.InDictionary_Ext != NULL);
- }
-
- Handle GetFrontText(Boolean getItAll)
- {
- ACCPtr laccp = &gacc; /* must use a local pointer */
- Handle ret;
- #ifndef powerc
- long cura4 = SetA4(_app_a4);
- #endif
- if (laccp->GetFrontText_Ext != NULL)
- ret = (*(laccp->GetFrontText_Ext))(getItAll);
- else
- ret = NULL;
- #ifndef powerc
- (void)SetA4(cura4);
- #endif
- return(ret);
- }
-
- Boolean HasGetFrontText()
- {
- return(gacc.GetFrontText_Ext != NULL);
- }
-
- void GetNextMultiFile(short *panePtr, short *indexPtr,
- short *vRefNumPtr, char *fileName, Boolean clearFlag)
- {
- ACCPtr laccp = &gacc; /* must use a local pointer */
- #ifndef powerc
- long cura4 = SetA4(_app_a4);
- #endif
- if (laccp->GetNextMultiFile_Ext != NULL)
- (*(laccp->GetNextMultiFile_Ext))(panePtr, indexPtr,
- vRefNumPtr, fileName, clearFlag);
- else
- *indexPtr = -1;
- #ifndef powerc
- (void)SetA4(cura4);
- #endif
- }
-
- Boolean HasGetNextMultiFile()
- {
- return(gacc.GetNextMultiFile_Ext != NULL);
- }
-
- short OKStopAlert(Ptr cstringPtr)
- {
- ACCPtr laccp = &gacc; /* must use a local pointer */
- short ret;
- #ifndef powerc
- long cura4 = SetA4(_app_a4);
- #endif
- if (laccp->OKStopAlert_Ext != NULL)
- ret = (*(laccp->OKStopAlert_Ext))(cstringPtr);
- else
- ret = 0;
- #ifndef powerc
- (void)SetA4(cura4);
- #endif
- return(ret);
- }
-
- Boolean HasOKStopAlert()
- {
- return(gacc.OKStopAlert_Ext != NULL);
- }
-
- void MemoryAlert()
- {
- ACCPtr laccp = &gacc; /* must use a local pointer */
- #ifndef powerc
- long cura4 = SetA4(_app_a4);
- #endif
- if (laccp->MemoryAlert_Ext != NULL)
- (*(laccp->MemoryAlert_Ext))();
- #ifndef powerc
- (void)SetA4(cura4);
- #endif
- }
-
- Boolean HasMemoryAlert()
- {
- return(gacc.MemoryAlert_Ext != NULL);
- }
-
- short GetScreenHeight()
- {
- ACCPtr laccp = &gacc; /* must use a local pointer */
- short ret;
- #ifndef powerc
- long cura4 = SetA4(_app_a4);
- #endif
- if (laccp->GetScreenHeight_Ext != NULL)
- ret = (*(laccp->GetScreenHeight_Ext))();
- else
- ret = 342; /* minimum possible */
- #ifndef powerc
- (void)SetA4(cura4);
- #endif
- return(ret);
- }
-
- Boolean HasGetScreenHeight()
- {
- return(gacc.GetScreenHeight_Ext != NULL);
- }
-
- short GetScreenWidth()
- {
- ACCPtr laccp = &gacc; /* must use a local pointer */
- short ret;
- #ifndef powerc
- long cura4 = SetA4(_app_a4);
- #endif
- if (laccp->GetScreenWidth_Ext != NULL)
- ret = (*(laccp->GetScreenWidth_Ext))();
- else
- ret = 512; /* minimum possible */
- #ifndef powerc
- (void)SetA4(cura4);
- #endif
- return(ret);
- }
-
- Boolean HasGetScreenWidth()
- {
- return(gacc.GetScreenWidth_Ext != NULL);
- }
-
- void SetWatchCursor()
- {
- ACCPtr laccp = &gacc; /* must use a local pointer */
- #ifndef powerc
- long cura4 = SetA4(_app_a4);
- #endif
- if (laccp->SetWatchCursor_Ext != NULL)
- (*(laccp->SetWatchCursor_Ext))();
- #ifndef powerc
- (void)SetA4(cura4);
- #endif
- }
-
- Boolean HasSetWatchCursor()
- {
- return(gacc.SetWatchCursor_Ext != NULL);
- }
-
- void DoEventLoopOnce()
- {
- ACCPtr laccp = &gacc; /* must use a local pointer */
- #ifndef powerc
- long cura4 = SetA4(_app_a4);
- #endif
- if (laccp->DoEventLoopOnce_Ext != NULL)
- (*(laccp->DoEventLoopOnce_Ext))();
- #ifndef powerc
- (void)SetA4(cura4);
- #endif
- }
-
- Boolean HasDoEventLoopOnce()
- {
- return(gacc.DoEventLoopOnce_Ext != NULL);
- }
-
- Handle GetTheClip()
- {
- ACCPtr laccp = &gacc; /* must use a local pointer */
- Handle ret;
- #ifndef powerc
- long cura4 = SetA4(_app_a4);
- #endif
- if (laccp->GetAppClip_Ext != NULL)
- ret = (*(laccp->GetAppClip_Ext))();
- else
- ret = NULL;
- #ifndef powerc
- (void)SetA4(cura4);
- #endif
- return(ret);
- }
-
- Boolean HasGetTheClip()
- {
- return(gacc.GetAppClip_Ext != NULL);
- }
-
- // Note for version 3 the version is signalled by long extendID == 'VER3'
- // inside gacc -- for previous versions, the odds of this long being set
- // to exactly 'VER3' are very small.
-
- short PutTheClip(char *newClipStr)
- {
- ACCPtr laccp = &gacc; /* must use a local pointer */
- short ret = 0;
- #ifndef powerc
- long cura4 = SetA4(_app_a4);
- #endif
- if (laccp->extendID == 'VER3' && laccp->PutAppClip_Ext != NULL)
- ret = (*(laccp->PutAppClip_Ext))(newClipStr);
- #ifndef powerc
- (void)SetA4(cura4);
- #endif
- return(ret);
- }
-
- Boolean HasPutTheClip(void)
- {
- return(gacc.extendID == 'VER3' && gacc.PutAppClip_Ext != NULL);
- }
-
-