home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / Emulatory / AROS / c / run.c < prev    next >
Encoding:
C/C++ Source or Header  |  1978-03-06  |  2.0 KB  |  99 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: run.c,v 1.6 1996/10/24 15:32:26 aros Exp $
  4.     $Log: run.c,v $
  5.     Revision 1.6  1996/10/24 15:32:26  aros
  6.     Fixed some warnings about int/ptr conversions
  7.  
  8.     Revision 1.5  1996/09/17 16:43:01  digulla
  9.     Use general startup code
  10.  
  11.     Revision 1.4  1996/09/13 17:52:11  digulla
  12.     Use IPTR
  13.  
  14.     Revision 1.3  1996/08/01 17:40:45  digulla
  15.     Added standard header for all files
  16.  
  17.     Desc:
  18.     Lang:
  19. */
  20. #include <exec/memory.h>
  21. #include <clib/exec_protos.h>
  22. #include <dos/dosextens.h>
  23. #include <dos/dostags.h>
  24. #include <clib/dos_protos.h>
  25. #include <utility/tagitem.h>
  26.  
  27. int main (int argc, char ** argv)
  28. {
  29.     STRPTR args[1]={ 0 };
  30.     struct RDArgs *rda;
  31.     BPTR in, out, shell;
  32.     STRPTR s1, s2, buf;
  33.     struct Process *process;
  34.     ULONG num;
  35.     LONG error=0;
  36.  
  37.     rda=ReadArgs("COMMAND/A/F",(IPTR *)args,NULL);
  38.     if(rda!=NULL)
  39.     {
  40.     error=RETURN_ERROR;
  41.     s1=s2=(STRPTR)args[0];
  42.     while(*s2++)
  43.         ;
  44.     buf=(STRPTR)AllocVec(8+s2-s1,MEMF_ANY);
  45.     if(buf!=NULL)
  46.     {
  47.         CopyMem("COMMAND ",buf,8);
  48.         CopyMem(s1,buf+8,s2-s1);
  49.         shell=LoadSeg("c:shell");
  50.         if(shell)
  51.         {
  52.         in=Open("CONSOLE:",MODE_OLDFILE);
  53.         if(in)
  54.         {
  55.             out=Open("CONSOLE:",MODE_NEWFILE);
  56.             if(out)
  57.             {
  58.             struct TagItem tags[]=
  59.             {
  60.                 { NP_Name, (IPTR)"Background task" },
  61.                 { NP_Arguments, 0 },
  62.                 { NP_Input, 0 },
  63.                 { NP_Output, 0 },
  64.                 { NP_Error, 0 },
  65.                 { NP_Seglist, 0 },
  66.                 { NP_Cli, 1 },
  67.                 { TAG_END, 0 }
  68.             };
  69.             tags[1].ti_Data=(IPTR)buf;
  70.             tags[2].ti_Data=(IPTR)in;
  71.             tags[3].ti_Data=(IPTR)out;
  72.             tags[5].ti_Data=(IPTR)shell;
  73.             Forbid();
  74.             process=CreateNewProc(tags);
  75.             if(process!=NULL)
  76.             {
  77.                 num=process->pr_TaskNum;
  78.                 out=in=shell=0;
  79.                 error=0;
  80.             }
  81.             Permit();
  82.             Close(out);
  83.             if(process&&VPrintf("[CLI %ld]\n",&num)<0)
  84.                error=RETURN_ERROR;
  85.             }
  86.             Close(in);
  87.         }
  88.         UnLoadSeg(shell);
  89.         }
  90.         FreeVec(buf);
  91.     }
  92.     FreeArgs(rda);
  93.     }else
  94.     error=RETURN_FAIL;
  95.     if(error)
  96.     PrintFault(IoErr(),"Run");
  97.     return error;
  98. }
  99.