home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / newc_dev / autores.lha / AutoRes.c < prev    next >
C/C++ Source or Header  |  1993-03-07  |  2KB  |  61 lines

  1. /* autores.c
  2.  *
  3.  *  autores, a small resident stub, you add it to the resident list, with
  4.  *  the name of the program you really want to be resident, and when it is
  5.  *  run first, it makes the real program resident, and then runs it..
  6.  *
  7.  */
  8.  
  9. #include <exec/types.h>
  10. #include <exec/execbase.h>
  11. #include <dos/dos.h>
  12. #include <dos/dosextens.h>
  13. #include <clib/dos_protos.h>
  14. #include <clib/exec_protos.h>
  15.  
  16. extern struct ExecBase *SysBase;
  17. extern void _exit(int);        /* don't know where the real prototype is */
  18.  
  19. int
  20. _main(arglen, argptr)
  21. int arglen;
  22. char *argptr;
  23. {
  24. char buf[35] = "C:";        /* only allows for 32 char filenames */
  25. char *name = buf+2;
  26. int rc = RETURN_FAIL;       /* default fail return */
  27.  
  28.     if( GetProgramName(name,30) ) {
  29.     BPTR L;
  30.  
  31.         if( L = Lock(buf,SHARED_LOCK) ) {
  32.         BPTR S;
  33.  
  34.             if( S = LoadSeg(buf) ) {
  35.                 /* is this a bug in dos.library? should be     *
  36.                  * passing 0 here according to the v37 AutoDocs*/
  37.                 if( AddSegment(name,S,1) ) {
  38.                 struct Segment *Seg;
  39.  
  40.                     Forbid();
  41.                     if( Seg = FindSegment(name,NULL,0) ) {
  42.                     /* I wouldn't have got past the Lock() if I was a Task */
  43.                     long stack = ((struct Process *)SysBase->ThisTask)->pr_StackSize;
  44.  
  45.                         Seg->seg_UC += 1;
  46.                         Permit();
  47.                         rc = RunCommand(Seg->seg_Seg,stack,argptr,arglen);
  48.                         Forbid();
  49.                         Seg->seg_UC -= 1;
  50.                     }
  51.                     Permit();
  52.                 } else
  53.                     UnLoadSeg(S);       /* only if AddSegment failed */
  54.             }
  55.             UnLock(L);
  56.         }
  57.     }
  58.  
  59.     _exit(rc);
  60. }
  61.