home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnuc / stdlib / rcs / system.c,v < prev   
Encoding:
Text File  |  1992-08-09  |  5.4 KB  |  217 lines

  1. head    1.2;
  2. access;
  3. symbols
  4.     version39-41:1.1;
  5. locks;
  6. comment    @ * @;
  7.  
  8.  
  9. 1.2
  10. date    92.08.09.21.07.26;    author amiga;    state Exp;
  11. branches;
  12. next    1.1;
  13.  
  14. 1.1
  15. date    92.06.08.17.01.06;    author mwild;    state Exp;
  16. branches;
  17. next    ;
  18.  
  19.  
  20. desc
  21. @initial checkin
  22. @
  23.  
  24.  
  25. 1.2
  26. log
  27. @change to 2.x header files
  28. @
  29. text
  30. @/*
  31.  *  This file is part of ixemul.library for the Amiga.
  32.  *  Copyright (C) 1991, 1992  Markus M. Wild
  33.  *
  34.  *  This library is free software; you can redistribute it and/or
  35.  *  modify it under the terms of the GNU Library General Public
  36.  *  License as published by the Free Software Foundation; either
  37.  *  version 2 of the License, or (at your option) any later version.
  38.  *
  39.  *  This library is distributed in the hope that it will be useful,
  40.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  41.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  42.  *  Library General Public License for more details.
  43.  *
  44.  *  You should have received a copy of the GNU Library General Public
  45.  *  License along with this library; if not, write to the Free
  46.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  47.  */
  48.  
  49. #define KERNEL
  50. #include "ixemul.h"
  51. #include <sys/wait.h>
  52. #include <ctype.h>
  53.  
  54. /* 2.0 support */
  55. #include <utility/tagitem.h>
  56. #include <dos/dostags.h>
  57.  
  58. struct    NewShell    {
  59.             ULONG    nsh_StackSize;    /* stacksize shell will use for children    */
  60.             BYTE    nsh_Pri;    /* ignored by interactive shells        */
  61.             UBYTE    nsh_Control;    /* bits/values: see above            */
  62.             CPTR    nsh_LogMsg;    /* Optional login message, if null, use default    */
  63.             BPTR    nsh_Input;    /* ignored by interactive shells, but        */
  64.             BPTR    nsh_Output;    /* used by background and execute options.    */
  65.             LONG    nsh_RESERVED[5];
  66.             };
  67.  
  68. #define    PRB_CLI        0L    /* Do a CLI, not a shell    */
  69. #define    PRB_BACKGROUND    1L    /* Background shell        */
  70. #define    PRB_EXECUTE    2L    /* Do as EXECUTE...        */
  71. #define    PRB_INTERACTIVE    3L    /* Run an interactive shell    */
  72. #define    PRB_FB        7L    /* Alt function bit...        */
  73.  
  74. #define    PRF_CLI        (1L << PRB_CLI)
  75. #define    PRF_BACKGROUND    (1L << PRB_BACKGROUND)
  76. #define    PRF_EXECUTE    (1L << PRB_EXECUTE)
  77. #define    PRF_INTERACTIVE    (1L << PRB_INTERACTIVE)
  78. #define    PRF_FB        (1L << PRB_FB)
  79.  
  80. #define    EXECUTE_ME        (PRF_FB|PRF_BACKGROUND|PRF_EXECUTE)    /* aptly named, doncha think?    */
  81.  
  82.  
  83. #define BASE_EXT_DECL
  84. #define BASE_PAR_DECL    
  85. #define BASE_PAR_DECL0    
  86. #define BASE_NAME    ix.ix_arp_base
  87. __inline static LONG ASyncRun(BASE_PAR_DECL const char* name, const char* command, struct NewShell* pcb)
  88. {
  89.     BASE_EXT_DECL
  90.     register LONG res __asm("d0");
  91.     register void *a6 __asm ("a6");
  92.     register const char* a0 __asm("a0");
  93.     register const char* a1 __asm("a1");
  94.     register struct NewShell* a2 __asm("a2");
  95.  
  96.     a6 = BASE_NAME;
  97.     a0 = name;
  98.     a1 = command;
  99.     a2 = pcb;
  100.     __asm volatile ("
  101.     jsr a6@@(-0x222)"
  102.     : "=r" (res)
  103.     : "r" (a6), "r" (a0), "r" (a1), "r" (a2)
  104.     : "d0", "d1", "a0", "a1", "a2", "memory");
  105.     return res;
  106. }
  107.  
  108.  
  109. extern int _dos20;
  110. #define alloca __builtin_alloca
  111.  
  112. int
  113. system (const char *cmd)
  114. {
  115.   int rc = -1, err = 0;
  116.   int stack_size;
  117.   struct CommandLineInterface *CLI;
  118.   struct Process *me;
  119.   int omask;
  120.  
  121.   /* I retry with our new signal mechanism ;-) */
  122.   omask = syscall (SYS_sigsetmask, ~0);
  123.  
  124.   me = (struct Process *)FindTask(0);
  125.   CLI = BTOCPTR (me->pr_CLI);
  126.   stack_size = CLI ? CLI->cli_DefaultStack * 4 : me->pr_StackSize;
  127.   if (stack_size <= 4096) stack_size = 250000;
  128.  
  129.   /* limited support to allow starting of files in the current directory
  130.    * with `./foo'. The better approach would use the __plock() trick to
  131.    * parse the command, LoadSeg it. But then this approach would have to
  132.    * do the whole redirection stuff on its own.. */
  133.   while (isspace (*cmd)) cmd++;
  134.   while (cmd[0] == '.' && cmd[1] == '/') cmd += 2;
  135.  
  136.   /* before OS2.0, use ARP functions */
  137.   if (! _dos20)
  138.     {
  139.       struct NewShell *nsh; /* only available starting with Arp1.3 !! */
  140.  
  141.       nsh = alloca (sizeof (*nsh));
  142.       bzero (nsh, sizeof (*nsh));
  143.       
  144.       /* use same stacksize as parent process */
  145.       nsh->nsh_StackSize = stack_size;
  146.       nsh->nsh_Control = EXECUTE_ME;  /* BACKGROUND | EXECUTE */
  147.         
  148.       /* rc should be 0 if the generated pid was >= 0 */
  149.       rc = ASyncRun ((UBYTE *)cmd, 0L, nsh) < 0;
  150.       err = __ioerr_to_errno (IoErr ());
  151.     }
  152.   else
  153.     {
  154.       struct TagItem tags [] = {
  155.     /* a stack of 4K is generally ways too small.. */
  156.     { NP_StackSize, stack_size, },
  157.     { TAG_END, 0, }
  158.       };
  159.  
  160.       rc = SystemTagList ((UBYTE *)cmd, tags);
  161.       err = __ioerr_to_errno (IoErr ());
  162.     }
  163.  
  164.   syscall (SYS_sigsetmask, omask);
  165.  
  166.   if (rc > 128)
  167.     errno = EINTR;
  168.   else 
  169.     errno = err;
  170.  
  171.   /* according to the BSD manual, system() should return the `exit status'
  172.    * of the shell, the implementation returns the wait-status. So I return
  173.    * an artificial wait status for now ... */
  174.   return (rc >= 128) ? W_EXITCODE (0, rc & 0x7f) : W_EXITCODE (rc, 0);
  175. }
  176. @
  177.  
  178.  
  179. 1.1
  180. log
  181. @Initial revision
  182. @
  183. text
  184. @d25 28
  185. a52 3
  186. #define NO_PROTOTYPES
  187. #include <libraries/arpbase.h>  /* HAS! to be V39 or higher! */
  188. #undef NO_PROTOTYPES
  189. d58 1
  190. a58 10
  191. #include <inline/arp.h>
  192.  
  193. /* 2.0 support */
  194. #include "gcc:include20/utility/tagitem.h"
  195. #include "gcc:include20/dos/dostags.h"
  196. #define BASE_EXT_DECL
  197. #define BASE_PAR_DECL    
  198. #define BASE_PAR_DECL0    
  199. #define BASE_NAME    ix.ix_dos_base
  200. __inline static LONG SystemTagList(BASE_PAR_DECL UBYTE* command, struct TagItem* tags)
  201. d63 3
  202. a65 2
  203.     register UBYTE* d1 __asm("d1");
  204.     register struct TagItem* d2 __asm("d2");
  205. d68 3
  206. a70 2
  207.     d1 = command;
  208.     d2 = tags;
  209. d72 1
  210. a72 1
  211.     jsr a6@@(-0x25e)"
  212. d74 2
  213. a75 2
  214.     : "r" (a6), "r" (d1), "r" (d2)
  215.     : "d0", "d1", "a0", "a1", "d2");
  216. @
  217.