diff options
Diffstat (limited to 'usub/curses.mus')
-rw-r--r-- | usub/curses.mus | 402 |
1 files changed, 302 insertions, 100 deletions
diff --git a/usub/curses.mus b/usub/curses.mus index 7bacb6b57e..ce53a38834 100644 --- a/usub/curses.mus +++ b/usub/curses.mus @@ -1,6 +1,9 @@ -/* $Header: curses.mus,v 4.0 91/03/20 01:56:13 lwall Locked $ +/* $RCSfile: curses.mus,v $$Revision: 4.0.1.1 $$Date: 91/11/05 19:06:19 $ * * $Log: curses.mus,v $ + * Revision 4.0.1.1 91/11/05 19:06:19 lwall + * patch11: usub/curses.mus now supports SysV curses + * * Revision 4.0 91/03/20 01:56:13 lwall * 4.0 baseline. * @@ -11,22 +14,50 @@ #include "EXTERN.h" #include "perl.h" -extern int wantarray; char *savestr(); +#undef bool #include <curses.h> +#ifndef A_UNDERLINE +#define NOSETATTR +#define A_STANDOUT 0x0200 +#define A_UNDERLINE 0x0100 +#define A_REVERSE 0x0200 +#define A_BLINK 0x0400 +#define A_BOLD 0x0800 +#define A_ALTCHARSET 0x1000 +#define A_NORMAL 0 +#endif + +#ifdef USG +static char *tcbuf = NULL; +#endif + +#ifdef NOSETATTR +static unsigned curattr = NORMAL; +#endif + static enum uservars { UV_curscr, UV_stdscr, - UV_Def_term, - UV_My_term, UV_ttytype, UV_LINES, UV_COLS, UV_ERR, UV_OK, +#ifdef BSD + UV_Def_term, + UV_My_term, +#endif + UV_A_STANDOUT, + UV_A_UNDERLINE, + UV_A_REVERSE, + UV_A_BLINK, + UV_A_DIM, + UV_A_BOLD, + UV_A_NORMAL, }; static enum usersubs { @@ -48,7 +79,6 @@ static enum usersubs { US_wdeleteln, US_erase, US_werase, - US_flushok, US_idlok, US_insch, US_winsch, @@ -58,8 +88,6 @@ static enum usersubs { US_wmove, US_overlay, US_overwrite, - US_printw, - US_wprintw, US_refresh, US_wrefresh, US_standout, @@ -76,13 +104,10 @@ static enum usersubs { US_wgetstr, US_raw, US_noraw, - US_scanw, - US_wscanw, US_baudrate, US_delwin, US_endwin, US_erasechar, - US_getcap, US_getyx, US_inch, US_winch, @@ -90,7 +115,6 @@ static enum usersubs { US_killchar, US_leaveok, US_longname, - US_fullname, US_mvwin, US_newwin, US_nl, @@ -98,7 +122,6 @@ static enum usersubs { US_scrollok, US_subwin, US_touchline, - US_touchoverlap, US_touchwin, US_unctrl, US_gettmode, @@ -107,8 +130,28 @@ static enum usersubs { US_savetty, US_resetty, US_setterm, + US_attroff, + US_wattroff, + US_attron, + US_wattron, + US_attrset, + US_wattrset, +#ifdef CURSEFMT + US_printw, /* remove */ + US_wprintw, /* remove */ + US_scanw, /* delete */ + US_wscanw, /* delete */ +#endif + US_getcap, +#ifdef BSD + US_flushok, + US_fullname, + US_touchoverlap, US_tstp, US__putchar, +#endif + US_mysub, + US_testcallback, }; static int usersub(); @@ -128,13 +171,22 @@ init_curses() MAGICVAR("curscr", UV_curscr); MAGICVAR("stdscr", UV_stdscr); - MAGICVAR("Def_term",UV_Def_term); - MAGICVAR("My_term", UV_My_term); MAGICVAR("ttytype", UV_ttytype); MAGICVAR("LINES", UV_LINES); MAGICVAR("COLS", UV_COLS); MAGICVAR("ERR", UV_ERR); MAGICVAR("OK", UV_OK); +#ifdef BSD + MAGICVAR("Def_term",UV_Def_term); + MAGICVAR("My_term", UV_My_term); +#endif + MAGICVAR("A_STANDOUT", UV_A_STANDOUT); + MAGICVAR("A_UNDERLINE", UV_A_UNDERLINE); + MAGICVAR("A_REVERSE", UV_A_REVERSE); + MAGICVAR("A_BLINK", UV_A_BLINK); + MAGICVAR("A_DIM", UV_A_DIM); + MAGICVAR("A_BOLD", UV_A_BOLD); + MAGICVAR("A_NORMAL", UV_A_NORMAL); make_usub("addch", US_addch, usersub, filename); make_usub("waddch", US_waddch, usersub, filename); @@ -154,7 +206,6 @@ init_curses() make_usub("wdeleteln", US_wdeleteln, usersub, filename); make_usub("erase", US_erase, usersub, filename); make_usub("werase", US_werase, usersub, filename); - make_usub("flushok", US_flushok, usersub, filename); make_usub("idlok", US_idlok, usersub, filename); make_usub("insch", US_insch, usersub, filename); make_usub("winsch", US_winsch, usersub, filename); @@ -164,8 +215,6 @@ init_curses() make_usub("wmove", US_wmove, usersub, filename); make_usub("overlay", US_overlay, usersub, filename); make_usub("overwrite", US_overwrite, usersub, filename); - make_usub("printw", US_printw, usersub, filename); - make_usub("wprintw", US_wprintw, usersub, filename); make_usub("refresh", US_refresh, usersub, filename); make_usub("wrefresh", US_wrefresh, usersub, filename); make_usub("standout", US_standout, usersub, filename); @@ -182,13 +231,10 @@ init_curses() make_usub("wgetstr", US_wgetstr, usersub, filename); make_usub("raw", US_raw, usersub, filename); make_usub("noraw", US_noraw, usersub, filename); - make_usub("scanw", US_scanw, usersub, filename); - make_usub("wscanw", US_wscanw, usersub, filename); make_usub("baudrate", US_baudrate, usersub, filename); make_usub("delwin", US_delwin, usersub, filename); make_usub("endwin", US_endwin, usersub, filename); make_usub("erasechar", US_erasechar, usersub, filename); - make_usub("getcap", US_getcap, usersub, filename); make_usub("getyx", US_getyx, usersub, filename); make_usub("inch", US_inch, usersub, filename); make_usub("winch", US_winch, usersub, filename); @@ -196,7 +242,6 @@ init_curses() make_usub("killchar", US_killchar, usersub, filename); make_usub("leaveok", US_leaveok, usersub, filename); make_usub("longname", US_longname, usersub, filename); - make_usub("fullname", US_fullname, usersub, filename); make_usub("mvwin", US_mvwin, usersub, filename); make_usub("newwin", US_newwin, usersub, filename); make_usub("nl", US_nl, usersub, filename); @@ -204,7 +249,6 @@ init_curses() make_usub("scrollok", US_scrollok, usersub, filename); make_usub("subwin", US_subwin, usersub, filename); make_usub("touchline", US_touchline, usersub, filename); - make_usub("touchoverlap", US_touchoverlap,usersub, filename); make_usub("touchwin", US_touchwin, usersub, filename); make_usub("unctrl", US_unctrl, usersub, filename); make_usub("gettmode", US_gettmode, usersub, filename); @@ -213,10 +257,97 @@ init_curses() make_usub("savetty", US_savetty, usersub, filename); make_usub("resetty", US_resetty, usersub, filename); make_usub("setterm", US_setterm, usersub, filename); + make_usub("getcap", US_getcap, usersub, filename); + make_usub("attroff", US_attroff, usersub, filename); + make_usub("wattroff", US_wattroff, usersub, filename); + make_usub("attron", US_attron, usersub, filename); + make_usub("wattron", US_wattron, usersub, filename); + make_usub("attrset", US_attrset, usersub, filename); + make_usub("wattrset", US_wattrset, usersub, filename); +#ifdef CURSEFMT + make_usub("printw", US_printw, usersub, filename); + make_usub("wprintw", US_wprintw, usersub, filename); + make_usub("scanw", US_scanw, usersub, filename); + make_usub("wscanw", US_wscanw, usersub, filename); +#endif +#ifdef BSD + make_usub("flushok", US_flushok, usersub, filename); + make_usub("fullname", US_fullname, usersub, filename); + make_usub("touchoverlap", US_touchoverlap,usersub, filename); make_usub("tstp", US_tstp, usersub, filename); make_usub("_putchar", US__putchar, usersub, filename); -}; +#endif + make_usub("testcallback", US_testcallback,usersub, filename); + }; + +#ifdef USG +static char +*getcap(cap) +register char *cap; +{ + static char nocaperr[] = "Cannot read termcap entry."; + + extern char *tgetstr(); + + if (tcbuf == NULL) { + if ((tcbuf = malloc(1024)) == NULL) { + fatal(nocaperr); + } + if (tgetent(tcbuf, ttytype) == -1) { + fatal(nocaperr); + } + } + + return (tgetstr(cap, NULL)); +} +#endif + +#ifdef NOSETATTR +#define attron(attr) wattron(stdscr, attr) +#define attroff(attr) wattroff(stdscr, attr) +#define attset(attr) wattset(stdscr, attr) + +int +wattron(win, attr) +WINDOW *win; +chtype attr; +{ + curattr |= attr; + if (curattr & A_STANDOUT) { + return(wstandout(win)); + } else { + return(wstandend(win)); + } +} + +int +wattroff(win, attr) +WINDOW *win; +chtype attr; +{ + curattr &= (~attr); + if (curattr & A_STANDOUT) { + return(wstandout(win)); + } else { + return(wstandend(win)); + } +} +int +wattrset(win, attr) +WINDOW *win; +chtype attr; +{ + curattr = attr; + if (curattr & A_STANDOUT) { + return(wstandout(win)); + } else { + return(wstandend(win)); + } +} + +#endif + static int usersub(ix, sp, items) int ix; @@ -300,11 +431,6 @@ CASE int werase I WINDOW* win END -CASE int flushok -I WINDOW* win -I bool boolf -END - CASE int idlok I WINDOW* win I bool boolf @@ -347,35 +473,6 @@ I WINDOW* win1 I WINDOW* win2 END - case US_printw: - if (items < 1) - fatal("Usage: &printw($fmt, $arg1, $arg2, ... )"); - else { - int retval; - STR* str = str_new(0); - - do_sprintf(str, items - 1, st + 1); - retval = addstr(str->str_ptr); - str_numset(st[0], (double) retval); - str_free(str); - } - return sp; - - case US_wprintw: - if (items < 2) - fatal("Usage: &wprintw($win, $fmt, $arg1, $arg2, ... )"); - else { - int retval; - STR* str = str_new(0); - WINDOW* win = *(WINDOW**) str_get(st[1]); - - do_sprintf(str, items - 1, st + 1); - retval = waddstr(win, str->str_ptr); - str_numset(st[0], (double) retval); - str_free(str); - } - return sp; - CASE int refresh END @@ -410,47 +507,47 @@ CASE int noecho END case US_getch: - if (items != 0) - fatal("Usage: &getch()"); - else { - int retval; + if (items != 0) + fatal("Usage: &getch()"); + else { + int retval; char retch; - retval = getch(); + retval = getch(); if (retval == EOF) st[0] = &str_undef; else { retch = retval; str_nset(st[0], &retch, 1); } - } - return sp; + } + return sp; case US_wgetch: - if (items != 1) - fatal("Usage: &wgetch($win)"); - else { - int retval; + if (items != 1) + fatal("Usage: &wgetch($win)"); + else { + int retval; char retch; - WINDOW* win = *(WINDOW**) str_get(st[1]); + WINDOW* win = *(WINDOW**) str_get(st[1]); - retval = wgetch(win); + retval = wgetch(win); if (retval == EOF) st[0] = &str_undef; else { retch = retval; str_nset(st[0], &retch, 1); } - } - return sp; + } + return sp; CASE int getstr -IO char* str +O char* str END CASE int wgetstr I WINDOW* win -IO char* str +O char* str END CASE int raw @@ -472,10 +569,6 @@ END CASE int erasechar END -CASE char* getcap -I char* str -END - case US_getyx: if (items != 3) fatal("Usage: &getyx($win, $y, $x)"); @@ -494,7 +587,6 @@ END str_free(str); } return sp; - CASE int inch END @@ -514,15 +606,17 @@ I WINDOW* win I bool boolf END +#ifdef BSD CASE char* longname I char* termbuf IO char* name END - -CASE int fullname -I char* termbuf -IO char* name +#else +CASE char* longname +I char* termbug +I char* name END +#endif CASE int mvwin I WINDOW* win @@ -563,11 +657,6 @@ I int startx I int endx END -CASE int touchoverlap -I WINDOW* win1 -I WINDOW* win2 -END - CASE int touchwin I WINDOW* win END @@ -600,6 +689,82 @@ CASE int setterm I char* name END +CASE int attroff +I chtype str +END + +CASE int wattroff +I chtype str +END + +CASE int wattron +I chtype str +END + +CASE int attron +I chtype str +END + +CASE int attrset +I chtype str +END + +CASE int wattrset +I chtype str +END + +#ifdef CURSEFMT + case US_printw: + if (items < 1) + fatal("Usage: &printw($fmt, $arg1, $arg2, ... )"); + else { + int retval; + STR* str = str_new(0); + + do_sprintf(str, items - 1, st + 1); + retval = addstr(str->str_ptr); + str_numset(st[0], (double) retval); + str_free(str); + } + return sp; + + case US_wprintw: + if (items < 2) + fatal("Usage: &wprintw($win, $fmt, $arg1, $arg2, ... )"); + else { + int retval; + STR* str = str_new(0); + WINDOW* win = *(WINDOW**) str_get(st[1]); + + do_sprintf(str, items - 1, st + 1); + retval = waddstr(win, str->str_ptr); + str_numset(st[0], (double) retval); + str_free(str); + } + return sp; + +#endif + +CASE char* getcap +I char* str +END + +#ifdef BSD +CASE int flushok +I WINDOW* win +I bool boolf +END + +CASE int fullname +I char* termbuf +IO char* name +END + +CASE int touchoverlap +I WINDOW* win1 +I WINDOW* win2 +END + CASE int tstp END @@ -607,6 +772,12 @@ CASE int _putchar I char ch END + case US_testcallback: + sp = callback("callback", sp + items, curcsv->wantarray, 1, items); + break; + +#endif + default: fatal("Unimplemented user-defined subroutine"); } @@ -622,18 +793,12 @@ STR *str; case UV_COLS: str_numset(str, (double)COLS); break; - case UV_Def_term: - str_set(str, Def_term); - break; case UV_ERR: str_numset(str, (double)ERR); break; case UV_LINES: str_numset(str, (double)LINES); break; - case UV_My_term: - str_numset(str, (double)My_term); - break; case UV_OK: str_numset(str, (double)OK); break; @@ -646,6 +811,35 @@ STR *str; case UV_ttytype: str_set(str, ttytype); break; +#ifdef BSD + case UV_Def_term: + str_set(str, Def_term); + break; + case UV_My_term: + str_numset(str, (double)My_term); + break; +#endif + case UV_A_STANDOUT: + str_numset(str, (double)A_STANDOUT); + break; + case UV_A_UNDERLINE: + str_numset(str, (double)A_UNDERLINE); + break; + case UV_A_REVERSE: + str_numset(str, (double)A_REVERSE); + break; + case UV_A_BLINK: + str_numset(str, (double)A_BLINK); + break; + case UV_A_DIM: + str_numset(str, (double)A_DIM); + break; + case UV_A_BOLD: + str_numset(str, (double)A_BOLD); + break; + case UV_A_NORMAL: + str_numset(str, (double)A_NORMAL); + break; } return 0; } @@ -659,18 +853,26 @@ STR *str; case UV_COLS: COLS = (int)str_gnum(str); break; - case UV_Def_term: - Def_term = savestr(str_get(str)); /* never freed */ - break; case UV_LINES: LINES = (int)str_gnum(str); break; - case UV_My_term: - My_term = (bool)str_gnum(str); - break; case UV_ttytype: strcpy(ttytype, str_get(str)); /* hope it fits */ +#ifdef USG + if (tcbuf != NULL) { + free(tcbuf); + tcbuf = NULL; + } +#endif + break; +#ifdef BSD + case UV_Def_term: + Def_term = savestr(str_get(str)); /* never freed */ + break; + case UV_My_term: + My_term = (bool)str_gnum(str); break; +#endif } return 0; } |