Initial cursesd

This commit is contained in:
jl777
2019-02-17 00:46:28 -11:00
parent e225c54012
commit e3ccd36f0b
10 changed files with 465 additions and 139 deletions

View File

@@ -2,7 +2,7 @@
cd rogue;
./configure # only need this first time
make; cd ..
gcc -Wno-write-strings -DBUILD_ROGUE -std=c++11 -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -o librogue.so -c cclib.cpp -lncurses
gcc -Wno-write-strings -DBUILD_ROGUE -std=c++11 -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -o librogue.so -c cclib.cpp
#gcc -std=c++11 -fPIC -shared -o librogue.so cclib.o rogue/rogue.so
cp librogue.so ../libcc.so

View File

@@ -17,13 +17,268 @@
static int32_t endwinflag;
WINDOW *newwin(int32_t nlines,int32_t ncols,int32_t begin_y,int32_t begin_x)
{
WINDOW *scr = 0;
if ( nlines == LINES && ncols == COLS && begin_y == 0 && begin_x == 0 )
scr = (WINDOW *)calloc(1,sizeof(*stdscr));
return(scr);
}
WINDOW *initscr()
{
if ( stdscr == 0 )
stdscr = (WINDOW *)calloc(1,sizeof(*stdscr));
stdscr = newwin(LINES,COLS,0,0);
return(stdscr);
}
int32_t delwin(WINDOW *win)
{
free(win);
return(0);
}
int32_t wmove(WINDOW *win, int32_t y, int32_t x)
{
win->y = y;
win->x = x;
return(0);
}
int32_t move(int32_t y, int32_t x)
{
return(wmove(stdscr,y,x));
}
int werase(WINDOW *win)
{
memset(win->screen,' ',sizeof(win->screen));
return(0);
}
int wclear(WINDOW *win)
{
werase(win);
clearok(win,TRUE);
return(0);
}
int wclrtoeol(WINDOW *win)
{
if ( win->x < COLS-1 )
memset(&win->screen[win->y][win->x],' ',COLS - win->x);
return(0);
}
int wclrtobot(WINDOW *win)
{
wclrtoeol(win);
if ( win->y < LINES-1 )
memset(&win->screen[win->y+1][0],' ',COLS);
return(0);
}
int erase(void)
{
return(werase(stdscr));
}
int clear(void)
{
return(wclear(stdscr));
}
int clrtobot(void)
{
return(wclrtobot(stdscr));
}
int clrtoeol(void)
{
return(wclrtoeol(stdscr));
}
int32_t waddch(WINDOW *win, chtype ch)
{
int32_t t;
if ( ch == '\t' )
{
for (i=0; i<8; i++)
{
if ( win->x >= COLS-1 )
break;
win->x++;
if ( (win->x & 7) == 0 )
break;
}
}
else if ( ch == '\n' )
{
wclrtoeol(win);
win->x = 0;
win->y++;
if ( win->y >= LINES )
win->y = 0;
}
else if ( ch == '\b' )
{
if ( win->x > 0 )
win->x--;
}
else
{
win->screen[win->y][win->x++] = ch;
if ( win->x >= COLS )
{
win->x = 0;
win->y++;
if ( win->y >= LINES )
win->y = 0;
}
}
reurn(0);
}
int32_t mvwaddch(WINDOW *win, int32_t y, int32_t x, chtype ch)
{
win->y = y;
win->x = x;
return(waddch(win,ch));
}
int32_t addch(chtype ch)
{
return(waddch(stdscr,ch));
}
int32_t mvaddch(int32_t y, int32_t x, chtype ch)
{
return(mvwaddch(stdscr,y,x,ch));
}
int32_t waddstr(WINDOW *win, const char *str)
{
int32_t i;
for (i=0; str[i]!=0; i++)
waddch(win,str[i]);
return(0);
}
int32_t waddnstr(WINDOW *win, const char *str, int32_t n)
{
int32_t i;
for (i=0; str[i]!=0 && i<n; i++)
waddch(win,str[i]);
return(0);
}
int32_t mvwaddstr(WINDOW *win, int32_t y, int32_t x, const char *str)
{
win->y = y;
win->x = x;
return(waddstr(win,str));
}
int32_t mvwaddnstr(WINDOW *win, int32_t y, int32_t x, const char *str, int32_t n)
{
win->y = y;
win->x = x;
return(waddnstr(win,str));
}
int32_t addstr(const char *str)
{
return(waddstr(stdscr,str));
}
int32_t addnstr(const char *str, int32_t n)
{
return(waddnstr(stdscr,str,n));
}
int32_t mvaddstr(int32_t y, int32_t x, const char *str)
{
stdscr->y = y;
stdscr->x = x;
return(waddstr(stdscr,str));
}
int32_t mvaddnstr(int32_t y, int32_t x, const char *str, int32_t n)
{
stdscr->y = y;
stdscr->x = x;
return(waddnstr(stdscr,str,n));
}
int32_t printw(char *fmt,...)
{
char str[512]; int32_t ret; va_list myargs; // Declare a va_list type variable
va_start(myargs,fmt); // Initialise the va_list variable with the ... after fmt
ret = vsprintf(str,fmt,myargs); // Forward the '...' to vsprintf
va_end(myargs); // Clean up the va_list
return(addstr(str));
}
int32_t wprintw(WINDOW *win,char *fmt,...)
{
char str[512]; int32_t ret; va_list myargs; // Declare a va_list type variable
va_start(myargs,fmt); // Initialise the va_list variable with the ... after fmt
ret = vsprintf(str,fmt,myargs); // Forward the '...' to vsprintf
va_end(myargs); // Clean up the va_list
return(waddstr(win,str));
}
int32_t mvprintw(int32_t y,int32_t x,char *fmt,...)
{
char str[512]; int32_t ret; va_list myargs; // Declare a va_list type variable
va_start(myargs,fmt); // Initialise the va_list variable with the ... after fmt
ret = vsprintf(str,fmt,myargs); // Forward the '...' to vsprintf
va_end(myargs); // Clean up the va_list
stdscr->y = y;
stdscr->x = x;
return(addstr(str));
}
int32_t mvwprintw(WINDOW *win,int32_t y,int32_t x,char *fmt,...)
{
char str[512]; int32_t ret; va_list myargs; // Declare a va_list type variable
va_start(myargs,fmt); // Initialise the va_list variable with the ... after fmt
ret = vsprintf(str,fmt,myargs); // Forward the '...' to vsprintf
va_end(myargs); // Clean up the va_list
win->y = y;
win->x = x;
return(waddstr(win,str));
}
chtype winch(WINDOW *win)
{
return(win->screen[win->y][win->x]);
}
chtype inch(void)
{
return(winch(stdscr));
}
chtype mvwinch(WINDOW *win, int32_t y, int32_t x)
{
win->y = y;
win->x = x;
return(win->screen[win->y][win->x]);
}
chtype mvinch(int32_t y, int32_t x)
{
return(mvwinch(stdscr,y,x));
}
int32_t mvcur(int32_t oldrow, int32_t oldcol, int32_t newrow, int32_t newcol)
{
stdscr->y = newrow;
stdscr->x = newcol;
return(0);
}
void endwin()
{
if ( stdscr != 0 )
@@ -36,27 +291,12 @@ int isendwin(void)
return(endwinflag);
}
int wrefresh(WINDOW *win)
{
return(0);
}
int refresh(void)
{
endwinflag = 0;
return(wrefresh(stdscr));
}
int wnoutrefresh(WINDOW *win)
{
return(0);
}
int doupdate(void)
{
return(0);
}
int redrawwin(WINDOW *win)
{
return(wrefresh(win));
@@ -67,42 +307,101 @@ int wredrawln(WINDOW *win, int beg_line, int num_lines)
return(wrefresh(win));
}
int werase(WINDOW *win)
// functions with no data side effect
#ifdef they_are_macros
int wrefresh(WINDOW *win)
{
return(0);
}
int erase(void)
int wnoutrefresh(WINDOW *win)
{
return(werase(stdscr));
return(0);
}
int wclear(WINDOW *win)
int doupdate(void)
{
return(0);
}
int clear(void)
int32_t touchwin(WINDOW *win)
{
return(wclear(stdscr));
return(0);
}
int wclrtobot(WINDOW *win)
int standout(void)
{
return(0);
}
int clrtobot(void)
int standend(void)
{
return(wclrtobot(stdscr));
return(0);
}
int wclrtoeol(WINDOW *win)
int raw(void)
{
return(0);
}
int clrtoeol(void)
int32_t keypad(WINDOW *win, bool bf)
{
return(wclrtoeol(stdscr));
return(0);
}
int noecho(void)
{
return(0);
}
int flushinp(void)
{
return(0);
}
int clearok(WINDOW *win, bool bf)
{
return(0);
}
int idlok(WINDOW *win, bool bf)
{
return(0);
}
int leaveok(WINDOW *win, bool bf)
{
return(0);
}
#endif
int32_t mvwin(WINDOW *win, int32_t y, int32_t x); // stub
{
fprintf(stderr,"unexpected call to mvwin\n");
return(0);
}
WINDOW *subwin(WINDOW *orig, int nlines, int ncols, int begin_y, int begin_x)
{
fprintf(stderr,"unexpected and unsupported call to subwin\n");
return(0);
}
char erasechar(void)
{
fprintf(stderr,"unexpected and unsupported call to erasechar\n");
return(8);
}
char killchar(void)
{
fprintf(stderr,"unexpected and unsupported call to erasechar\n");
return(3);
}
int32_t mvgetnstr(int32_t y, int32_t x, char *str, int32_t n) // stub
{
fprintf(stderr,"unexpected and unsupported call to mvgetnstr\n");
return(0);
}

