/* NAME     : CUP
 * VERSION  : 1.0
 * DATE     : 15.9.1992
 * AUTHOR   : Ulrich Diedrichsen
 * SHORT    : Convert Unix Pathnames and Call Prog with Amigapathnames
 * NOTE     : Only ONE the first argument improved (SAS ONLY)
 * COMPILE  : lc -L cup
 * COMPILER : SAS 5.10a
*/

#define ENVVAR "UNIXPROG"       /* Name of Enviormentvariable */
#define DEFAULTPROG "MuchMore"  /* Called if Enviormentvariable unset */

#include <stdlib.h>
#include <string.h>

#include <exec/types.h>
#include <exec/execbase.h>
#include <intuition/intuitionbase.h>
#include <intuition/screens.h>

#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/intuition_protos.h>

#include <pragmas/exec_pragmas.h>
#include <pragmas/dos_pragmas.h>
#include <pragmas/intuition_pragmas.h>

extern struct ExecBase *SysBase;
extern struct Library *DOSBase;

void _main(char *arg)
{
 register char *ptr;
 register char *str;
 char commandbuf[256];
 if (arg[strlen(arg)-1] == '\n')
  arg[strlen(arg)-1] = '\0';
 ptr=strchr(arg+1, '\"');
 if (ptr!=NULL) {
  ptr += 2;
  if (*ptr!='\0') {
   if (*ptr=='/') *ptr=':';
   str=strchr(ptr,'/');
   if (str && (*str=='/')) {
    *str=':';
    if (*ptr==':') *ptr=' ';
   }
   if (str=getenv(ENVVAR)) strcpy(commandbuf,str);
   else strcpy(commandbuf,DEFAULTPROG);
   strcat(commandbuf," ");
   strcat(commandbuf,ptr);
   Execute(commandbuf,NULL,NULL);
  }
 }
 _exit(RETURN_OK);
}
