
/*
 * RUN.C
 *
 * (c)1986 Matthew Dillon     9 October 1986
 *
 *    RUN   handles running of external commands.
 *
 * version 2.05M (Manx Version and Additions) by Steve Drew 20-Jan-87
 *
 */

#include "shell.h"

char *FindIt();

do_run(str)
char *str;
{
   int i, try = -1;
   int run = 0;
   char buf[128];
   char runcmd[128];
   char *save, *path;


   if (path = FindIt(av[0],"",buf)) {   
      if (!strcmp(av[0],"run")) {
         if (FindIt(av[1],"",runcmd)) {
            run =        myprocess = (struct Process *) FindTask(NULL);      
        replyport = (struct MsgPort *) CreatePort(NULL,NULL);
        if(!replyport) exit(10);
        packet = (struct StandardPacket *) 
            AllocMem((long)sizeof(*packet),MEMF_PUBLIC | MEMF_CLEAR);
        conid = (struct MsgPort *) myprocess->pr_ConsoleTask; /* get console handler */
        printf("\23312{");
        set_var (LEVEL_SET, "_insert", "1");
    }
}

void
cleanupconsole()
{

    if (IsInteractive(Input())) {
       FreeMem(packet,(long)sizeof(*packet)); 
       DeletePort(replyport); 
    }
}

void 
setraw(onoff)
int onoff; 
{
 
 packet->sp_Msg.mn_Node.ln_Name = (char *) &(packet->sp_Pkt); /* link packet- */
 packet->sp_Pkt.dp_Link         = &(packet->sp_Msg);        /* to message    */
 packet->sp_Pkt.dp_Port         = replyport;         /* set-up reply port   */
 packet->sp_Pkt.dp_Type = ACTION_SCREEN_MODE;        /* function */

 if (onoff) { 
     packet->sp_Pkt.dp_Arg1 = Dsprefix = 1;
   }
   
   if (!hasprefix) {
   	Myprocess->pr_WindowPtr = (APTR)(-1);
   	s = get_var(LEVEL_SET, V_PATH);
   }

   strcpy(buf, cmd);
   strcat(buf, ext);
   while ((lock = (long)Lock(buf, ACCESS_READ)) == 0) {
      if (*s == NULL || hasprefix) break;
      for(ptr = s; *s && *s != ','; s++) ;
      strcpy(buf, ptr);
      buf[s-ptr] = '\0';
      strcat(buf, cmd);
      strcat(buf, ext);
      if (*s) s++;
   }
   Myprocess->pr_WindowPtr = original;
   if (lock) {
      UnLock(lock);
      return(buf);
   }
   return(NULL);
}


