/* This file is part of the origami distrubution. (Amiga Port)
 *
 * Source code written by Thomas Hadig in September 1991
 * Version : 1.6.92.1, February 1994
 * (C) 1991-94 by Thomas Hadig
 * may be distributed unchanged ! (see copyright notes)
 */

/*{{{}}}*/
/*{{{  #includes*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <libraries/dos.h>
#include <fcntl.h>

#ifdef __SASC
#include <dos.h>
#include <proto/exec.h>
#include <proto/dos.h>
#else
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#endif

#define SHELL_C
#define I_PROMPT_C
#define I_GETTK_C

#include <origami/origami.h>
/*}}}  */
/*{{{  variables*/
public char const *shell_name;
public boolean secure= True,
               force_sh = False;
extern TOKEN buffer_keys[buffer_keys_max];
/*}}}  */

/*{{{  subshell*/
public int subshell (char const *const cmd)
 {
  BPTR f;
  int ret;
  char text[]="\n[Press any key to continue !]";

  if (cmd)
   /*{{{  execute shell command*/
   {
    /*{{{  handle shell command*/
    /*{{{  open window*/
    if (!(f=Open ("RAW:0/0/639/199/Origami Shell Command",MODE_OLDFILE)))
      return (system (cmd));
    /*}}}  */
    ret = Execute (cmd,0,f);
    /*{{{  get key and close window*/
    Write (f,text,strlen(text));
    if (!executing_macro) while (Read (f,text,1)!=1);
    Close(f);
    /*}}}  */
    if ((key_buffer_max==0)&&(!executing_macro))
     {
      buffer_keys[0]=O_RETURN;
      key_buffer_max=1;
     }
    return ret;
    /*}}}  */
   }
   /*}}}  */
  /*{{{  open new shell*/
  if (!shell_name) shell_name=getenv("SHELL");
  if ((shell_name)&&(*shell_name))
   {
    message ("Sub shell created");
    system (shell_name);
    return 0;
   }
  message ("Enviroment variable SHELL not set !");
  return 1;
  /*}}}  */
 }
/*}}}  */
#if 0
/*{{{  open_shell*/
public FILE *open_shell(const char * const prog,const char * const type)
 {
  return (FILE *)0;
 }
/*}}}  */
/*{{{  close_shell*/
public int close_shell(FILE *f)
 {
  return 0;
 }
/*}}}  */
#endif
