home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / dirs / cclib_399.lzh / CCLib / Source / _main.c next >
C/C++ Source or Header  |  1990-11-02  |  2KB  |  113 lines

  1. #define ANSIC 1
  2. #include "iolib.h"
  3. #include "ccfunc.h"
  4. #include <libraries/dosextens.h>
  5. #include <workbench/startup.h>
  6. #include <functions.h>
  7.  
  8. long _savsp, _stkbase;
  9.  
  10. extern short _math;     /* this is in "math.c" */
  11. extern long blocksize;     /* this is in blocksize.c */
  12.  
  13. struct WBStartup *WBenchMsg;
  14. void *_oldtrap, **_trapaddr;
  15. void (*exit_fcn)();
  16. void *MathIeeeDoubBasBase, *CCLibBase, *SysBase, *DOSBase, *MathBase;
  17. FILE *stdin, *stdout, *stderr;
  18. long errno;
  19. char *type;
  20.  
  21. void _main(long alen, char *aptr)
  22. {
  23. register task_UserData *ud;
  24. register struct Process *ThisProcess;
  25. void main(long,char **);
  26.  
  27. /* This stuff is needed for the Aztec C compiler */
  28. _stkbase = _savsp - *((long *)_savsp+1) + 8;
  29. *(long *)_stkbase = 0x4d414e58L;
  30.  
  31. ThisProcess = (struct Process *)FindTask(NULL);
  32.  
  33. /* Get the Workbench Message if this program is being executed
  34.  * from the workbench. */
  35. if( !ThisProcess->pr_CLI )
  36.    {
  37.    WaitPort((struct MsgPort *)&ThisProcess->pr_MsgPort);
  38.    WBenchMsg = (struct WBStartup *)
  39.            GetMsg((struct MsgPort *)&ThisProcess->pr_MsgPort);
  40.    }
  41.  
  42. /* Open the C library */
  43. if( !(CCLibBase = OpenLibrary(CCLIBNAME,0L)) )
  44.    goto abort;
  45.  
  46. if( _math )  /* open up the Ieee math library */
  47.    if( !(MathIeeeDoubBasBase = OpenLibrary("mathieeedoubbas.library",0L)) )
  48.       goto abort;
  49.  
  50. /* Do some further initialization of the task specific structures.
  51.  * This will:
  52.  *
  53.  * 1) Initialize the task_UserData structure.
  54.  * 2) Parse the command line arguments or the Workbench message.
  55.  * 3) Open standard stream IO for the application.
  56.  * 4) Set up pointers to errno, and blocksize.
  57.  * 5) Give the library a pointer to the Ieee math library if opened above.
  58.  * 6) Set the standard abort function.
  59.  */
  60. if( !SetupSTDIO(&stdin,&stdout,&stderr,
  61.     &errno,&blocksize,&type,MathIeeeDoubBasBase,alen,aptr,WBenchMsg,_exit) )
  62.    goto abort;
  63.  
  64. /* get a pointer to this task's user data structure */
  65. ud = GetSTDIO();
  66.  
  67. /* application entry point */
  68. main((long)ud->_argc, ud->_argv);
  69.  
  70. abort:
  71. _exit(0L);
  72. }
  73.  
  74.  
  75. void _exit( long code )
  76. {
  77. long rv = code;
  78. if( exit_fcn )
  79.    (*exit_fcn)();
  80. if( _trapaddr ) /* clean up signal handling */
  81.    *_trapaddr = _oldtrap;
  82.  
  83. if( MathIeeeDoubBasBase )
  84.    CloseLibrary( MathIeeeDoubBasBase );
  85.  
  86. if( CCLibBase )
  87.    {
  88.    ClearSTDIO();
  89.    CloseLibrary(CCLibBase);
  90.    }
  91.  
  92. /* This stuff is needed for the Aztec C compiler */
  93.    {
  94. #asm
  95.    move.l  -4(a5),d0
  96.    move.l  __savsp#,sp
  97.    rts
  98. #endasm
  99.    }
  100. }
  101.  
  102. void exit( long code )
  103. {
  104. void _exit();
  105. _exit(code);
  106. }
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.