#include #include #include "eat.h" void stupid_test(void) { if (initscr() == NULL) { perror("initscr"); return; } printw("This is a a curses window\n"); refresh(); sleep(3); printw("Going bye-bye now\n"); refresh(); sleep(3); endwin(); } /* Allocate and initialize a new window */ struct win_t* create_win(struct screen_t* s, int l, int t, int r, int b, int sb_h, win_type_t type) { struct win_t* w = malloc(sizeof(struct win_t)); /* Allocate */ if (w == NULL) return NULL; /* Failure */ if (init_win(w, s, l, t, r, b, sb_h, type) == NULL) { /* Initialize */ destroy_win(w); /* Deallocate */ return NULL; /* Failure */ } return w; /* Success */ } /* Initialize an already-allocated window */ struct win_t* init_win(struct win_t* w, struct screen_t* s, int l, int t, int r, int b, int sb_h, win_type_t type) { int max_r, max_b; if (w == NULL || s == NULL) return NULL; /* Failure */ /* Clip coordinates */ getmaxyx(s->c_win, max_r, max_b); if (l < 0) l = 0; if (t < 0) t = 0; if (r > max_r) r = max_r; if (b > max_b) b = max_b; /* Store some basic information */ w->l = l; w->t = t; w->r = r; w->b = b; w->w = r - l + 1; w->h = b - t + 1; w->type = type; /* Create a curses window */ w->c_win = subwin(s->c_win, w->h, w->w, w->t, w->l); if (w->c_win == NULL) return NULL; /* Failure */ return w; /* Success */ } /* Destroy a window */ int destroy_win(struct win_t* w) { if (w == NULL) return 0; /* Failure */ if (w->c_win != NULL && delwin(w->c_win) == ERR) return 0;/* Failure */ /* Also, deallocate type-specific stuff */ return 1; /* Success */ }