#ifndef SUNUNIX 
#ifndef EMBEDDED_RDBMS
#define WINDOWS
#endif
#else
typedef int HWND,HINSTANCE,HDC,HANDLE ,LONG;
typedef unsigned int UINT;
#define PASCAL 
#define BOOL int 
#define FAR 
#endif
typedef struct history
{
 char *data;
 struct history *next;
 struct history *prev;
}HISTORY;
//-------------------------
typedef struct
  {
   long prev;
   long next;
   long datasize;  //current msg size
   char *dataptr;    //msg buffer
   short int EnqTaskPriority;
   unsigned char  reserved1[2];
   long reserved2;
   long EnqTaskId;
  } TUWA_CIRCULAR_Q_INFO;

typedef struct _circular_queue_
{
  long qID;
  long CreatorTaskId;
  long CreatorTaskPriority;
  long Qhead;
  long Qtail;
  long ElementSize;
  long QElementCount;
  long Qcapacity;
  long Handle;
  HWND hwndOutput;
  char *showbuffer;
  char *dequeuebuf;
  char displaywindowpresent;
  int CharHeight;
  char isqlPrompt[32];
  void (*shellcmdexecutor)(char *buf);
  HISTORY *historyhead;
  HISTORY *historytail;
  HISTORY *historyptr;
  int historycount;
  int ShellMode;
  int outputlinebegin;
  int displaylinecount;
  int linestodraw;
  int copysize;
  int offset;
  int setsize;
  int availablefilelines;
  int displaycharcount;

#ifndef SUNUNIX
  POINTS point;
  WINDOWPLACEMENT wpl;
  PAINTSTRUCT ps;
  TEXTMETRIC tm;
  HDC hdc;
  RECT rect;
  RECT linerect;
  HBRUSH hbrush;
  UINT oldalign;
  HFONT hfont;
  HFONT oldfont;
  LOGFONT cur_font;
#endif  
  int width;
  int height ;
  int slot;
  char buf[30];
  WORD x1;
  WORD y1;
  WORD x2;
  WORD y2;
  char trackbegin;
  char carethidden;
  int line1;
  int col1;
  int line2;
  int col2;
  int curpos;
  //static POINT point;
  int cursor_was_on_non_edit_line;
  long h;
    
  int CharWidth;
  int targetline,line,EditCharHeight,OutputLeftCharPtr;
  char *ptr;
  int createmsg;
  int LineCursor;
  int count; 
  int datalen;
  char signonmsg;


  char *shellcmdbuf;
  int curlen;
  int allwidth[256];
  int LeftCharPtr;
  int qcount;
  int curposclick;

  TUWA_CIRCULAR_Q_INFO *Qbuffer;
  char EnqMutex;
  char DeqMutex;
  char QaccessMutex;
  long highlight_element_from;
  long highlight_element_to;
} TUWA_CIRCULAR_QUEUE;
TUWA_CIRCULAR_QUEUE *GetQueuePtr(HWND);
TUWA_CIRCULAR_QUEUE *GetQueuePtrById(long id);

#define TUWA_CIRC_Q_SIZE 1
long ClearQueueHighLights(long qid);
long SetQueueHighLights(long qid,long from,long to);
long WithinQueueHighLights(long qid,long element);

int  FlushCircularQueue(long OuputQueID);
long EnQueueCircularQ(long qid ,char *buffer,long size);
long DeQueueCircularQ(long qid,char *buffer,long size);
char *LockEnQueueBuffer(long qid);
char *LockDeQueueBuffer(long qid);
long UnLockEnQueueBuffer(long qid);
long UnLockDeQueueBuffer(long qid);
long GetQcapacity(long qid);
long GetQelementSize(long qid);
void InitCircularQ();
long CreateCircularQ(long elementsize,long qcapacity);
long DeleteCircularQ(long Qid);
long QEmpty(long qid);
long QFull(long qid);
long GetQElementCount(long qid);
long GetQElementDataSize(long qid,long elementno);
long SetQElementDataSize(long qid,long elementno,long datacount);
char *GetQElementData(long qid,long elementno);

#ifdef WINDOWS
#define MAX_SHOW_BUFFER 65536
#define WM_APPEND_OUTPUT   1000
#define WM_SHOW_OUTPUT     1001
long CreateOutputWindow(HWND hwnd);
long CloseOutputWindow(void);
long CreateOutputWindowDeskTop(void);

extern "C" int PrintOutput(char *msg);

#else
long CreateOutputWindow(int qcount);
long CloseOutputWindow(void);
long DeleteOutputWindow(void);
#define MSG_START    0x01
#define MSG_STOP     0x02
#define MSG_SHOW     0x03
#define MSG_PAGEUP   0x04
#define MSG_PAGEDOWN 0x05
#define MSG_LINEUP   0x06
#define MSG_LINEDOWN 0x07
#endif
int SendOutput(TUWA_CIRCULAR_QUEUE *q,char *msg);
void InsertHistory(TUWA_CIRCULAR_QUEUE *q,char *buf);
void DeleteHistory(TUWA_CIRCULAR_QUEUE *q);
void NextHistory(TUWA_CIRCULAR_QUEUE *q,char *buf);
void PrevHistory(TUWA_CIRCULAR_QUEUE *q,char *buf);
int GetPromptSize(TUWA_CIRCULAR_QUEUE *q);
int  ShowPrompt(TUWA_CIRCULAR_QUEUE *q);
void ShellPrompt(TUWA_CIRCULAR_QUEUE *q);
INT_PTR CALLBACK proc_Output(HWND hwnd, //win handle
			   UINT message, //win message
			   WPARAM wParam, //win word param
			   LPARAM lParam);//win long param



