home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / programm / programi / ixemupd_.lzh / ixemupd-920129 / stdlib / system.c < prev   
Encoding:
C/C++ Source or Header  |  1992-01-18  |  3.4 KB  |  126 lines

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *
  5.  *  This library is free software; you can redistribute it and/or
  6.  *  modify it under the terms of the GNU Library General Public
  7.  *  License as published by the Free Software Foundation; either
  8.  *  version 2 of the License, or (at your option) any later version.
  9.  *
  10.  *  This library is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  *  Library General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU Library General Public
  16.  *  License along with this library; if not, write to the Free
  17.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #define KERNEL
  21. #include "ixemul.h"
  22.  
  23. #include <ctype.h>
  24.  
  25. #define NO_PROTOTYPES
  26. #include <libraries/arpbase.h>  /* HAS! to be V39 or higher! */
  27. #undef NO_PROTOTYPES
  28.  
  29. #define BASE_EXT_DECL
  30. #define BASE_PAR_DECL    
  31. #define BASE_PAR_DECL0    
  32. #define BASE_NAME    ix.ix_arp_base
  33. #include <inline/arp.h>
  34.  
  35. /* 2.0 support */
  36. #include "gcc:include20/utility/tagitem.h"
  37. #include "gcc:include20/dos/dostags.h"
  38. #define BASE_EXT_DECL
  39. #define BASE_PAR_DECL    
  40. #define BASE_PAR_DECL0    
  41. #define BASE_NAME    ix.ix_dos_base
  42. __inline static LONG SystemTagList(BASE_PAR_DECL UBYTE* command, struct TagItem* tags)
  43. {
  44.     BASE_EXT_DECL
  45.     register LONG res __asm("d0");
  46.     register void *a6 __asm ("a6");
  47.     register UBYTE* d1 __asm("d1");
  48.     register struct TagItem* d2 __asm("d2");
  49.  
  50.     a6 = BASE_NAME;
  51.     d1 = command;
  52.     d2 = tags;
  53.     __asm volatile ("
  54.     jsr a6@(-0x25e)"
  55.     : "=r" (res)
  56.     : "r" (a6), "r" (d1), "r" (d2)
  57.     : "d0", "d1", "a0", "a1", "d2");
  58.     return res;
  59. }
  60.  
  61.  
  62. extern int _dos20;
  63. #define alloca __builtin_alloca
  64.  
  65. int
  66. system (const char *cmd)
  67. {
  68.   int rc, err = 0;
  69.   int stack_size;
  70.   struct CommandLineInterface *CLI;
  71.   struct Process *me;
  72.   int omask;
  73.  
  74.   /* I retry with our new signal mechanism ;-) */
  75.   omask = syscall (SYS_sigsetmask, ~0);
  76.  
  77.   me = (struct Process *)FindTask(0);
  78.   CLI = BTOCPTR (me->pr_CLI);
  79.   stack_size = CLI ? CLI->cli_DefaultStack * 4 : me->pr_StackSize;
  80.   if (stack_size <= 4096) stack_size = 250000;
  81.  
  82.   /* limited support to allow starting of files in the current directory
  83.    * with `./foo'. The better approach would use the __plock() trick to
  84.    * parse the command, LoadSeg it. But then this approach would have to
  85.    * do the whole redirection stuff on its own.. */
  86.   while (isspace (*cmd)) cmd++;
  87.   while (cmd[0] == '.' && cmd[1] == '/') cmd += 2;
  88.  
  89.   /* before OS2.0, use ARP functions */
  90.   if (! _dos20)
  91.     {
  92.       struct NewShell *nsh; /* only available starting with Arp1.3 !! */
  93.  
  94.       nsh = alloca (sizeof (*nsh));
  95.       bzero (nsh, sizeof (*nsh));
  96.       
  97.       /* use same stacksize as parent process */
  98.       nsh->nsh_StackSize = stack_size;
  99.       nsh->nsh_Control = EXECUTE_ME;  /* BACKGROUND | EXECUTE */
  100.         
  101.       /* rc should be 0 if the generated pid was >= 0 */
  102.       rc = ASyncRun ((UBYTE *)cmd, 0L, nsh) < 0;
  103.       err = __ioerr_to_errno (IoErr ());
  104.     }
  105.   else
  106.     {
  107.       struct TagItem tags [] = {
  108.     /* a stack of 4K is generally ways too small.. */
  109.     { NP_StackSize, stack_size, },
  110.     { TAG_END, 0, }
  111.       };
  112.  
  113.       rc = SystemTagList ((UBYTE *)cmd, tags);
  114.       err = __ioerr_to_errno (IoErr ());
  115.     }
  116.  
  117.   syscall (SYS_sigsetmask, omask);
  118.  
  119.   if (rc > 128)
  120.     errno = EINTR;
  121.   else 
  122.     errno = err;
  123.  
  124.   return rc;
  125. }
  126.