apps/examples/pdcurses: Minor fixes to examples/pdcurses apps to support multi-threading, cleanup RAM, etc.

This commit is contained in:
Ken Pettit 2019-01-05 13:28:06 -06:00 committed by Gregory Nutt
parent 73fc5eb199
commit c776901ac2
9 changed files with 131 additions and 0 deletions

View File

@ -76,6 +76,9 @@ int charset_main(int argc, char *argv[])
int row;
int col;
int i;
#ifdef CONFIG_PDCURSES_MULTITHREAD
FAR struct pdc_context_s *ctx = PDC_ctx();
#endif
/* Initialize */

View File

@ -79,6 +79,10 @@ static short color_table[] =
static void myrefresh(void)
{
#ifdef CONFIG_PDCURSES_MULTITHREAD
FAR struct pdc_context_s *ctx = PDC_ctx();
#endif
napms(DELAYSIZE);
move(LINES - 1, COLS - 1);
refresh();
@ -157,6 +161,9 @@ int firework_main(int argc, char *argv[])
int direction;
int seed;
int i;
#ifdef CONFIG_PDCURSES_MULTITHREAD
FAR struct pdc_context_s *ctx = PDC_ctx();
#endif
traceon();
initscr();

View File

@ -102,6 +102,9 @@ static char *messages[] =
static int wait_for_user(void)
{
chtype ch;
#ifdef CONFIG_PDCURSES_MULTITHREAD
FAR struct pdc_context_s *ctx = PDC_ctx();
#endif
nodelay(stdscr, true);
halfdelay(50);
@ -198,6 +201,9 @@ static int bouncing_balls(WINDOW *win)
int xd3;
int yd3;
int c;
#ifdef CONFIG_PDCURSES_MULTITHREAD
FAR struct pdc_context_s *ctx = PDC_ctx();
#endif
curs_set(0);
@ -313,6 +319,9 @@ int newdemo_main(int argc, char *argv[])
int i;
int j;
int seed;
#ifdef CONFIG_PDCURSES_MULTITHREAD
FAR struct pdc_context_s *ctx = PDC_ctx();
#endif
traceon();
initscr();

View File

@ -79,6 +79,9 @@ static void backfill(void)
{
int x;
int y;
#ifdef CONFIG_PDCURSES_MULTITHREAD
FAR struct pdc_context_s *ctx = PDC_ctx();
#endif
erase();
@ -94,6 +97,9 @@ static void backfill(void)
static void wait_a_while(long msec)
{
int c;
#ifdef CONFIG_PDCURSES_MULTITHREAD
FAR struct pdc_context_s *ctx = PDC_ctx();
#endif
if (msec != 1)
{
@ -110,6 +116,9 @@ static void wait_a_while(long msec)
static void saywhat(const char *text)
{
#ifdef CONFIG_PDCURSES_MULTITHREAD
FAR struct pdc_context_s *ctx = PDC_ctx();
#endif
mvprintw(LINES - 1, 0, "%-20.20s", text);
}

View File

@ -83,6 +83,9 @@ int rain_main(int argc, char *argv[])
{
int x, y, j, r, c, seed;
static int xpos[5], ypos[5];
#ifdef CONFIG_PDCURSES_MULTITHREAD
FAR struct pdc_context_s *ctx = PDC_ctx();
#endif
traceon();
initscr();

View File

@ -246,6 +246,10 @@ static void continue2(void)
static int init_test(WINDOW ** win, int argc, char *argv[])
{
#ifdef CONFIG_PDCURSES_MULTITHREAD
FAR struct pdc_context_s *ctx = PDC_ctx();
#endif
traceon();
initscr();
#ifdef A_COLOR
@ -359,6 +363,9 @@ static void input_test(WINDOW *win)
WINDOW *subWin;
static const char spinner[4] = "/-\\|";
int spinner_count = 0;
#ifdef CONFIG_PDCURSES_MULTITHREAD
FAR struct pdc_context_s *ctx = PDC_ctx();
#endif
wclear(win);
@ -629,6 +636,9 @@ static void output_test(WINDOW *win)
chtype ch;
int bx;
int by;
#ifdef CONFIG_PDCURSES_MULTITHREAD
FAR struct pdc_context_s *ctx = PDC_ctx();
#endif
nl();
wclear(win);
@ -799,6 +809,9 @@ static void resize_test(WINDOW *dummy)
WINDOW *win1;
int nwidth = 135;
int nheight = 52;
#ifdef CONFIG_PDCURSES_MULTITHREAD
FAR struct pdc_context_s *ctx = PDC_ctx();
#endif
int owidth = COLS;
int oheight = LINES;
@ -891,6 +904,9 @@ static void clipboard_test(WINDOW *win)
char *ptr = NULL;
long length = 0;
long i;
#ifdef CONFIG_PDCURSES_MULTITHREAD
FAR struct pdc_context_s *ctx = PDC_ctx();
#endif
mvaddstr(1, 1, "This test will display the contents of the system clipboard");
@ -950,6 +966,9 @@ static void clipboard_test(WINDOW *win)
static void acs_test(WINDOW *win)
{
#ifdef CONFIG_PDCURSES_MULTITHREAD
FAR struct pdc_context_s *ctx = PDC_ctx();
#endif
chtype acs_values[ACSNUM];
int tmarg = (LINES - 22) / 2;
int i;
@ -1046,6 +1065,9 @@ static void color_test(WINDOW *win)
int col3;
int i;
int j;
#ifdef CONFIG_PDCURSES_MULTITHREAD
FAR struct pdc_context_s *ctx = PDC_ctx();
#endif
if (!has_colors())
{
@ -1137,6 +1159,9 @@ static void wide_test(WINDOW *win)
{
wchar_t tmp[513];
size_t i;
#ifdef CONFIG_PDCURSES_MULTITHREAD
FAR struct pdc_context_s *ctx = PDC_ctx();
#endif
attrset(A_BOLD);
mvaddstr(1, (COLS - 25) / 2, "Wide Character Input Test");
@ -1165,6 +1190,9 @@ static void wide_test(WINDOW *win)
void display_menu(int old_option, int new_option)
{
#ifdef CONFIG_PDCURSES_MULTITHREAD
FAR struct pdc_context_s *ctx = PDC_ctx();
#endif
int lmarg = (COLS - 14) / 2, tmarg = (LINES - (MAX_OPTIONS + 2)) / 2;
if (old_option == -1)
@ -1209,6 +1237,9 @@ int testcurs_main(int argc, char *argv[])
int old_option = -1;
int new_option = 0;
bool quit = false;
#ifdef CONFIG_PDCURSES_MULTITHREAD
FAR struct pdc_context_s *ctx = PDC_ctx();
#endif
#ifdef CONFIG_LIBC_LOCALE
setlocale(LC_ALL, "");

View File

@ -138,6 +138,10 @@ static char *prepad(char *s, int length)
static void rmline(WINDOW *win, int nr) /* keeps box lines intact */
{
#ifdef CONFIG_PDCURSES_MULTITHREAD
FAR struct pdc_context_s *ctx = PDC_ctx();
#endif
mvwaddstr(win, nr, 1, padstr(" ", bw - 2));
wrefresh(win);
}
@ -212,6 +216,9 @@ static void idle(void)
char buf[MAXSTRLEN];
time_t t;
struct tm *tp;
#ifdef CONFIG_PDCURSES_MULTITHREAD
FAR struct pdc_context_s *ctx = PDC_ctx();
#endif
if (time(&t) == -1)
{
@ -453,6 +460,10 @@ void rmstatus(void)
void titlemsg(char *msg)
{
#ifdef CONFIG_PDCURSES_MULTITHREAD
FAR struct pdc_context_s *ctx = PDC_ctx();
#endif
mvwaddstr(wtitl, 0, 2, padstr(msg, bw - 3));
wrefresh(wtitl);
}
@ -465,6 +476,10 @@ void bodymsg(char *msg)
void errormsg(char *msg)
{
#ifdef CONFIG_PDCURSES_MULTITHREAD
FAR struct pdc_context_s *ctx = PDC_ctx();
#endif
beep();
mvwaddstr(wstat, 0, 2, padstr(msg, bw - 3));
wrefresh(wstat);
@ -472,6 +487,10 @@ void errormsg(char *msg)
void statusmsg(char *msg)
{
#ifdef CONFIG_PDCURSES_MULTITHREAD
FAR struct pdc_context_s *ctx = PDC_ctx();
#endif
mvwaddstr(wstat, 1, 2, padstr(msg, bw - 3));
wrefresh(wstat);
}
@ -617,8 +636,13 @@ void domenu(const menu *mp)
void startmenu(menu *mp, char *mtitle)
{
#ifdef CONFIG_PDCURSES_MULTITHREAD
FAR struct pdc_context_s *ctx = PDC_ctx();
#endif
traceon();
initscr();
quit = false;
incurses = true;
initcolor();
@ -753,6 +777,13 @@ int weditstr(WINDOW *win, char *buf, int field)
curs_set(insert ? 2 : 1);
break;
case KEY_DC:
if (*bp != 0)
{
memmove((void *)(bp), (const void *)(bp+1), strlen(bp));
}
break;
default:
if (c == erasechar()) /* backspace, ^H */
{

View File

@ -619,6 +619,9 @@ int worm_main(int argc, char *argv[])
int last;
int bottom;
int seed;
#ifdef CONFIG_PDCURSES_MULTITHREAD
FAR struct pdc_context_s *ctx = PDC_ctx();
#endif
for (x = 1; x < argc; x++)
{

View File

@ -790,6 +790,9 @@ int xmas_main(int argc, char *argv[])
#endif
{
int loopy;
#ifdef CONFIG_PDCURSES_MULTITHREAD
FAR struct pdc_context_s *ctx = PDC_ctx();
#endif
traceon();
initscr();
@ -1077,6 +1080,38 @@ int xmas_main(int argc, char *argv[])
clear();
refresh();
delwin(treescrn);
delwin(treescrn2);
delwin(treescrn3);
delwin(treescrn4);
delwin(treescrn5);
delwin(treescrn6);
delwin(treescrn7);
delwin(treescrn8);
delwin(dotdeer0);
delwin(stardeer0);
delwin(lildeer0);
delwin(lildeer1);
delwin(lildeer2);
delwin(lildeer3);
delwin(middeer0);
delwin(middeer1);
delwin(middeer2);
delwin(middeer3);
delwin(bigdeer0);
delwin(bigdeer1);
delwin(bigdeer2);
delwin(bigdeer3);
delwin(bigdeer4);
delwin(lookdeer0);
delwin(lookdeer1);
delwin(lookdeer2);
delwin(lookdeer3);
delwin(lookdeer4);
delwin(w_holiday);
delwin(w_del_msg);
endwin();
return 0;
}