View File

@@ -36,38 +36,107 @@
#include <sys/stat.h>
#include <errno.h>
#ifdef notyet
struct cursesd_info
{
uint8_t screen[LINES][COLS];
int32_t x,y;
} *stdscr;
typedef struct cursesd_info WINDOW;
typedef char chtype;
WINDOW *initscr(void);
int endwin(void);
int isendwin(void);
int32_t endwin(void);
int32_t isendwin(void);
//SCREEN *newterm(const char *type, FILE *outfd, FILE *infd);
//SCREEN *set_term(SCREEN *new);
//void delscreen(SCREEN* sp);
int refresh(void);
int wrefresh(WINDOW *win);
//int wnoutrefresh(WINDOW *win);
//int doupdate(void);
int redrawwin(WINDOW *win);
int wredrawln(WINDOW *win, int beg_line, int num_lines);
int32_t refresh(void);
int32_t wrefresh(WINDOW *win);
//int32_t wnoutrefresh(WINDOW *win);
//int32_t doupdate(void);
int32_t redrawwin(WINDOW *win);
int32_t wredrawln(WINDOW *win, int32_t beg_line, int32_t num_lines);
int erase(void);
int werase(WINDOW *win);
int clear(void);
int wclear(WINDOW *win);
int clrtobot(void);
int wclrtobot(WINDOW *win);
int clrtoeol(void);
int wclrtoeol(WINDOW *win);
int32_t erase(void);
int32_t werase(WINDOW *win);
int32_t clear(void);
int32_t wclear(WINDOW *win);
int32_t clrtobot(void);
int32_t wclrtobot(WINDOW *win);
int32_t clrtoeol(void);
int32_t wclrtoeol(WINDOW *win);
#endif
int32_t standout(void);
int32_t standend(void);
int32_t raw(void);
int32_t noecho(void);
int32_t flushinp(void);
int32_t keypad(WINDOW *win, bool bf);
int32_t clearok(WINDOW *win, bool bf);
int32_t idlok(WINDOW *win, bool bf);
int32_t leaveok(WINDOW *win, bool bf);
WINDOW *newwin(int32_t nlines,int32_t ncols,int32_t begin_y,int32_t begin_x); // only LINES,COLS,0,0
int32_t delwin(WINDOW *win);
int32_t touchwin(WINDOW *win); // stub
WINDOW *subwin(WINDOW *orig, int32_t nlines, int32_t ncols, int32_t begin_y, int32_t begin_x); // stub
int32_t mvwin(WINDOW *win, int32_t y, int32_t x); // stub
int32_t mvcur(int32_t oldrow, int32_t oldcol, int32_t newrow, int32_t newcol);
char erasechar(void); // stub
char killchar(void); // stub
int32_t move(int32_t y, int32_t x);
int32_t wmove(WINDOW *win, int32_t y, int32_t x);
chtype inch(void);
chtype winch(WINDOW *win);
chtype mvinch(int32_t y, int32_t x);
chtype mvwinch(WINDOW *win, int32_t y, int32_t x);
int32_t addch(chtype ch);
int32_t waddch(WINDOW *win, chtype ch);
int32_t mvaddch(int32_t y, int32_t x, chtype ch);
int32_t mvwaddch(WINDOW *win, int32_t y, int32_t x, chtype ch);
int32_t addstr(const char *str);
int32_t addnstr(const char *str, int32_t n);
int32_t waddstr(WINDOW *win, const char *str);
int32_t waddnstr(WINDOW *win, const char *str, int32_t n);
int32_t mvaddstr(int32_t y, int32_t x, const char *str);
int32_t mvaddnstr(int32_t y, int32_t x, const char *str, int32_t n);
int32_t mvwaddstr(WINDOW *win, int32_t y, int32_t x, const char *str);
int32_t mvwaddnstr(WINDOW *win, int32_t y, int32_t x, const char *str, int32_t n);
int32_t mvgetnstr(int32_t y, int32_t x, char *str, int32_t n); // stub
int32_t printw(char *fmt,...);
int32_t wprintw(WINDOW *win,char *fmt,...);
int32_t mvprintw(int32_t y,int32_t x,char *fmt,...);
int32_t mvwprintw(WINDOW *win,int32_t y,int32_t x,char *fmt,...);
#define A_CHARTEXT 0xff
#define baudrate() 9600
#define unctrl(a) "^x"
#define getmaxx(a) COLS
#define getmaxy(a) LINES
#define getxy(win,y,x) y = win->y, x = win->x
// functions with only visible effects
#define wrefresh(win) 0
#define wnoutrefresh(win) 0
#define doupdate() 0
#define touchwin(win) 0
#define standout() 0
#define standend() 0
#define raw() 0
#define keypad(win,bf) 0
#define noecho() 0
#define flushinp() 0
#define clearok(win,bf) 0
#define idlok(win,bf) 0
#define leaveok(win,bf) 0
#ifndef TRUE
#define TRUE 1
@@ -77,57 +146,3 @@ int wclrtoeol(WINDOW *win);
#endif
#define standout()
#define standend()
#define refresh()
#define raw()
#define noecho()
#define flushinp()
#define clear()
#define clrtoeol()
#define addch(a)
#define werase(a)
#define wclear(a)
#define delwin(a)
#define addstr(a)
#define touchwin(a)
#define idlok(a,b)
#define clearok(a,b)
#define keypad(a,b)
#define leaveok(a,b)
#define waddch(a,b)
#define waddstr(a,b)
#define move(a,b)
#define mvwin(a,b,c)
#define wmove(a,b,c)
#define mvaddch(a,b,c)
#define mvaddstr(a,b,c)
#define wgetnstr(a,b,c)
#define getyx(a,b,c)
#define mvcur(a,b,c,d)
#define mvwaddch(a,b,c,d)
#define mvprintw(...)
#define printw(...)
#define wprintw(...)
#define mvwprintw(...)
#define A_CHARTEXT 0xff
#define inch() 0
#define endwin() 1
#define isendwin() 0
#define baudrate() 9600
#define killchar() 3
#define erasechar() 8
#define wclrtoeol(a) 0
#define wrefresh(a) 0
#define unctrl(a) "^x"
#define getmaxx(a) COLS
#define getmaxy(a) LINES
#define mvinch(a,b) '.'
#define mvwinch(a,b,c) 0
#define newwin(a,b,c,d) 0
#define subwin(a,b,c,d,e) 0
#endif

