#include <curspriv.h>
#include <stdlib.h>
char ttytype[128];
#define PDC_STR( x) #x
#define PDC_str( x) PDC_STR( x)
static const char *_curses_notice =
"PDCurses " PDC_str(PDC_VER_MAJOR) "."
PDC_str(PDC_VER_MINOR) "."
PDC_str(PDC_VER_CHANGE) " - Public Domain "
PDC_str(PDC_VER_YEAR) "-"
PDC_str(PDC_VER_MONTH) "-"
PDC_str(PDC_VER_DAY);
SCREEN *SP = (SCREEN*)NULL;
WINDOW *curscr = (WINDOW *)NULL;
WINDOW *stdscr = (WINDOW *)NULL;
WINDOW *pdc_lastscr = (WINDOW *)NULL;
int LINES = 0;
int COLS = 0;
int TABSIZE = 8;
MOUSE_STATUS Mouse_status, pdc_mouse_status;
extern RIPPEDOFFLINE linesripped[5];
extern char linesrippedoff;
WINDOW *Xinitscr(int argc, char *argv[])
{
int i;
PDC_LOG(("Xinitscr() - called\n"));
if (SP && SP->alive)
return NULL;
if (PDC_scr_open(argc, argv) == ERR)
{
fprintf(stderr, "initscr(): Unable to create SP\n");
exit(8);
}
SP->autocr = TRUE;
SP->raw_out = FALSE;
SP->raw_inp = FALSE;
SP->cbreak = TRUE;
SP->save_key_modifiers = FALSE;
SP->return_key_modifiers = FALSE;
SP->echo = TRUE;
SP->visibility = 1;
SP->resized = FALSE;
SP->_trap_mbe = 0L;
SP->_map_mbe_to_key = 0L;
SP->linesrippedoff = 0;
SP->linesrippedoffontop = 0;
SP->delaytenths = 0;
SP->line_color = -1;
SP->orig_cursor = PDC_get_cursor_mode();
LINES = SP->lines;
COLS = SP->cols;
if (LINES < 2 || COLS < 2)
{
fprintf(stderr, "initscr(): LINES=%d COLS=%d: too small.\n",
LINES, COLS);
exit(4);
}
if ((curscr = newwin(LINES, COLS, 0, 0)) == (WINDOW *)NULL)
{
fprintf(stderr, "initscr(): Unable to create curscr.\n");
exit(2);
}
if ((pdc_lastscr = newwin(LINES, COLS, 0, 0)) == (WINDOW *)NULL)
{
fprintf(stderr, "initscr(): Unable to create pdc_lastscr.\n");
exit(2);
}
wattrset(pdc_lastscr, (chtype)(-1));
werase(pdc_lastscr);
PDC_slk_initialize();
LINES -= SP->slklines;
for (i = 0; i < linesrippedoff; i++)
{
if (linesripped[i].line < 0)
(*linesripped[i].init)(newwin(1, COLS, LINES - 1, 0), COLS);
else
(*linesripped[i].init)(newwin(1, COLS,
SP->linesrippedoffontop++, 0), COLS);
SP->linesrippedoff++;
LINES--;
}
linesrippedoff = 0;
if (!(stdscr = newwin(LINES, COLS, SP->linesrippedoffontop, 0)))
{
fprintf(stderr, "initscr(): Unable to create stdscr.\n");
exit(1);
}
wclrtobot(stdscr);
if (SP->_preserve)
{
untouchwin(curscr);
untouchwin(stdscr);
stdscr->_clear = FALSE;
curscr->_clear = FALSE;
}
else
curscr->_clear = TRUE;
PDC_init_atrtab();
MOUSE_X_POS = MOUSE_Y_POS = -1;
BUTTON_STATUS(1) = BUTTON_RELEASED;
BUTTON_STATUS(2) = BUTTON_RELEASED;
BUTTON_STATUS(3) = BUTTON_RELEASED;
Mouse_status.changes = 0;
SP->alive = TRUE;
def_shell_mode();
longname( );
return stdscr;
}
WINDOW *initscr(void)
{
PDC_LOG(("initscr() - called\n"));
return Xinitscr(0, NULL);
}
int endwin(void)
{
PDC_LOG(("endwin() - called\n"));
def_prog_mode();
PDC_scr_close();
SP->alive = FALSE;
return OK;
}
bool isendwin(void)
{
PDC_LOG(("isendwin() - called\n"));
return SP ? !(SP->alive) : FALSE;
}
SCREEN *newterm(const char *type, FILE *outfd, FILE *infd)
{
PDC_LOG(("newterm() - called\n"));
return Xinitscr(0, NULL) ? SP : NULL;
}
SCREEN *set_term(SCREEN *new)
{
PDC_LOG(("set_term() - called\n"));
return (new == SP) ? SP : NULL;
}
void delscreen(SCREEN *sp)
{
PDC_LOG(("delscreen() - called\n"));
if (sp != SP)
return;
PDC_slk_free();
delwin(stdscr);
delwin(curscr);
delwin(pdc_lastscr);
stdscr = (WINDOW *)NULL;
curscr = (WINDOW *)NULL;
pdc_lastscr = (WINDOW *)NULL;
SP->alive = FALSE;
PDC_scr_free();
SP = (SCREEN *)NULL;
}
int resize_term(int nlines, int ncols)
{
PDC_LOG(("resize_term() - called: nlines %d\n", nlines));
if( PDC_resize_screen(nlines, ncols) == ERR)
return ERR;
if (!stdscr)
return OK;
SP->lines = PDC_get_rows();
LINES = SP->lines - SP->linesrippedoff - SP->slklines;
SP->cols = COLS = PDC_get_columns();
if (wresize(curscr, SP->lines, SP->cols) == ERR ||
wresize(stdscr, LINES, COLS) == ERR ||
wresize(pdc_lastscr, SP->lines, SP->cols) == ERR)
return ERR;
werase(pdc_lastscr);
curscr->_clear = TRUE;
if (SP->slk_winptr)
{
if (wresize(SP->slk_winptr, SP->slklines, COLS) == ERR)
return ERR;
wmove(SP->slk_winptr, 0, 0);
wclrtobot(SP->slk_winptr);
PDC_slk_initialize();
slk_noutrefresh();
}
touchwin(stdscr);
wnoutrefresh(stdscr);
return OK;
}
bool is_termresized(void)
{
PDC_LOG(("is_termresized() - called\n"));
return SP->resized;
}
const char *curses_version(void)
{
return _curses_notice;
}