/* > c.screen Ed Doppenberg 28-4-90 < */
#include <string.h>
#include "window.h"
#include "parse.h"

#define  EQUAL    0
#define  ESC      '\33'
#define  CTL(c)   (c - 0x40)
#define  HELP_KEY 0x6200
#define  UNDO_KEY 0x6100
#define  NORM_MODE 1
#define  HELP_MODE 2

extern int aspect, align, graph_flag;
extern int rep_macro[17], i_macro;
extern short gamma, Con_Perc;
extern char _argbreak, *wi_title;


/* flushfile : flushes an inputfile */

static void
flushfile(FILE *f)
{
 while (getc(f)!=EOF);
}

/* interact : this is the main procedure that makes things happen. When called
  and if a character-key is pressed it is returned, otherwise the
  cursor continues to blink, or when you want real gem-interaction
  the procedure takes care of execution of the commands */

void interact(char *s, FILE *fp, int mode, VENSTER **w, int *x, int *y)

/* mode = 0 means normal interact.
   mode = 1 means return in x and y the coordinates of an
     indicated point (by means of the mouse).
     w may be used to indicate a window, or may point
     to a NULL pointer, in which case the window is
     reported back in that.
   mode = 2 is same as one, but don't wait for button release.
*/
{

#define SPEED 300

int  i,speed;
char  c;
int  ready, macro, menucom;
static int all_quit = FALSE;
wimp_eventstr *evnt;

menucom = ready = FALSE;
i = 0;
if(mode == 1 || mode == 2)
  {
   printw("Mode 1 and 2 not yet implemented\n");
   *s='\0';
  }
if (fp == stdin)
 {
   speed=SPEED;
   macro = FALSE;
   all_quit = FALSE;
 }
else
 {
   speed=0;
   macro = TRUE;
   ready = TRUE;
   if (all_quit)
     {
      rep_macro[i_macro] = FALSE;
      flushfile(fp);
      *s = '\0';
     }
   else getline (s,fp);
 }
do
{
  if (!macro && !mode)
   {
    _argbreak = c; /* save last character for escape sequence */
    s=poll_loop(s,0,evnt);
    ready = TRUE;
   }

 if (!macro && (mode == 1 || mode == 2))
   {
    printw("MAcro=false and mode!=0 Not yet implemented\n");
    ready=TRUE;
   }

} while (!ready);

if (mode == 0)
  {
/* Dpg
   if ((macro)
     {
      printw(s);
      wvdu('\n');
     }
*/
   strcpy(s,stpblk(s));
  }
}
