/**************************************************************************/
/*                                                                        */
/*                                 Sources                                */
/*                                from  the                               */
/*                           XSC SOFTWARE PACKAGE                         */
/*                                                                        */
/*                Copyright (c) 1997 University of Karlsruhe              */
/*                     Institute for Appl. Mathematics                    */
/*                                                                        */
/* This program is free software for non-commercial use. For details, see */
/* the file LICENSE.XSC, distributed with this software package.          */
/*                                                                        */
/* This program is distributed WITHOUT ANY WARRANTY. For details, see the */
/* file LICENSE.XSC, distributed with this software package.              */
/*                                                                        */
/**************************************************************************/

/* RCS $Id: a_syst.c,v 1.2 1997/09/25 16:53:46 ae59 Exp $ */
/*
$Log: a_syst.c,v $
 * Revision 1.2  1997/09/25  16:53:46  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:20:50  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : a_syst.c                              */
/*                                                              */
/*      Entries         : a_intg a_syst(s)                      */
/*                        s_trng s;                             */
/*                                                              */
/*      Arguments       : command string                        */
/*                                                              */
/*      Description     : execute command in command string     */
/*                                                              */
/*      Date            : 1991-08-28                            */
/*      1991-08-28 : special call to routine which returns      */
/*                   correct return call in case of IBM_AT_MS_C */
/*      1991-02-13 : copy string if substring                   */
/*      1991-01-22 : initialization of n removed                */
/*      1991-01-10 : free temporary variable before E_TPOPP()   */
/*      1990-11-15 : E_TPUSH+E_TPOPP                            */
/****************************************************************/

#ifndef ALL_IN_ONE
#ifdef AIX
#include "/u/p88c/runtime/o_defs.h"
#else
#include "o_defs.h"
#endif
#define local
extern dotprecision b_cm__;
#endif

/*------------------------------------------------------*/
/*  msc_system : system call that gives the correct     */
/*               return value of the given command.     */
/*------------------------------------------------------*/

#if IBM_AT_MS_C

#include <process.h>

static int msc_system (const char *s)

        {
        char *par[10];
        int   i = 0;
        char *p = (char *)b_cm__;

        (void)strcpy(p,s);

        while (*p==' ') p++;                    /* skip leading blanks */
        while (*p!='\0')
           {
           par[i++] = p;
           while (*p!=' ' && *p!='\0') p++;     /* search next blank */
           if (*p==' ')
              {
              *p = '\0';                        /* store null char */
              p++;
              while (*p==' ') p++;              /* skip leading blanks */
              }
           }
        par [i] = NULL ;

        return  spawnvp (P_WAIT, par[0],par ) ;
        }
#endif



#ifdef LINT_ARGS
local a_intg a_syst(s_trng s)
#else
local a_intg a_syst(s)

s_trng s;
#endif
        {
        a_intg n;

        E_TPUSH("a_syst")

        if (s.clen>0)
           {
           if (s.suba) s_asgn(&s,s);
           s.ptr[s.clen] = '\0';
#if IBM_AT_MS_C
           n = msc_system(s.ptr);
#else
           n = system(s.ptr);
#endif
           }
        else
#if IBM_AT_MS_C
           n = msc_system(NULL);
#else
           n = system(NULL);
#endif

        if (s.tmp) s_free(&s);

        E_TPOPP("a_syst")
        return(n);
        }



