home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 530b.lha / AMenu_v1.3 / ArpC.c < prev    next >
C/C++ Source or Header  |  1991-07-03  |  3KB  |  83 lines

  1. ;/* Execute build for ArpC.c  (c.o replacement)
  2. lc -j73 -cst -v -ms -O ArpC
  3. quit
  4. /*********************************************************************\
  5. **                               ________________________________    **
  6. **    A n t h o n y             |________    __    __    ________|   **
  7. **                                       |  |o_|  |o_|  |            **
  8. **            T h y s s e n            __|   __    __   |__          **
  9. **                                  __|   __|  |  |  |__   |__       **
  10. **   `` Dragon Computing ! ''    __|   __|     |  |     |__   |__    **
  11. **                              |_____|        |__|        |_____|   **
  12. **                                                                   **
  13. \*********************************************************************/
  14. /*    This is a C startup routine for use in my own programs.
  15. **  The routine `_Startup_' must be the first code encountered and
  16. **  this module the first module linked using `blink' replacing
  17. **  the lattice supplied "c.o" startup code.
  18. **    The code will open the Arp library (setting its global base
  19. **  variables); parse any CLI arguments using the user supplied
  20. **  Templates and the Arp `GADS' library routine; and if WB startup
  21. **  read and return the WBStartup Message.
  22. **    See "ArpC.h" for the global variables defined here and
  23. **  which global variables the user MUST himself define.
  24. */
  25. #include "ArpC.h"
  26. #include <libraries/ArpBase.h>
  27. #include <proto/Exec.h>
  28.  
  29.  
  30. void __saveds __asm
  31. _Startup_ ( register __d0 int ArgLen, register __a0 char *ArgLine )
  32. /*   This routine MUST be the first memory used by the compiler.
  33. ** IE the first module linked and no global varibales defined
  34. ** before it (declaring externs is however ok).
  35. **    Note the `__saveds' is used to get the complier to set the A4
  36. **  Global Variable Register and `__asm' to read the CLI argument
  37. **  line handed to the program in registers D0 and A0.
  38. */
  39. {
  40.   if( ArpBase = (struct ArpBase *)OpenLibrary("arp.library", 39) ) {
  41.     IntuitionBase = (struct IntuitionBase *) ArpBase->IntuiBase;
  42.     GfxBase       = (struct GfxBase *)       ArpBase->GfxBase;
  43.   }
  44.   WBMsg = (struct WBStartup *)NULL;
  45.   Process = (struct Process *)FindTask(NULL);
  46.   if( Process->pr_CLI ) {
  47.     int argc;
  48.     if( !ArpBase )   Exit(100);
  49.     argc = GADS( ArgLine, ArgLen, CLI_Help, (char **)CLI_Args, CLI_Template );
  50.     if( argc < 0 )  exit(20);
  51.     main( argc, CLI_Args );
  52.   }
  53.   else {  /* Workbench startup */
  54.     WaitPort(&Process->pr_MsgPort);
  55.     WBMsg = (struct WBstart *)GetMsg(&Process->pr_MsgPort);
  56.     if( !ArpBase )   exit(100);
  57.     main( 0, (char **)WBMsg );
  58.   }
  59.   exit( 0 );
  60. }
  61.  
  62.  
  63. void
  64. exit( int retcode )
  65. {
  66.   if (ArpBase)                  /* this will close all arp stuff too */
  67.     CloseLibrary((struct Library *)ArpBase);
  68.   if( WBMsg ) {
  69.     Forbid();
  70.     ReplyMsg((struct Message *)WBMsg);
  71.   }
  72.   Exit(retcode);
  73. }
  74.  
  75.  
  76. /* HERE provide the global variables defined in this module */
  77. struct ArpBase       *ArpBase;
  78. struct IntuitionBase *IntuitionBase;
  79. struct GfxBase       *GfxBase;
  80. struct Process       *Process;  /* this process */
  81. struct WBStartup     *WBMsg;    /* WBStartup message (NULL if CLI start) */
  82.  
  83.