#ifndef RAWIN_H
#define RAWIN_H

/*	$Filename: RawIN.h $
**	$Release: 1.00 $
**	$Date: June 13, 1992 $
**	$Author: Sam Yee (samy@sfu.ca) $
**
**	Header file for RawIN.lib
**
**	Freely redistributable if this file is unmodified.
*/

#include <exec/types.h>
#include <dos/dosextens.h>
#include <dos/dos.h>

/*
*********************************************************************
** structures
*********************************************************************
*/

struct Line
{
    char	*buf,		/* buffer for command line */
		lastchar,	/* last input character */
		ansi,		/* any ansi input chars toggles ansi mode */
		csi,		/* last two chars are "<ESC>[" or 0x9b (Amiga) */
		pad;		/* alignment */
    ULONG	bufindex,	/* index into buf */
		buflen,		/* length of current command line */
		bufmax,		/* max length of buffer */
		hist_linesmax,	/* maximum number of history lines */
		hist_linecount,	/* as of right now, the number of lines */
		hist_lineindex;	/* current history line */
    struct History	*hist_head,	/* first history line */
			*hist_tail;	/* last history line */
};

/* history node */
struct History
{
    struct History	*last,	/* previous history line */
			*next;	/* next history line */
    char		*buf;	/* buffer of the history line */
    ULONG		buflen;	/* length of this history line */
};


/*
*********************************************************************
** protos
*********************************************************************
*/

/* set stdout to raw mode */
void
RawMode(long);				/* -1L == rawmode, 0L == cooked mode */

/* attemp to abort a read */
void
AbortRead(struct MsgPort *);		/* the message port is the same one you
					   supplied with StartAsyncRead */
/* should we exit program? */
char /* true if non-zero, else false */
ReadDone(struct StandardPacket *packet);

/* start the next raw read */
void
StartAsyncRead(struct StandardPacket *,	/* packet to send to input handler msgport */
	       struct MsgPort *,	/* this port will get a message if user
					   types a character. */
	       char *);			/* address to put in input character */

int			/* returns non-zero if user has pressed CR or LF */
BuildLine(BPTR,				/* file handle, eg. outfh = Output()
					   if 0 no output */
	  struct Line *,		/* line to build */
	  char,				/* character to put into line */
	  long);			/* # of characters for this command line,
					   if -1 use default. */
/*
** history functions
*/

void
MakeHistory(struct Line *,		/* line's history to add buffer */
	    char *,			/* buffer to add */
	    long);			/* length of buffer to add, if -1 use default */

struct History *	/* returns pointer to History, else NULL */
GetHistory(struct Line	*,		/* line to get history from */
	   long);			/* history line # */

void
ShowHistory(BPTR,		/* output file handler, if 0 no output */
	    struct Line *,
	    long,		/* start listing history lines from this location,
				   1 is the beginning, -1 is the end. */
	    long,		/* # of history lines to display, -1L == all */
	    char);		/* if non-zero then reverse order of output */

void
DeleteHistory(struct Line *,	/* line to delete history*/
	      long);		/* history # to delete, 1 is the first, -1 is the last*/

/*
** Line functions
*/

struct Line *		/* returns allocated Line structure, NULL == failure */
AllocLine(ULONG,			/* size of input buffer to allocate */
	  ULONG);			/* number of history lines */

void			/* de-allocate a Line structure */
FreeLine(struct Line *);

void			/* reset a Line (eg. initialize the indices, etc.) */
ResetLine(struct Line *);


/*
** synchronous input routine
*/

long /* -2L == nothing to read, -1L == ^C abort,
         0L == user only pressed return, else the # of chars read */
RawGets(char *,		/* buffer to store command line */
	ULONG,		/* length of buffer */
	ULONG,		/* default size of buffer to display */
	char,		/* hotkey if true, returns when a key is hit. */
	char,		/* CAPS if true */
	char);		/* quiet(no echo) if true */

#endif	/* RAWIN_H */
