home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / programm / programi / ixemupd_.lzh / ixemupd-920129 / lib / crt0.c next >
Encoding:
C/C++ Source or Header  |  1992-01-26  |  2.9 KB  |  136 lines

  1. #include <exec/types.h>
  2. #include <exec/libraries.h>
  3. #include <exec/execbase.h>
  4. #include <inline/exec.h>
  5. #include <libraries/dosextens.h>
  6.  
  7. #include <sys/syscall.h>
  8.  
  9. /* get the current revision number. Version control is automatically done by
  10.  * OpenLibrary(), I just have to check the revision number 
  11.  */
  12. #include "/library/version.h"
  13.  
  14. struct Library *ixemulbase;
  15.  
  16. static int start_stdio();
  17.  
  18. /*
  19.  * Have to take care.. I may not use any library functions in this file,
  20.  * since they are exactly then used, when the library itself couldn't be
  21.  * opened...
  22.  */
  23. static char *build_warn (char *t1, int num1, char *t2, int num2);
  24.  
  25. extern int main();
  26. extern int expand_cmd_line;
  27. extern char *default_wb_window;
  28. extern int errno;
  29. extern char *_ctype_;
  30. extern int sys_nerr;
  31.  
  32. int
  33. ENTRY()
  34. {
  35.   register unsigned char *rega0  asm("a0");
  36.   register unsigned long  regd0  asm("d0");
  37.  
  38.   UBYTE *aline = rega0;
  39.   ULONG alen = regd0;
  40.  
  41.   int res = 20;
  42.   
  43.   ixemulbase = OpenLibrary ("ixemul.library", 37);
  44.   if (ixemulbase)
  45.     {
  46.       /* just warn, in case the user tries to run program with might require
  47.        * more functions than are currently available under this revision. */
  48.       if (ixemulbase->lib_Revision < IX_REVISION)
  49.     {
  50.       /* I wish I had stdio in the library... */
  51.       __panic_msg ("ixemul.library warning: current revision ",
  52.                  ixemulbase->lib_Revision,
  53.                  ", needed revision ",
  54.                  IX_REVISION);
  55.     }
  56.  
  57.       res = ix_startup (aline, alen, 
  58.                 expand_cmd_line, default_wb_window, start_stdio, &errno);
  59.  
  60.       CloseLibrary (ixemulbase);
  61.     }
  62.   else
  63.     {
  64.       struct Process *me = (struct Process *)((*(struct ExecBase **)4)->ThisTask);
  65.  
  66.       __panic_msg ("Need at least version ", IX_VERSION, " of ixemul.library.", 0);
  67.       
  68.       /* quickly deal with the WB startup message, as the library couldn't do
  69.        * this for us. Nothing at all is done that isn't necessary to just shutup
  70.        * workbench..*/
  71.       if (! me->pr_CLI)
  72.         {
  73.       Forbid (); 
  74.       ReplyMsg ((WaitPort (& me->pr_MsgPort), GetMsg (& me->pr_MsgPort)));
  75.     }
  76.       
  77.       res = 20;
  78.     }
  79.  
  80.   return res;
  81. }
  82.  
  83. int
  84. start_stdio(int a1, int a2)
  85. {
  86.   int res;
  87.  
  88.   /* more to follow ;-) */
  89.   ix_get_vars (&_ctype_, &sys_nerr);
  90.  
  91.   _init_stdio();
  92.  
  93.   res = main (a1, a2);
  94.   return res;
  95. }
  96.  
  97. /* this thing is best done with sprintf else, but I don't want to include
  98.  * the stdio package per default... 
  99.  */
  100. static char *
  101. itoa (int num)
  102. {
  103.   short snum = num;
  104.  
  105.   /* how large can a long get...?? */
  106.   static char buf[16];
  107.   char *cp;
  108.   
  109.   buf[15] = 0;
  110.   for (cp = &buf[15]; snum; snum /= 10) 
  111.     *--cp = (snum % 10) + '0';
  112.  
  113.   return cp;
  114. }
  115.  
  116. static char *
  117. pstrcpy (char *start, char *arg)
  118. {
  119.   while (*start++=*arg++) ;
  120.   return start-1;
  121. }
  122.  
  123. static char *
  124. build_warn (char *t1, int num1, char *t2, int num2)
  125. {
  126.   char buf[255], *cp;
  127.   
  128.   cp = pstrcpy (buf, t1);
  129.   cp = pstrcpy (cp, itoa (num1));
  130.   cp = pstrcpy (cp, t2);
  131.   if (num2)
  132.     pstrcpy (cp, itoa (num2));
  133.  
  134.   return buf;
  135. }
  136.