View File

@@ -266,7 +266,7 @@ get_str(struct rogue_state *rs,void *vopt, WINDOW *win)
{
if (c == -1)
continue;
else if (c == erasechar()) /* process erase character */
/*else if (c == erasechar()) // process erase character
{
if (sp > buf)
{
@@ -276,12 +276,12 @@ get_str(struct rogue_state *rs,void *vopt, WINDOW *win)
}
continue;
}
else if (c == killchar()) /* process kill character */
else if (c == killchar()) // process kill character
{
sp = buf;
wmove(win, oy, ox);
continue;
}
}*/
else if (sp == buf)
{
if (c == '-' && win != stdscr)

View File

@@ -87,6 +87,7 @@ score(struct rogue_state *rs,int amount, int flags, char monst)
delwin(curscr);
if (hw != NULL)
delwin(hw);
hw = NULL;
}
top_ten = (SCORE *) malloc(numscores * sizeof (SCORE));

View File

@@ -91,7 +91,9 @@ void rogueiterate(struct rogue_state *rs)
// Set up windows
if ( hw == NULL )
{
hw = newwin(LINES, COLS, 0, 0);
}
idlok(stdscr, TRUE);
idlok(hw, TRUE);
#ifdef MASTER

View File

@@ -29,7 +29,7 @@
#include <sys/stat.h>
#include <errno.h>
#ifndef DONTUSEGUI
#ifndef BUILD_ROGUE
#include <curses.h>
#else

