
/*
 *  HANDLER.H
 */

#include <exec/types.h>
#include <exec/nodes.h>
#include <exec/ports.h>
#include <exec/interrupts.h>
#include <exec/memory.h>
#include <exec/alerts.h>
#include <dos/dos.h>
#include <dos/dosextens.h>
#include <dos/filehandler.h>
#include <clib/dos_protos.h>
#include <clib/exec_protos.h>
#include <clib/alib_protos.h>

#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <lib/requestfh.h>

#define Prototype extern

#define DOS_TRUE    -1
#define DOS_FALSE   0

#define CB_SIZE     1024	/*  lines buffer */

#define BTOC(bptr)  ((void *)((long)(bptr) << 2))
#define CTOB(cptr)  ((BPTR)(((long)cptr) >> 2))

typedef struct DosPacket    DosPacket;
typedef struct FileHandle   FileHandle;
typedef struct DeviceNode   DeviceNode;
typedef struct Process	    Process;
typedef struct MinNode	    Node;
typedef struct MinList	    List;
typedef struct Node	    MaxNode;
typedef struct List	    MaxList;
typedef struct MsgPort	    MsgPort;
typedef struct Message	    Message;
typedef struct Interrupt    Interrupt;
typedef struct DosList	    DosList;
typedef struct RootNode     RootNode;
typedef struct DosInfo	    DosInfo;

typedef struct SharRead {
    void	*sr_FifoR;
    long	sr_Refs;
} SharRead;

typedef struct FHan {
    MaxNode	ff_Node;    /*	fifo node   */
    short	ff_Flags;
    short	ff_Refs;    /*	open refs   */
    SharRead	*ff_SRead;  /*	fifo handle for reading */
    void	*ff_FifoW;  /*	fifo handle for writing */
    long	ff_FBufSiz; /*	FifoW buffer size	*/
    Message	ff_RdMsg;
    Message	ff_WrMsg;
    MsgPort	*ff_Port;   /*	unique port for messages    */
    List	ff_RdWait;
    List	ff_WrWait;
    char	*ff_CookBuf;/*	cooked buffer handling	    */
    short	ff_CookIdx;
    short	ff_LRet;
    void	*ff_Task;
} FHan;

#define ff_FifoR    ff_SRead->sr_FifoR

#define FHF_COOKED	0x0001
#define FHF_RPEND	0x0002
#define FHF_WAVAIL	0x0004
#define FHF_READ	0x0008
#define FHF_WRITE	0x0010
#define FHF_CLOSEEOF	0x0020
#define FHF_MASTER	0x0040
#define FHF_TEE 	0x0080
#define FHF_SHELL	0x0100
#define FHF_COOKBFUL	0x0200	    /*	cooked buffer is full	*/
#define FHF_COOKECHOBLK 0x0400	    /*	blocked echoing chars!	*/
#define FHF_REOF	0x0800	    /*	REMOTE EOF		*/
#define FHF_WIHOLD	0x1000	    /*	write hold due to input */
#define FHF_COOKCRLF	0x2000	    /*	need to write CRLF	*/
#define FHF_RREQUIRED	0x4000

#include "fifohan-protos.h"

