home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Utilities / Programming / EnterAct 3.5 / hAWK project / AWK Source / Code_Main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-12  |  9.8 KB  |  393 lines  |  [TEXT/KEEN]

  1. /***********main file for hAWK**************/
  2. /* This file contains the entry point for the code resource, and
  3. a bit of glue for the extension functions. From resource to resource
  4. all that varies is the name of the function called to do the real
  5. work - "InvokeHAWK" here.                 */
  6.  
  7. /* Copyright © 1986,1988,1989,1991,1992 the Free Software Foundation, Inc.
  8.  *         This file is part of GAWK, the GNU implementation of the
  9.  * AWK Progamming Language, modified for the Macintosh (also called hAWK).
  10.  *         GAWK is free software; you can redistribute or modify
  11.  * it under the terms of the GNU General Public License as published by
  12.  * the Free Software Foundation; either version 1, or any later version.
  13.  *         GAWK is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16.  * GNU General Public License for more details.
  17.  *         You should have received a copy of the GNU General Public License
  18.  * along with GAWK; see the file "COPYING hAWK". If not, write to
  19.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  * Written for THINK C 4 on the Macintosh by Ken Earle (Dynabyte) Aug 1991.
  21.    Revised May 1992: new setup/restore a4 strategy.
  22.    Rev Apr 1995: converted over to Code Warrior
  23.  */
  24.  
  25. #ifdef powerc
  26. #include <CodeFragments.h>
  27. #else
  28. #include <A4Stuff.h>
  29. #endif
  30.  
  31. #include <string.h>
  32. #include <stdlib.h>
  33. #include "AppCodeComm.h"
  34.  
  35.  
  36. #ifndef NULL
  37. #define NULL        ((void *) 0)
  38. #endif
  39.  
  40. /* Global copy of the AppCodeComm struct passed from the application
  41. to the code resource - gacc stands for Global Application-Code resource
  42. Communication. Gacc.*/
  43. AppCodeComm    gacc;
  44.  
  45. /* Global to indicate if calling app's event loop has been made
  46. available and should call it */
  47. Boolean gConcurrent;
  48.  
  49. #ifndef powerc
  50. long _app_a4;
  51. #endif
  52. /* "main" call for the specific code resource */
  53. extern short InvokeHAWK(void); /* see Hawk_Interface.c */
  54.  
  55. /* Protos for functions in this file */
  56. void main(ACCPtr ac);
  57. /* Callbacks, to be made available to other files */
  58. short InDictionary(char *tokenName);
  59. Boolean HasInDictionary(void);
  60. Handle GetFrontText(Boolean getItAll);
  61. Boolean HasGetFrontText(void);
  62. void GetNextMultiFile(short *panePtr, short *indexPtr, 
  63.         short *vRefNumPtr, char *fileName, Boolean clearFlag);
  64. Boolean HasGetNextMultiFile(void);
  65. short OKStopAlert(Ptr cstringPtr);
  66. Boolean HasOKStopAlert(void);
  67. void MemoryAlert(void);
  68. Boolean HasMemoryAlert(void);
  69. short GetScreenHeight(void);
  70. Boolean HasGetScreenHeight(void);
  71. short GetScreenWidth(void);
  72. Boolean HasGetScreenWidth(void);
  73. void SetWatchCursor(void);
  74. Boolean HasSetWatchCursor(void);
  75. void DoEventLoopOnce(void);
  76. Boolean HasDoEventLoopOnce(void);
  77. Handle GetTheClip(void);
  78. Boolean HasGetTheClip(void);
  79. short PutTheClip(char *newClipStr);
  80. Boolean HasPutTheClip(void);
  81.  
  82. // Kludge required by CodeWarrior 6
  83.  void (*__exit_proc__)(void);
  84.  
  85. /* The "main" that is called from the running application. This file is
  86. kept small and in its own segment because lots of other things get piled
  87. into here as well - the jump table for the code resource, for example.
  88. So do the bare minimum - set up the global register reference, call the
  89. code resource main function, pass back a result code, and restore the
  90. a4 register. Functions below main() are the extension interface
  91. functions, which must be in this file to make use of the little functions
  92. above that save and restore a4. They all check to see that the extension
  93. in question has been passed from the application, and if not either return
  94. a zero or NULL or return a safe general value. No extension should be
  95. essential to the operation of the code resource.
  96. */
  97. /* results:
  98. <= -3 : counts as -1 at present
  99. -2 : show stderr
  100. -1 : user cancelled or error during dialog - no run
  101. 0  : run OK, do nothing special after
  102. 1  : show stdout
  103. 2  : show and select stdout
  104. > 2 : no action at present (counts as equivalent to 0)
  105. */
  106. void main(ACCPtr ac)
  107.     {
  108.     short    result;
  109. #ifndef powerc
  110.     long     _app_a4 = SetCurrentA4();    //sets A4 to point to your code resources globals
  111.                                     //it returns what's currently in A4 so you can restore it later
  112.                                     //SetCurrentA4 and SetA4 are analogous to SetCurrentA5 and SetA5
  113. #endif
  114.     extern short AWKmain(short argc, char **argv);
  115.     extern void do_input(void);
  116.     extern short Progress(char *msg, short msgLen);
  117.     
  118.     /* Uncomment this for a version "sanity check": **************
  119.     if (ac->version < 0 || ac->version > 100)
  120.         {
  121.         OKStopAlert("Version number passed by calling application \
  122. is impossible. Please fix the application before trying again.");
  123.         ac->result = -1;
  124.         (void)SetA4(_app_a4);
  125.         return;
  126.         }
  127.     ********** end version check */
  128.  
  129.     gacc = *ac; /* make a global copy */
  130.  
  131.     if (gacc.version <= 1)
  132.         {
  133.         gacc.DoEventLoopOnce_Ext = NULL;
  134.         gacc.GetAppClip_Ext = NULL;
  135.         }
  136.     if (HasDoEventLoopOnce())
  137.         gConcurrent = TRUE;
  138.     else
  139.         gConcurrent = FALSE;
  140.     
  141.     /* call 'true' main of code resource */
  142.     result = InvokeHAWK();
  143.     ac->result = result;
  144. #ifndef powerc
  145.     //Reset A4 to what it was when we entered.  The return value (which we ignore) is our
  146.     //global pointing A4.
  147.     (void)SetA4(_app_a4);
  148.     /* return nothing - communication via (ga)ac->result */
  149. #endif
  150.     }
  151.  
  152. /* Extension functions. See Call_Resource.c for details
  153. on what these do. EnterAct supplies them all, but your application
  154. doesn't have to supply any of them, and your code resource should
  155. not rely on any of them being available.
  156.  
  157. A Boolean companion function for each extension reports whether
  158. the extension is available for use. 
  159. */
  160.  
  161. short InDictionary(char *tokenName)
  162.     {
  163.     ACCPtr    laccp = &gacc; /* must use a local pointer if 68K */
  164.     short    ret;
  165. #ifndef powerc
  166.     long cura4 = SetA4(_app_a4);
  167. #endif
  168.     if (laccp->InDictionary_Ext != NULL)
  169.         ret = (*(laccp->InDictionary_Ext))(tokenName);
  170.     else
  171.         ret = 0;
  172. #ifndef powerc
  173.     (void)SetA4(cura4);
  174. #endif
  175.     return(ret);
  176.     }
  177.  
  178. Boolean HasInDictionary()
  179.     {
  180.     return(gacc.InDictionary_Ext != NULL);
  181.     }
  182.  
  183. Handle GetFrontText(Boolean getItAll)
  184.     {
  185.     ACCPtr    laccp = &gacc; /* must use a local pointer */
  186.     Handle    ret;
  187. #ifndef powerc
  188.     long cura4 = SetA4(_app_a4);
  189. #endif
  190.     if (laccp->GetFrontText_Ext != NULL)
  191.         ret = (*(laccp->GetFrontText_Ext))(getItAll);
  192.     else
  193.         ret = NULL;
  194. #ifndef powerc
  195.     (void)SetA4(cura4);
  196. #endif
  197.     return(ret);
  198.     }
  199.  
  200. Boolean HasGetFrontText()
  201.     {
  202.     return(gacc.GetFrontText_Ext != NULL);
  203.     }
  204.  
  205. void GetNextMultiFile(short *panePtr, short *indexPtr, 
  206.         short *vRefNumPtr, char *fileName, Boolean clearFlag)
  207.     {
  208.     ACCPtr    laccp = &gacc; /* must use a local pointer */
  209. #ifndef powerc
  210.     long cura4 = SetA4(_app_a4);
  211. #endif
  212.     if (laccp->GetNextMultiFile_Ext != NULL)
  213.         (*(laccp->GetNextMultiFile_Ext))(panePtr, indexPtr,
  214.             vRefNumPtr, fileName, clearFlag);
  215.     else
  216.         *indexPtr = -1;
  217. #ifndef powerc
  218.     (void)SetA4(cura4);
  219. #endif
  220.     }
  221.  
  222. Boolean HasGetNextMultiFile()
  223.     {
  224.     return(gacc.GetNextMultiFile_Ext != NULL);
  225.     }
  226.  
  227. short OKStopAlert(Ptr cstringPtr)
  228.     {
  229.     ACCPtr    laccp = &gacc; /* must use a local pointer */
  230.     short    ret;
  231. #ifndef powerc
  232.     long cura4 = SetA4(_app_a4);
  233. #endif
  234.     if (laccp->OKStopAlert_Ext != NULL)
  235.         ret = (*(laccp->OKStopAlert_Ext))(cstringPtr);
  236.     else
  237.         ret = 0;
  238. #ifndef powerc
  239.     (void)SetA4(cura4);
  240. #endif
  241.     return(ret);
  242.     }
  243.  
  244. Boolean HasOKStopAlert()
  245.     {
  246.     return(gacc.OKStopAlert_Ext != NULL);
  247.     }
  248.  
  249. void MemoryAlert()
  250.     {
  251.     ACCPtr    laccp = &gacc; /* must use a local pointer */
  252. #ifndef powerc
  253.     long cura4 = SetA4(_app_a4);
  254. #endif
  255.     if (laccp->MemoryAlert_Ext != NULL)
  256.         (*(laccp->MemoryAlert_Ext))();
  257. #ifndef powerc
  258.     (void)SetA4(cura4);
  259. #endif
  260.     }
  261.  
  262. Boolean HasMemoryAlert()
  263.     {
  264.     return(gacc.MemoryAlert_Ext != NULL);
  265.     }
  266.  
  267. short GetScreenHeight()
  268.     {
  269.     ACCPtr    laccp = &gacc; /* must use a local pointer */
  270.     short        ret;
  271. #ifndef powerc
  272.     long cura4 = SetA4(_app_a4);
  273. #endif
  274.     if (laccp->GetScreenHeight_Ext != NULL)
  275.         ret = (*(laccp->GetScreenHeight_Ext))();
  276.     else
  277.         ret = 342; /* minimum possible */
  278. #ifndef powerc
  279.     (void)SetA4(cura4);
  280. #endif
  281.     return(ret);
  282.     }
  283.  
  284. Boolean HasGetScreenHeight()
  285.     {
  286.     return(gacc.GetScreenHeight_Ext != NULL);
  287.     }
  288.  
  289. short GetScreenWidth()
  290.     {
  291.     ACCPtr    laccp = &gacc; /* must use a local pointer */
  292.     short        ret;
  293. #ifndef powerc
  294.     long cura4 = SetA4(_app_a4);
  295. #endif
  296.     if (laccp->GetScreenWidth_Ext != NULL)
  297.         ret = (*(laccp->GetScreenWidth_Ext))();
  298.     else
  299.         ret = 512; /* minimum possible */
  300. #ifndef powerc
  301.     (void)SetA4(cura4);
  302. #endif
  303.     return(ret);
  304.     }
  305.  
  306. Boolean HasGetScreenWidth()
  307.     {
  308.     return(gacc.GetScreenWidth_Ext != NULL);
  309.     }
  310.  
  311. void SetWatchCursor()
  312.     {
  313.     ACCPtr    laccp = &gacc; /* must use a local pointer */
  314. #ifndef powerc
  315.     long cura4 = SetA4(_app_a4);
  316. #endif
  317.     if (laccp->SetWatchCursor_Ext != NULL)
  318.         (*(laccp->SetWatchCursor_Ext))();
  319. #ifndef powerc
  320.     (void)SetA4(cura4);
  321. #endif
  322.     }
  323.  
  324. Boolean HasSetWatchCursor()
  325.     {
  326.     return(gacc.SetWatchCursor_Ext != NULL);
  327.     }
  328.  
  329. void DoEventLoopOnce()
  330.     {
  331.     ACCPtr    laccp = &gacc; /* must use a local pointer */
  332. #ifndef powerc
  333.     long cura4 = SetA4(_app_a4);
  334. #endif
  335.     if (laccp->DoEventLoopOnce_Ext != NULL)
  336.         (*(laccp->DoEventLoopOnce_Ext))();
  337. #ifndef powerc
  338.     (void)SetA4(cura4);
  339. #endif
  340.     }
  341.  
  342. Boolean HasDoEventLoopOnce()
  343.     {
  344.     return(gacc.DoEventLoopOnce_Ext != NULL);
  345.     }
  346.  
  347. Handle GetTheClip()
  348.     {
  349.     ACCPtr    laccp = &gacc; /* must use a local pointer */
  350.     Handle    ret;
  351. #ifndef powerc
  352.     long cura4 = SetA4(_app_a4);
  353. #endif
  354.     if (laccp->GetAppClip_Ext != NULL)
  355.         ret = (*(laccp->GetAppClip_Ext))();
  356.     else
  357.         ret = NULL;
  358. #ifndef powerc
  359.     (void)SetA4(cura4);
  360. #endif
  361.     return(ret);
  362.     }
  363.  
  364. Boolean HasGetTheClip()
  365.     {
  366.     return(gacc.GetAppClip_Ext != NULL);
  367.     }
  368.  
  369. // Note for version 3 the version is signalled by long extendID == 'VER3'
  370. // inside gacc -- for previous versions, the odds of this long being set
  371. // to exactly 'VER3' are very small.
  372.  
  373. short PutTheClip(char *newClipStr)
  374.     {
  375.     ACCPtr    laccp = &gacc; /* must use a local pointer */
  376.     short    ret = 0;
  377. #ifndef powerc
  378.     long cura4 = SetA4(_app_a4);
  379. #endif
  380.     if (laccp->extendID == 'VER3' && laccp->PutAppClip_Ext != NULL)
  381.         ret = (*(laccp->PutAppClip_Ext))(newClipStr);
  382. #ifndef powerc
  383.     (void)SetA4(cura4);
  384. #endif
  385.     return(ret);
  386.     }
  387.  
  388. Boolean HasPutTheClip(void)
  389.     {
  390.     return(gacc.extendID == 'VER3' && gacc.PutAppClip_Ext != NULL);
  391.     }
  392.  
  393.