0
src/cc/rogue/rogue.scr Normal file
View File

View File

@@ -227,7 +227,9 @@ restore(struct rogue_state *rs,char *file, char **envp)
char buf[MAXSTR];
//auto
STAT sbuf2;
if ( rs->guiflag == 0 )
return(0);
if (strcmp(file, "-r") == 0)
file = file_name;

View File

@@ -502,37 +502,44 @@ add_line(struct rogue_state *rs,char *fmt, char *arg)
msg(rs,"");
if ( rs->sleeptime != 0 )
refresh();
tw = newwin(line_cnt + 1, maxlen + 2, 0, COLS - maxlen - 3);
sw = subwin(tw, line_cnt + 1, maxlen + 1, 0, COLS - maxlen - 2);
for (y = 0; y <= line_cnt; y++)
if ( rs->guiflag != 0 )
{
wmove(sw, y, 0);
for (x = 0; x <= maxlen; x++)
waddch(sw, mvwinch(hw, y, x));
}
wmove(tw, line_cnt, 1);
waddstr(tw, prompt);
/*
* if there are lines below, use 'em
*/
if (LINES > NUMLINES)
{
if (NUMLINES + line_cnt > LINES)
mvwin(tw, LINES - (line_cnt + 1), COLS - maxlen - 3);
else
mvwin(tw, NUMLINES, 0);
}
touchwin(tw);
wrefresh(tw);
wait_for(rs,' ');
if (md_hasclreol())
{
werase(tw);
leaveok(tw, TRUE);
tw = newwin(line_cnt + 1, maxlen + 2, 0, COLS - maxlen - 3);
sw = subwin(tw, line_cnt + 1, maxlen + 1, 0, COLS - maxlen - 2);
for (y = 0; y <= line_cnt; y++)
{
wmove(sw, y, 0);
for (x = 0; x <= maxlen; x++)
waddch(sw, mvwinch(hw, y, x));
}
wmove(tw, line_cnt, 1);
waddstr(tw, prompt);
/*
* if there are lines below, use 'em
*/
if (LINES > NUMLINES)
{
if (NUMLINES + line_cnt > LINES)
mvwin(tw, LINES - (line_cnt + 1), COLS - maxlen - 3);
else
mvwin(tw, NUMLINES, 0);
}
touchwin(tw);
wrefresh(tw);
wait_for(rs,' ');
if (md_hasclreol())
{
werase(tw);
leaveok(tw, TRUE);
wrefresh(tw);
}
delwin(tw);
touchwin(stdscr);
}
else
{
wait_for(rs,' ');
}
delwin(tw);
touchwin(stdscr);
}
else
{