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

  1. /*-------------------------------------------------------------------------+
  2.  |                                       |
  3.  | Name:    lcmain.c                               |
  4.  | Purpose: C startup code replacement for Lattice               |
  5.  |                                       |
  6.  | Author:  RWA                    Date: 9/89           |
  7.  +-------------------------------------------------------------------------*/
  8.  
  9. #include "iolib.h"
  10. #include "ccfunc.h"
  11. #include <libraries/dosextens.h>
  12. #include <workbench/startup.h>
  13.  
  14. extern short _math;     /* this is in "math.c" */
  15. extern long blocksize;     /* this is in blocksize.c */
  16.  
  17. extern struct WBStartup *WBenchMsg;
  18. void (*exit_fcn)();
  19. void *CCLibBase;
  20. /* Resolve this reference from the library. */
  21. extern void *MathIeeeDoubBasBase;
  22. FILE *stdin, *stdout, *stderr;
  23. long errno, argc;
  24. char *type;
  25. static short _mathopen;
  26.  
  27. void _main(aptr)
  28. char *aptr;  /* A NULL terminated string is passed in Lattice */
  29. {
  30. extern void _exit();
  31. struct Task *FindTask();
  32. struct Library *OpenLibrary();
  33. struct Message *GetMsg();
  34. void WaitPort();
  35. register task_UserData *ud;
  36. register struct Process *ThisProcess;
  37. register long alen;
  38.  
  39. /*           WARNING
  40.  * This checks to make sure that the modified version of
  41.  * c.o (cc.o) is being used. This is for Lattice C only
  42.  * because the workbench is handled completly by CClib.library
  43.  * and the workbench handling code in c.o will crash the system
  44.  * if it is used. The problem will only occur if the program is
  45.  * executed from the workbench.
  46.  */
  47. if( WBenchMsg )
  48.    XCEXIT(100L);
  49.  
  50. /* Get the Workbench Message if this program is being executed
  51.  * from the workbench.
  52.  */
  53. ThisProcess = (struct Process *)FindTask(0L);
  54. if( !ThisProcess->pr_CLI )
  55.   {
  56.   WaitPort(&ThisProcess->pr_MsgPort);
  57.   WBenchMsg = (struct WBStartup *)GetMsg(&ThisProcess->pr_MsgPort);
  58.   }
  59.  
  60. /* __fpinit sould always be done AFTER the workbench message
  61.  * has been taken from the task's message port.
  62.  */
  63. __fpinit();
  64.  
  65.  
  66. /* Open the C library */
  67. if( !(CCLibBase = OpenLibrary(CCLIBNAME,0L)) )
  68.    goto abort;
  69.  
  70. /* Get the length of the argument string, this must be done after opening
  71.  * CClib.library or else the reference to strlen will be unresolved. */
  72. alen = strlen(aptr);
  73.  
  74. if( _math )  /* open up the Ieee math library */
  75.    {
  76.    if( !MathIeeeDoubBasBase )
  77.      /* May have been already done by Lattice, and
  78.       * usually is if you are using the supplied startup
  79.       * code.
  80.       */
  81.       {
  82.       if( !(MathIeeeDoubBasBase =
  83.      OpenLibrary("mathieeedoubbas.library",0L)) )
  84.       goto abort;
  85.       }
  86.    else
  87.       _mathopen = 1; /* Math library was opened by Lattice */
  88.    }
  89.  
  90.  
  91. /* Do some further initialization of the task specific structures.
  92.  * This will:
  93.  *
  94.  * 1) Initialize the task_UserData structure.
  95.  * 2) Parse the command line arguments or the Workbench message.
  96.  * 3) Open standard stream IO for the application.
  97.  * 4) Set up pointers to errno, and blocksize.
  98.  * 5) Give the library a pointer to the Ieee math library if opened above.
  99.  * 6) Set the standard abort function.
  100.  */
  101. if( !SetupSTDIO(&stdin,&stdout,&stderr,
  102.     &errno,&blocksize,&type,MathIeeeDoubBasBase,alen,aptr,WBenchMsg,_exit) )
  103.    goto abort;
  104.  
  105. /* get a pointer to this task's user data structure */
  106. ud = GetSTDIO();
  107.  
  108. /* application entry point */
  109. main(ud->_argc, ud->_argv);
  110.  
  111. abort:
  112. _exit(0L);
  113. }
  114.  
  115. void CloseLibrary();
  116.  
  117. void _exit(code)
  118. long code;
  119. {
  120. if( exit_fcn )
  121.    (*exit_fcn)();
  122.  
  123. if( MathIeeeDoubBasBase && (!_mathopen) )
  124.    CloseLibrary( MathIeeeDoubBasBase );
  125.  
  126. if( CCLibBase )
  127.    {
  128.    ClearSTDIO();
  129.    CloseLibrary(CCLibBase);
  130.    }
  131.  
  132. /* This jumps into the Lattice startup code. */
  133. XCEXIT(code);
  134. }
  135.  
  136. void exit(code)
  137. long code;
  138. {
  139. void _exit();
  140. _exit(code);
  141. }
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.