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

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: newshell.c,v 1.5 1996/10/24 15:32:25 aros Exp $
  4.     $Log: newshell.c,v $
  5.     Revision 1.5  1996/10/24 15:32:25  aros
  6.     Fixed some warnings about int/ptr conversions
  7.  
  8.     Revision 1.4  1996/09/17 16:43:01  digulla
  9.     Use general startup code
  10.  
  11.     Revision 1.3  1996/09/13 17:52:11  digulla
  12.     Use IPTR
  13.  
  14.     Revision 1.2  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[2]={ "CON:", "S:Shell-Startup" };
  30.     struct RDArgs *rda;
  31.     BPTR lock, in, out, shell;
  32.     STRPTR s1, s2, s3, buf;
  33.     struct Process *process;
  34.     LONG error=RETURN_ERROR;
  35.  
  36.     rda=ReadArgs("WINDOW,FROM",(IPTR *)args,NULL);
  37.     if(rda!=NULL)
  38.     {
  39.     s1=s2=(STRPTR)args[1];
  40.     while(*s2++)
  41.         ;
  42.     buf=(STRPTR)AllocVec(6+2*(s2-s1),MEMF_ANY);
  43.     if(buf!=NULL)
  44.     {
  45.         CopyMem("FROM ",buf,5);
  46.         s3=buf+5;
  47.         s2=s1;
  48.         *s3++='\"';
  49.         while(*s1)
  50.         {
  51.         if(*s1=='*'||*s1=='\"'||*s1=='\n')
  52.             *s3++='*';
  53.         if(*s1=='\n')
  54.             *s3++='n';
  55.         else
  56.             *s3++=*s1;
  57.         s1++;
  58.         }
  59.         *s3++='\"';
  60.         *s3=0;
  61.  
  62.         shell=LoadSeg("c:shell");
  63.         if(shell)
  64.         {
  65.         out=Open(args[0],MODE_READWRITE);
  66.         if(out)
  67.         {
  68.             /* Clone output filehandle */
  69.             lock=DupLockFromFH(out);
  70.             if(lock)
  71.             {
  72.             in=OpenFromLock(lock);
  73.             if(!in)
  74.                 UnLock(lock);
  75.             }else
  76.             in=0;
  77.             if(in)
  78.             {
  79.             struct TagItem tags[]=
  80.             {
  81.                 { NP_Arguments, 0 },
  82.                 { NP_Input, 0 },
  83.                 { NP_Output, 0 },
  84.                 { NP_Error, 0 },
  85.                 { NP_Seglist, 0 },
  86.                 { NP_Cli, 1 },
  87.                 { TAG_END, 0 }
  88.             };
  89.             tags[0].ti_Data=(IPTR)buf;
  90.             tags[1].ti_Data=(IPTR)in;
  91.             tags[2].ti_Data=(IPTR)out;
  92.             tags[4].ti_Data=(IPTR)shell;
  93.             process=CreateNewProc(tags);
  94.             if(process!=NULL)
  95.             {
  96.                 out=in=shell=0;
  97.                 error=0;
  98.             }
  99.             Close(in);
  100.             }
  101.             Close(out);
  102.         }
  103.         UnLoadSeg(shell);
  104.         }
  105.         FreeVec(buf);
  106.     }
  107.     FreeArgs(rda);
  108.     }else
  109.     error=RETURN_FAIL;
  110.     if(error)
  111.     PrintFault(IoErr(),"NewShell");
  112.     return error;
  113. }
  114.