#ifndef VMS_CURSES_H
#define VMS_CURSES_H
/*
 * VT-based curses replacement for OpenVMS 9.x
 * Uses raw VT/ANSI escape sequences for output and SYS$QIOW for input.
 * All functions prefixed vc_ to avoid DECC$ name prefix collisions.
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>

typedef unsigned int chtype;

#define A_NORMAL   0x0000
#define A_BOLD     0x0100
#define A_REVERSE  0x0400
#define A_BLINK    0x0800
#define A_STANDOUT A_BOLD
#define A_DIM      A_BOLD

#define KEY_UP     0x101
#define KEY_DOWN   0x102
#define KEY_LEFT   0x103
#define KEY_RIGHT  0x104
#define KEY_PPAGE  0x105
#define KEY_NPAGE  0x106
#define KEY_ENTER  0x107

#define OK   0
#define ERR  (-1)
#ifndef TRUE
#define TRUE  1
#define FALSE 0
#endif

#define COLOR_BLACK   0
#define COLOR_RED     1
#define COLOR_GREEN   2
#define COLOR_YELLOW  3
#define COLOR_BLUE    4
#define COLOR_MAGENTA 5
#define COLOR_CYAN    6
#define COLOR_WHITE   7
#define COLOR_PAIR(n) 0
#define has_colors()  0
#define start_color() ((void)0)
#define use_default_colors() ((void)0)
#define init_pair(n, f, b) ((void)0)

#define VWF_SCROLL  0x01

typedef struct vc_window {
    int maxy, maxx;
    int begy, begx;
    int cury, curx;
    int attr;
    int flags;
    chtype *cells;
    int *dirty;
} WINDOW;

extern WINDOW *stdscr;
extern int LINES, COLS;

/* Implementation functions (vc_ prefix avoids DECC$ name collisions) */
WINDOW *vc_initscr(void);
int vc_endwin(void);
WINDOW *vc_newwin(int h, int w, int y, int x);
int vc_delwin(WINDOW *w);
int vc_wmove(WINDOW *w, int y, int x);
int vc_waddch(WINDOW *w, chtype ch);
int vc_waddstr(WINDOW *w, const char *s);
int vc_wprintw(WINDOW *w, const char *fmt, ...);
int vc_mvwprintw(WINDOW *w, int y, int x, const char *fmt, ...);
int vc_wrefresh(WINDOW *w);
int vc_werase(WINDOW *w);
int vc_wclear(WINDOW *w);
int vc_wgetch(WINDOW *w);
int vc_touchwin(WINDOW *w);
int vc_box(WINDOW *w, chtype vert, chtype horiz);
int vc_wgetnstr(WINDOW *w, char *buf, int n);
void vc_mark_refresh(WINDOW *w);
void vc_do_update(void);

/* Map standard curses names to our vc_ functions */
#define initscr()         vc_initscr()
#define endwin()          vc_endwin()
#define newwin(h,w,y,x)   vc_newwin((h),(w),(y),(x))
#define delwin(w)         vc_delwin(w)
#define wmove(w,y,x)      vc_wmove((w),(y),(x))
#define waddch(w,ch)      vc_waddch((w),(ch))
#define waddstr(w,s)      vc_waddstr((w),(s))
#define wprintw           vc_wprintw
#define mvwprintw         vc_mvwprintw
#define wrefresh(w)       vc_wrefresh(w)
#define werase(w)         vc_werase(w)
#define wclear(w)         vc_wclear(w)
#define wgetch(w)         vc_wgetch(w)
#define touchwin(w)       vc_touchwin(w)
#define box(w,v,h)        vc_box((w),(v),(h))
#define wgetnstr(w,b,n)   vc_wgetnstr((w),(b),(n))

#define scrollok(w, bf)   ((bf) ? ((w)->flags |= VWF_SCROLL) : ((w)->flags &= ~VWF_SCROLL))
#define keypad(w, bf)     ((void)0)
#define curs_set(v)       ((void)0)
#define cbreak()          ((void)0)
#define noecho()          ((void)0)
#define nonl()            ((void)0)
#define echo()            ((void)0)
#define nodelay(w, bf)    ((void)0)

#define mvwaddch(w, y, x, ch)   (vc_wmove((w),(y),(x)) == ERR ? ERR : vc_waddch((w),(ch)))
#define mvwaddstr(w, y, x, s)   (vc_wmove((w),(y),(x)) == ERR ? ERR : vc_waddstr((w),(s)))
#define mvprintw(y, x, ...)     (vc_wmove(stdscr,(y),(x)) == ERR ? ERR : vc_wprintw(stdscr, __VA_ARGS__))
#define mvaddstr(y, x, s)       mvwaddstr(stdscr,(y),(x),(s))
#define addstr(s)               vc_waddstr(stdscr,(s))
#define addch(ch)               vc_waddch(stdscr,(ch))
#define move(y, x)              vc_wmove(stdscr,(y),(x))
#define clear()                 vc_wclear(stdscr)
#define erase()                 vc_werase(stdscr)
#define refresh()               vc_wrefresh(stdscr)
#define getch()                 vc_wgetch(stdscr)
#define printw(...)             vc_wprintw(stdscr, __VA_ARGS__)
#define wnoutrefresh(w)         vc_mark_refresh(w)
#define doupdate()              vc_do_update()
#define getmaxyx(w, y, x)      ((y) = (w)->maxy, (x) = (w)->maxx)
#define wresize(w, h, ww)      (OK)

#define attron(a)               (stdscr->attr |= (a))
#define attroff(a)              (stdscr->attr &= ~(a))
#define wattron(w, a)           ((w)->attr |= (a))
#define wattroff(w, a)          ((w)->attr &= ~(a))

#endif
