Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
| Download
GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
Project: cocalc-sagemath-dev-slelievre
Views: 418346/***************************************************************************1**2*A ncurses.c BROWSE package Frank Lübeck3**4** Provide functions from ncurses C-library to GAP.5** We choose a subset of functions, usually the 'w'-variants.6** Panels can also be used.7**8*/910#define VERSION "1.8.7"1112const char * Revision_ncurses_c =13"VERSION";1415/* read GAP source header files with a combined header file */1617#include "src/compiled.h" /* GAP headers */18#include <stdio.h>19#include <unistd.h>20#include <stdlib.h> /* for getenv and co */21#ifdef WIDECHARS22#define _XOPEN_SOURCE_EXTENDED23#include <locale.h>24#include <ncursesw/curses.h>25#include <ncursesw/panel.h>26#else27#include <ncurses.h>28#include <panel.h>29#endif3031/* remember attributes at init time XXX32static attr_t startattr;33static short startcp;34*/3536/* We store the living WINDOW and PANEL pointers in two strings. The37pointer to window i (zero based counting) is stored in38((WINDOW**)CHARS_STRING(winlist))[i]. If this window is wrapped in39a panel then the pointer to this panel is stored in the same position of40panellist.4142For debugging purposes the strings winlist and panellist are available in43GAP as record components of the same name in 'NCurses'.44*/45static Obj winlist;46static Obj panellist;4748/* the functions */495051/* get the win or panel from number (return NULL if no valid input) */52WINDOW* winnum(Obj num) {53Int n;54if (!IS_INTOBJ(num))55return (WINDOW*)0;56n = INT_INTOBJ(num);57if (n < 0 || n * sizeof(Obj) >= GET_LEN_STRING(winlist))58return (WINDOW*)0;59return ((WINDOW**)CHARS_STRING(winlist))[n];60}61PANEL* pannum(Obj num) {62Int n;63if (!IS_INTOBJ(num))64return (PANEL*)0;65n = INT_INTOBJ(num);66/* no panel for stdscr */67if (n < 1 || n * sizeof(Obj) >= GET_LEN_STRING(panellist))68return (PANEL*)0;69return ((PANEL**)CHARS_STRING(panellist))[n];70}7172Obj IsStdinATty(Obj self) {73if (isatty(0))74return True;75else76return False;77}7879Obj IsStdoutATty(Obj self) {80if (isatty(1))81return True;82else83return False;84}8586/* interface to configure some basic behaviour of the ncurses screen */87Obj Cbreak(Obj self) {88if (cbreak() != ERR)89return True;90else91return False;92}9394Obj Nocbreak(Obj self) {95if (nocbreak() != ERR)96return True;97else98return False;99}100101Obj Echo(Obj self) {102if (echo() != ERR)103return True;104else105return False;106}107108Obj Noecho(Obj self) {109if (noecho() != ERR)110return True;111else112return False;113}114115Obj Nl(Obj self) {116if (nl() != ERR)117return True;118else119return False;120}121122Obj Nonl(Obj self) {123if (nonl() != ERR)124return True;125else126return False;127}128129Obj Raw(Obj self) {130if (raw() != ERR)131return True;132else133return False;134}135136Obj Noraw(Obj self) {137if (noraw() != ERR)138return True;139else140return False;141}142143Obj Intrflush(Obj self, Obj num, Obj bf) {144WINDOW *win;145win = winnum(num);146if (!win)147return False;148if (bf == True)149if (intrflush(win, TRUE) != ERR)150return True;151else152return False;153else154if (intrflush(win, FALSE) != ERR)155return True;156else157return False;158}159160Obj Keypad(Obj self, Obj num, Obj bf) {161WINDOW *win;162win = winnum(num);163if (!win)164return False;165if (bf == True)166if (keypad(win, TRUE) != ERR)167return True;168else169return False;170else171if (keypad(win, FALSE) != ERR)172return True;173else174return False;175}176177Obj Idlok(Obj self, Obj num, Obj bf) {178WINDOW *win;179win = winnum(num);180if (!win)181return False;182if (bf == True)183if (idlok(win, TRUE) != ERR)184return True;185else186return False;187else188if (idlok(win, FALSE) != ERR)189return True;190else191return False;192}193194Obj Leaveok(Obj self, Obj num, Obj bf) {195WINDOW *win;196win = winnum(num);197if (!win)198return False;199if (bf == True)200if (leaveok(win, TRUE) != ERR)201return True;202else203return False;204else205if (leaveok(win, FALSE) != ERR)206return True;207else208return False;209}210211Obj Scrollok(Obj self, Obj num, Obj bf) {212WINDOW *win;213win = winnum(num);214if (!win)215return False;216if (bf == True)217if (scrollok(win, TRUE) != ERR)218return True;219else220return False;221else222if (scrollok(win, FALSE) != ERR)223return True;224else225return False;226}227228Obj Clearok(Obj self, Obj num, Obj bf) {229WINDOW *win;230win = winnum(num);231if (!win)232return False;233if (bf == True)234if (clearok(win, TRUE) != ERR)235return True;236else237return False;238else239if (clearok(win, FALSE) != ERR)240return True;241else242return False;243}244245Obj Immedok(Obj self, Obj num, Obj bf) {246WINDOW *win;247win = winnum(num);248if (!win)249return False;250if (bf == True)251immedok(win, TRUE);252else253immedok(win, FALSE);254return True;255}256257Obj WTimeout(Obj self, Obj num, Obj time) {258WINDOW *win;259Int t;260win = winnum(num);261if (!win)262return False;263if (!IS_INTOBJ(time))264t = 0;265else266t = INT_INTOBJ(time);267wtimeout(win, (int)t);268return True;269}270271Obj Napms(Obj self, Obj time) {272Int t;273if (!IS_INTOBJ(time))274t = 0;275else276t = INT_INTOBJ(time);277napms(t);278return True;279}280281Obj Curs_set(Obj self, Obj vis) {282int res;283if (!IS_INTOBJ(vis))284return False;285res = curs_set(INT_INTOBJ(vis));286if (res == ERR)287return False;288return INTOBJ_INT(res);289}290291Obj Savetty(Obj self) {292savetty();293return True;294}295296Obj Resetty(Obj self) {297resetty();298return True;299}300301static int default_curs_vis = ERR;302Obj ResetCursor(Obj self) {303if (default_curs_vis != ERR)304curs_set(default_curs_vis);305return True;306}307308/* set default attributes, stored during init of ncurses XXX309Obj Attrsetdefault(Obj self) {310attr_set(startattr, startcp, 0);311return (Obj)0;312}*/313314/* delete all windows, except stdscr, and panels; clear stdscr */315Obj ClearAll(Obj self) {316317SET_LEN_STRING(winlist, sizeof(Obj));318SET_LEN_STRING(panellist, sizeof(Obj));319clear();320return (Obj)0;321}322323/* basic functions: wrefresh, endwin, doupdate */324Obj WRefresh( Obj self, Obj num ) {325WINDOW* win;326win = winnum(num);327if (win) {328if (wrefresh(win) != ERR)329return True;330else331return False;332}333else334return False;335}336337Obj Doupdate( Obj self ) {338if (doupdate() != ERR)339return True;340else341return False;342}343344Obj Endwin( Obj self ) {345if (endwin() != ERR)346return True;347else348return False;349}350351Obj Isendwin( Obj self ) {352if (isendwin())353return True;354else355return False;356}357358359/* create, delete, move windows */360Obj Newwin( Obj self, Obj nlines, Obj ncols, Obj begin_y, Obj begin_x) {361Int nl, nc, by, bx;362int num;363WINDOW *win;364365if (IS_INTOBJ(nlines))366nl = INT_INTOBJ(nlines);367else368nl = 0;369if (IS_INTOBJ(ncols))370nc = INT_INTOBJ(ncols);371else372nc = 0;373if (IS_INTOBJ(begin_y))374by = INT_INTOBJ(begin_y);375else376by = 0;377if (IS_INTOBJ(begin_x))378bx = INT_INTOBJ(begin_x);379else380bx = 0;381win = newwin(nl, nc, by, bx);382if (win) {383num = GET_LEN_STRING(winlist)/sizeof(Obj);384GROW_STRING(winlist, (num+1)*sizeof(Obj));385((WINDOW**)(CHARS_STRING(winlist)))[num] = win;386SET_LEN_STRING(winlist, (num+1)*sizeof(Obj));387CHANGED_BAG(winlist);388return INTOBJ_INT(num);389}390else391return False;392}393394Obj Delwin( Obj self, Obj num ) {395WINDOW* win;396Int i, n;397win = winnum(num);398if (win) {399if (delwin(win) != ERR) {400n = INT_INTOBJ(num);401((WINDOW**)(CHARS_STRING(winlist)))[n] = 0;402if ((n+1)*sizeof(Obj) == GET_LEN_STRING(winlist)) {403for (i = GET_LEN_STRING(winlist)/sizeof(Obj);404i > 0 && ((WINDOW**)(CHARS_STRING(winlist)))[i-1] == 0;405i--);406SET_LEN_STRING(winlist, i * sizeof(Obj));407}408CHANGED_BAG(winlist);409return True;410}411else412return False;413}414else415return False;416}417418Obj Mvwin(Obj self, Obj num, Obj y, Obj x) {419Int iy, ix;420WINDOW *win;421win = winnum(num);422if (!win)423return False;424if (IS_INTOBJ(y))425iy = INT_INTOBJ(y);426else427iy = 0;428if (IS_INTOBJ(x))429ix = INT_INTOBJ(x);430else431ix = 0;432if (mvwin(win, iy, ix) != ERR)433return True;434else435return False;436}437438/* moving curser, writing characters and strings to terminal */439Obj WMove(Obj self, Obj num, Obj y, Obj x) {440WINDOW *win;441Int iy, ix;442win = winnum(num);443if (!win)444return False;445if (IS_INTOBJ(y))446iy = INT_INTOBJ(y);447else448iy = 0;449if (IS_INTOBJ(x))450ix = INT_INTOBJ(x);451else452ix = 0;453if (wmove(win, iy, ix) != ERR)454return True;455else456return False;457}458459/* whole window, or to EOL or to bottom of window */460Obj WClear( Obj self, Obj num ) {461WINDOW* win;462win = winnum(num);463if (win) {464if (wclear(win) != ERR)465return True;466else467return False;468}469else470return False;471}472473Obj WErase( Obj self, Obj num ) {474WINDOW* win;475win = winnum(num);476if (win) {477if (werase(win) != ERR)478return True;479else480return False;481}482else483return False;484}485486Obj WClrtoeol( Obj self, Obj num ) {487WINDOW* win;488win = winnum(num);489if (win) {490if (wclrtoeol(win) != ERR)491return True;492else493return False;494}495else496return False;497}498499Obj WClrtobot( Obj self, Obj num ) {500WINDOW* win;501win = winnum(num);502if (win) {503if (wclrtobot(win) != ERR)504return True;505else506return False;507}508else509return False;510}511512Obj WAddnstr(Obj self, Obj num, Obj str, Obj n) {513WINDOW *win;514Int len;515win = winnum(num);516if (!win)517return False;518if (!IS_STRING_REP(str))519return False;520if (!IS_INTOBJ(n))521len = GET_LEN_STRING(str);522else523len = INT_INTOBJ(n);524if (waddnstr(win, CSTR_STRING(str), len) != ERR)525return True;526else527return False;528}529530/* ch can be a GAP character or an INTOBJ (possibly containing531attribute info) */532Obj WAddch(Obj self, Obj num, Obj ch) {533WINDOW *win;534Int ich;535win = winnum(num);536if (!win)537return False;538if (TNUM_OBJ(ch) == T_CHAR)539ich = *(UChar*)ADDR_OBJ(ch);540else if (IS_INTOBJ(ch))541ich = INT_INTOBJ(ch);542else543return False;544if (waddch(win, ich) != ERR)545return True;546else547return False;548}549550#ifdef WIDECHARS551Obj WAddwch(Obj self, Obj num, Obj ch) {552WINDOW *win;553wchar_t ich[CCHARW_MAX];554cchar_t cc;555Obj c;556Int i;557558win = winnum(num);559if (!win)560return False;561if (TNUM_OBJ(ch) == T_CHAR){562ich[0] = *(UChar*)ADDR_OBJ(ch);563ich[1] = L'\0';564}565else if (IS_INTOBJ(ch)){566ich[0] = INT_INTOBJ(ch);567ich[1] = L'\0';568}569else if (IS_LIST(ch)){570for (i=1, c=ELM0_LIST(ch,1); i < CCHARW_MAX && IS_INTOBJ(c);571i++, c=ELM0_LIST(ch,i)) {572ich[i-1] = INT_INTOBJ(c);573}574ich[i-1] = L'\0';575}576else577return False;578579if (setcchar(&cc, ich, 0, 0, NULL) == ERR)580return False;581582583if (wecho_wchar(win, &cc) != ERR)584return True;585else586return False;587}588#endif589590Obj WBorder(Obj self, Obj num, Obj chars) {591WINDOW *win;592Obj ls, rs, ts, bs, tl, tr, bl, br;593Int ils, irs, its, ibs, itl, itr, ibl, ibr;594if (IS_PLIST(chars) && LEN_PLIST(chars) > 7) {595ls = ELM_PLIST(chars, 1);596rs = ELM_PLIST(chars, 2);597ts = ELM_PLIST(chars, 3);598bs = ELM_PLIST(chars, 4);599tl = ELM_PLIST(chars, 5);600tr = ELM_PLIST(chars, 6);601bl = ELM_PLIST(chars, 7);602br = ELM_PLIST(chars, 8);603}604else {605ls = Fail; rs = Fail; ts = Fail; bs = Fail;606tl = Fail; tr = Fail; bl = Fail; br = Fail;607}608win = winnum(num);609if (!win)610return False;611if (TNUM_OBJ(ls) == T_CHAR)612ils = *(UChar*)ADDR_OBJ(ls);613else if (IS_INTOBJ(ls))614ils = INT_INTOBJ(ls);615else616ils = 0;617if (TNUM_OBJ(rs) == T_CHAR)618irs = *(UChar*)ADDR_OBJ(rs);619else if (IS_INTOBJ(rs))620irs = INT_INTOBJ(rs);621else622irs = 0;623if (TNUM_OBJ(ts) == T_CHAR)624its = *(UChar*)ADDR_OBJ(ts);625else if (IS_INTOBJ(ts))626its = INT_INTOBJ(ts);627else628its = 0;629if (TNUM_OBJ(bs) == T_CHAR)630ibs = *(UChar*)ADDR_OBJ(bs);631else if (IS_INTOBJ(bs))632ibs = INT_INTOBJ(bs);633else634ibs = 0;635if (TNUM_OBJ(tl) == T_CHAR)636itl = *(UChar*)ADDR_OBJ(tl);637else if (IS_INTOBJ(tl))638itl = INT_INTOBJ(tl);639else640itl = 0;641if (TNUM_OBJ(tr) == T_CHAR)642itr = *(UChar*)ADDR_OBJ(tr);643else if (IS_INTOBJ(tr))644itr = INT_INTOBJ(tr);645else646itr = 0;647if (TNUM_OBJ(bl) == T_CHAR)648ibl = *(UChar*)ADDR_OBJ(bl);649else if (IS_INTOBJ(bl))650ibl = INT_INTOBJ(bl);651else652ibl = 0;653if (TNUM_OBJ(br) == T_CHAR)654ibr = *(UChar*)ADDR_OBJ(br);655else if (IS_INTOBJ(br))656ibr = INT_INTOBJ(br);657else658ibr = 0;659if (wborder(win, (chtype)ils, (chtype)irs, (chtype)its, (chtype)ibs,660(chtype)itl, (chtype)itr, (chtype)ibl, (chtype)ibr) != ERR)661return True;662else663return False;664}665666Obj WVline(Obj self, Obj num, Obj ch, Obj n) {667Int x, y, ich;668WINDOW *win;669win = winnum(num);670if (!win)671return False;672if (TNUM_OBJ(ch) == T_CHAR)673ich = *(UChar*)ADDR_OBJ(ch);674else if (IS_INTOBJ(ch))675ich = INT_INTOBJ(ch);676else677ich = 0;678if (!IS_INTOBJ(n))679getmaxyx(win, y, x);680else681y = INT_INTOBJ(n);682x = wvline(win, ich, y);683if (x != ERR)684return INTOBJ_INT(x);685else686return False;687}688689Obj WHline(Obj self, Obj num, Obj ch, Obj n) {690Int x, y, ich;691WINDOW *win;692win = winnum(num);693if (!win)694return False;695if (TNUM_OBJ(ch) == T_CHAR)696ich = *(UChar*)ADDR_OBJ(ch);697else if (IS_INTOBJ(ch))698ich = INT_INTOBJ(ch);699else700ich = 0;701if (!IS_INTOBJ(n))702getmaxyx(win, y, x);703else704x = INT_INTOBJ(n);705y = whline(win, ich, x);706if (y != ERR)707return INTOBJ_INT(y);708else709return False;710}711712/* returns integer which can be fed back in waddch */713Obj WInch(Obj self, Obj num) {714WINDOW *win;715win = winnum(num);716if (!win)717return False;718return INTOBJ_INT((Int) winch(win));719}720721/* get size of window and cursor position */722Obj Getyx(Obj self, Obj num) {723WINDOW *win;724int x, y;725Obj res;726win = winnum(num);727if (!win)728return False;729res = NEW_PLIST(T_PLIST, 2);730SET_LEN_PLIST(res, 2);731getyx(win, y, x);732SET_ELM_PLIST(res, 1, INTOBJ_INT(y));733SET_ELM_PLIST(res, 2, INTOBJ_INT(x));734return res;735}736737Obj Getbegyx(Obj self, Obj num) {738WINDOW *win;739int x, y;740Obj res;741win = winnum(num);742if (!win)743return False;744res = NEW_PLIST(T_PLIST, 2);745SET_LEN_PLIST(res, 2);746getbegyx(win, y, x);747SET_ELM_PLIST(res, 1, INTOBJ_INT(y));748SET_ELM_PLIST(res, 2, INTOBJ_INT(x));749return res;750}751752Obj Getmaxyx(Obj self, Obj num) {753WINDOW *win;754int x, y;755Obj res;756win = winnum(num);757if (!win)758return False;759res = NEW_PLIST(T_PLIST, 2);760SET_LEN_PLIST(res, 2);761getmaxyx(win, y, x);762SET_ELM_PLIST(res, 1, INTOBJ_INT(y));763SET_ELM_PLIST(res, 2, INTOBJ_INT(x));764return res;765}766767768/* the win argument is used for possible echoing */769Obj WGetch(Obj self, Obj num) {770int c;771WINDOW *win;772win = winnum(num);773if (!win)774win = stdscr;775c = getch();776if (c != ERR)777return INTOBJ_INT(c == 127 ? KEY_BACKSPACE : c);778else779return False;780}781782Obj Ungetch(Obj self, Obj ch) {783int ich;784if (!IS_INTOBJ(ch))785return False;786ich = (int) INT_INTOBJ(ch);787if (ungetch(ich) != ERR)788return True;789else790return False;791}792793Obj Has_key(Obj self, Obj ch) {794int ich;795if (!IS_INTOBJ(ch))796return False;797ich = (int) INT_INTOBJ(ch);798if (has_key(ich) == TRUE)799return True;800else801return False;802}803804805806/* Keys, we give symbols of standard special keys to GAP */807808/* test with 'has_key' and add some more (?),809see http://hessling-editor.sourceforge.net/doc/misc/app2.html */810Obj InitKeys() {811Obj tmp;812813tmp = NEW_PREC(0);814AssPRec(tmp, RNamName("DOWN"), INTOBJ_INT((Int)KEY_DOWN));815AssPRec(tmp, RNamName("UP"), INTOBJ_INT((Int)KEY_UP));816AssPRec(tmp, RNamName("LEFT"), INTOBJ_INT((Int)KEY_LEFT));817AssPRec(tmp, RNamName("RIGHT"), INTOBJ_INT((Int)KEY_RIGHT));818AssPRec(tmp, RNamName("HOME"), INTOBJ_INT((Int)KEY_HOME));819AssPRec(tmp, RNamName("END"), INTOBJ_INT((Int)KEY_END));820AssPRec(tmp, RNamName("PPAGE"), INTOBJ_INT((Int)KEY_PPAGE));821AssPRec(tmp, RNamName("NPAGE"), INTOBJ_INT((Int)KEY_NPAGE));822AssPRec(tmp, RNamName("BACKSPACE"), INTOBJ_INT((Int)KEY_BACKSPACE));823AssPRec(tmp, RNamName("DC"), INTOBJ_INT((Int)KEY_DC));824AssPRec(tmp, RNamName("ENTER"), INTOBJ_INT((Int)KEY_ENTER));825AssPRec(tmp, RNamName("IC"), INTOBJ_INT((Int)KEY_IC));826AssPRec(tmp, RNamName("REPLACE"), INTOBJ_INT((Int)KEY_REPLACE));827AssPRec(tmp, RNamName("STAB"), INTOBJ_INT((Int)KEY_STAB));828AssPRec(tmp, RNamName("F1"), INTOBJ_INT((Int)KEY_F(1)));829AssPRec(tmp, RNamName("F2"), INTOBJ_INT((Int)KEY_F(2)));830AssPRec(tmp, RNamName("F3"), INTOBJ_INT((Int)KEY_F(3)));831AssPRec(tmp, RNamName("F4"), INTOBJ_INT((Int)KEY_F(4)));832AssPRec(tmp, RNamName("F5"), INTOBJ_INT((Int)KEY_F(5)));833AssPRec(tmp, RNamName("F6"), INTOBJ_INT((Int)KEY_F(6)));834AssPRec(tmp, RNamName("F7"), INTOBJ_INT((Int)KEY_F(7)));835AssPRec(tmp, RNamName("F8"), INTOBJ_INT((Int)KEY_F(8)));836AssPRec(tmp, RNamName("F9"), INTOBJ_INT((Int)KEY_F(9)));837AssPRec(tmp, RNamName("F10"), INTOBJ_INT((Int)KEY_F(10)));838AssPRec(tmp, RNamName("F11"), INTOBJ_INT((Int)KEY_F(11)));839AssPRec(tmp, RNamName("F12"), INTOBJ_INT((Int)KEY_F(12)));840AssPRec(tmp, RNamName("F13"), INTOBJ_INT((Int)KEY_F(13)));841AssPRec(tmp, RNamName("F14"), INTOBJ_INT((Int)KEY_F(14)));842AssPRec(tmp, RNamName("F15"), INTOBJ_INT((Int)KEY_F(15)));843AssPRec(tmp, RNamName("F16"), INTOBJ_INT((Int)KEY_F(16)));844AssPRec(tmp, RNamName("F17"), INTOBJ_INT((Int)KEY_F(17)));845AssPRec(tmp, RNamName("F18"), INTOBJ_INT((Int)KEY_F(18)));846AssPRec(tmp, RNamName("F19"), INTOBJ_INT((Int)KEY_F(19)));847AssPRec(tmp, RNamName("F20"), INTOBJ_INT((Int)KEY_F(20)));848AssPRec(tmp, RNamName("F21"), INTOBJ_INT((Int)KEY_F(21)));849AssPRec(tmp, RNamName("F22"), INTOBJ_INT((Int)KEY_F(22)));850AssPRec(tmp, RNamName("F23"), INTOBJ_INT((Int)KEY_F(23)));851AssPRec(tmp, RNamName("F24"), INTOBJ_INT((Int)KEY_F(24)));852AssPRec(tmp, RNamName("A1"), INTOBJ_INT((Int)KEY_A1));853AssPRec(tmp, RNamName("A3"), INTOBJ_INT((Int)KEY_A3));854AssPRec(tmp, RNamName("B2"), INTOBJ_INT((Int)KEY_B2));855AssPRec(tmp, RNamName("C1"), INTOBJ_INT((Int)KEY_C1));856AssPRec(tmp, RNamName("C3"), INTOBJ_INT((Int)KEY_C3));857AssPRec(tmp, RNamName("MOUSE"), INTOBJ_INT((Int)KEY_MOUSE));858859return tmp;860}861862/* Line drawing characters on GAP level */863Obj InitLineDraw() {864Obj res;865res = NEW_PREC(0);866AssPRec(res, RNamName("BLOCK"), INTOBJ_INT((Int)ACS_BLOCK));867AssPRec(res, RNamName("BOARD"), INTOBJ_INT((Int)ACS_BOARD));868AssPRec(res, RNamName("BTEE"), INTOBJ_INT((Int)ACS_BTEE));869AssPRec(res, RNamName("BULLET"), INTOBJ_INT((Int)ACS_BULLET));870AssPRec(res, RNamName("CKBOARD"), INTOBJ_INT((Int)ACS_CKBOARD));871AssPRec(res, RNamName("DARROW"), INTOBJ_INT((Int)ACS_DARROW));872AssPRec(res, RNamName("DEGREE"), INTOBJ_INT((Int)ACS_DEGREE));873AssPRec(res, RNamName("DIAMOND"), INTOBJ_INT((Int)ACS_DIAMOND));874AssPRec(res, RNamName("GEQUAL"), INTOBJ_INT((Int)ACS_GEQUAL));875AssPRec(res, RNamName("HLINE"), INTOBJ_INT((Int)ACS_HLINE));876AssPRec(res, RNamName("LANTERN"), INTOBJ_INT((Int)ACS_LANTERN));877AssPRec(res, RNamName("LARROW"), INTOBJ_INT((Int)ACS_LARROW));878AssPRec(res, RNamName("LEQUAL"), INTOBJ_INT((Int)ACS_LEQUAL));879AssPRec(res, RNamName("LLCORNER"), INTOBJ_INT((Int)ACS_LLCORNER));880AssPRec(res, RNamName("LRCORNER"), INTOBJ_INT((Int)ACS_LRCORNER));881AssPRec(res, RNamName("LTEE"), INTOBJ_INT((Int)ACS_LTEE));882AssPRec(res, RNamName("NEQUAL"), INTOBJ_INT((Int)ACS_NEQUAL));883AssPRec(res, RNamName("PI"), INTOBJ_INT((Int)ACS_PI));884AssPRec(res, RNamName("PLMINUS"), INTOBJ_INT((Int)ACS_PLMINUS));885AssPRec(res, RNamName("PLUS"), INTOBJ_INT((Int)ACS_PLUS));886AssPRec(res, RNamName("RARROW"), INTOBJ_INT((Int)ACS_RARROW));887AssPRec(res, RNamName("RTEE"), INTOBJ_INT((Int)ACS_RTEE));888AssPRec(res, RNamName("S1"), INTOBJ_INT((Int)ACS_S1));889AssPRec(res, RNamName("S3"), INTOBJ_INT((Int)ACS_S3));890AssPRec(res, RNamName("S7"), INTOBJ_INT((Int)ACS_S7));891AssPRec(res, RNamName("S9"), INTOBJ_INT((Int)ACS_S9));892AssPRec(res, RNamName("STERLING"), INTOBJ_INT((Int)ACS_STERLING));893AssPRec(res, RNamName("TTEE"), INTOBJ_INT((Int)ACS_TTEE));894AssPRec(res, RNamName("UARROW"), INTOBJ_INT((Int)ACS_UARROW));895AssPRec(res, RNamName("ULCORNER"), INTOBJ_INT((Int)ACS_ULCORNER));896AssPRec(res, RNamName("URCORNER"), INTOBJ_INT((Int)ACS_URCORNER));897AssPRec(res, RNamName("VLINE"), INTOBJ_INT((Int)ACS_VLINE));898899return res;900}901902/* Attributes, we handle colors and standard attributes */903904Obj InitAttrs() {905Obj tmp, cp;906UInt4 i, n;907908tmp = NEW_PREC(0);909if (has_colors()) {910start_color();911use_default_colors();912AssPRec(tmp, RNamName("has_colors"), True);913/* initialize color pairs 1..64 */914cp = NEW_PLIST(T_PLIST, 64);915for (i = 1; i <= 64 && i < COLOR_PAIRS; i++) {916if (i < 64)917if (i%8 == i/8) {918init_pair(i, i%8, -1);919} else {920init_pair(i, i % 8, i/8);921}922else923init_pair(i, 0, -1);924n = COLOR_PAIR(i);925SET_ELM_PLIST(cp, i, INTOBJ_INT(n));926SET_LEN_PLIST(cp, (UInt)i);927}928AssPRec(tmp, RNamName("ColorPairs"), cp);929/* fgcolor with default background */930if (72 < COLOR_PAIRS) {931cp = NEW_PLIST(T_PLIST, 8);932SET_LEN_PLIST(cp, 8);933for (i = 0; i <= 7; i++) {934init_pair(65+i, i, -1);935n = COLOR_PAIR(65+i);936SET_ELM_PLIST(cp, i+1, INTOBJ_INT(n));937}938AssPRec(tmp, RNamName("ColorPairsFg"), cp);939}940/* bgcolor with default foreground */941if (80 < COLOR_PAIRS) {942cp = NEW_PLIST(T_PLIST, 8);943SET_LEN_PLIST(cp, 8);944for (i = 0; i <= 7; i++) {945init_pair(73+i, -1, i);946n = COLOR_PAIR(73+i);947SET_ELM_PLIST(cp, i+1, INTOBJ_INT(n));948}949AssPRec(tmp, RNamName("ColorPairsBg"), cp);950}951}952else {953AssPRec(tmp, RNamName("has_colors"), False);954}955/* the other attributes */956AssPRec(tmp, RNamName("NORMAL"), INTOBJ_INT(A_NORMAL));957AssPRec(tmp, RNamName("STANDOUT"), INTOBJ_INT(A_STANDOUT));958AssPRec(tmp, RNamName("UNDERLINE"), INTOBJ_INT(A_UNDERLINE));959AssPRec(tmp, RNamName("REVERSE"), INTOBJ_INT(A_REVERSE));960AssPRec(tmp, RNamName("BLINK"), INTOBJ_INT(A_BLINK));961AssPRec(tmp, RNamName("DIM"), INTOBJ_INT(A_DIM));962AssPRec(tmp, RNamName("BOLD"), INTOBJ_INT(A_BOLD));963964return tmp;965}966967Obj WAttrset(Obj self, Obj num, Obj attrs) {968Int i;969WINDOW *win;970win = winnum(num);971if (!win)972return False;973if (IS_INTOBJ(attrs))974i = INT_INTOBJ(attrs);975else976i = 0;977if (wattrset(win, i) != ERR)978return True;979else980return False;981}982983Obj WAttron(Obj self, Obj num, Obj attrs) {984Int i;985WINDOW *win;986win = winnum(num);987if (!win)988return False;989if (IS_INTOBJ(attrs))990i = INT_INTOBJ(attrs);991else992i = 0;993if (wattron(win, i) != ERR)994return True;995else996return False;997}998999Obj WAttroff(Obj self, Obj num, Obj attrs) {1000Int i;1001WINDOW *win;1002win = winnum(num);1003if (!win)1004return False;1005if (IS_INTOBJ(attrs))1006i = INT_INTOBJ(attrs);1007else1008i = 0;1009if (wattroff(win, i) != ERR)1010return True;1011else1012return False;1013}10141015/* wattr_get is a macro and allows NULL pointers as arguments, this is1016checked in the code.1017If we call it with arguments which are obviously never NULL, then1018gcc >= 4.6 with -Wall or -Waddress issues a warning that a pointer1019is checked for not being NULL although it is never NULL.1020We wrap that macro in a function to avoid the warning. */1021int wattr_get_fun(WINDOW *win, attr_t * pa, short *ps, void *opts) {1022int ret;1023ret = wattr_get(win, pa, ps, opts);1024return ret;1025}1026Obj WAttrCPGet(Obj self, Obj num) {1027WINDOW *win;1028attr_t a;1029short cp;1030Obj res;1031win = winnum(num);1032if (!win)1033return False;1034wattr_get_fun(win, &a, &cp, NULL);1035res = NEW_PLIST(T_PLIST, 2);1036SET_LEN_PLIST(res, 2);1037SET_ELM_PLIST(res, 1, INTOBJ_INT((int)a));1038SET_ELM_PLIST(res, 2, INTOBJ_INT((int)cp));1039return res;1040};104110421043Obj WBkgdset(Obj self, Obj num, Obj attrs) {1044Int i;1045WINDOW *win;1046win = winnum(num);1047if (!win)1048return False;1049if (IS_INTOBJ(attrs))1050i = INT_INTOBJ(attrs);1051else1052i = 0;1053wbkgdset(win, i);1054return True;1055}10561057Obj WBkgd(Obj self, Obj num, Obj attrs) {1058Int i;1059WINDOW *win;1060win = winnum(num);1061if (!win)1062return False;1063if (IS_INTOBJ(attrs))1064i = INT_INTOBJ(attrs);1065else1066i = 0;1067wbkgd(win, i);1068return True;1069}107010711072/* Panels: create, delete, update, move, stack movements, hide, show */1073Obj New_panel(Obj self, Obj num) {1074WINDOW *win;1075PANEL *pan;1076int n;1077win = winnum(num);1078if (!win)1079return False;1080n = INT_INTOBJ(num);1081if (n == 0)1082/* no panel for stdscr */1083return False;1084pan = new_panel(win);1085if (!pan)1086return False;1087GROW_STRING(panellist, (n+1)*sizeof(Obj));1088((PANEL**)(CHARS_STRING(panellist)))[n] = pan;1089if ((n+1)*sizeof(Obj) > GET_LEN_STRING(panellist))1090SET_LEN_STRING(panellist, (n+1)*sizeof(Obj));1091CHANGED_BAG(panellist);1092return num;1093}10941095Obj Del_panel(Obj self, Obj pnum) {1096PANEL *pan;1097Int i, n;1098pan = pannum(pnum);1099if (!pan)1100return False;1101if (del_panel(pan) != ERR) {1102n = INT_INTOBJ(pnum);1103((PANEL**)(CHARS_STRING(panellist)))[n] = 0;1104if ((n+1)*sizeof(Obj) == GET_LEN_STRING(panellist)) {1105for (i = GET_LEN_STRING(panellist)/sizeof(Obj);1106i > 0 && ((PANEL**)(CHARS_STRING(panellist)))[i-1] == 0;1107i--);1108SET_LEN_STRING(panellist, i * sizeof(Obj));1109}1110CHANGED_BAG(panellist);1111return True;1112}1113else1114return False;1115}11161117Obj Update_panels(Obj self) {1118update_panels();1119return True;1120}11211122Obj Hide_panel(Obj self, Obj pnum) {1123PANEL *pan;1124pan = pannum(pnum);1125if (!pan)1126return False;1127if (hide_panel(pan) != ERR) {1128return True;1129}1130else1131return False;1132}11331134Obj Show_panel(Obj self, Obj pnum) {1135PANEL *pan;1136pan = pannum(pnum);1137if (!pan)1138return False;1139if (show_panel(pan) != ERR) {1140return True;1141}1142else1143return False;1144}11451146Obj Bottom_panel(Obj self, Obj pnum) {1147PANEL *pan;1148pan = pannum(pnum);1149if (!pan)1150return False;1151if (bottom_panel(pan) != ERR) {1152return True;1153}1154else1155return False;1156}11571158Obj Top_panel(Obj self, Obj pnum) {1159PANEL *pan;1160pan = pannum(pnum);1161if (!pan)1162return False;1163if (top_panel(pan) != ERR) {1164return True;1165}1166else1167return False;1168}11691170Obj Panel_above(Obj self, Obj pnum) {1171PANEL *pan;1172int i;1173pan = pannum(pnum);1174pan = panel_above(pan);1175if (!pan)1176return False;1177for(i = 1; ((PANEL**)(CHARS_STRING(panellist)))[i] != pan; i++);1178return INTOBJ_INT((Int)i);1179}11801181Obj Panel_below(Obj self, Obj pnum) {1182PANEL *pan;1183int i;1184pan = pannum(pnum);1185pan = panel_below(pan);1186if (!pan)1187return False;1188for(i = 1; ((PANEL**)(CHARS_STRING(panellist)))[i] != pan; i++);1189return INTOBJ_INT((Int)i);1190}11911192Obj Move_panel(Obj self, Obj pnum, Obj y, Obj x) {1193Int iy, ix;1194PANEL *pan;1195pan = pannum(pnum);1196if (!pan)1197return False;1198if (IS_INTOBJ(y))1199iy = INT_INTOBJ(y);1200else1201iy = 0;1202if (IS_INTOBJ(x))1203ix = INT_INTOBJ(x);1204else1205ix = 0;1206if (move_panel(pan, iy, ix) != ERR)1207return True;1208else1209return False;1210}12111212/* mouse interface if available */1213#ifdef NCURSES_MOUSE_VERSION1214static mmask_t mmaskbits[] = {1215BUTTON1_PRESSED, BUTTON1_RELEASED, BUTTON1_CLICKED, BUTTON1_DOUBLE_CLICKED,1216BUTTON1_TRIPLE_CLICKED,1217BUTTON2_PRESSED, BUTTON2_RELEASED, BUTTON2_CLICKED, BUTTON2_DOUBLE_CLICKED,1218BUTTON2_TRIPLE_CLICKED,1219BUTTON3_PRESSED, BUTTON3_RELEASED, BUTTON3_CLICKED, BUTTON3_DOUBLE_CLICKED,1220BUTTON3_TRIPLE_CLICKED,1221BUTTON4_PRESSED, BUTTON4_RELEASED, BUTTON4_CLICKED, BUTTON4_DOUBLE_CLICKED,1222BUTTON4_TRIPLE_CLICKED,1223BUTTON_SHIFT, BUTTON_CTRL, BUTTON_ALT, REPORT_MOUSE_POSITION1224#if NCURSES_MOUSE_VERSION == 21225, BUTTON5_PRESSED, BUTTON5_RELEASED, BUTTON5_CLICKED, BUTTON5_DOUBLE_CLICKED,1226BUTTON5_TRIPLE_CLICKED,1227#endif1228};1229#if NCURSES_MOUSE_VERSION == 21230# define LENmmaskbits 291231#else1232# define LENmmaskbits 241233#endif123412351236/* translate mmask_t to list of integers and vice versa */1237Obj IntlistMmask_t(mmask_t mask) {1238Obj res;1239Int l, i;1240res = NEW_PLIST(T_PLIST, 1);1241SET_LEN_PLIST(res, 0);1242for (l=1, i=0; i<LENmmaskbits; i++) {1243if (mask & mmaskbits[i]) {AssPlist(res, l, INTOBJ_INT(i)); l++;}1244}1245return res;1246}1247mmask_t mmaskIntlist(Obj list) {1248mmask_t res = (mmask_t)0;1249Int l, i, n;1250while (! IS_PLIST(list)) {1251list = ErrorReturnObj("<list> must be a plain list of integers, not a %s)",1252(Int)TNAM_OBJ(list), 0L,1253"you can replace <list> via 'return <list>;'" );1254}1255l = LEN_PLIST(list);1256for (i = 0; i<l; i++) {1257n = INT_INTOBJ(ELM_PLIST(list, i+1));1258if (n >= 0 && n < LENmmaskbits) {res += mmaskbits[n];}1259}1260return res;1261}12621263Obj Mousemask(Obj self, Obj list) {1264mmask_t new, old;1265Obj res;1266while (! IS_PLIST(list)) {1267list = ErrorReturnObj("<list> must be a plain list of integers, not a %s)",1268(Int)TNAM_OBJ(list), 0L,1269"you can replace <list> via 'return <list>;'" );1270}1271new = mmaskIntlist(list);1272new = mousemask(new, &old);1273res = NEW_PREC(0);1274AssPRec(res, RNamName("new"), IntlistMmask_t(new));1275AssPRec(res, RNamName("old"), IntlistMmask_t(old));1276return res;1277}12781279static MEVENT mev;12801281Obj GetMouse(Obj self) {1282int y, x;1283Obj res, mask;1284if (getmouse(&mev) == ERR) return Fail;1285mask = IntlistMmask_t(mev.bstate);1286y = mev.y;1287x = mev.x;1288/* find panels/windows from above under mouse event */1289res = NEW_PLIST(T_PLIST, 3);1290SET_LEN_PLIST(res, 3);1291SET_ELM_PLIST(res, 1, INTOBJ_INT(y));1292SET_ELM_PLIST(res, 2, INTOBJ_INT(x));1293SET_ELM_PLIST(res, 3, mask);1294return res;1295}12961297Obj Wenclose(Obj self, Obj wnum, Obj iy, Obj ix) {1298WINDOW *win;1299int y, x;1300win = winnum(wnum);1301if (win == NULL) return False;1302if (! IS_INTOBJ(iy)) return False;1303else y = INT_INTOBJ(iy);1304if (! IS_INTOBJ(ix)) return False;1305else x = INT_INTOBJ(ix);1306if (wenclose(win, y, x) == TRUE) return True;1307else return False;1308}13091310Obj Mouseinterval( Obj len) {1311if (! IS_INTOBJ(len)) return INTOBJ_INT(mouseinterval(200));1312return INTOBJ_INT(mouseinterval(INT_INTOBJ(len)));1313}131413151316#endif131713181319/*F * * * * * * * * * * * initialize package * * * * * * * * * * * * * * * */1320132113221323/****************************************************************************1324**13251326*V GVarFilts . . . . . . . . . . . . . . . . . . . list of filters to export1327*/1328/*static StructGVarFilt GVarFilts [] = {13291330{ "IS_BOOL", "obj", &IsBoolFilt,1331IsBoolHandler, "src/bool.c:IS_BOOL" },13321333{ 0 }13341335}; ?????*/13361337/****************************************************************************1338**13391340*V GVarFuncs . . . . . . . . . . . . . . . . . . list of functions to export1341*/1342static StructGVarFunc GVarFuncs [] = {13431344/* XXX { "attrsetdefault", 0, "", Attrsetdefault, "ncurses.c:Attrsetdefault" }, */1345{ "ClearAll", 0, "", ClearAll, "ncurses.c:ClearAll" },1346{ "cbreak", 0, "", Cbreak, "ncurses.c:Cbreak" },1347{ "nocbreak", 0, "", Nocbreak, "ncurses.c:Nocbreak" },1348{ "echo", 0, "", Echo, "ncurses.c:Echo" },1349{ "noecho", 0, "", Noecho, "ncurses.c:Noecho" },1350{ "intrflush", 2, "win, bool", Intrflush, "ncurses.c:Intrflush" },1351{ "keypad", 2, "win, bool", Keypad, "ncurses.c:Keypad" },1352{ "idlok", 2, "win, bool", Idlok, "ncurses.c:Idlok" },1353{ "leaveok", 2, "win, bool", Leaveok, "ncurses.c:Leaveok" },1354{ "scrollok", 2, "win, bool", Scrollok, "ncurses.c:Scrollok" },1355{ "clearok", 2, "win, bool", Clearok, "ncurses.c:Clearok" },1356{ "immedok", 2, "win, bool", Immedok, "ncurses.c:Immedok" },1357{ "raw", 0, "", Raw, "ncurses.c:Raw" },1358{ "noraw", 0, "", Noraw, "ncurses.c:Noraw" },1359{ "nl", 0, "", Nl, "ncurses.c:Nl" },1360{ "nonl", 0, "", Nonl, "ncurses.c:Nonl" },1361{ "curs_set", 1, "vis", Curs_set, "ncurses.c:Curs_set" },1362{ "ResetCursor", 0, "", ResetCursor, "ncurses.c:ResetCursor" },1363{ "wtimeout", 2, "win, time", WTimeout, "ncurses.c:WTimeout" },1364{ "IsStdinATty", 0, "", IsStdinATty, "ncurses.c:IsStdinATty" },1365{ "IsStdoutATty", 0, "", IsStdoutATty, "ncurses.c:IsStdoutATty" },1366{ "savetty", 0, "", Savetty, "ncurses.c:Savetty" },1367{ "resetty", 0, "", Resetty, "ncurses.c:Resetty" },1368{ "napms", 1, "time", Napms, "ncurses.c:Napms" },1369{ "doupdate", 0, "", Doupdate, "ncurses.c:Doupdate" },1370{ "wrefresh", 1, "win", WRefresh, "ncurses.c:WRefresh" },1371{ "wclear", 1, "win", WClear, "ncurses.c:WClear" },1372{ "werase", 1, "win", WErase, "ncurses.c:WErase" },1373{ "wclrtoeol", 1, "win", WClrtoeol, "ncurses.c:WClrtoeol" },1374{ "wclrtobot", 1, "win", WClrtobot, "ncurses.c:WClrtobot" },1375{ "endwin", 0, "", Endwin, "ncurses.c:Endwin" },1376{ "isendwin", 0, "", Isendwin, "ncurses.c:Isendwin" },1377{ "newwin", 4, "nlines, ncols, begin_y, begin_x",1378Newwin, "ncurses.c:Newwin" },1379{ "delwin", 1, "win", Delwin, "ncurses.c:Delwin" },1380{ "mvwin", 3, "win, y, x", Mvwin, "ncurses.c:Mvwin" },1381{ "wmove", 3, "win, y, x", WMove, "ncurses.c:WMove" },1382{ "waddnstr", 3, "win, str, len", WAddnstr, "ncurses.c:WAddnstr" },1383{ "waddch", 2, "win, ch", WAddch, "ncurses.c:WAddch" },1384#ifdef WIDECHARS1385{ "wecho_wchar", 2, "win, ch", WAddwch, "ncurses.c:WAddwch" },1386#endif1387{ "wborder", 2, "win, chars", WBorder, "ncurses.c:WBorder" },1388{ "wvline", 3, "win, ch, n", WVline, "ncurses.c:WVline" },1389{ "whline", 3, "win, ch, n", WHline, "ncurses.c:WHline" },1390{ "winch", 1, "win", WInch, "ncurses.c:WInch" },1391{ "wgetch", 1, "win", WGetch, "ncurses.c:WGetch" },1392{ "ungetch", 1, "ch", Ungetch, "ncurses.c:Ungetch" },1393{ "has_key", 1, "ch", Has_key, "ncurses.c:Has_key" },1394{ "getyx", 1, "win", Getyx, "ncurses.c:Getyx" },1395{ "getbegyx", 1, "win", Getbegyx, "ncurses.c:Getbegyx" },1396{ "getmaxyx", 1, "win", Getmaxyx, "ncurses.c:Getmaxyx" },1397{ "wattr_get", 1, "win", WAttrCPGet, "ncurses.c:WAttrCPGet" },1398{ "wattrset", 2, "win, attr", WAttrset, "ncurses.c:WAttrset" },1399{ "wattron", 2, "win, attr", WAttron, "ncurses.c:WAttron" },1400{ "wattroff", 2, "win, attr", WAttroff, "ncurses.c:WAttroff" },1401{ "wbkgdset", 2, "win, attr", WBkgdset, "ncurses.c:WBkgdset" },1402{ "wbkgd", 2, "win, attr", WBkgd, "ncurses.c:WBkgd" },1403{ "new_panel", 1, "win", New_panel, "ncurses.c:New_panel" },1404{ "update_panels", 0, "", Update_panels, "ncurses.c:Update_panels" },1405{ "bottom_panel", 1, "pan", Bottom_panel, "ncurses.c:Bottom_panel" },1406{ "top_panel", 1, "pan", Top_panel, "ncurses.c:Top_panel" },1407{ "show_panel", 1, "pan", Show_panel, "ncurses.c:Show_panel" },1408{ "hide_panel", 1, "pan", Hide_panel, "ncurses.c:Hide_panel" },1409{ "panel_above", 1, "pan", Panel_above, "ncurses.c:Panel_above" },1410{ "panel_below", 1, "pan", Panel_below, "ncurses.c:Panel_below" },1411{ "move_panel", 3, "pan, y, x", Move_panel, "ncurses.c:Move_panel" },1412{ "del_panel", 1, "pan", Del_panel, "ncurses.c:Del_panel" },1413#ifdef NCURSES_MOUSE_VERSION1414{ "mousemask", 1, "list", Mousemask, "ncurses.c:Mousemask" },1415{ "mouseinterval", 1, "len", Mouseinterval, "ncurses.c:Mouseinterval" },1416{ "getmouse", 0, "", GetMouse, "ncurses.c:GetMouse" },1417{ "wenclose", 3, "win, y, x", Wenclose, "ncurses.c:Wenclose" },1418#endif14191420{ 0 }14211422};1423142414251426/**************************************************************************14271428*F InitKernel( <module> ) . . . . . . . . initialise kernel data structures1429*/1430static Int InitKernel (1431StructInitInfo * module )1432{14331434/* return success */1435InitGlobalBag( &winlist, "src/ncurses.c:winlist" );1436InitGlobalBag( &panellist, "src/ncurses.c:panellist" );14371438/* init filters and functions */1439InitHdlrFuncsFromTable( GVarFuncs );14401441return 0;1442}14431444/****************************************************************************1445**1446*F PostRestore( <module> ) . . . . . . . . . . . . . after restore workspace1447*/1448static Int PostRestore (1449StructInitInfo * module )1450{1451Int i, gvar;1452Obj tmp, vers;1453char* cvers = VERSION;14541455/* setup and initialize the ncurses package */1456winlist = NEW_STRING(sizeof(Obj));1457SET_LEN_STRING(winlist, sizeof(Obj));1458panellist = NEW_STRING(sizeof(Obj));1459SET_LEN_STRING(panellist, sizeof(Obj));14601461#ifdef WIDECHARS1462/* set locale from environment */1463setlocale(LC_ALL,"");1464#endif14651466/* make sure that TERM is set to avoid exit by initscr */1467if (getenv("TERM") == NULL)1468putenv("TERM=vt102");14691470/* init filters and functions1471we assign the functions to components of a record "NCurses" */1472/* (re)build kernel part of NCurses */1473gvar = GVarName("NCurses");1474tmp = VAL_GVAR(gvar);1475if (!tmp) {1476tmp = NEW_PREC(0);1477}14781479if (! isatty(1))1480putenv("TERM=dumb");1481/* initialize ncurses */1482((WINDOW**)CHARS_STRING(winlist))[0] = initscr();1483((PANEL**)CHARS_STRING(panellist))[0] = 0;1484endwin();14851486for ( i = 0; GVarFuncs[i].name != 0; i++ ) {1487AssPRec(tmp, RNamName((Char*)GVarFuncs[i].name),1488NewFunctionC( GVarFuncs[i].name, GVarFuncs[i].nargs,1489GVarFuncs[i].args, GVarFuncs[i].handler ) );1490}1491AssPRec(tmp, RNamName("keys"), InitKeys() );1492AssPRec(tmp, RNamName("attrs"), InitAttrs() );1493AssPRec(tmp, RNamName("lineDraw"), InitLineDraw() );1494AssPRec(tmp, RNamName("winlist"), winlist);1495AssPRec(tmp, RNamName("panellist"), panellist);1496vers = NEW_STRING(strlen(cvers));1497memcpy(CHARS_STRING(vers), cvers, strlen(cvers));1498AssPRec(tmp, RNamName("KernelModuleVersion"), vers);14991500/* (re)assign */1501MakeReadWriteGVar( gvar);1502AssGVar( gvar, tmp );1503MakeReadOnlyGVar(gvar);15041505/* find and save cursor visibility */1506for(i = 0; default_curs_vis == ERR && i < 3; i++) {1507default_curs_vis = curs_set(i);1508}1509if (default_curs_vis != ERR)1510curs_set(default_curs_vis);15111512/* return success */1513return 0;1514}15151516/****************************************************************************1517**1518*F InitLibrary( <module> ) . . . . . . . initialise library data structures1519*/1520static Int InitLibrary (1521StructInitInfo * module )1522{1523PostRestore( module );15241525/* return success */1526return 0;1527}152815291530/****************************************************************************1531**1532*F InitInfopl() . . . . . . . . . . . . . . . . . table of init functions1533*/1534/* <name> returns the description of this module */1535static StructInitInfo module = {1536#ifdef NCURSESSTATIC1537/* type = */ MODULE_STATIC,1538#else1539/* type = */ MODULE_DYNAMIC,1540#endif1541/* name = */ "ncurses",1542/* revision_c = */ 0,1543/* revision_h = */ 0,1544/* version = */ 0,1545/* crc = */ 0,1546/* initKernel = */ InitKernel,1547/* initLibrary = */ InitLibrary,1548/* checkInit = */ 0,1549/* preSave = */ 0,1550/* postSave = */ 0,1551/* postRestore = */ PostRestore1552};15531554#ifndef NCURSESSTATIC1555StructInitInfo * Init__Dynamic ( void )1556{1557return &module;1558}1559#endif15601561StructInitInfo * Init__ncurses ( void )1562{1563return &module;1564}1565156615671568