home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / newlibs / cclib.lzh / _main.c next >
C/C++ Source or Header  |  1989-09-25  |  3KB  |  119 lines

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