/*
** vbcc-PowerOpen/WarpOS version of system.c
**
** v0.2 03.12.98 phx
**      Implemented a real system() call.
** v0.1 06.03.98 phx
**      copied from SVR4 libvc.a, which also does nothing at the moment
*/

#include <exec/libraries.h>
#include <utility/TagItem.h>
#include <powerpc/powerpc.h>
#include <clib/powerpc_protos.h>
#include <proto/dos.h>


int system(const char *string)
{
  struct PPCArgs pa;

  if (!string)
    return (1);

  pa.PP_Code = (APTR)DOSBase;
  pa.PP_Flags = pa.PP_StackSize = 0;
  pa.PP_Stack = NULL;
  pa.PP_Regs[PPREG_D1] = (ULONG)string;
  pa.PP_Regs[PPREG_A6] = (ULONG)DOSBase;
  if (((struct Library *)DOSBase)->lib_Version >= 36) {
    static struct TagItem systemlist[] = { { TAG_END } };
    pa.PP_Offset = -606;  /* _LVOSystemTagList */
    pa.PP_Regs[PPREG_D2] = (ULONG)systemlist;
  }
  else {
    pa.PP_Offset = -222;  /* _LVOExecute */
    pa.PP_Regs[PPREG_D2] = pa.PP_Regs[PPREG_D3] = 0;
  }
  Run68K(&pa);
  return((int)pa.PP_Regs[PPREG_D0]);
}
