From 47fb8fd7b70a7868f56dec3e4473873eb1e3efa4 Mon Sep 17 00:00:00 2001 From: D-a-n-i-l-o Date: Sat, 16 Oct 2021 13:38:53 +0200 Subject: [PATCH] Added ncurses module by Rob C Signed-off-by: D-a-n-i-l-o --- modules/ncurses/README.md | 15 + modules/ncurses/makefile_windows.wx | 56 + modules/ncurses/module.json | 7 + modules/ncurses/ncurses.wx | 601 +++++ modules/ncurses/pdcurses/HISTORY.md | 2114 ++++++++++++++++++ modules/ncurses/pdcurses/IMPLEMNT.md | 329 +++ modules/ncurses/pdcurses/README.md | 55 + modules/ncurses/pdcurses/curses.h | 1397 ++++++++++++ modules/ncurses/pdcurses/curspriv.h | 129 ++ modules/ncurses/pdcurses/demos/README.md | 25 + modules/ncurses/pdcurses/demos/firework.c | 148 ++ modules/ncurses/pdcurses/demos/nctests.mif | 31 + modules/ncurses/pdcurses/demos/ncurses_cfg.h | 57 + modules/ncurses/pdcurses/demos/ozdemo.c | 424 ++++ modules/ncurses/pdcurses/demos/ptest.c | 309 +++ modules/ncurses/pdcurses/demos/rain.c | 158 ++ modules/ncurses/pdcurses/demos/testcurs.c | 1282 +++++++++++ modules/ncurses/pdcurses/demos/tui.c | 820 +++++++ modules/ncurses/pdcurses/demos/tui.h | 65 + modules/ncurses/pdcurses/demos/tuidemo.c | 228 ++ modules/ncurses/pdcurses/demos/worm.c | 433 ++++ modules/ncurses/pdcurses/demos/xmas.c | 955 ++++++++ modules/ncurses/pdcurses/panel.h | 56 + modules/ncurses/pdcurses/pdcurses/README.md | 25 + modules/ncurses/pdcurses/pdcurses/addch.c | 411 ++++ modules/ncurses/pdcurses/pdcurses/addchstr.c | 245 ++ modules/ncurses/pdcurses/pdcurses/addstr.c | 240 ++ modules/ncurses/pdcurses/pdcurses/attr.c | 352 +++ modules/ncurses/pdcurses/pdcurses/beep.c | 68 + modules/ncurses/pdcurses/pdcurses/bkgd.c | 223 ++ modules/ncurses/pdcurses/pdcurses/border.c | 411 ++++ modules/ncurses/pdcurses/pdcurses/clear.c | 159 ++ modules/ncurses/pdcurses/pdcurses/color.c | 296 +++ modules/ncurses/pdcurses/pdcurses/debug.c | 108 + modules/ncurses/pdcurses/pdcurses/delch.c | 96 + modules/ncurses/pdcurses/pdcurses/deleteln.c | 211 ++ modules/ncurses/pdcurses/pdcurses/deprec.c | 27 + modules/ncurses/pdcurses/pdcurses/getch.c | 413 ++++ modules/ncurses/pdcurses/pdcurses/getstr.c | 474 ++++ modules/ncurses/pdcurses/pdcurses/getyx.c | 145 ++ modules/ncurses/pdcurses/pdcurses/inch.c | 127 ++ modules/ncurses/pdcurses/pdcurses/inchstr.c | 214 ++ modules/ncurses/pdcurses/pdcurses/initscr.c | 342 +++ modules/ncurses/pdcurses/pdcurses/inopts.c | 324 +++ modules/ncurses/pdcurses/pdcurses/insch.c | 271 +++ modules/ncurses/pdcurses/pdcurses/insstr.c | 264 +++ modules/ncurses/pdcurses/pdcurses/instr.c | 246 ++ modules/ncurses/pdcurses/pdcurses/kernel.c | 259 +++ modules/ncurses/pdcurses/pdcurses/keyname.c | 131 ++ modules/ncurses/pdcurses/pdcurses/mouse.c | 431 ++++ modules/ncurses/pdcurses/pdcurses/move.c | 57 + modules/ncurses/pdcurses/pdcurses/outopts.c | 159 ++ modules/ncurses/pdcurses/pdcurses/overlay.c | 214 ++ modules/ncurses/pdcurses/pdcurses/pad.c | 260 +++ modules/ncurses/pdcurses/pdcurses/panel.c | 641 ++++++ modules/ncurses/pdcurses/pdcurses/printw.c | 126 ++ modules/ncurses/pdcurses/pdcurses/refresh.c | 279 +++ modules/ncurses/pdcurses/pdcurses/scanw.c | 578 +++++ modules/ncurses/pdcurses/pdcurses/scr_dump.c | 213 ++ modules/ncurses/pdcurses/pdcurses/scroll.c | 101 + modules/ncurses/pdcurses/pdcurses/slk.c | 646 ++++++ modules/ncurses/pdcurses/pdcurses/termattr.c | 172 ++ modules/ncurses/pdcurses/pdcurses/terminfo.c | 217 ++ modules/ncurses/pdcurses/pdcurses/touch.c | 163 ++ modules/ncurses/pdcurses/pdcurses/util.c | 307 +++ modules/ncurses/pdcurses/pdcurses/window.c | 569 +++++ modules/ncurses/pdcurses/term.h | 47 + modules/ncurses/pdcurses/wincon/Makefile | 113 + modules/ncurses/pdcurses/wincon/Makefile.bcc | 86 + modules/ncurses/pdcurses/wincon/Makefile.vc | 120 + modules/ncurses/pdcurses/wincon/Makefile.wcc | 52 + modules/ncurses/pdcurses/wincon/README.md | 70 + modules/ncurses/pdcurses/wincon/pdcclip.c | 150 ++ modules/ncurses/pdcurses/wincon/pdcdisp.c | 160 ++ modules/ncurses/pdcurses/wincon/pdcgetsc.c | 55 + modules/ncurses/pdcurses/wincon/pdckbd.c | 680 ++++++ modules/ncurses/pdcurses/wincon/pdcscrn.c | 677 ++++++ modules/ncurses/pdcurses/wincon/pdcsetsc.c | 117 + modules/ncurses/pdcurses/wincon/pdcurses.ico | Bin 0 -> 1078 bytes modules/ncurses/pdcurses/wincon/pdcurses.rc | 28 + modules/ncurses/pdcurses/wincon/pdcutil.c | 26 + modules/ncurses/pdcurses/wincon/pdcwin.h | 28 + modules/ncurses/tests/test01.wx | 85 + modules/ncurses/tests/test02.wx | 69 + 84 files changed, 23472 insertions(+) create mode 100644 modules/ncurses/README.md create mode 100644 modules/ncurses/makefile_windows.wx create mode 100644 modules/ncurses/module.json create mode 100644 modules/ncurses/ncurses.wx create mode 100644 modules/ncurses/pdcurses/HISTORY.md create mode 100644 modules/ncurses/pdcurses/IMPLEMNT.md create mode 100644 modules/ncurses/pdcurses/README.md create mode 100644 modules/ncurses/pdcurses/curses.h create mode 100644 modules/ncurses/pdcurses/curspriv.h create mode 100644 modules/ncurses/pdcurses/demos/README.md create mode 100644 modules/ncurses/pdcurses/demos/firework.c create mode 100644 modules/ncurses/pdcurses/demos/nctests.mif create mode 100644 modules/ncurses/pdcurses/demos/ncurses_cfg.h create mode 100644 modules/ncurses/pdcurses/demos/ozdemo.c create mode 100644 modules/ncurses/pdcurses/demos/ptest.c create mode 100644 modules/ncurses/pdcurses/demos/rain.c create mode 100644 modules/ncurses/pdcurses/demos/testcurs.c create mode 100644 modules/ncurses/pdcurses/demos/tui.c create mode 100644 modules/ncurses/pdcurses/demos/tui.h create mode 100644 modules/ncurses/pdcurses/demos/tuidemo.c create mode 100644 modules/ncurses/pdcurses/demos/worm.c create mode 100644 modules/ncurses/pdcurses/demos/xmas.c create mode 100644 modules/ncurses/pdcurses/panel.h create mode 100644 modules/ncurses/pdcurses/pdcurses/README.md create mode 100644 modules/ncurses/pdcurses/pdcurses/addch.c create mode 100644 modules/ncurses/pdcurses/pdcurses/addchstr.c create mode 100644 modules/ncurses/pdcurses/pdcurses/addstr.c create mode 100644 modules/ncurses/pdcurses/pdcurses/attr.c create mode 100644 modules/ncurses/pdcurses/pdcurses/beep.c create mode 100644 modules/ncurses/pdcurses/pdcurses/bkgd.c create mode 100644 modules/ncurses/pdcurses/pdcurses/border.c create mode 100644 modules/ncurses/pdcurses/pdcurses/clear.c create mode 100644 modules/ncurses/pdcurses/pdcurses/color.c create mode 100644 modules/ncurses/pdcurses/pdcurses/debug.c create mode 100644 modules/ncurses/pdcurses/pdcurses/delch.c create mode 100644 modules/ncurses/pdcurses/pdcurses/deleteln.c create mode 100644 modules/ncurses/pdcurses/pdcurses/deprec.c create mode 100644 modules/ncurses/pdcurses/pdcurses/getch.c create mode 100644 modules/ncurses/pdcurses/pdcurses/getstr.c create mode 100644 modules/ncurses/pdcurses/pdcurses/getyx.c create mode 100644 modules/ncurses/pdcurses/pdcurses/inch.c create mode 100644 modules/ncurses/pdcurses/pdcurses/inchstr.c create mode 100644 modules/ncurses/pdcurses/pdcurses/initscr.c create mode 100644 modules/ncurses/pdcurses/pdcurses/inopts.c create mode 100644 modules/ncurses/pdcurses/pdcurses/insch.c create mode 100644 modules/ncurses/pdcurses/pdcurses/insstr.c create mode 100644 modules/ncurses/pdcurses/pdcurses/instr.c create mode 100644 modules/ncurses/pdcurses/pdcurses/kernel.c create mode 100644 modules/ncurses/pdcurses/pdcurses/keyname.c create mode 100644 modules/ncurses/pdcurses/pdcurses/mouse.c create mode 100644 modules/ncurses/pdcurses/pdcurses/move.c create mode 100644 modules/ncurses/pdcurses/pdcurses/outopts.c create mode 100644 modules/ncurses/pdcurses/pdcurses/overlay.c create mode 100644 modules/ncurses/pdcurses/pdcurses/pad.c create mode 100644 modules/ncurses/pdcurses/pdcurses/panel.c create mode 100644 modules/ncurses/pdcurses/pdcurses/printw.c create mode 100644 modules/ncurses/pdcurses/pdcurses/refresh.c create mode 100644 modules/ncurses/pdcurses/pdcurses/scanw.c create mode 100644 modules/ncurses/pdcurses/pdcurses/scr_dump.c create mode 100644 modules/ncurses/pdcurses/pdcurses/scroll.c create mode 100644 modules/ncurses/pdcurses/pdcurses/slk.c create mode 100644 modules/ncurses/pdcurses/pdcurses/termattr.c create mode 100644 modules/ncurses/pdcurses/pdcurses/terminfo.c create mode 100644 modules/ncurses/pdcurses/pdcurses/touch.c create mode 100644 modules/ncurses/pdcurses/pdcurses/util.c create mode 100644 modules/ncurses/pdcurses/pdcurses/window.c create mode 100644 modules/ncurses/pdcurses/term.h create mode 100644 modules/ncurses/pdcurses/wincon/Makefile create mode 100644 modules/ncurses/pdcurses/wincon/Makefile.bcc create mode 100644 modules/ncurses/pdcurses/wincon/Makefile.vc create mode 100644 modules/ncurses/pdcurses/wincon/Makefile.wcc create mode 100644 modules/ncurses/pdcurses/wincon/README.md create mode 100644 modules/ncurses/pdcurses/wincon/pdcclip.c create mode 100644 modules/ncurses/pdcurses/wincon/pdcdisp.c create mode 100644 modules/ncurses/pdcurses/wincon/pdcgetsc.c create mode 100644 modules/ncurses/pdcurses/wincon/pdckbd.c create mode 100644 modules/ncurses/pdcurses/wincon/pdcscrn.c create mode 100644 modules/ncurses/pdcurses/wincon/pdcsetsc.c create mode 100644 modules/ncurses/pdcurses/wincon/pdcurses.ico create mode 100644 modules/ncurses/pdcurses/wincon/pdcurses.rc create mode 100644 modules/ncurses/pdcurses/wincon/pdcutil.c create mode 100644 modules/ncurses/pdcurses/wincon/pdcwin.h create mode 100644 modules/ncurses/tests/test01.wx create mode 100644 modules/ncurses/tests/test02.wx diff --git a/modules/ncurses/README.md b/modules/ncurses/README.md new file mode 100644 index 00000000..79f0decf --- /dev/null +++ b/modules/ncurses/README.md @@ -0,0 +1,15 @@ +# ncurses + +A [curses](http://www.tldp.org/HOWTO/html_single/NCURSES-Programming-HOWTO/) library wrapper for Wonkey that supports Windows, Linux, and macOS + +On Windows [PDCurses](https://github.com/wmcbrine/PDCurses) is used. + +On Linux and macOS [Ncurses](https://en.wikipedia.org/wiki/Ncurses) is used. + + +## Instructions +* On Linux you will need to install 'ncurses-dev' (sudo apt install ncurses-dev) +* On macOS you will need to install 'ncurses' (using Homebrew or Cakebrew) +* Recompile module "ncurses" +* Compile tests inside the ‘tests’ folder +* Run tests via your ‘products’ folder and not via Wide diff --git a/modules/ncurses/makefile_windows.wx b/modules/ncurses/makefile_windows.wx new file mode 100644 index 00000000..2ce006c3 --- /dev/null +++ b/modules/ncurses/makefile_windows.wx @@ -0,0 +1,56 @@ +Namespace ncurses + +#Import "" + +#Import "pdcurses/*.h" + +#Import "pdcurses/pdcurses/addch.c" +#Import "pdcurses/pdcurses/addchstr.c" +#Import "pdcurses/pdcurses/addstr.c" +#Import "pdcurses/pdcurses/attr.c" +#Import "pdcurses/pdcurses/beep.c" +#Import "pdcurses/pdcurses/bkgd.c" +#Import "pdcurses/pdcurses/border.c" +#Import "pdcurses/pdcurses/clear.c" +#Import "pdcurses/pdcurses/color.c" +#Import "pdcurses/pdcurses/debug.c" +#Import "pdcurses/pdcurses/delch.c" +#Import "pdcurses/pdcurses/deleteln.c" +#Import "pdcurses/pdcurses/deprec.c" +#Import "pdcurses/pdcurses/getch.c" +#Import "pdcurses/pdcurses/getstr.c" +#Import "pdcurses/pdcurses/getyx.c" +#Import "pdcurses/pdcurses/inch.c" +#Import "pdcurses/pdcurses/inchstr.c" +#Import "pdcurses/pdcurses/initscr.c" +#Import "pdcurses/pdcurses/inopts.c" +#Import "pdcurses/pdcurses/insch.c" +#Import "pdcurses/pdcurses/insstr.c" +#Import "pdcurses/pdcurses/instr.c" +#Import "pdcurses/pdcurses/kernel.c" +#Import "pdcurses/pdcurses/keyname.c" +#Import "pdcurses/pdcurses/mouse.c" +#Import "pdcurses/pdcurses/move.c" +#Import "pdcurses/pdcurses/outopts.c" +#Import "pdcurses/pdcurses/overlay.c" +#Import "pdcurses/pdcurses/pad.c" +#Import "pdcurses/pdcurses/panel.c" +#Import "pdcurses/pdcurses/printw.c" +#Import "pdcurses/pdcurses/refresh.c" +#Import "pdcurses/pdcurses/scanw.c" +#Import "pdcurses/pdcurses/scroll.c" +#Import "pdcurses/pdcurses/scr_dump.c" +#Import "pdcurses/pdcurses/slk.c" +#Import "pdcurses/pdcurses/termattr.c" +#Import "pdcurses/pdcurses/terminfo.c" +#Import "pdcurses/pdcurses/touch.c" +#Import "pdcurses/pdcurses/util.c" +#Import "pdcurses/pdcurses/window.c" + +#Import "pdcurses/wincon/pdcclip.c" +#Import "pdcurses/wincon/pdcdisp.c" +#Import "pdcurses/wincon/pdcgetsc.c" +#Import "pdcurses/wincon/pdckbd.c" +#Import "pdcurses/wincon/pdcscrn.c" +#Import "pdcurses/wincon/pdcsetsc.c" +#Import "pdcurses/wincon/pdcutil.c" \ No newline at end of file diff --git a/modules/ncurses/module.json b/modules/ncurses/module.json new file mode 100644 index 00000000..64aec642 --- /dev/null +++ b/modules/ncurses/module.json @@ -0,0 +1,7 @@ +{ + "module":"ncurses", + "about":"ncurses library wrapper", + "author":"Rob C", + "version":"1.0.0", + "depends":["libc"] +} \ No newline at end of file diff --git a/modules/ncurses/ncurses.wx b/modules/ncurses/ncurses.wx new file mode 100644 index 00000000..ae5bb7fe --- /dev/null +++ b/modules/ncurses/ncurses.wx @@ -0,0 +1,601 @@ +#rem + + ncurses library import for Wonkey + + Author: Rob C + +#end +Namespace ncurses + +#Import "" +#Import "" +Using std.. +Using libc.. + +#If __TARGET__="windows" + + #Import "makefile_windows" + #Import "" + +#ElseIf __TARGET__="macos" + + '#Import "makefile_macos" + #Import "" + #Import "" + +#ElseIf __TARGET__="linux" + + #Import "" + #Import "" + +#Endif + +Extern + + Class Window Extends Void="WINDOW" + End + + Class Screen Extends Void="SCREEN" + End + + Struct mmask_t + End + + Struct MouseEvent="MEVENT" + field id:Short + field x:Int + field y:Int + field z:Int + field bstate:mmask_t + End + + Const ALL_MOUSE_EVENTS:mmask_t + + Const OK:Int + + Const KEY_CODE_YES:Int + Const KEY_BREAK:Int + Const KEY_DOWN:Int + Const KEY_UP:Int + Const KEY_LEFT:Int + Const KEY_RIGHT:Int + Const KEY_HOME:Int + Const KEY_BACKSPACE:Int + Const KEY_F0:Int + Const KEY_DL:Int + Const KEY_IL:Int + Const KEY_DC:Int + Const KEY_IC:Int + Const KEY_EIC:Int + Const KEY_CLEAR:Int + Const KEY_EOS:Int + Const KEY_EOL:Int + Const KEY_SF:Int + Const KEY_SR:Int + Const KEY_NPAGE:Int + Const KEY_PPAGE:Int + Const KEY_STAB:Int + Const KEY_CTAB:Int + Const KEY_CATAB:Int + Const KEY_ENTER:Int + Const KEY_SRESET:Int + Const KEY_RESET:Int + Const KEY_PRINT:Int + Const KEY_LL:Int + Const KEY_ABORT:Int + Const KEY_SHELP:Int + Const KEY_LHELP:Int + Const KEY_BTAB:Int + Const KEY_BEG:Int + Const KEY_CANCEL:Int + Const KEY_CLOSE:Int + Const KEY_COMMAND:Int + Const KEY_COPY:Int + Const KEY_CREATE:Int + Const KEY_END:Int + Const KEY_EXIT:Int + Const KEY_FIND:Int + Const KEY_HELP:Int + Const KEY_MARK:Int + Const KEY_MESSAGE:Int + Const KEY_MOVE:Int + Const KEY_NEXT:Int + Const KEY_OPEN:Int + Const KEY_OPTIONS:Int + Const KEY_PREVIOUS:Int + Const KEY_REDO:Int + Const KEY_REFERENCE:Int + Const KEY_REFRESH:Int + Const KEY_REPLACE:Int + Const KEY_RESTART:Int + Const KEY_RESUME:Int + Const KEY_SAVE:Int + Const KEY_SBEG:Int + Const KEY_SCANCEL:Int + Const KEY_SCOMMAND:Int + Const KEY_SCOPY:Int + Const KEY_SCREATE:Int + Const KEY_SDC:Int + Const KEY_SDL:Int + Const KEY_SELECT:Int + Const KEY_SEND:Int + Const KEY_SEOL:Int + Const KEY_SEXIT:Int + Const KEY_SFIND:Int + Const KEY_SHOME:Int + Const KEY_SIC:Int + Const KEY_SLEFT:Int + Const KEY_SMESSAGE:Int + Const KEY_SMOVE:Int + Const KEY_SNEXT:Int + Const KEY_SOPTIONS:Int + Const KEY_SPREVIOUS:Int + Const KEY_SPRINT:Int + Const KEY_SREDO:Int + Const KEY_SREPLACE:Int + Const KEY_SRIGHT:Int + Const KEY_SRSUME:Int + Const KEY_SSAVE:Int + Const KEY_SSUSPEND:Int + Const KEY_SUNDO:Int + Const KEY_SUSPEND:Int + Const KEY_UNDO:Int + + Const stdscr:Window + Const A_STANDOUT:Int + Const A_UNDERLINE:Int + Const A_REVERSE:Int + Const A_PROTECT:Int + Const A_INVIS:Int + Const A_DIM:Int + Const A_BOLD:Int + Const A_BLINK:Int + Const A_ALTCHARSET:Int + + Const A_ATTRIBUTES:Int + Const A_CHARTEXT:Int + Const A_COLOR:Int + + Global COLS:Int + Global LINES:Int + + Const COLOR_BLACK:Int + Const COLOR_BLUE:Int + Const COLOR_GREEN:Int + Const COLOR_CYAN:Int + Const COLOR_RED:Int + Const COLOR_MAGENTA:Int + Const COLOR_YELLOW:Int + Const COLOR_WHITE:Int + + #If __TARGET__="windows" + Function getmouse:Int(event:MouseEvent Ptr)="nc_getmouse" + #Else + Function getmouse:Int(event:MouseEvent Ptr) + #Endif + + '/Standard / + + Function addch:Int( Int ) + Function addchnstr:Int( Int, Int ) + Function addchstr:Int( Int ) + Function addnstr:Int( CString, Int ) + Function addstr:Int( CString ) + Function attroff:Int( Int ) + Function attron:Int( Int ) + Function attrset:Int( Int ) + Function attr_get:Int( attribute:Int, Short ) + Function attr_off:Int( attribute:Int ) + Function attr_on:Int( attribute:Int ) + Function attr_set:Int( attribute:Int, Short ) + Function baudrate:Int() + Function beep:Int() + Function bkgd:Int( Int ) + Function bkgdset:Void( Int ) + Function border:Int( Int, Int, Int, Int, Int, Int, Int, Int ) + Function box:Int( window:Window, Int, Int ) + Function can_change_color:Bool() + Function cbreak:Int() + Function chgat:Int( Int, attribute:Int, Short ) + Function clearok:Int( window:Window, Bool ) + Function clear:Int() + Function clrtobot:Int() + Function clrtoeol:Int() + Function color_content:Int( Short, Short, Short, Short ) + Function color_set:Int( Short ) + Function copywin:Int( window:Window, Window, Int, Int, Int, Int, Int, Int, Int ) + Function curs_set:Int( Int ) + Function def_prog_mode:Int() + Function def_shell_mode:Int() + Function delay_output:Int( Int ) + Function delch:Int() + Function deleteln:Int() + Function delscreen:Void( Screen ) + Function delwin:Int( window:Window ) + Function derwin:Window( window:Window, Int, Int, Int, Int ) + Function doupdate:Int() + Function dupwin:Window( window:Window ) + Function echochar:Int( Int ) + Function echo:Int() + Function endwin:Int() + Function erasechar:CString() + Function erase:Int() + Function filter:Void() + Function flash:Int() + Function flushinp:Int() + Function getbkgd:Int( window:Window ) + Function getnstr:Int( CString, Int ) + Function getstr:Int( CString ) + Function getwin:Window( FILE ) + Function halfdelay:Int( Int ) + Function has_colors:Bool() + Function has_ic:Bool() + Function has_il:Bool() + Function hline:Int( Int, Int ) + Function idcok:Void( window:Window, Bool ) + Function idlok:Int( window:Window, Bool ) + Function immedok:Void( window:Window, Bool ) + Function inchnstr:Int( Int, Int ) + Function inchstr:Int( Int ) + Function inch:Int() + Function init_color:Int( color:Short, r:Short, g:Short, b:Short ) + Function init_pair:Int( pair:Short, fg:Short, bg:Short ) + Function initscr:Window() + Function innstr:Int( CString, Int ) + Function insch:Int( Int ) + Function insdelln:Int( Int ) + Function insertln:Int() + Function insnstr:Int( CString, Int ) + Function insstr:Int( CString ) + Function instr:Int( CString ) + Function intrflush:Int( window:Window, Bool ) + Function isendwin:Bool() + Function is_linetouched:Bool( window:Window, Int ) + Function is_wintouched:Bool( window:Window ) + Function keyname:CString( Int ) + Function keypad:Int( window:Window, Bool ) + Function killchar:CString() + Function leaveok:Int( window:Window, Bool ) + Function longname:CString() + Function meta:Int( window:Window, Bool ) + Function move:Int( Int, Int ) + Function mvaddch:Int( Int, Int, Int ) + Function mvaddchnstr:Int( Int, Int, Int, Int ) + Function mvaddchstr:Int( Int, Int, Int ) + Function mvaddnstr:Int( Int, Int, CString, Int ) + Function mvaddstr:Int( Int, Int, CString ) + Function mvchgat:Int( Int, Int, Int, attribute:Int, Short ) + Function mvcur:Int( Int, Int, Int, Int ) + Function mvdelch:Int( Int, Int ) + Function mvderwin:Int( window:Window, Int, Int ) + Function mvgetch:Int( Int, Int ) + Function mvgetnstr:Int( Int, Int, CString, Int ) + Function mvgetstr:Int( Int, Int, CString ) + Function mvhline:Int( Int, Int, Int, Int ) + Function mvinch:Int( Int, Int ) + Function mvinchnstr:Int( Int, Int, Int, Int ) + Function mvinchstr:Int( Int, Int, Int ) + Function mvinnstr:Int( Int, Int, CString, Int ) + Function mvinsch:Int( Int, Int, Int ) + Function mvinsnstr:Int( Int, Int, CString, Int ) + Function mvinsstr:Int( Int, Int, CString ) + Function mvinstr:Int( Int, Int, CString ) + Function mvprintw:Int( Int, Int, CString ) + Function mvscanw:Int( Int, Int, CString ) + Function mvvline:Int( Int, Int, Int, Int ) + Function mvwaddchnstr:Int( window:Window, Int, Int, Int, Int ) + Function mvwaddchstr:Int( window:Window, Int, Int, Int ) + Function mvwaddch:Int( window:Window, Int, Int, Int ) + Function mvwaddnstr:Int( window:Window, Int, Int, CString, Int ) + Function mvwaddstr:Int( window:Window, Int, Int, CString ) + Function mvwchgat:Int( window:Window, Int, Int, Int, attribute:Int, Short ) + Function mvwdelch:Int( window:Window, Int, Int ) + Function mvwgetch:Int( window:Window, Int, Int ) + Function mvwgetnstr:Int( window:Window, Int, Int, CString, Int ) + Function mvwgetstr:Int( window:Window, Int, Int, CString ) + Function mvwhline:Int( window:Window, Int, Int, Int, Int ) + Function mvwinchnstr:Int( window:Window, Int, Int, Int, Int ) + Function mvwinchstr:Int( window:Window, Int, Int, Int ) + Function mvwinch:Int( window:Window, Int, Int ) + Function mvwinnstr:Int( window:Window, Int, Int, CString, Int ) + Function mvwinsch:Int( window:Window, Int, Int, Int ) + Function mvwinsnstr:Int( window:Window, Int, Int, CString, Int ) + Function mvwinsstr:Int( window:Window, Int, Int, CString ) + Function mvwinstr:Int( window:Window, Int, Int, CString ) + Function mvwin:Int( window:Window, y:Int, x:Int ) + Function mvwprintw:Int( window:Window, Int, Int, CString ) + Function mvwscanw:Int( window:Window, Int, Int, CString ) + Function mvwvline:Int( window:Window, Int, Int, Int, Int ) + Function napms:Int( Int ) + Function newpad:Window( Int, Int ) + Function newterm:Screen( CString, FILE, FILE ) + Function newwin:Window( w:Int, h:Int, x:Int, y:Int ) + Function nl:Int() + Function nocbreak:Int() + Function nodelay:Int( window:Window, Bool ) + Function noecho:Int() + Function nonl:Int() + Function noqiflush:Void() + Function noraw:Int() + Function notimeout:Int( window:Window, Bool ) + Function overlay:Int( window:Window, Window ) + Function overwrite:Int( window:Window, Window ) + Function pair_content:Int( Short, Short, Short ) + Function pechochar:Int( window:Window, Int ) + Function pnoutrefresh:Int( window:Window, Int, Int, Int, Int, Int, Int ) + Function prefresh:Int( window:Window, Int, Int, Int, Int, Int, Int ) + Function printw:Int( CString ) + Function putwin:Int( window:Window, FILE ) + Function qiflush:Void() + Function raw:Int() + Function redrawwin:Int( window:Window ) + Function refresh:Int() + Function reset_prog_mode:Int() + Function reset_shell_mode:Int() + Function resetty:Int() + Function ripoffline:Int( Int, func:Int(Window, int) ) + Function savetty:Int() + Function scanw:Int( CString ) + Function scr_dump:Int( CString ) + Function scr_init:Int( CString ) + Function scr_restore:Int( CString ) + Function scr_set:Int( CString ) + Function scrl:Int( Int ) + Function scroll:Int( window:Window ) + Function scrollok:Int( window:Window, Bool ) + Function set_term:Screen( Screen ) + Function setscrreg:Int( Int, Int ) + Function slk_attroff:Int( Int ) + Function slk_attr_off:Int( attribute:Int ) + Function slk_attron:Int( Int ) + Function slk_attr_on:Int( attribute:Int ) + Function slk_attrset:Int( Int ) + Function slk_attr_set:Int( attribute:Int, Short ) + Function slk_clear:Int() + Function slk_color:Int( Short ) + Function slk_init:Int( Int ) + Function slk_label:CString( Int ) + Function slk_noutrefresh:Int() + Function slk_refresh:Int() + Function slk_restore:Int() + Function slk_set:Int( Int, CString, Int ) + Function slk_touch:Int() + Function standend:Int() + Function standout:Int() + Function start_color:Int() + Function subpad:Window( window:Window, Int, Int, Int, Int ) + Function subwin:Window( window:Window, Int, Int, Int, Int ) + Function syncok:Int( window:Window, Bool ) + Function termattrs:Int() + Function term_attrs:Int() + Function termname:CString() + Function timeout:Void( Int ) + Function touchline:Int( window:Window, Int, Int ) + Function touchwin:Int( window:Window ) + Function typeahead:Int( Int ) + Function untouchwin:Int( window:Window ) + Function use_env:Void( Bool ) + Function vidattr:Int( Int ) + Function vid_attr:Int( attribute:Int, Short ) + Function vidputs:Int( Int, func:Int( Int ) ) + Function vid_puts:Int( attribute:Int, Short, void, func:Int( Int ) ) + Function vline:Int( Int, Int ) +' Function vw_printw:Int( window:Window, CString, va_list ) +' Function vwprintw:Int( window:Window, CString, va_list ) +' Function vw_scanw:Int( window:Window, CString, va_list ) +' Function vwscanw:Int( window:Window, CString, va_list ) + Function waddchnstr:Int( window:Window, Int, Int ) + Function waddchstr:Int( window:Window, Int ) + Function waddch:Int( window:Window, Int ) + Function waddnstr:Int( window:Window, CString, Int ) + Function waddstr:Int( window:Window, CString ) + Function wattroff:Int( window:Window, Int ) + Function wattron:Int( window:Window, Int ) + Function wattrset:Int( window:Window, Int ) + Function wattr_get:Int( window:Window, attribute:Int, Short ) + Function wattr_off:Int( window:Window, attribute:Int ) + Function wattr_on:Int( window:Window, attribute:Int ) + Function wattr_set:Int( window:Window, attribute:Int, Short ) + Function wbkgdset:Void( window:Window, Int ) + Function wbkgd:Int( window:Window, Int ) + Function wborder:Int( window:Window, Int, Int, Int, Int, Int, Int, Int, Int ) + Function wchgat:Int( window:Window, Int, attribute:Int, Short ) + Function wclear:Int( window:Window ) + Function wclrtobot:Int( window:Window ) + Function wclrtoeol:Int( window:Window ) + Function wcolor_set:Int( window:Window, Short ) + Function wcursyncup:Void( window:Window ) + Function wdelch:Int( window:Window ) + Function wdeleteln:Int( window:Window ) + Function wechochar:Int( window:Window, Int ) + Function werase:Int( window:Window ) + Function wgetch:Int( window:Window ) + Function wgetnstr:Int( window:Window, CString, Int ) + Function wgetstr:Int( window:Window, CString ) + Function whline:Int( window:Window, Int, Int ) + Function winchnstr:Int( window:Window, Int, Int ) + Function winchstr:Int( window:Window, Int ) + Function winch:Int( window:Window ) + Function winnstr:Int( window:Window, CString, Int ) + Function winsch:Int( window:Window, Int ) + Function winsdelln:Int( window:Window, Int ) + Function winsertln:Int( window:Window ) + Function winsnstr:Int( window:Window, CString, Int ) + Function winsstr:Int( window:Window, CString ) + Function winstr:Int( window:Window, CString ) + Function wmove:Int( window:Window, Int, Int ) + Function wnoutrefresh:Int( window:Window ) + Function wprintw:Int( window:Window, CString ) + Function wredrawln:Int( window:Window, Int, Int ) + Function wrefresh:Int( window:Window ) + Function wscanw:Int( window:Window, CString ) + Function wscrl:Int( window:Window, Int ) + Function wsetscrreg:Int( window:Window, Int, Int ) + Function wstandend:Int( window:Window ) + Function wstandout:Int( window:Window ) + Function wsyncdown:Void( window:Window ) + Function wsyncup:Void( window:Window ) + Function wtimeout:Void( window:Window, Int ) + Function wtouchln:Int( window:Window, Int, Int, Int ) + Function wvline:Int( window:Window, Int, Int ) + + '/Wide-character functions / + + #rem PDC_WIDE + Function int addnwstr( wchar_t, Int ) + Function int addwstr( wchar_t ) + Function int add_wch( cchar_t ) + Function int add_wchnstr( cchar_t, Int ) + Function int add_wchstr( cchar_t ) + Function int bkgrnd( cchar_t ) + Function void bkgrndset( cchar_t ) + Function int border_set( cchar_t, cchar_t, cchar_t , + cchar_t, cchar_t, cchar_t , + cchar_t, cchar_t ) + Function int box_set(Window, cchar_t, cchar_t ) + Function int echo_wchar( cchar_t ) + Function int erasewchar(wchar_t ) + Function int getbkgrnd(cchar_t ) + Function int getcchar( cchar_t, wchar_t, attribute:Int, Short ) + Function int getn_wstr(wint_t, Int ) + Function int get_wch(wint_t ) + Function int get_wstr(wint_t ) + Function int hline_set( cchar_t, Int ) + Function int innwstr(wchar_t, Int ) + Function int ins_nwstr( wchar_t, Int ) + Function int ins_wch( cchar_t ) + Function int ins_wstr( wchar_t ) + Function int inwstr(wchar_t ) + Function int in_wch(cchar_t ) + Function int in_wchnstr(cchar_t, Int ) + Function int in_wchstr(cchar_t ) + Function CString key_name(wchar_t ) + Function int killwchar(wchar_t ) + Function int mvaddnwstr(Int, Int, wchar_t, Int ) + Function int mvaddwstr(Int, Int, wchar_t ) + Function int mvadd_wch(Int, Int, cchar_t ) + Function int mvadd_wchnstr(Int, Int, cchar_t, Int ) + Function int mvadd_wchstr(Int, Int, cchar_t ) + Function int mvgetn_wstr(Int, Int, wint_t, Int ) + Function int mvget_wch(Int, Int, wint_t ) + Function int mvget_wstr(Int, Int, wint_t ) + Function int mvhline_set(Int, Int, cchar_t, Int ) + Function int mvinnwstr(Int, Int, wchar_t, Int ) + Function int mvins_nwstr(Int, Int, wchar_t, Int ) + Function int mvins_wch(Int, Int, cchar_t ) + Function int mvins_wstr(Int, Int, wchar_t ) + Function int mvinwstr(Int, Int, wchar_t ) + Function int mvin_wch(Int, Int, cchar_t ) + Function int mvin_wchnstr(Int, Int, cchar_t, Int ) + Function int mvin_wchstr(Int, Int, cchar_t ) + Function int mvvline_set(Int, Int, cchar_t, Int ) + Function int mvwaddnwstr(Window, Int, Int, wchar_t, Int ) + Function int mvwaddwstr(Window, Int, Int, wchar_t ) + Function int mvwadd_wch(Window, Int, Int, cchar_t ) + Function int mvwadd_wchnstr(Window, Int, Int, cchar_t, Int ) + Function int mvwadd_wchstr(Window, Int, Int, cchar_t ) + Function int mvwgetn_wstr(Window, Int, Int, wint_t, Int ) + Function int mvwget_wch(Window, Int, Int, wint_t ) + Function int mvwget_wstr(Window, Int, Int, wint_t ) + Function int mvwhline_set(Window, Int, Int, cchar_t, Int ) + Function int mvwinnwstr(Window, Int, Int, wchar_t, Int ) + Function int mvwins_nwstr(Window, Int, Int, wchar_t, Int ) + Function int mvwins_wch(Window, Int, Int, cchar_t ) + Function int mvwins_wstr(Window, Int, Int, wchar_t ) + Function int mvwin_wch(Window, Int, Int, cchar_t ) + Function int mvwin_wchnstr(Window, Int, Int, cchar_t, Int ) + Function int mvwin_wchstr(Window, Int, Int, cchar_t ) + Function int mvwinwstr(Window, Int, Int, wchar_t ) + Function int mvwvline_set(Window, Int, Int, cchar_t, Int ) + Function int pecho_wchar(Window, cchar_t) + Function int setcchar(cchar_t, wchar_t, attribute:Int, + Short, void) + Function int slk_wset(Int, wchar_t, Int ) + Function int unget_wch( wchar_t ) + Function int vline_set( cchar_t, Int ) + Function int waddnwstr(Window, wchar_t, Int ) + Function int waddwstr(Window, wchar_t ) + Function int wadd_wch(Window, cchar_t ) + Function int wadd_wchnstr(Window, cchar_t, Int ) + Function int wadd_wchstr(Window, cchar_t ) + Function int wbkgrnd(Window, cchar_t ) + Function void wbkgrndset(Window, cchar_t ) + Function int wborder_set(Window, cchar_t, cchar_t , + cchar_t, cchar_t, cchar_t , + cchar_t, cchar_t, cchar_t ) + Function int wecho_wchar(Window, cchar_t ) + Function int wgetbkgrnd(Window, cchar_t ) + Function int wgetn_wstr(Window, wint_t, Int ) + Function int wget_wch(Window, wint_t ) + Function int wget_wstr(Window, wint_t ) + Function int whline_set(Window, cchar_t, Int ) + Function int winnwstr(Window, wchar_t, Int ) + Function int wins_nwstr(Window, wchar_t, Int ) + Function int wins_wch(Window, cchar_t ) + Function int wins_wstr(Window, wchar_t ) + Function int winwstr(Window, wchar_t ) + Function int win_wch(Window, cchar_t ) + Function int win_wchnstr(Window, cchar_t, Int ) + Function int win_wchstr(Window, cchar_t ) + Function wchar_t wunctrl(cchar_t ) + Function int wvline_set(Window, cchar_t, Int ) + #end + + '/Quasi-standard / + + Function getattrs:Int( window:Window ) + Function getbegx:Int( window:Window ) + Function getbegy:Int( window:Window ) + Function getmaxx:Int( window:Window ) + Function getmaxy:Int( window:Window ) + Function getparx:Int( window:Window ) + Function getpary:Int( window:Window ) + Function getcurx:Int( window:Window ) + Function getcury:Int( window:Window ) + Function traceoff:Void() + Function traceon:Void() + Function unctrl:CString( Int ) + Function crmode:Int() + Function nocrmode:Int() + Function draino:Int( Int ) + Function resetterm:Int() + Function fixterm:Int() + Function saveterm:Int() + Function setsyx:Int( Int, Int ) + Function mouse_set:Int( ULong ) + Function mouse_on:Int( ULong ) + Function mouse_off:Int( ULong ) + Function request_mouse_pos:Int() + Function map_button:Int( ULong ) + Function wmouse_position:Void( window:Window, Int, Int ) +' Function getmouse:ULong() + Function getbmap:ULong() + + '/ncurses / + + Function assume_default_colors:Int( fg:Int, bg:Int ) + Function curses_version:CString() + Function has_key:Bool( Int ) + Function use_default_colors:Int() + Function wresize:Int( window:Window, Int, Int ) + Function mouseinterval:Int( Int ) + Function mousemask:mmask_t( mmask_t, mmask_t Ptr ) + Function mouse_trafo:Bool( Int, Int, Bool ) +' Function nc_getmouse:Int( MouseEvent ) + Function ungetmouse:Int( MouseEvent ) + Function wenclose:Bool( window:Window, Int, Int ) + Function wmouse_trafo:Bool( window:Window, Int, Int, Bool ) + + '/*** Functions defined as macros ** + + Function getch:Int() + + Function COLOR_PAIR:Int( pair:Int ) + Function PAIR_NUMBER:Int( number:Int ) + + Function getbegyx( w:Window, y:Int Ptr, x:Int Ptr ) + Function getmaxyx( w:Window, y:Int, x:Int ) + Function getparyx( w:Window, y:Int Ptr, x:Int Ptr ) + Function getyx( w:Window, y:Int Ptr, x:Int Ptr ) + + Function getsyx( y:Int Ptr, x:Int Ptr ) diff --git a/modules/ncurses/pdcurses/HISTORY.md b/modules/ncurses/pdcurses/HISTORY.md new file mode 100644 index 00000000..6e041f41 --- /dev/null +++ b/modules/ncurses/pdcurses/HISTORY.md @@ -0,0 +1,2114 @@ +PDCurses 3.5 - 2018/01/15 +========================= + +So, it's been a while, eh? + +This release is an attempt to bring PDCurses mostly up to date, without +breaking too many things in the process. + + +New features +------------ + +- SDL2 port, and TTF and Unicode support for both SDL1 and SDL2. Credit + for these goes mostly to Laura Michaels and Robin Gustafsson. + +- 256 colors for SDL and X11, by Bill Gray. Colors 16-255 are set up to + match xterm colors, but can be redefined, as with 0-15. + +- Bold and italic font options for SDL and X11. A_BOLD's behavior is + controlled by the new function PDC_set_bold() -- TRUE to select bold + font, FALSE to choose high foregound intensity (as before). Italic + fonts are selected by A_ITALIC (always on). X11 originally from Mark + Hessling. + +- Real blinking in SDL and X11, controlled by PDC_set_blink(). Largely + due to Kevin Lamonte and Bill Gray. + +- Support for A_UNDERLINE, A_LEFTLINE and A_RIGHTLINE in the Windows + console. This requires a recent version of Windows (10, maybe 8?) to + work with the standard console, but underlining also works with + ConEmu, at least as far back as XP. + +- User resizing (i.e. grab window edges or maximize button) for Windows + console -- needs recent Windows or ConEmu. + +- New-style color-changing code for the Windows console (using the new + offical API instead of undocumented functions), supporting + redefinition of colors 0-15 via init_color(). Works at least as far + back as Windows XP SP3. Patch by "Didrole". + +- The Windows console port now creates a separate console buffer by + default, making for a cleaner and more complete restoration of the + original buffer. The old behavior can be used by setting + "PDC_RESTORE_SCREEN=0". Patch by Jason Hood. + +- Left/right scroll wheel support for Windows console, SDL and X11. X11 + by Mark Hessling. + +- testcurs now includes an additional test to show various attributes, + and a display of the extended colors, where applicable. + + +Bug fixes and such +------------------ + +- termattrs() now returns something vaguely resembling the actual + capabilities of the specific "terminal". Specifically, A_BOLD and + A_BLINK reflect the availability of true bold fonts, and real + blinking; when not set in termattrs(), the attributes still work, but + control foreground and background intensity, as before. *LINE are also + meaningful, and even A_COLOR is set (or not). + +- pad size check in pnoutrefresh() was broken since 3.0. Reported by + Peter Hull. + +- In newpad(), begx and begy should be set to zero, otherwise creating a + subpad of the same width or height fails due to the check in subpad(). + Patch by Raphael Assenat. + +- More straightforward math for subpad(), plus another off-by-one error. + Reported by Werner Wenzel, John Hartmann et al. + +- New subwindows/subpads/resized windows should copy _delayms. Patch by + "xaizek". + +- Potentially invalid saved cursor position in resize_window() -- + another off-by-one _maxx/_maxy error. Patch after "Luke-Jr". + +- copywin() needs to disallow corner values equal to _maxx or _maxy, not + just less than. Reported by "Aleksandr". + +- Misaligned soft-label keys in 4-4-4 mode. Reported by Werner Wenzel. + +- Missing prototypes for bkgrnd() and bkgrndset(). + +- Missing WA_NORMAL and WA_ATTRIBUTES from the X/Open spec. + +- keyname() and termname() now return static buffers, as documented. + +- In the X11 port, due to (post-PDCurses-3.4) changes in Xt, + XtAppMainLoop() always hung. Fixed by re-implementing it within + PDCurses, basically. + +- Fix blinking X11 cursor for clients that call move() more frequently + than cursorBlinkRate -- patch by Kevin Lamonte. + +- Improved cursor rendering for X11, by John P. Hartmann. + +- ALT key combos sometimes not reported in X11, per Mark Hessling et al. + +- Support for XK_ISO_Left_Tab in X11, by John P. Hartmann. + +- Support for "Super" keys in X11, by Bill Gray. + +- Make xcurses-config inclue -DPDC_WIDE when appropriate, per M.H. + +- The configure script and accompanying files, which were always + specific only to the X11 port (causing considerable confusion), have + been moved to the x11 directory. + +- In SDL, SP->key_code wasn't being set for KEY_MOUSE events. Reported + by Bill Gray. + +- SDL events need to keep pumping through non-input delays. (Really + messed up on current macOS before this change.) + +- SDL2 is outperforming SDL1 by about 10x on the platforms I've tried + that support both, so I've removed Makefile.mng from the SDL1 port. + +- Updated for the most current compilers, wherever possible; various + warning suppressions. All included makefiles were tested with their + respective compilers, shortly before release (including the POSIX + stuff on macOS with clang, and on Ubuntu Linux with gcc). The oldest + compiler I tested with was Turbo C++ 3.0, from 1992; the latest, + several compilers from 2017. + +- Dropped support for LCC-Win32 -- the official site is shut down. + +- Dropped support for Digital Mars -- not updated since 2014, limited + makefile, library missing some needed Windows APIs. + +- Dropped MS C for DOS, and Cset/2 for OS/2. + +- Dropped support for building DLLs with EMX. + +- Minor code and makefile reorganization; mingwin32.mak merged into + gccwin32.mak (i.e. you can use it with both compilers). Some + contributions by Bill Gray and Simon Sobisch. + +- Watcom makefile paths and option markers changed to Unix-friendly + style, after Tee-Kiah Chia. + +- The *.def files are no longer needed, replaced by more PDCEX + declarations in the include files. After Bill Gray and Simon Sobisch. + +- When building with DEBUG=Y, no longer strip the executables. After + Simon Sobisch. + +- Hold debug file ("trace") open after traceon(), for greater + performance. Set PDC_TRACE_FLUSH to make it fflush() after each write + (slower but safer in case of a crash). Patch by Ellie Timoney. + +- Since 3.2, the panel library was simply a copy of the main library. + This kludge is now dropped. (panel.h remains separate from curses.h.) + +- Removed PDCurses.spec, and the RPM-building makefile option. I think + this is better left to the various package/distro maintainers. + +- Various formatting corrections (e.g., trailing spaces stripped), and + variables renamed to avoid clashes. Some contributed by Stefan + Reinauer and Bill Gray. + +- Various documentation corrections and updates. All documentation + "converted" to Markdown format (involving few actual changes -- mainly + the file extension), for better rendering on GitHub, SourceForge, etc. + Some contributed by Anatoly Techtonik. + +- The "Win32" label is deprecated by Microsoft, and accordingly I've + replaced references in the documentation, although not yet changed the + filenames. The Windows console code can just as well be built for + 64-bit (and always could be, AFAIK, although there are minor tweaks + to support it in this version). + +- The ncurses_tests can now be built under SDL as well as X11. Also, all + our tests (still/again) build under recent ncurses. + +- Put testcurs' "Output test" into real blink mode, if possible; and if + COLORS >= 16, use colors 0-15 directly in the color test, instead of + or'ing with A_BOLD to get the high-intensity colors. + +- Renamed the (by now rather old) "newdemo" to "ozdemo". + +- Moved from CVS to git; source is now on GitHub as well as SourceForge; + central site is now pdcurses.org. + +See the git log for more details. + +------------------------------------------------------------------------ + +PDCurses 3.4 - 2008/09/08 +========================= + +Nothing much new this time, but I've been sitting on some bug fixes for +almost a year, so it's overdue. Apart from bugs, the main changes are in +the documentation. + +New features: + +- setsyx() is now a function rather than a macro. + +Bug fixes and such: + +- In x11, the xc_atrtab table size was under-calculated by half, + resulting in crashes at (oddly) certain line counts. (It should've + crashed a lot more.) Reported by Mark Hessling. + +- Test for moved cursor was omitting the window origin offset. Reported + by Carey Evans. + +- Is DOS and OS/2, the value for max items in key_table was still wrong. + Reported by C.E. + +- Changed isendwin() so it won't crash after delscreen(). + +- Ensure zero-termination in PDC_mbstowcs() and PDC_wcstombs(). + +- Disable QuickEdit Mode when enabling mouse input for the Win32 + console; reported by "Zalapkrakna". + +- Fix for building under Innotek C (I hope). Report by Elbert Pol, fix + courtesy of Paul Smedley. + +- Unified exports list with no duplicates -- pdcurses.def is now built + from components at compile time. + +- Don't install curspriv.h, and don't include it with binary + distributions. + +- Building DLLs with LCC is no longer supported, due to the primitive + nature of its make.exe. + +- Export the terminfo stub functions from the DLLs, too. + +- Added support for Apple's ".dylib" in configure. Suggested by Marc + Vaillant (who says it's needed with OS 10.5.) + +- In sdl1/Makefile.mng, ensure that CC is set. + +- In the gcc makefiles, "$?" didn't really have the desired effect -- + _all_ the dependencies showed up on the command line, including + curses.h, and pdcurses.a twice. And apparently, this can mess up some + old version (?) of MinGW. So, revert to spelling out "tuidemo.o + tui.o". Reported by "Howard L." + +- Extensive documentation revision and reorganizing. More to do here. + For example, I moved the build instructions from INSTALL (which never + really described installation) to the platform-specific READMEs. + +- New indentation standard: four spaces, no tabs. + +------------------------------------------------------------------------ + +PDCurses 3.3 - 2007/07/11 +========================= + +This release adds an SDL backend, refines the demos, and is faster in +some cases. + +New features: + +- SDL port. See INSTALL, doc/sdl.txt and sdl1/* for details. + +- Double-buffering -- minimize screen writes by checking, in doupdate() + and wnoutrefresh(), whether the changes to curscr are really changes. + In most cases, this makes no difference (writes were already limited + to areas marked as changed), but it can greatly reduce the overhead + from touchwin(). It also helps if you have small, separated updates on + the same line. + +- The PDC_RGB colors can now be used, or not, with any platform (as long + as the same options are used when compiling both the library and + apps). This may help if you have apps that are hardwired to assume + certain definitions. + +- Restored the use_default_colors() stuff from the ncurses versions of + the rain and worm demos, to make them "transparent" (this is useful + now, with the SDL port); added transparency to newdemo. + +- Added setlocale() to tuidemo, to make it easier to browse files with + non-ASCII characters. + +- Sped up firework demo by replacing unneeded clear() and init_pair() + calls. + +- Allow exit from ptest demo by typing 'q'. + +- New functions for implementors: PDC_pair_content() and PDC_init_pair() + (the old pdc_atrtab stuff was arguably the last remnant of code in the + pdcurses directory that was based on platform details). + +Bug fixes and such: + +- Implicit wrefresh() needs to be called from wgetch() when the window's + cursor position is changed, even if there are no other changes. + +- Set SP->audible on a per-platform basis, as was documented in + IMPLEMNT, but not actually being done. + +- Minor tweaks for efficiency and readability, notably with wscrl(). + +- tuidemo didn't work correctly on monochrome screens when A_COLOR was + defined -- the color pair numbers appeared as the corresponding + character; also, the input box was (I now realize) broken with ncurses + since our 2.7, and broke more subtly with PDCurses' new implicit + refresh handling; also, the path to the default file for the Browse + function was a bit off. + +- Assume in the demos that curs_set() is always available -- there's no + good test for this, and the existing tests were bogus. + +- Made the command-line parameter for ptest work. (If given an argument, + it delays that number of milliseconds between changes, instead of + waiting for a key, and automatically loops five times.) + +- Building the Win32 DLL with MinGW or Cygwin wouldn't work from outside + the platform directory. + +- Building the X11 port with Cygwin required manually editing the + Makefile after configuring; no longer. Reported by Warren W. Gay. + +- Minor tightening of configure and makefiles. + +- Bogus references to "ACS_BLCORNER" in the border man page. Reported by + "Walrii". + +- slk_wlabel() was not documented. + +- Spelling cleanup. + +- Changed RCSIDs to not end with a semicolon -- avoids warnings when + compiling with the -pedantic option. + +- Merged latin-1.txt into x11.txt. + +- Updated config.guess and config.sub to more recent versions. + +------------------------------------------------------------------------ + +PDCurses 3.2 - 2007/06/06 +========================= + +This release mainly covers changes to the build process, along with a +few structural changes. + +New features: + +- The panel library has been folded into the main library. What this + means is that you no longer need to specify "-lpanel" or equivalent + when linking programs that use panel functionality with PDCurses; + however, panel.lib/.a is still provided (as a copy of pdcurses.lib/.a) + so that you can, optionally, build your projects with no changes. It + also means that panel functionality is available with the DLL or + shared library. Note that panel.h remains separate from curses.h. + +- Setting the PDCURSES_SRCDIR environment variable is no longer required + before building, unless you want to build in a location other than the + platform directory. (See INSTALL.) + +- MinGW and Cygwin makefiles support building DLLs, via the "DLL=Y" + option. Partly due to Timofei Shatrov. + +- Support for the Digital Mars compiler. + +- Watcom makefiles now use the "loaddll" feature. + +Bug fixes and such: + +- Eliminated the platform defines (DOS, WIN32, OS2, XCURSES) from + curses.h, except for X11-specific SCREEN elements and functions. + Dynamically-linked X11 apps built against an old version will have + their red and blue swapped until rebuilt. (You can define PDC_RGB to + build the library with the old color scheme, but it would also have to + be defined when building any new app.) Any app that depends on + PDCurses to determine the platform it's building on will have to make + other arrangements. + +- Documentation cleanup -- added more details; removed some content that + didn't apply to PDCurses; moved the doc-building tool to the doc + directory; changed *.man to *.txt. + +- The EMX makefile now accepts "DLL=Y", builds pdcurses.dll instead of + curses.dll, builds either the static library or the DLL (not both at + once), and links all the demos with the DLL when building it. + +- In Win32, read the registry only when needed: when init_color() or + color_content() is called, instead of at startup. + +- A few additional consts in declarations. + +- The Win32 compilers that build DLLs now use common .def files. + +- panel.h functions sorted by name, as with other .h files; curses.h is + no longer included by repeated inclusions of panel.h or term.h. + +- Simplified Borland makefiles. + +- Makefile.aix.in depended on a file, xcurses.exp, that was never there. + This problem was fixed as part of the change to common .def files; + however, I still haven't been able to test building on AIX. + +------------------------------------------------------------------------ + +PDCurses 3.1 - 2007/05/03 +========================= + +Primarily clipboard-related fixes, and special UTF-8 support. + +New features: + +- "Force UTF-8" mode, a compile-time option to force the use of UTF-8 + for multibyte strings, instead of the system locale. (Mainly for + Windows, where UTF-8 doesn't work well in the console.) See INSTALL. + +- Multibyte string support in PDC_*clipboard() functions, and in Win32's + PDC_set_title(). + +- Added the global string "ttytype", per other curses implementations, + for compatibility with old BSD curses. + +- Real functions for the "quasi-standard aliases" -- crmode(), + nocrmode(), draino(), resetterm(), fixterm() and saveterm(). + (Corresponding macros removed.) + +Bug fixes and such: + +- In Win32, under NT-family OSes, the scrollback buffer would be + restored by endwin(), but would not be turned off again when resuming + curses after an endwin(). The result was an odd, partly-scrolled-up + display. Now, the buffer is toggled by PDC_reset_prog_mode() and + PDC_reset_shell_mode(), so it's properly turned off when returning + from an endwin(). + +- In 3.0, selection in X11 didn't work. (Well, the selecting worked, but + the pasting elsewhere didn't.) This was due to the attempted fix + "don't return selection start as a press event," so that's been + reverted for now. + +- PDC_setclipboard() was locking up in X11. Reported by Mark Hessling. + +- Missing underscore in the declaration of XC_say() prevented + compilation with PDCDEBUG defined. Reported by M.H. + +- Off-by-one error in copywin() -- the maximum coordinates for the + destination window should be inclusive. Reported by Tiago Dionizio. + +- Start in echo mode, per X/Open. Reported by T.D. + +- Strip leading and trailing spaces from slk labels, per a literal + reading of X/Open. Suggested by Alexey Miheev (about ncurses, but it + also applies here). + +- The #endif for __PDCURSES__ needs to come _after_ the closing of the + extern "C". This has been broken since June 2005. Fortunately (?), it + only shows up if the file is included multiple times, and then only in + C++. Reported on the DOSBox forums. + +- Use CF_OEMTEXT instead of CF_TEXT in the narrow versions of the + clipboard functions in Win32, to match the console. + +- Changed the format of the string returned from longname(). + +- In the clipboard test in the testcurs demo, use a single mvprintw() to + display the return from PDC_getclipboard(), instead of a loop of + addch(), which was incompatible with multibyte strings. + +- Moved has_key() into the keyname module, and documented it. + +- Moved RIPPEDOFFLINE to curspriv.h. + +- Typos in IMPLEMNT. + +------------------------------------------------------------------------ + +PDCurses 3.0 - 2007/04/01 +========================= + +The focuses for this release are X/Open conformance, i18n, better color +support, cleaner code, and more consistency across platforms. + +This is only a brief summary of the changes. For more details, consult +the CVS log. + +New features: + +- An almost complete implementation of X/Open curses, including the + wide-character and attr_t functions (but excluding terminfo). The + wide-character functions work only in Win32 and X11, for now, and + require building the library with the appropriate options (see + INSTALL). Note that this is a simplistic implementation, with exactly + one wchar_t per cchar_t; the only characters it handles properly are + those that are one column wide. + +- Support for X Input Methods in the X11 port (see INSTALL). When built + this way, the internal compose key support is disabled in favor of + XIM's, which is a lot more complete, although you lose the box cursor. + +- Multibyte character support in the non-wide string handling functions, + per X/Open. This only works when the library is built with wide- + character support enabled. + +- Mouse support for DOS and OS/2. The DOS version includes untested + support for scroll wheels, via the "CuteMouse" driver. + +- An ncurses-compatible mouse interface, which can work in parallel with + the traditional PDCurses mouse interface. See the man page (or + mouse.c) for details. + +- DOS and OS/2 can now return modifiers as keys, as in Win32 and X11. + +- COLORS, which had been fixed at 8, is now either 8 or 16, depending on + the terminal -- usually 16. When it's 8, blinking mode is enabled + (controlled as before by the A_BLINK attribute); when it's 16, bright + background colors are used instead. On platforms where it can be + changed, the mode is toggled by the new function PDC_set_blink(). + PDCurses tries to set PDC_set_blink(FALSE) at startup. (In Win32, it's + always set to FALSE; in DOS, with other than an EGA or VGA card, it + can't be.) Also, COLORS is now set to 0 until start_color() is called. + +- Corresponding to the change in COLORS, COLOR_PAIRS is now 256. + +- Working init_color() and color_content(). The OS/2 version of + init_color() works only in a full-screen session; the Win32 version + works only in windowed mode, and only in NT-family OSes; the DOS + version works only with VGA adapters (real or simulated). The Win32 + version is based mostly on James Brown's setconsoleinfo.c + (www.catch22.net). + +- use_default_colors(), assume_default_colors(), and curses_version(), + after ncurses. + +- Added global int TABSIZE, after ncurses and Solaris curses; removed + window-specific _tabsize. + +- Logical extension to the wide-character slk_ funcs: slk_wlabel(), for + retrieving the label as a wide-character string. + +- A non-macro implementation of ncurses' wresize(). + +- Working putwin(), getwin(), scr_dump() and scr_restore(). + +- A working acs_map[]. Characters from the ACS are now stored in window + structures as a regular character plus the A_ALTCHARSET attribute, and + rendered to the ACS only when displayed. (This allows, for example, + the correct display on one platform of windows saved from another.) + +- In X11, allow selection and paste of UTF8_STRING. + +- The testcurs demo now includes a color chart and init_color() test, a + wide character input test, a display of wide ACS characters with + sample Unicode text, a specific test of flash(), more info in the + resize test, and attempts to change the width as well as the height. + +- Command-line option for MSVC to build DLLs (see INSTALL). Also, the + naming distinction for DLLs ("curses" vs. "pdcurses") is abandoned, + and either the static lib or DLL is built, not both at once (except + for X11). + +- For backwards compatibility, a special module just for deprecated + functions -- currently PDC_check_bios_key(), PDC_get_bios_key(), + PDC_get_ctrl_break() and PDC_set_ctrl_break(). These shouldn't be used + in applications, but currently are... in fact, all the "private" + functions (in curspriv.h) are subject to change and should be avoided. + +- A new document, IMPLEMNT, describing PDCurses' internal functions for + those wishing to port it to new platforms. + +- Mark Hessling has released the X11 port to the public domain. + (However, x11/ScrollBox* retain their separate copyright and MIT-like + license.) + +Bug fixes and such: + +- Most of the macros have been removed (along with the NOMACROS ifdef). + The only remaining ones are those which have to be macros to work, and + those that are required by X/Open to be macros. There were numerous + problems with the macros, and no apparent reason to keep them, except + tradition -- although it was PCcurses 1.x that first omitted them. + +- Clean separation of platform-specific code from the rest. Outside of + the platform directories, there remain only a few ifdefs in curses.h + and curspriv.h. + +- General reorganization and simplification. + +- Documentation revisions. + +- When expanding control characters in addch() or insch(), retain the + attributes from the chtype. + +- Preserve the A_ALTCHARSET attribute in addch() and insch(). + +- Per X/Open, beep() should always return OK. + +- On platforms with a controlling terminal (i.e., not X11), curs_set(1) + now sets the cursor to the shape it had at the time of initscr(), + rather than always making it small. (Exception for DOS: If the video + mode has been changed by PDC_resize_screen(), curs_set(1) reverts to + line 6/7.) The shape is taken from SP->orig_cursor (the meaning of + which is platform-specific). + +- Stop updating the cursor position when the cursor is invisible (this + gives a huge performance boost in Win 9x); update the cursor position + from curs_set() if changing from invisible to visible. + +- Some tweaking of the behavior of def_prog_mode(), def_shell_mode(), + savetty(), reset_prog_mode(), reset_shell_mode() and resetty()... + still not quite right. + +- flash() was not implemented for Win32 or X. A portable implementation + is now used for all platforms. Note that it's much slower than the + old (DOS and OS/2) version, but this is only apparent on an extremely + slow machine, such as an XT. + +- In getstr(), backspacing on high-bit characters caused a double + backspace. + +- hline() and vline() used an incorrect (off by one) interpretation of + _maxx and _maxy. If values of n greater than the max were specified, + these functions could access unallocated memory. + +- innstr() is supposed to return the number of characters read, not just + OK or ERR. Reported by Mike Aubury. + +- A proper implementation of insch() -- the PDC_chadd()-based version + wasn't handling the control characters correctly. + +- Return ASCII and control key names from keyname() (problem revealed by + ncurses' movewindow test); also, per X/Open, return "UNKNOWN KEY" when + appropriate, rather than "NO KEY NAME". + +- Turn off the cursor from leaveok(TRUE), even in X11; leaveok(FALSE) + now calls curs_set(1), regardless of the previous state of the cursor. + +- In the slk area, BUTTON_CLICKED events now translate to function keys, + along with the previously recognized BUTTON_PRESSED events. Of course, + it should really be checking the events specified by map_button(), + which still doesn't work. + +- napms(0) now returns immediately. + +- A unified napms() implementation for DOS -- no longer throttles the + CPU when built with any compiler. + +- Allow backspace editing of the nocbreak() buffer. + +- pair_content(0, ...) is valid. + +- There was no check to ensure that the pnoutrefresh() window fit within + the screen. It now returns an ERR if it doesn't. + +- In X11, resize_term() must be called with parameters (0, 0), and only + when SP->resized is set, else it returns ERR. + +- Copy _bkgd in resize_window(). Patch found on Frederic L. W. Meunier's + web site. + +- slk_clear() now removes the buttons completely, as in ncurses. + +- Use the current foreground color for the line attributes (underline, + left, right), unless PDC_set_line_color() is explicitly called. After + setting the line color, you can reset it to this mode via + "PDC_set_line_color(-1)". + +- Removed non-macro implementations of COLOR_PAIR() and PAIR_NUMBER(). + +- Dispensed with PDC_chadd() and PDC_chins() -- waddch() and winsch() + are now (again) the core functions. + +- Dropped or made static many obsolete, unused, and/or broken functions, + including PDC_chg_attrs(), PDC_cursor_on() and _off(), + PDC_fix_cursor(), PDC_get_attribute(), PDC_get_cur_col() and _row(), + PDC_set_80x25(), PDC_set_cursor_mode(), PDC_set_rows(), + PDC_wunderline(), PDC_wleftline(), PDC_wrightline(), + XCursesModifierPress() and XCurses_refresh_scrollbar(). + +- Obsolete/unused defines: _BCHAR, _GOCHAR, _STOPCHAR, _PRINTCHAR + _ENDLINE, _FULLWIN and _SCROLLWIN. + +- Obsolete/unused elements of the WINDOW struct: _pmax*, _lastp*, + _lasts*. + +- Obsolete/unused elements of the SCREEN struct: orgcbr, visible_cursor, + sizeable, shell, blank, cursor, orig_emulation, font, orig_font, + tahead, adapter, scrnmode, kbdinfo, direct_video, video_page, + video_seg, video_ofs, bogus_adapter. (Some of these persist outside + the SCREEN struct, in the platform directories.) Added mouse_wait and + key_code. + +- Removed all the EMALLOC stuff. Straight malloc calls were used + elsewhere; it was undocumented outside of comments in curspriv.h; and + there are better ways to use a substitute malloc(). + +- Single mouse clicks are now reportable on all platforms (not just + double-clicks). And in general, mouse event reporting is more + consistent across platforms. + +- The mouse cursor no longer appears in full-screen mode in Win32 unless + a nonzero mouse event mask is used. + +- ALT-keypad input now works in Win32. + +- In Win32, SetConsoleMode(ENABLE_WINDOW_INPUT) is not useful, and + appears to be the source of a four-year-old bug report (hanging in + THE) by Phil Smith. + +- Removed the PDC_THREAD_BUILD stuff, which has never worked. For the + record: PDCurses is not thread-safe. Neither is ncurses; and the + X/Open curses spec explicitly makes it a non-requirement. + +- With the internal compose key system in the X11 port, modifier keys + were breaking out of the compose state, making it impossible to type + accented capitals, etc. Also, Multi_key is now the default compose + key, instead of leaving it undefined by default; and a few more combos + are supported. + +- In X11, the first reported mouse event after startup always read as a + double-click at position 0, 0. (This bug was introduced in 2.8.) + +- In X11, don't return selection start as a press event. (Shift-click on + button 1 is still returned.) + +- In X11, properly handle pasting of high-bit chars. (It was doing an + unwanted sign extension.) + +- In X11, BUTTON_MOVED was never returned, although PDC_MOUSE_MOVED was + set. + +- The fix in 2.8 for the scroll wheel in X11 wasn't very good -- it did + report the events as scroll wheel events, but it doubled them. Here's + a proper fix. + +- Changed mouse handling in X11: Simpler translation table, with + XCursesPasteSelection() called from XCursesButton() instead of the + translation table; require shift with button 1 or 2 for select or + paste when mouse events are being reported (as with ncurses), allowing + passthrough of simple button 2 events. This fixes the previously + unreliable button 2 behavior. + +- Modifier keys are now returned on key up in X11, as in Win32. And in + general, modifier key reporting is more consistent across platforms. + +- Modifiers are not returned as keys when a mouse click has occurred + since the key press. + +- In BIOS mode (in DOS), count successive identical output bytes, and + make only one BIOS call for all of them. This dramatically improves + performance. + +- The cursor position was not always updated correctly in BIOS mode. + +- In testcurs, the way the ACS test was written, it would really only + work with a) PDCurses (with any compiler), or b) gcc (with any + curses). Here's a more portable implementation. + +- Better reporting of mouse events in testcurs. + +- Blank out buffer and num before the scanw() test in testcurs, in case + the user just hits enter or etc.; clear the screen after resizing. + +- Allow tuidemo to use the last line. + +- Separate left/right modifier keys are now reported properly in Win32. + (Everything was being reported as _R.) + +- Attempts to redirect input in Win32 now cause program exit and an + error message, instead of hanging. + +- Dropped support for the Microway NDP compiler. + +- Some modules renamed, rearranged. + +- Fixes for errors and warnings when building with Visual C++ 2005. + +- In MSVC, the panel library didn't work with the DLL. + +- Complete export lists for DLLs. + +- Simplified makefiles; moved common elements to .mif files; better + optimization; strip demos when possible. + +- Changed makefile targets of "pdcurses.a/lib" and "panel.a/lib" to + $(LIBCURSES) and $(LIBPANEL). Suggestion of Doug Kaufman. + +- Changed "install" target in the makefile to a double-colon rule, to + get around a conflict with INSTALL on non-case-sensitive filesystems, + such as Mac OS X's HFS+. Reported by Douglas Godfrey et al. + +- Make PDCurses.man dependent on manext. Suggestion of Tiziano Mueller. + +- Set up configure.ac so autoheader works; removed some obsolescent + macros. Partly the suggestion of T.M. + +- The X11 port now builds in the x11 directory (including the demos), as + with other ports. + +- The X11 port should now build on more 64-bit systems. Partly due to + M.H. + +- The default window title and icons for the X11 port are now "PDCurses" + instead of "XCurses". + +- Internal functions and variables made static where possible. + +- Adopted a somewhat more consistent naming style: Internal functions + with external linkage, and only those, have the prefix "PDC_"; + external variables that aren't part of the API use "pdc_"; static + functions use "_"; and "XC_" and "xc_" prefixes are used for functions + and variables, respectively, that are shared between both processes in + the X11 port. Also eliminated camel casing, where possible. + +- Changed the encoding for non-ASCII characters in comments and + documentation from Latin-1 to UTF-8. + +------------------------------------------------------------------------ + +PDCurses 2.8 - 2006/04/01 +========================= + +As with the previous version, you should assume that apps linked against +older dynamic versions of the library won't work with this one until +recompiled. + +New features: + +- Simpler, faster. + +- Declarations for all supported, standard functions, per the X/Open + Curses 4.2 spec, with the notable exception of getch() and ungetch(). + You can disable the use of the macro versions by defining NOMACROS + before including curses.h (see xmas.c for an example). NOMACROS yields + smaller but theoretically slower executables. + +- New functions: vwprintw(), vwscanw(), vw_printw() and vw_scanw(). This + completes the list of X/Open 4.2 functions, except for those concerned + with attr_t and wide characters. Some (especially the terminfo/termcap + functions) aren't yet fully fleshed out, though. + +- Non-macro implementations for COLOR_PAIR(), PAIR_NUMBER(), getbkgd(), + mvgetnstr(), mvwgetnstr(), mvhline(), mvvline(), mvwhline(), and + mvwvline(). (The macros are still available, too.) + +- newterm() works now, in a limited way -- the parameters are ignored, + and only the first invocation will work (i.e., only one SCREEN can be + used). + +- start_color() works now -- which is to say, if you _don't_ call it, + you'll only get monochrome output. Also, without calling it, the + terminal's default colors will be used, where supported (currently + only in Win32). This is equivalent to the PDC_ORIGINAL_COLORS behavior + introduced in 2.7, except that _only_ the default colors will be used. + (PDC_ORIGINAL_COLORS is still available, if you want to combine the + use of specific colors and the default colors.) + +- New logic for termname() and longname(): termname() always returns + "pdcurses"; longname() returns "PDCurses for [platform] [adapter] + [COLOR/MONO]-YxX" (adapter is only defined for DOS and OS/2). This is + the first time these functions return _anything_ in Win32. + +- New installation method for XCurses: the header files are placed in a + subdirectory "xcurses" within the include directory, rather than being + renamed. (But the renamed xcurses.h and xpanel.h are also installed, + for backwards compatibility.) curspriv.h and term.h are now available, + and existing curses-based code need no longer be edited to use + XCurses' curses.h. And with no more need for explicit XCursesExit() + calls (see below), your code need not be changed at all to move from + another curses implementation to XCurses. It can be as simple as "gcc + -I/usr/local/include/xcurses -lXCurses -oprogname progname.c". + +- Combined readme.* into this HISTORY file, and incorporated the old 1.x + (PCcurses) history. + +- New functionality for the testcurs demo: ACS character display; menu + support for PgUp, PgDn, Home and End; centered menu; and it can now + be resized in X. + +- Added modified versions of the rain and worm demos from ncurses. + +Bug fixes and such: + +- Big cleanup of dead and redundant code, including unneeded defines, + ifdefs, and structure elements. + +- flushinp() was not implemented for Win32. + +- resetty() was not restoring LINES and COLS. + +- nonl() made '\n' print a line feed without carriage return. This was + incorrect. + +- Removed bogus implementation of intrflush(). + +- The line-breakout optimization system, disabled by default in 2.7, is + removed in 2.8. It simply didn't work, and never has. (The typeahead() + function remains, for compatibility, but does nothing.) + +- The declarations for the printw() and scanw() function families were + erroneously ifdef'd. + +- Safer printw() calls on platforms that support vsnprintf(). + +- Use the native vsscanf() in DJGPP, MinGW and Cygwin. + +- ACS_BLOCK now works in X. + +- Explicit calls to XCursesExit() are no longer needed. + +- XCURSES is now defined automatically if not DOS, OS2 or WIN32. + +- The default icon for XCurses wasn't working (had to remove the focus + hint code to fix this). Also, the default title is now "XCurses" + instead of "main". + +- Incorrect dimensions (undercounting by two in each direction) were + shown while resizing in X. + +- Scroll wheel events were not always correctly reported in X. + +- 32 bits are enough for the "long" chtype, but 64 bits were used on a + 64-bit system, wasting memory. Now conditioned on _LP64. This could be + faster, too. + +- The short, 16-bit chtype now works with XCurses. + +- Corrected return value for is_linetouched(), is_wintouched(), + can_change_color() and isendwin() (bool instead of int). + +- timeout(), wtimeout(), idcok() and immedok() return void. + +- pair_content() takes a short. + +- Replaced incorrect usages of attr_t with chtype. attr_t is still + typedef'd, for backwards compatibility. (It's supposed to be used for + the WA_*-style functions, which PDCurses doesn't yet support.) + +- Added const where required by the spec, and in other appropriate + places. + +- Removed PDC_usleep(). napms() is now the core delay routine. + +- Fixed poll() support in napms(). + +- Various changes to the internal PDC_* functions -- don't depend on + these, and don't use them unless you absolutely have to. + +- Some routines accessed window structures in their variable + declarations, _before_ checking for a NULL window pointer. + +- Dropped support for the undocumented PDC_FULL_DISPLAY, wtitle(), and + PDC_print(). + +- Cleaned up remaining warnings. + +- Reduced unnecessary #include directives -- speeds up compilation. + +- Fix for demos build in Borland/DOS -- the makefile in 2.7 didn't + specify the memory model. Reported by Erwin Waterlander. + +- Simplified the makefiles; e.g., some now build each demo in a single + step, and Watcom no longer uses demos.lnk. Also, the demo exes are now + stripped when possible; maximum compression used for archives built + by the makefiles; xcurses-config removed as part of "make distclean"; + and I tweaked optimization for some platforms. + +- Reverted to /usr/local/ as default installation directory for XCurses. + +- Upgraded to autoconf 2.59... instantly doubling the size of the + configure script. Ah well. Otherwise, simplified the build system. + +- Dropped support for pre-ANSI compilers. (It hasn't worked since at + least version 2.4, anyway.) + +- Revised and, I hope, clarified the boilerplate and other comments. + +- Simplified logging and RCS ids; added RCS ids where missing. + +- Consistent formatting for all code, approximately equivalent to + "indent -kr -i8 -bl -bli0", with adjustments for 80 columns. + +------------------------------------------------------------------------ + +PDCurses 2.7 - 2005/12/30 +========================= + +INTRODUCTION: + +Hello all. As of a few weeks ago, I'm the new maintainer for PDCurses. +Here's a brief summary of changes in this release. (More details are +available in the CVS log and trackers on SourceForge.) + +NEW FEATURES: + +- Functions: delscreen(), getattrs(), has_key(), slk_color(), + wcolor_set(), wtimeout(). + +- Macros: color_set(), mvhline(), mvvline(), mvwgetnstr(), mvwhline(), + mvwvline(), timeout(), wresize(). + +- Stub implementations of terminfo functions (including a term.h). + +- More stubs for compatibility: filter(), getwin(), putwin(), + noqiflush(), qiflush(), scr_dump(), scr_init(), scr_restore(), + scr_set(), use_env(), vidattr(), vidputs(). + +- The terminal's default colors are used as curses' default colors when + the environment variable "PDC_ORIGINAL_COLORS" is set to any value + (Win32 only at the moment). + +- Simplified build system. + +- Replaced PDC_STATIC_BUILD with its opposite, PDC_DLL_BUILD (see .mak + files for more info). + +- Minimal implementation of color_content() -- no longer a stub. + +- Added the remaining ACS defines (ACS_S3, ACS_BBSS, etc.) for + DOS/OS2/Win; "enhanced" versions of existing ACS characters used. + +- Support for scroll wheels. + +- Support for Pacific C. + +BUGS FIXED: + +- Builds correctly (including demos) on all tested platforms (see + below); nearly all compiler warnings have been cleaned up; the ptest + demo is built on all platforms; "clean" targets are improved. + +- The ability to build ncurses_tests has been restored (see demos dir). + +- Line-breakout optimization now defaults to off (equivalent to + "typeahead(-1)"), so output is not interrupted by keystrokes (it's + supposed to resume on the next refresh(), which wasn't working). + +- Implicit wrefresh() in wgetch() was not being invoked in nodelay mode. + +- subpad() was erroneously offsetting from the origin coordinates of the + parent pad (which are always -1,-1). + +- In wborder(), whline(), and wvline(), the current (wattrset) attribute + was being used, but not the current background (wbkgd). + +- Allow Russian 'r' character ASCII 0xe0 to be returned. + +- termattrs() now also returns A_UNDERLINE, A_REVERSE. + +- In Win32, with large scrollback buffers set, there was an unwanted + "scrollup" effect on startup. + +- Revamped keyboard handling for Win32. + +- New screen resize method for Win32. + +- napms(), delay_output(), etc. now work with Cygwin. + +- curs_set(0) wasn't working in Win32 in full-screen (ALT-ENTER) mode -- + the cursor stayed on. + +- The A_REVERSE attribute was broken in XCurses. + +- On 64-bit systems, XCurses was ignoring every other keystroke. + +- Added focus hints for XCurses. + +- Demos (except for tuidemo) once again have their proper titles in + XCurses (using Xinitscr() instead of the obsolete XCursesProgramName). + +- The 16-bit chtype is a working option again (by removing #define + CHTYPE_LONG from curses.h), except in XCurses. It's not recommended; + but if your needs are limited, it still works. + +- Reset screen size in resetty() under DOS, as in Win32 and OS/2. + +- Changes for cursor size under DOS. + +- Automatic setting of BIOS mode for CGA under DOS now works. + +- The cursor is now always updated in PDC_gotoxy(); this fixes the + problem of missing characters in BIOS mode. + +- Macros nocbreak(), cbreak(), nocrmode(), crmode(), nodelay(), + nl() and nonl() now return OK. + +- ERR and OK are now defined as -1 and 0, respectively, for + compatibility with other curses implementations -- note that this + change is not binary compatible; you'll have to rebuild programs that + use shared/dynamic libraries. + +- Added "const" to prototypes where appropriate. + +- Miscellaneous code cleanup. + +ACKNOWLEDGEMENTS: + + - Walter Briscoe + - Jean-Pierre Demailly + - Ruslan Fedyarov + - Warren Gay + - Florian Grosse-Coosmann + - Vladimir Kokovic + - Matt Maloy + - K.H. Man + - Michael Ryazanov + - Ron Thibodeau + - Alexandr Zamaraev + +and of course, MARK HESSLING, for his over 13 years of service as the +maintainer of PDCurses. Plus, thanks to all who've reported bugs or +requested features. Apologies to anyone I've forgotten. + +I've tested this version on Turbo C++ 3.0 and Borland C++ 3.1 for DOS; +DJGPP 2.X; Open Watcom 1.3 for DOS (16 and 32-bit), Windows and OS/2; +EMX 0.9d and the "newgcc" version of EMX; Borland C++ 5.5 for Windows; +recent versions of MinGW, Cygwin, LCC-Win32 and Microsoft Visual C++; +and gcc under several flavors of Linux, Mac OS X, *BSD and Solaris. + +-- William McBrine + +------------------------------------------------------------------------ + +PDCurses 2.6 - 2003/01/08 +========================= + +INTRODUCTION: + + This release of PDCurses includes the following changes: + +BUGS FIXED: + +- Allow accented characters on Win32 platform when run on non-English + keyboards. + +- Allow "special" characters like Ctrl-S, Ctrl-Q under OS/2 to be returned. + +- Some bugs with halfdelay() fixed by William McBrine. + +- pechochar() should now work correctly. + +- redrawwin() macro in curses.h was incorrect - fixed by Alberto Ornaghi + +- Don't include "special" characters like KEY_SHIFT_L to be returned in + getnstr() family. Bug 542913 + +- Entering TAB in wgetnstr() no longer exceeds requested buffer size. + Bug 489233 + +- Fixed bug 550066, scrollok() and pads. + Also beep() called when buffer exceeded. Bug 562041. + +- Reverse video of X11 selection reinstated. Pablo Garcia Abio?? + +- Right Alt modifier now works like left Alt modifier under Win32 + +- Add support for all libXaw replacement libraries with Scrollbar bug. + Note that for this to work, you still have to change the libXaw + replacement libraries to fix the bug :-( + +- Don't trap signals in XCurses if calling application has ignored them. + Change by Frank Heckenbach. + +- Bug reports from Warren W. Gay: + - Fix termattrs() to return A_REVERSE and A_BLINK on all platforms. + - Fix definition of getsyx() and setsyx() to be consistent with + ncurses. Bug 624424. + - Fix definition of echo() and noecho(). Bug 625001. + - Fix definition of keypad() and leaveok(). Bug 632653. + - Missing panel_hidden() prototype. Bug 649320. + +- Fixed bug with calling def_prog_mode(), resize_term(), + reset_prog_mode(); the resize details were being lost. + +NEW FEATURES: + +- Clipboard support now available on DOS platform, but handled + internally to the currently running process. + +- New X11 resource: textCursor, allows the text cursor to be specified + as a vertical bar, or the standard horizontal bar. Thanks to Frank + Heckenbach for the suggestion. + +NEW COMPILER SUPPORT: + +- lcc-win32 now works correctly + +------------------------------------------------------------------------ + +PDCurses 2.5 - 2001/11/26 +========================= + +INTRODUCTION: + + This release of PDCurses includes the following changes: + +- Set BASE address for Win32 DLL + +- Add KEY_SUP and KEY_SDOWN. + +- Add PDC_set_line_color() + +- Add blink support as bold background + +- Add bold colors + +- Add getbkgd() macro + +- Add new PDC functions for adding underline, overline, leftline and + rightline + +- Add support for shifted keypad keys. + +- Allow more keypad keys to work under Win32 + +- Change Win32 and OS/2 DLL name to curses.dll + +- Change example resources to allow overriding from the command line + +- Changes for building cleanly on OS/2 + +- Changes to handle building XCurses under AIX + +- Check if prefresh() and pnoutrefresh() parameters are valid. + +- Ensure build/install works from any directory + +- Handle platforms where X11 headers do not typedef XPointer. + +- Mention that Flexos is likely out-of-date. + +- Pass delaytenths to XCurses_rawgetch() + +- Remove boldFont + +- Updates for cursor blinking and italic. + +BUGS FIXED: + +- Fix bug with getting Win32 clipboard contents. Added new + PDC_freeclipboard() function. + +- Fix bug with halfdelay() + +- Fix bug with mouse interrupting programs that are not trapping mouse + events under Win32. + +- Fix return value from curs_set() + +- Reverse the left and right pointing bars in ALT_CHARSET + +NEW COMPILER SUPPORT: + +- Add QNX-RTP port + +------------------------------------------------------------------------ + +PDCurses 2.4 - 2000/01/17 +========================= + +INTRODUCTION: + + This release of PDCurses includes the following changes: + +- full support of X11 selection handling + +- removed the need for the cursos2.h file + +- enabled the "shifted" key on the numeric keypad + +- added native clipboard support for X11, Win32 and OS/2 + +- added extra functions for obtaining internal PDCurses status + +- added clipboard and key modifier tests in testcurs.c + +- fixes for panel library + +- key modifiers pressed by themselves are now returned as keys: + KEY_SHIFT_L KEY_SHIFT_R KEY_CONTROL_L KEY_CONTROL_R KEY_ALT_L KEY_ALT_R + This works on Win32 and X11 ports only + +- Added X11 shared library support + +- Added extra slk formats supported by ncurses + +- Fixed bug with resizing the terminal when slk were on. + +- Changed behavior of slk_attrset(), slk_attron() slk_attroff() + functions to work more like ncurses. + +BUGS FIXED: + +- some minor bug and portability fixes were included in this release + +NEW FUNCTIONS: + +- PDC_getclipboard() and PDC_setclipboard() for accessing the native + clipboard (X11, Win32 and OS/2) + +- PDC_set_title() for setting the title of the window (X11 and Win32 + only) + +- PDC_get_input_fd() for getting the file handle of the PDCurses input + +- PDC_get_key_modifiers() for getting the keyboard modifier settings at + the time of the last (w)getch() + +- Xinitscr() (only for X11 port) which allows standard X11 switches to + be passed to the application + +NEW COMPILER SUPPORT: + +- MingW32 GNU compiler under Win95/NT + +- Cygnus Win32 GNU compiler under Win95/NT + +- Borland C++ for OS/2 1.0+ + +- lcc-win32 compiler under Win95/NT + +ACKNOWLEDGEMENTS: (for this release) + +- Georg Fuchs for various changes. +- Juan David Palomar for pointing out getnstr() was not implemented. +- William McBrine for fix to allow black/black as valid color pair. +- Peter Preus for pointing out the missing bccos2.mak file. +- Laura Michaels for a couple of bug fixes and changes required to + support Mingw32 compiler. +- Frank Heckenbach for PDC_get_input_fd() and some portability fixes and + the fixes for panel library. +- Matthias Burian for the lcc-win32 compiler support. + +------------------------------------------------------------------------ + +PDCurses 2.3 - 1998/07/09 +========================= + +INTRODUCTION: + +This release of PDCurses includes the following changes: + +- added more System V R4 functions + +- added Win32 port + +- the X11 port is now fully functional + +- the MS Visual C++ Win32 port now includes a DLL + +- both the X11 and Win32 ports support the mouse + +- the slk..() functions are now functional + +- support for scrollbars under X11 are experimental at this stage + +- long chtype extended to non-Unix ports + +The name of the statically built library is pdcurses.lib (or +pdcurses.a). The name of the DLL import library (where applicable) is +curses.lib. + +BUGS FIXED: + +- some minor bugs were corrected in this release + +NEW FUNCTIONS: + +- slk..() functions + +NEW COMPILER SUPPORT: + +- MS Visual C++ under Win95/NT + +- Watcom C++ under OS/2, Win32 and DOS + +- two EMX ports have been provided: + - OS/2 only using OS/2 APIs + - OS/2 and DOS using EMX video support routines + +EXTRA OPTIONS: + +PDCurses recognizes two environment variables which determines the +initialization and finalization behavior. These environment variables +do not apply to the X11 port. + +PDC_PRESERVE_SCREEN - +If this environment variable is set, PDCurses will not clear the screen +to the default white on black on startup. This allows you to overlay +a window over the top of the existing screen background. + +PDC_RESTORE_SCREEN - +If this environment variable is set, PDCurses will take a copy of the +contents of the screen at the time that PDCurses is started; initscr(), +and when endwin() is called, the screen will be restored. + + +ACKNOWLEDGEMENTS: (for this release) + +- Chris Szurgot for original Win32 port. +- Gurusamy Sarathy for some updates to the Win32 port. +- Kim Huron for the slk..() functions. +- Florian Grosse Coosmann for some bug fixes. +- Esa Peuha for reducing compiler warnings. +- Augustin Martin Domingo for patches to X11 port to enable accented + characters. + +------------------------------------------------------------------------ + +PDCurses 2.2 - 1995/02/12 +========================= + +INTRODUCTION: + + This release of PDCurses has includes a number of major changes: + +- The portable library functions are now grouped together into single + files with the same arrangement as System V R4 curses. + +- A panels library has been included. This panels library was written by + Warren Tucker. + +- Quite a few more functions have been supplied by Wade Schauer and + incorporated into release 2.2. Wade also supplied the support for the + Microway NDP C/C++ 32 bit DOS compiler. + +- The curses datatype has been changed from an unsigned int to a long. + This allows more attributes to be stored as well as increasing the + number of color-pairs from 32 to 64. + +- Xwindows port (experimental at the moment). + +BUGS FIXED: + +- mvwin() checked the wrong coordinates + +- removed DESQview shadow memory buffer checking bug in curses.h in + \#define for wstandout() + +- lots of others I can't remember + +NEW FUNCTIONS: + +- Too many to mention. See intro.man for a complete list of the + functions PDCurses now supports. + +COMPILER SUPPORT: + +- DJGPP 1.12 is now supported. The run-time error that caused programs + to crash has been removed. + +- emx 0.9a is supported. A program compiled for OS/2 should also work + under DOS if you use the VID=EMX switch when compiling. See the + makefile for details. + +- The Microway NDP C/C++ DOS compiler is now supported. Thanks to Wade + Schauer for this port. + +- The Watcom C++ 10.0 DOS compiler is now supported. Thanks to Pieter + Kunst for this port. + +- The library now has many functions grouped together to reduce the size + of the library and to improve the speed of compilation. + +- The "names" of a couple of the compilers in the makefile has changed; + CSET2 is now ICC and GO32 is now GCC. + +EXTRA OPTIONS: + + One difference between the behavior of PDCurses and Unix curses is the + attributes that are displayed when a character is cleared. Under Unix + curses, no attributes are displayed, so the result is always black. + Under PDCurses, these functions clear with the current attributes in + effect at the time. With the introduction of the bkgd functions, by + default, PDCurses clears using the value set by (w)bkgd(). To have + PDCurses behave the same way as it did before release 2.2, compile with + -DPDCURSES_WCLR + +ACKNOWLEDGEMENTS: (for this release) + + Pieter Kunst, David Nugent, Warren Tucker, Darin Haugen, Stefan Strack, + Wade Schauer and others who either alerted me to bugs or supplied + fixes. + +------------------------------------------------------------------------ + +PDCurses 2.1 - 1993/06/20 +========================= + +INTRODUCTION: + + The current code contains bug fixes for the DOS and OS/2 releases and + also includes an alpha release for Unix. The Unix release uses another + public domain package (mytinfo) to handle the low-level screen writes. + mytinfo was posted to comp.sources.unix (or misc) in December 1992 or + January 1993. Unless you are a glutton for punishment I would recommend + you avoid the Unix port at this stage. + + The other major addition to PDCurses is the support for DJGPP (the DOS + port of GNU C++). Thanks to David Nugent . + + Other additions are copywin() function, function debugging support and + getting the small and medium memory models to work. The testcurs.c demo + program has also been changed significantly and a new demo program, + tuidemo, has been added. + + Some people have suggested including information on where to get dmake + from. oak.oakland.edu in /pub/msdos/c + +OTHER NOTES: + + Under DOS, by default, screen writes to a CGA monitor are done via the + video BIOS rather than by direct video memory writes. This is due to + the CGA "snow" problem. If you have a CGA monitor and do not suffer + from snow, you can compile private\_queryad.c with CGA_DIRECT defined. + This will then use cause PDCurses to write directly to the CGA video + memory. + + Function debugging: Firstly to get function debugging, you have to + compile the library with OPT=N in the makefile. This also turns on + compiler debugging. You can control when you want PDCurses to write to + the debug file (called trace in the current directory) by using the + functions traceon() and traceoff() in your program. + + Microsoft C 6.00 Users note: + ---------------------------- + + With the addition of several new functions, using dmake to compile + PDCurses now causes the compiler to run "out of heap space in pass 2". + Using the 6.00AX version (DOS-Extended) to compile PDCurses fixes this + problem; hence the -EM switch. + + Functional changes + ------------------ + + Added OS/2 DLL support. + + A few curses functions have been fixed to exhibit their correct + behavior and make them more functionally portable with System V + curses. The functions that have changed are overlay(), overwrite() and + typeahead. + + overlay() and overwrite() + + Both of theses functions in PDCurses 2.0 allowed for one window to be + effectively placed on top of another, and the characters in the first + window were overlaid or overwritten starting at 0,0 in both windows. + This behavior of these functions was not correct. These functions only + operate on windows that physically overlap with respect to the + displayed screen. To achieve the same functionality as before, use the + new function copywin(). See the manual page for further details. + + typeahead() + + This function in PDCurses 2.0 effectively checked to see if there were + any characters remaining in the keyboard buffer. This is not the + behavior exhibited by System V curses. This function is intended + purely to set a flag so that curses can check while updating the + physical screen if any keyboard input is pending. To achieve the same + effect with typeahead() under PDCurses 2.1 the following code should be + used. + + In place of... + + while(!typeahead(stdin)) + { + /* do something until any key is pressed... */ + } + + use... + + /* getch() to return ERR if no key pending */ + nodelay(stdscr,TRUE); + while(getch() == (ERR)) + { + /* do something until any key is pressed... */ + } + + +ACKNOWLEDGEMENTS: (in no particular order) + + Jason Shumate, Pieter Kunst, David Nugent, Andreas Otte, Pasi + Hamalainen, James McLennan, Duane Paulson, Ib Hojme + + Apologies to anyone I may have left out. + +------------------------------------------------------------------------ + +PDCurses 2.0 - 1992/11/23 +========================= + +INTRODUCTION: + + Well, here it finally is; PDCurses v2.0. + + PDCurses v2.0 is an almost total rewrite of PCcurses 1.4 done by John + 'Frotz' Fa'atuai, the previous maintainer. It adds support for OS/2 as + well as DOS. + + This version has been tested with Microsoft C v6.0, QuickC v2.0 and + Borland C++ 2.0 under DOS and Microsoft C v6.0 and TopSpeed c v3.02 + under OS/2 2.0. Also the library has been compiled successfully with + emx 0.8e, C Set/2 and Watcom 9. Most testing was done with the large + memory model, where applicable. The large memory model is probably the + best model to use. + + The amount of testing has not been as extensive as I would have liked, + but demands on releasing a product have outweighed the product's + quality. Nothing new with that !! Hopefully with wider circulation, + more bugs will be fixed more quickly. + + I have included just 1 makefile which is suitable for dmake 3.8 for + both DOS and OS/2. The makefile does not rely on customization of the + dmake.ini file. + + If you discover bugs, and especially if you have fixes, please let me + know ASAP. + + The source to the library is distributed as a zip file made with zip + 1.9. You will need Info-ZIP unzip 5.0 to unzip. Follow the directions + below to compile the library. + +DIRECTIONS: + + 1. Create a new directory in which to unzip pdcurs20.zip. This will + create a curses directory and a number of subdirectories containing + source code for the library and utilities and the documentation. + + 2. Make changes to the makefile where necessary: + Change the MODEL or model macro to the appropriate value (if it + applies to your compiler). Use model for Borland compilers. + + Change any paths in the defined macros to be suitable for your + compiler. + + 3. Invoke DMAKE [-e environment_options] [target] + + where environment_options are: + + OS (host operating system) + COMP (compiler) + OPT (optimized version or debug version) - optional. default Y + TOS (target operating system) - optional. default OS + + see the makefile for valid combinations + + targets: all, demos, lcursesd.lib, manual... + + NB. dmake is case sensitive with targets, so those environments that + use an upper case model value (eg MSC) MUST specify the library + target as for eg. Lcursesd.lib + + The makefile is by default set up for Borland C++. The use of -e + environment_options override these defaults. If you prefer, you can + just change the defaults in the makefile and invoke it without the + -e switch. + +OTHER NOTES: + + The documentation for the library is built into each source file, a + couple of specific doc files and the header files. A program is + supplied (manext) to build the manual. This program gets compiled when + you build the documentation. + + To generate the library response file correctly, I had to write a quick + and dirty program (buildlrf) to achieve this. Originally the makefiles + just had statements like: "echo -+$(OBJ)\$* & >> $(LRF)" which appended + a suitable line to the response file. Unfortunately under some + combinations of makefiles and command processors (eg. nmake and 4DOS) + the & would get treated as stderr and the echo command would fail. + + The original source for PDCurses that I received from the previous + maintainer contained support for the FLEXOS operating system. Not + having access to it, I could not test the changes I made so its support + has fallen by the wayside. If you really need to have PDCurses running + under FLEXOS, contact me and I will see what can be arranged. + + Under DOS, by default, screen writes to a CGA monitor are done via the + video BIOS rather than by direct video memory writes. This is due to + the CGA "snow" problem. If you have a CGA monitor and do not suffer + from snow, you can compile private\_queryad.c with CGA_DIRECT defined. + This will then use cause PDCurses to write directly to the CGA video + memory. + + Added System V color support. + +COMPILER-SPECIFIC NOTES: + + Microsoft C + ----------- + + It is possible with MSC 6.0 to build the OS/2 libraries and demo + programs from within DOS. This is the only case where it is possible to + specify the value of TOS on the command line to be OS2 and the value of + OS be DOS. + + C Set/2 + ------- + + I have only tested the library using the migration libraries. I doubt + that the demo programs will work without them. + + emx + --- + + Testing has been done with 0.8e of emx together with the 16_to_32 + libraries. The emx\lib directory should include the vio32.lib and + kbd32.lib libraries from the 16_to_32 package. + +BUGS and UNFINISHED BUSINESS: + +- PDC_set_ctrl_break() function does not work under OS/2. + +- win_print() and PDC_print() do not work under OS/2. + +- The file todo.man in the doc directory also lists those functions of + System V 3.2 curses not yet implemented. Any volunteers? + +ACKNOWLEDGEMENTS: + +- John 'Frotz' Fa'atuai, the previous maintainer for providing an + excellent base for further development. +- John Burnell , for the OS/2 port. +- John Steele, Jason (finally NOT a John) Shumate.... + for various fixes and suggestions. +- Eberhardt Mattes (author of emx) for allowing code based on his + C library to be included with PDCurses. +- Several others for their support, moral and actual. + +-- Mark Hessling + +------------------------------------------------------------------------ + +PDCurses 2.0Beta - 1991/12/21 +============================= + +Changed back from short to int. (int is the correct size for the default +platform. Short might be too short on some platforms. This is more +portable. I, also, made this mistake.) + +Many functions are now macros. If you want the real thing, #undef the +macro. (X/Open requirement.) + +Merged many sources into current release. + +Added many X/Open routines (not quite all yet). + +Added internal documentation to all routines. + +Added a HISTORY file to the environment. + +Added a CONTRIB file to the environment. + +------------------------------------------------------------------------ + +PDCurses 1.5Beta - 1990/07/14 +============================= + +Added many levels of compiler support. Added mixed prototypes for all +"internal" routines. Removed all assembly language. Added EGA/VGA +support. Converted all #ifdef to #if in all modules except CURSES.H and +CURSPRIV.H. Always include ASSERT.H. Added support for an external +malloc(), calloc() and free(). Added support for FAST_VIDEO +(direct-memory writes). Added various memory model support (for +FAST_VIDEO). Added much of the December 1988 X/Open Curses +specification. + +-- John 'Frotz' Fa'atuai + +------------------------------------------------------------------------ + +PCcurses 1.4 - 1990/01/14 +========================= + + In PCcurses v.1.4, both portability improvements and bugfixes have +been made. The files have been changed to allow lint-free compilation +with Microsoft C v.5.1, and with Turbo C v.2.0. The source should still +compile without problems on older compilers, although this has not been +verified. + + The makefiles have been changed to suit both the public release and +the author, who maintains a special kind of libraries for himself. In +the case of Microsoft C, changes were done in the makefile to lower the +warning level to 2 (was 3). This was to avoid ANSI warnings which are +abundant because PCcurses does not attempt to follow strict ANSI C +standard. + + BUG FIXES FROM V.1.3 TO V.1.4: + + !!!IMPORTANT CHANGE!!! + + The definitions for OK and ERR in curses.h were exchanged. This was +done to be more consistent with UNIX versions. Also, it permits +functions like newwin() and subwin() to return 0 (=NULL) when they fail +due to memory shortage. This incompatibility with UNIX curses was +pointed out by Fred C. Smith. If you have tested success/failure by +comparisons to anything other than ERR and OK, your applications will +need to be be changed on that point. Sorry... but presumably most of you +used the symbolic constants? + + (END OF IMPORTANT CHANGE) + + Fred also pointed out a bug in the file update.c. The bug caused the +first character printed after 'unauthorized' screen changes (like during +a shell escape, for example) to be placed at the wrong screen position. +This happened even if the normal precautions (clear / touch / refresh) +were taken. The problem has now been fixed. + + PCcurses is currently also being used on a 68000 system with +hard-coded ESCape sequences for ANSI terminals. However, ints used by +the 68000 C compiler are 32 bits. Therefore ints have been turned into +shorts wherever possible in the code (otherwise all window structures +occupy twice as much space as required on the 68000). This does not +affect PC versions since normally both ints and shorts are 16 bits for +PC C compilers. + + At some places in the source code there are references made to the +68000 version. There are also a makefile, a curses68.c file, and a +curses68.cmd file. These are for making, low-level I/O, and linking +commands when building the 68000 version. These files are probably +useful to no-one but the author, since it is very specific for its +special hardware environment. Still in an effort to keep all +curses-related sources in one place they are included. Note however that +PCcurses will not officially support a non-PC environment. + + The file cursesio.c, which was included in the package at revision +level 1.2, and which was to be an alternative to the cursesio.asm file, +has been verified to behave incorrectly in the function _curseskeytst(). +The problem was that the value of 'cflag' does not contain the proper +data for the test that is attempted. Furthermore, neither Turbo C or +Microsoft C allows any way to return the data that is needed, and +consequently you should not use cursesio.c. The best solution is to +simply use the ASM version. In v.1.2 and v.1.3, the user could edit the +makefile to select which version he wanted to use. The makefiles in +v.1.4 have removed this possibility forcing the use of the ASM file, and +cursesio.c has been dropped from the distribution. + + A bug in the wgetstr() function caused PCcurses to echo characters +when reading a keyboard string, even if the echo had been turned off. +Thanks to Per Foreby at Lund University, Sweden, for this. Per also +reported bugs concerning the handling of characters with bit 8 set. +Their ASCII code were considered as lower than 32, so they were erased +etc. like control characters, i.e. erasing two character positions. The +control character test was changed to cope with this. + + The overlay() and overwrite() functions were changed so that the +overlaying window is positioned at its 'own' coordinates inside the +underlying window (it used to be at the underlying window's [0,0] +position). There is some controversy about this - the documentation for +different curses versions say different things. I think the choice made +is the most reasonable. + + The border() and wborder() functions were changed to actually draw a +border, since this seems to be the correct behavior of these functions. +They used to just set the border characters to be used by box(). These +functions are not present in standard BSD UNIX curses. + + The subwin() function previously did not allow the subwindow to be as +big as the original window in which it was created. This has now been +fixed. There was also the problem that the default size (set by +specifying numlines or numcols (or both) as 0 made the resulting actual +size 1 line/column too small. + + There were a few spelling errors in function names, both in the +function declarations and in curses.h. This was reported by Carlos +Amaral at INESC in Portugal. Thanks! There was also an unnecessary (but +harmless) parameter in a function call at one place. + +------------------------------------------------------------------------ + +PCcurses 1.3 - 1988/10/05 +========================= + + The file 'border.c' is now included. It allows you to explicitly +specify what characters should be used as box borders when the box() +functions are called. If the new border characters are non-0, they +override the border characters specified in the box() call. In my +understanding, this functionality is required for AT&T UNIX sV.3 +compatibility. Thanks for this goes to Tony L. Hansen +(hansen@pegasus.UUCP) for posting an article about it on Usenet +(newsgroup comp.unix.questions; his posting was not related at all to +PCcurses). + + The only other difference between v.1.2 and v.1.3 is that the latter +has been changed to avoid warning diagnostics if the source files are +compiled with warning switches on (for Microsoft this means '-W3', for +Turbo C it means '-w -w-pro'). Of these, the Turbo C warning check is +clearly to be used rather than Microsoft, even if neither of them comes +even close to a real UNIX 'lint'. Some of the warnings in fact indicated +real bugs, mostly functions that did not return correct return values or +types. + + The makefiles for both MSC and TRC have been modified to produce +warning messages as part of normal compilation. + +------------------------------------------------------------------------ + +PCcurses 1.2 - 1988/10/02 +========================= + + The changes from v.1.1 to v.1.2 are minor. The biggest change is that +there was a bug related to limiting the cursor movement if the +application tried to move it outside the screen (something that should +not be done anyway). Such erroneous application behavior is now handled +appropriately. + + All modules have been changed to have a revision string in them, which +makes it easier to determine what version is linked into a program (or +what library version you have). + + There is now a 'cursesio.c' file. That file does the same as +'cursesio.asm' (i.e. it provides the interface to the lower-level system +I/O routines). It is written in C and thus it is (possibly) more +portable than the assembler version (but still not so portable since it +uses 8086 INT XX calls directly). When one creates new curses libraries, +one chooses whether to use the assembler or the C version of cursesio. +The choice is made by commenting out the appropriate dependencies for +cursesio.obj, near the end of the makefiles. + + There is now a 'setmode.c' file. That file contains functions that +save and restore terminal modes. They do it into other variables than do +savetty() and resetty(), so one should probably use either +savetty()/resetty() or the new functions only - and not mix the both +ways unless one really knows what one does. + + Diff lists vs v.1.0 are no longer included in the distribution. The +make utility still is. PCcurses v.1.2 still compiles with Microsoft C +v.4.0, and with Borland Turbo C v.1.0. There is as far as I know no +reason to believe that it does not compile under Microsoft C v.3.0 and +5.x, or Turbo C v.1.5, but this has not been tested. + + There are two makefiles included, one for Microsoft C, one for Turbo +C. They are both copies of my personal makefiles, and as such they +reflect the directory structure on my own computer. This will have to be +changed before you run make. Check $(INCDIR) and $(LIBDIR) in +particular, and make the choice of ASM or C cursesio version as +mentioned above (the distribution version uses the C version of +cursesio). + + The manual file (curses.man) has been changed at appropriate places. + + I would like to thank the following persons for their help: + + Brandon S. Allbery (alberry@ncoast.UUCP) + for running comp.binaries.ibm.pc (at that time) + and comp.source.misc. + + Steve Balogh (Steve@cit5.cit.oz.AU) + for writing a set of manual pages and posting + them to the net. + + Torbjorn Lindh + for finding bugs and suggesting raw + character output routines. + + Nathan Glasser (nathan@eddie.mit.edu) + for finding and reporting bugs. + + Ingvar Olafsson (...enea!hafro!ingvar) + for finding and reporting bugs. + + Eric Rosco (...enea!ipmoea!ericr) + for finding and reporting bugs. + + Steve Creps (creps@silver.bacs.indiana.edu) + for doing a lot of work - among others + posting bug fixes to the net, and writing + the new cursesio.c module. + + N. Dean Pentcheff (dean@violet.berkeley.edu) + for finding bugs and rewriting cursesio.asm + for Turbo 'C' 1.5. + + Finally, Jeff Dean (parcvax,hplabs}!cdp!jeff) + (jeff@ads.arpa) + has had a shareware version of curses deliverable since + about half a year before I released PCcurses 1.0 on Use- + Net. He is very concerned about confusion between the two + packages, and therefore any references on the network + should make clear whether they reference Dean's PCcurses + or Larsson's PCcurses. + +------------------------------------------------------------------------ + +PCcurses 1.1 - 1988/03/06 +========================= + + The changes from v.1.0 to v.1.1 are minor. There are a few bug fixes, +and new (non-portable) functions for verbatim IBM character font display +have been added (in charadd.c and charins.c). The manual file +(curses.man) has been changed at appropriate places. + + In the file v10tov11.dif there are listings of the differences between +version 1.0 and 1.1. The diff listings are in UNIX diff(1) format. + + Version 1.1 compiles with Turbo C v.1.0, as well as Microsoft C v.3.0 +and v.4.0. On the release disk there is a make.exe utility which is very +similar to UNIX make (If the package was mailed to you, the make utility +will be in uuencoded format - in make.uu - and must be uudecoded first). +It is much more powerful than Microsoft's different MAKEs; the latter +ones will NOT generate libraries properly if used with the PCcurses +makefiles. + + There are three makefiles: + + makefile generic MSC 3.0 makefile + makefile.ms MSC 4.0 makefile + makefile.tc Turbo C 1.0 makefile + + To make a library with for example Turbo C, make directories to hold +.H and .LIB files (these directories are the 'standard places'), edit +makefile.tc for this, and type + + make -f makefile.tc all + +and libraries for all memory models will be created in the .LIB +directory, while the include files will end up in the .H directory. Also +read what is said about installation below! + +------------------------------------------------------------------------ + +PCcurses 1.0 - 1987/08/24 +========================= + + This is the release notes for the PCcurses v.1.0 cursor/window control +package. PCcurses offers the functionality of UNIX curses, plus some +extras. Normally it should be possible to port curses-based programs +from UNIX curses to PCcurses on the IBM PC without changes. PCcurses is +a port/ rewrite of Pavel Curtis' public domain 'ncurses' package. All +the code has been re-written - it is not just an edit of ncurses (or +UNIX curses). I mention this to clarify any copyright violation claims. +The data structures and ideas are very similar to ncurses. As for UNIX +curses, I have not even seen any sources for it. + + For an introduction to the use of 'curses' and its derivatives, you +should read 'Screen Updating and Cursor Movement Optimization: A Library +Package' by Kenneth C. R. C. Arnold, which describes the original +Berkeley UNIX version of curses. It is available as part of the UNIX +manuals. The other source of information is 'The Ncurses Reference +Manual' by Pavel Curtis. The latter is part of Curtis' ncurses package. + + The only other documentation provided is a 'man' page which describes +all the included functions in a very terse way. In the sources, each +function is preceded by a rather thorough description of what the +function does. I didn't have time to write a nice manual/tutorial - +sorry. + + PCcurses is released as a number of source files, a man page, and a +make file. A uuencoded copy of a 'make' utility, and a manpage for the +'make' is also provided to make it easier to put together PCcurses +libraries. Even if you are not interested in PCcurses, it may be +worthwhile to grab the make. + + The makefile assumes the presence of the Microsoft C compiler (3.0 or +4.0), Microsoft MASM and LIB, plus some MS-DOS utilities. The reason for +supplying MAKE.EXE is that the Microsoft 'MAKE:s' are much inferior to a +real UNIX make. The supplied make is a port of a public domain make, +published on Usenet. It is almost completely compatible with UNIX make. +When generating the curses libraries, the makefile will direct make to +do some directory creating and file copying, and then re-invoke itself +with new targets. The workings of the makefile are not absolutely +crystal clear at first sight... just start it and see what it does. + + For portability, the curses libraries depend on one assembler file for +access to the BIOS routines. There is no support for the EGA, but both +CGA, MGA, and the HGA can be used. The libraries are originally for +Microsoft C, but all C modules should be portable right away. In the +assembler file, segment names probably need to be changed, and possibly +the parameter passing scheme. I think Turbo C will work right away - as +far as I understand, all its conventions are compatible with Microsoft +C. + + There are some parts left out between ncurses and PCcurses. One is the +support for multiple terminals - not very interesting on a PC anyway. +Because we KNOW what terminal we have, there is no need for a termcap or +terminfo library. PCcurses also has some things that neither curses nor +ncurses have. Compared to the original UNIX curses, PCcurses has lots of +extras. + + The BIOS routines are used directly, which gives fast screen updates. +PCcurses does not do direct writes to screen RAM - in my opinion it is +a bit ugly to rely that much on hardware compatibility. Anyone could fix +that, of course... + + One of the more serious problems with PCcurses is the way in which +normal, cbreak, and raw input modes are done. All those details are in +the 'charget' module - I do raw I/O via the BIOS, and perform any +buffering myself. If an application program uses PCcurses, it should do +ALL its I/O via PCcurses calls, otherwise the mix of normal and +PCcurses I/O may mess up the display. I think my code is reasonable... +comments are welcome, provided you express them nicely... + + To install, copy all files to a work directory, edit 'makefile' to +define the standard include and library file directory names of your +choice (these directories must exist already, and their path names must +be relative to the root directory, not to the current one). You must +also run uudecode on make.uu, to generate MAKE.EXE. You can do that on +your PC, if you have uudecode there, otherwise you can do it under UNIX +and do a binary transfer to the PC. When you have MAKE.EXE in your work +directory (or in your /bin directory), type make. + + Make will now create 4 sub-directories (one for each memory model), +copy some assembler include files into them, copy two include files to +your include directory, CHDIR to each sub-directory and re-invoke itself +with other make targets to compile and assemble all the source files +into the appropriate directories. Then the library manager is run to +create the library files in your desired library directory. Presto! + + If you only want to generate a library for one memory model, type +'make small', 'make large', etc. The name of the memory model must be in +lower case, like in the makefile. + + I think the package is fairly well debugged - but then again, that's +what I always think. It was completed in May-87, and no problems found +yet. Now it's your turn... Comments, suggestions and bug reports and +fixes (no flames please) to + +-- Bjorn Larsson diff --git a/modules/ncurses/pdcurses/IMPLEMNT.md b/modules/ncurses/pdcurses/IMPLEMNT.md new file mode 100644 index 00000000..a7c691ee --- /dev/null +++ b/modules/ncurses/pdcurses/IMPLEMNT.md @@ -0,0 +1,329 @@ +PDCurses Implementor's Guide +============================ + +- Version 1.3 - 2018/01/12 - notes about official ports, new indentation + style; markdown +- Version 1.2 - 2007/07/11 - added PDC_init_pair(), PDC_pair_content(), + version history; removed pdc_atrtab +- Version 1.1 - 2007/06/06 - minor cosmetic change +- Version 1.0 - 2007/04/01 - initial revision + +This document is for those wishing to port PDCurses to a new platform, +or just wanting to better understand how it works. Nothing here should +be needed for application programming; for that, refer to PDCurses.md, +as built in doc/, or distributed as a file separate from this source +package. This document assumes that you've read the user-level +documentation and are very familiar with application-level curses +programming. + +If you want to submit your port for possible inclusion into the main +PDCurses distribution, please follow these guidelines: + + - Don't modify anything in the pdcurses directory or in other port + directories. Don't modify curses.h or curspriv.h unless absolutely + necessary. (And prefer modifying curspriv.h over curses.h.) + + - Use the same indentation style, naming and scope conventions as the + existing code. + + - Release all your code to the public domain -- no copyright. Code + under GPL, BSD, etc. will not be accepted. + + +Data Structures +=============== + +A port of PDCurses must provide acs_map[], a 128-element array of +chtypes, with values laid out based on the Alternate Character Set of +the VT100 (see curses.h). PDC_transform_line() must use this table; when +it encounters a chtype with the A_ALTCHARSET flag set, and an A_CHARTEXT +value in the range 0-127, it must render it using the A_CHARTEXT portion +of the corresponding value from this table, instead of the original +value. Also, values may be read from this table by apps, and passed +through functions such as waddch(), which does no special processing on +control characters (0-31 and 127) when the A_ALTCHARSET flag is set. +Thus, any control characters used in acs_map[] should also have the +A_ALTCHARSET flag set. Implementations should provide suitable values +for all the ACS_ macros defined in curses.h; other values in the table +should be filled with their own indices (e.g., acs_map['E'] == 'E'). The +table can be either hardwired, or filled by PDC_scr_open(). Existing +ports define it in pdcdisp.c, but this is not required. + + +Functions +========= + +A port of PDCurses must implement the following functions, with extern +scope. These functions are traditionally divided into several modules, +as indicated below; this division is not required (only the functions +are), but may make it easier to follow for someone familiar with the +existing ports. + +Any other functions you create as part of your implementation should +have static scope, if possible. If they can't be static, they should be +named with the "PDC_" prefix. This minimizes the risk of collision with +an application's choices. + +Current PDCurses style also uses a single leading underscore with the +name of any static function; and modified BSD/Allman-style indentation, +approximately equivalent to "indent -kr -nut -bl -bli0", with +adjustments to keep every line under 80 columns. + + +pdcdisp.c: +---------- + +### void PDC_gotoyx(int y, int x); + +Move the physical cursor (as opposed to the logical cursor affected by +wmove()) to the given location. This is called mainly from doupdate(). +In general, this function need not compare the old location with the new +one, and should just move the cursor unconditionally. + +### void PDC_transform_line(int lineno, int x, int len, const chtype *srcp); + +The core output routine. It takes len chtype entities from srcp (a +pointer into curscr) and renders them to the physical screen at line +lineno, column x. It must also translate characters 0-127 via acs_map[], +if they're flagged with A_ALTCHARSET in the attribute portion of the +chtype. + + +pdcgetsc.c: +----------- + +### int PDC_get_columns(void); + +Returns the size of the screen in columns. It's used in resize_term() to +set the new value of COLS. (Some existing implementations also call it +internally from PDC_scr_open(), but this is not required.) + +### int PDC_get_cursor_mode(void); + +Returns the size/shape of the cursor. The format of the result is +unspecified, except that it must be returned as an int. This function is +called from initscr(), and the result is stored in SP->orig_cursor, +which is used by PDC_curs_set() to determine the size/shape of the +cursor in normal visibility mode (curs_set(1)). + +### int PDC_get_rows(void); + +Returns the size of the screen in rows. It's used in resize_term() to +set the new value of LINES. (Some existing implementations also call it +internally from PDC_scr_open(), but this is not required.) + + +pdckbd.c: +--------- + +### bool PDC_check_key(void); + +Keyboard/mouse event check, called from wgetch(). Returns TRUE if +there's an event ready to process. This function must be non-blocking. + +### void PDC_flushinp(void); + +This is the core of flushinp(). It discards any pending key or mouse +events, removing them from any internal queue and from the OS queue, if +applicable. + +### int PDC_get_key(void); + +Get the next available key, or mouse event (indicated by a return of +KEY_MOUSE), and remove it from the OS' input queue, if applicable. This +function is called from wgetch(). This function may be blocking, and +traditionally is; but it need not be. If a valid key or mouse event +cannot be returned, for any reason, this function returns -1. Valid keys +are those that fall within the appropriate character set, or are in the +list of special keys found in curses.h (KEY_MIN through KEY_MAX). When +returning a special key code, this routine must also set SP->key_code to +TRUE; otherwise it must set it to FALSE. If SP->return_key_modifiers is +TRUE, this function may return modifier keys (shift, control, alt), +pressed alone, as special key codes; if SP->return_key_modifiers is +FALSE, it must not. If modifier keys are returned, it should only happen +if no other keys were pressed in the meantime; i.e., the return should +happen on key up. But if this is not possible, it may return the +modifier keys on key down (if and only if SP->return_key_modifiers is +TRUE). + +### int PDC_modifiers_set(void); + +Called from PDC_return_key_modifiers(). If your platform needs to do +anything in response to a change in SP->return_key_modifiers, do it +here. Returns OK or ERR, which is passed on by the caller. + +### int PDC_mouse_set(void); + +Called by mouse_set(), mouse_on(), and mouse_off() -- all the functions +that modify SP->_trap_mbe. If your platform needs to do anything in +response to a change in SP->_trap_mbe (for example, turning the mouse +cursor on or off), do it here. Returns OK or ERR, which is passed on by +the caller. + +### void PDC_set_keyboard_binary(bool on); + +Set keyboard input to "binary" mode. If you need to do something to keep +the OS from processing ^C, etc. on your platform, do it here. TRUE turns +the mode on; FALSE reverts it. This function is called from raw() and +noraw(). + + +pdcscrn.c: +---------- + +### bool PDC_can_change_color(void); + +Returns TRUE if init_color() and color_content() give meaningful +results, FALSE otherwise. Called from can_change_color(). + +### int PDC_color_content(short color, short *red, short *green, short *blue); + +The core of color_content(). This does all the work of that function, +except checking for values out of range and null pointers. + +### int PDC_init_color(short color, short red, short green, short blue); + +The core of init_color(). This does all the work of that function, +except checking for values out of range. + +### void PDC_init_pair(short pair, short fg, short bg); + +The core of init_pair(). This does all the work of that function, except +checking for values out of range. The values passed to this function +should be returned by a call to PDC_pair_content() with the same pair +number. PDC_transform_line() should use the specified colors when +rendering a chtype with the given pair number. + +### int PDC_pair_content(short pair, short *fg, short *bg); + +The core of pair_content(). This does all the work of that function, +except checking for values out of range and null pointers. + +### void PDC_reset_prog_mode(void); + +The non-portable functionality of reset_prog_mode() is handled here -- +whatever's not done in _restore_mode(). In current ports: In OS/2, this +sets the keyboard to binary mode; in Windows console, it enables or +disables the mouse pointer to match the saved mode; in others it does +nothing. + +### void PDC_reset_shell_mode(void); + +The same thing, for reset_shell_mode(). In OS/2 and Windows console, it +restores the default console mode; in others it does nothing. + +### int PDC_resize_screen(int nlines, int ncols); + +This does the main work of resize_term(). It may respond to non-zero +parameters, by setting the screen to the specified size; to zero +parameters, by setting the screen to a size chosen by the user at +runtime, in an unspecified way (e.g., by dragging the edges of the +window); or both. It may also do nothing, if there's no appropriate +action for the platform. + +### void PDC_restore_screen_mode(int i); + +Called from _restore_mode() in kernel.c, this function does the actual +mode changing, if applicable. Currently used only in DOS and OS/2. + +### void PDC_save_screen_mode(int i); + +Called from _save_mode() in kernel.c, this function saves the actual +screen mode, if applicable. Currently used only in DOS and OS/2. + +### void PDC_scr_close(void); + +The platform-specific part of endwin(). It may restore the image of the +original screen saved by PDC_scr_open(), if the PDC_RESTORE_SCREEN +environment variable is set; either way, if using an existing terminal, +this function should restore it to the mode it had at startup, and move +the cursor to the lower left corner. (The X11 port does nothing.) + +### void PDC_scr_free(void); + +Frees the memory for SP allocated by PDC_scr_open(). Called by +delscreen(). + +### int PDC_scr_open(int argc, char **argv); + +The platform-specific part of initscr(). It's actually called from +Xinitscr(); the arguments, if present, correspond to those used with +main(), and may be used to set the title of the terminal window, or for +other, platform-specific purposes. (The arguments are currently used +only in X11.) PDC_scr_open() must allocate memory for SP, and must +initialize acs_map[] (unless it's preset) and several members of SP, +including lines, cols, mouse_wait, orig_attr (and if orig_attr is TRUE, +orig_fore and orig_back), mono, _restore and _preserve. (Although SP is +used the same way in all ports, it's allocated here in order to allow +the X11 port to map it to a block of shared memory.) If using an +existing terminal, and the environment variable PDC_RESTORE_SCREEN is +set, this function may also store the existing screen image for later +restoration by PDC_scr_close(). + + +pdcsetsc.c: +----------- + +### int PDC_curs_set(int visibility); + +Called from curs_set(). Changes the appearance of the cursor -- 0 turns +it off, 1 is normal (the terminal's default, if applicable, as +determined by SP->orig_cursor), and 2 is high visibility. The exact +appearance of these modes is not specified. + + +pdcutil.c: +---------- + +### void PDC_beep(void); + +Emits a short audible beep. If this is not possible on your platform, +you must set SP->audible to FALSE during initialization (i.e., from +PDC_scr_open() -- not here); otherwise, set it to TRUE. This function is +called from beep(). + +### void PDC_napms(int ms); + +This is the core delay routine, called by napms(). It pauses for about +(the X/Open spec says "at least") ms milliseconds, then returns. High +degrees of accuracy and precision are not expected (though desirable, if +you can achieve them). More important is that this function gives back +the process' time slice to the OS, so that PDCurses idles at low CPU +usage. + +### const char *PDC_sysname(void); + +Returns a short string describing the platform, such as "DOS" or "X11". +This is used by longname(). It must be no more than 100 characters; it +should be much, much shorter (existing platforms use no more than 5). + + +More functions +============== + +The following functions are implemented in the platform directories, but +are accessed directly by apps. Refer to the user documentation for their +descriptions: + + +pdcclip.c: +---------- + +### int PDC_clearclipboard(void); +### int PDC_freeclipboard(char *contents); +### int PDC_getclipboard(char **contents, long *length); +### int PDC_setclipboard(const char *contents, long length); + + +pdckbd.c: +--------- + +### unsigned long PDC_get_input_fd(void); + + +pdcsetsc.c: +----------- + +### int PDC_set_blink(bool blinkon); +### int PDC_set_bold(bool boldon); +### void PDC_set_title(const char *title); diff --git a/modules/ncurses/pdcurses/README.md b/modules/ncurses/pdcurses/README.md new file mode 100644 index 00000000..0c3d803c --- /dev/null +++ b/modules/ncurses/pdcurses/README.md @@ -0,0 +1,55 @@ +Welcome to PDCurses! +==================== + +Public Domain Curses, aka PDCurses, is an implementation of X/Open +curses for multiple platforms. The latest version can be found at: + + http://pdcurses.org/ + +For changes, see the [HISTORY](HISTORY.md) file. + + +Legal Stuff +----------- + +The core package is in the public domain, but small portions of PDCurses +are subject to copyright under various licenses. Each directory +contains a README.md file, with a section titled "Distribution Status" +which describes the status of the files in that directory. + +If you use PDCurses in an application, an acknowledgement would be +appreciated, but is not mandatory. If you make corrections or +enhancements to PDCurses, please forward them to the current maintainer +for the benefit of other users. + +This software is provided AS IS with NO WARRANTY whatsoever. + + +Ports +----- + +PDCurses has been ported to DOS, OS/2, Windows, X11 and SDL. A directory +containing the port-specific source files exists for each of these +platforms. + +Build instructions are in the README.md file for each platform: + +- [DOS](dos/README.md) +- [OS/2](os2/README.md) +- [SDL 1.x](sdl1/README.md) +- [SDL 2.x](sdl2/README.md) +- [Windows](wincon/README.md) +- [X11](x11/README.md) + + +Distribution Status +------------------- + +All files in this directory (not including subdirectories) are released +to the Public Domain. + + +Maintainer +---------- + +William McBrine diff --git a/modules/ncurses/pdcurses/curses.h b/modules/ncurses/pdcurses/curses.h new file mode 100644 index 00000000..cac4b414 --- /dev/null +++ b/modules/ncurses/pdcurses/curses.h @@ -0,0 +1,1397 @@ +/* Public Domain Curses */ + +/*----------------------------------------------------------------------* + * PDCurses * + *----------------------------------------------------------------------*/ + +#ifndef __PDCURSES__ +#define __PDCURSES__ 1 + +/*man-start************************************************************** + +PDCurses definitions list: (Only define those needed) + + XCURSES True if compiling for X11. + PDC_RGB True if you want to use RGB color definitions + (Red = 1, Green = 2, Blue = 4) instead of BGR. + PDC_WIDE True if building wide-character support. + PDC_DLL_BUILD True if building a Windows DLL. + NCURSES_MOUSE_VERSION Use the ncurses mouse API instead + of PDCurses' traditional mouse API. + +PDCurses portable platform definitions list: + + PDC_BUILD Defines API build version. + PDCURSES Enables access to PDCurses-only routines. + XOPEN Always true. + SYSVcurses True if you are compiling for SYSV portability. + BSDcurses True if you are compiling for BSD portability. + +**man-end****************************************************************/ + +#define PDC_BUILD 3502 +#define PDCURSES 1 /* PDCurses-only routines */ +#define XOPEN 1 /* X/Open Curses routines */ +#define SYSVcurses 1 /* System V Curses routines */ +#define BSDcurses 1 /* BSD Curses routines */ +#define CHTYPE_LONG 1 /* size of chtype; long */ + +/*----------------------------------------------------------------------*/ + +#include +#include +#include /* Required by X/Open usage below */ + +#ifdef PDC_WIDE +# include +#endif + +#if defined(__cplusplus) || defined(__cplusplus__) || defined(__CPLUSPLUS) +extern "C" +{ +# define bool _bool +#endif + +/*---------------------------------------------------------------------- + * + * PDCurses Manifest Constants + * + */ + +#ifndef FALSE +# define FALSE 0 +#endif +#ifndef TRUE +# define TRUE 1 +#endif +#ifndef NULL +# define NULL (void *)0 +#endif +#ifndef ERR +# define ERR (-1) +#endif +#ifndef OK +# define OK 0 +#endif + +/*---------------------------------------------------------------------- + * + * PDCurses Type Declarations + * + */ + +typedef unsigned char bool; /* PDCurses Boolean type */ + +#ifdef CHTYPE_LONG +# if _LP64 +typedef unsigned int chtype; +# else +typedef unsigned long chtype; /* 16-bit attr + 16-bit char */ +# endif +#else +typedef unsigned short chtype; /* 8-bit attr + 8-bit char */ +#endif + +#ifdef PDC_WIDE +typedef chtype cchar_t; +#endif + +typedef chtype attr_t; + +/*---------------------------------------------------------------------- + * + * PDCurses Mouse Interface -- SYSVR4, with extensions + * + */ + +typedef struct +{ + int x; /* absolute column, 0 based, measured in characters */ + int y; /* absolute row, 0 based, measured in characters */ + short button[3]; /* state of each button */ + int changes; /* flags indicating what has changed with the mouse */ +} MOUSE_STATUS; + +#define BUTTON_RELEASED 0x0000 +#define BUTTON_PRESSED 0x0001 +#define BUTTON_CLICKED 0x0002 +#define BUTTON_DOUBLE_CLICKED 0x0003 +#define BUTTON_TRIPLE_CLICKED 0x0004 +#define BUTTON_MOVED 0x0005 /* PDCurses */ +#define WHEEL_SCROLLED 0x0006 /* PDCurses */ +#define BUTTON_ACTION_MASK 0x0007 /* PDCurses */ + +#define PDC_BUTTON_SHIFT 0x0008 /* PDCurses */ +#define PDC_BUTTON_CONTROL 0x0010 /* PDCurses */ +#define PDC_BUTTON_ALT 0x0020 /* PDCurses */ +#define BUTTON_MODIFIER_MASK 0x0038 /* PDCurses */ + +#define MOUSE_X_POS (Mouse_status.x) +#define MOUSE_Y_POS (Mouse_status.y) + +/* + * Bits associated with the .changes field: + * 3 2 1 0 + * 210987654321098765432109876543210 + * 1 <- button 1 has changed + * 10 <- button 2 has changed + * 100 <- button 3 has changed + * 1000 <- mouse has moved + * 10000 <- mouse position report + * 100000 <- mouse wheel up + * 1000000 <- mouse wheel down + * 10000000 <- mouse wheel left + * 100000000 <- mouse wheel right + */ + +#define PDC_MOUSE_MOVED 0x0008 +#define PDC_MOUSE_POSITION 0x0010 +#define PDC_MOUSE_WHEEL_UP 0x0020 +#define PDC_MOUSE_WHEEL_DOWN 0x0040 +#define PDC_MOUSE_WHEEL_LEFT 0x0080 +#define PDC_MOUSE_WHEEL_RIGHT 0x0100 + +#define A_BUTTON_CHANGED (Mouse_status.changes & 7) +#define MOUSE_MOVED (Mouse_status.changes & PDC_MOUSE_MOVED) +#define MOUSE_POS_REPORT (Mouse_status.changes & PDC_MOUSE_POSITION) +#define BUTTON_CHANGED(x) (Mouse_status.changes & (1 << ((x) - 1))) +#define BUTTON_STATUS(x) (Mouse_status.button[(x) - 1]) +#define MOUSE_WHEEL_UP (Mouse_status.changes & PDC_MOUSE_WHEEL_UP) +#define MOUSE_WHEEL_DOWN (Mouse_status.changes & PDC_MOUSE_WHEEL_DOWN) +#define MOUSE_WHEEL_LEFT (Mouse_status.changes & PDC_MOUSE_WHEEL_LEFT) +#define MOUSE_WHEEL_RIGHT (Mouse_status.changes & PDC_MOUSE_WHEEL_RIGHT) + +/* mouse bit-masks */ + +#define BUTTON1_RELEASED 0x00000001L +#define BUTTON1_PRESSED 0x00000002L +#define BUTTON1_CLICKED 0x00000004L +#define BUTTON1_DOUBLE_CLICKED 0x00000008L +#define BUTTON1_TRIPLE_CLICKED 0x00000010L +#define BUTTON1_MOVED 0x00000010L /* PDCurses */ + +#define BUTTON2_RELEASED 0x00000020L +#define BUTTON2_PRESSED 0x00000040L +#define BUTTON2_CLICKED 0x00000080L +#define BUTTON2_DOUBLE_CLICKED 0x00000100L +#define BUTTON2_TRIPLE_CLICKED 0x00000200L +#define BUTTON2_MOVED 0x00000200L /* PDCurses */ + +#define BUTTON3_RELEASED 0x00000400L +#define BUTTON3_PRESSED 0x00000800L +#define BUTTON3_CLICKED 0x00001000L +#define BUTTON3_DOUBLE_CLICKED 0x00002000L +#define BUTTON3_TRIPLE_CLICKED 0x00004000L +#define BUTTON3_MOVED 0x00004000L /* PDCurses */ + +/* For the ncurses-compatible functions only, BUTTON4_PRESSED and + BUTTON5_PRESSED are returned for mouse scroll wheel up and down; + otherwise PDCurses doesn't support buttons 4 and 5 */ + +#define BUTTON4_RELEASED 0x00008000L +#define BUTTON4_PRESSED 0x00010000L +#define BUTTON4_CLICKED 0x00020000L +#define BUTTON4_DOUBLE_CLICKED 0x00040000L +#define BUTTON4_TRIPLE_CLICKED 0x00080000L + +#define BUTTON5_RELEASED 0x00100000L +#define BUTTON5_PRESSED 0x00200000L +#define BUTTON5_CLICKED 0x00400000L +#define BUTTON5_DOUBLE_CLICKED 0x00800000L +#define BUTTON5_TRIPLE_CLICKED 0x01000000L + +#define MOUSE_WHEEL_SCROLL 0x02000000L /* PDCurses */ +#define BUTTON_MODIFIER_SHIFT 0x04000000L /* PDCurses */ +#define BUTTON_MODIFIER_CONTROL 0x08000000L /* PDCurses */ +#define BUTTON_MODIFIER_ALT 0x10000000L /* PDCurses */ + +#define ALL_MOUSE_EVENTS 0x1fffffffL +#define REPORT_MOUSE_POSITION 0x20000000L + +/* ncurses mouse interface */ + +typedef unsigned long mmask_t; + +typedef struct +{ + short id; /* unused, always 0 */ + int x, y, z; /* x, y same as MOUSE_STATUS; z unused */ + mmask_t bstate; /* equivalent to changes + button[], but + in the same format as used for mousemask() */ +} MEVENT; + +#ifdef NCURSES_MOUSE_VERSION +# define BUTTON_SHIFT BUTTON_MODIFIER_SHIFT +# define BUTTON_CONTROL BUTTON_MODIFIER_CONTROL +# define BUTTON_CTRL BUTTON_MODIFIER_CONTROL +# define BUTTON_ALT BUTTON_MODIFIER_ALT +#else +# define BUTTON_SHIFT PDC_BUTTON_SHIFT +# define BUTTON_CONTROL PDC_BUTTON_CONTROL +# define BUTTON_ALT PDC_BUTTON_ALT +#endif + +/*---------------------------------------------------------------------- + * + * PDCurses Structure Definitions + * + */ + +typedef struct _win /* definition of a window */ +{ + int _cury; /* current pseudo-cursor */ + int _curx; + int _maxy; /* max window coordinates */ + int _maxx; + int _begy; /* origin on screen */ + int _begx; + int _flags; /* window properties */ + chtype _attrs; /* standard attributes and colors */ + chtype _bkgd; /* background, normally blank */ + bool _clear; /* causes clear at next refresh */ + bool _leaveit; /* leaves cursor where it is */ + bool _scroll; /* allows window scrolling */ + bool _nodelay; /* input character wait flag */ + bool _immed; /* immediate update flag */ + bool _sync; /* synchronise window ancestors */ + bool _use_keypad; /* flags keypad key mode active */ + chtype **_y; /* pointer to line pointer array */ + int *_firstch; /* first changed character in line */ + int *_lastch; /* last changed character in line */ + int _tmarg; /* top of scrolling region */ + int _bmarg; /* bottom of scrolling region */ + int _delayms; /* milliseconds of delay for getch() */ + int _parx, _pary; /* coords relative to parent (0,0) */ + struct _win *_parent; /* subwin's pointer to parent win */ +} WINDOW; + +/* Avoid using the SCREEN struct directly -- use the corresponding + functions if possible. This struct may eventually be made private. */ + +typedef struct +{ + bool alive; /* if initscr() called, and not endwin() */ + bool autocr; /* if cr -> lf */ + bool cbreak; /* if terminal unbuffered */ + bool echo; /* if terminal echo */ + bool raw_inp; /* raw input mode (v. cooked input) */ + bool raw_out; /* raw output mode (7 v. 8 bits) */ + bool audible; /* FALSE if the bell is visual */ + bool mono; /* TRUE if current screen is mono */ + bool resized; /* TRUE if TERM has been resized */ + bool orig_attr; /* TRUE if we have the original colors */ + short orig_fore; /* original screen foreground color */ + short orig_back; /* original screen foreground color */ + int cursrow; /* position of physical cursor */ + int curscol; /* position of physical cursor */ + int visibility; /* visibility of cursor */ + int orig_cursor; /* original cursor size */ + int lines; /* new value for LINES */ + int cols; /* new value for COLS */ + unsigned long _trap_mbe; /* trap these mouse button events */ + unsigned long _map_mbe_to_key; /* map mouse buttons to slk */ + int mouse_wait; /* time to wait (in ms) for a + button release after a press, in + order to count it as a click */ + int slklines; /* lines in use by slk_init() */ + WINDOW *slk_winptr; /* window for slk */ + int linesrippedoff; /* lines ripped off via ripoffline() */ + int linesrippedoffontop; /* lines ripped off on + top via ripoffline() */ + int delaytenths; /* 1/10ths second to wait block + getch() for */ + bool _preserve; /* TRUE if screen background + to be preserved */ + int _restore; /* specifies if screen background + to be restored, and how */ + bool save_key_modifiers; /* TRUE if each key modifiers saved + with each key press */ + bool return_key_modifiers; /* TRUE if modifier keys are + returned as "real" keys */ + bool key_code; /* TRUE if last key is a special key; + used internally by get_wch() */ +#ifdef XCURSES + int XcurscrSize; /* size of Xcurscr shared memory block */ + bool sb_on; + int sb_viewport_y; + int sb_viewport_x; + int sb_total_y; + int sb_total_x; + int sb_cur_y; + int sb_cur_x; +#endif + short line_color; /* color of line attributes - default -1 */ + attr_t termattrs; /* attribute capabilities */ +} SCREEN; + +/*---------------------------------------------------------------------- + * + * PDCurses External Variables + * + */ + +#ifdef PDC_DLL_BUILD +# ifdef CURSES_LIBRARY +# define PDCEX __declspec(dllexport) extern +# else +# define PDCEX __declspec(dllimport) +# endif +#else +# define PDCEX extern +#endif + +PDCEX int LINES; /* terminal height */ +PDCEX int COLS; /* terminal width */ +PDCEX WINDOW *stdscr; /* the default screen window */ +PDCEX WINDOW *curscr; /* the current screen image */ +PDCEX SCREEN *SP; /* curses variables */ +PDCEX MOUSE_STATUS Mouse_status; +PDCEX int COLORS; +PDCEX int COLOR_PAIRS; +PDCEX int TABSIZE; +PDCEX chtype acs_map[]; /* alternate character set map */ +PDCEX char ttytype[]; /* terminal name/description */ + +/*man-start************************************************************** + +PDCurses Text Attributes +======================== + +Originally, PDCurses used a short (16 bits) for its chtype. To include +color, a number of things had to be sacrificed from the strict Unix and +System V support. The main problem was fitting all character attributes +and color into an unsigned char (all 8 bits!). + +Today, PDCurses by default uses a long (32 bits) for its chtype, as in +System V. The short chtype is still available, by undefining CHTYPE_LONG +and rebuilding the library. + +The following is the structure of a win->_attrs chtype: + +short form: + + +-----------------------------------------------+ + |15|14|13|12|11|10| 9| 8| 7| 6| 5| 4| 3| 2| 1| 0| + +-----------------------------------------------+ + color number | attrs | character eg 'a' + +The available non-color attributes are bold, reverse and blink. Others +have no effect. The high order char is an index into an array of +physical colors (defined in color.c) -- 32 foreground/background color +pairs (5 bits) plus 3 bits for other attributes. + +long form: + + +--------------------------------------------------------------------+ + |31|30|29|28|27|26|25|24|23|22|21|20|19|18|17|16|15|14|13|..| 2| 1| 0| + +--------------------------------------------------------------------+ + color number | modifiers | character eg 'a' + +The available non-color attributes are bold, underline, right-line, +left-line, italic, reverse and blink, plus the alternate character set +indicator. 256 color pairs (8 bits), 8 bits for other attributes, and 16 +bits for character data. + +**man-end****************************************************************/ + +/*** Video attribute macros ***/ + +#define A_NORMAL (chtype)0 + +#ifdef CHTYPE_LONG +# define A_ALTCHARSET (chtype)0x00010000 +# define A_RIGHT (chtype)0x00020000 +# define A_LEFT (chtype)0x00040000 +# define A_ITALIC (chtype)0x00080000 +# define A_UNDERLINE (chtype)0x00100000 +# define A_REVERSE (chtype)0x00200000 +# define A_BLINK (chtype)0x00400000 +# define A_BOLD (chtype)0x00800000 + +# define A_ATTRIBUTES (chtype)0xffff0000 +# define A_CHARTEXT (chtype)0x0000ffff +# define A_COLOR (chtype)0xff000000 + +# define PDC_COLOR_SHIFT 24 +#else +# define A_BOLD (chtype)0x0100 /* X/Open */ +# define A_REVERSE (chtype)0x0200 /* X/Open */ +# define A_BLINK (chtype)0x0400 /* X/Open */ + +# define A_ATTRIBUTES (chtype)0xff00 /* X/Open */ +# define A_CHARTEXT (chtype)0x00ff /* X/Open */ +# define A_COLOR (chtype)0xf800 /* System V */ + +# define A_ALTCHARSET A_NORMAL /* X/Open */ +# define A_UNDERLINE A_NORMAL /* X/Open */ + +# define A_LEFT A_NORMAL +# define A_RIGHT A_NORMAL +# define A_ITALIC A_NORMAL + +# define PDC_COLOR_SHIFT 11 +#endif + +#define A_LEFTLINE A_LEFT +#define A_RIGHTLINE A_RIGHT +#define A_STANDOUT (A_REVERSE | A_BOLD) /* X/Open */ + +#define A_DIM A_NORMAL +#define A_INVIS A_NORMAL +#define A_PROTECT A_NORMAL + +#define A_HORIZONTAL A_NORMAL +#define A_LOW A_NORMAL +#define A_TOP A_NORMAL +#define A_VERTICAL A_NORMAL + +#define CHR_MSK A_CHARTEXT /* Obsolete */ +#define ATR_MSK A_ATTRIBUTES /* Obsolete */ +#define ATR_NRM A_NORMAL /* Obsolete */ + +/* For use with attr_t -- X/Open says, "these shall be distinct", so + this is a non-conforming implementation. */ + +#define WA_NORMAL A_NORMAL + +#define WA_ALTCHARSET A_ALTCHARSET +#define WA_BLINK A_BLINK +#define WA_BOLD A_BOLD +#define WA_DIM A_DIM +#define WA_INVIS A_INVIS +#define WA_ITALIC A_ITALIC +#define WA_LEFT A_LEFT +#define WA_PROTECT A_PROTECT +#define WA_REVERSE A_REVERSE +#define WA_RIGHT A_RIGHT +#define WA_STANDOUT A_STANDOUT +#define WA_UNDERLINE A_UNDERLINE + +#define WA_HORIZONTAL A_HORIZONTAL +#define WA_LOW A_LOW +#define WA_TOP A_TOP +#define WA_VERTICAL A_VERTICAL + +#define WA_ATTRIBUTES A_ATTRIBUTES + +/*** Alternate character set macros ***/ + +/* 'w' = 32-bit chtype; acs_map[] index | A_ALTCHARSET + 'n' = 16-bit chtype; it gets the fallback set because no bit is + available for A_ALTCHARSET */ + +#ifdef CHTYPE_LONG +# define ACS_PICK(w, n) ((chtype)w | A_ALTCHARSET) +#else +# define ACS_PICK(w, n) ((chtype)n) +#endif + +/* VT100-compatible symbols -- box chars */ + +#define ACS_ULCORNER ACS_PICK('l', '+') +#define ACS_LLCORNER ACS_PICK('m', '+') +#define ACS_URCORNER ACS_PICK('k', '+') +#define ACS_LRCORNER ACS_PICK('j', '+') +#define ACS_RTEE ACS_PICK('u', '+') +#define ACS_LTEE ACS_PICK('t', '+') +#define ACS_BTEE ACS_PICK('v', '+') +#define ACS_TTEE ACS_PICK('w', '+') +#define ACS_HLINE ACS_PICK('q', '-') +#define ACS_VLINE ACS_PICK('x', '|') +#define ACS_PLUS ACS_PICK('n', '+') + +/* VT100-compatible symbols -- other */ + +#define ACS_S1 ACS_PICK('o', '-') +#define ACS_S9 ACS_PICK('s', '_') +#define ACS_DIAMOND ACS_PICK('`', '+') +#define ACS_CKBOARD ACS_PICK('a', ':') +#define ACS_DEGREE ACS_PICK('f', '\'') +#define ACS_PLMINUS ACS_PICK('g', '#') +#define ACS_BULLET ACS_PICK('~', 'o') + +/* Teletype 5410v1 symbols -- these are defined in SysV curses, but + are not well-supported by most terminals. Stick to VT100 characters + for optimum portability. */ + +#define ACS_LARROW ACS_PICK(',', '<') +#define ACS_RARROW ACS_PICK('+', '>') +#define ACS_DARROW ACS_PICK('.', 'v') +#define ACS_UARROW ACS_PICK('-', '^') +#define ACS_BOARD ACS_PICK('h', '#') +#define ACS_LANTERN ACS_PICK('i', '*') +#define ACS_BLOCK ACS_PICK('0', '#') + +/* That goes double for these -- undocumented SysV symbols. Don't use + them. */ + +#define ACS_S3 ACS_PICK('p', '-') +#define ACS_S7 ACS_PICK('r', '-') +#define ACS_LEQUAL ACS_PICK('y', '<') +#define ACS_GEQUAL ACS_PICK('z', '>') +#define ACS_PI ACS_PICK('{', 'n') +#define ACS_NEQUAL ACS_PICK('|', '+') +#define ACS_STERLING ACS_PICK('}', 'L') + +/* Box char aliases */ + +#define ACS_BSSB ACS_ULCORNER +#define ACS_SSBB ACS_LLCORNER +#define ACS_BBSS ACS_URCORNER +#define ACS_SBBS ACS_LRCORNER +#define ACS_SBSS ACS_RTEE +#define ACS_SSSB ACS_LTEE +#define ACS_SSBS ACS_BTEE +#define ACS_BSSS ACS_TTEE +#define ACS_BSBS ACS_HLINE +#define ACS_SBSB ACS_VLINE +#define ACS_SSSS ACS_PLUS + +/* cchar_t aliases */ + +#ifdef PDC_WIDE +# define WACS_ULCORNER (&(acs_map['l'])) +# define WACS_LLCORNER (&(acs_map['m'])) +# define WACS_URCORNER (&(acs_map['k'])) +# define WACS_LRCORNER (&(acs_map['j'])) +# define WACS_RTEE (&(acs_map['u'])) +# define WACS_LTEE (&(acs_map['t'])) +# define WACS_BTEE (&(acs_map['v'])) +# define WACS_TTEE (&(acs_map['w'])) +# define WACS_HLINE (&(acs_map['q'])) +# define WACS_VLINE (&(acs_map['x'])) +# define WACS_PLUS (&(acs_map['n'])) + +# define WACS_S1 (&(acs_map['o'])) +# define WACS_S9 (&(acs_map['s'])) +# define WACS_DIAMOND (&(acs_map['`'])) +# define WACS_CKBOARD (&(acs_map['a'])) +# define WACS_DEGREE (&(acs_map['f'])) +# define WACS_PLMINUS (&(acs_map['g'])) +# define WACS_BULLET (&(acs_map['~'])) + +# define WACS_LARROW (&(acs_map[','])) +# define WACS_RARROW (&(acs_map['+'])) +# define WACS_DARROW (&(acs_map['.'])) +# define WACS_UARROW (&(acs_map['-'])) +# define WACS_BOARD (&(acs_map['h'])) +# define WACS_LANTERN (&(acs_map['i'])) +# define WACS_BLOCK (&(acs_map['0'])) + +# define WACS_S3 (&(acs_map['p'])) +# define WACS_S7 (&(acs_map['r'])) +# define WACS_LEQUAL (&(acs_map['y'])) +# define WACS_GEQUAL (&(acs_map['z'])) +# define WACS_PI (&(acs_map['{'])) +# define WACS_NEQUAL (&(acs_map['|'])) +# define WACS_STERLING (&(acs_map['}'])) + +# define WACS_BSSB WACS_ULCORNER +# define WACS_SSBB WACS_LLCORNER +# define WACS_BBSS WACS_URCORNER +# define WACS_SBBS WACS_LRCORNER +# define WACS_SBSS WACS_RTEE +# define WACS_SSSB WACS_LTEE +# define WACS_SSBS WACS_BTEE +# define WACS_BSSS WACS_TTEE +# define WACS_BSBS WACS_HLINE +# define WACS_SBSB WACS_VLINE +# define WACS_SSSS WACS_PLUS +#endif + +/*** Color macros ***/ + +#define COLOR_BLACK 0 + +#ifdef PDC_RGB /* RGB */ +# define COLOR_RED 1 +# define COLOR_GREEN 2 +# define COLOR_BLUE 4 +#else /* BGR */ +# define COLOR_BLUE 1 +# define COLOR_GREEN 2 +# define COLOR_RED 4 +#endif + +#define COLOR_CYAN (COLOR_BLUE | COLOR_GREEN) +#define COLOR_MAGENTA (COLOR_RED | COLOR_BLUE) +#define COLOR_YELLOW (COLOR_RED | COLOR_GREEN) + +#define COLOR_WHITE 7 + +/*---------------------------------------------------------------------- + * + * Function and Keypad Key Definitions. + * Many are just for compatibility. + * + */ + +#define KEY_CODE_YES 0x100 /* If get_wch() gives a key code */ + +#define KEY_BREAK 0x101 /* Not on PC KBD */ +#define KEY_DOWN 0x102 /* Down arrow key */ +#define KEY_UP 0x103 /* Up arrow key */ +#define KEY_LEFT 0x104 /* Left arrow key */ +#define KEY_RIGHT 0x105 /* Right arrow key */ +#define KEY_HOME 0x106 /* home key */ +#define KEY_BACKSPACE 0x107 /* not on pc */ +#define KEY_F0 0x108 /* function keys; 64 reserved */ + +#define KEY_DL 0x148 /* delete line */ +#define KEY_IL 0x149 /* insert line */ +#define KEY_DC 0x14a /* delete character */ +#define KEY_IC 0x14b /* insert char or enter ins mode */ +#define KEY_EIC 0x14c /* exit insert char mode */ +#define KEY_CLEAR 0x14d /* clear screen */ +#define KEY_EOS 0x14e /* clear to end of screen */ +#define KEY_EOL 0x14f /* clear to end of line */ +#define KEY_SF 0x150 /* scroll 1 line forward */ +#define KEY_SR 0x151 /* scroll 1 line back (reverse) */ +#define KEY_NPAGE 0x152 /* next page */ +#define KEY_PPAGE 0x153 /* previous page */ +#define KEY_STAB 0x154 /* set tab */ +#define KEY_CTAB 0x155 /* clear tab */ +#define KEY_CATAB 0x156 /* clear all tabs */ +#define KEY_ENTER 0x157 /* enter or send (unreliable) */ +#define KEY_SRESET 0x158 /* soft/reset (partial/unreliable) */ +#define KEY_RESET 0x159 /* reset/hard reset (unreliable) */ +#define KEY_PRINT 0x15a /* print/copy */ +#define KEY_LL 0x15b /* home down/bottom (lower left) */ +#define KEY_ABORT 0x15c /* abort/terminate key (any) */ +#define KEY_SHELP 0x15d /* short help */ +#define KEY_LHELP 0x15e /* long help */ +#define KEY_BTAB 0x15f /* Back tab key */ +#define KEY_BEG 0x160 /* beg(inning) key */ +#define KEY_CANCEL 0x161 /* cancel key */ +#define KEY_CLOSE 0x162 /* close key */ +#define KEY_COMMAND 0x163 /* cmd (command) key */ +#define KEY_COPY 0x164 /* copy key */ +#define KEY_CREATE 0x165 /* create key */ +#define KEY_END 0x166 /* end key */ +#define KEY_EXIT 0x167 /* exit key */ +#define KEY_FIND 0x168 /* find key */ +#define KEY_HELP 0x169 /* help key */ +#define KEY_MARK 0x16a /* mark key */ +#define KEY_MESSAGE 0x16b /* message key */ +#define KEY_MOVE 0x16c /* move key */ +#define KEY_NEXT 0x16d /* next object key */ +#define KEY_OPEN 0x16e /* open key */ +#define KEY_OPTIONS 0x16f /* options key */ +#define KEY_PREVIOUS 0x170 /* previous object key */ +#define KEY_REDO 0x171 /* redo key */ +#define KEY_REFERENCE 0x172 /* ref(erence) key */ +#define KEY_REFRESH 0x173 /* refresh key */ +#define KEY_REPLACE 0x174 /* replace key */ +#define KEY_RESTART 0x175 /* restart key */ +#define KEY_RESUME 0x176 /* resume key */ +#define KEY_SAVE 0x177 /* save key */ +#define KEY_SBEG 0x178 /* shifted beginning key */ +#define KEY_SCANCEL 0x179 /* shifted cancel key */ +#define KEY_SCOMMAND 0x17a /* shifted command key */ +#define KEY_SCOPY 0x17b /* shifted copy key */ +#define KEY_SCREATE 0x17c /* shifted create key */ +#define KEY_SDC 0x17d /* shifted delete char key */ +#define KEY_SDL 0x17e /* shifted delete line key */ +#define KEY_SELECT 0x17f /* select key */ +#define KEY_SEND 0x180 /* shifted end key */ +#define KEY_SEOL 0x181 /* shifted clear line key */ +#define KEY_SEXIT 0x182 /* shifted exit key */ +#define KEY_SFIND 0x183 /* shifted find key */ +#define KEY_SHOME 0x184 /* shifted home key */ +#define KEY_SIC 0x185 /* shifted input key */ + +#define KEY_SLEFT 0x187 /* shifted left arrow key */ +#define KEY_SMESSAGE 0x188 /* shifted message key */ +#define KEY_SMOVE 0x189 /* shifted move key */ +#define KEY_SNEXT 0x18a /* shifted next key */ +#define KEY_SOPTIONS 0x18b /* shifted options key */ +#define KEY_SPREVIOUS 0x18c /* shifted prev key */ +#define KEY_SPRINT 0x18d /* shifted print key */ +#define KEY_SREDO 0x18e /* shifted redo key */ +#define KEY_SREPLACE 0x18f /* shifted replace key */ +#define KEY_SRIGHT 0x190 /* shifted right arrow */ +#define KEY_SRSUME 0x191 /* shifted resume key */ +#define KEY_SSAVE 0x192 /* shifted save key */ +#define KEY_SSUSPEND 0x193 /* shifted suspend key */ +#define KEY_SUNDO 0x194 /* shifted undo key */ +#define KEY_SUSPEND 0x195 /* suspend key */ +#define KEY_UNDO 0x196 /* undo key */ + +/* PDCurses-specific key definitions -- PC only */ + +#define ALT_0 0x197 +#define ALT_1 0x198 +#define ALT_2 0x199 +#define ALT_3 0x19a +#define ALT_4 0x19b +#define ALT_5 0x19c +#define ALT_6 0x19d +#define ALT_7 0x19e +#define ALT_8 0x19f +#define ALT_9 0x1a0 +#define ALT_A 0x1a1 +#define ALT_B 0x1a2 +#define ALT_C 0x1a3 +#define ALT_D 0x1a4 +#define ALT_E 0x1a5 +#define ALT_F 0x1a6 +#define ALT_G 0x1a7 +#define ALT_H 0x1a8 +#define ALT_I 0x1a9 +#define ALT_J 0x1aa +#define ALT_K 0x1ab +#define ALT_L 0x1ac +#define ALT_M 0x1ad +#define ALT_N 0x1ae +#define ALT_O 0x1af +#define ALT_P 0x1b0 +#define ALT_Q 0x1b1 +#define ALT_R 0x1b2 +#define ALT_S 0x1b3 +#define ALT_T 0x1b4 +#define ALT_U 0x1b5 +#define ALT_V 0x1b6 +#define ALT_W 0x1b7 +#define ALT_X 0x1b8 +#define ALT_Y 0x1b9 +#define ALT_Z 0x1ba + +#define CTL_LEFT 0x1bb /* Control-Left-Arrow */ +#define CTL_RIGHT 0x1bc +#define CTL_PGUP 0x1bd +#define CTL_PGDN 0x1be +#define CTL_HOME 0x1bf +#define CTL_END 0x1c0 + +#define KEY_A1 0x1c1 /* upper left on Virtual keypad */ +#define KEY_A2 0x1c2 /* upper middle on Virt. keypad */ +#define KEY_A3 0x1c3 /* upper right on Vir. keypad */ +#define KEY_B1 0x1c4 /* middle left on Virt. keypad */ +#define KEY_B2 0x1c5 /* center on Virt. keypad */ +#define KEY_B3 0x1c6 /* middle right on Vir. keypad */ +#define KEY_C1 0x1c7 /* lower left on Virt. keypad */ +#define KEY_C2 0x1c8 /* lower middle on Virt. keypad */ +#define KEY_C3 0x1c9 /* lower right on Vir. keypad */ + +#define PADSLASH 0x1ca /* slash on keypad */ +#define PADENTER 0x1cb /* enter on keypad */ +#define CTL_PADENTER 0x1cc /* ctl-enter on keypad */ +#define ALT_PADENTER 0x1cd /* alt-enter on keypad */ +#define PADSTOP 0x1ce /* stop on keypad */ +#define PADSTAR 0x1cf /* star on keypad */ +#define PADMINUS 0x1d0 /* minus on keypad */ +#define PADPLUS 0x1d1 /* plus on keypad */ +#define CTL_PADSTOP 0x1d2 /* ctl-stop on keypad */ +#define CTL_PADCENTER 0x1d3 /* ctl-enter on keypad */ +#define CTL_PADPLUS 0x1d4 /* ctl-plus on keypad */ +#define CTL_PADMINUS 0x1d5 /* ctl-minus on keypad */ +#define CTL_PADSLASH 0x1d6 /* ctl-slash on keypad */ +#define CTL_PADSTAR 0x1d7 /* ctl-star on keypad */ +#define ALT_PADPLUS 0x1d8 /* alt-plus on keypad */ +#define ALT_PADMINUS 0x1d9 /* alt-minus on keypad */ +#define ALT_PADSLASH 0x1da /* alt-slash on keypad */ +#define ALT_PADSTAR 0x1db /* alt-star on keypad */ +#define ALT_PADSTOP 0x1dc /* alt-stop on keypad */ +#define CTL_INS 0x1dd /* ctl-insert */ +#define ALT_DEL 0x1de /* alt-delete */ +#define ALT_INS 0x1df /* alt-insert */ +#define CTL_UP 0x1e0 /* ctl-up arrow */ +#define CTL_DOWN 0x1e1 /* ctl-down arrow */ +#define CTL_TAB 0x1e2 /* ctl-tab */ +#define ALT_TAB 0x1e3 +#define ALT_MINUS 0x1e4 +#define ALT_EQUAL 0x1e5 +#define ALT_HOME 0x1e6 +#define ALT_PGUP 0x1e7 +#define ALT_PGDN 0x1e8 +#define ALT_END 0x1e9 +#define ALT_UP 0x1ea /* alt-up arrow */ +#define ALT_DOWN 0x1eb /* alt-down arrow */ +#define ALT_RIGHT 0x1ec /* alt-right arrow */ +#define ALT_LEFT 0x1ed /* alt-left arrow */ +#define ALT_ENTER 0x1ee /* alt-enter */ +#define ALT_ESC 0x1ef /* alt-escape */ +#define ALT_BQUOTE 0x1f0 /* alt-back quote */ +#define ALT_LBRACKET 0x1f1 /* alt-left bracket */ +#define ALT_RBRACKET 0x1f2 /* alt-right bracket */ +#define ALT_SEMICOLON 0x1f3 /* alt-semi-colon */ +#define ALT_FQUOTE 0x1f4 /* alt-forward quote */ +#define ALT_COMMA 0x1f5 /* alt-comma */ +#define ALT_STOP 0x1f6 /* alt-stop */ +#define ALT_FSLASH 0x1f7 /* alt-forward slash */ +#define ALT_BKSP 0x1f8 /* alt-backspace */ +#define CTL_BKSP 0x1f9 /* ctl-backspace */ +#define PAD0 0x1fa /* keypad 0 */ + +#define CTL_PAD0 0x1fb /* ctl-keypad 0 */ +#define CTL_PAD1 0x1fc +#define CTL_PAD2 0x1fd +#define CTL_PAD3 0x1fe +#define CTL_PAD4 0x1ff +#define CTL_PAD5 0x200 +#define CTL_PAD6 0x201 +#define CTL_PAD7 0x202 +#define CTL_PAD8 0x203 +#define CTL_PAD9 0x204 + +#define ALT_PAD0 0x205 /* alt-keypad 0 */ +#define ALT_PAD1 0x206 +#define ALT_PAD2 0x207 +#define ALT_PAD3 0x208 +#define ALT_PAD4 0x209 +#define ALT_PAD5 0x20a +#define ALT_PAD6 0x20b +#define ALT_PAD7 0x20c +#define ALT_PAD8 0x20d +#define ALT_PAD9 0x20e + +#define CTL_DEL 0x20f /* clt-delete */ +#define ALT_BSLASH 0x210 /* alt-back slash */ +#define CTL_ENTER 0x211 /* ctl-enter */ + +#define SHF_PADENTER 0x212 /* shift-enter on keypad */ +#define SHF_PADSLASH 0x213 /* shift-slash on keypad */ +#define SHF_PADSTAR 0x214 /* shift-star on keypad */ +#define SHF_PADPLUS 0x215 /* shift-plus on keypad */ +#define SHF_PADMINUS 0x216 /* shift-minus on keypad */ +#define SHF_UP 0x217 /* shift-up on keypad */ +#define SHF_DOWN 0x218 /* shift-down on keypad */ +#define SHF_IC 0x219 /* shift-insert on keypad */ +#define SHF_DC 0x21a /* shift-delete on keypad */ + +#define KEY_MOUSE 0x21b /* "mouse" key */ +#define KEY_SHIFT_L 0x21c /* Left-shift */ +#define KEY_SHIFT_R 0x21d /* Right-shift */ +#define KEY_CONTROL_L 0x21e /* Left-control */ +#define KEY_CONTROL_R 0x21f /* Right-control */ +#define KEY_ALT_L 0x220 /* Left-alt */ +#define KEY_ALT_R 0x221 /* Right-alt */ +#define KEY_RESIZE 0x222 /* Window resize */ +#define KEY_SUP 0x223 /* Shifted up arrow */ +#define KEY_SDOWN 0x224 /* Shifted down arrow */ + +#define KEY_MIN KEY_BREAK /* Minimum curses key value */ +#define KEY_MAX KEY_SDOWN /* Maximum curses key */ + +#define KEY_F(n) (KEY_F0 + (n)) + +/*---------------------------------------------------------------------- + * + * PDCurses Function Declarations + * + */ + +/* Standard */ + +PDCEX int addch(const chtype); +PDCEX int addchnstr(const chtype *, int); +PDCEX int addchstr(const chtype *); +PDCEX int addnstr(const char *, int); +PDCEX int addstr(const char *); +PDCEX int attroff(chtype); +PDCEX int attron(chtype); +PDCEX int attrset(chtype); +PDCEX int attr_get(attr_t *, short *, void *); +PDCEX int attr_off(attr_t, void *); +PDCEX int attr_on(attr_t, void *); +PDCEX int attr_set(attr_t, short, void *); +PDCEX int baudrate(void); +PDCEX int beep(void); +PDCEX int bkgd(chtype); +PDCEX void bkgdset(chtype); +PDCEX int border(chtype, chtype, chtype, chtype, + chtype, chtype, chtype, chtype); +PDCEX int box(WINDOW *, chtype, chtype); +PDCEX bool can_change_color(void); +PDCEX int cbreak(void); +PDCEX int chgat(int, attr_t, short, const void *); +PDCEX int clearok(WINDOW *, bool); +PDCEX int clear(void); +PDCEX int clrtobot(void); +PDCEX int clrtoeol(void); +PDCEX int color_content(short, short *, short *, short *); +PDCEX int color_set(short, void *); +PDCEX int copywin(const WINDOW *, WINDOW *, int, int, int, + int, int, int, int); +PDCEX int curs_set(int); +PDCEX int def_prog_mode(void); +PDCEX int def_shell_mode(void); +PDCEX int delay_output(int); +PDCEX int delch(void); +PDCEX int deleteln(void); +PDCEX void delscreen(SCREEN *); +PDCEX int delwin(WINDOW *); +PDCEX WINDOW *derwin(WINDOW *, int, int, int, int); +PDCEX int doupdate(void); +PDCEX WINDOW *dupwin(WINDOW *); +PDCEX int echochar(const chtype); +PDCEX int echo(void); +PDCEX int endwin(void); +PDCEX char erasechar(void); +PDCEX int erase(void); +PDCEX void filter(void); +PDCEX int flash(void); +PDCEX int flushinp(void); +PDCEX chtype getbkgd(WINDOW *); +PDCEX int getnstr(char *, int); +PDCEX int getstr(char *); +PDCEX WINDOW *getwin(FILE *); +PDCEX int halfdelay(int); +PDCEX bool has_colors(void); +PDCEX bool has_ic(void); +PDCEX bool has_il(void); +PDCEX int hline(chtype, int); +PDCEX void idcok(WINDOW *, bool); +PDCEX int idlok(WINDOW *, bool); +PDCEX void immedok(WINDOW *, bool); +PDCEX int inchnstr(chtype *, int); +PDCEX int inchstr(chtype *); +PDCEX chtype inch(void); +PDCEX int init_color(short, short, short, short); +PDCEX int init_pair(short, short, short); +PDCEX WINDOW *initscr(void); +PDCEX int innstr(char *, int); +PDCEX int insch(chtype); +PDCEX int insdelln(int); +PDCEX int insertln(void); +PDCEX int insnstr(const char *, int); +PDCEX int insstr(const char *); +PDCEX int instr(char *); +PDCEX int intrflush(WINDOW *, bool); +PDCEX bool isendwin(void); +PDCEX bool is_linetouched(WINDOW *, int); +PDCEX bool is_wintouched(WINDOW *); +PDCEX char *keyname(int); +PDCEX int keypad(WINDOW *, bool); +PDCEX char killchar(void); +PDCEX int leaveok(WINDOW *, bool); +PDCEX char *longname(void); +PDCEX int meta(WINDOW *, bool); +PDCEX int move(int, int); +PDCEX int mvaddch(int, int, const chtype); +PDCEX int mvaddchnstr(int, int, const chtype *, int); +PDCEX int mvaddchstr(int, int, const chtype *); +PDCEX int mvaddnstr(int, int, const char *, int); +PDCEX int mvaddstr(int, int, const char *); +PDCEX int mvchgat(int, int, int, attr_t, short, const void *); +PDCEX int mvcur(int, int, int, int); +PDCEX int mvdelch(int, int); +PDCEX int mvderwin(WINDOW *, int, int); +PDCEX int mvgetch(int, int); +PDCEX int mvgetnstr(int, int, char *, int); +PDCEX int mvgetstr(int, int, char *); +PDCEX int mvhline(int, int, chtype, int); +PDCEX chtype mvinch(int, int); +PDCEX int mvinchnstr(int, int, chtype *, int); +PDCEX int mvinchstr(int, int, chtype *); +PDCEX int mvinnstr(int, int, char *, int); +PDCEX int mvinsch(int, int, chtype); +PDCEX int mvinsnstr(int, int, const char *, int); +PDCEX int mvinsstr(int, int, const char *); +PDCEX int mvinstr(int, int, char *); +PDCEX int mvprintw(int, int, const char *, ...); +PDCEX int mvscanw(int, int, const char *, ...); +PDCEX int mvvline(int, int, chtype, int); +PDCEX int mvwaddchnstr(WINDOW *, int, int, const chtype *, int); +PDCEX int mvwaddchstr(WINDOW *, int, int, const chtype *); +PDCEX int mvwaddch(WINDOW *, int, int, const chtype); +PDCEX int mvwaddnstr(WINDOW *, int, int, const char *, int); +PDCEX int mvwaddstr(WINDOW *, int, int, const char *); +PDCEX int mvwchgat(WINDOW *, int, int, int, attr_t, short, const void *); +PDCEX int mvwdelch(WINDOW *, int, int); +PDCEX int mvwgetch(WINDOW *, int, int); +PDCEX int mvwgetnstr(WINDOW *, int, int, char *, int); +PDCEX int mvwgetstr(WINDOW *, int, int, char *); +PDCEX int mvwhline(WINDOW *, int, int, chtype, int); +PDCEX int mvwinchnstr(WINDOW *, int, int, chtype *, int); +PDCEX int mvwinchstr(WINDOW *, int, int, chtype *); +PDCEX chtype mvwinch(WINDOW *, int, int); +PDCEX int mvwinnstr(WINDOW *, int, int, char *, int); +PDCEX int mvwinsch(WINDOW *, int, int, chtype); +PDCEX int mvwinsnstr(WINDOW *, int, int, const char *, int); +PDCEX int mvwinsstr(WINDOW *, int, int, const char *); +PDCEX int mvwinstr(WINDOW *, int, int, char *); +PDCEX int mvwin(WINDOW *, int, int); +PDCEX int mvwprintw(WINDOW *, int, int, const char *, ...); +PDCEX int mvwscanw(WINDOW *, int, int, const char *, ...); +PDCEX int mvwvline(WINDOW *, int, int, chtype, int); +PDCEX int napms(int); +PDCEX WINDOW *newpad(int, int); +PDCEX SCREEN *newterm(const char *, FILE *, FILE *); +PDCEX WINDOW *newwin(int, int, int, int); +PDCEX int nl(void); +PDCEX int nocbreak(void); +PDCEX int nodelay(WINDOW *, bool); +PDCEX int noecho(void); +PDCEX int nonl(void); +PDCEX void noqiflush(void); +PDCEX int noraw(void); +PDCEX int notimeout(WINDOW *, bool); +PDCEX int overlay(const WINDOW *, WINDOW *); +PDCEX int overwrite(const WINDOW *, WINDOW *); +PDCEX int pair_content(short, short *, short *); +PDCEX int pechochar(WINDOW *, chtype); +PDCEX int pnoutrefresh(WINDOW *, int, int, int, int, int, int); +PDCEX int prefresh(WINDOW *, int, int, int, int, int, int); +PDCEX int printw(const char *, ...); +PDCEX int putwin(WINDOW *, FILE *); +PDCEX void qiflush(void); +PDCEX int raw(void); +PDCEX int redrawwin(WINDOW *); +PDCEX int refresh(void); +PDCEX int reset_prog_mode(void); +PDCEX int reset_shell_mode(void); +PDCEX int resetty(void); +PDCEX int ripoffline(int, int (*)(WINDOW *, int)); +PDCEX int savetty(void); +PDCEX int scanw(const char *, ...); +PDCEX int scr_dump(const char *); +PDCEX int scr_init(const char *); +PDCEX int scr_restore(const char *); +PDCEX int scr_set(const char *); +PDCEX int scrl(int); +PDCEX int scroll(WINDOW *); +PDCEX int scrollok(WINDOW *, bool); +PDCEX SCREEN *set_term(SCREEN *); +PDCEX int setscrreg(int, int); +PDCEX int slk_attroff(const chtype); +PDCEX int slk_attr_off(const attr_t, void *); +PDCEX int slk_attron(const chtype); +PDCEX int slk_attr_on(const attr_t, void *); +PDCEX int slk_attrset(const chtype); +PDCEX int slk_attr_set(const attr_t, short, void *); +PDCEX int slk_clear(void); +PDCEX int slk_color(short); +PDCEX int slk_init(int); +PDCEX char *slk_label(int); +PDCEX int slk_noutrefresh(void); +PDCEX int slk_refresh(void); +PDCEX int slk_restore(void); +PDCEX int slk_set(int, const char *, int); +PDCEX int slk_touch(void); +PDCEX int standend(void); +PDCEX int standout(void); +PDCEX int start_color(void); +PDCEX WINDOW *subpad(WINDOW *, int, int, int, int); +PDCEX WINDOW *subwin(WINDOW *, int, int, int, int); +PDCEX int syncok(WINDOW *, bool); +PDCEX chtype termattrs(void); +PDCEX attr_t term_attrs(void); +PDCEX char *termname(void); +PDCEX void timeout(int); +PDCEX int touchline(WINDOW *, int, int); +PDCEX int touchwin(WINDOW *); +PDCEX int typeahead(int); +PDCEX int untouchwin(WINDOW *); +PDCEX void use_env(bool); +PDCEX int vidattr(chtype); +PDCEX int vid_attr(attr_t, short, void *); +PDCEX int vidputs(chtype, int (*)(int)); +PDCEX int vid_puts(attr_t, short, void *, int (*)(int)); +PDCEX int vline(chtype, int); +PDCEX int vw_printw(WINDOW *, const char *, va_list); +PDCEX int vwprintw(WINDOW *, const char *, va_list); +PDCEX int vw_scanw(WINDOW *, const char *, va_list); +PDCEX int vwscanw(WINDOW *, const char *, va_list); +PDCEX int waddchnstr(WINDOW *, const chtype *, int); +PDCEX int waddchstr(WINDOW *, const chtype *); +PDCEX int waddch(WINDOW *, const chtype); +PDCEX int waddnstr(WINDOW *, const char *, int); +PDCEX int waddstr(WINDOW *, const char *); +PDCEX int wattroff(WINDOW *, chtype); +PDCEX int wattron(WINDOW *, chtype); +PDCEX int wattrset(WINDOW *, chtype); +PDCEX int wattr_get(WINDOW *, attr_t *, short *, void *); +PDCEX int wattr_off(WINDOW *, attr_t, void *); +PDCEX int wattr_on(WINDOW *, attr_t, void *); +PDCEX int wattr_set(WINDOW *, attr_t, short, void *); +PDCEX void wbkgdset(WINDOW *, chtype); +PDCEX int wbkgd(WINDOW *, chtype); +PDCEX int wborder(WINDOW *, chtype, chtype, chtype, chtype, + chtype, chtype, chtype, chtype); +PDCEX int wchgat(WINDOW *, int, attr_t, short, const void *); +PDCEX int wclear(WINDOW *); +PDCEX int wclrtobot(WINDOW *); +PDCEX int wclrtoeol(WINDOW *); +PDCEX int wcolor_set(WINDOW *, short, void *); +PDCEX void wcursyncup(WINDOW *); +PDCEX int wdelch(WINDOW *); +PDCEX int wdeleteln(WINDOW *); +PDCEX int wechochar(WINDOW *, const chtype); +PDCEX int werase(WINDOW *); +PDCEX int wgetch(WINDOW *); +PDCEX int wgetnstr(WINDOW *, char *, int); +PDCEX int wgetstr(WINDOW *, char *); +PDCEX int whline(WINDOW *, chtype, int); +PDCEX int winchnstr(WINDOW *, chtype *, int); +PDCEX int winchstr(WINDOW *, chtype *); +PDCEX chtype winch(WINDOW *); +PDCEX int winnstr(WINDOW *, char *, int); +PDCEX int winsch(WINDOW *, chtype); +PDCEX int winsdelln(WINDOW *, int); +PDCEX int winsertln(WINDOW *); +PDCEX int winsnstr(WINDOW *, const char *, int); +PDCEX int winsstr(WINDOW *, const char *); +PDCEX int winstr(WINDOW *, char *); +PDCEX int wmove(WINDOW *, int, int); +PDCEX int wnoutrefresh(WINDOW *); +PDCEX int wprintw(WINDOW *, const char *, ...); +PDCEX int wredrawln(WINDOW *, int, int); +PDCEX int wrefresh(WINDOW *); +PDCEX int wscanw(WINDOW *, const char *, ...); +PDCEX int wscrl(WINDOW *, int); +PDCEX int wsetscrreg(WINDOW *, int, int); +PDCEX int wstandend(WINDOW *); +PDCEX int wstandout(WINDOW *); +PDCEX void wsyncdown(WINDOW *); +PDCEX void wsyncup(WINDOW *); +PDCEX void wtimeout(WINDOW *, int); +PDCEX int wtouchln(WINDOW *, int, int, int); +PDCEX int wvline(WINDOW *, chtype, int); + +/* Wide-character functions */ + +#ifdef PDC_WIDE +PDCEX int addnwstr(const wchar_t *, int); +PDCEX int addwstr(const wchar_t *); +PDCEX int add_wch(const cchar_t *); +PDCEX int add_wchnstr(const cchar_t *, int); +PDCEX int add_wchstr(const cchar_t *); +PDCEX int bkgrnd(const cchar_t *); +PDCEX void bkgrndset(const cchar_t *); +PDCEX int border_set(const cchar_t *, const cchar_t *, const cchar_t *, + const cchar_t *, const cchar_t *, const cchar_t *, + const cchar_t *, const cchar_t *); +PDCEX int box_set(WINDOW *, const cchar_t *, const cchar_t *); +PDCEX int echo_wchar(const cchar_t *); +PDCEX int erasewchar(wchar_t *); +PDCEX int getbkgrnd(cchar_t *); +PDCEX int getcchar(const cchar_t *, wchar_t *, attr_t *, short *, void *); +PDCEX int getn_wstr(wint_t *, int); +PDCEX int get_wch(wint_t *); +PDCEX int get_wstr(wint_t *); +PDCEX int hline_set(const cchar_t *, int); +PDCEX int innwstr(wchar_t *, int); +PDCEX int ins_nwstr(const wchar_t *, int); +PDCEX int ins_wch(const cchar_t *); +PDCEX int ins_wstr(const wchar_t *); +PDCEX int inwstr(wchar_t *); +PDCEX int in_wch(cchar_t *); +PDCEX int in_wchnstr(cchar_t *, int); +PDCEX int in_wchstr(cchar_t *); +PDCEX char *key_name(wchar_t); +PDCEX int killwchar(wchar_t *); +PDCEX int mvaddnwstr(int, int, const wchar_t *, int); +PDCEX int mvaddwstr(int, int, const wchar_t *); +PDCEX int mvadd_wch(int, int, const cchar_t *); +PDCEX int mvadd_wchnstr(int, int, const cchar_t *, int); +PDCEX int mvadd_wchstr(int, int, const cchar_t *); +PDCEX int mvgetn_wstr(int, int, wint_t *, int); +PDCEX int mvget_wch(int, int, wint_t *); +PDCEX int mvget_wstr(int, int, wint_t *); +PDCEX int mvhline_set(int, int, const cchar_t *, int); +PDCEX int mvinnwstr(int, int, wchar_t *, int); +PDCEX int mvins_nwstr(int, int, const wchar_t *, int); +PDCEX int mvins_wch(int, int, const cchar_t *); +PDCEX int mvins_wstr(int, int, const wchar_t *); +PDCEX int mvinwstr(int, int, wchar_t *); +PDCEX int mvin_wch(int, int, cchar_t *); +PDCEX int mvin_wchnstr(int, int, cchar_t *, int); +PDCEX int mvin_wchstr(int, int, cchar_t *); +PDCEX int mvvline_set(int, int, const cchar_t *, int); +PDCEX int mvwaddnwstr(WINDOW *, int, int, const wchar_t *, int); +PDCEX int mvwaddwstr(WINDOW *, int, int, const wchar_t *); +PDCEX int mvwadd_wch(WINDOW *, int, int, const cchar_t *); +PDCEX int mvwadd_wchnstr(WINDOW *, int, int, const cchar_t *, int); +PDCEX int mvwadd_wchstr(WINDOW *, int, int, const cchar_t *); +PDCEX int mvwgetn_wstr(WINDOW *, int, int, wint_t *, int); +PDCEX int mvwget_wch(WINDOW *, int, int, wint_t *); +PDCEX int mvwget_wstr(WINDOW *, int, int, wint_t *); +PDCEX int mvwhline_set(WINDOW *, int, int, const cchar_t *, int); +PDCEX int mvwinnwstr(WINDOW *, int, int, wchar_t *, int); +PDCEX int mvwins_nwstr(WINDOW *, int, int, const wchar_t *, int); +PDCEX int mvwins_wch(WINDOW *, int, int, const cchar_t *); +PDCEX int mvwins_wstr(WINDOW *, int, int, const wchar_t *); +PDCEX int mvwin_wch(WINDOW *, int, int, cchar_t *); +PDCEX int mvwin_wchnstr(WINDOW *, int, int, cchar_t *, int); +PDCEX int mvwin_wchstr(WINDOW *, int, int, cchar_t *); +PDCEX int mvwinwstr(WINDOW *, int, int, wchar_t *); +PDCEX int mvwvline_set(WINDOW *, int, int, const cchar_t *, int); +PDCEX int pecho_wchar(WINDOW *, const cchar_t*); +PDCEX int setcchar(cchar_t*, const wchar_t*, const attr_t, + short, const void*); +PDCEX int slk_wset(int, const wchar_t *, int); +PDCEX int unget_wch(const wchar_t); +PDCEX int vline_set(const cchar_t *, int); +PDCEX int waddnwstr(WINDOW *, const wchar_t *, int); +PDCEX int waddwstr(WINDOW *, const wchar_t *); +PDCEX int wadd_wch(WINDOW *, const cchar_t *); +PDCEX int wadd_wchnstr(WINDOW *, const cchar_t *, int); +PDCEX int wadd_wchstr(WINDOW *, const cchar_t *); +PDCEX int wbkgrnd(WINDOW *, const cchar_t *); +PDCEX void wbkgrndset(WINDOW *, const cchar_t *); +PDCEX int wborder_set(WINDOW *, const cchar_t *, const cchar_t *, + const cchar_t *, const cchar_t *, const cchar_t *, + const cchar_t *, const cchar_t *, const cchar_t *); +PDCEX int wecho_wchar(WINDOW *, const cchar_t *); +PDCEX int wgetbkgrnd(WINDOW *, cchar_t *); +PDCEX int wgetn_wstr(WINDOW *, wint_t *, int); +PDCEX int wget_wch(WINDOW *, wint_t *); +PDCEX int wget_wstr(WINDOW *, wint_t *); +PDCEX int whline_set(WINDOW *, const cchar_t *, int); +PDCEX int winnwstr(WINDOW *, wchar_t *, int); +PDCEX int wins_nwstr(WINDOW *, const wchar_t *, int); +PDCEX int wins_wch(WINDOW *, const cchar_t *); +PDCEX int wins_wstr(WINDOW *, const wchar_t *); +PDCEX int winwstr(WINDOW *, wchar_t *); +PDCEX int win_wch(WINDOW *, cchar_t *); +PDCEX int win_wchnstr(WINDOW *, cchar_t *, int); +PDCEX int win_wchstr(WINDOW *, cchar_t *); +PDCEX wchar_t *wunctrl(cchar_t *); +PDCEX int wvline_set(WINDOW *, const cchar_t *, int); +#endif + +/* Quasi-standard */ + +PDCEX chtype getattrs(WINDOW *); +PDCEX int getbegx(WINDOW *); +PDCEX int getbegy(WINDOW *); +PDCEX int getmaxx(WINDOW *); +PDCEX int getmaxy(WINDOW *); +PDCEX int getparx(WINDOW *); +PDCEX int getpary(WINDOW *); +PDCEX int getcurx(WINDOW *); +PDCEX int getcury(WINDOW *); +PDCEX void traceoff(void); +PDCEX void traceon(void); +PDCEX char *unctrl(chtype); + +PDCEX int crmode(void); +PDCEX int nocrmode(void); +PDCEX int draino(int); +PDCEX int resetterm(void); +PDCEX int fixterm(void); +PDCEX int saveterm(void); +PDCEX int setsyx(int, int); + +PDCEX int mouse_set(unsigned long); +PDCEX int mouse_on(unsigned long); +PDCEX int mouse_off(unsigned long); +PDCEX int request_mouse_pos(void); +PDCEX int map_button(unsigned long); +PDCEX void wmouse_position(WINDOW *, int *, int *); +PDCEX unsigned long getmouse(void); +PDCEX unsigned long getbmap(void); + +/* ncurses */ + +PDCEX int assume_default_colors(int, int); +PDCEX const char *curses_version(void); +PDCEX bool has_key(int); +PDCEX int use_default_colors(void); +PDCEX int wresize(WINDOW *, int, int); + +PDCEX int mouseinterval(int); +PDCEX mmask_t mousemask(mmask_t, mmask_t *); +PDCEX bool mouse_trafo(int *, int *, bool); +PDCEX int nc_getmouse(MEVENT *); +PDCEX int ungetmouse(MEVENT *); +PDCEX bool wenclose(const WINDOW *, int, int); +PDCEX bool wmouse_trafo(const WINDOW *, int *, int *, bool); + +/* PDCurses */ + +PDCEX int addrawch(chtype); +PDCEX int insrawch(chtype); +PDCEX bool is_termresized(void); +PDCEX int mvaddrawch(int, int, chtype); +PDCEX int mvdeleteln(int, int); +PDCEX int mvinsertln(int, int); +PDCEX int mvinsrawch(int, int, chtype); +PDCEX int mvwaddrawch(WINDOW *, int, int, chtype); +PDCEX int mvwdeleteln(WINDOW *, int, int); +PDCEX int mvwinsertln(WINDOW *, int, int); +PDCEX int mvwinsrawch(WINDOW *, int, int, chtype); +PDCEX int raw_output(bool); +PDCEX int resize_term(int, int); +PDCEX WINDOW *resize_window(WINDOW *, int, int); +PDCEX int waddrawch(WINDOW *, chtype); +PDCEX int winsrawch(WINDOW *, chtype); +PDCEX char wordchar(void); + +#ifdef PDC_WIDE +PDCEX wchar_t *slk_wlabel(int); +#endif + +PDCEX void PDC_debug(const char *, ...); +PDCEX int PDC_ungetch(int); +PDCEX int PDC_set_blink(bool); +PDCEX int PDC_set_bold(bool); +PDCEX int PDC_set_line_color(short); +PDCEX void PDC_set_title(const char *); + +PDCEX int PDC_clearclipboard(void); +PDCEX int PDC_freeclipboard(char *); +PDCEX int PDC_getclipboard(char **, long *); +PDCEX int PDC_setclipboard(const char *, long); + +PDCEX unsigned long PDC_get_input_fd(void); +PDCEX unsigned long PDC_get_key_modifiers(void); +PDCEX int PDC_return_key_modifiers(bool); +PDCEX int PDC_save_key_modifiers(bool); + +#ifdef XCURSES +PDCEX WINDOW *Xinitscr(int, char **); +PDCEX void XCursesExit(void); +PDCEX int sb_init(void); +PDCEX int sb_set_horz(int, int, int); +PDCEX int sb_set_vert(int, int, int); +PDCEX int sb_get_horz(int *, int *, int *); +PDCEX int sb_get_vert(int *, int *, int *); +PDCEX int sb_refresh(void); +#endif + +/*** Functions defined as macros ***/ + +/* getch() and ungetch() conflict with some DOS libraries */ + +#define getch() wgetch(stdscr) +#define ungetch(ch) PDC_ungetch(ch) + +#define COLOR_PAIR(n) (((chtype)(n) << PDC_COLOR_SHIFT) & A_COLOR) +#define PAIR_NUMBER(n) (((n) & A_COLOR) >> PDC_COLOR_SHIFT) + +/* These will _only_ work as macros */ + +#define getbegyx(w, y, x) (y = getbegy(w), x = getbegx(w)) +#define getmaxyx(w, y, x) (y = getmaxy(w), x = getmaxx(w)) +#define getparyx(w, y, x) (y = getpary(w), x = getparx(w)) +#define getyx(w, y, x) (y = getcury(w), x = getcurx(w)) + +#define getsyx(y, x) { if (curscr->_leaveit) (y)=(x)=-1; \ + else getyx(curscr,(y),(x)); } + +#ifdef NCURSES_MOUSE_VERSION +# define getmouse(x) nc_getmouse(x) +#endif + +/* return codes from PDC_getclipboard() and PDC_setclipboard() calls */ + +#define PDC_CLIP_SUCCESS 0 +#define PDC_CLIP_ACCESS_ERROR 1 +#define PDC_CLIP_EMPTY 2 +#define PDC_CLIP_MEMORY_ERROR 3 + +/* PDCurses key modifier masks */ + +#define PDC_KEY_MODIFIER_SHIFT 1 +#define PDC_KEY_MODIFIER_CONTROL 2 +#define PDC_KEY_MODIFIER_ALT 4 +#define PDC_KEY_MODIFIER_NUMLOCK 8 + +#if defined(__cplusplus) || defined(__cplusplus__) || defined(__CPLUSPLUS) +# undef bool +} +#endif + +#endif /* __PDCURSES__ */ diff --git a/modules/ncurses/pdcurses/curspriv.h b/modules/ncurses/pdcurses/curspriv.h new file mode 100644 index 00000000..37fb6666 --- /dev/null +++ b/modules/ncurses/pdcurses/curspriv.h @@ -0,0 +1,129 @@ +/* Public Domain Curses */ + +/* Private definitions and declarations for use within PDCurses. + These should generally not be referenced by applications. */ + +#ifndef __CURSES_INTERNALS__ +#define __CURSES_INTERNALS__ 1 + +#define CURSES_LIBRARY +#include + +#if defined(__TURBOC__) || defined(__EMX__) || defined(__DJGPP__) || \ + defined(__CYGWIN__) || defined(__MINGW32__) || \ + defined(__WATCOMC__) || defined(__PACIFIC__) +# ifndef HAVE_VSSCANF +# define HAVE_VSSCANF /* have vsscanf() */ +# endif +#endif + +#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__WATCOMC__) +# ifndef HAVE_VSNPRINTF +# define HAVE_VSNPRINTF /* have vsnprintf() */ +# endif +#endif + +/*----------------------------------------------------------------------*/ + +typedef struct /* structure for ripped off lines */ +{ + int line; + int (*init)(WINDOW *, int); +} RIPPEDOFFLINE; + +/* Window properties */ + +#define _SUBWIN 0x01 /* window is a subwindow */ +#define _PAD 0x10 /* X/Open Pad. */ +#define _SUBPAD 0x20 /* X/Open subpad. */ + +/* Miscellaneous */ + +#define _NO_CHANGE -1 /* flags line edge unchanged */ + +#define _ECHAR 0x08 /* Erase char (^H) */ +#define _DWCHAR 0x17 /* Delete Word char (^W) */ +#define _DLCHAR 0x15 /* Delete Line char (^U) */ + +extern WINDOW *pdc_lastscr; +extern FILE *pdc_dbfp; /* tracing file pointer (NULL = off) */ +extern bool pdc_color_started; +extern unsigned long pdc_key_modifiers; +extern MOUSE_STATUS pdc_mouse_status; + +/*----------------------------------------------------------------------*/ + +/* Platform implementation functions */ + +void PDC_beep(void); +bool PDC_can_change_color(void); +int PDC_color_content(short, short *, short *, short *); +bool PDC_check_key(void); +int PDC_curs_set(int); +void PDC_flushinp(void); +int PDC_get_columns(void); +int PDC_get_cursor_mode(void); +int PDC_get_key(void); +int PDC_get_rows(void); +void PDC_gotoyx(int, int); +int PDC_init_color(short, short, short, short); +void PDC_init_pair(short, short, short); +int PDC_modifiers_set(void); +int PDC_mouse_set(void); +void PDC_napms(int); +int PDC_pair_content(short, short *, short *); +void PDC_reset_prog_mode(void); +void PDC_reset_shell_mode(void); +int PDC_resize_screen(int, int); +void PDC_restore_screen_mode(int); +void PDC_save_screen_mode(int); +void PDC_scr_close(void); +void PDC_scr_free(void); +int PDC_scr_open(int, char **); +void PDC_set_keyboard_binary(bool); +void PDC_transform_line(int, int, int, const chtype *); +const char *PDC_sysname(void); + +/* Internal cross-module functions */ + +void PDC_init_atrtab(void); +WINDOW *PDC_makelines(WINDOW *); +WINDOW *PDC_makenew(int, int, int, int); +int PDC_mouse_in_slk(int, int); +void PDC_slk_free(void); +void PDC_slk_initialize(void); +void PDC_sync(WINDOW *); + +#ifdef PDC_WIDE +int PDC_mbtowc(wchar_t *, const char *, size_t); +size_t PDC_mbstowcs(wchar_t *, const char *, size_t); +size_t PDC_wcstombs(char *, const wchar_t *, size_t); +#endif + +#ifdef PDCDEBUG +# define PDC_LOG(x) if (pdc_dbfp) PDC_debug x +#else +# define PDC_LOG(x) +#endif + +/* Internal macros for attributes */ + +#ifdef CHTYPE_LONG +# define PDC_COLOR_PAIRS 256 +#else +# define PDC_COLOR_PAIRS 32 +#endif + +#ifndef max +# define max(a,b) (((a) > (b)) ? (a) : (b)) +#endif +#ifndef min +# define min(a,b) (((a) < (b)) ? (a) : (b)) +#endif + +#define DIVROUND(num, divisor) ((num) + ((divisor) >> 1)) / (divisor) + +#define PDC_CLICK_PERIOD 150 /* time to wait for a click, if + not set by mouseinterval() */ + +#endif /* __CURSES_INTERNALS__*/ diff --git a/modules/ncurses/pdcurses/demos/README.md b/modules/ncurses/pdcurses/demos/README.md new file mode 100644 index 00000000..4df65840 --- /dev/null +++ b/modules/ncurses/pdcurses/demos/README.md @@ -0,0 +1,25 @@ +PDCurses Demos +============== + +This directory contains demonstration programs to show and test the +capabilities of curses libraries. Some of them predate PDCurses, +PCcurses or even pcurses/ncurses. Although some PDCurses-specific code +has been added, all programs remain portable to other implementations +(at a minimum, to ncurses). + + +Building +-------- + +The demos are built by the platform-specific makefiles, in the platform +directories. Alternatively, you can build them manually, individually, +and link with any curses library; e.g., "cc -lcurses -orain rain.c". +There are no dependencies besides curses and the standard C library, and +no configuration is needed. + + +Distribution Status +------------------- + +Public Domain, except for rain.c and worm.c, which are under the ncurses +license (MIT-like). diff --git a/modules/ncurses/pdcurses/demos/firework.c b/modules/ncurses/pdcurses/demos/firework.c new file mode 100644 index 00000000..20ac6768 --- /dev/null +++ b/modules/ncurses/pdcurses/demos/firework.c @@ -0,0 +1,148 @@ +#include +#include +#include +#include +#include +#include +#include + +#define DELAYSIZE 200 + +void myrefresh(void); +void get_color(void); +void explode(int, int); + +short color_table[] = +{ + COLOR_RED, COLOR_BLUE, COLOR_GREEN, COLOR_CYAN, + COLOR_RED, COLOR_MAGENTA, COLOR_YELLOW, COLOR_WHITE +}; + +int main(int argc, char **argv) +{ + time_t seed; + int start, end, row, diff, flag, direction; + short i; + +#ifdef XCURSES + Xinitscr(argc, argv); +#else + initscr(); +#endif + nodelay(stdscr, TRUE); + noecho(); + + if (has_colors()) + start_color(); + + for (i = 0; i < 8; i++) + init_pair(i, color_table[i], COLOR_BLACK); + + seed = time((time_t *)0); + srand(seed); + flag = 0; + + while (getch() == ERR) /* loop until a key is hit */ + { + do { + start = rand() % (COLS - 3); + end = rand() % (COLS - 3); + start = (start < 2) ? 2 : start; + end = (end < 2) ? 2 : end; + direction = (start > end) ? -1 : 1; + diff = abs(start - end); + + } while (diff < 2 || diff >= LINES - 2); + + attrset(A_NORMAL); + + for (row = 0; row < diff; row++) + { + mvaddstr(LINES - row, row * direction + start, + (direction < 0) ? "\\" : "/"); + + if (flag++) + { + myrefresh(); + erase(); + flag = 0; + } + } + + if (flag++) + { + myrefresh(); + flag = 0; + } + + explode(LINES - row, diff * direction + start); + erase(); + myrefresh(); + } + + endwin(); + + return 0; +} + +void explode(int row, int col) +{ + erase(); + mvaddstr(row, col, "-"); + myrefresh(); + + --col; + + get_color(); + mvaddstr(row - 1, col, " - "); + mvaddstr(row, col, "-+-"); + mvaddstr(row + 1, col, " - "); + myrefresh(); + + --col; + + get_color(); + mvaddstr(row - 2, col, " --- "); + mvaddstr(row - 1, col, "-+++-"); + mvaddstr(row, col, "-+#+-"); + mvaddstr(row + 1, col, "-+++-"); + mvaddstr(row + 2, col, " --- "); + myrefresh(); + + get_color(); + mvaddstr(row - 2, col, " +++ "); + mvaddstr(row - 1, col, "++#++"); + mvaddstr(row, col, "+# #+"); + mvaddstr(row + 1, col, "++#++"); + mvaddstr(row + 2, col, " +++ "); + myrefresh(); + + get_color(); + mvaddstr(row - 2, col, " # "); + mvaddstr(row - 1, col, "## ##"); + mvaddstr(row, col, "# #"); + mvaddstr(row + 1, col, "## ##"); + mvaddstr(row + 2, col, " # "); + myrefresh(); + + get_color(); + mvaddstr(row - 2, col, " # # "); + mvaddstr(row - 1, col, "# #"); + mvaddstr(row, col, " "); + mvaddstr(row + 1, col, "# #"); + mvaddstr(row + 2, col, " # # "); + myrefresh(); +} + +void myrefresh(void) +{ + napms(DELAYSIZE); + move(LINES - 1, COLS - 1); + refresh(); +} + +void get_color(void) +{ + chtype bold = (rand() % 2) ? A_BOLD : A_NORMAL; + attrset(COLOR_PAIR(rand() % 8) | bold); +} diff --git a/modules/ncurses/pdcurses/demos/nctests.mif b/modules/ncurses/pdcurses/demos/nctests.mif new file mode 100644 index 00000000..a6e8afa1 --- /dev/null +++ b/modules/ncurses/pdcurses/demos/nctests.mif @@ -0,0 +1,31 @@ +# This provides for compiling and linking the ncurses test programs. + +NCURSES_TESTS = bs$(E) gdc$(E) hanoi$(E) knight$(E) tclock$(E) ncurses$(E) + +ncurses_tests: $(NCURSES_TESTS) + +ncurses_clean: + -rm -f *.$(O) trace $(NCURSES_TESTS) + +NCFLAGS = $(DEMOFLAGS) -I$(demodir) -I$(ncurses_testdir) + +bs$(E): $(ncurses_testdir)/bs.c + $(BUILD) $(NCFLAGS) -o $@ $< $(LDFLAGS) + +gdc$(E): $(ncurses_testdir)/gdc.c + $(BUILD) $(NCFLAGS) -o $@ $< $(LDFLAGS) + +hanoi$(E): $(ncurses_testdir)/hanoi.c + $(BUILD) $(NCFLAGS) -o $@ $< $(LDFLAGS) + +knight$(E): $(ncurses_testdir)/knight.c + $(BUILD) $(NCFLAGS) -o $@ $< $(LDFLAGS) + +tclock$(E): $(ncurses_testdir)/tclock.c + $(BUILD) $(NCFLAGS) -o $@ $< $(LDFLAGS) + +view$(E): $(ncurses_testdir)/view.c + $(BUILD) $(NCFLAGS) -o $@ $< $(LDFLAGS) + +ncurses$(E): $(ncurses_testdir)/ncurses.c + $(BUILD) $(NCFLAGS) -o $@ $< $(LDFLAGS) diff --git a/modules/ncurses/pdcurses/demos/ncurses_cfg.h b/modules/ncurses/pdcurses/demos/ncurses_cfg.h new file mode 100644 index 00000000..9a7c2cd6 --- /dev/null +++ b/modules/ncurses/pdcurses/demos/ncurses_cfg.h @@ -0,0 +1,57 @@ +/* This file is only used with the ncurses test programs. + * + * Have ncurses-5.9 unpacked in your $(HOME) (you don't need to build + * it), or edit ncurses_testdir appropriately in the Makefile or + * nctests.mif. Configure and build PDCurses, and: + * + * "make ncurses_tests" to start. + * "make ncurses_clean" when you're done. + * + * Builds: bs gdc hanoi knight tclock ncurses + */ + +#define NCURSES_MOUSE_VERSION 2 +#define NCURSES_CONST +#define NCURSES_EXPORT(foo) foo + +#define RETSIGTYPE void +#define TIME_WITH_SYS_TIME 1 +#define HAVE_SYS_TIME_H 1 +#define HAVE_SYS_TIME_SELECT 1 +#define HAVE_UNISTD_H 1 +#define HAVE_TERMATTRS 1 + +#include + +#define ExitProgram exit + +#define HAVE_CURSES_VERSION 1 +#define HAVE_GETBEGX 1 +#define HAVE_GETCURX 1 +#define HAVE_GETMAXX 1 +#define HAVE_GETNSTR 1 +#define HAVE_GETTIMEOFDAY 1 +#define HAVE_GETWIN 1 +#define HAVE_LIBPANEL 1 +#define HAVE_LOCALE_H 1 +#define HAVE_MATH_H 1 +#define HAVE_NAPMS 1 +#define HAVE_PANEL_H 1 +#define HAVE_PUTWIN 1 +#define HAVE_SLK_COLOR 1 +#define HAVE_SLK_INIT 1 +#define HAVE_WRESIZE 1 + +#ifdef PDC_WIDE +# define USE_WIDEC_SUPPORT 1 +# define HAVE_WCSRTOMBS 1 +# define HAVE_MBSRTOWCS 1 +# define HAVE_MBRTOWC 1 +# define HAVE_MBRLEN 1 +#endif + +/* Fool ncurses.c so it gives us all the tests, and doesn't redefine + ACS_ chars +*/ + +#define NCURSES_VERSION PDCURSES diff --git a/modules/ncurses/pdcurses/demos/ozdemo.c b/modules/ncurses/pdcurses/demos/ozdemo.c new file mode 100644 index 00000000..7fcd40bc --- /dev/null +++ b/modules/ncurses/pdcurses/demos/ozdemo.c @@ -0,0 +1,424 @@ +/* + * ozdemo.c - A demo program using PDCurses. The program + * (formerly newdemo) illustrates the use of colors for text output. + * + * Hacks by jbuhler@cs.washington.edu on 12/29/96 + */ + +#include +#include +#include +#include +#include +#include + +int WaitForUser(void); +int SubWinTest(WINDOW *); +int BouncingBalls(WINDOW *); +void trap(int); + +/* An ASCII map of Australia */ + +char *AusMap[17] = +{ + " A ", + " AA AA ", + " N.T. AAAAA AAAA ", + " AAAAAAAAAAA AAAAAAAA ", + " AAAAAAAAAAAAAAAAAAAAAAAAA Qld.", + " AAAAAAAAAAAAAAAAAAAAAAAAAAAA ", + " AAAAAAAAAAAAAAAAAAAAAAAAAAAAA ", + " AAAAAAAAAAAAAAAAAAAAAAAAAAAA ", + " AAAAAAAAAAAAAAAAAAAAAAAAA N.S.W.", + "W.A. AAAAAAAAA AAAAAA Vic.", + " AAA S.A. AA", + " A Tas.", + "" +}; + +/* Funny messages for the scroller */ + +char *messages[] = +{ + "Hello from the Land Down Under", + "The Land of crocs, and a big Red Rock", + "Where the sunflower runs along the highways", + "The dusty red roads lead one to loneliness", + "Blue sky in the morning and", + "Freezing nights and twinkling stars", + NULL +}; + +int WaitForUser(void) +{ + chtype ch; + + nodelay(stdscr, TRUE); + halfdelay(50); + + ch = getch(); + + nodelay(stdscr, FALSE); + nocbreak(); /* Reset the halfdelay() value */ + cbreak(); + + return (ch == '\033') ? ch : 0; +} + +int SubWinTest(WINDOW *win) +{ + WINDOW *swin1, *swin2, *swin3; + int w, h, sw, sh, bx, by; + + wattrset(win, 0); + getmaxyx(win, h, w); + getbegyx(win, by, bx); + + sw = w / 3; + sh = h / 3; + + if ((swin1 = derwin(win, sh, sw, 3, 5)) == NULL) + return 1; + if ((swin2 = subwin(win, sh, sw, by + 4, bx + 8)) == NULL) + return 1; + if ((swin3 = subwin(win, sh, sw, by + 5, bx + 11)) == NULL) + return 1; + + init_pair(8, COLOR_RED, COLOR_BLUE); + wbkgd(swin1, COLOR_PAIR(8)); + werase(swin1); + mvwaddstr(swin1, 0, 3, "Sub-window 1"); + wrefresh(swin1); + + init_pair(9, COLOR_CYAN, COLOR_MAGENTA); + wbkgd(swin2, COLOR_PAIR(9)); + werase(swin2); + mvwaddstr(swin2, 0, 3, "Sub-window 2"); + wrefresh(swin2); + + init_pair(10, COLOR_YELLOW, COLOR_GREEN); + wbkgd(swin3, COLOR_PAIR(10)); + werase(swin3); + mvwaddstr(swin3, 0, 3, "Sub-window 3"); + wrefresh(swin3); + + delwin(swin1); + delwin(swin2); + delwin(swin3); + WaitForUser(); + + return 0; +} + +int BouncingBalls(WINDOW *win) +{ + chtype c1, c2, c3, ball1, ball2, ball3; + int w, h, x1, y1, xd1, yd1, x2, y2, xd2, yd2, x3, y3, xd3, yd3, c; + + curs_set(0); + + wbkgd(win, COLOR_PAIR(1)); + wrefresh(win); + wattrset(win, 0); + + init_pair(11, COLOR_RED, COLOR_GREEN); + init_pair(12, COLOR_BLUE, COLOR_RED); + init_pair(13, COLOR_YELLOW, COLOR_WHITE); + + ball1 = 'O' | COLOR_PAIR(11); + ball2 = '*' | COLOR_PAIR(12); + ball3 = '@' | COLOR_PAIR(13); + + getmaxyx(win, h, w); + + x1 = 2 + rand() % (w - 4); + y1 = 2 + rand() % (h - 4); + x2 = 2 + rand() % (w - 4); + y2 = 2 + rand() % (h - 4); + x3 = 2 + rand() % (w - 4); + y3 = 2 + rand() % (h - 4); + + xd1 = 1; + yd1 = 1; + xd2 = 1; + yd2 = -1; + xd3 = -1; + yd3 = 1; + + nodelay(stdscr, TRUE); + + while ((c = getch()) == ERR) + { + x1 += xd1; + if (x1 <= 1 || x1 >= w - 2) + xd1 *= -1; + + y1 += yd1; + if (y1 <= 1 || y1 >= h - 2) + yd1 *= -1; + + x2 += xd2; + if (x2 <= 1 || x2 >= w - 2) + xd2 *= -1; + + y2 += yd2; + if (y2 <= 1 || y2 >= h - 2) + yd2 *= -1; + + x3 += xd3; + if (x3 <= 1 || x3 >= w - 2) + xd3 *= -1; + + y3 += yd3; + if (y3 <= 1 || y3 >= h - 2) + yd3 *= -1; + + c1 = mvwinch(win, y1, x1); + c2 = mvwinch(win, y2, x2); + c3 = mvwinch(win, y3, x3); + + mvwaddch(win, y1, x1, ball1); + mvwaddch(win, y2, x2, ball2); + mvwaddch(win, y3, x3, ball3); + + wmove(win, 0, 0); + wrefresh(win); + + mvwaddch(win, y1, x1, c1); + mvwaddch(win, y2, x2, c2); + mvwaddch(win, y3, x3, c3); + + napms(150); + } + + nodelay(stdscr, FALSE); + ungetch(c); + return 0; +} + +/* Trap interrupt */ + +void trap(int sig) +{ + if (sig == SIGINT) + { + endwin(); + + exit(0); + } +} + +int main(int argc, char **argv) +{ + WINDOW *win; + chtype save[80], ch; + time_t seed; + int width, height, w, x, y, i, j; + +#ifdef XCURSES + Xinitscr(argc, argv); +#else + initscr(); +#endif + seed = time((time_t *)0); + srand(seed); + + start_color(); +# if defined(NCURSES_VERSION) || (defined(PDC_BUILD) && PDC_BUILD > 3000) + use_default_colors(); +# endif + cbreak(); + noecho(); + + curs_set(0); + +#if !defined(__TURBOC__) && !defined(OS2) + signal(SIGINT, trap); +#endif + noecho(); + + /* refresh stdscr so that reading from it will not cause it to + overwrite the other windows that are being created */ + + refresh(); + + /* Create a drawing window */ + + width = 48; + height = 15; + + win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2); + + if (win == NULL) + { + endwin(); + + return 1; + } + + for (;;) + { + init_pair(1, COLOR_WHITE, COLOR_BLUE); + wbkgd(win, COLOR_PAIR(1)); + werase(win); + + init_pair(2, COLOR_RED, COLOR_RED); + wattrset(win, COLOR_PAIR(2)); + box(win, ' ', ' '); + wrefresh(win); + + wattrset(win, 0); + + /* Do random output of a character */ + + ch = 'a'; + + nodelay(stdscr, TRUE); + + for (i = 0; i < 5000; ++i) + { + x = rand() % (width - 2) + 1; + y = rand() % (height - 2) + 1; + + mvwaddch(win, y, x, ch); + wrefresh(win); + + if (getch() != ERR) + break; + + if (i == 2000) + { + ch = 'b'; + init_pair(3, COLOR_CYAN, COLOR_YELLOW); + wattrset(win, COLOR_PAIR(3)); + } + } + + nodelay(stdscr, FALSE); + + SubWinTest(win); + + /* Erase and draw green window */ + + init_pair(4, COLOR_YELLOW, COLOR_GREEN); + wbkgd(win, COLOR_PAIR(4)); + wattrset(win, A_BOLD); + werase(win); + wrefresh(win); + + /* Draw RED bounding box */ + + wattrset(win, COLOR_PAIR(2)); + box(win, ' ', ' '); + wrefresh(win); + + /* Display Australia map */ + + wattrset(win, A_BOLD); + i = 0; + + while (*AusMap[i]) + { + mvwaddstr(win, i + 1, 8, AusMap[i]); + wrefresh(win); + napms(100); + ++i; + } + + init_pair(5, COLOR_BLUE, COLOR_WHITE); + wattrset(win, COLOR_PAIR(5) | A_BLINK); + mvwaddstr(win, height - 2, 2, + " PDCurses 3.5 - DOS, OS/2, Windows, X11, SDL"); + wrefresh(win); + + /* Draw running messages */ + + init_pair(6, COLOR_BLACK, COLOR_WHITE); + wattrset(win, COLOR_PAIR(6)); + w = width - 2; + nodelay(win, TRUE); + + /* jbuhler's re-hacked scrolling messages */ + + for (j = 0; messages[j] != NULL; j++) + { + char *message = messages[j]; + int msg_len = strlen(message); + int scroll_len = w + 2 * msg_len; + char *scrollbuf = malloc(scroll_len); + char *visbuf = scrollbuf + msg_len; + int stop = 0; + int i; + + for (i = w + msg_len; i > 0; i--) + { + memset(visbuf, ' ', w); + strncpy(scrollbuf + i, message, msg_len); + mvwaddnstr(win, height / 2, 1, visbuf, w); + wrefresh(win); + + if (wgetch(win) != ERR) + { + flushinp(); + stop = 1; + break; + } + + napms(100); + } + + free(scrollbuf); + + if (stop) + break; + } + + j = 0; + + /* Draw running 'A's across in RED */ + + init_pair(7, COLOR_RED, COLOR_GREEN); + wattron(win, COLOR_PAIR(7)); + + for (i = 2; i < width - 4; ++i) + { + ch = mvwinch(win, 5, i); + save[j++] = ch; + ch = ch & 0x7f; + mvwaddch(win, 5, i, ch); + } + + wrefresh(win); + + /* Put a message up; wait for a key */ + + i = height - 2; + wattrset(win, COLOR_PAIR(5)); + mvwaddstr(win, i, 2, + " Type a key to continue or ESC to quit "); + wrefresh(win); + + if (WaitForUser() == '\033') + break; + + /* Restore the old line */ + + wattrset(win, 0); + + for (i = 2, j = 0; i < width - 4; ++i) + mvwaddch(win, 5, i, save[j++]); + + wrefresh(win); + + BouncingBalls(win); + + /* BouncingBalls() leaves a keystroke in the queue */ + + if (WaitForUser() == '\033') + break; + } + + endwin(); + + return 0; +} diff --git a/modules/ncurses/pdcurses/demos/ptest.c b/modules/ncurses/pdcurses/demos/ptest.c new file mode 100644 index 00000000..3f02f3a9 --- /dev/null +++ b/modules/ncurses/pdcurses/demos/ptest.c @@ -0,0 +1,309 @@ +#include +#include +#include + +PANEL *p1, *p2, *p3, *p4, *p5; +WINDOW *w4, *w5; + +long nap_msec = 1; + +char *mod[] = +{ + "test ", "TEST ", "(**) ", "*()* ", "<--> ", "LAST " +}; + +void pflush(void) +{ + update_panels(); + doupdate(); +} + +void sizecheck(void) +{ + if (COLS < 70 || LINES < 23) + { + printw("A window at least 70x23 is required for this demo"); + refresh(); + napms(5000); + endwin(); + exit(-1); + } +} + +void backfill(void) +{ + int y, x; + + erase(); + + for (y = 0; y < LINES - 1; y++) + for (x = 0; x < COLS; x++) + printw("%d", (y + x) % 10); +} + +void wait_a_while(long msec) +{ + int c; + + if (msec != 1) + timeout(msec); + + c = getch(); + +#ifdef KEY_RESIZE + if (c == KEY_RESIZE) + { +# ifdef PDCURSES + resize_term(0, 0); +# endif + sizecheck(); + backfill(); + } + else +#endif + if (c == 'q') + { + endwin(); + exit(1); + } +} + +void saywhat(const char *text) +{ + mvprintw(LINES - 1, 0, "%-20.20s", text); +} + +/* mkpanel - alloc a win and panel and associate them */ + +PANEL *mkpanel(int rows, int cols, int tly, int tlx) +{ + WINDOW *win = newwin(rows, cols, tly, tlx); + PANEL *pan = (PANEL *)0; + + if (win) + { + pan = new_panel(win); + + if (!pan) + delwin(win); + } + + return pan; +} + +void rmpanel(PANEL *pan) +{ + WINDOW *win = pan->win; + + del_panel(pan); + delwin(win); +} + +void fill_panel(PANEL *pan) +{ + WINDOW *win = pan->win; + char num = *((char *)pan->user + 1); + int y, x, maxy, maxx; + + box(win, 0, 0); + mvwprintw(win, 1, 1, "-pan%c-", num); + getmaxyx(win, maxy, maxx); + + for (y = 2; y < maxy - 1; y++) + for (x = 1; x < maxx - 1; x++) + mvwaddch(win, y, x, num); +} + +int main(int argc, char **argv) +{ + int itmp, y; + + if (argc > 1 && atol(argv[1])) + nap_msec = atol(argv[1]); + +#ifdef XCURSES + Xinitscr(argc, argv); +#else + initscr(); +#endif + + keypad(stdscr, TRUE); + sizecheck(); + backfill(); + + for (y = 0; y < 5; y++) + { + p1 = mkpanel(10, 10, 0, 0); + set_panel_userptr(p1, "p1"); + + p2 = mkpanel(14, 14, 5, 5); + set_panel_userptr(p2, "p2"); + + p3 = mkpanel(6, 8, 12, 12); + set_panel_userptr(p3, "p3"); + + p4 = mkpanel(10, 10, 10, 30); + w4 = panel_window(p4); + set_panel_userptr(p4, "p4"); + + p5 = mkpanel(10, 10, 13, 37); + w5 = panel_window(p5); + set_panel_userptr(p5, "p5"); + + fill_panel(p1); + fill_panel(p2); + fill_panel(p3); + fill_panel(p4); + fill_panel(p5); + hide_panel(p4); + hide_panel(p5); + pflush(); + wait_a_while(nap_msec); + + saywhat("h3 s1 s2 s4 s5;"); + move_panel(p1, 0, 0); + hide_panel(p3); + show_panel(p1); + show_panel(p2); + show_panel(p4); + show_panel(p5); + pflush(); + wait_a_while(nap_msec); + + saywhat("s1;"); + show_panel(p1); + pflush(); + wait_a_while(nap_msec); + + saywhat("s2;"); + show_panel(p2); + pflush(); + wait_a_while(nap_msec); + + saywhat("m2;"); + move_panel(p2, 10, 10); + pflush(); + wait_a_while(nap_msec); + + saywhat("s3;"); + show_panel(p3); + pflush(); + wait_a_while(nap_msec); + + saywhat("m3;"); + move_panel(p3, 5, 5); + pflush(); + wait_a_while(nap_msec); + + saywhat("b3;"); + bottom_panel(p3); + pflush(); + wait_a_while(nap_msec); + + saywhat("s4;"); + show_panel(p4); + pflush(); + wait_a_while(nap_msec); + + saywhat("s5;"); + show_panel(p5); + pflush(); + wait_a_while(nap_msec); + + saywhat("t3;"); + top_panel(p3); + pflush(); + wait_a_while(nap_msec); + + saywhat("t1;"); + top_panel(p1); + pflush(); + wait_a_while(nap_msec); + + saywhat("t2;"); + top_panel(p2); + pflush(); + wait_a_while(nap_msec); + + saywhat("t3;"); + top_panel(p3); + pflush(); + wait_a_while(nap_msec); + + saywhat("t4;"); + top_panel(p4); + pflush(); + wait_a_while(nap_msec); + + for (itmp = 0; itmp < 6; itmp++) + { + saywhat("m4;"); + mvwaddstr(w4, 3, 1, mod[itmp]); + move_panel(p4, 4, itmp * 10); + mvwaddstr(w5, 4, 1, mod[itmp]); + pflush(); + wait_a_while(nap_msec); + + saywhat("m5;"); + mvwaddstr(w4, 4, 1, mod[itmp]); + move_panel(p5, 7, itmp * 10 + 6); + mvwaddstr(w5, 3, 1, mod[itmp]); + pflush(); + wait_a_while(nap_msec); + } + + saywhat("m4;"); + move_panel(p4, 4, itmp * 10); + pflush(); + wait_a_while(nap_msec); + + saywhat("t5;"); + top_panel(p5); + pflush(); + wait_a_while(nap_msec); + + saywhat("t2;"); + top_panel(p2); + pflush(); + wait_a_while(nap_msec); + + saywhat("t1;"); + top_panel(p1); + pflush(); + wait_a_while(nap_msec); + + saywhat("d2;"); + rmpanel(p2); + pflush(); + wait_a_while(nap_msec); + + saywhat("h3;"); + hide_panel(p3); + pflush(); + wait_a_while(nap_msec); + + saywhat("d1;"); + rmpanel(p1); + pflush(); + wait_a_while(nap_msec); + + saywhat("d4; "); + rmpanel(p4); + pflush(); + wait_a_while(nap_msec); + + saywhat("d5; "); + rmpanel(p5); + pflush(); + wait_a_while(nap_msec); + + if (nap_msec == 1) + break; + + nap_msec = 100L; + } + + endwin(); + + return 0; +} /* end of main */ diff --git a/modules/ncurses/pdcurses/demos/rain.c b/modules/ncurses/pdcurses/demos/rain.c new file mode 100644 index 00000000..b8ef4e53 --- /dev/null +++ b/modules/ncurses/pdcurses/demos/rain.c @@ -0,0 +1,158 @@ +/**************************************************************************** + * Copyright (c) 2002 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +#include +#include +#include + +/* rain 11/3/1980 EPS/CITHEP */ + +static int next_j(int j) +{ + if (j == 0) + j = 4; + else + --j; + + if (has_colors()) + { + int z = rand() % 3; + chtype color = COLOR_PAIR(z); + + if (z) + color |= A_BOLD; + + attrset(color); + } + + return j; +} + +int main(int argc, char *argv[]) +{ + time_t seed; + int x, y, j, r, c; + static int xpos[5], ypos[5]; + +#ifdef XCURSES + Xinitscr(argc, argv); +#else + initscr(); +#endif + seed = time((time_t *)0); + srand(seed); + + if (has_colors()) + { + short bg = COLOR_BLACK; + + start_color(); + +#if defined(NCURSES_VERSION) || (defined(PDC_BUILD) && PDC_BUILD > 3000) + if (use_default_colors() == OK) + bg = -1; +#endif + init_pair(1, COLOR_BLUE, bg); + init_pair(2, COLOR_CYAN, bg); + } + + nl(); + noecho(); + curs_set(0); + timeout(0); + keypad(stdscr, TRUE); + + r = LINES - 4; + c = COLS - 4; + + for (j = 5; --j >= 0;) + { + xpos[j] = rand() % c + 2; + ypos[j] = rand() % r + 2; + } + + for (j = 0;;) + { + x = rand() % c + 2; + y = rand() % r + 2; + + mvaddch(y, x, '.'); + + mvaddch(ypos[j], xpos[j], 'o'); + + j = next_j(j); + mvaddch(ypos[j], xpos[j], 'O'); + + j = next_j(j); + mvaddch(ypos[j] - 1, xpos[j], '-'); + mvaddstr(ypos[j], xpos[j] - 1, "|.|"); + mvaddch(ypos[j] + 1, xpos[j], '-'); + + j = next_j(j); + mvaddch(ypos[j] - 2, xpos[j], '-'); + mvaddstr(ypos[j] - 1, xpos[j] - 1, "/ \\"); + mvaddstr(ypos[j], xpos[j] - 2, "| O |"); + mvaddstr(ypos[j] + 1, xpos[j] - 1, "\\ /"); + mvaddch(ypos[j] + 2, xpos[j], '-'); + + j = next_j(j); + mvaddch(ypos[j] - 2, xpos[j], ' '); + mvaddstr(ypos[j] - 1, xpos[j] - 1, " "); + mvaddstr(ypos[j], xpos[j] - 2, " "); + mvaddstr(ypos[j] + 1, xpos[j] - 1, " "); + mvaddch(ypos[j] + 2, xpos[j], ' '); + + xpos[j] = x; + ypos[j] = y; + + switch (getch()) + { + case 'q': + case 'Q': + curs_set(1); + endwin(); + return EXIT_SUCCESS; + case 's': + nodelay(stdscr, FALSE); + break; + case ' ': + nodelay(stdscr, TRUE); +#ifdef KEY_RESIZE + break; + case KEY_RESIZE: +# ifdef PDCURSES + resize_term(0, 0); + erase(); +# endif + r = LINES - 4; + c = COLS - 4; +#endif + } + napms(50); + } +} diff --git a/modules/ncurses/pdcurses/demos/testcurs.c b/modules/ncurses/pdcurses/demos/testcurs.c new file mode 100644 index 00000000..921a9bb0 --- /dev/null +++ b/modules/ncurses/pdcurses/demos/testcurs.c @@ -0,0 +1,1282 @@ +/* + * This is a test program for PDCurses. Originally by + * John Burnell + * + * wrs(5/28/93) -- modified to be consistent (perform identically) + * with either PDCurses or under Unix System V, R4 + */ + +#ifndef _XOPEN_SOURCE_EXTENDED +# define _XOPEN_SOURCE_EXTENDED 1 +#endif + +#include +#include +#include +#include + +#ifdef WACS_S1 +# define HAVE_WIDE 1 +#else +# define HAVE_WIDE 0 +#endif + +#include + +#if HAVE_WIDE +# include +#endif + +#if defined(PDCURSES) && !defined(XCURSES) +# define HAVE_RESIZE 1 +#else +# define HAVE_RESIZE 0 +#endif + +#ifdef A_COLOR +# define HAVE_COLOR 1 +#else +# define HAVE_COLOR 0 +#endif + +/* Set to non-zero if you want to test the PDCurses clipboard */ + +#define HAVE_CLIPBOARD 0 + +void inputTest(WINDOW *); +void scrollTest(WINDOW *); +void introTest(WINDOW *); +int initTest(WINDOW **, int, char **); +void outputTest(WINDOW *); +void padTest(WINDOW *); +void acsTest(WINDOW *); +void attrTest(WINDOW *); + +#if HAVE_COLOR +void colorTest(WINDOW *); +#endif + +#if HAVE_RESIZE +void resizeTest(WINDOW *); +#endif + +#if HAVE_CLIPBOARD +void clipboardTest(WINDOW *); +#endif + +#if HAVE_WIDE +void wideTest(WINDOW *); +#endif + +void display_menu(int, int); + +struct commands +{ + const char *text; + void (*function)(WINDOW *); +}; + +typedef struct commands COMMAND; + +#define MAX_OPTIONS (7 + HAVE_COLOR + HAVE_RESIZE + HAVE_CLIPBOARD + HAVE_WIDE) + +COMMAND command[MAX_OPTIONS] = +{ + {"Intro Test", introTest}, + {"Pad Test", padTest}, +#if HAVE_RESIZE + {"Resize Test", resizeTest}, +#endif + {"Scroll Test", scrollTest}, + {"Input Test", inputTest}, + {"Output Test", outputTest}, + {"ACS Test", acsTest}, + {"Attrib Test", attrTest}, +#if HAVE_COLOR + {"Color Test", colorTest}, +#endif +#if HAVE_CLIPBOARD + {"Clipboard Test", clipboardTest}, +#endif +#if HAVE_WIDE + {"Wide Input", wideTest} +#endif +}; + +int width, height; + +int main(int argc, char *argv[]) +{ + WINDOW *win; + int key, old_option = -1, new_option = 0; + bool quit = FALSE; + + setlocale(LC_ALL, ""); + + if (initTest(&win, argc, argv)) + return 1; + +#ifdef A_COLOR + if (has_colors()) + { + init_pair(1, COLOR_WHITE, COLOR_BLUE); + wbkgd(win, COLOR_PAIR(1)); + } + else +#endif + wbkgd(win, A_REVERSE); + + erase(); + display_menu(old_option, new_option); + + while (1) + { + noecho(); + keypad(stdscr, TRUE); + raw(); + + key = getch(); + + switch(key) + { + case 10: + case 13: + case KEY_ENTER: + old_option = -1; + erase(); + refresh(); + (*command[new_option].function)(win); + erase(); + display_menu(old_option, new_option); + break; + + case KEY_PPAGE: + case KEY_HOME: + old_option = new_option; + new_option = 0; + display_menu(old_option, new_option); + break; + + case KEY_NPAGE: + case KEY_END: + old_option = new_option; + new_option = MAX_OPTIONS - 1; + display_menu(old_option, new_option); + break; + + case KEY_UP: + old_option = new_option; + new_option = (new_option == 0) ? + new_option : new_option - 1; + display_menu(old_option, new_option); + break; + + case KEY_DOWN: + old_option = new_option; + new_option = (new_option == MAX_OPTIONS - 1) ? + new_option : new_option + 1; + display_menu(old_option, new_option); + break; +#ifdef KEY_RESIZE + case KEY_RESIZE: +# ifdef PDCURSES + resize_term(0, 0); +# endif + old_option = -1; + erase(); + display_menu(old_option, new_option); + break; +#endif + case 'Q': + case 'q': + quit = TRUE; + } + + if (quit == TRUE) + break; + } + + delwin(win); + endwin(); + + return 0; +} + +void Continue(WINDOW *win) +{ + mvwaddstr(win, 10, 1, " Press any key to continue"); + wrefresh(win); + raw(); + wgetch(win); +} + +void Continue2(void) +{ + move(LINES - 1, 1); + clrtoeol(); + mvaddstr(LINES - 2, 1, " Press any key to continue"); + refresh(); + raw(); + getch(); +} + +int initTest(WINDOW **win, int argc, char *argv[]) +{ +#ifdef XCURSES + Xinitscr(argc, argv); +#else + initscr(); +#endif +#ifdef A_COLOR + if (has_colors()) + start_color(); +#endif + /* Create a drawing window */ + + width = 60; + height = 13; + + *win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2); + + if (*win == NULL) + { + endwin(); + return 1; + } + + return 0; +} + +void introTest(WINDOW *win) +{ + werase(win); + wmove(win, height / 2 - 5, width / 2); + wvline(win, ACS_VLINE, 10); + wmove(win, height / 2, width / 2 - 10); + whline(win, ACS_HLINE, 20); + Continue(win); + + beep(); + werase(win); + + box(win, ACS_VLINE, ACS_HLINE); + wrefresh(win); + + cbreak(); + mvwaddstr(win, 1, 1, + "You should have a rectangle in the middle of the screen"); + mvwaddstr(win, 2, 1, "You should have heard a beep"); + Continue(win); + + flash(); + mvwaddstr(win, 3, 1, "You should have seen a flash"); + Continue(win); +} + +void scrollTest(WINDOW *win) +{ + int i, OldY; +#ifndef PDCURSES + int OldX; +#endif + werase(win); + mvwaddstr(win, height - 2, 1, "The window will now scroll slowly"); + box(win, ACS_VLINE, ACS_HLINE); + wrefresh(win); + scrollok(win, TRUE); + napms(500); + + for (i = 1; i <= height; i++) + { + napms(150); + scroll(win); + wrefresh(win); + }; + +#ifdef PDCURSES + OldY = getmaxy(win); +#else + getmaxyx(win, OldY, OldX); +#endif + mvwaddstr(win, 6, 1, "The top of the window will scroll"); + wmove(win, 1, 1); + wsetscrreg(win, 0, 4); + box(win, ACS_VLINE, ACS_HLINE); + wrefresh(win); + + for (i = 1; i <= 5; i++) + { + napms(500); + scroll(win); + wrefresh(win); + } + + mvwaddstr(win, 3, 1, "The bottom of the window will scroll"); + wmove(win, 8, 1); + wsetscrreg(win, 5, --OldY); + box(win, ACS_VLINE, ACS_HLINE); + wrefresh(win); + + for (i = 5; i <= OldY; i++) + { + napms(300); + wscrl(win, -1); + wrefresh(win); + } + + wsetscrreg(win, 0, OldY); +} + +void inputTest(WINDOW *win) +{ + int w, h, bx, by, sw, sh, i, c, num = 0; + char buffer[80]; + WINDOW *subWin; + static const char spinner[4] = "/-\\|"; + int spinner_count = 0; + + wclear(win); + + getmaxyx(win, h, w); + getbegyx(win, by, bx); + + sw = w / 3; + sh = h / 3; + + if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) + == NULL) + return; + +#ifdef A_COLOR + if (has_colors()) + { + init_pair(2, COLOR_WHITE, COLOR_RED); + wbkgd(subWin, COLOR_PAIR(2) | A_BOLD); + } + else +#endif + wbkgd(subWin, A_BOLD); + + box(subWin, ACS_VLINE, ACS_HLINE); + wrefresh(win); + + nocbreak(); + + wclear (win); + mvwaddstr(win, 1, 1, + "Press keys (or mouse buttons) to show their names"); + mvwaddstr(win, 2, 1, "Press spacebar to finish"); + wrefresh(win); + + keypad(win, TRUE); + raw(); + noecho(); + + wtimeout(win, 200); + +#ifdef PDCURSES + mouse_set(ALL_MOUSE_EVENTS); + PDC_save_key_modifiers(TRUE); + PDC_return_key_modifiers(TRUE); +#endif + curs_set(0); /* turn cursor off */ + + while (1) + { + while (1) + { + c = wgetch(win); + + if (c == ERR) + { + spinner_count++; + if (spinner_count == 4) + spinner_count = 0; + mvwaddch(win, 3, 3, spinner[spinner_count]); + wrefresh(win); + } + else + break; + } +#ifdef PDCURSES + wmove(win, 4, 18); + wclrtoeol(win); +#endif + mvwaddstr(win, 3, 5, "Key Pressed: "); + wclrtoeol(win); + + if (c >= KEY_MIN) + wprintw(win, "%s", keyname(c)); + else if (isprint(c)) + wprintw(win, "%c", c); + else + wprintw(win, "%s", unctrl(c)); +#ifdef PDCURSES + if (c == KEY_MOUSE) + { + int button = 0; + request_mouse_pos(); + + if (BUTTON_CHANGED(1)) + button = 1; + else if (BUTTON_CHANGED(2)) + button = 2; + else if (BUTTON_CHANGED(3)) + button = 3; + + if (button && (BUTTON_STATUS(button) & + BUTTON_MODIFIER_MASK)) + { + waddstr(win, " Modifier(s):"); + + if (BUTTON_STATUS(button) & BUTTON_SHIFT) + waddstr(win, " SHIFT"); + + if (BUTTON_STATUS(button) & BUTTON_CONTROL) + waddstr(win, " CONTROL"); + + if (BUTTON_STATUS(button) & BUTTON_ALT) + waddstr(win, " ALT"); + } + + wmove(win, 4, 18); + wclrtoeol(win); + wprintw(win, "Button %d: ", button); + + if (MOUSE_MOVED) + waddstr(win, "moved: "); + else if (MOUSE_WHEEL_UP) + waddstr(win, "wheel up: "); + else if (MOUSE_WHEEL_DOWN) + waddstr(win, "wheel dn: "); + else if (MOUSE_WHEEL_LEFT) + waddstr(win, "wheel lt: "); + else if (MOUSE_WHEEL_RIGHT) + waddstr(win, "wheel rt: "); + else if ((BUTTON_STATUS(button) & + BUTTON_ACTION_MASK) == BUTTON_PRESSED) + waddstr(win, "pressed: "); + else if ((BUTTON_STATUS(button) & + BUTTON_ACTION_MASK) == BUTTON_CLICKED) + waddstr(win, "clicked: "); + else if ((BUTTON_STATUS(button) & + BUTTON_ACTION_MASK) == BUTTON_DOUBLE_CLICKED) + waddstr(win, "double: "); + else + waddstr(win, "released: "); + + wprintw(win, "Position: Y: %d X: %d", MOUSE_Y_POS, MOUSE_X_POS); + } + else if (PDC_get_key_modifiers()) + { + waddstr(win, " Modifier(s):"); + if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_SHIFT) + waddstr(win, " SHIFT"); + + if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_CONTROL) + waddstr(win, " CONTROL"); + + if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_ALT) + waddstr(win, " ALT"); + + if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_NUMLOCK) + waddstr(win, " NUMLOCK"); + } +#endif + wrefresh(win); + + if (c == ' ') + break; + } + + wtimeout(win, -1); /* turn off timeout() */ + curs_set(1); /* turn cursor back on */ + +#ifdef PDCURSES + mouse_set(0L); + PDC_save_key_modifiers(FALSE); + PDC_return_key_modifiers(FALSE); +#endif + wclear(win); + mvwaddstr(win, 2, 1, "Press some keys for 5 seconds"); + mvwaddstr(win, 1, 1, "Pressing ^C should do nothing"); + wrefresh(win); + + werase(subWin); + box(subWin, ACS_VLINE, ACS_HLINE); + + for (i = 0; i < 5; i++) + { + mvwprintw(subWin, 1, 1, "Time = %d", i); + wrefresh(subWin); + napms(1000); + flushinp(); + } + + delwin(subWin); + werase(win); + flash(); + wrefresh(win); + napms(500); + flushinp(); + + mvwaddstr(win, 2, 1, "Press a key, followed by ENTER"); + wmove(win, 9, 10); + wrefresh(win); + echo(); + + keypad(win, TRUE); + raw(); + wgetnstr(win, buffer, 3); + flushinp(); + + wmove(win, 9, 10); + wdelch(win); + mvwaddstr(win, 4, 1, "The character should now have been deleted"); + Continue(win); + + refresh(); + wclear(win); + echo(); + buffer[0] = '\0'; + mvwaddstr(win, 3, 2, "The window should have moved"); + mvwaddstr(win, 4, 2, + "This text should have appeared without you pressing a key"); + mvwaddstr(win, 6, 2, "Enter a number then a string seperated by space"); + mvwin(win, 2, 1); + wrefresh(win); + mvwscanw(win, 7, 6, "%d %s", &num, buffer); + mvwprintw(win, 8, 6, "String: %s Number: %d", buffer, num); + Continue(win); + + refresh(); + wclear(win); + echo(); + mvwaddstr(win, 3, 2, "Enter a 5 character string: "); + wgetnstr(win, buffer, 5); + mvwprintw(win, 4, 2, "String: %s", buffer); + Continue(win); +} + +void outputTest(WINDOW *win) +{ + WINDOW *win1; + char Buffer[80]; + chtype ch; + int by, bx; + +#ifdef PDCURSES + PDC_set_blink(TRUE); +#endif + nl(); + wclear(win); + mvwaddstr(win, 1, 1, "You should now have a screen in the upper " + "left corner, and this text should have wrapped"); + waddstr(win,"\nThis text should be down\n"); + waddstr(win, "and broken into two here ^"); + Continue(win); + + wclear(win); + wattron(win, A_BOLD); + mvwaddstr(win, 1, 1, "A new window will appear with this text in it"); + mvwaddstr(win, 8, 1, "Press any key to continue"); + wrefresh(win); + wgetch(win); + + getbegyx(win, by, bx); + + if (LINES < 24 || COLS < 75) + { + mvwaddstr(win, 5, 1, "Some tests have been skipped as they require a"); + mvwaddstr(win, 6, 1, "display of at least 24 LINES by 75 COLUMNS"); + Continue(win); + } + else + { + win1 = newwin(10, 50, 14, 25); + + if (win1 == NULL) + { + endwin(); + return; + } + +#ifdef A_COLOR + if (has_colors()) + { + init_pair(3, COLOR_BLUE, COLOR_WHITE); + wbkgd(win1, COLOR_PAIR(3)); + } + else +#endif + wbkgd(win1, A_NORMAL); + + wclear(win1); + mvwaddstr(win1, 5, 1, "This text should appear; using overlay option"); + copywin(win, win1, 0, 0, 0, 0, 9, 49, TRUE); + box(win1, ACS_VLINE, ACS_HLINE); + wmove(win1, 8, 26); + wrefresh(win1); + wgetch(win1); + + wclear(win1); + + wattron(win1, A_BLINK); + mvwaddstr(win1, 4, 1, + "This blinking text should appear in only the second window"); + wattroff(win1, A_BLINK); + + mvwin(win1, by, bx); + overlay(win, win1); + mvwin(win1, 14, 25); + wmove(win1, 8, 26); + wrefresh(win1); + wgetch(win1); + + delwin(win1); + } + + clear(); + wclear(win); + wrefresh(win); + mvwaddstr(win, 6, 2, "This line shouldn't appear"); + mvwaddstr(win, 4, 2, "Only half of the next line is visible"); + mvwaddstr(win, 5, 2, "Only half of the next line is visible"); + wmove(win, 6, 1); + wclrtobot(win); + wmove(win, 5, 20); + wclrtoeol(win); + mvwaddstr(win, 8, 2, "This line also shouldn't appear"); + wmove(win, 8, 1); + winsdelln(win, -1); + Continue(win); + + wmove(win, 5, 9); + ch = winch(win); + + wclear(win); + wmove(win, 6, 2); + waddstr(win, "The next char should be l: "); + winsch(win, ch); + Continue(win); + + mvwinsstr(win, 6, 2, "A1B2C3D4E5"); + Continue(win); + + wmove(win, 5, 1); + winsdelln(win, 1); + mvwaddstr(win, 5, 2, "The lines below should have moved down"); + Continue(win); + + wclear(win); + wmove(win, 2, 2); + wprintw(win, "This is a formatted string in a window: %d %s\n", + 42, "is it"); + mvwaddstr(win, 10, 1, "Enter a string: "); + wrefresh(win); + echo(); + wscanw(win, "%s", Buffer); + + printw("This is a formatted string in stdscr: %d %s\n", 42, "is it"); + mvaddstr(10, 1, "Enter a string: "); + scanw("%s", Buffer); + + wclear(win); + curs_set(2); + mvwaddstr(win, 1, 1, "The cursor should be in high-visibility mode"); + Continue(win); + + wclear(win); + curs_set(0); + mvwaddstr(win, 1, 1, "The cursor should have disappeared"); + Continue(win); + + wclear(win); + curs_set(1); + mvwaddstr(win, 1, 1, "The cursor should be normal"); + Continue(win); + +#ifdef A_COLOR + if (has_colors()) + { + wclear(win); + mvwaddstr(win, 1, 1, "Colors should change after you press a key"); + Continue(win); + + init_pair(1, COLOR_RED, COLOR_WHITE); + wrefresh(win); + } +#endif + werase(win); + mvwaddstr(win, 1, 1, "Information About Your Terminal"); + mvwaddstr(win, 3, 1, termname()); + mvwaddstr(win, 4, 1, longname()); + + if (termattrs() & A_BLINK) + mvwaddstr(win, 5, 1, "This terminal claims to support blinking."); + else + mvwaddstr(win, 5, 1, "This terminal does NOT support blinking."); + + mvwaddnstr(win, 7, 5, "Have a nice day!ok", 16); + wrefresh(win); + + mvwinnstr(win, 7, 5, Buffer, 18); + mvaddstr(LINES - 2, 10, Buffer); + refresh(); + Continue(win); +#ifdef PDCURSES + PDC_set_blink(FALSE); +#endif +} + +#if HAVE_RESIZE +void resizeTest(WINDOW *dummy) +{ + WINDOW *win1; + int nwidth = 135, nheight = 52; + int owidth = COLS, oheight = LINES; + + savetty(); + + resize_term(nheight, nwidth); + + clear(); + refresh(); + + win1 = newwin(10, 50, 14, 25); + + if (win1 == NULL) + { + endwin(); + return; + } + +#ifdef A_COLOR + if (has_colors()) + { + init_pair(3, COLOR_BLUE, COLOR_WHITE); + wattrset(win1, COLOR_PAIR(3)); + } + + wclear(win1); +#endif + mvwaddstr(win1, 0, 0, "The screen may now be resized"); + mvwprintw(win1, 1, 4, "Given size: %d by %d", nwidth, nheight); + mvwprintw(win1, 2, 4, "Actual size: %d by %d", COLS, LINES); + Continue(win1); + + wclear(win1); + resetty(); + + mvwaddstr(win1, 0, 0, "The screen should now be reset"); + mvwprintw(win1, 1, 6, "Old size: %d by %d", owidth, oheight); + mvwprintw(win1, 2, 6, "Size now: %d by %d", COLS, LINES); + Continue(win1); + + delwin(win1); + + clear(); + refresh(); +} +#endif /* HAVE_RESIZE */ + +void padTest(WINDOW *dummy) +{ + WINDOW *pad, *spad; + + pad = newpad(50, 100); + wattron(pad, A_REVERSE); + mvwaddstr(pad, 5, 2, "This is a new pad"); + wattrset(pad, 0); + mvwaddstr(pad, 8, 0, + "The end of this line should be truncated here:except now"); + mvwaddstr(pad, 11, 1, "This line should not appear.It will now"); + wmove(pad, 10, 1); + wclrtoeol(pad); + mvwaddstr(pad, 10, 1, " Press any key to continue"); + prefresh(pad, 0, 0, 0, 0, 10, 45); + keypad(pad, TRUE); + raw(); + wgetch(pad); + + spad = subpad(pad, 12, 25, 7, 52); + mvwaddstr(spad, 2, 2, "This is a new subpad"); + box(spad, 0, 0); + prefresh(pad, 0, 0, 0, 0, 15, 75); + keypad(pad, TRUE); + raw(); + wgetch(pad); + + mvwaddstr(pad, 35, 2, "This is displayed at line 35 in the pad"); + mvwaddstr(pad, 40, 1, " Press any key to continue"); + prefresh(pad, 30, 0, 0, 0, 10, 45); + keypad(pad, TRUE); + raw(); + wgetch(pad); + + delwin(pad); +} + +#if HAVE_CLIPBOARD +void clipboardTest(WINDOW *win) +{ + static const char *text = + "This string placed in clipboard by PDCurses test program, testcurs."; + char *ptr = NULL; + long i, length = 0; + + mvaddstr(1, 1, + "This test will display the contents of the system clipboard"); + + Continue2(); + + scrollok(stdscr, TRUE); + i = PDC_getclipboard(&ptr, &length); + + switch(i) + { + case PDC_CLIP_ACCESS_ERROR: + mvaddstr(3, 1, "There was an error accessing the clipboard"); + refresh(); + break; + + case PDC_CLIP_MEMORY_ERROR: + mvaddstr(3, 1, + "Unable to allocate memory for clipboard contents"); + break; + + case PDC_CLIP_EMPTY: + mvaddstr(3, 1, "There was no text in the clipboard"); + break; + + default: + wsetscrreg(stdscr, 0, LINES - 1); + clear(); + mvaddstr(1, 1, "Clipboard contents..."); + mvprintw(2, 1, "%s\n", ptr); + } + + Continue2(); + + clear(); + mvaddstr(1, 1, + "This test will place the following string in the system clipboard:"); + mvaddstr(2, 1, text); + + i = PDC_setclipboard(text, strlen(text)); + + switch(i) + { + case PDC_CLIP_ACCESS_ERROR: + mvaddstr(3, 1, "There was an error accessing the clipboard"); + break; + + case PDC_CLIP_MEMORY_ERROR: + mvaddstr(3, 1, "Unable to allocate memory for clipboard contents"); + break; + + default: + mvaddstr(3, 1, "The string was placed in the clipboard successfully"); + } + + Continue2(); +} +#endif /* HAVE_CLIPBOARD */ + +void acsTest(WINDOW *win) +{ +#ifdef ACS_S3 +# define ACSNUM 32 +#else +# define ACSNUM 25 +#endif + static const char *acs_names[] = + { + "ACS_ULCORNER", "ACS_URCORNER", "ACS_LLCORNER", "ACS_LRCORNER", + "ACS_LTEE", "ACS_RTEE", "ACS_TTEE", "ACS_BTEE", "ACS_HLINE", + "ACS_VLINE", "ACS_PLUS", + + "ACS_S1", "ACS_S9", "ACS_DIAMOND", "ACS_CKBOARD", "ACS_DEGREE", + "ACS_PLMINUS", "ACS_BULLET", + + "ACS_LARROW", "ACS_RARROW", "ACS_UARROW", "ACS_DARROW", + "ACS_BOARD", "ACS_LANTERN", "ACS_BLOCK" +#ifdef ACS_S3 + , "ACS_S3", "ACS_S7", "ACS_LEQUAL", "ACS_GEQUAL", + "ACS_PI", "ACS_NEQUAL", "ACS_STERLING" +#endif + }; + + chtype acs_values[ACSNUM]; + +#if HAVE_WIDE + cchar_t *wacs_values[] = + { + WACS_ULCORNER, WACS_URCORNER, WACS_LLCORNER, WACS_LRCORNER, + WACS_LTEE, WACS_RTEE, WACS_TTEE, WACS_BTEE, WACS_HLINE, + WACS_VLINE, WACS_PLUS, + + WACS_S1, WACS_S9, WACS_DIAMOND, WACS_CKBOARD, WACS_DEGREE, + WACS_PLMINUS, WACS_BULLET, + + WACS_LARROW, WACS_RARROW, WACS_UARROW, WACS_DARROW, WACS_BOARD, + WACS_LANTERN, WACS_BLOCK +# ifdef WACS_S3 + , WACS_S3, WACS_S7, WACS_LEQUAL, WACS_GEQUAL, WACS_PI, + WACS_NEQUAL, WACS_STERLING +# endif + }; + + static const wchar_t russian[] = {0x0420, 0x0443, 0x0441, 0x0441, + 0x043a, 0x0438, 0x0439, L' ', 0x044f, 0x0437, 0x044b, 0x043a, 0}; + + static const wchar_t greek[] = {0x0395, 0x03bb, 0x03bb, 0x03b7, + 0x03bd, 0x03b9, 0x03ba, 0x03ac, 0}; + + static const wchar_t georgian[] = {0x10e5, 0x10d0, 0x10e0, 0x10d7, + 0x10e3, 0x10da, 0x10d8, L' ', 0x10d4, 0x10dc, 0x10d0, 0}; +#endif + + int i, tmarg = (LINES - 22) / 2; + + attrset(A_BOLD); + mvaddstr(tmarg, (COLS - 23) / 2, "Alternate Character Set"); + attrset(A_NORMAL); + + tmarg += 3; + +#define A(b,c) acs_values[b] = ACS_##c + + A(0,ULCORNER); A(1,URCORNER); A(2,LLCORNER); A(3,LRCORNER); + A(4,LTEE); A(5,RTEE); A(6,TTEE); A(7,BTEE); + A(8,HLINE); A(9,VLINE); A(10,PLUS); A(11,S1); + A(12,S9); A(13,DIAMOND); A(14,CKBOARD); A(15,DEGREE); + + A(16,PLMINUS); A(17,BULLET); A(18,LARROW); A(19,RARROW); + A(20,UARROW); A(21,DARROW); A(22,BOARD); A(23,LANTERN); + A(24,BLOCK); +#ifdef ACS_S3 + A(25,S3); A(26,S7); A(27,LEQUAL); A(28,GEQUAL); + A(29,PI); A(30,NEQUAL); A(31,STERLING); +#endif + +#undef A + + for (i = 0; i < ACSNUM; i++) + { + move((i % 8) * 2 + tmarg, (i / 8) * (COLS / 4) + (COLS / 8 - 7)); + addch(acs_values[i]); + printw(" %s", acs_names[i]); + } + + mvaddstr(tmarg + 18, 3, "Press any key to continue"); + getch(); + +#if HAVE_WIDE + clear(); + + attrset(A_BOLD); + mvaddstr(tmarg - 3, (COLS - 28) / 2, "Wide Alternate Character Set"); + attrset(A_NORMAL); + + for (i = 0; i < ACSNUM; i++) + { + move((i % 8) * 2 + tmarg, (i / 8) * (COLS / 4) + (COLS / 8 - 7)); + add_wch(wacs_values[i]); + printw(" W%s", acs_names[i]); + } + + /* Spanish, Russian, Greek, Georgian */ + + mvaddwstr(tmarg + 16, COLS / 8 - 5, L"Espa\xf1ol"); + mvaddwstr(tmarg + 16, 3 * (COLS / 8) - 5, russian); + mvaddwstr(tmarg + 16, 5 * (COLS / 8) - 5, greek); + mvaddwstr(tmarg + 16, 7 * (COLS / 8) - 5, georgian); + + mvaddstr(tmarg + 18, 3, "Press any key to continue"); + getch(); +#endif +} + +void attrTest(WINDOW *win) +{ + int tmarg = (LINES - 16) / 2; + int col1 = (COLS - 36) / 2, col2 = col1 + 20; + + attrset(A_BOLD); + mvaddstr(tmarg, (COLS - 20) / 2, "Character Attributes"); + attrset(A_NORMAL); + + refresh(); + +#ifdef PDCURSES + PDC_set_blink(TRUE); + PDC_set_bold(TRUE); +#endif + +#ifdef A_ITALIC + attrset(A_ITALIC); + mvaddstr(tmarg + 3, col1, "A_ITALIC"); + attrset(A_NORMAL); +#endif + + attrset(A_BOLD); + mvaddstr(tmarg + 5, col1, "A_BOLD"); + attrset(A_NORMAL); + + attrset(A_BLINK); + mvaddstr(tmarg + 7, col1, "A_BLINK"); + attrset(A_NORMAL); + + attrset(A_REVERSE); + mvaddstr(tmarg + 9, col1, "A_REVERSE"); + attrset(A_NORMAL); + + attrset(A_STANDOUT); + mvaddstr(tmarg + 11, col1, "A_STANDOUT"); + attrset(A_NORMAL); + + attrset(A_UNDERLINE); + mvaddstr(tmarg + 13, col1, "A_UNDERLINE"); + attrset(A_NORMAL); + +#ifdef A_ITALIC + attrset(A_ITALIC|A_UNDERLINE); + mvaddstr(tmarg + 3, col2, "Underlined Italic"); + attrset(A_NORMAL); +#endif + + attrset(A_BOLD|A_UNDERLINE); + mvaddstr(tmarg + 5, col2, "Underlined Bold"); + attrset(A_NORMAL); + + attrset(A_BLINK|A_UNDERLINE); + mvaddstr(tmarg + 7, col2, "Underlined Blink"); + attrset(A_NORMAL); + +#ifdef A_LEFT + attrset(A_LEFT); + mvaddstr(tmarg + 9, col2, "A_LEFT"); + attrset(A_NORMAL); +#endif + +#ifdef A_RIGHT + attrset(A_RIGHT); + mvaddstr(tmarg + 11, col2, "A_RIGHT"); + attrset(A_NORMAL); +#endif + + attrset(A_BLINK|A_REVERSE); + mvaddstr(tmarg + 13, col2, "Reverse Blink"); + attrset(A_NORMAL); + + mvaddstr(tmarg + 16, 3, "Press any key to continue"); + getch(); + +#ifdef PDCURSES + PDC_set_bold(FALSE); + PDC_set_blink(FALSE); +#endif +} + +#if HAVE_COLOR +void colorTest(WINDOW *win) +{ + static const short colors[] = + { + COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_BLUE, + COLOR_CYAN, COLOR_MAGENTA, COLOR_YELLOW, COLOR_WHITE + }; + + static const char *colornames[] = + { + "COLOR_BLACK", "COLOR_RED", "COLOR_GREEN", "COLOR_BLUE", + "COLOR_CYAN", "COLOR_MAGENTA", "COLOR_YELLOW", "COLOR_WHITE" + }; + + chtype fill = ACS_BLOCK; + int maxcol = (COLORS >= 16) ? 16 : 8; + bool widecol = (maxcol == 16); + + int i, j, tmarg, col1, col2, col3; + + if (!has_colors()) + return; + + tmarg = (LINES - 19) / 2; + col1 = (COLS - 60) / 2; + col2 = col1 + 20; + col3 = col2 + 20; + + attrset(A_BOLD); + mvaddstr(tmarg, (COLS - 22) / 2, "Color Attribute Macros"); + attrset(A_NORMAL); + + if (widecol) + { + mvaddstr(tmarg + 3, col2 + 3, "Colors 0-7"); + mvaddstr(tmarg + 3, col3 + 2, "Colors 8-15"); + } + else + { + mvaddstr(tmarg + 3, col2 + 4, "A_NORMAL"); + mvaddstr(tmarg + 3, col3 + 5, "A_BOLD"); + } + + for (i = 0; i < 8; i++) + { + init_pair(i + 4, colors[i], COLOR_BLACK); + if (widecol) + init_pair(i + 12, colors[i] + 8, COLOR_BLACK); + + mvaddstr(tmarg + i + 5, col1, colornames[i]); + + for (j = 0; j < 16; j++) + { + mvaddch(tmarg + i + 5, col2 + j, fill | COLOR_PAIR(i + 4)); + mvaddch(tmarg + i + 5, col3 + j, fill | (widecol ? + COLOR_PAIR(i + 12) : (COLOR_PAIR(i + 4) | A_BOLD) )); + } + } + + mvprintw(tmarg + 15, col1, "COLORS = %d", COLORS); + mvprintw(tmarg + 16, col1, "COLOR_PAIRS = %d", COLOR_PAIRS); + + mvaddstr(tmarg + 19, 3, "Press any key to continue"); + getch(); + + if (can_change_color()) + { + struct + { + short red, green, blue; + } orgcolors[16]; + + for (i = 0; i < maxcol; i++) + color_content(i, &(orgcolors[i].red), + &(orgcolors[i].green), + &(orgcolors[i].blue)); + + attrset(A_BOLD); + mvaddstr(tmarg, (COLS - 22) / 2, " init_color() Example "); + attrset(A_NORMAL); + + refresh(); + + for (i = 0; i < 8; i++) + { + init_color(colors[i], i * 125, 0, i * 125); + + if (widecol) + init_color(colors[i] + 8, 0, i * 125, 0); + } + + mvaddstr(tmarg + 19, 3, "Press any key to continue"); + getch(); + + for (i = 0; i < maxcol; i++) + init_color(i, orgcolors[i].red, + orgcolors[i].green, + orgcolors[i].blue); + } + + if (COLORS >= 256) + { + int x, y, z, lmarg = (COLS - 77) / 2; + + erase(); + + attrset(A_BOLD); + mvaddstr(tmarg, (COLS - 15) / 2, "Extended Colors"); + attrset(A_NORMAL); + + mvaddstr(tmarg + 3, lmarg, "6x6x6 Color Cube (16-231):"); + + for (i = 16; i < 256; i++) + init_pair(i, COLOR_BLACK, i); + + for (i = 16, x = 0; x < 6; x++) + for (z = 0; z < 6; z++) + for (y = 0; y < 6; y++) + { + chtype ch = ' ' | COLOR_PAIR(i++); + + mvaddch(tmarg + 5 + y, z * 13 + x * 2 + lmarg, ch); + addch(ch); + } + + mvaddstr(tmarg + 13, lmarg, "Greyscale (232-255):"); + + for (x = 0; x < 24; x++) + { + chtype ch = ' ' | COLOR_PAIR(232 + x); + + mvaddch(tmarg + 15, x * 2 + lmarg, ch); + addch(ch); + } + + mvaddstr(tmarg + 19, 3, "Press any key to continue"); + getch(); + } +} +#endif + +#if HAVE_WIDE +void wideTest(WINDOW *win) +{ + wchar_t tmp[513]; + size_t i; + + attrset(A_BOLD); + mvaddstr(1, (COLS - 25) / 2, "Wide Character Input Test"); + attrset(A_NORMAL); + + mvaddstr(4, 1, "Enter a string: "); + + echo(); + + get_wstr((wint_t *)tmp); + addstr("\n\n String:\n\n "); + addwstr(tmp); + addstr("\n\n\n Hex:\n\n "); + + for (i = 0; i < wcslen(tmp); i++) + { + printw("%04x ", tmp[i]); + addnwstr(tmp + i, 1); + addstr(" "); + } + + noecho(); + + Continue2(); +} +#endif + +void display_menu(int old_option, int new_option) +{ + int lmarg = (COLS - 14) / 2, + tmarg = (LINES - (MAX_OPTIONS + 2)) / 2; + + if (old_option == -1) + { + int i; + + attrset(A_BOLD); + mvaddstr(tmarg - 3, lmarg - 5, "PDCurses Test Program"); + attrset(A_NORMAL); + + for (i = 0; i < MAX_OPTIONS; i++) + mvaddstr(tmarg + i, lmarg, command[i].text); + } + else + mvaddstr(tmarg + old_option, lmarg, command[old_option].text); + + attrset(A_REVERSE); + mvaddstr(tmarg + new_option, lmarg, command[new_option].text); + attrset(A_NORMAL); + + mvaddstr(tmarg + MAX_OPTIONS + 2, lmarg - 23, + "Use Up and Down Arrows to select - Enter to run - Q to quit"); + refresh(); +} diff --git a/modules/ncurses/pdcurses/demos/tui.c b/modules/ncurses/pdcurses/demos/tui.c new file mode 100644 index 00000000..f32a0bc4 --- /dev/null +++ b/modules/ncurses/pdcurses/demos/tui.c @@ -0,0 +1,820 @@ +/********************************* tui.c ************************************/ +/* + * 'textual user interface' + * + * Author : P.J. Kunst + * Date : 25-02-93 + */ + +#include +#include +#include +#include +#include +#include +#include "tui.h" + +void statusmsg(char *); +int waitforkey(void); +void rmerror(void); + +#if defined(__unix) && !defined(__DJGPP__) +#include +#endif + +#ifdef A_COLOR +# define TITLECOLOR 1 /* color pair indices */ +# define MAINMENUCOLOR (2 | A_BOLD) +# define MAINMENUREVCOLOR (3 | A_BOLD | A_REVERSE) +# define SUBMENUCOLOR (4 | A_BOLD) +# define SUBMENUREVCOLOR (5 | A_BOLD | A_REVERSE) +# define BODYCOLOR 6 +# define STATUSCOLOR (7 | A_BOLD) +# define INPUTBOXCOLOR 8 +# define EDITBOXCOLOR (9 | A_BOLD | A_REVERSE) +#else +# define TITLECOLOR 0 /* color pair indices */ +# define MAINMENUCOLOR (A_BOLD) +# define MAINMENUREVCOLOR (A_BOLD | A_REVERSE) +# define SUBMENUCOLOR (A_BOLD) +# define SUBMENUREVCOLOR (A_BOLD | A_REVERSE) +# define BODYCOLOR 0 +# define STATUSCOLOR (A_BOLD) +# define INPUTBOXCOLOR 0 +# define EDITBOXCOLOR (A_BOLD | A_REVERSE) +#endif + + +#define th 1 /* title window height */ +#define mh 1 /* main menu height */ +#define sh 2 /* status window height */ +#define bh (LINES - th - mh - sh) /* body window height */ +#define bw COLS /* body window width */ + + +/******************************* STATIC ************************************/ + +static WINDOW *wtitl, *wmain, *wbody, *wstat; /* title, menu, body, status win*/ +static int nexty, nextx; +static int key = ERR, ch = ERR; +static bool quit = FALSE; +static bool incurses = FALSE; + +#ifndef PDCURSES +static char wordchar(void) +{ + return 0x17; /* ^W */ +} +#endif + +static char *padstr(char *s, int length) +{ + static char buf[MAXSTRLEN]; + char fmt[10]; + + sprintf(fmt, (int)strlen(s) > length ? "%%.%ds" : "%%-%ds", length); + sprintf(buf, fmt, s); + + return buf; +} + +static char *prepad(char *s, int length) +{ + int i; + char *p = s; + + if (length > 0) + { + memmove((void *)(s + length), (const void *)s, strlen(s) + 1); + + for (i = 0; i < length; i++) + *p++ = ' '; + } + + return s; +} + +static void rmline(WINDOW *win, int nr) /* keeps box lines intact */ +{ + mvwaddstr(win, nr, 1, padstr(" ", bw - 2)); + wrefresh(win); +} + +static void initcolor(void) +{ +#ifdef A_COLOR + if (has_colors()) + start_color(); + + /* foreground, background */ + + init_pair(TITLECOLOR & ~A_ATTR, COLOR_BLACK, COLOR_CYAN); + init_pair(MAINMENUCOLOR & ~A_ATTR, COLOR_WHITE, COLOR_CYAN); + init_pair(MAINMENUREVCOLOR & ~A_ATTR, COLOR_WHITE, COLOR_BLACK); + init_pair(SUBMENUCOLOR & ~A_ATTR, COLOR_WHITE, COLOR_CYAN); + init_pair(SUBMENUREVCOLOR & ~A_ATTR, COLOR_WHITE, COLOR_BLACK); + init_pair(BODYCOLOR & ~A_ATTR, COLOR_WHITE, COLOR_BLUE); + init_pair(STATUSCOLOR & ~A_ATTR, COLOR_WHITE, COLOR_CYAN); + init_pair(INPUTBOXCOLOR & ~A_ATTR, COLOR_BLACK, COLOR_CYAN); + init_pair(EDITBOXCOLOR & ~A_ATTR, COLOR_WHITE, COLOR_BLACK); +#endif +} + +static void setcolor(WINDOW *win, chtype color) +{ + chtype attr = color & A_ATTR; /* extract Bold, Reverse, Blink bits */ + +#ifdef A_COLOR + attr &= ~A_REVERSE; /* ignore reverse, use colors instead! */ + wattrset(win, COLOR_PAIR(color & A_CHARTEXT) | attr); +#else + attr &= ~A_BOLD; /* ignore bold, gives messy display on HP-UX */ + wattrset(win, attr); +#endif +} + +static void colorbox(WINDOW *win, chtype color, int hasbox) +{ + int maxy; +#ifndef PDCURSES + int maxx; +#endif + chtype attr = color & A_ATTR; /* extract Bold, Reverse, Blink bits */ + + setcolor(win, color); + +#ifdef A_COLOR + if (has_colors()) + wbkgd(win, COLOR_PAIR(color & A_CHARTEXT) | (attr & ~A_REVERSE)); + else +#endif + wbkgd(win, attr); + + werase(win); + +#ifdef PDCURSES + maxy = getmaxy(win); +#else + getmaxyx(win, maxy, maxx); +#endif + if (hasbox && (maxy > 2)) + box(win, 0, 0); + + touchwin(win); + wrefresh(win); +} + +static void idle(void) +{ + char buf[MAXSTRLEN]; + time_t t; + struct tm *tp; + + if (time (&t) == -1) + return; /* time not available */ + + tp = localtime(&t); + sprintf(buf, " %.2d-%.2d-%.4d %.2d:%.2d:%.2d", + tp->tm_mday, tp->tm_mon + 1, tp->tm_year + 1900, + tp->tm_hour, tp->tm_min, tp->tm_sec); + + mvwaddstr(wtitl, 0, bw - strlen(buf) - 2, buf); + wrefresh(wtitl); +} + +static void menudim(menu *mp, int *lines, int *columns) +{ + int n, l, mmax = 0; + + for (n = 0; mp->func; n++, mp++) + if ((l = strlen(mp->name)) > mmax) mmax = l; + + *lines = n; + *columns = mmax + 2; +} + +static void setmenupos(int y, int x) +{ + nexty = y; + nextx = x; +} + +static void getmenupos(int *y, int *x) +{ + *y = nexty; + *x = nextx; +} + +static int hotkey(const char *s) +{ + int c0 = *s; /* if no upper case found, return first char */ + + for (; *s; s++) + if (isupper((unsigned char)*s)) + break; + + return *s ? *s : c0; +} + +static void repaintmenu(WINDOW *wmenu, menu *mp) +{ + int i; + menu *p = mp; + + for (i = 0; p->func; i++, p++) + mvwaddstr(wmenu, i + 1, 2, p->name); + + touchwin(wmenu); + wrefresh(wmenu); +} + +static void repaintmainmenu(int width, menu *mp) +{ + int i; + menu *p = mp; + + for (i = 0; p->func; i++, p++) + mvwaddstr(wmain, 0, i * width, prepad(padstr(p->name, width - 1), 1)); + + touchwin(wmain); + wrefresh(wmain); +} + +static void mainhelp(void) +{ +#ifdef ALT_X + statusmsg("Use arrow keys and Enter to select (Alt-X to quit)"); +#else + statusmsg("Use arrow keys and Enter to select"); +#endif +} + +static void mainmenu(menu *mp) +{ + int nitems, barlen, old = -1, cur = 0, c, cur0; + + menudim(mp, &nitems, &barlen); + repaintmainmenu(barlen, mp); + + while (!quit) + { + if (cur != old) + { + if (old != -1) + { + mvwaddstr(wmain, 0, old * barlen, + prepad(padstr(mp[old].name, barlen - 1), 1)); + + statusmsg(mp[cur].desc); + } + else + mainhelp(); + + setcolor(wmain, MAINMENUREVCOLOR); + + mvwaddstr(wmain, 0, cur * barlen, + prepad(padstr(mp[cur].name, barlen - 1), 1)); + + setcolor(wmain, MAINMENUCOLOR); + old = cur; + wrefresh(wmain); + } + + switch (c = (key != ERR ? key : waitforkey())) + { + case KEY_DOWN: + case '\n': /* menu item selected */ + touchwin(wbody); + wrefresh(wbody); + rmerror(); + setmenupos(th + mh, cur * barlen); + curs_set(1); + (mp[cur].func)(); /* perform function */ + curs_set(0); + + switch (key) + { + case KEY_LEFT: + cur = (cur + nitems - 1) % nitems; + key = '\n'; + break; + + case KEY_RIGHT: + cur = (cur + 1) % nitems; + key = '\n'; + break; + + default: + key = ERR; + } + + repaintmainmenu(barlen, mp); + old = -1; + break; + + case KEY_LEFT: + cur = (cur + nitems - 1) % nitems; + break; + + case KEY_RIGHT: + cur = (cur + 1) % nitems; + break; + + case KEY_ESC: + mainhelp(); + break; + + default: + cur0 = cur; + + do + { + cur = (cur + 1) % nitems; + + } while ((cur != cur0) && (hotkey(mp[cur].name) != toupper(c))); + + if (hotkey(mp[cur].name) == toupper(c)) + key = '\n'; + } + + } + + rmerror(); + touchwin(wbody); + wrefresh(wbody); +} + +static void cleanup(void) /* cleanup curses settings */ +{ + if (incurses) + { + delwin(wtitl); + delwin(wmain); + delwin(wbody); + delwin(wstat); + curs_set(1); + endwin(); + incurses = FALSE; + } +} + + +/******************************* EXTERNAL **********************************/ + +void clsbody(void) +{ + werase(wbody); + wmove(wbody, 0, 0); +} + +int bodylen(void) +{ +#ifdef PDCURSES + return getmaxy(wbody); +#else + int maxy, maxx; + + getmaxyx(wbody, maxy, maxx); + return maxy; +#endif +} + +WINDOW *bodywin(void) +{ + return wbody; +} + +void rmerror(void) +{ + rmline(wstat, 0); +} + +void rmstatus(void) +{ + rmline(wstat, 1); +} + +void titlemsg(char *msg) +{ + mvwaddstr(wtitl, 0, 2, padstr(msg, bw - 3)); + wrefresh(wtitl); +} + +void bodymsg(char *msg) +{ + waddstr(wbody, msg); + wrefresh(wbody); +} + +void errormsg(char *msg) +{ + beep(); + mvwaddstr(wstat, 0, 2, padstr(msg, bw - 3)); + wrefresh(wstat); +} + +void statusmsg(char *msg) +{ + mvwaddstr(wstat, 1, 2, padstr(msg, bw - 3)); + wrefresh(wstat); +} + +bool keypressed(void) +{ + ch = wgetch(wbody); + + return ch != ERR; +} + +int getkey(void) +{ + int c = ch; + + ch = ERR; +#ifdef ALT_X + quit = (c == ALT_X); /* PC only ! */ +#endif + return c; +} + +int waitforkey(void) +{ + do idle(); while (!keypressed()); + return getkey(); +} + +void DoExit(void) /* terminate program */ +{ + quit = TRUE; +} + +void domenu(menu *mp) +{ + int y, x, nitems, barlen, mheight, mw, old = -1, cur = 0, cur0; + bool stop = FALSE; + WINDOW *wmenu; + + curs_set(0); + getmenupos(&y, &x); + menudim(mp, &nitems, &barlen); + mheight = nitems + 2; + mw = barlen + 2; + wmenu = newwin(mheight, mw, y, x); + colorbox(wmenu, SUBMENUCOLOR, 1); + repaintmenu(wmenu, mp); + + key = ERR; + + while (!stop && !quit) + { + if (cur != old) + { + if (old != -1) + mvwaddstr(wmenu, old + 1, 1, + prepad(padstr(mp[old].name, barlen - 1), 1)); + + setcolor(wmenu, SUBMENUREVCOLOR); + mvwaddstr(wmenu, cur + 1, 1, + prepad(padstr(mp[cur].name, barlen - 1), 1)); + + setcolor(wmenu, SUBMENUCOLOR); + statusmsg(mp[cur].desc); + + old = cur; + wrefresh(wmenu); + } + + switch (key = ((key != ERR) ? key : waitforkey())) + { + case '\n': /* menu item selected */ + touchwin(wbody); + wrefresh(wbody); + setmenupos(y + 1, x + 1); + rmerror(); + + key = ERR; + curs_set(1); + (mp[cur].func)(); /* perform function */ + curs_set(0); + + repaintmenu(wmenu, mp); + + old = -1; + break; + + case KEY_UP: + cur = (cur + nitems - 1) % nitems; + key = ERR; + break; + + case KEY_DOWN: + cur = (cur + 1) % nitems; + key = ERR; + break; + + case KEY_ESC: + case KEY_LEFT: + case KEY_RIGHT: + if (key == KEY_ESC) + key = ERR; /* return to prev submenu */ + + stop = TRUE; + break; + + default: + cur0 = cur; + + do + { + cur = (cur + 1) % nitems; + + } while ((cur != cur0) && + (hotkey(mp[cur].name) != toupper((int)key))); + + key = (hotkey(mp[cur].name) == toupper((int)key)) ? '\n' : ERR; + } + + } + + rmerror(); + delwin(wmenu); + touchwin(wbody); + wrefresh(wbody); +} + +void startmenu(menu *mp, char *mtitle) +{ + initscr(); + incurses = TRUE; + initcolor(); + + wtitl = subwin(stdscr, th, bw, 0, 0); + wmain = subwin(stdscr, mh, bw, th, 0); + wbody = subwin(stdscr, bh, bw, th + mh, 0); + wstat = subwin(stdscr, sh, bw, th + mh + bh, 0); + + colorbox(wtitl, TITLECOLOR, 0); + colorbox(wmain, MAINMENUCOLOR, 0); + colorbox(wbody, BODYCOLOR, 0); + colorbox(wstat, STATUSCOLOR, 0); + + if (mtitle) + titlemsg(mtitle); + + cbreak(); /* direct input (no newline required)... */ + noecho(); /* ... without echoing */ + curs_set(0); /* hide cursor (if possible) */ + nodelay(wbody, TRUE); /* don't wait for input... */ + halfdelay(10); /* ...well, no more than a second, anyway */ + keypad(wbody, TRUE); /* enable cursor keys */ + scrollok(wbody, TRUE); /* enable scrolling in main window */ + + leaveok(stdscr, TRUE); + leaveok(wtitl, TRUE); + leaveok(wmain, TRUE); + leaveok(wstat, TRUE); + + mainmenu(mp); + + cleanup(); +} + +static void repainteditbox(WINDOW *win, int x, char *buf) +{ +#ifndef PDCURSES + int maxy; +#endif + int maxx; + +#ifdef PDCURSES + maxx = getmaxx(win); +#else + getmaxyx(win, maxy, maxx); +#endif + werase(win); + mvwprintw(win, 0, 0, "%s", padstr(buf, maxx)); + wmove(win, 0, x); + wrefresh(win); +} + +/* + + weditstr() - edit string + + Description: + The initial value of 'str' with a maximum length of 'field' - 1, + which is supplied by the calling routine, is editted. The user's + erase (^H), kill (^U) and delete word (^W) chars are interpreted. + The PC insert or Tab keys toggle between insert and edit mode. + Escape aborts the edit session, leaving 'str' unchanged. + Enter, Up or Down Arrow are used to accept the changes to 'str'. + NOTE: editstr(), mveditstr(), and mvweditstr() are macros. + + Return Value: + Returns the input terminating character on success (Escape, + Enter, Up or Down Arrow) and ERR on error. + + Errors: + It is an error to call this function with a NULL window pointer. + The length of the initial 'str' must not exceed 'field' - 1. + +*/ + +int weditstr(WINDOW *win, char *buf, int field) +{ + char org[MAXSTRLEN], *tp, *bp = buf; + bool defdisp = TRUE, stop = FALSE, insert = FALSE; + int cury, curx, begy, begx; + chtype oldattr; + WINDOW *wedit; + int c = 0; + + if ((field >= MAXSTRLEN) || (buf == NULL) || + ((int)strlen(buf) > field - 1)) + return ERR; + + strcpy(org, buf); /* save original */ + + wrefresh(win); + getyx(win, cury, curx); + getbegyx(win, begy, begx); + + wedit = subwin(win, 1, field, begy + cury, begx + curx); + oldattr = getattrs(wedit); + colorbox(wedit, EDITBOXCOLOR, 0); + + keypad(wedit, TRUE); + curs_set(1); + + while (!stop) + { + idle(); + repainteditbox(wedit, bp - buf, buf); + + switch (c = wgetch(wedit)) + { + case ERR: + break; + + case KEY_ESC: + strcpy(buf, org); /* restore original */ + stop = TRUE; + break; + + case '\n': + case KEY_UP: + case KEY_DOWN: + stop = TRUE; + break; + + case KEY_LEFT: + if (bp > buf) + bp--; + break; + + case KEY_RIGHT: + defdisp = FALSE; + if (bp - buf < (int)strlen(buf)) + bp++; + break; + + case '\t': /* TAB -- because insert + is broken on HPUX */ + case KEY_IC: /* enter insert mode */ + case KEY_EIC: /* exit insert mode */ + defdisp = FALSE; + insert = !insert; + + curs_set(insert ? 2 : 1); + break; + + default: + if (c == erasechar()) /* backspace, ^H */ + { + if (bp > buf) + { + memmove((void *)(bp - 1), (const void *)bp, strlen(bp) + 1); + bp--; + } + } + else if (c == killchar()) /* ^U */ + { + bp = buf; + *bp = '\0'; + } + else if (c == wordchar()) /* ^W */ + { + tp = bp; + + while ((bp > buf) && (*(bp - 1) == ' ')) + bp--; + while ((bp > buf) && (*(bp - 1) != ' ')) + bp--; + + memmove((void *)bp, (const void *)tp, strlen(tp) + 1); + } + else if (isprint(c)) + { + if (defdisp) + { + bp = buf; + *bp = '\0'; + defdisp = FALSE; + } + + if (insert) + { + if ((int)strlen(buf) < field - 1) + { + memmove((void *)(bp + 1), (const void *)bp, + strlen(bp) + 1); + + *bp++ = c; + } + } + else if (bp - buf < field - 1) + { + /* append new string terminator */ + + if (!*bp) + bp[1] = '\0'; + + *bp++ = c; + } + } + } + } + + curs_set(0); + + wattrset(wedit, oldattr); + repainteditbox(wedit, bp - buf, buf); + delwin(wedit); + + return c; +} + +WINDOW *winputbox(WINDOW *win, int nlines, int ncols) +{ + WINDOW *winp; + int cury, curx, begy, begx; + + getyx(win, cury, curx); + getbegyx(win, begy, begx); + + winp = newwin(nlines, ncols, begy + cury, begx + curx); + colorbox(winp, INPUTBOXCOLOR, 1); + + return winp; +} + +int getstrings(char *desc[], char *buf[], int field) +{ + WINDOW *winput; + int oldy, oldx, maxy, maxx, nlines, ncols, i, n, l, mmax = 0; + int c = 0; + bool stop = FALSE; + + for (n = 0; desc[n]; n++) + if ((l = strlen(desc[n])) > mmax) + mmax = l; + + nlines = n + 2; ncols = mmax + field + 4; + getyx(wbody, oldy, oldx); + getmaxyx(wbody, maxy, maxx); + + winput = mvwinputbox(wbody, (maxy - nlines) / 2, (maxx - ncols) / 2, + nlines, ncols); + + for (i = 0; i < n; i++) + mvwprintw(winput, i + 1, 2, "%s", desc[i]); + + i = 0; + + while (!stop) + { + switch (c = mvweditstr(winput, i+1, mmax+3, buf[i], field)) + { + case KEY_ESC: + stop = TRUE; + break; + + case KEY_UP: + i = (i + n - 1) % n; + break; + + case '\n': + case '\t': + case KEY_DOWN: + if (++i == n) + stop = TRUE; /* all passed? */ + } + } + + delwin(winput); + touchwin(wbody); + wmove(wbody, oldy, oldx); + wrefresh(wbody); + + return c; +} diff --git a/modules/ncurses/pdcurses/demos/tui.h b/modules/ncurses/pdcurses/demos/tui.h new file mode 100644 index 00000000..a272c54c --- /dev/null +++ b/modules/ncurses/pdcurses/demos/tui.h @@ -0,0 +1,65 @@ +/* + * 'textual user interface' + * + * Author : P.J. Kunst + * Date : 25-02-93 + */ + +#ifndef _TUI_H_ +#define _TUI_H_ + +#include + +#ifdef A_COLOR +#define A_ATTR (A_ATTRIBUTES ^ A_COLOR) /* A_BLINK, A_REVERSE, A_BOLD */ +#else +#define A_ATTR (A_ATTRIBUTES) /* standard UNIX attributes */ +#endif + +#define MAXSTRLEN 256 +#define KEY_ESC 0x1b /* Escape */ + +typedef void (*FUNC)(void); + +typedef struct +{ + char *name; /* item label */ + FUNC func; /* (pointer to) function */ + char *desc; /* function description */ +} menu; + +/* ANSI C function prototypes: */ + +void clsbody(void); +int bodylen(void); +WINDOW *bodywin(void); + +void rmerror(void); +void rmstatus(void); + +void titlemsg(char *msg); +void bodymsg(char *msg); +void errormsg(char *msg); +void statusmsg(char *msg); + +bool keypressed(void); +int getkey(void); +int waitforkey(void); + +void DoExit(void); +void startmenu(menu *mp, char *title); +void domenu(menu *mp); + +int weditstr(WINDOW *win, char *buf, int field); +WINDOW *winputbox(WINDOW *win, int nlines, int ncols); +int getstrings(char *desc[], char *buf[], int field); + +#define editstr(s,f) (weditstr(stdscr,s,f)) +#define mveditstr(y,x,s,f) (move(y,x)==ERR?ERR:editstr(s,f)) +#define mvweditstr(w,y,x,s,f) (wmove(w,y,x)==ERR?ERR:weditstr(w,s,f)) + +#define inputbox(l,c) (winputbox(stdscr,l,c)) +#define mvinputbox(y,x,l,c) (move(y,x)==ERR?w:inputbox(l,c)) +#define mvwinputbox(w,y,x,l,c) (wmove(w,y,x)==ERR?w:winputbox(w,l,c)) + +#endif diff --git a/modules/ncurses/pdcurses/demos/tuidemo.c b/modules/ncurses/pdcurses/demos/tuidemo.c new file mode 100644 index 00000000..8e7607f0 --- /dev/null +++ b/modules/ncurses/pdcurses/demos/tuidemo.c @@ -0,0 +1,228 @@ +/* + * Author : P.J. Kunst + * Date : 25-02-93 + * + * Purpose: This program demonstrates the use of the 'curses' library + * for the creation of (simple) menu-operated programs. + * In the PDCurses version, use is made of colors for the + * highlighting of subwindows (title bar, status bar etc). + * + * Acknowledgement: some ideas were borrowed from Mark Hessling's + * version of the 'testcurs' program. + */ + +#include +#include +#include +#include +#include "tui.h" + +/* change this if source at other location */ + +#ifdef XCURSES +# define FNAME "../demos/tui.c" +#else +# define FNAME "..\\demos\\tui.c" +#endif + +/**************************** strings entry box ***************************/ + +void address(void) +{ + char *fieldname[6] = + { + "Name", "Street", "City", "State", "Country", (char *)0 + }; + + char *fieldbuf[5]; + WINDOW *wbody = bodywin(); + int i, field = 50; + + for (i = 0; i < 5; i++) + fieldbuf[i] = calloc(1, field + 1); + + if (getstrings(fieldname, fieldbuf, field) != KEY_ESC) + { + for (i = 0; fieldname[i]; i++) + wprintw(wbody, "%10s : %s\n", + fieldname[i], fieldbuf[i]); + + wrefresh(wbody); + } + + for (i = 0; i < 5; i++) + free(fieldbuf[i]); +} + +/**************************** string entry box ****************************/ + +char *getfname(char *desc, char *fname, int field) +{ + char *fieldname[2]; + char *fieldbuf[1]; + + fieldname[0] = desc; + fieldname[1] = 0; + fieldbuf[0] = fname; + + return (getstrings(fieldname, fieldbuf, field) == KEY_ESC) ? NULL : fname; +} + +/**************************** a very simple file browser ******************/ + +void showfile(char *fname) +{ + int i, bh = bodylen(); + FILE *fp; + char buf[MAXSTRLEN]; + bool ateof = FALSE; + + statusmsg("FileBrowser: Hit key to continue, Q to quit"); + + if ((fp = fopen(fname, "r")) != NULL) /* file available? */ + { + while (!ateof) + { + clsbody(); + + for (i = 0; i < bh - 1 && !ateof; i++) + { + if (fgets(buf, MAXSTRLEN, fp)) + bodymsg(buf); + else + ateof = TRUE; + } + + switch (waitforkey()) + { + case 'Q': + case 'q': + case 0x1b: + ateof = TRUE; + } + } + + fclose(fp); + } + else + { + sprintf(buf, "ERROR: file '%s' not found", fname); + errormsg(buf); + } +} + +/***************************** forward declarations ***********************/ + +void sub0(void), sub1(void), sub2(void), sub3(void); +void func1(void), func2(void); +void subfunc1(void), subfunc2(void); +void subsub(void); + +/***************************** menus initialization ***********************/ + +menu MainMenu[] = +{ + { "Asub", sub0, "Go inside first submenu" }, + { "Bsub", sub1, "Go inside second submenu" }, + { "Csub", sub2, "Go inside third submenu" }, + { "Dsub", sub3, "Go inside fourth submenu" }, + { "", (FUNC)0, "" } /* always add this as the last item! */ +}; + +menu SubMenu0[] = +{ + { "Exit", DoExit, "Terminate program" }, + { "", (FUNC)0, "" } +}; + +menu SubMenu1[] = +{ + { "OneBeep", func1, "Sound one beep" }, + { "TwoBeeps", func2, "Sound two beeps" }, + { "", (FUNC)0, "" } +}; + +menu SubMenu2[] = +{ + { "Browse", subfunc1, "Source file lister" }, + { "Input", subfunc2, "Interactive file lister" }, + { "Address", address, "Get address data" }, + { "", (FUNC)0, "" } +}; + +menu SubMenu3[] = +{ + { "SubSub", subsub, "Go inside sub-submenu" }, + { "", (FUNC)0, "" } +}; + +/***************************** main menu functions ************************/ + +void sub0(void) +{ + domenu(SubMenu0); +} + +void sub1(void) +{ + domenu(SubMenu1); +} + +void sub2(void) +{ + domenu(SubMenu2); +} + +void sub3(void) +{ + domenu(SubMenu3); +} + +/***************************** submenu1 functions *************************/ + +void func1(void) +{ + beep(); + bodymsg("One beep! "); +} + +void func2(void) +{ + beep(); + bodymsg("Two beeps! "); + beep(); +} + +/***************************** submenu2 functions *************************/ + +void subfunc1(void) +{ + showfile(FNAME); +} + +void subfunc2(void) +{ + char fname[MAXSTRLEN]; + + strcpy(fname, FNAME); + if (getfname ("File to browse:", fname, 50)) + showfile(fname); +} + +/***************************** submenu3 functions *************************/ + +void subsub(void) +{ + domenu(SubMenu2); +} + +/***************************** start main menu ***************************/ + +int main(int argc, char **argv) +{ + setlocale(LC_ALL, ""); + + startmenu(MainMenu, "TUI - 'textual user interface' demonstration program"); + + return 0; +} diff --git a/modules/ncurses/pdcurses/demos/worm.c b/modules/ncurses/pdcurses/demos/worm.c new file mode 100644 index 00000000..3eca3459 --- /dev/null +++ b/modules/ncurses/pdcurses/demos/worm.c @@ -0,0 +1,433 @@ +/**************************************************************************** + * Copyright (c) 2005 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/* + + @@@ @@@ @@@@@@@@@@ @@@@@@@@@@@ @@@@@@@@@@@@ + @@@ @@@ @@@@@@@@@@@@ @@@@@@@@@@@@ @@@@@@@@@@@@@ + @@@ @@@ @@@@ @@@@ @@@@ @@@@ @@@ @@@@ + @@@ @@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ + @@@ @@@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ + @@@@ @@@@ @@@@ @@@ @@@ @@@ @@@ @@@ @@@ + @@@@@@@@@@@@ @@@@ @@@@ @@@ @@@ @@@ @@@ + @@@@ @@@@ @@@@@@@@@@@@ @@@ @@@ @@@ @@@ + @@ @@ @@@@@@@@@@ @@@ @@@ @@@ @@@ + + Eric P. Scott + Caltech High Energy Physics + October, 1980 + + Color by Eric S. Raymond + July, 1995 + +Options: + -f fill screen with copies of 'WORM' at start. + -l set worm length + -n set number of worms + -t make worms leave droppings +*/ + +#include +#include +#include + +#define FLAVORS 7 + +static chtype flavor[FLAVORS] = +{ + 'O', '*', '#', '$', '%', '0', '@' +}; + +static const short xinc[] = +{ + 1, 1, 1, 0, -1, -1, -1, 0 +}, +yinc[] = +{ + -1, 0, 1, 1, 1, 0, -1, -1 +}; + +static struct worm +{ + int orientation, head; + short *xpos, *ypos; +} worm[40]; + +static const char *field; +static int length = 16, number = 3; +static chtype trail = ' '; + +static const struct options +{ + int nopts; + int opts[3]; +} normal[8] = +{ + { 3, { 7, 0, 1 } }, { 3, { 0, 1, 2 } }, { 3, { 1, 2, 3 } }, + { 3, { 2, 3, 4 } }, { 3, { 3, 4, 5 } }, { 3, { 4, 5, 6 } }, + { 3, { 5, 6, 7 } }, { 3, { 6, 7, 0 } } +}, +upper[8] = +{ + { 1, { 1, 0, 0 } }, { 2, { 1, 2, 0 } }, { 0, { 0, 0, 0 } }, + { 0, { 0, 0, 0 } }, { 0, { 0, 0, 0 } }, { 2, { 4, 5, 0 } }, + { 1, { 5, 0, 0 } }, { 2, { 1, 5, 0 } } +}, +left[8] = +{ + { 0, { 0, 0, 0 } }, { 0, { 0, 0, 0 } }, { 0, { 0, 0, 0 } }, + { 2, { 2, 3, 0 } }, { 1, { 3, 0, 0 } }, { 2, { 3, 7, 0 } }, + { 1, { 7, 0, 0 } }, { 2, { 7, 0, 0 } } +}, +right[8] = +{ + { 1, { 7, 0, 0 } }, { 2, { 3, 7, 0 } }, { 1, { 3, 0, 0 } }, + { 2, { 3, 4, 0 } }, { 0, { 0, 0, 0 } }, { 0, { 0, 0, 0 } }, + { 0, { 0, 0, 0 } }, { 2, { 6, 7, 0 } } +}, +lower[8] = +{ + { 0, { 0, 0, 0 } }, { 2, { 0, 1, 0 } }, { 1, { 1, 0, 0 } }, + { 2, { 1, 5, 0 } }, { 1, { 5, 0, 0 } }, { 2, { 5, 6, 0 } }, + { 0, { 0, 0, 0 } }, { 0, { 0, 0, 0 } } +}, +upleft[8] = +{ + { 0, { 0, 0, 0 } }, { 0, { 0, 0, 0 } }, { 0, { 0, 0, 0 } }, + { 0, { 0, 0, 0 } }, { 0, { 0, 0, 0 } }, { 1, { 3, 0, 0 } }, + { 2, { 1, 3, 0 } }, { 1, { 1, 0, 0 } } +}, +upright[8] = +{ + { 2, { 3, 5, 0 } }, { 1, { 3, 0, 0 } }, { 0, { 0, 0, 0 } }, + { 0, { 0, 0, 0 } }, { 0, { 0, 0, 0 } }, { 0, { 0, 0, 0 } }, + { 0, { 0, 0, 0 } }, { 1, { 5, 0, 0 } } +}, +lowleft[8] = +{ + { 3, { 7, 0, 1 } }, { 0, { 0, 0, 0 } }, { 0, { 0, 0, 0 } }, + { 1, { 1, 0, 0 } }, { 2, { 1, 7, 0 } }, { 1, { 7, 0, 0 } }, + { 0, { 0, 0, 0 } }, { 0, { 0, 0, 0 } } +}, +lowright[8] = +{ + { 0, { 0, 0, 0 } }, { 1, { 7, 0, 0 } }, { 2, { 5, 7, 0 } }, + { 1, { 5, 0, 0 } }, { 0, { 0, 0, 0 } }, { 0, { 0, 0, 0 } }, + { 0, { 0, 0, 0 } }, { 0, { 0, 0, 0 } } +}; + +static void cleanup(void) +{ + standend(); + refresh(); + curs_set(1); + endwin(); +} + +int main(int argc, char *argv[]) +{ + const struct options *op; + struct worm *w; + short **ref, *ip; + time_t seed; + int x, y, n, h, last, bottom; + + for (x = 1; x < argc; x++) + { + char *p = argv[x]; + + if (*p == '-') + p++; + + switch (*p) + { + case 'f': + field = "WORM"; + break; + case 'l': + if (++x == argc) + goto usage; + + if ((length = atoi(argv[x])) < 2 || length > 1024) + { + fprintf(stderr, "%s: Invalid length\n", *argv); + return EXIT_FAILURE; + } + + break; + case 'n': + if (++x == argc) + goto usage; + + if ((number = atoi(argv[x])) < 1 || number > 40) + { + fprintf(stderr, "%s: Invalid number of worms\n", *argv); + return EXIT_FAILURE; + } + + break; + case 't': + trail = '.'; + break; + default: + usage: + fprintf(stderr, "usage: %s [-field] [-length #] " + "[-number #] [-trail]\n", *argv); + return EXIT_FAILURE; + } + } + +#ifdef XCURSES + Xinitscr(argc, argv); +#else + initscr(); +#endif + seed = time((time_t *)0); + srand(seed); + + noecho(); + cbreak(); + nonl(); + keypad(stdscr, TRUE); + + curs_set(0); + + bottom = LINES - 1; + last = COLS - 1; + +#ifdef A_COLOR + if (has_colors()) + { + short bg = COLOR_BLACK; + start_color(); + +# if defined(NCURSES_VERSION) || (defined(PDC_BUILD) && PDC_BUILD > 3000) + if (use_default_colors() == OK) + bg = -1; +# endif + +# define SET_COLOR(num, fg) \ + init_pair(num + 1, fg, bg); \ + flavor[num] |= COLOR_PAIR(num + 1) | A_BOLD + + SET_COLOR(0, COLOR_GREEN); + SET_COLOR(1, COLOR_RED); + SET_COLOR(2, COLOR_CYAN); + SET_COLOR(3, COLOR_WHITE); + SET_COLOR(4, COLOR_MAGENTA); + SET_COLOR(5, COLOR_BLUE); + SET_COLOR(6, COLOR_YELLOW); + } +#endif + + ref = malloc(sizeof(short *) * LINES); + + for (y = 0; y < LINES; y++) + { + ref[y] = malloc(sizeof(short) * COLS); + + for (x = 0; x < COLS; x++) + ref[y][x] = 0; + } + +#ifdef BADCORNER + /* if addressing the lower right corner doesn't work in your curses */ + + ref[bottom][last] = 1; +#endif + + for (n = number, w = &worm[0]; --n >= 0; w++) + { + w->orientation = w->head = 0; + + if ((ip = malloc(sizeof(short) * (length + 1))) == NULL) + { + fprintf(stderr, "%s: out of memory\n", *argv); + return EXIT_FAILURE; + } + + w->xpos = ip; + + for (x = length; --x >= 0;) + *ip++ = -1; + + if ((ip = malloc(sizeof(short) * (length + 1))) == NULL) + { + fprintf(stderr, "%s: out of memory\n", *argv); + return EXIT_FAILURE; + } + + w->ypos = ip; + + for (y = length; --y >= 0;) + *ip++ = -1; + } + + if (field) + { + const char *p = field; + + for (y = bottom; --y >= 0;) + for (x = COLS; --x >= 0;) + { + addch((chtype) (*p++)); + + if (!*p) + p = field; + } + } + + napms(12); + refresh(); + nodelay(stdscr, TRUE); + + for (;;) + { + int ch; + + if ((ch = getch()) > 0) + { +#ifdef KEY_RESIZE + if (ch == KEY_RESIZE) + { +# ifdef PDCURSES + resize_term(0, 0); + erase(); +# endif + if (last != COLS - 1) + { + for (y = 0; y <= bottom; y++) + { + ref[y] = realloc(ref[y], sizeof(short) * COLS); + + for (x = last + 1; x < COLS; x++) + ref[y][x] = 0; + } + + last = COLS - 1; + } + + if (bottom != LINES - 1) + { + for (y = LINES; y <= bottom; y++) + free(ref[y]); + + ref = realloc(ref, sizeof(short *) * LINES); + + for (y = bottom + 1; y < LINES; y++) + { + ref[y] = malloc(sizeof(short) * COLS); + + for (x = 0; x < COLS; x++) + ref[y][x] = 0; + } + + bottom = LINES - 1; + } + } + +#endif /* KEY_RESIZE */ + + /* Make it simple to put this into single-step mode, + or resume normal operation - T. Dickey */ + + if (ch == 'q') + { + cleanup(); + return EXIT_SUCCESS; + } + else if (ch == 's') + nodelay(stdscr, FALSE); + else if (ch == ' ') + nodelay(stdscr, TRUE); + } + + for (n = 0, w = &worm[0]; n < number; n++, w++) + { + if ((x = w->xpos[h = w->head]) < 0) + { + move(y = w->ypos[h] = bottom, x = w->xpos[h] = 0); + addch(flavor[n % FLAVORS]); + ref[y][x]++; + } + else + y = w->ypos[h]; + + if (x > last) + x = last; + + if (y > bottom) + y = bottom; + + if (++h == length) + h = 0; + + if (w->xpos[w->head = h] >= 0) + { + int x1 = w->xpos[h]; + int y1 = w->ypos[h]; + + if (y1 < LINES && x1 < COLS && --ref[y1][x1] == 0) + { + move(y1, x1); + addch(trail); + } + } + + op = &(x == 0 ? (y == 0 ? upleft : + (y == bottom ? lowleft : left)) : + (x == last ? (y == 0 ? upright : + (y == bottom ? lowright : right)) : + (y == 0 ? upper : + (y == bottom ? lower : normal)))) + [w->orientation]; + + switch (op->nopts) + { + case 0: + cleanup(); + return EXIT_SUCCESS; + case 1: + w->orientation = op->opts[0]; + break; + default: + w->orientation = op->opts[rand() % op->nopts]; + } + + move(y += yinc[w->orientation], x += xinc[w->orientation]); + + if (y < 0) + y = 0; + + addch(flavor[n % FLAVORS]); + ref[w->ypos[h] = y][w->xpos[h] = x]++; + } + napms(12); + refresh(); + } +} diff --git a/modules/ncurses/pdcurses/demos/xmas.c b/modules/ncurses/pdcurses/demos/xmas.c new file mode 100644 index 00000000..62b4842a --- /dev/null +++ b/modules/ncurses/pdcurses/demos/xmas.c @@ -0,0 +1,955 @@ +/******************************************************************************/ +/* asciixmas */ +/* December 1989 Larry Bartz Indianapolis, IN */ +/* */ +/* */ +/* I'm dreaming of an ascii character-based monochrome Christmas, */ +/* Just like the one's I used to know! */ +/* Via a full duplex communications channel, */ +/* At 9600 bits per second, */ +/* Even though it's kinda slow. */ +/* */ +/* I'm dreaming of an ascii character-based monochrome Christmas, */ +/* With ev'ry C program I write! */ +/* May your screen be merry and bright! */ +/* And may all your Christmases be amber or green, */ +/* (for reduced eyestrain and improved visibility)! */ +/* */ +/* */ +/* */ +/* IMPLEMENTATION */ +/* */ +/* Feel free to modify the defined string FROMWHO to reflect you, your */ +/* organization, your site, whatever. */ +/* */ +/* This looks a lot better if you can turn off your cursor before execution. */ +/* The cursor is distracting but it doesn't really ruin the show. */ +/* */ +/* At our site, we invoke this for our users just after login and the */ +/* determination of terminal type. */ +/* */ +/* */ +/* PORTABILITY */ +/* */ +/* I wrote this using only the very simplest curses functions so that it */ +/* might be the most portable. I was personally able to test on five */ +/* different cpu/UNIX combinations. */ +/* */ +/* */ +/* COMPILE */ +/* */ +/* usually this: */ +/* */ +/* cc -O xmas.c -lcurses -o xmas -s */ +/* */ +/******************************************************************************/ + +#include +#include + +void lil(WINDOW *); +void midtop(WINDOW *); +void bigtop(WINDOW *); +void bigface(WINDOW *, chtype); +void legs1(WINDOW *); +void legs2(WINDOW *); +void legs3(WINDOW *); +void legs4(WINDOW *); +void initdeer(void); +void boxit(void); +void seas(void); +void greet(void); +void fromwho(void); +void del_msg(void); +void tree(void); +void balls(void); +void star(void); +void strng1(void); +void strng2(void); +void strng3(void); +void strng4(void); +void strng5(void); +void blinkit(void); +void reindeer(void); + +#define FROMWHO "From Larry Bartz, Mark Hessling and William McBrine" + +int y_pos, x_pos; + +WINDOW *treescrn, *treescrn2, *treescrn3, *treescrn4, *treescrn5, + *treescrn6, *treescrn7, *treescrn8, *dotdeer0, *stardeer0, + *lildeer0, *lildeer1, *lildeer2, *lildeer3, *middeer0, + *middeer1, *middeer2, *middeer3, *bigdeer0, *bigdeer1, + *bigdeer2, *bigdeer3, *bigdeer4, *lookdeer0, *lookdeer1, + *lookdeer2, *lookdeer3, *lookdeer4, *w_holiday, *w_del_msg; + +int main(int argc, char **argv) +{ + int loopy; + +#ifdef XCURSES + Xinitscr(argc, argv); +#else + initscr(); +#endif + nodelay(stdscr, TRUE); + noecho(); + nonl(); + refresh(); + +#ifdef A_COLOR + if (has_colors()) + start_color(); +#endif + curs_set(0); + + treescrn = newwin(16, 27, 3, 53); + treescrn2 = newwin(16, 27, 3, 53); + treescrn3 = newwin(16, 27, 3, 53); + treescrn4 = newwin(16, 27, 3, 53); + treescrn5 = newwin(16, 27, 3, 53); + treescrn6 = newwin(16, 27, 3, 53); + treescrn7 = newwin(16, 27, 3, 53); + treescrn8 = newwin(16, 27, 3, 53); + + w_holiday = newwin(1, 26, 3, 27); + + w_del_msg = newwin(1, 12, 23, 60); + + mvwaddstr(w_holiday, 0, 0, "H A P P Y H O L I D A Y S"); + + initdeer(); + + clear(); + werase(treescrn); + touchwin(treescrn); + werase(treescrn2); + touchwin(treescrn2); + werase(treescrn8); + touchwin(treescrn8); + refresh(); + napms(1000); + + boxit(); + del_msg(); + napms(1000); + + seas(); + del_msg(); + napms(1000); + + greet(); + del_msg(); + napms(1000); + + fromwho(); + del_msg(); + napms(1000); + + tree(); + napms(1000); + + balls(); + napms(1000); + + star(); + napms(1000); + + strng1(); + strng2(); + strng3(); + strng4(); + strng5(); + + /* set up the windows for our blinking trees */ + /* **************************************** */ + /* treescrn3 */ + + overlay(treescrn, treescrn3); + + /* balls */ + mvwaddch(treescrn3, 4, 18, ' '); + mvwaddch(treescrn3, 7, 6, ' '); + mvwaddch(treescrn3, 8, 19, ' '); + mvwaddch(treescrn3, 11, 22, ' '); + + /* star */ + mvwaddch(treescrn3, 0, 12, '*'); + + /* strng1 */ + mvwaddch(treescrn3, 3, 11, ' '); + + /* strng2 */ + mvwaddch(treescrn3, 5, 13, ' '); + mvwaddch(treescrn3, 6, 10, ' '); + + /* strng3 */ + mvwaddch(treescrn3, 7, 16, ' '); + mvwaddch(treescrn3, 7, 14, ' '); + + /* strng4 */ + mvwaddch(treescrn3, 10, 13, ' '); + mvwaddch(treescrn3, 10, 10, ' '); + mvwaddch(treescrn3, 11, 8, ' '); + + /* strng5 */ + mvwaddch(treescrn3, 11, 18, ' '); + mvwaddch(treescrn3, 12, 13, ' '); + + /* treescrn4 */ + + overlay(treescrn, treescrn4); + + /* balls */ + mvwaddch(treescrn4, 3, 9, ' '); + mvwaddch(treescrn4, 4, 16, ' '); + mvwaddch(treescrn4, 7, 6, ' '); + mvwaddch(treescrn4, 8, 19, ' '); + mvwaddch(treescrn4, 11, 2, ' '); + mvwaddch(treescrn4, 12, 23, ' '); + + /* star */ + mvwaddch(treescrn4, 0, 12, '*' | A_STANDOUT); + + /* strng1 */ + mvwaddch(treescrn4, 3, 13, ' '); + + /* strng2 */ + + /* strng3 */ + mvwaddch(treescrn4, 7, 15, ' '); + mvwaddch(treescrn4, 8, 11, ' '); + + /* strng4 */ + mvwaddch(treescrn4, 9, 16, ' '); + mvwaddch(treescrn4, 10, 12, ' '); + mvwaddch(treescrn4, 11, 8, ' '); + + /* strng5 */ + mvwaddch(treescrn4, 11, 18, ' '); + mvwaddch(treescrn4, 12, 14, ' '); + + /* treescrn5 */ + + overlay(treescrn, treescrn5); + + /* balls */ + mvwaddch(treescrn5, 3, 15, ' '); + mvwaddch(treescrn5, 10, 20, ' '); + mvwaddch(treescrn5, 12, 1, ' '); + + /* star */ + mvwaddch(treescrn5, 0, 12, '*'); + + /* strng1 */ + mvwaddch(treescrn5, 3, 11, ' '); + + /* strng2 */ + mvwaddch(treescrn5, 5, 12, ' '); + + /* strng3 */ + mvwaddch(treescrn5, 7, 14, ' '); + mvwaddch(treescrn5, 8, 10, ' '); + + /* strng4 */ + mvwaddch(treescrn5, 9, 15, ' '); + mvwaddch(treescrn5, 10, 11, ' '); + mvwaddch(treescrn5, 11, 7, ' '); + + /* strng5 */ + mvwaddch(treescrn5, 11, 17, ' '); + mvwaddch(treescrn5, 12, 13, ' '); + + /* treescrn6 */ + + overlay(treescrn, treescrn6); + + /* balls */ + mvwaddch(treescrn6, 6, 7, ' '); + mvwaddch(treescrn6, 7, 18, ' '); + mvwaddch(treescrn6, 10, 4, ' '); + mvwaddch(treescrn6, 11, 23, ' '); + + /* star */ + mvwaddch(treescrn6, 0, 12, '*' | A_STANDOUT); + + /* strng1 */ + + /* strng2 */ + mvwaddch(treescrn6, 5, 11, ' '); + + /* strng3 */ + mvwaddch(treescrn6, 7, 13, ' '); + mvwaddch(treescrn6, 8, 9, ' '); + + /* strng4 */ + mvwaddch(treescrn6, 9, 14, ' '); + mvwaddch(treescrn6, 10, 10, ' '); + mvwaddch(treescrn6, 11, 6, ' '); + + /* strng5 */ + mvwaddch(treescrn6, 11, 16, ' '); + mvwaddch(treescrn6, 12, 12, ' '); + + /* treescrn7 */ + + overlay(treescrn, treescrn7); + + /* balls */ + mvwaddch(treescrn7, 3, 15, ' '); + mvwaddch(treescrn7, 6, 7, ' '); + mvwaddch(treescrn7, 7, 18, ' '); + mvwaddch(treescrn7, 10, 4, ' '); + mvwaddch(treescrn7, 11, 22, ' '); + + /* star */ + mvwaddch(treescrn7, 0, 12, '*'); + + /* strng1 */ + mvwaddch(treescrn7, 3, 12, ' '); + + /* strng2 */ + mvwaddch(treescrn7, 5, 13, ' '); + mvwaddch(treescrn7, 6, 9, ' '); + + /* strng3 */ + mvwaddch(treescrn7, 7, 15, ' '); + mvwaddch(treescrn7, 8, 11, ' '); + + /* strng4 */ + mvwaddch(treescrn7, 9, 16, ' '); + mvwaddch(treescrn7, 10, 12, ' '); + mvwaddch(treescrn7, 11, 8, ' '); + + /* strng5 */ + mvwaddch(treescrn7, 11, 18, ' '); + mvwaddch(treescrn7, 12, 14, ' '); + + napms(1000); + reindeer(); + + touchwin(w_holiday); + wrefresh(w_holiday); + wrefresh(w_del_msg); + + napms(1000); + + for (loopy = 0; loopy < 50; loopy++) + blinkit(); + + clear(); + refresh(); + endwin(); + + return 0; +} + +void lil(WINDOW *win) +{ + mvwaddch(win, 0, 0, (chtype) 'V'); + mvwaddch(win, 1, 0, (chtype) '@'); + mvwaddch(win, 1, 3, (chtype) '~'); +} + +void midtop(WINDOW *win) +{ + mvwaddstr(win, 0, 2, "yy"); + mvwaddstr(win, 1, 2, "0(=)~"); +} + +void bigtop(WINDOW *win) +{ + mvwaddstr(win, 0, 17, "\\/"); + mvwaddstr(win, 0, 20, "\\/"); + mvwaddch(win, 1, 18, (chtype) '\\'); + mvwaddch(win, 1, 20, (chtype) '/'); + mvwaddstr(win, 2, 19, "|_"); + mvwaddstr(win, 3, 18, "/^0\\"); + mvwaddstr(win, 4, 17, "//\\"); + mvwaddch(win, 4, 22, (chtype) '\\'); + mvwaddstr(win, 5, 7, "^~~~~~~~~// ~~U"); +} + +void bigface(WINDOW *win, chtype noseattr) +{ + mvwaddstr(win, 0, 16, "\\/ \\/"); + mvwaddstr(win, 1, 17, "\\Y/ \\Y/"); + mvwaddstr(win, 2, 19, "\\=/"); + mvwaddstr(win, 3, 17, "^\\o o/^"); + mvwaddstr(win, 4, 17, "//( )"); + mvwaddstr(win, 5, 7, "^~~~~~~~~// \\"); + waddch(win, 'O' | noseattr); + waddstr(win, "/"); +} + +void legs1(WINDOW *win) +{ + mvwaddstr(win, 6, 7, "( \\_____( /"); + mvwaddstr(win, 7, 8, "( ) /"); + mvwaddstr(win, 8, 9, "\\\\ /"); + mvwaddstr(win, 9, 11, "\\>/>"); +} + +void legs2(WINDOW *win) +{ + mvwaddstr(win, 6, 7, "(( )____( /"); + mvwaddstr(win, 7, 7, "( / |"); + mvwaddstr(win, 8, 8, "\\/ |"); + mvwaddstr(win, 9, 9, "|> |>"); +} + +void legs3(WINDOW *win) +{ + mvwaddstr(win, 6, 6, "( ()_____( /"); + mvwaddstr(win, 7, 6, "/ / /"); + mvwaddstr(win, 8, 5, "|/ \\"); + mvwaddstr(win, 9, 5, "/> \\>"); +} + +void legs4(WINDOW *win) +{ + mvwaddstr(win, 6, 6, "( )______( /"); + mvwaddstr(win, 7, 5, "(/ \\"); + mvwaddstr(win, 8, 0, "v___= ----^"); +} + +void initdeer(void) +{ + chtype noseattr; + +#ifdef A_COLOR + if (has_colors()) + { + init_pair(31, COLOR_RED, COLOR_BLACK); + noseattr = COLOR_PAIR(31); + } + else +#endif + noseattr = A_NORMAL; + + /* set up the windows for our various reindeer */ + + dotdeer0 = newwin(3, 71, 0, 8); + stardeer0 = newwin(4, 56, 0, 8); + lildeer0 = newwin(7, 54, 0, 8); + middeer0 = newwin(15, 42, 0, 8); + bigdeer0 = newwin(10, 23, 0, 0); + lookdeer0 = newwin(10, 25, 0, 0); + + /* lildeer1 */ + lildeer1 = newwin(2, 4, 0, 0); + lil(lildeer1); + mvwaddstr(lildeer1, 1, 1, "<>"); + + /* lildeer2 */ + lildeer2 = newwin(2, 4, 0, 0); + lil(lildeer2); + mvwaddstr(lildeer2, 1, 1, "||"); + + /* lildeer3 */ + lildeer3 = newwin(2, 4, 0, 0); + lil(lildeer3); + mvwaddstr(lildeer3, 1, 1, "><"); + + /* middeer1 */ + middeer1 = newwin(3, 7, 0, 0); + midtop(middeer1); + mvwaddstr(middeer1, 2, 3, "\\/"); + + /* middeer2 */ + middeer2 = newwin(3, 7, 0, 0); + midtop(middeer2); + mvwaddch(middeer2, 2, 3, (chtype) '|'); + mvwaddch(middeer2, 2, 5, (chtype) '|'); + + /* middeer3 */ + middeer3 = newwin(3, 7, 0, 0); + midtop(middeer3); + mvwaddch(middeer3, 2, 2, (chtype) '/'); + mvwaddch(middeer3, 2, 6, (chtype) '\\'); + + /* bigdeer1 */ + bigdeer1 = newwin(10, 23, 0, 0); + bigtop(bigdeer1); + legs1(bigdeer1); + + /* bigdeer2 */ + bigdeer2 = newwin(10, 23, 0, 0); + bigtop(bigdeer2); + legs2(bigdeer2); + + /* bigdeer3 */ + bigdeer3 = newwin(10, 23, 0, 0); + bigtop(bigdeer3); + legs3(bigdeer3); + + /* bigdeer4 */ + bigdeer4 = newwin(10, 23, 0, 0); + bigtop(bigdeer4); + legs4(bigdeer4); + + /* lookdeer1 */ + lookdeer1 = newwin(10, 25, 0, 0); + bigface(lookdeer1, noseattr); + legs1(lookdeer1); + + /* lookdeer2 */ + lookdeer2 = newwin(10, 25, 0, 0); + bigface(lookdeer2, noseattr); + legs2(lookdeer2); + + /* lookdeer3 */ + lookdeer3 = newwin(10, 25, 0, 0); + bigface(lookdeer3, noseattr); + legs3(lookdeer3); + + /* lookdeer4 */ + lookdeer4 = newwin(10, 25, 0, 0); + bigface(lookdeer4, noseattr); + legs4(lookdeer4); +} + +void boxit(void) +{ + int x; + + for (x = 0; x < 20; ++x) + mvaddch(x, 7, '|'); + + for (x = 0; x < 80; ++x) + { + if (x > 7) + mvaddch(19, x, '_'); + + mvaddch(22, x, '_'); + } +} + +void seas(void) +{ + mvaddch(4, 1, 'S'); + mvaddch(6, 1, 'E'); + mvaddch(8, 1, 'A'); + mvaddch(10, 1, 'S'); + mvaddch(12, 1, 'O'); + mvaddch(14, 1, 'N'); + mvaddch(16, 1, '`'); + mvaddch(18, 1, 'S'); +} + +void greet(void) +{ + mvaddch(3, 5, 'G'); + mvaddch(5, 5, 'R'); + mvaddch(7, 5, 'E'); + mvaddch(9, 5, 'E'); + mvaddch(11, 5, 'T'); + mvaddch(13, 5, 'I'); + mvaddch(15, 5, 'N'); + mvaddch(17, 5, 'G'); + mvaddch(19, 5, 'S'); +} + +void fromwho(void) +{ + mvaddstr(21, 13, FROMWHO); +} + +void del_msg(void) +{ + refresh(); +} + +void tree(void) +{ +#ifdef A_COLOR + if (has_colors()) + { + init_pair(30, COLOR_GREEN, COLOR_BLACK); + wattrset(treescrn, COLOR_PAIR(30)); + } +#endif + mvwaddch(treescrn, 1, 11, (chtype) '/'); + mvwaddch(treescrn, 2, 11, (chtype) '/'); + mvwaddch(treescrn, 3, 10, (chtype) '/'); + mvwaddch(treescrn, 4, 9, (chtype) '/'); + mvwaddch(treescrn, 5, 9, (chtype) '/'); + mvwaddch(treescrn, 6, 8, (chtype) '/'); + mvwaddch(treescrn, 7, 7, (chtype) '/'); + mvwaddch(treescrn, 8, 6, (chtype) '/'); + mvwaddch(treescrn, 9, 6, (chtype) '/'); + mvwaddch(treescrn, 10, 5, (chtype) '/'); + mvwaddch(treescrn, 11, 3, (chtype) '/'); + mvwaddch(treescrn, 12, 2, (chtype) '/'); + + mvwaddch(treescrn, 1, 13, (chtype) '\\'); + mvwaddch(treescrn, 2, 13, (chtype) '\\'); + mvwaddch(treescrn, 3, 14, (chtype) '\\'); + mvwaddch(treescrn, 4, 15, (chtype) '\\'); + mvwaddch(treescrn, 5, 15, (chtype) '\\'); + mvwaddch(treescrn, 6, 16, (chtype) '\\'); + mvwaddch(treescrn, 7, 17, (chtype) '\\'); + mvwaddch(treescrn, 8, 18, (chtype) '\\'); + mvwaddch(treescrn, 9, 18, (chtype) '\\'); + mvwaddch(treescrn, 10, 19, (chtype) '\\'); + mvwaddch(treescrn, 11, 21, (chtype) '\\'); + mvwaddch(treescrn, 12, 22, (chtype) '\\'); + + mvwaddch(treescrn, 4, 10, (chtype) '_'); + mvwaddch(treescrn, 4, 14, (chtype) '_'); + mvwaddch(treescrn, 8, 7, (chtype) '_'); + mvwaddch(treescrn, 8, 17, (chtype) '_'); + + mvwaddstr(treescrn, 13, 0, + "//////////// \\\\\\\\\\\\\\\\\\\\\\\\"); + +#ifdef A_COLOR + if (has_colors()) + { + init_pair(20, COLOR_YELLOW, COLOR_BLACK); + wattrset(treescrn, COLOR_PAIR(20)); + } +#endif + mvwaddstr(treescrn, 14, 11, "| |"); + mvwaddstr(treescrn, 15, 11, "|_|"); + + wrefresh(treescrn); + wrefresh(w_del_msg); +} + +void balls(void) +{ + chtype ball1, ball2, ball3, ball4, ball5, ball6; + + overlay(treescrn, treescrn2); + +#ifdef A_COLOR + if (has_colors()) + { + init_pair(1, COLOR_BLUE, COLOR_BLACK); + init_pair(2, COLOR_RED, COLOR_BLACK); + init_pair(3, COLOR_MAGENTA, COLOR_BLACK); + init_pair(4, COLOR_CYAN, COLOR_BLACK); + init_pair(5, COLOR_YELLOW, COLOR_BLACK); + init_pair(6, COLOR_WHITE, COLOR_BLACK); + ball1 = COLOR_PAIR(1) | '@'; + ball2 = COLOR_PAIR(2) | '@'; + ball3 = COLOR_PAIR(3) | '@'; + ball4 = COLOR_PAIR(4) | '@'; + ball5 = COLOR_PAIR(5) | '@'; + ball6 = COLOR_PAIR(6) | '@'; + } + else +#endif + ball1 = ball2 = ball3 = ball4 = ball5 = ball6 = '@'; + + mvwaddch(treescrn2, 3, 9, ball1); + mvwaddch(treescrn2, 3, 15, ball2); + mvwaddch(treescrn2, 4, 8, ball3); + mvwaddch(treescrn2, 4, 16, ball4); + mvwaddch(treescrn2, 5, 7, ball5); + mvwaddch(treescrn2, 5, 17, ball6); + mvwaddch(treescrn2, 7, 6, ball1 | A_BOLD); + mvwaddch(treescrn2, 7, 18, ball2 | A_BOLD); + mvwaddch(treescrn2, 8, 5, ball3 | A_BOLD); + mvwaddch(treescrn2, 8, 19, ball4 | A_BOLD); + mvwaddch(treescrn2, 10, 4, ball5 | A_BOLD); + mvwaddch(treescrn2, 10, 20, ball6 | A_BOLD); + mvwaddch(treescrn2, 11, 2, ball1); + mvwaddch(treescrn2, 11, 22, ball2); + mvwaddch(treescrn2, 12, 1, ball3); + mvwaddch(treescrn2, 12, 23, ball4); + + wrefresh(treescrn2); + wrefresh(w_del_msg); +} + +void star(void) +{ + mvwaddch(treescrn2, 0, 12, (chtype) '*' | A_STANDOUT); + + wrefresh(treescrn2); + wrefresh(w_del_msg); +} + +void strng1(void) +{ +#ifdef A_COLOR + if (has_colors()) + { + init_pair(10, COLOR_YELLOW, COLOR_BLACK); + wattrset(treescrn2, COLOR_PAIR(10) | A_BOLD); + } +#endif + mvwaddstr(treescrn2, 3, 11, ".:'"); + + wrefresh(treescrn2); + wrefresh(w_del_msg); +} + +void strng2(void) +{ +#ifdef A_COLOR + if (has_colors()) + { + init_pair(11, COLOR_RED, COLOR_BLACK); + wattrset(treescrn2, COLOR_PAIR(11) | A_BOLD); + } +#endif + mvwaddstr(treescrn2, 5, 11, ",.:'"); + mvwaddstr(treescrn2, 6, 9, ":'"); + + wrefresh(treescrn2); + wrefresh(w_del_msg); +} + +void strng3(void) +{ +#ifdef A_COLOR + if (has_colors()) + { + init_pair(12, COLOR_GREEN, COLOR_BLACK); + wattrset(treescrn2, COLOR_PAIR(12) | A_BOLD); + } +#endif + mvwaddstr(treescrn2, 7, 13, ",.:'"); + mvwaddstr(treescrn2, 8, 9, ",.:'"); + + wrefresh(treescrn2); + wrefresh(w_del_msg); +} + +void strng4(void) +{ +#ifdef A_COLOR + if (has_colors()) + { + init_pair(13, COLOR_WHITE, COLOR_BLACK); + wattrset(treescrn2, COLOR_PAIR(13) | A_BOLD); + } +#endif + mvwaddstr(treescrn2, 9, 14, ",.:'"); + mvwaddstr(treescrn2, 10, 10, ",.:'"); + mvwaddstr(treescrn2, 11, 6, ",.:'"); + mvwaddch(treescrn2, 12, 5, (chtype) '\''); + + wrefresh(treescrn2); + wrefresh(w_del_msg); +} + +void strng5(void) +{ +#ifdef A_COLOR + if (has_colors()) + { + init_pair(14, COLOR_CYAN, COLOR_BLACK); + wattrset(treescrn2, COLOR_PAIR(14) | A_BOLD); + } +#endif + mvwaddstr(treescrn2, 11, 16, ",.:'"); + mvwaddstr(treescrn2, 12, 12, ",.:'"); + + /* save a fully lit tree */ + overlay(treescrn2, treescrn); + + wrefresh(treescrn2); + wrefresh(w_del_msg); +} + +void blinkit(void) +{ + static int cycle; + + if (cycle > 4) + cycle = 0; + + touchwin(treescrn8); + + switch (cycle) + { + case 0: + overlay(treescrn3, treescrn8); + break; + + case 1: + overlay(treescrn4, treescrn8); + break; + + case 2: + overlay(treescrn5, treescrn8); + break; + + case 3: + overlay(treescrn6, treescrn8); + break; + + case 4: + overlay(treescrn7, treescrn8); + } + + wrefresh(treescrn8); + wrefresh(w_del_msg); + + napms(50); + touchwin(treescrn8); + + /*ALL ON************************************************** */ + + overlay(treescrn, treescrn8); + wrefresh(treescrn8); + wrefresh(w_del_msg); + + ++cycle; +} + +#define TSHOW(win, pause) touchwin(win); wrefresh(win); \ + wrefresh(w_del_msg); napms(pause) + +#define SHOW(win, pause) mvwin(win, y_pos, x_pos); wrefresh(win); \ + wrefresh(w_del_msg); napms(pause) + +void reindeer(void) +{ + int looper; + + y_pos = 0; + + for (x_pos = 70; x_pos > 62; x_pos--) + { + if (x_pos < 62) + y_pos = 1; + + for (looper = 0; looper < 4; looper++) + { + mvwaddch(dotdeer0, y_pos, x_pos, (chtype) '.'); + wrefresh(dotdeer0); + wrefresh(w_del_msg); + werase(dotdeer0); + wrefresh(dotdeer0); + wrefresh(w_del_msg); + } + } + + y_pos = 2; + + for (; x_pos > 50; x_pos--) + { + for (looper = 0; looper < 4; looper++) + { + if (x_pos < 56) + { + y_pos = 3; + + mvwaddch(stardeer0, y_pos, x_pos, (chtype) '*'); + wrefresh(stardeer0); + wrefresh(w_del_msg); + werase(stardeer0); + wrefresh(stardeer0); + } + else + { + mvwaddch(dotdeer0, y_pos, x_pos, (chtype) '*'); + wrefresh(dotdeer0); + wrefresh(w_del_msg); + werase(dotdeer0); + wrefresh(dotdeer0); + } + wrefresh(w_del_msg); + } + } + + x_pos = 58; + + for (y_pos = 2; y_pos < 5; y_pos++) + { + TSHOW(lildeer0, 50); + + for (looper = 0; looper < 4; looper++) + { + SHOW(lildeer3, 50); + SHOW(lildeer2, 50); + SHOW(lildeer1, 50); + SHOW(lildeer2, 50); + SHOW(lildeer3, 50); + + TSHOW(lildeer0, 50); + + x_pos -= 2; + } + } + + x_pos = 35; + + for (y_pos = 5; y_pos < 10; y_pos++) + { + touchwin(middeer0); + wrefresh(middeer0); + wrefresh(w_del_msg); + + for (looper = 0; looper < 2; looper++) + { + SHOW(middeer3, 50); + SHOW(middeer2, 50); + SHOW(middeer1, 50); + SHOW(middeer2, 50); + SHOW(middeer3, 50); + + TSHOW(middeer0, 50); + + x_pos -= 3; + } + } + + napms(2000); + + y_pos = 1; + + for (x_pos = 8; x_pos < 16; x_pos++) + { + SHOW(bigdeer4, 30); + SHOW(bigdeer3, 30); + SHOW(bigdeer2, 30); + SHOW(bigdeer1, 30); + SHOW(bigdeer2, 30); + SHOW(bigdeer3, 30); + SHOW(bigdeer4, 30); + SHOW(bigdeer0, 30); + } + + --x_pos; + + for (looper = 0; looper < 6; looper++) + { + SHOW(lookdeer4, 40); + SHOW(lookdeer3, 40); + SHOW(lookdeer2, 40); + SHOW(lookdeer1, 40); + SHOW(lookdeer2, 40); + SHOW(lookdeer3, 40); + SHOW(lookdeer4, 40); + } + + SHOW(lookdeer0, 40); + + for (; y_pos < 10; y_pos++) + { + for (looper = 0; looper < 2; looper++) + { + SHOW(bigdeer4, 30); + SHOW(bigdeer3, 30); + SHOW(bigdeer2, 30); + SHOW(bigdeer1, 30); + SHOW(bigdeer2, 30); + SHOW(bigdeer3, 30); + SHOW(bigdeer4, 30); + } + + SHOW(bigdeer0, 30); + } + + --y_pos; + + mvwin(lookdeer3, y_pos, x_pos); + wrefresh(lookdeer3); + wrefresh(w_del_msg); +} diff --git a/modules/ncurses/pdcurses/panel.h b/modules/ncurses/pdcurses/panel.h new file mode 100644 index 00000000..6cfba0fa --- /dev/null +++ b/modules/ncurses/pdcurses/panel.h @@ -0,0 +1,56 @@ +/* Public Domain Curses */ + +/*----------------------------------------------------------------------* + * Panels for PDCurses * + *----------------------------------------------------------------------*/ + +#ifndef __PDCURSES_PANEL_H__ +#define __PDCURSES_PANEL_H__ 1 + +#include + +#if defined(__cplusplus) || defined(__cplusplus__) || defined(__CPLUSPLUS) +extern "C" +{ +#endif + +typedef struct panelobs +{ + struct panelobs *above; + struct panel *pan; +} PANELOBS; + +typedef struct panel +{ + WINDOW *win; + int wstarty; + int wendy; + int wstartx; + int wendx; + struct panel *below; + struct panel *above; + const void *user; + struct panelobs *obscure; +} PANEL; + +PDCEX int bottom_panel(PANEL *pan); +PDCEX int del_panel(PANEL *pan); +PDCEX int hide_panel(PANEL *pan); +PDCEX int move_panel(PANEL *pan, int starty, int startx); +PDCEX PANEL *new_panel(WINDOW *win); +PDCEX PANEL *panel_above(const PANEL *pan); +PDCEX PANEL *panel_below(const PANEL *pan); +PDCEX int panel_hidden(const PANEL *pan); +PDCEX const void *panel_userptr(const PANEL *pan); +PDCEX WINDOW *panel_window(const PANEL *pan); +PDCEX int replace_panel(PANEL *pan, WINDOW *win); +PDCEX int set_panel_userptr(PANEL *pan, const void *uptr); +PDCEX int show_panel(PANEL *pan); +PDCEX int top_panel(PANEL *pan); +PDCEX void update_panels(void); + +#if defined(__cplusplus) || defined(__cplusplus__) || defined(__CPLUSPLUS) +} +#endif + +#endif /* __PDCURSES_PANEL_H__ */ diff --git a/modules/ncurses/pdcurses/pdcurses/README.md b/modules/ncurses/pdcurses/pdcurses/README.md new file mode 100644 index 00000000..a6a7ee8f --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/README.md @@ -0,0 +1,25 @@ +PDCurses Portable Core +====================== + +This directory contains core PDCurses source code files common to all +platforms. + + +Building +-------- + +These modules are built by the platform-specific makefiles, in the +platform directories. + + +Distribution Status +------------------- + +The files in this directory are released to the Public Domain. + + +Acknowledgements +---------------- + +The panel library was originally provided by +Warren Tucker diff --git a/modules/ncurses/pdcurses/pdcurses/addch.c b/modules/ncurses/pdcurses/pdcurses/addch.c new file mode 100644 index 00000000..bf7c8b10 --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/addch.c @@ -0,0 +1,411 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +addch +----- + +### Synopsis + + int addch(const chtype ch); + int waddch(WINDOW *win, const chtype ch); + int mvaddch(int y, int x, const chtype ch); + int mvwaddch(WINDOW *win, int y, int x, const chtype ch); + int echochar(const chtype ch); + int wechochar(WINDOW *win, const chtype ch); + + int addrawch(chtype ch); + int waddrawch(WINDOW *win, chtype ch); + int mvaddrawch(int y, int x, chtype ch); + int mvwaddrawch(WINDOW *win, int y, int x, chtype ch); + + int add_wch(const cchar_t *wch); + int wadd_wch(WINDOW *win, const cchar_t *wch); + int mvadd_wch(int y, int x, const cchar_t *wch); + int mvwadd_wch(WINDOW *win, int y, int x, const cchar_t *wch); + int echo_wchar(const cchar_t *wch); + int wecho_wchar(WINDOW *win, const cchar_t *wch); + +### Description + + addch() adds the chtype ch to the default window (stdscr) at the + current cursor position, and advances the cursor. Note that + chtypes can convey both text (a single character) and + attributes, including a color pair. add_wch() is the wide- + character version of this function, taking a pointer to a + cchar_t instead of a chtype. + + waddch() is like addch(), but also lets you specify the window. + (This is in fact the core output routine.) wadd_wch() is the + wide version. + + mvaddch() moves the cursor to the specified (y, x) position, and + adds ch to stdscr. mvadd_wch() is the wide version. + + mvwaddch() moves the cursor to the specified position and adds + ch to the specified window. mvwadd_wch() is the wide version. + + echochar() adds ch to stdscr at the current cursor position and + calls refresh(). echo_wchar() is the wide version. + + wechochar() adds ch to the specified window and calls + wrefresh(). wecho_wchar() is the wide version. + + addrawch(), waddrawch(), mvaddrawch() and mvwaddrawch() are + PDCurses-specific wrappers for addch() etc. that disable the + translation of control characters. + + The following applies to all these functions: + + If the cursor moves on to the right margin, an automatic newline + is performed. If scrollok is enabled, and a character is added + to the bottom right corner of the window, the scrolling region + will be scrolled up one line. If scrolling is not allowed, ERR + will be returned. + + If ch is a tab, newline, or backspace, the cursor will be moved + appropriately within the window. If ch is a newline, the + clrtoeol routine is called before the cursor is moved to the + beginning of the next line. If newline mapping is off, the + cursor will be moved to the next line, but the x coordinate will + be unchanged. If ch is a tab the cursor is moved to the next + tab position within the window. If ch is another control + character, it will be drawn in the ^X notation. Calling the + inch() routine after adding a control character returns the + representation of the control character, not the control + character. + + Video attributes can be combined with a character by ORing them + into the parameter. Text, including attributes, can be copied + from one place to another by using inch() and addch(). + + Note that in PDCurses, for now, a cchar_t and a chtype are the + same. The text field is 16 bits wide, and is treated as Unicode + (UCS-2) when PDCurses is built with wide-character support + (define PDC_WIDE). So, in functions that take a chtype, like + addch(), both the wide and narrow versions will handle Unicode. + But for portability, you should use the wide functions. + +### Return Value + + All functions return OK on success and ERR on error. + +### Portability + X/Open BSD SYS V + addch Y Y Y + waddch Y Y Y + mvaddch Y Y Y + mvwaddch Y Y Y + echochar Y - 3.0 + wechochar Y - 3.0 + addrawch - - - + waddrawch - - - + mvaddrawch - - - + mvwaddrawch - - - + add_wch Y + wadd_wch Y + mvadd_wch Y + mvwadd_wch Y + echo_wchar Y + wecho_wchar Y + +**man-end****************************************************************/ + +int waddch(WINDOW *win, const chtype ch) +{ + int x, y; + chtype text, attr; + bool xlat; + + PDC_LOG(("waddch() - called: win=%p ch=%x (text=%c attr=0x%x)\n", + win, ch, ch & A_CHARTEXT, ch & A_ATTRIBUTES)); + + if (!win) + return ERR; + + x = win->_curx; + y = win->_cury; + + if (y > win->_maxy || x > win->_maxx || y < 0 || x < 0) + return ERR; + + xlat = !SP->raw_out && !(ch & A_ALTCHARSET); + text = ch & A_CHARTEXT; + attr = ch & A_ATTRIBUTES; + + if (xlat && (text < ' ' || text == 0x7f)) + { + int x2; + + switch (text) + { + case '\t': + for (x2 = ((x / TABSIZE) + 1) * TABSIZE; x < x2; x++) + { + if (waddch(win, attr | ' ') == ERR) + return ERR; + + /* if tab to next line, exit the loop */ + + if (!win->_curx) + break; + } + return OK; + + case '\n': + /* if lf -> crlf */ + + if (!SP->raw_out) + x = 0; + + wclrtoeol(win); + + if (++y > win->_bmarg) + { + y--; + + if (wscrl(win, 1) == ERR) + return ERR; + } + + break; + + case '\b': + /* don't back over left margin */ + + if (--x < 0) + case '\r': + x = 0; + + break; + + case 0x7f: + if (waddch(win, attr | '^') == ERR) + return ERR; + + return waddch(win, attr | '?'); + + default: + /* handle control chars */ + + if (waddch(win, attr | '^') == ERR) + return ERR; + + return waddch(win, ch + '@'); + } + } + else + { + /* If the incoming character doesn't have its own attribute, + then use the current attributes for the window. If it has + attributes but not a color component, OR the attributes to + the current attributes for the window. If it has a color + component, use the attributes solely from the incoming + character. */ + + if (!(attr & A_COLOR)) + attr |= win->_attrs; + + /* wrs (4/10/93): Apply the same sort of logic for the window + background, in that it only takes precedence if other color + attributes are not there and that the background character + will only print if the printing character is blank. */ + + if (!(attr & A_COLOR)) + attr |= win->_bkgd & A_ATTRIBUTES; + else + attr |= win->_bkgd & (A_ATTRIBUTES ^ A_COLOR); + + if (text == ' ') + text = win->_bkgd & A_CHARTEXT; + + /* Add the attribute back into the character. */ + + text |= attr; + + /* Only change _firstch/_lastch if the character to be added is + different from the character/attribute that is already in + that position in the window. */ + + if (win->_y[y][x] != text) + { + if (win->_firstch[y] == _NO_CHANGE) + win->_firstch[y] = win->_lastch[y] = x; + else + if (x < win->_firstch[y]) + win->_firstch[y] = x; + else + if (x > win->_lastch[y]) + win->_lastch[y] = x; + + win->_y[y][x] = text; + } + + if (++x >= win->_maxx) + { + /* wrap around test */ + + x = 0; + + if (++y > win->_bmarg) + { + y--; + + if (wscrl(win, 1) == ERR) + { + PDC_sync(win); + return ERR; + } + } + } + } + + win->_curx = x; + win->_cury = y; + + if (win->_immed) + wrefresh(win); + if (win->_sync) + wsyncup(win); + + return OK; +} + +int addch(const chtype ch) +{ + PDC_LOG(("addch() - called: ch=%x\n", ch)); + + return waddch(stdscr, ch); +} + +int mvaddch(int y, int x, const chtype ch) +{ + PDC_LOG(("mvaddch() - called: y=%d x=%d ch=%x\n", y, x, ch)); + + if (move(y,x) == ERR) + return ERR; + + return waddch(stdscr, ch); +} + +int mvwaddch(WINDOW *win, int y, int x, const chtype ch) +{ + PDC_LOG(("mvwaddch() - called: win=%p y=%d x=%d ch=%d\n", win, y, x, ch)); + + if (wmove(win, y, x) == ERR) + return ERR; + + return waddch(win, ch); +} + +int echochar(const chtype ch) +{ + PDC_LOG(("echochar() - called: ch=%x\n", ch)); + + return wechochar(stdscr, ch); +} + +int wechochar(WINDOW *win, const chtype ch) +{ + PDC_LOG(("wechochar() - called: win=%p ch=%x\n", win, ch)); + + if (waddch(win, ch) == ERR) + return ERR; + + return wrefresh(win); +} + +int waddrawch(WINDOW *win, chtype ch) +{ + PDC_LOG(("waddrawch() - called: win=%p ch=%x (text=%c attr=0x%x)\n", + win, ch, ch & A_CHARTEXT, ch & A_ATTRIBUTES)); + + if ((ch & A_CHARTEXT) < ' ' || (ch & A_CHARTEXT) == 0x7f) + ch |= A_ALTCHARSET; + + return waddch(win, ch); +} + +int addrawch(chtype ch) +{ + PDC_LOG(("addrawch() - called: ch=%x\n", ch)); + + return waddrawch(stdscr, ch); +} + +int mvaddrawch(int y, int x, chtype ch) +{ + PDC_LOG(("mvaddrawch() - called: y=%d x=%d ch=%d\n", y, x, ch)); + + if (move(y, x) == ERR) + return ERR; + + return waddrawch(stdscr, ch); +} + +int mvwaddrawch(WINDOW *win, int y, int x, chtype ch) +{ + PDC_LOG(("mvwaddrawch() - called: win=%p y=%d x=%d ch=%d\n", + win, y, x, ch)); + + if (wmove(win, y, x) == ERR) + return ERR; + + return waddrawch(win, ch); +} + +#ifdef PDC_WIDE +int wadd_wch(WINDOW *win, const cchar_t *wch) +{ + PDC_LOG(("wadd_wch() - called: win=%p wch=%x\n", win, *wch)); + + return wch ? waddch(win, *wch) : ERR; +} + +int add_wch(const cchar_t *wch) +{ + PDC_LOG(("add_wch() - called: wch=%x\n", *wch)); + + return wadd_wch(stdscr, wch); +} + +int mvadd_wch(int y, int x, const cchar_t *wch) +{ + PDC_LOG(("mvaddch() - called: y=%d x=%d wch=%x\n", y, x, *wch)); + + if (move(y,x) == ERR) + return ERR; + + return wadd_wch(stdscr, wch); +} + +int mvwadd_wch(WINDOW *win, int y, int x, const cchar_t *wch) +{ + PDC_LOG(("mvwaddch() - called: win=%p y=%d x=%d wch=%d\n", + win, y, x, *wch)); + + if (wmove(win, y, x) == ERR) + return ERR; + + return wadd_wch(win, wch); +} + +int echo_wchar(const cchar_t *wch) +{ + PDC_LOG(("echo_wchar() - called: wch=%x\n", *wch)); + + return wecho_wchar(stdscr, wch); +} + +int wecho_wchar(WINDOW *win, const cchar_t *wch) +{ + PDC_LOG(("wecho_wchar() - called: win=%p wch=%x\n", win, *wch)); + + if (!wch || (wadd_wch(win, wch) == ERR)) + return ERR; + + return wrefresh(win); +} +#endif diff --git a/modules/ncurses/pdcurses/pdcurses/addchstr.c b/modules/ncurses/pdcurses/pdcurses/addchstr.c new file mode 100644 index 00000000..8cb719a9 --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/addchstr.c @@ -0,0 +1,245 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +addchstr +-------- + +### Synopsis + + int addchstr(const chtype *ch); + int addchnstr(const chtype *ch, int n); + int waddchstr(WINDOW *win, const chtype *ch); + int waddchnstr(WINDOW *win, const chtype *ch, int n); + int mvaddchstr(int y, int x, const chtype *ch); + int mvaddchnstr(int y, int x, const chtype *ch, int n); + int mvwaddchstr(WINDOW *, int y, int x, const chtype *ch); + int mvwaddchnstr(WINDOW *, int y, int x, const chtype *ch, int n); + + int add_wchstr(const cchar_t *wch); + int add_wchnstr(const cchar_t *wch, int n); + int wadd_wchstr(WINDOW *win, const cchar_t *wch); + int wadd_wchnstr(WINDOW *win, const cchar_t *wch, int n); + int mvadd_wchstr(int y, int x, const cchar_t *wch); + int mvadd_wchnstr(int y, int x, const cchar_t *wch, int n); + int mvwadd_wchstr(WINDOW *win, int y, int x, const cchar_t *wch); + int mvwadd_wchnstr(WINDOW *win, int y, int x, const cchar_t *wch, + int n); + +### Description + + These routines write a chtype or cchar_t string directly into + the window structure, starting at the current or specified + position. The four routines with n as the last argument copy at + most n elements, but no more than will fit on the line. If n = + -1 then the whole string is copied, up to the maximum number + that will fit on the line. + + The cursor position is not advanced. These routines do not check + for newline or other special characters, nor does any line + wrapping occur. + +### Return Value + + All functions return OK or ERR. + +### Portability + X/Open BSD SYS V + addchstr Y - 4.0 + waddchstr Y - 4.0 + mvaddchstr Y - 4.0 + mvwaddchstr Y - 4.0 + addchnstr Y - 4.0 + waddchnstr Y - 4.0 + mvaddchnstr Y - 4.0 + mvwaddchnstr Y - 4.0 + add_wchstr Y + wadd_wchstr Y + mvadd_wchstr Y + mvwadd_wchstr Y + add_wchnstr Y + wadd_wchnstr Y + mvadd_wchnstr Y + mvwadd_wchnstr Y + +**man-end****************************************************************/ + +#include + +int waddchnstr(WINDOW *win, const chtype *ch, int n) +{ + int y, x, maxx, minx; + chtype *ptr; + + PDC_LOG(("waddchnstr() - called: win=%p n=%d\n", win, n)); + + if (!win || !ch || !n || n < -1) + return ERR; + + x = win->_curx; + y = win->_cury; + ptr = &(win->_y[y][x]); + + if (n == -1 || n > win->_maxx - x) + n = win->_maxx - x; + + minx = win->_firstch[y]; + maxx = win->_lastch[y]; + + for (; n && *ch; n--, x++, ptr++, ch++) + { + if (*ptr != *ch) + { + if (x < minx || minx == _NO_CHANGE) + minx = x; + + if (x > maxx) + maxx = x; + + PDC_LOG(("y %d x %d minx %d maxx %d *ptr %x *ch" + " %x firstch: %d lastch: %d\n", + y, x, minx, maxx, *ptr, *ch, + win->_firstch[y], win->_lastch[y])); + + *ptr = *ch; + } + } + + win->_firstch[y] = minx; + win->_lastch[y] = maxx; + + return OK; +} + +int addchstr(const chtype *ch) +{ + PDC_LOG(("addchstr() - called\n")); + + return waddchnstr(stdscr, ch, -1); +} + +int addchnstr(const chtype *ch, int n) +{ + PDC_LOG(("addchnstr() - called\n")); + + return waddchnstr(stdscr, ch, n); +} + +int waddchstr(WINDOW *win, const chtype *ch) +{ + PDC_LOG(("waddchstr() - called: win=%p\n", win)); + + return waddchnstr(win, ch, -1); +} + +int mvaddchstr(int y, int x, const chtype *ch) +{ + PDC_LOG(("mvaddchstr() - called: y %d x %d\n", y, x)); + + if (move(y, x) == ERR) + return ERR; + + return waddchnstr(stdscr, ch, -1); +} + +int mvaddchnstr(int y, int x, const chtype *ch, int n) +{ + PDC_LOG(("mvaddchnstr() - called: y %d x %d n %d\n", y, x, n)); + + if (move(y, x) == ERR) + return ERR; + + return waddchnstr(stdscr, ch, n); +} + +int mvwaddchstr(WINDOW *win, int y, int x, const chtype *ch) +{ + PDC_LOG(("mvwaddchstr() - called:\n")); + + if (wmove(win, y, x) == ERR) + return ERR; + + return waddchnstr(win, ch, -1); +} + +int mvwaddchnstr(WINDOW *win, int y, int x, const chtype *ch, int n) +{ + PDC_LOG(("mvwaddchnstr() - called: y %d x %d n %d \n", y, x, n)); + + if (wmove(win, y, x) == ERR) + return ERR; + + return waddchnstr(win, ch, n); +} + +#ifdef PDC_WIDE +int wadd_wchnstr(WINDOW *win, const cchar_t *wch, int n) +{ + PDC_LOG(("wadd_wchnstr() - called: win=%p n=%d\n", win, n)); + + return waddchnstr(win, wch, n); +} + +int add_wchstr(const cchar_t *wch) +{ + PDC_LOG(("add_wchstr() - called\n")); + + return wadd_wchnstr(stdscr, wch, -1); +} + +int add_wchnstr(const cchar_t *wch, int n) +{ + PDC_LOG(("add_wchnstr() - called\n")); + + return wadd_wchnstr(stdscr, wch, n); +} + +int wadd_wchstr(WINDOW *win, const cchar_t *wch) +{ + PDC_LOG(("wadd_wchstr() - called: win=%p\n", win)); + + return wadd_wchnstr(win, wch, -1); +} + +int mvadd_wchstr(int y, int x, const cchar_t *wch) +{ + PDC_LOG(("mvadd_wchstr() - called: y %d x %d\n", y, x)); + + if (move(y, x) == ERR) + return ERR; + + return wadd_wchnstr(stdscr, wch, -1); +} + +int mvadd_wchnstr(int y, int x, const cchar_t *wch, int n) +{ + PDC_LOG(("mvadd_wchnstr() - called: y %d x %d n %d\n", y, x, n)); + + if (move(y, x) == ERR) + return ERR; + + return wadd_wchnstr(stdscr, wch, n); +} + +int mvwadd_wchstr(WINDOW *win, int y, int x, const cchar_t *wch) +{ + PDC_LOG(("mvwadd_wchstr() - called:\n")); + + if (wmove(win, y, x) == ERR) + return ERR; + + return wadd_wchnstr(win, wch, -1); +} + +int mvwadd_wchnstr(WINDOW *win, int y, int x, const cchar_t *wch, int n) +{ + PDC_LOG(("mvwadd_wchnstr() - called: y %d x %d n %d \n", y, x, n)); + + if (wmove(win, y, x) == ERR) + return ERR; + + return wadd_wchnstr(win, wch, n); +} +#endif diff --git a/modules/ncurses/pdcurses/pdcurses/addstr.c b/modules/ncurses/pdcurses/pdcurses/addstr.c new file mode 100644 index 00000000..a2a9465c --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/addstr.c @@ -0,0 +1,240 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +addstr +------ + +### Synopsis + + int addstr(const char *str); + int addnstr(const char *str, int n); + int waddstr(WINDOW *win, const char *str); + int waddnstr(WINDOW *win, const char *str, int n); + int mvaddstr(int y, int x, const char *str); + int mvaddnstr(int y, int x, const char *str, int n); + int mvwaddstr(WINDOW *win, int y, int x, const char *str); + int mvwaddnstr(WINDOW *win, int y, int x, const char *str, int n); + + int addwstr(const wchar_t *wstr); + int addnwstr(const wchar_t *wstr, int n); + int waddwstr(WINDOW *win, const wchar_t *wstr); + int waddnwstr(WINDOW *win, const wchar_t *wstr, int n); + int mvaddwstr(int y, int x, const wchar_t *wstr); + int mvaddnwstr(int y, int x, const wchar_t *wstr, int n); + int mvwaddwstr(WINDOW *win, int y, int x, const wchar_t *wstr); + int mvwaddnwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n); + +### Description + + These routines write all the characters of the null-terminated + string str or wide-character string wstr to the given window. + The functionality is similar to calling waddch() once for each + character in the string; except that, when PDCurses is built + with wide-character support enabled, the narrow-character + functions treat the string as a multibyte string in the current + locale, and convert it. The routines with n as the last + argument write at most n characters; if n is negative, then the + entire string will be added. + +### Return Value + + All functions return OK or ERR. + +### Portability + X/Open BSD SYS V + addstr Y Y Y + waddstr Y Y Y + mvaddstr Y Y Y + mvwaddstr Y Y Y + addnstr Y - 4.0 + waddnstr Y - 4.0 + mvaddnstr Y - 4.0 + mvwaddnstr Y - 4.0 + addwstr Y + waddwstr Y + mvaddwstr Y + mvwaddwstr Y + addnwstr Y + waddnwstr Y + mvaddnwstr Y + mvwaddnwstr Y + +**man-end****************************************************************/ + +int waddnstr(WINDOW *win, const char *str, int n) +{ + int i = 0; + + PDC_LOG(("waddnstr() - called: string=\"%s\" n %d \n", str, n)); + + if (!win || !str) + return ERR; + + while (str[i] && (i < n || n < 0)) + { +#ifdef PDC_WIDE + wchar_t wch; + int retval = PDC_mbtowc(&wch, str + i, n >= 0 ? n - i : 6); + + if (retval <= 0) + return OK; + + i += retval; +#else + chtype wch = (unsigned char)(str[i++]); +#endif + if (waddch(win, wch) == ERR) + return ERR; + } + + return OK; +} + +int addstr(const char *str) +{ + PDC_LOG(("addstr() - called: string=\"%s\"\n", str)); + + return waddnstr(stdscr, str, -1); +} + +int addnstr(const char *str, int n) +{ + PDC_LOG(("addnstr() - called: string=\"%s\" n %d \n", str, n)); + + return waddnstr(stdscr, str, n); +} + +int waddstr(WINDOW *win, const char *str) +{ + PDC_LOG(("waddstr() - called: string=\"%s\"\n", str)); + + return waddnstr(win, str, -1); +} + +int mvaddstr(int y, int x, const char *str) +{ + PDC_LOG(("mvaddstr() - called: y %d x %d string=\"%s\"\n", y, x, str)); + + if (move(y, x) == ERR) + return ERR; + + return waddnstr(stdscr, str, -1); +} + +int mvaddnstr(int y, int x, const char *str, int n) +{ + PDC_LOG(("mvaddnstr() - called: y %d x %d string=\"%s\" n %d \n", + y, x, str, n)); + + if (move(y, x) == ERR) + return ERR; + + return waddnstr(stdscr, str, n); +} + +int mvwaddstr(WINDOW *win, int y, int x, const char *str) +{ + PDC_LOG(("mvwaddstr() - called: string=\"%s\"\n", str)); + + if (wmove(win, y, x) == ERR) + return ERR; + + return waddnstr(win, str, -1); +} + +int mvwaddnstr(WINDOW *win, int y, int x, const char *str, int n) +{ + PDC_LOG(("mvwaddnstr() - called: y %d x %d string=\"%s\" n %d \n", + y, x, str, n)); + + if (wmove(win, y, x) == ERR) + return ERR; + + return waddnstr(win, str, n); +} + +#ifdef PDC_WIDE +int waddnwstr(WINDOW *win, const wchar_t *wstr, int n) +{ + int i = 0; + + PDC_LOG(("waddnwstr() - called\n")); + + if (!win || !wstr) + return ERR; + + while (wstr[i] && (i < n || n < 0)) + { + chtype wch = wstr[i++]; + + if (waddch(win, wch) == ERR) + return ERR; + } + + return OK; +} + +int addwstr(const wchar_t *wstr) +{ + PDC_LOG(("addwstr() - called\n")); + + return waddnwstr(stdscr, wstr, -1); +} + +int addnwstr(const wchar_t *wstr, int n) +{ + PDC_LOG(("addnwstr() - called\n")); + + return waddnwstr(stdscr, wstr, n); +} + +int waddwstr(WINDOW *win, const wchar_t *wstr) +{ + PDC_LOG(("waddwstr() - called\n")); + + return waddnwstr(win, wstr, -1); +} + +int mvaddwstr(int y, int x, const wchar_t *wstr) +{ + PDC_LOG(("mvaddstr() - called\n")); + + if (move(y, x) == ERR) + return ERR; + + return waddnwstr(stdscr, wstr, -1); +} + +int mvaddnwstr(int y, int x, const wchar_t *wstr, int n) +{ + PDC_LOG(("mvaddnstr() - called\n")); + + if (move(y, x) == ERR) + return ERR; + + return waddnwstr(stdscr, wstr, n); +} + +int mvwaddwstr(WINDOW *win, int y, int x, const wchar_t *wstr) +{ + PDC_LOG(("mvwaddstr() - called\n")); + + if (wmove(win, y, x) == ERR) + return ERR; + + return waddnwstr(win, wstr, -1); +} + +int mvwaddnwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n) +{ + PDC_LOG(("mvwaddnstr() - called\n")); + + if (wmove(win, y, x) == ERR) + return ERR; + + return waddnwstr(win, wstr, n); +} +#endif diff --git a/modules/ncurses/pdcurses/pdcurses/attr.c b/modules/ncurses/pdcurses/pdcurses/attr.c new file mode 100644 index 00000000..26b922ea --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/attr.c @@ -0,0 +1,352 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +attr +---- + +### Synopsis + + int attroff(chtype attrs); + int wattroff(WINDOW *win, chtype attrs); + int attron(chtype attrs); + int wattron(WINDOW *win, chtype attrs); + int attrset(chtype attrs); + int wattrset(WINDOW *win, chtype attrs); + int standend(void); + int wstandend(WINDOW *win); + int standout(void); + int wstandout(WINDOW *win); + + int color_set(short color_pair, void *opts); + int wcolor_set(WINDOW *win, short color_pair, void *opts); + + int attr_get(attr_t *attrs, short *color_pair, void *opts); + int attr_off(attr_t attrs, void *opts); + int attr_on(attr_t attrs, void *opts); + int attr_set(attr_t attrs, short color_pair, void *opts); + int wattr_get(WINDOW *win, attr_t *attrs, short *color_pair, + void *opts); + int wattr_off(WINDOW *win, attr_t attrs, void *opts); + int wattr_on(WINDOW *win, attr_t attrs, void *opts); + int wattr_set(WINDOW *win, attr_t attrs, short color_pair, + void *opts); + + int chgat(int n, attr_t attr, short color, const void *opts); + int mvchgat(int y, int x, int n, attr_t attr, short color, + const void *opts); + int mvwchgat(WINDOW *win, int y, int x, int n, attr_t attr, + short color, const void *opts); + int wchgat(WINDOW *win, int n, attr_t attr, short color, + const void *opts); + + chtype getattrs(WINDOW *win); + +### Description + + These functions manipulate the current attributes and/or colors + of the named window. These attributes can be any combination + of A_STANDOUT, A_REVERSE, A_BOLD, A_DIM, A_BLINK, A_UNDERLINE. + + These constants are defined in and can be combined + with the bitwise-OR operator (|). + + The current attributes of a window are applied to all chtypes + that are written into the window with waddch(). Attributes are + a property of the chtype, and move with the character through + any scrolling or insert/delete operations. + + attrset() sets the current attributes of the given window to + attrs. attroff() turns off the named attributes without + affecting any other attributes; attron() turns them on. + color_set() sets the window color to the value of color_pair. + + standout() is the same as attron(A_STANDOUT). standend() is the + same as attrset(A_NORMAL); that is, it turns off all attributes. + +### Return Value + + All functions return OK on success and ERR on error. + +### Portability + X/Open BSD SYS V + attroff Y Y Y + wattroff Y Y Y + attron Y Y Y + wattron Y Y Y + attrset Y Y Y + wattrset Y Y Y + standend Y Y Y + wstandend Y Y Y + standout Y Y Y + wstandout Y Y Y + color_set Y + wcolor_set Y + attr_get Y + wattr_get Y + attr_on Y + wattr_on Y + attr_off Y + wattr_off Y + attr_set Y + wattr_set Y + chgat Y + wchgat Y + mvchgat Y + mvwchgat Y + getattrs - + +**man-end****************************************************************/ + +int wattroff(WINDOW *win, chtype attrs) +{ + PDC_LOG(("wattroff() - called\n")); + + if (!win) + return ERR; + + win->_attrs &= (~attrs & A_ATTRIBUTES); + + return OK; +} + +int attroff(chtype attrs) +{ + PDC_LOG(("attroff() - called\n")); + + return wattroff(stdscr, attrs); +} + +int wattron(WINDOW *win, chtype attrs) +{ + chtype newcolr, oldcolr, newattr, oldattr; + + PDC_LOG(("wattron() - called\n")); + + if (!win) + return ERR; + + if ((win->_attrs & A_COLOR) && (attrs & A_COLOR)) + { + oldcolr = win->_attrs & A_COLOR; + oldattr = win->_attrs ^ oldcolr; + newcolr = attrs & A_COLOR; + newattr = (attrs & A_ATTRIBUTES) ^ newcolr; + newattr |= oldattr; + win->_attrs = newattr | newcolr; + } + else + win->_attrs |= (attrs & A_ATTRIBUTES); + + return OK; +} + +int attron(chtype attrs) +{ + PDC_LOG(("attron() - called\n")); + + return wattron(stdscr, attrs); +} + +int wattrset(WINDOW *win, chtype attrs) +{ + PDC_LOG(("wattrset() - called\n")); + + if (!win) + return ERR; + + win->_attrs = attrs & A_ATTRIBUTES; + + return OK; +} + +int attrset(chtype attrs) +{ + PDC_LOG(("attrset() - called\n")); + + return wattrset(stdscr, attrs); +} + +int standend(void) +{ + PDC_LOG(("standend() - called\n")); + + return wattrset(stdscr, A_NORMAL); +} + +int standout(void) +{ + PDC_LOG(("standout() - called\n")); + + return wattrset(stdscr, A_STANDOUT); +} + +int wstandend(WINDOW *win) +{ + PDC_LOG(("wstandend() - called\n")); + + return wattrset(win, A_NORMAL); +} + +int wstandout(WINDOW *win) +{ + PDC_LOG(("wstandout() - called\n")); + + return wattrset(win, A_STANDOUT); +} + +chtype getattrs(WINDOW *win) +{ + return win ? win->_attrs : 0; +} + +int wcolor_set(WINDOW *win, short color_pair, void *opts) +{ + PDC_LOG(("wcolor_set() - called\n")); + + if (!win) + return ERR; + + win->_attrs = (win->_attrs & ~A_COLOR) | COLOR_PAIR(color_pair); + + return OK; +} + +int color_set(short color_pair, void *opts) +{ + PDC_LOG(("color_set() - called\n")); + + return wcolor_set(stdscr, color_pair, opts); +} + +int wattr_get(WINDOW *win, attr_t *attrs, short *color_pair, void *opts) +{ + PDC_LOG(("wattr_get() - called\n")); + + if (!win) + return ERR; + + if (attrs) + *attrs = win->_attrs & (A_ATTRIBUTES & ~A_COLOR); + + if (color_pair) + *color_pair = PAIR_NUMBER(win->_attrs); + + return OK; +} + +int attr_get(attr_t *attrs, short *color_pair, void *opts) +{ + PDC_LOG(("attr_get() - called\n")); + + return wattr_get(stdscr, attrs, color_pair, opts); +} + +int wattr_off(WINDOW *win, attr_t attrs, void *opts) +{ + PDC_LOG(("wattr_off() - called\n")); + + return wattroff(win, attrs); +} + +int attr_off(attr_t attrs, void *opts) +{ + PDC_LOG(("attr_off() - called\n")); + + return wattroff(stdscr, attrs); +} + +int wattr_on(WINDOW *win, attr_t attrs, void *opts) +{ + PDC_LOG(("wattr_off() - called\n")); + + return wattron(win, attrs); +} + +int attr_on(attr_t attrs, void *opts) +{ + PDC_LOG(("attr_on() - called\n")); + + return wattron(stdscr, attrs); +} + +int wattr_set(WINDOW *win, attr_t attrs, short color_pair, void *opts) +{ + PDC_LOG(("wattr_set() - called\n")); + + if (!win) + return ERR; + + win->_attrs = (attrs & (A_ATTRIBUTES & ~A_COLOR)) | COLOR_PAIR(color_pair); + + return OK; +} + +int attr_set(attr_t attrs, short color_pair, void *opts) +{ + PDC_LOG(("attr_get() - called\n")); + + return wattr_set(stdscr, attrs, color_pair, opts); +} + +int wchgat(WINDOW *win, int n, attr_t attr, short color, const void *opts) +{ + chtype *dest, newattr; + int startpos, endpos; + + PDC_LOG(("wchgat() - called\n")); + + if (!win) + return ERR; + + newattr = (attr & A_ATTRIBUTES) | COLOR_PAIR(color); + + startpos = win->_curx; + endpos = ((n < 0) ? win->_maxx : min(startpos + n, win->_maxx)) - 1; + dest = win->_y[win->_cury]; + + for (n = startpos; n <= endpos; n++) + dest[n] = (dest[n] & A_CHARTEXT) | newattr; + + n = win->_cury; + + if (startpos < win->_firstch[n] || win->_firstch[n] == _NO_CHANGE) + win->_firstch[n] = startpos; + + if (endpos > win->_lastch[n]) + win->_lastch[n] = endpos; + + PDC_sync(win); + + return OK; +} + +int chgat(int n, attr_t attr, short color, const void *opts) +{ + PDC_LOG(("chgat() - called\n")); + + return wchgat(stdscr, n, attr, color, opts); +} + +int mvchgat(int y, int x, int n, attr_t attr, short color, const void *opts) +{ + PDC_LOG(("mvchgat() - called\n")); + + if (move(y, x) == ERR) + return ERR; + + return wchgat(stdscr, n, attr, color, opts); +} + +int mvwchgat(WINDOW *win, int y, int x, int n, attr_t attr, short color, + const void *opts) +{ + PDC_LOG(("mvwchgat() - called\n")); + + if (wmove(win, y, x) == ERR) + return ERR; + + return wchgat(win, n, attr, color, opts); +} diff --git a/modules/ncurses/pdcurses/pdcurses/beep.c b/modules/ncurses/pdcurses/pdcurses/beep.c new file mode 100644 index 00000000..857706cc --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/beep.c @@ -0,0 +1,68 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +beep +---- + +### Synopsis + + int beep(void); + int flash(void); + +### Description + + beep() sounds the audible bell on the terminal, if possible; + if not, it calls flash(). + + flash() "flashes" the screen, by inverting the foreground and + background of every cell, pausing, and then restoring the + original attributes. + +### Return Value + + These functions return OK. + +### Portability + X/Open BSD SYS V + beep Y Y Y + flash Y Y Y + +**man-end****************************************************************/ + +int beep(void) +{ + PDC_LOG(("beep() - called\n")); + + if (SP->audible) + PDC_beep(); + else + flash(); + + return OK; +} + +int flash(void) +{ + int z, y, x; + + PDC_LOG(("flash() - called\n")); + + /* Reverse each cell; wait; restore the screen */ + + for (z = 0; z < 2; z++) + { + for (y = 0; y < LINES; y++) + for (x = 0; x < COLS; x++) + curscr->_y[y][x] ^= A_REVERSE; + + wrefresh(curscr); + + if (!z) + napms(50); + } + + return OK; +} diff --git a/modules/ncurses/pdcurses/pdcurses/bkgd.c b/modules/ncurses/pdcurses/pdcurses/bkgd.c new file mode 100644 index 00000000..a0e046e1 --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/bkgd.c @@ -0,0 +1,223 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +bkgd +---- + +### Synopsis + + int bkgd(chtype ch); + void bkgdset(chtype ch); + chtype getbkgd(WINDOW *win); + int wbkgd(WINDOW *win, chtype ch); + void wbkgdset(WINDOW *win, chtype ch); + + int bkgrnd(const cchar_t *wch); + void bkgrndset(const cchar_t *wch); + int getbkgrnd(cchar_t *wch); + int wbkgrnd(WINDOW *win, const cchar_t *wch); + void wbkgrndset(WINDOW *win, const cchar_t *wch); + int wgetbkgrnd(WINDOW *win, cchar_t *wch); + +### Description + + bkgdset() and wbkgdset() manipulate the background of a window. + The background is a chtype consisting of any combination of + attributes and a character; it is combined with each chtype + added or inserted to the window by waddch() or winsch(). Only + the attribute part is used to set the background of non-blank + characters, while both character and attributes are used for + blank positions. + + bkgd() and wbkgd() not only change the background, but apply it + immediately to every cell in the window. + + The attributes that are defined with the attrset()/attron() set + of functions take precedence over the background attributes if + there is a conflict (e.g., different color pairs). + +### Return Value + + bkgd() and wbkgd() return OK, unless the window is NULL, in + which case they return ERR. + +### Portability + X/Open BSD SYS V + bkgd Y - 4.0 + bkgdset Y - 4.0 + getbkgd Y + wbkgd Y - 4.0 + wbkgdset Y - 4.0 + bkgrnd Y + bkgrndset Y + getbkgrnd Y + wbkgrnd Y + wbkgrndset Y + wgetbkgrnd Y + +**man-end****************************************************************/ + +int wbkgd(WINDOW *win, chtype ch) +{ + int x, y; + chtype oldcolr, oldch, newcolr, newch, colr, attr; + chtype oldattr = 0, newattr = 0; + chtype *winptr; + + PDC_LOG(("wbkgd() - called\n")); + + if (!win) + return ERR; + + if (win->_bkgd == ch) + return OK; + + oldcolr = win->_bkgd & A_COLOR; + if (oldcolr) + oldattr = (win->_bkgd & A_ATTRIBUTES) ^ oldcolr; + + oldch = win->_bkgd & A_CHARTEXT; + + wbkgdset(win, ch); + + newcolr = win->_bkgd & A_COLOR; + if (newcolr) + newattr = (win->_bkgd & A_ATTRIBUTES) ^ newcolr; + + newch = win->_bkgd & A_CHARTEXT; + + /* what follows is what seems to occur in the System V + implementation of this routine */ + + for (y = 0; y < win->_maxy; y++) + { + for (x = 0; x < win->_maxx; x++) + { + winptr = win->_y[y] + x; + + ch = *winptr; + + /* determine the colors and attributes of the character read + from the window */ + + colr = ch & A_COLOR; + attr = ch & (A_ATTRIBUTES ^ A_COLOR); + + /* if the color is the same as the old background color, + then make it the new background color, otherwise leave it */ + + if (colr == oldcolr) + colr = newcolr; + + /* remove any attributes (non color) from the character that + were part of the old background, then combine the + remaining ones with the new background */ + + attr ^= oldattr; + attr |= newattr; + + /* change character if it is there because it was the old + background character */ + + ch &= A_CHARTEXT; + if (ch == oldch) + ch = newch; + + ch |= (attr | colr); + + *winptr = ch; + + } + } + + touchwin(win); + PDC_sync(win); + return OK; +} + +int bkgd(chtype ch) +{ + PDC_LOG(("bkgd() - called\n")); + + return wbkgd(stdscr, ch); +} + +void wbkgdset(WINDOW *win, chtype ch) +{ + PDC_LOG(("wbkgdset() - called\n")); + + if (win) + { + if (!(ch & A_CHARTEXT)) + ch |= ' '; + + win->_bkgd = ch; + } +} + +void bkgdset(chtype ch) +{ + PDC_LOG(("bkgdset() - called\n")); + + wbkgdset(stdscr, ch); +} + +chtype getbkgd(WINDOW *win) +{ + PDC_LOG(("getbkgd() - called\n")); + + return win ? win->_bkgd : (chtype)ERR; +} + +#ifdef PDC_WIDE +int wbkgrnd(WINDOW *win, const cchar_t *wch) +{ + PDC_LOG(("wbkgrnd() - called\n")); + + return wch ? wbkgd(win, *wch) : ERR; +} + +int bkgrnd(const cchar_t *wch) +{ + PDC_LOG(("bkgrnd() - called\n")); + + return wbkgrnd(stdscr, wch); +} + +void wbkgrndset(WINDOW *win, const cchar_t *wch) +{ + PDC_LOG(("wbkgdset() - called\n")); + + if (wch) + wbkgdset(win, *wch); +} + +void bkgrndset(const cchar_t *wch) +{ + PDC_LOG(("bkgrndset() - called\n")); + + wbkgrndset(stdscr, wch); +} + +int wgetbkgrnd(WINDOW *win, cchar_t *wch) +{ + PDC_LOG(("wgetbkgrnd() - called\n")); + + if (!win || !wch) + return ERR; + + *wch = win->_bkgd; + + return OK; +} + +int getbkgrnd(cchar_t *wch) +{ + PDC_LOG(("getbkgrnd() - called\n")); + + return wgetbkgrnd(stdscr, wch); +} +#endif diff --git a/modules/ncurses/pdcurses/pdcurses/border.c b/modules/ncurses/pdcurses/pdcurses/border.c new file mode 100644 index 00000000..663167f9 --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/border.c @@ -0,0 +1,411 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +border +------ + +### Synopsis + + int border(chtype ls, chtype rs, chtype ts, chtype bs, chtype tl, + chtype tr, chtype bl, chtype br); + int wborder(WINDOW *win, chtype ls, chtype rs, chtype ts, + chtype bs, chtype tl, chtype tr, chtype bl, chtype br); + int box(WINDOW *win, chtype verch, chtype horch); + int hline(chtype ch, int n); + int vline(chtype ch, int n); + int whline(WINDOW *win, chtype ch, int n); + int wvline(WINDOW *win, chtype ch, int n); + int mvhline(int y, int x, chtype ch, int n); + int mvvline(int y, int x, chtype ch, int n); + int mvwhline(WINDOW *win, int y, int x, chtype ch, int n); + int mvwvline(WINDOW *win, int y, int x, chtype ch, int n); + + int border_set(const cchar_t *ls, const cchar_t *rs, + const cchar_t *ts, const cchar_t *bs, + const cchar_t *tl, const cchar_t *tr, + const cchar_t *bl, const cchar_t *br); + int wborder_set(WINDOW *win, const cchar_t *ls, const cchar_t *rs, + const cchar_t *ts, const cchar_t *bs, + const cchar_t *tl, const cchar_t *tr, + const cchar_t *bl, const cchar_t *br); + int box_set(WINDOW *win, const cchar_t *verch, const cchar_t *horch); + int hline_set(const cchar_t *wch, int n); + int vline_set(const cchar_t *wch, int n); + int whline_set(WINDOW *win, const cchar_t *wch, int n); + int wvline_set(WINDOW *win, const cchar_t *wch, int n); + int mvhline_set(int y, int x, const cchar_t *wch, int n); + int mvvline_set(int y, int x, const cchar_t *wch, int n); + int mvwhline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n); + int mvwvline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n); + +### Description + + border(), wborder(), and box() draw a border around the edge of + the window. If any argument is zero, an appropriate default is + used: + + ls left side of border ACS_VLINE + rs right side of border ACS_VLINE + ts top side of border ACS_HLINE + bs bottom side of border ACS_HLINE + tl top left corner of border ACS_ULCORNER + tr top right corner of border ACS_URCORNER + bl bottom left corner of border ACS_LLCORNER + br bottom right corner of border ACS_LRCORNER + + hline() and whline() draw a horizontal line, using ch, starting + from the current cursor position. The cursor position does not + change. The line is at most n characters long, or as many as + will fit in the window. + + vline() and wvline() draw a vertical line, using ch, starting + from the current cursor position. The cursor position does not + change. The line is at most n characters long, or as many as + will fit in the window. + +### Return Value + + These functions return OK on success and ERR on error. + +### Portability + X/Open BSD SYS V + border Y - 4.0 + wborder Y - 4.0 + box Y Y Y + hline Y - 4.0 + vline Y - 4.0 + whline Y - 4.0 + wvline Y - 4.0 + mvhline Y + mvvline Y + mvwhline Y + mvwvline Y + border_set Y + wborder_set Y + box_set Y + hline_set Y + vline_set Y + whline_set Y + wvline_set Y + mvhline_set Y + mvvline_set Y + mvwhline_set Y + mvwvline_set Y + +**man-end****************************************************************/ + +/* _attr_passthru() -- Takes a single chtype 'ch' and checks if the + current attribute of window 'win', as set by wattrset(), and/or the + current background of win, as set by wbkgd(), should by combined with + it. Attributes set explicitly in ch take precedence. */ + +static chtype _attr_passthru(WINDOW *win, chtype ch) +{ + chtype attr; + + /* If the incoming character doesn't have its own attribute, then + use the current attributes for the window. If the incoming + character has attributes, but not a color component, OR the + attributes to the current attributes for the window. If the + incoming character has a color component, use only the attributes + from the incoming character. */ + + attr = ch & A_ATTRIBUTES; + if (!(attr & A_COLOR)) + attr |= win->_attrs; + + /* wrs (4/10/93) -- Apply the same sort of logic for the window + background, in that it only takes precedence if other color + attributes are not there. */ + + if (!(attr & A_COLOR)) + attr |= win->_bkgd & A_ATTRIBUTES; + else + attr |= win->_bkgd & (A_ATTRIBUTES ^ A_COLOR); + + ch = (ch & A_CHARTEXT) | attr; + + return ch; +} + +int wborder(WINDOW *win, chtype ls, chtype rs, chtype ts, chtype bs, + chtype tl, chtype tr, chtype bl, chtype br) +{ + int i, ymax, xmax; + + PDC_LOG(("wborder() - called\n")); + + if (!win) + return ERR; + + ymax = win->_maxy - 1; + xmax = win->_maxx - 1; + + ls = _attr_passthru(win, ls ? ls : ACS_VLINE); + rs = _attr_passthru(win, rs ? rs : ACS_VLINE); + ts = _attr_passthru(win, ts ? ts : ACS_HLINE); + bs = _attr_passthru(win, bs ? bs : ACS_HLINE); + tl = _attr_passthru(win, tl ? tl : ACS_ULCORNER); + tr = _attr_passthru(win, tr ? tr : ACS_URCORNER); + bl = _attr_passthru(win, bl ? bl : ACS_LLCORNER); + br = _attr_passthru(win, br ? br : ACS_LRCORNER); + + for (i = 1; i < xmax; i++) + { + win->_y[0][i] = ts; + win->_y[ymax][i] = bs; + } + + for (i = 1; i < ymax; i++) + { + win->_y[i][0] = ls; + win->_y[i][xmax] = rs; + } + + win->_y[0][0] = tl; + win->_y[0][xmax] = tr; + win->_y[ymax][0] = bl; + win->_y[ymax][xmax] = br; + + for (i = 0; i <= ymax; i++) + { + win->_firstch[i] = 0; + win->_lastch[i] = xmax; + } + + PDC_sync(win); + + return OK; +} + +int border(chtype ls, chtype rs, chtype ts, chtype bs, chtype tl, + chtype tr, chtype bl, chtype br) +{ + PDC_LOG(("border() - called\n")); + + return wborder(stdscr, ls, rs, ts, bs, tl, tr, bl, br); +} + +int box(WINDOW *win, chtype verch, chtype horch) +{ + PDC_LOG(("box() - called\n")); + + return wborder(win, verch, verch, horch, horch, 0, 0, 0, 0); +} + +int whline(WINDOW *win, chtype ch, int n) +{ + chtype *dest; + int startpos, endpos; + + PDC_LOG(("whline() - called\n")); + + if (!win || n < 1) + return ERR; + + startpos = win->_curx; + endpos = min(startpos + n, win->_maxx) - 1; + dest = win->_y[win->_cury]; + ch = _attr_passthru(win, ch ? ch : ACS_HLINE); + + for (n = startpos; n <= endpos; n++) + dest[n] = ch; + + n = win->_cury; + + if (startpos < win->_firstch[n] || win->_firstch[n] == _NO_CHANGE) + win->_firstch[n] = startpos; + + if (endpos > win->_lastch[n]) + win->_lastch[n] = endpos; + + PDC_sync(win); + + return OK; +} + +int hline(chtype ch, int n) +{ + PDC_LOG(("hline() - called\n")); + + return whline(stdscr, ch, n); +} + +int mvhline(int y, int x, chtype ch, int n) +{ + PDC_LOG(("mvhline() - called\n")); + + if (move(y, x) == ERR) + return ERR; + + return whline(stdscr, ch, n); +} + +int mvwhline(WINDOW *win, int y, int x, chtype ch, int n) +{ + PDC_LOG(("mvwhline() - called\n")); + + if (wmove(win, y, x) == ERR) + return ERR; + + return whline(win, ch, n); +} + +int wvline(WINDOW *win, chtype ch, int n) +{ + int endpos, x; + + PDC_LOG(("wvline() - called\n")); + + if (!win || n < 1) + return ERR; + + endpos = min(win->_cury + n, win->_maxy); + x = win->_curx; + + ch = _attr_passthru(win, ch ? ch : ACS_VLINE); + + for (n = win->_cury; n < endpos; n++) + { + win->_y[n][x] = ch; + + if (x < win->_firstch[n] || win->_firstch[n] == _NO_CHANGE) + win->_firstch[n] = x; + + if (x > win->_lastch[n]) + win->_lastch[n] = x; + } + + PDC_sync(win); + + return OK; +} + +int vline(chtype ch, int n) +{ + PDC_LOG(("vline() - called\n")); + + return wvline(stdscr, ch, n); +} + +int mvvline(int y, int x, chtype ch, int n) +{ + PDC_LOG(("mvvline() - called\n")); + + if (move(y, x) == ERR) + return ERR; + + return wvline(stdscr, ch, n); +} + +int mvwvline(WINDOW *win, int y, int x, chtype ch, int n) +{ + PDC_LOG(("mvwvline() - called\n")); + + if (wmove(win, y, x) == ERR) + return ERR; + + return wvline(win, ch, n); +} + +#ifdef PDC_WIDE +int wborder_set(WINDOW *win, const cchar_t *ls, const cchar_t *rs, + const cchar_t *ts, const cchar_t *bs, const cchar_t *tl, + const cchar_t *tr, const cchar_t *bl, const cchar_t *br) +{ + PDC_LOG(("wborder_set() - called\n")); + + return wborder(win, ls ? *ls : 0, rs ? *rs : 0, ts ? *ts : 0, + bs ? *bs : 0, tl ? *tl : 0, tr ? *tr : 0, + bl ? *bl : 0, br ? *br : 0); +} + +int border_set(const cchar_t *ls, const cchar_t *rs, const cchar_t *ts, + const cchar_t *bs, const cchar_t *tl, const cchar_t *tr, + const cchar_t *bl, const cchar_t *br) +{ + PDC_LOG(("border_set() - called\n")); + + return wborder_set(stdscr, ls, rs, ts, bs, tl, tr, bl, br); +} + +int box_set(WINDOW *win, const cchar_t *verch, const cchar_t *horch) +{ + PDC_LOG(("box_set() - called\n")); + + return wborder_set(win, verch, verch, horch, horch, + (const cchar_t *)NULL, (const cchar_t *)NULL, + (const cchar_t *)NULL, (const cchar_t *)NULL); +} + +int whline_set(WINDOW *win, const cchar_t *wch, int n) +{ + PDC_LOG(("whline_set() - called\n")); + + return wch ? whline(win, *wch, n) : ERR; +} + +int hline_set(const cchar_t *wch, int n) +{ + PDC_LOG(("hline_set() - called\n")); + + return whline_set(stdscr, wch, n); +} + +int mvhline_set(int y, int x, const cchar_t *wch, int n) +{ + PDC_LOG(("mvhline_set() - called\n")); + + if (move(y, x) == ERR) + return ERR; + + return whline_set(stdscr, wch, n); +} + +int mvwhline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n) +{ + PDC_LOG(("mvwhline_set() - called\n")); + + if (wmove(win, y, x) == ERR) + return ERR; + + return whline_set(win, wch, n); +} + +int wvline_set(WINDOW *win, const cchar_t *wch, int n) +{ + PDC_LOG(("wvline_set() - called\n")); + + return wch ? wvline(win, *wch, n) : ERR; +} + +int vline_set(const cchar_t *wch, int n) +{ + PDC_LOG(("vline_set() - called\n")); + + return wvline_set(stdscr, wch, n); +} + +int mvvline_set(int y, int x, const cchar_t *wch, int n) +{ + PDC_LOG(("mvvline_set() - called\n")); + + if (move(y, x) == ERR) + return ERR; + + return wvline_set(stdscr, wch, n); +} + +int mvwvline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n) +{ + PDC_LOG(("mvwvline_set() - called\n")); + + if (wmove(win, y, x) == ERR) + return ERR; + + return wvline_set(win, wch, n); +} +#endif diff --git a/modules/ncurses/pdcurses/pdcurses/clear.c b/modules/ncurses/pdcurses/pdcurses/clear.c new file mode 100644 index 00000000..7e14b265 --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/clear.c @@ -0,0 +1,159 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +clear +----- + +### Synopsis + + int clear(void); + int wclear(WINDOW *win); + int erase(void); + int werase(WINDOW *win); + int clrtobot(void); + int wclrtobot(WINDOW *win); + int clrtoeol(void); + int wclrtoeol(WINDOW *win); + +### Description + + erase() and werase() copy blanks (i.e. the background chtype) to + every cell of the window. + + clear() and wclear() are similar to erase() and werase(), but + they also call clearok() to ensure that the the window is + cleared on the next wrefresh(). + + clrtobot() and wclrtobot() clear the window from the current + cursor position to the end of the window. + + clrtoeol() and wclrtoeol() clear the window from the current + cursor position to the end of the current line. + +### Return Value + + All functions return OK on success and ERR on error. + +### Portability + X/Open BSD SYS V + clear Y Y Y + wclear Y Y Y + erase Y Y Y + werase Y Y Y + clrtobot Y Y Y + wclrtobot Y Y Y + clrtoeol Y Y Y + wclrtoeol Y Y Y + +**man-end****************************************************************/ + +int wclrtoeol(WINDOW *win) +{ + int x, y, minx; + chtype blank, *ptr; + + PDC_LOG(("wclrtoeol() - called: Row: %d Col: %d\n", + win->_cury, win->_curx)); + + if (!win) + return ERR; + + y = win->_cury; + x = win->_curx; + + /* wrs (4/10/93) account for window background */ + + blank = win->_bkgd; + + for (minx = x, ptr = &win->_y[y][x]; minx < win->_maxx; minx++, ptr++) + *ptr = blank; + + if (x < win->_firstch[y] || win->_firstch[y] == _NO_CHANGE) + win->_firstch[y] = x; + + win->_lastch[y] = win->_maxx - 1; + + PDC_sync(win); + return OK; +} + +int clrtoeol(void) +{ + PDC_LOG(("clrtoeol() - called\n")); + + return wclrtoeol(stdscr); +} + +int wclrtobot(WINDOW *win) +{ + int savey, savex; + + PDC_LOG(("wclrtobot() - called\n")); + + if (!win) + return ERR; + + savey = win->_cury; + savex = win->_curx; + + /* should this involve scrolling region somehow ? */ + + if (win->_cury + 1 < win->_maxy) + { + win->_curx = 0; + win->_cury++; + for (; win->_maxy > win->_cury; win->_cury++) + wclrtoeol(win); + win->_cury = savey; + win->_curx = savex; + } + wclrtoeol(win); + + PDC_sync(win); + return OK; +} + +int clrtobot(void) +{ + PDC_LOG(("clrtobot() - called\n")); + + return wclrtobot(stdscr); +} + +int werase(WINDOW *win) +{ + PDC_LOG(("werase() - called\n")); + + if (wmove(win, 0, 0) == ERR) + return ERR; + + return wclrtobot(win); +} + +int erase(void) +{ + PDC_LOG(("erase() - called\n")); + + return werase(stdscr); +} + +int wclear(WINDOW *win) +{ + PDC_LOG(("wclear() - called\n")); + + if (!win) + return ERR; + + win->_clear = TRUE; + return werase(win); +} + +int clear(void) +{ + PDC_LOG(("clear() - called\n")); + + return wclear(stdscr); +} diff --git a/modules/ncurses/pdcurses/pdcurses/color.c b/modules/ncurses/pdcurses/pdcurses/color.c new file mode 100644 index 00000000..1b8af10f --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/color.c @@ -0,0 +1,296 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +color +----- + +### Synopsis + + int start_color(void); + int init_pair(short pair, short fg, short bg); + int init_color(short color, short red, short green, short blue); + bool has_colors(void); + bool can_change_color(void); + int color_content(short color, short *red, short *green, short *blue); + int pair_content(short pair, short *fg, short *bg); + + int assume_default_colors(int f, int b); + int use_default_colors(void); + + int PDC_set_line_color(short color); + +### Description + + To use these routines, start_color() must be called, usually + immediately after initscr(). Colors are always used in pairs, + referred to as color-pairs. A color-pair consists of a + foreground color and a background color. A color-pair is + initialized via init_pair(). After initialization, COLOR_PAIR(n) + can be used like any other video attribute. + + start_color() initializes eight basic colors (black, red, green, + yellow, blue, magenta, cyan, and white), and two global + variables; COLORS and COLOR_PAIRS (respectively defining the + maximum number of colors and color-pairs the terminal is capable + of displaying). + + init_pair() changes the definition of a color-pair. It takes + three arguments: the number of the color-pair to be redefined, + and the new values of the foreground and background colors. The + pair number must be between 0 and COLOR_PAIRS - 1, inclusive. + The foreground and background must be between 0 and COLORS - 1, + inclusive. If the color pair was previously initialized, the + screen is refreshed, and all occurrences of that color-pair are + changed to the new definition. + + has_colors() indicates if the terminal supports, and can + maniplulate color. It returns TRUE or FALSE. + + can_change_color() indicates if the terminal has the capability + to change the definition of its colors. + + pair_content() is used to determine what the colors of a given + color-pair consist of. + + assume_default_colors() and use_default_colors() emulate the + ncurses extensions of the same names. assume_default_colors(f, + b) is essentially the same as init_pair(0, f, b) (which isn't + allowed); it redefines the default colors. use_default_colors() + allows the use of -1 as a foreground or background color with + init_pair(), and calls assume_default_colors(-1, -1); -1 + represents the foreground or background color that the terminal + had at startup. If the environment variable PDC_ORIGINAL_COLORS + is set at the time start_color() is called, that's equivalent to + calling use_default_colors(). + + PDC_set_line_color() is used to set the color, globally, for the + color of the lines drawn for the attributes: A_UNDERLINE, A_LEFT + and A_RIGHT. A value of -1 (the default) indicates that the + current foreground color should be used. + + NOTE: COLOR_PAIR() and PAIR_NUMBER() are implemented as macros. + +### Return Value + + All functions return OK on success and ERR on error, except for + has_colors() and can_change_colors(), which return TRUE or FALSE. + +### Portability + X/Open BSD SYS V + start_color Y - 3.2 + init_pair Y - 3.2 + init_color Y - 3.2 + has_colors Y - 3.2 + can_change_color Y - 3.2 + color_content Y - 3.2 + pair_content Y - 3.2 + assume_default_colors - - - + use_default_colors - - - + PDC_set_line_color - - - + +**man-end****************************************************************/ + +#include +#include + +int COLORS = 0; +int COLOR_PAIRS = PDC_COLOR_PAIRS; + +bool pdc_color_started = FALSE; + +/* pair_set[] tracks whether a pair has been set via init_pair() */ + +static bool pair_set[PDC_COLOR_PAIRS]; +static bool default_colors = FALSE; +static short first_col = 0; + +int start_color(void) +{ + PDC_LOG(("start_color() - called\n")); + + if (SP->mono) + return ERR; + + pdc_color_started = TRUE; + + PDC_set_blink(FALSE); /* Also sets COLORS */ + + if (!default_colors && SP->orig_attr && getenv("PDC_ORIGINAL_COLORS")) + default_colors = TRUE; + + PDC_init_atrtab(); + + memset(pair_set, 0, PDC_COLOR_PAIRS); + + return OK; +} + +static void _normalize(short *fg, short *bg) +{ + if (*fg == -1) + *fg = SP->orig_attr ? SP->orig_fore : COLOR_WHITE; + + if (*bg == -1) + *bg = SP->orig_attr ? SP->orig_back : COLOR_BLACK; +} + +int init_pair(short pair, short fg, short bg) +{ + PDC_LOG(("init_pair() - called: pair %d fg %d bg %d\n", pair, fg, bg)); + + if (!pdc_color_started || pair < 1 || pair >= COLOR_PAIRS || + fg < first_col || fg >= COLORS || bg < first_col || bg >= COLORS) + return ERR; + + _normalize(&fg, &bg); + + /* To allow the PDC_PRESERVE_SCREEN option to work, we only reset + curscr if this call to init_pair() alters a color pair created by + the user. */ + + if (pair_set[pair]) + { + short oldfg, oldbg; + + PDC_pair_content(pair, &oldfg, &oldbg); + + if (oldfg != fg || oldbg != bg) + curscr->_clear = TRUE; + } + + PDC_init_pair(pair, fg, bg); + + pair_set[pair] = TRUE; + + return OK; +} + +bool has_colors(void) +{ + PDC_LOG(("has_colors() - called\n")); + + return !(SP->mono); +} + +int init_color(short color, short red, short green, short blue) +{ + PDC_LOG(("init_color() - called\n")); + + if (color < 0 || color >= COLORS || !PDC_can_change_color() || + red < 0 || red > 1000 || green < 0 || green > 1000 || + blue < 0 || blue > 1000) + return ERR; + + return PDC_init_color(color, red, green, blue); +} + +int color_content(short color, short *red, short *green, short *blue) +{ + PDC_LOG(("color_content() - called\n")); + + if (color < 0 || color >= COLORS || !red || !green || !blue) + return ERR; + + if (PDC_can_change_color()) + return PDC_color_content(color, red, green, blue); + else + { + /* Simulated values for platforms that don't support palette + changing */ + + short maxval = (color & 8) ? 1000 : 680; + + *red = (color & COLOR_RED) ? maxval : 0; + *green = (color & COLOR_GREEN) ? maxval : 0; + *blue = (color & COLOR_BLUE) ? maxval : 0; + + return OK; + } +} + +bool can_change_color(void) +{ + PDC_LOG(("can_change_color() - called\n")); + + return PDC_can_change_color(); +} + +int pair_content(short pair, short *fg, short *bg) +{ + PDC_LOG(("pair_content() - called\n")); + + if (pair < 0 || pair >= COLOR_PAIRS || !fg || !bg) + return ERR; + + return PDC_pair_content(pair, fg, bg); +} + +int assume_default_colors(int f, int b) +{ + PDC_LOG(("assume_default_colors() - called: f %d b %d\n", f, b)); + + if (f < -1 || f >= COLORS || b < -1 || b >= COLORS) + return ERR; + + if (pdc_color_started) + { + short fg, bg, oldfg, oldbg; + + fg = f; + bg = b; + + _normalize(&fg, &bg); + + PDC_pair_content(0, &oldfg, &oldbg); + + if (oldfg != fg || oldbg != bg) + curscr->_clear = TRUE; + + PDC_init_pair(0, fg, bg); + } + + return OK; +} + +int use_default_colors(void) +{ + PDC_LOG(("use_default_colors() - called\n")); + + default_colors = TRUE; + first_col = -1; + + return assume_default_colors(-1, -1); +} + +int PDC_set_line_color(short color) +{ + PDC_LOG(("PDC_set_line_color() - called: %d\n", color)); + + if (color < -1 || color >= COLORS) + return ERR; + + SP->line_color = color; + + return OK; +} + +void PDC_init_atrtab(void) +{ + short i, fg, bg; + + if (pdc_color_started && !default_colors) + { + fg = COLOR_WHITE; + bg = COLOR_BLACK; + } + else + fg = bg = -1; + + _normalize(&fg, &bg); + + for (i = 0; i < PDC_COLOR_PAIRS; i++) + PDC_init_pair(i, fg, bg); +} diff --git a/modules/ncurses/pdcurses/pdcurses/debug.c b/modules/ncurses/pdcurses/pdcurses/debug.c new file mode 100644 index 00000000..f76af401 --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/debug.c @@ -0,0 +1,108 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +debug +----- + +### Synopsis + + void traceon(void); + void traceoff(void); + void PDC_debug(const char *, ...); + +### Description + + traceon() and traceoff() toggle the recording of debugging + information to the file "trace". Although not standard, similar + functions are in some other curses implementations. + + PDC_debug() is the function that writes to the file, based on + whether traceon() has been called. It's used from the PDC_LOG() + macro. + + The environment variable PDC_TRACE_FLUSH controls whether the + trace file contents are fflushed after each write. The default + is not. Set it to enable this (may affect performance). + +### Portability + X/Open BSD SYS V + traceon - - - + traceoff - - - + PDC_debug - - - + +**man-end****************************************************************/ + +#include +#include +#include +#include + +FILE *pdc_dbfp = NULL; +static bool want_fflush = FALSE; + +void PDC_debug(const char *fmt, ...) +{ + va_list args; + char hms[9]; + time_t now; + + if (!pdc_dbfp) + return; + + time(&now); + strftime(hms, 9, "%H:%M:%S", localtime(&now)); + fprintf(pdc_dbfp, "At: %8.8ld - %s ", (long) clock(), hms); + + va_start(args, fmt); + vfprintf(pdc_dbfp, fmt, args); + va_end(args); + + /* If you are crashing and losing debugging information, enable this + by setting the environment variable PDC_TRACE_FLUSH. This may + impact performance. */ + + if (want_fflush) + fflush(pdc_dbfp); + + /* If with PDC_TRACE_FLUSH enabled you are still losing logging in + crashes, you may need to add a platform-dependent mechanism to + flush the OS buffers as well (such as fsync() on POSIX) -- but + expect terrible performance. */ +} + +void traceon(void) +{ + char *env; + + if (pdc_dbfp) + fclose(pdc_dbfp); + + /* open debug log file append */ + pdc_dbfp = fopen("trace", "a"); + if (!pdc_dbfp) + { + fprintf(stderr, + "PDC_debug(): Unable to open debug log file\n"); + return; + } + + if ((env = getenv("PDC_TRACE_FLUSH"))) + want_fflush = atoi(env); + + PDC_LOG(("traceon() - called\n")); +} + +void traceoff(void) +{ + if (!pdc_dbfp) + return; + + PDC_LOG(("traceoff() - called\n")); + + fclose(pdc_dbfp); + pdc_dbfp = NULL; + want_fflush = FALSE; +} diff --git a/modules/ncurses/pdcurses/pdcurses/delch.c b/modules/ncurses/pdcurses/pdcurses/delch.c new file mode 100644 index 00000000..2dfc4371 --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/delch.c @@ -0,0 +1,96 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +delch +----- + +### Synopsis + + int delch(void); + int wdelch(WINDOW *win); + int mvdelch(int y, int x); + int mvwdelch(WINDOW *win, int y, int x); + +### Description + + The character under the cursor in the window is deleted. All + characters to the right on the same line are moved to the left + one position and the last character on the line is filled with + a blank. The cursor position does not change (after moving to + y, x if coordinates are specified). + +### Return Value + + All functions return OK on success and ERR on error. + +### Portability + X/Open BSD SYS V + delch Y Y Y + wdelch Y Y Y + mvdelch Y Y Y + mvwdelch Y Y Y + +**man-end****************************************************************/ + +#include + +int wdelch(WINDOW *win) +{ + int y, x, maxx; + chtype *temp1; + + PDC_LOG(("wdelch() - called\n")); + + if (!win) + return ERR; + + y = win->_cury; + x = win->_curx; + maxx = win->_maxx - 1; + temp1 = &win->_y[y][x]; + + memmove(temp1, temp1 + 1, (maxx - x) * sizeof(chtype)); + + /* wrs (4/10/93) account for window background */ + + win->_y[y][maxx] = win->_bkgd; + + win->_lastch[y] = maxx; + + if ((win->_firstch[y] == _NO_CHANGE) || (win->_firstch[y] > x)) + win->_firstch[y] = x; + + PDC_sync(win); + + return OK; +} + +int delch(void) +{ + PDC_LOG(("delch() - called\n")); + + return wdelch(stdscr); +} + +int mvdelch(int y, int x) +{ + PDC_LOG(("mvdelch() - called\n")); + + if (move(y, x) == ERR) + return ERR; + + return wdelch(stdscr); +} + +int mvwdelch(WINDOW *win, int y, int x) +{ + PDC_LOG(("mvwdelch() - called\n")); + + if (wmove(win, y, x) == ERR) + return ERR; + + return wdelch(win); +} diff --git a/modules/ncurses/pdcurses/pdcurses/deleteln.c b/modules/ncurses/pdcurses/pdcurses/deleteln.c new file mode 100644 index 00000000..f5329372 --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/deleteln.c @@ -0,0 +1,211 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +deleteln +-------- + +### Synopsis + + int deleteln(void); + int wdeleteln(WINDOW *win); + int insdelln(int n); + int winsdelln(WINDOW *win, int n); + int insertln(void); + int winsertln(WINDOW *win); + + int mvdeleteln(int y, int x); + int mvwdeleteln(WINDOW *win, int y, int x); + int mvinsertln(int y, int x); + int mvwinsertln(WINDOW *win, int y, int x); + +### Description + + With the deleteln() and wdeleteln() functions, the line under + the cursor in the window is deleted. All lines below the + current line are moved up one line. The bottom line of the + window is cleared. The cursor position does not change. + + With the insertln() and winsertn() functions, a blank line is + inserted above the current line and the bottom line is lost. + + mvdeleteln(), mvwdeleteln(), mvinsertln() and mvwinsertln() + allow moving the cursor and inserting/deleting in one call. + +### Return Value + + All functions return OK on success and ERR on error. + +### Portability + X/Open BSD SYS V + deleteln Y Y Y + wdeleteln Y Y Y + mvdeleteln - - - + mvwdeleteln - - - + insdelln Y - 4.0 + winsdelln Y - 4.0 + insertln Y Y Y + winsertln Y Y Y + mvinsertln - - - + mvwinsertln - - - + +**man-end****************************************************************/ + +int wdeleteln(WINDOW *win) +{ + chtype blank, *temp, *ptr; + int y; + + PDC_LOG(("wdeleteln() - called\n")); + + if (!win) + return ERR; + + /* wrs (4/10/93) account for window background */ + + blank = win->_bkgd; + + temp = win->_y[win->_cury]; + + for (y = win->_cury; y < win->_bmarg; y++) + { + win->_y[y] = win->_y[y + 1]; + win->_firstch[y] = 0; + win->_lastch[y] = win->_maxx - 1; + } + + for (ptr = temp; (ptr - temp < win->_maxx); ptr++) + *ptr = blank; /* make a blank line */ + + if (win->_cury <= win->_bmarg) + { + win->_firstch[win->_bmarg] = 0; + win->_lastch[win->_bmarg] = win->_maxx - 1; + win->_y[win->_bmarg] = temp; + } + + return OK; +} + +int deleteln(void) +{ + PDC_LOG(("deleteln() - called\n")); + + return wdeleteln(stdscr); +} + +int mvdeleteln(int y, int x) +{ + PDC_LOG(("mvdeleteln() - called\n")); + + if (move(y, x) == ERR) + return ERR; + + return wdeleteln(stdscr); +} + +int mvwdeleteln(WINDOW *win, int y, int x) +{ + PDC_LOG(("mvwdeleteln() - called\n")); + + if (wmove(win, y, x) == ERR) + return ERR; + + return wdeleteln(win); +} + +int winsdelln(WINDOW *win, int n) +{ + int i; + + PDC_LOG(("winsdelln() - called\n")); + + if (!win) + return ERR; + + if (n > 0) + { + for (i = 0; i < n; i++) + if (winsertln(win) == ERR) + return ERR; + } + else if (n < 0) + { + n = -n; + for (i = 0; i < n; i++) + if (wdeleteln(win) == ERR) + return ERR; + } + + return OK; +} + +int insdelln(int n) +{ + PDC_LOG(("insdelln() - called\n")); + + return winsdelln(stdscr, n); +} + +int winsertln(WINDOW *win) +{ + chtype blank, *temp, *end; + int y; + + PDC_LOG(("winsertln() - called\n")); + + if (!win) + return ERR; + + /* wrs (4/10/93) account for window background */ + + blank = win->_bkgd; + + temp = win->_y[win->_maxy - 1]; + + for (y = win->_maxy - 1; y > win->_cury; y--) + { + win->_y[y] = win->_y[y - 1]; + win->_firstch[y] = 0; + win->_lastch[y] = win->_maxx - 1; + } + + win->_y[win->_cury] = temp; + + for (end = &temp[win->_maxx - 1]; temp <= end; temp++) + *temp = blank; + + win->_firstch[win->_cury] = 0; + win->_lastch[win->_cury] = win->_maxx - 1; + + return OK; +} + +int insertln(void) +{ + PDC_LOG(("insertln() - called\n")); + + return winsertln(stdscr); +} + +int mvinsertln(int y, int x) +{ + PDC_LOG(("mvinsertln() - called\n")); + + if (move(y, x) == ERR) + return ERR; + + return winsertln(stdscr); +} + +int mvwinsertln(WINDOW *win, int y, int x) +{ + PDC_LOG(("mvwinsertln() - called\n")); + + if (wmove(win, y, x) == ERR) + return ERR; + + return winsertln(win); +} diff --git a/modules/ncurses/pdcurses/pdcurses/deprec.c b/modules/ncurses/pdcurses/pdcurses/deprec.c new file mode 100644 index 00000000..53b0db6a --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/deprec.c @@ -0,0 +1,27 @@ +/* Public Domain Curses */ + +#include + +/* Deprecated functions. These should not be used, and will eventually + be removed. They're here solely for the benefit of applications that + linked to them in older versions of PDCurses. */ + +bool PDC_check_bios_key(void) +{ + return PDC_check_key(); +} + +int PDC_get_bios_key(void) +{ + return PDC_get_key(); +} + +bool PDC_get_ctrl_break(void) +{ + return !SP->raw_inp; +} + +int PDC_set_ctrl_break(bool setting) +{ + return setting ? noraw() : raw(); +} diff --git a/modules/ncurses/pdcurses/pdcurses/getch.c b/modules/ncurses/pdcurses/pdcurses/getch.c new file mode 100644 index 00000000..7f8d8655 --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/getch.c @@ -0,0 +1,413 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +getch +----- + +### Synopsis + + int getch(void); + int wgetch(WINDOW *win); + int mvgetch(int y, int x); + int mvwgetch(WINDOW *win, int y, int x); + int ungetch(int ch); + int flushinp(void); + + int get_wch(wint_t *wch); + int wget_wch(WINDOW *win, wint_t *wch); + int mvget_wch(int y, int x, wint_t *wch); + int mvwget_wch(WINDOW *win, int y, int x, wint_t *wch); + int unget_wch(const wchar_t wch); + + unsigned long PDC_get_key_modifiers(void); + int PDC_save_key_modifiers(bool flag); + int PDC_return_key_modifiers(bool flag); + +### Description + + With the getch(), wgetch(), mvgetch(), and mvwgetch() functions, + a character is read from the terminal associated with the window. + In nodelay mode, if there is no input waiting, the value ERR is + returned. In delay mode, the program will hang until the system + passes text through to the program. Depending on the setting of + cbreak(), this will be after one character or after the first + newline. Unless noecho() has been set, the character will also + be echoed into the designated window. + + If keypad() is TRUE, and a function key is pressed, the token for + that function key will be returned instead of the raw characters. + Possible function keys are defined in with integers + beginning with 0401, whose names begin with KEY_. + + If nodelay(win, TRUE) has been called on the window and no input + is waiting, the value ERR is returned. + + ungetch() places ch back onto the input queue to be returned by + the next call to wgetch(). + + flushinp() throws away any type-ahead that has been typed by the + user and has not yet been read by the program. + + PDC_get_key_modifiers() returns the keyboard modifiers (shift, + control, alt, numlock) effective at the time of the last getch() + call, if PDC_save_key_modifiers(TRUE) has been called before the + getch(). Use the macros PDC_KEY_MODIFIER_* to determine which + modifier(s) were set. PDC_return_key_modifiers() tells getch() + to return modifier keys pressed alone as keystrokes (KEY_ALT_L, + etc.). These may not work on all platforms. + + NOTE: getch() and ungetch() are implemented as macros, to avoid + conflict with many DOS compiler's runtime libraries. + +### Return Value + + These functions return ERR or the value of the character, meta + character or function key token. + +### Portability + X/Open BSD SYS V + getch Y Y Y + wgetch Y Y Y + mvgetch Y Y Y + mvwgetch Y Y Y + ungetch Y Y Y + flushinp Y Y Y + get_wch Y + wget_wch Y + mvget_wch Y + mvwget_wch Y + unget_wch Y + PDC_get_key_modifiers - - - + +**man-end****************************************************************/ + +#define _INBUFSIZ 512 /* size of terminal input buffer */ +#define NUNGETCH 256 /* max # chars to ungetch() */ + +static int c_pindex = 0; /* putter index */ +static int c_gindex = 1; /* getter index */ +static int c_ungind = 0; /* ungetch() push index */ +static int c_ungch[NUNGETCH]; /* array of ungotten chars */ + +static int _mouse_key(void) +{ + int i, key = KEY_MOUSE; + unsigned long mbe = SP->_trap_mbe; + + /* Filter unwanted mouse events */ + + for (i = 0; i < 3; i++) + { + if (pdc_mouse_status.changes & (1 << i)) + { + int shf = i * 5; + short button = pdc_mouse_status.button[i] & BUTTON_ACTION_MASK; + + if ( (!(mbe & (BUTTON1_PRESSED << shf)) && + (button == BUTTON_PRESSED)) + + || (!(mbe & (BUTTON1_CLICKED << shf)) && + (button == BUTTON_CLICKED)) + + || (!(mbe & (BUTTON1_DOUBLE_CLICKED << shf)) && + (button == BUTTON_DOUBLE_CLICKED)) + + || (!(mbe & (BUTTON1_MOVED << shf)) && + (button == BUTTON_MOVED)) + + || (!(mbe & (BUTTON1_RELEASED << shf)) && + (button == BUTTON_RELEASED)) + ) + pdc_mouse_status.changes ^= (1 << i); + } + } + + if (pdc_mouse_status.changes & PDC_MOUSE_MOVED) + { + if (!(mbe & (BUTTON1_MOVED|BUTTON2_MOVED|BUTTON3_MOVED))) + pdc_mouse_status.changes ^= PDC_MOUSE_MOVED; + } + + if (pdc_mouse_status.changes & + (PDC_MOUSE_WHEEL_UP|PDC_MOUSE_WHEEL_DOWN)) + { + if (!(mbe & MOUSE_WHEEL_SCROLL)) + pdc_mouse_status.changes &= + ~(PDC_MOUSE_WHEEL_UP|PDC_MOUSE_WHEEL_DOWN); + } + + if (!pdc_mouse_status.changes) + return -1; + + /* Check for click in slk area */ + + i = PDC_mouse_in_slk(pdc_mouse_status.y, pdc_mouse_status.x); + + if (i) + { + if (pdc_mouse_status.button[0] & (BUTTON_PRESSED|BUTTON_CLICKED)) + key = KEY_F(i); + else + key = -1; + } + + return key; +} + +int wgetch(WINDOW *win) +{ + static int buffer[_INBUFSIZ]; /* character buffer */ + int key, waitcount; + + PDC_LOG(("wgetch() - called\n")); + + if (!win) + return ERR; + + waitcount = 0; + + /* set the number of 1/20th second napms() calls */ + + if (SP->delaytenths) + waitcount = 2 * SP->delaytenths; + else + if (win->_delayms) + { + /* Can't really do millisecond intervals, so delay in + 1/20ths of a second (50ms) */ + + waitcount = win->_delayms / 50; + if (!waitcount) + waitcount = 1; + } + + /* refresh window when wgetch is called if there have been changes + to it and it is not a pad */ + + if (!(win->_flags & _PAD) && ((!win->_leaveit && + (win->_begx + win->_curx != SP->curscol || + win->_begy + win->_cury != SP->cursrow)) || is_wintouched(win))) + wrefresh(win); + + /* if ungotten char exists, remove and return it */ + + if (c_ungind) + return c_ungch[--c_ungind]; + + /* if normal and data in buffer */ + + if ((!SP->raw_inp && !SP->cbreak) && (c_gindex < c_pindex)) + return buffer[c_gindex++]; + + /* prepare to buffer data */ + + c_pindex = 0; + c_gindex = 0; + + /* to get here, no keys are buffered. go and get one. */ + + for (;;) /* loop for any buffering */ + { + /* is there a keystroke ready? */ + + if (!PDC_check_key()) + { + /* if not, handle timeout() and halfdelay() */ + + if (SP->delaytenths || win->_delayms) + { + if (!waitcount) + return ERR; + + waitcount--; + } + else + if (win->_nodelay) + return ERR; + + napms(50); /* sleep for 1/20th second */ + continue; /* then check again */ + } + + /* if there is, fetch it */ + + key = PDC_get_key(); + + if (SP->key_code) + { + /* filter special keys if not in keypad mode */ + + if (!win->_use_keypad) + key = -1; + + /* filter mouse events; translate mouse clicks in the slk + area to function keys */ + + else if (key == KEY_MOUSE) + key = _mouse_key(); + } + + /* unwanted key? loop back */ + + if (key == -1) + continue; + + /* translate CR */ + + if (key == '\r' && SP->autocr && !SP->raw_inp) + key = '\n'; + + /* if echo is enabled */ + + if (SP->echo && !SP->key_code) + { + waddch(win, key); + wrefresh(win); + } + + /* if no buffering */ + + if (SP->raw_inp || SP->cbreak) + return key; + + /* if no overflow, put data in buffer */ + + if (key == '\b') + { + if (c_pindex > c_gindex) + c_pindex--; + } + else + if (c_pindex < _INBUFSIZ - 2) + buffer[c_pindex++] = key; + + /* if we got a line */ + + if (key == '\n' || key == '\r') + return buffer[c_gindex++]; + } +} + +int mvgetch(int y, int x) +{ + PDC_LOG(("mvgetch() - called\n")); + + if (move(y, x) == ERR) + return ERR; + + return wgetch(stdscr); +} + +int mvwgetch(WINDOW *win, int y, int x) +{ + PDC_LOG(("mvwgetch() - called\n")); + + if (wmove(win, y, x) == ERR) + return ERR; + + return wgetch(win); +} + +int PDC_ungetch(int ch) +{ + PDC_LOG(("ungetch() - called\n")); + + if (c_ungind >= NUNGETCH) /* pushback stack full */ + return ERR; + + c_ungch[c_ungind++] = ch; + + return OK; +} + +int flushinp(void) +{ + PDC_LOG(("flushinp() - called\n")); + + PDC_flushinp(); + + c_gindex = 1; /* set indices to kill buffer */ + c_pindex = 0; + c_ungind = 0; /* clear c_ungch array */ + + return OK; +} + +unsigned long PDC_get_key_modifiers(void) +{ + PDC_LOG(("PDC_get_key_modifiers() - called\n")); + + return pdc_key_modifiers; +} + +int PDC_save_key_modifiers(bool flag) +{ + PDC_LOG(("PDC_save_key_modifiers() - called\n")); + + SP->save_key_modifiers = flag; + return OK; +} + +int PDC_return_key_modifiers(bool flag) +{ + PDC_LOG(("PDC_return_key_modifiers() - called\n")); + + SP->return_key_modifiers = flag; + return PDC_modifiers_set(); +} + +#ifdef PDC_WIDE +int wget_wch(WINDOW *win, wint_t *wch) +{ + int key; + + PDC_LOG(("wget_wch() - called\n")); + + if (!wch) + return ERR; + + key = wgetch(win); + + if (key == ERR) + return ERR; + + *wch = key; + + return SP->key_code ? KEY_CODE_YES : OK; +} + +int get_wch(wint_t *wch) +{ + PDC_LOG(("get_wch() - called\n")); + + return wget_wch(stdscr, wch); +} + +int mvget_wch(int y, int x, wint_t *wch) +{ + PDC_LOG(("mvget_wch() - called\n")); + + if (move(y, x) == ERR) + return ERR; + + return wget_wch(stdscr, wch); +} + +int mvwget_wch(WINDOW *win, int y, int x, wint_t *wch) +{ + PDC_LOG(("mvwget_wch() - called\n")); + + if (wmove(win, y, x) == ERR) + return ERR; + + return wget_wch(win, wch); +} + +int unget_wch(const wchar_t wch) +{ + return PDC_ungetch(wch); +} +#endif diff --git a/modules/ncurses/pdcurses/pdcurses/getstr.c b/modules/ncurses/pdcurses/pdcurses/getstr.c new file mode 100644 index 00000000..56f7e340 --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/getstr.c @@ -0,0 +1,474 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +getstr +------ + +### Synopsis + + int getstr(char *str); + int wgetstr(WINDOW *win, char *str); + int mvgetstr(int y, int x, char *str); + int mvwgetstr(WINDOW *win, int y, int x, char *str); + int getnstr(char *str, int n); + int wgetnstr(WINDOW *win, char *str, int n); + int mvgetnstr(int y, int x, char *str, int n); + int mvwgetnstr(WINDOW *win, int y, int x, char *str, int n); + + int get_wstr(wint_t *wstr); + int wget_wstr(WINDOW *win, wint_t *wstr); + int mvget_wstr(int y, int x, wint_t *wstr); + int mvwget_wstr(WINDOW *win, int, int, wint_t *wstr); + int getn_wstr(wint_t *wstr, int n); + int wgetn_wstr(WINDOW *win, wint_t *wstr, int n); + int mvgetn_wstr(int y, int x, wint_t *wstr, int n); + int mvwgetn_wstr(WINDOW *win, int y, int x, wint_t *wstr, int n); + +### Description + + These routines call wgetch() repeatedly to build a string, + interpreting erase and kill characters along the way, until a + newline or carriage return is received. When PDCurses is built + with wide-character support enabled, the narrow-character + functions convert the wgetch()'d values into a multibyte string + in the current locale before returning it. The resulting string + is placed in the area pointed to by *str. The routines with n as + the last argument read at most n characters. + + Note that there's no way to know how long the buffer passed to + wgetstr() is, so use wgetnstr() to avoid buffer overflows. + +### Return Value + + These functions return ERR on failure or any other value on + success. + +### Portability + X/Open BSD SYS V + getstr Y Y Y + wgetstr Y Y Y + mvgetstr Y Y Y + mvwgetstr Y Y Y + getnstr Y - 4.0 + wgetnstr Y - 4.0 + mvgetnstr Y - - + mvwgetnstr Y - - + get_wstr Y + wget_wstr Y + mvget_wstr Y + mvwget_wstr Y + getn_wstr Y + wgetn_wstr Y + mvgetn_wstr Y + mvwgetn_wstr Y + +**man-end****************************************************************/ + +#define MAXLINE 255 + +int wgetnstr(WINDOW *win, char *str, int n) +{ +#ifdef PDC_WIDE + wchar_t wstr[MAXLINE + 1]; + + if (n < 0 || n > MAXLINE) + n = MAXLINE; + + if (wgetn_wstr(win, (wint_t *)wstr, n) == ERR) + return ERR; + + return PDC_wcstombs(str, wstr, n); +#else + int ch, i, num, x, chars; + char *p; + bool stop, oldecho, oldcbreak, oldnodelay; + + PDC_LOG(("wgetnstr() - called\n")); + + if (!win || !str) + return ERR; + + chars = 0; + p = str; + stop = FALSE; + + x = win->_curx; + + oldcbreak = SP->cbreak; /* remember states */ + oldecho = SP->echo; + oldnodelay = win->_nodelay; + + SP->echo = FALSE; /* we do echo ourselves */ + cbreak(); /* ensure each key is returned immediately */ + win->_nodelay = FALSE; /* don't return -1 */ + + wrefresh(win); + + while (!stop) + { + ch = wgetch(win); + + switch (ch) + { + + case '\t': + ch = ' '; + num = TABSIZE - (win->_curx - x) % TABSIZE; + for (i = 0; i < num; i++) + { + if (chars < n) + { + if (oldecho) + waddch(win, ch); + *p++ = ch; + ++chars; + } + else + beep(); + } + break; + + case _ECHAR: /* CTRL-H -- Delete character */ + if (p > str) + { + if (oldecho) + waddstr(win, "\b \b"); + ch = (unsigned char)(*--p); + if ((ch < ' ') && (oldecho)) + waddstr(win, "\b \b"); + chars--; + } + break; + + case _DLCHAR: /* CTRL-U -- Delete line */ + while (p > str) + { + if (oldecho) + waddstr(win, "\b \b"); + ch = (unsigned char)(*--p); + if ((ch < ' ') && (oldecho)) + waddstr(win, "\b \b"); + } + chars = 0; + break; + + case _DWCHAR: /* CTRL-W -- Delete word */ + + while ((p > str) && (*(p - 1) == ' ')) + { + if (oldecho) + waddstr(win, "\b \b"); + + --p; /* remove space */ + chars--; + } + while ((p > str) && (*(p - 1) != ' ')) + { + if (oldecho) + waddstr(win, "\b \b"); + + ch = (unsigned char)(*--p); + if ((ch < ' ') && (oldecho)) + waddstr(win, "\b \b"); + chars--; + } + break; + + case '\n': + case '\r': + stop = TRUE; + if (oldecho) + waddch(win, '\n'); + break; + + default: + if (chars < n) + { + if (!SP->key_code && ch < 0x100) + { + *p++ = ch; + if (oldecho) + waddch(win, ch); + chars++; + } + } + else + beep(); + + break; + + } + + wrefresh(win); + } + + *p = '\0'; + + SP->echo = oldecho; /* restore old settings */ + SP->cbreak = oldcbreak; + win->_nodelay = oldnodelay; + + return OK; +#endif +} + +int getstr(char *str) +{ + PDC_LOG(("getstr() - called\n")); + + return wgetnstr(stdscr, str, MAXLINE); +} + +int wgetstr(WINDOW *win, char *str) +{ + PDC_LOG(("wgetstr() - called\n")); + + return wgetnstr(win, str, MAXLINE); +} + +int mvgetstr(int y, int x, char *str) +{ + PDC_LOG(("mvgetstr() - called\n")); + + if (move(y, x) == ERR) + return ERR; + + return wgetnstr(stdscr, str, MAXLINE); +} + +int mvwgetstr(WINDOW *win, int y, int x, char *str) +{ + PDC_LOG(("mvwgetstr() - called\n")); + + if (wmove(win, y, x) == ERR) + return ERR; + + return wgetnstr(win, str, MAXLINE); +} + +int getnstr(char *str, int n) +{ + PDC_LOG(("getnstr() - called\n")); + + return wgetnstr(stdscr, str, n); +} + +int mvgetnstr(int y, int x, char *str, int n) +{ + PDC_LOG(("mvgetnstr() - called\n")); + + if (move(y, x) == ERR) + return ERR; + + return wgetnstr(stdscr, str, n); +} + +int mvwgetnstr(WINDOW *win, int y, int x, char *str, int n) +{ + PDC_LOG(("mvwgetnstr() - called\n")); + + if (wmove(win, y, x) == ERR) + return ERR; + + return wgetnstr(win, str, n); +} + +#ifdef PDC_WIDE +int wgetn_wstr(WINDOW *win, wint_t *wstr, int n) +{ + int ch, i, num, x, chars; + wint_t *p; + bool stop, oldecho, oldcbreak, oldnodelay; + + PDC_LOG(("wgetn_wstr() - called\n")); + + if (!win || !wstr) + return ERR; + + chars = 0; + p = wstr; + stop = FALSE; + + x = win->_curx; + + oldcbreak = SP->cbreak; /* remember states */ + oldecho = SP->echo; + oldnodelay = win->_nodelay; + + SP->echo = FALSE; /* we do echo ourselves */ + cbreak(); /* ensure each key is returned immediately */ + win->_nodelay = FALSE; /* don't return -1 */ + + wrefresh(win); + + while (!stop) + { + ch = wgetch(win); + + switch (ch) + { + + case '\t': + ch = ' '; + num = TABSIZE - (win->_curx - x) % TABSIZE; + for (i = 0; i < num; i++) + { + if (chars < n) + { + if (oldecho) + waddch(win, ch); + *p++ = ch; + ++chars; + } + else + beep(); + } + break; + + case _ECHAR: /* CTRL-H -- Delete character */ + if (p > wstr) + { + if (oldecho) + waddstr(win, "\b \b"); + ch = *--p; + if ((ch < ' ') && (oldecho)) + waddstr(win, "\b \b"); + chars--; + } + break; + + case _DLCHAR: /* CTRL-U -- Delete line */ + while (p > wstr) + { + if (oldecho) + waddstr(win, "\b \b"); + ch = *--p; + if ((ch < ' ') && (oldecho)) + waddstr(win, "\b \b"); + } + chars = 0; + break; + + case _DWCHAR: /* CTRL-W -- Delete word */ + + while ((p > wstr) && (*(p - 1) == ' ')) + { + if (oldecho) + waddstr(win, "\b \b"); + + --p; /* remove space */ + chars--; + } + while ((p > wstr) && (*(p - 1) != ' ')) + { + if (oldecho) + waddstr(win, "\b \b"); + + ch = *--p; + if ((ch < ' ') && (oldecho)) + waddstr(win, "\b \b"); + chars--; + } + break; + + case '\n': + case '\r': + stop = TRUE; + if (oldecho) + waddch(win, '\n'); + break; + + default: + if (chars < n) + { + if (!SP->key_code) + { + *p++ = ch; + if (oldecho) + waddch(win, ch); + chars++; + } + } + else + beep(); + + break; + + } + + wrefresh(win); + } + + *p = '\0'; + + SP->echo = oldecho; /* restore old settings */ + SP->cbreak = oldcbreak; + win->_nodelay = oldnodelay; + + return OK; +} + +int get_wstr(wint_t *wstr) +{ + PDC_LOG(("get_wstr() - called\n")); + + return wgetn_wstr(stdscr, wstr, MAXLINE); +} + +int wget_wstr(WINDOW *win, wint_t *wstr) +{ + PDC_LOG(("wget_wstr() - called\n")); + + return wgetn_wstr(win, wstr, MAXLINE); +} + +int mvget_wstr(int y, int x, wint_t *wstr) +{ + PDC_LOG(("mvget_wstr() - called\n")); + + if (move(y, x) == ERR) + return ERR; + + return wgetn_wstr(stdscr, wstr, MAXLINE); +} + +int mvwget_wstr(WINDOW *win, int y, int x, wint_t *wstr) +{ + PDC_LOG(("mvwget_wstr() - called\n")); + + if (wmove(win, y, x) == ERR) + return ERR; + + return wgetn_wstr(win, wstr, MAXLINE); +} + +int getn_wstr(wint_t *wstr, int n) +{ + PDC_LOG(("getn_wstr() - called\n")); + + return wgetn_wstr(stdscr, wstr, n); +} + +int mvgetn_wstr(int y, int x, wint_t *wstr, int n) +{ + PDC_LOG(("mvgetn_wstr() - called\n")); + + if (move(y, x) == ERR) + return ERR; + + return wgetn_wstr(stdscr, wstr, n); +} + +int mvwgetn_wstr(WINDOW *win, int y, int x, wint_t *wstr, int n) +{ + PDC_LOG(("mvwgetn_wstr() - called\n")); + + if (wmove(win, y, x) == ERR) + return ERR; + + return wgetn_wstr(win, wstr, n); +} +#endif diff --git a/modules/ncurses/pdcurses/pdcurses/getyx.c b/modules/ncurses/pdcurses/pdcurses/getyx.c new file mode 100644 index 00000000..a11ba547 --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/getyx.c @@ -0,0 +1,145 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +getyx +----- + +### Synopsis + + void getyx(WINDOW *win, int y, int x); + void getparyx(WINDOW *win, int y, int x); + void getbegyx(WINDOW *win, int y, int x); + void getmaxyx(WINDOW *win, int y, int x); + + void getsyx(int y, int x); + int setsyx(int y, int x); + + int getbegy(WINDOW *win); + int getbegx(WINDOW *win); + int getcury(WINDOW *win); + int getcurx(WINDOW *win); + int getpary(WINDOW *win); + int getparx(WINDOW *win); + int getmaxy(WINDOW *win); + int getmaxx(WINDOW *win); + +### Description + + The getyx() macro (defined in curses.h -- the prototypes here + are merely illustrative) puts the current cursor position of the + specified window into y and x. getbegyx() and getmaxyx() return + the starting coordinates and size of the specified window, + respectively. getparyx() returns the starting coordinates of the + parent's window, if the specified window is a subwindow; + otherwise it sets y and x to -1. These are all macros. + + getsyx() gets the coordinates of the virtual screen cursor, and + stores them in y and x. If leaveok() is TRUE, it returns -1, -1. + If lines have been removed with ripoffline(), then getsyx() + includes these lines in its count; so, the returned y and x + values should only be used with setsyx(). + + setsyx() sets the virtual screen cursor to the y, x coordinates. + If y, x are -1, -1, leaveok() is set TRUE. + + getsyx() and setsyx() are meant to be used by a library routine + that manipulates curses windows without altering the position of + the cursor. Note that getsyx() is defined only as a macro. + + getbegy(), getbegx(), getcurx(), getcury(), getmaxy(), + getmaxx(), getpary(), and getparx() return the appropriate + coordinate or size values, or ERR in the case of a NULL window. + +### Portability + X/Open BSD SYS V + getyx Y Y Y + getparyx - - 4.0 + getbegyx - - 3.0 + getmaxyx - - 3.0 + getsyx - - 3.0 + setsyx - - 3.0 + getbegy - - - + getbegx - - - + getcury - - - + getcurx - - - + getpary - - - + getparx - - - + getmaxy - - - + getmaxx - - - + +**man-end****************************************************************/ + +int getbegy(WINDOW *win) +{ + PDC_LOG(("getbegy() - called\n")); + + return win ? win->_begy : ERR; +} + +int getbegx(WINDOW *win) +{ + PDC_LOG(("getbegx() - called\n")); + + return win ? win->_begx : ERR; +} + +int getcury(WINDOW *win) +{ + PDC_LOG(("getcury() - called\n")); + + return win ? win->_cury : ERR; +} + +int getcurx(WINDOW *win) +{ + PDC_LOG(("getcurx() - called\n")); + + return win ? win->_curx : ERR; +} + +int getpary(WINDOW *win) +{ + PDC_LOG(("getpary() - called\n")); + + return win ? win->_pary : ERR; +} + +int getparx(WINDOW *win) +{ + PDC_LOG(("getparx() - called\n")); + + return win ? win->_parx : ERR; +} + +int getmaxy(WINDOW *win) +{ + PDC_LOG(("getmaxy() - called\n")); + + return win ? win->_maxy : ERR; +} + +int getmaxx(WINDOW *win) +{ + PDC_LOG(("getmaxx() - called\n")); + + return win ? win->_maxx : ERR; +} + +int setsyx(int y, int x) +{ + PDC_LOG(("setsyx() - called\n")); + + if(y == -1 && x == -1) + { + curscr->_leaveit = TRUE; + return OK; + } + else + { + curscr->_leaveit = FALSE; + return wmove(curscr, y, x); + } +} diff --git a/modules/ncurses/pdcurses/pdcurses/inch.c b/modules/ncurses/pdcurses/pdcurses/inch.c new file mode 100644 index 00000000..97259b95 --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/inch.c @@ -0,0 +1,127 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +inch +---- + +### Synopsis + + chtype inch(void); + chtype winch(WINDOW *win); + chtype mvinch(int y, int x); + chtype mvwinch(WINDOW *win, int y, int x); + + int in_wch(cchar_t *wcval); + int win_wch(WINDOW *win, cchar_t *wcval); + int mvin_wch(int y, int x, cchar_t *wcval); + int mvwin_wch(WINDOW *win, int y, int x, cchar_t *wcval); + +### Description + + The inch() functions retrieve the character and attribute from + the current or specified window position, in the form of a + chtype. If a NULL window is specified, (chtype)ERR is returned. + + The in_wch() functions are the wide-character versions; instead + of returning a chtype, they store a cchar_t at the address + specified by wcval, and return OK or ERR. (No value is stored + when ERR is returned.) Note that in PDCurses, chtype and cchar_t + are the same. + +### Portability + X/Open BSD SYS V + inch Y Y Y + winch Y Y Y + mvinch Y Y Y + mvwinch Y Y Y + in_wch Y + win_wch Y + mvin_wch Y + mvwin_wch Y + +**man-end****************************************************************/ + +chtype winch(WINDOW *win) +{ + PDC_LOG(("winch() - called\n")); + + if (!win) + return (chtype)ERR; + + return win->_y[win->_cury][win->_curx]; +} + +chtype inch(void) +{ + PDC_LOG(("inch() - called\n")); + + return winch(stdscr); +} + +chtype mvinch(int y, int x) +{ + PDC_LOG(("mvinch() - called\n")); + + if (move(y, x) == ERR) + return (chtype)ERR; + + return stdscr->_y[stdscr->_cury][stdscr->_curx]; +} + +chtype mvwinch(WINDOW *win, int y, int x) +{ + PDC_LOG(("mvwinch() - called\n")); + + if (wmove(win, y, x) == ERR) + return (chtype)ERR; + + return win->_y[win->_cury][win->_curx]; +} + +#ifdef PDC_WIDE +int win_wch(WINDOW *win, cchar_t *wcval) +{ + PDC_LOG(("win_wch() - called\n")); + + if (!win || !wcval) + return ERR; + + *wcval = win->_y[win->_cury][win->_curx]; + + return OK; +} + +int in_wch(cchar_t *wcval) +{ + PDC_LOG(("in_wch() - called\n")); + + return win_wch(stdscr, wcval); +} + +int mvin_wch(int y, int x, cchar_t *wcval) +{ + PDC_LOG(("mvin_wch() - called\n")); + + if (!wcval || (move(y, x) == ERR)) + return ERR; + + *wcval = stdscr->_y[stdscr->_cury][stdscr->_curx]; + + return OK; +} + +int mvwin_wch(WINDOW *win, int y, int x, cchar_t *wcval) +{ + PDC_LOG(("mvwin_wch() - called\n")); + + if (!wcval || (wmove(win, y, x) == ERR)) + return ERR; + + *wcval = win->_y[win->_cury][win->_curx]; + + return OK; +} +#endif diff --git a/modules/ncurses/pdcurses/pdcurses/inchstr.c b/modules/ncurses/pdcurses/pdcurses/inchstr.c new file mode 100644 index 00000000..b107fb0e --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/inchstr.c @@ -0,0 +1,214 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +inchstr +------- + +### Synopsis + + int inchstr(chtype *ch); + int inchnstr(chtype *ch, int n); + int winchstr(WINDOW *win, chtype *ch); + int winchnstr(WINDOW *win, chtype *ch, int n); + int mvinchstr(int y, int x, chtype *ch); + int mvinchnstr(int y, int x, chtype *ch, int n); + int mvwinchstr(WINDOW *, int y, int x, chtype *ch); + int mvwinchnstr(WINDOW *, int y, int x, chtype *ch, int n); + + int in_wchstr(cchar_t *wch); + int in_wchnstr(cchar_t *wch, int n); + int win_wchstr(WINDOW *win, cchar_t *wch); + int win_wchnstr(WINDOW *win, cchar_t *wch, int n); + int mvin_wchstr(int y, int x, cchar_t *wch); + int mvin_wchnstr(int y, int x, cchar_t *wch, int n); + int mvwin_wchstr(WINDOW *win, int y, int x, cchar_t *wch); + int mvwin_wchnstr(WINDOW *win, int y, int x, cchar_t *wch, int n); + +### Description + + These routines read a chtype or cchar_t string from the window, + starting at the current or specified position, and ending at the + right margin, or after n elements, whichever is less. + +### Return Value + + All functions return the number of elements read, or ERR on + error. + +### Portability + X/Open BSD SYS V + inchstr Y - 4.0 + winchstr Y - 4.0 + mvinchstr Y - 4.0 + mvwinchstr Y - 4.0 + inchnstr Y - 4.0 + winchnstr Y - 4.0 + mvinchnstr Y - 4.0 + mvwinchnstr Y - 4.0 + in_wchstr Y + win_wchstr Y + mvin_wchstr Y + mvwin_wchstr Y + in_wchnstr Y + win_wchnstr Y + mvin_wchnstr Y + mvwin_wchnstr Y + +**man-end****************************************************************/ + +int winchnstr(WINDOW *win, chtype *ch, int n) +{ + chtype *src; + int i; + + PDC_LOG(("winchnstr() - called\n")); + + if (!win || !ch || n < 0) + return ERR; + + if ((win->_curx + n) > win->_maxx) + n = win->_maxx - win->_curx; + + src = win->_y[win->_cury] + win->_curx; + + for (i = 0; i < n; i++) + *ch++ = *src++; + + *ch = (chtype)0; + + return OK; +} + +int inchstr(chtype *ch) +{ + PDC_LOG(("inchstr() - called\n")); + + return winchnstr(stdscr, ch, stdscr->_maxx - stdscr->_curx); +} + +int winchstr(WINDOW *win, chtype *ch) +{ + PDC_LOG(("winchstr() - called\n")); + + return winchnstr(win, ch, win->_maxx - win->_curx); +} + +int mvinchstr(int y, int x, chtype *ch) +{ + PDC_LOG(("mvinchstr() - called: y %d x %d\n", y, x)); + + if (move(y, x) == ERR) + return ERR; + + return winchnstr(stdscr, ch, stdscr->_maxx - stdscr->_curx); +} + +int mvwinchstr(WINDOW *win, int y, int x, chtype *ch) +{ + PDC_LOG(("mvwinchstr() - called:\n")); + + if (wmove(win, y, x) == ERR) + return ERR; + + return winchnstr(win, ch, win->_maxx - win->_curx); +} + +int inchnstr(chtype *ch, int n) +{ + PDC_LOG(("inchnstr() - called\n")); + + return winchnstr(stdscr, ch, n); +} + +int mvinchnstr(int y, int x, chtype *ch, int n) +{ + PDC_LOG(("mvinchnstr() - called: y %d x %d n %d\n", y, x, n)); + + if (move(y, x) == ERR) + return ERR; + + return winchnstr(stdscr, ch, n); +} + +int mvwinchnstr(WINDOW *win, int y, int x, chtype *ch, int n) +{ + PDC_LOG(("mvwinchnstr() - called: y %d x %d n %d \n", y, x, n)); + + if (wmove(win, y, x) == ERR) + return ERR; + + return winchnstr(win, ch, n); +} + +#ifdef PDC_WIDE +int win_wchnstr(WINDOW *win, cchar_t *wch, int n) +{ + PDC_LOG(("win_wchnstr() - called\n")); + + return winchnstr(win, wch, n); +} + +int in_wchstr(cchar_t *wch) +{ + PDC_LOG(("in_wchstr() - called\n")); + + return win_wchnstr(stdscr, wch, stdscr->_maxx - stdscr->_curx); +} + +int win_wchstr(WINDOW *win, cchar_t *wch) +{ + PDC_LOG(("win_wchstr() - called\n")); + + return win_wchnstr(win, wch, win->_maxx - win->_curx); +} + +int mvin_wchstr(int y, int x, cchar_t *wch) +{ + PDC_LOG(("mvin_wchstr() - called: y %d x %d\n", y, x)); + + if (move(y, x) == ERR) + return ERR; + + return win_wchnstr(stdscr, wch, stdscr->_maxx - stdscr->_curx); +} + +int mvwin_wchstr(WINDOW *win, int y, int x, cchar_t *wch) +{ + PDC_LOG(("mvwin_wchstr() - called:\n")); + + if (wmove(win, y, x) == ERR) + return ERR; + + return win_wchnstr(win, wch, win->_maxx - win->_curx); +} + +int in_wchnstr(cchar_t *wch, int n) +{ + PDC_LOG(("in_wchnstr() - called\n")); + + return win_wchnstr(stdscr, wch, n); +} + +int mvin_wchnstr(int y, int x, cchar_t *wch, int n) +{ + PDC_LOG(("mvin_wchnstr() - called: y %d x %d n %d\n", y, x, n)); + + if (move(y, x) == ERR) + return ERR; + + return win_wchnstr(stdscr, wch, n); +} + +int mvwin_wchnstr(WINDOW *win, int y, int x, cchar_t *wch, int n) +{ + PDC_LOG(("mvwinchnstr() - called: y %d x %d n %d \n", y, x, n)); + + if (wmove(win, y, x) == ERR) + return ERR; + + return win_wchnstr(win, wch, n); +} +#endif diff --git a/modules/ncurses/pdcurses/pdcurses/initscr.c b/modules/ncurses/pdcurses/pdcurses/initscr.c new file mode 100644 index 00000000..09708755 --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/initscr.c @@ -0,0 +1,342 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +initscr +------- + +### Synopsis + + WINDOW *initscr(void); + WINDOW *Xinitscr(int argc, char *argv[]); + int endwin(void); + bool isendwin(void); + SCREEN *newterm(const char *type, FILE *outfd, FILE *infd); + SCREEN *set_term(SCREEN *new); + void delscreen(SCREEN *sp); + + int resize_term(int nlines, int ncols); + bool is_termresized(void); + const char *curses_version(void); + +### Description + + initscr() should be the first curses routine called. It will + initialize all curses data structures, and arrange that the + first call to refresh() will clear the screen. In case of + error, initscr() will write a message to standard error and end + the program. + + endwin() should be called before exiting or escaping from curses + mode temporarily. It will restore tty modes, move the cursor to + the lower left corner of the screen and reset the terminal into + the proper non-visual mode. To resume curses after a temporary + escape, call refresh() or doupdate(). + + isendwin() returns TRUE if endwin() has been called without a + subsequent refresh, unless SP is NULL. + + In some implementations of curses, newterm() allows the use of + multiple terminals. Here, it's just an alternative interface for + initscr(). It always returns SP, or NULL. + + delscreen() frees the memory allocated by newterm() or + initscr(), since it's not freed by endwin(). This function is + usually not needed. In PDCurses, the parameter must be the + value of SP, and delscreen() sets SP to NULL. + + set_term() does nothing meaningful in PDCurses, but is included + for compatibility with other curses implementations. + + resize_term() is effectively two functions: When called with + nonzero values for nlines and ncols, it attempts to resize the + screen to the given size. When called with (0, 0), it merely + adjusts the internal structures to match the current size after + the screen is resized by the user. On the currently supported + platforms, SDL, Windows console, and X11 allow user resizing, while + DOS, OS/2, SDL and Windows console allow programmatic resizing. If + you want to support user resizing, you should check for getch() + returning KEY_RESIZE, and/or call is_termresized() at appropriate + times; if either condition occurs, call resize_term(0, 0). Then, with + either user or programmatic resizing, you'll have to resize any + windows you've created, as appropriate; resize_term() only + handles stdscr and curscr. + + is_termresized() returns TRUE if the curses screen has been + resized by the user, and a call to resize_term() is needed. + Checking for KEY_RESIZE is generally preferable, unless you're + not handling the keyboard. + + curses_version() returns a string describing the version of + PDCurses. + +### Return Value + + All functions return NULL on error, except endwin(), which always + returns OK, and resize_term(), which returns either OK or ERR. + +### Portability + X/Open BSD SYS V + initscr Y Y Y + endwin Y Y Y + isendwin Y - 3.0 + newterm Y - Y + set_term Y - Y + delscreen Y - 4.0 + resize_term - - - + is_termresized - - - + curses_version - - - + +**man-end****************************************************************/ + +#include + +char ttytype[128]; + +const char *_curses_notice = "PDCurses 3.5 - Public Domain 2018"; + +SCREEN *SP = (SCREEN*)NULL; /* curses variables */ +WINDOW *curscr = (WINDOW *)NULL; /* the current screen image */ +WINDOW *stdscr = (WINDOW *)NULL; /* the default screen window */ +WINDOW *pdc_lastscr = (WINDOW *)NULL; /* the last screen image */ + +int LINES = 0; /* current terminal height */ +int COLS = 0; /* current terminal width */ +int TABSIZE = 8; + +MOUSE_STATUS Mouse_status, pdc_mouse_status; + +extern RIPPEDOFFLINE linesripped[5]; +extern char linesrippedoff; + +WINDOW *Xinitscr(int argc, char *argv[]) +{ + int i; + + PDC_LOG(("Xinitscr() - called\n")); + + if (SP && SP->alive) + return NULL; + + if (PDC_scr_open(argc, argv) == ERR) + { + fprintf(stderr, "initscr(): Unable to create SP\n"); + exit(8); + } + + SP->autocr = TRUE; /* cr -> lf by default */ + SP->raw_out = FALSE; /* tty I/O modes */ + SP->raw_inp = FALSE; /* tty I/O modes */ + SP->cbreak = TRUE; + SP->save_key_modifiers = FALSE; + SP->return_key_modifiers = FALSE; + SP->echo = TRUE; + SP->visibility = 1; + SP->resized = FALSE; + SP->_trap_mbe = 0L; + SP->_map_mbe_to_key = 0L; + SP->linesrippedoff = 0; + SP->linesrippedoffontop = 0; + SP->delaytenths = 0; + SP->line_color = -1; + + SP->orig_cursor = PDC_get_cursor_mode(); + + LINES = SP->lines; + COLS = SP->cols; + + if (LINES < 2 || COLS < 2) + { + fprintf(stderr, "initscr(): LINES=%d COLS=%d: too small.\n", + LINES, COLS); + exit(4); + } + + if ((curscr = newwin(LINES, COLS, 0, 0)) == (WINDOW *)NULL) + { + fprintf(stderr, "initscr(): Unable to create curscr.\n"); + exit(2); + } + + if ((pdc_lastscr = newwin(LINES, COLS, 0, 0)) == (WINDOW *)NULL) + { + fprintf(stderr, "initscr(): Unable to create pdc_lastscr.\n"); + exit(2); + } + + wattrset(pdc_lastscr, (chtype)(-1)); + werase(pdc_lastscr); + + PDC_slk_initialize(); + LINES -= SP->slklines; + + /* We have to sort out ripped off lines here, and reduce the height + of stdscr by the number of lines ripped off */ + + for (i = 0; i < linesrippedoff; i++) + { + if (linesripped[i].line < 0) + (*linesripped[i].init)(newwin(1, COLS, LINES - 1, 0), COLS); + else + (*linesripped[i].init)(newwin(1, COLS, + SP->linesrippedoffontop++, 0), COLS); + + SP->linesrippedoff++; + LINES--; + } + + linesrippedoff = 0; + + if (!(stdscr = newwin(LINES, COLS, SP->linesrippedoffontop, 0))) + { + fprintf(stderr, "initscr(): Unable to create stdscr.\n"); + exit(1); + } + + wclrtobot(stdscr); + + /* If preserving the existing screen, don't allow a screen clear */ + + if (SP->_preserve) + { + untouchwin(curscr); + untouchwin(stdscr); + stdscr->_clear = FALSE; + curscr->_clear = FALSE; + } + else + curscr->_clear = TRUE; + + PDC_init_atrtab(); /* set up default colors */ + + MOUSE_X_POS = MOUSE_Y_POS = -1; + BUTTON_STATUS(1) = BUTTON_RELEASED; + BUTTON_STATUS(2) = BUTTON_RELEASED; + BUTTON_STATUS(3) = BUTTON_RELEASED; + Mouse_status.changes = 0; + + SP->alive = TRUE; + + def_shell_mode(); + + sprintf(ttytype, "pdcurses|PDCurses for %s", PDC_sysname()); + + return stdscr; +} + +WINDOW *initscr(void) +{ + PDC_LOG(("initscr() - called\n")); + + return Xinitscr(0, NULL); +} + +int endwin(void) +{ + PDC_LOG(("endwin() - called\n")); + + /* Allow temporary exit from curses using endwin() */ + + def_prog_mode(); + PDC_scr_close(); + + SP->alive = FALSE; + + return OK; +} + +bool isendwin(void) +{ + PDC_LOG(("isendwin() - called\n")); + + return SP ? !(SP->alive) : FALSE; +} + +SCREEN *newterm(const char *type, FILE *outfd, FILE *infd) +{ + PDC_LOG(("newterm() - called\n")); + + return Xinitscr(0, NULL) ? SP : NULL; +} + +SCREEN *set_term(SCREEN *new) +{ + PDC_LOG(("set_term() - called\n")); + + /* We only support one screen */ + + return (new == SP) ? SP : NULL; +} + +void delscreen(SCREEN *sp) +{ + PDC_LOG(("delscreen() - called\n")); + + if (sp != SP) + return; + + PDC_slk_free(); /* free the soft label keys, if needed */ + + delwin(stdscr); + delwin(curscr); + delwin(pdc_lastscr); + stdscr = (WINDOW *)NULL; + curscr = (WINDOW *)NULL; + pdc_lastscr = (WINDOW *)NULL; + + SP->alive = FALSE; + + PDC_scr_free(); /* free SP and pdc_atrtab */ + + SP = (SCREEN *)NULL; +} + +int resize_term(int nlines, int ncols) +{ + PDC_LOG(("resize_term() - called: nlines %d\n", nlines)); + + if (!stdscr || PDC_resize_screen(nlines, ncols) == ERR) + return ERR; + + SP->lines = PDC_get_rows(); + LINES = SP->lines - SP->linesrippedoff - SP->slklines; + SP->cols = COLS = PDC_get_columns(); + + if (wresize(curscr, SP->lines, SP->cols) == ERR || + wresize(stdscr, LINES, COLS) == ERR || + wresize(pdc_lastscr, SP->lines, SP->cols) == ERR) + return ERR; + + werase(pdc_lastscr); + curscr->_clear = TRUE; + + if (SP->slk_winptr) + { + if (wresize(SP->slk_winptr, SP->slklines, COLS) == ERR) + return ERR; + + wmove(SP->slk_winptr, 0, 0); + wclrtobot(SP->slk_winptr); + PDC_slk_initialize(); + slk_noutrefresh(); + } + + touchwin(stdscr); + wnoutrefresh(stdscr); + + return OK; +} + +bool is_termresized(void) +{ + PDC_LOG(("is_termresized() - called\n")); + + return SP->resized; +} + +const char *curses_version(void) +{ + return _curses_notice; +} diff --git a/modules/ncurses/pdcurses/pdcurses/inopts.c b/modules/ncurses/pdcurses/pdcurses/inopts.c new file mode 100644 index 00000000..948396c6 --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/inopts.c @@ -0,0 +1,324 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +inopts +------ + +### Synopsis + + int cbreak(void); + int nocbreak(void); + int echo(void); + int noecho(void); + int halfdelay(int tenths); + int intrflush(WINDOW *win, bool bf); + int keypad(WINDOW *win, bool bf); + int meta(WINDOW *win, bool bf); + int nl(void); + int nonl(void); + int nodelay(WINDOW *win, bool bf); + int notimeout(WINDOW *win, bool bf); + int raw(void); + int noraw(void); + void noqiflush(void); + void qiflush(void); + void timeout(int delay); + void wtimeout(WINDOW *win, int delay); + int typeahead(int fildes); + + int crmode(void); + int nocrmode(void); + +### Description + + cbreak() and nocbreak() toggle cbreak mode. In cbreak mode, + characters typed by the user are made available immediately, and + erase/kill character processing is not performed. In nocbreak + mode, typed characters are buffered until a newline or carriage + return. Interrupt and flow control characters are unaffected by + this mode. PDCurses always starts in cbreak mode. + + echo() and noecho() control whether typed characters are echoed + by the input routine. Initially, input characters are echoed. + Subsequent calls to echo() and noecho() do not flush type-ahead. + + halfdelay() is similar to cbreak(), but allows for a time limit + to be specified, in tenths of a second. This causes getch() to + block for that period before returning ERR if no key has been + received. tenths must be between 1 and 255. + + keypad() controls whether getch() returns function/special keys + as single key codes (e.g., the left arrow key as KEY_LEFT). Per + X/Open, the default for keypad mode is OFF. You'll probably want + it on. With keypad mode off, if a special key is pressed, + getch() does nothing or returns ERR. + + nodelay() controls whether wgetch() is a non-blocking call. If + the option is enabled, and no input is ready, wgetch() will + return ERR. If disabled, wgetch() will hang until input is + ready. + + nl() enables the translation of a carriage return into a newline + on input. nonl() disables this. Initially, the translation does + occur. + + raw() and noraw() toggle raw mode. Raw mode is similar to cbreak + mode, in that characters typed are immediately passed through to + the user program. The difference is that in raw mode, the INTR, + QUIT, SUSP, and STOP characters are passed through without being + interpreted, and without generating a signal. + + In PDCurses, the meta() function sets raw mode on or off. + + timeout() and wtimeout() set blocking or non-blocking reads for + the specified window. The delay is measured in milliseconds. If + it's negative, a blocking read is used; if zero, then non- + blocking reads are done -- if no input is waiting, ERR is + returned immediately. If the delay is positive, the read blocks + for the delay period; if the period expires, ERR is returned. + + intrflush(), notimeout(), noqiflush(), qiflush() and typeahead() + do nothing in PDCurses, but are included for compatibility with + other curses implementations. + + crmode() and nocrmode() are archaic equivalents to cbreak() and + nocbreak(), respectively. + +### Return Value + + All functions return OK on success and ERR on error. + +### Portability + X/Open BSD SYS V + cbreak Y Y Y + nocbreak Y Y Y + echo Y Y Y + noecho Y Y Y + halfdelay Y - Y + intrflush Y - Y + keypad Y - Y + meta Y - Y + nl Y Y Y + nonl Y Y Y + nodelay Y - Y + notimeout Y - Y + raw Y Y Y + noraw Y Y Y + noqiflush Y - Y + qiflush Y - Y + timeout Y - Y + wtimeout Y - Y + typeahead Y - Y + crmode - + nocrmode - + +**man-end****************************************************************/ + +int cbreak(void) +{ + PDC_LOG(("cbreak() - called\n")); + + SP->cbreak = TRUE; + + return OK; +} + +int nocbreak(void) +{ + PDC_LOG(("nocbreak() - called\n")); + + SP->cbreak = FALSE; + SP->delaytenths = 0; + + return OK; +} + +int echo(void) +{ + PDC_LOG(("echo() - called\n")); + + SP->echo = TRUE; + + return OK; +} + +int noecho(void) +{ + PDC_LOG(("noecho() - called\n")); + + SP->echo = FALSE; + + return OK; +} + +int halfdelay(int tenths) +{ + PDC_LOG(("halfdelay() - called\n")); + + if (tenths < 1 || tenths > 255) + return ERR; + + SP->delaytenths = tenths; + + return OK; +} + +int intrflush(WINDOW *win, bool bf) +{ + PDC_LOG(("intrflush() - called\n")); + + return OK; +} + +int keypad(WINDOW *win, bool bf) +{ + PDC_LOG(("keypad() - called\n")); + + if (!win) + return ERR; + + win->_use_keypad = bf; + + return OK; +} + +int meta(WINDOW *win, bool bf) +{ + PDC_LOG(("meta() - called\n")); + + SP->raw_inp = bf; + + return OK; +} + +int nl(void) +{ + PDC_LOG(("nl() - called\n")); + + SP->autocr = TRUE; + + return OK; +} + +int nonl(void) +{ + PDC_LOG(("nonl() - called\n")); + + SP->autocr = FALSE; + + return OK; +} + +int nodelay(WINDOW *win, bool flag) +{ + PDC_LOG(("nodelay() - called\n")); + + if (!win) + return ERR; + + win->_nodelay = flag; + + return OK; +} + +int notimeout(WINDOW *win, bool flag) +{ + PDC_LOG(("notimeout() - called\n")); + + return OK; +} + +int raw(void) +{ + PDC_LOG(("raw() - called\n")); + + PDC_set_keyboard_binary(TRUE); + SP->raw_inp = TRUE; + + return OK; +} + +int noraw(void) +{ + PDC_LOG(("noraw() - called\n")); + + PDC_set_keyboard_binary(FALSE); + SP->raw_inp = FALSE; + + return OK; +} + +void noqiflush(void) +{ + PDC_LOG(("noqiflush() - called\n")); +} + +void qiflush(void) +{ + PDC_LOG(("qiflush() - called\n")); +} + +int typeahead(int fildes) +{ + PDC_LOG(("typeahead() - called\n")); + + return OK; +} + +void wtimeout(WINDOW *win, int delay) +{ + PDC_LOG(("wtimeout() - called\n")); + + if (!win) + return; + + if (delay < 0) + { + /* This causes a blocking read on the window, so turn on delay + mode */ + + win->_nodelay = FALSE; + win->_delayms = 0; + } + else if (!delay) + { + /* This causes a non-blocking read on the window, so turn off + delay mode */ + + win->_nodelay = TRUE; + win->_delayms = 0; + } + else + { + /* This causes the read on the window to delay for the number of + milliseconds. Also forces the window into non-blocking read + mode */ + + /*win->_nodelay = TRUE;*/ + win->_delayms = delay; + } +} + +void timeout(int delay) +{ + PDC_LOG(("timeout() - called\n")); + + wtimeout(stdscr, delay); +} + +int crmode(void) +{ + PDC_LOG(("crmode() - called\n")); + + return cbreak(); +} + +int nocrmode(void) +{ + PDC_LOG(("nocrmode() - called\n")); + + return nocbreak(); +} diff --git a/modules/ncurses/pdcurses/pdcurses/insch.c b/modules/ncurses/pdcurses/pdcurses/insch.c new file mode 100644 index 00000000..33d0c308 --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/insch.c @@ -0,0 +1,271 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +insch +----- + +### Synopsis + + int insch(chtype ch); + int winsch(WINDOW *win, chtype ch); + int mvinsch(int y, int x, chtype ch); + int mvwinsch(WINDOW *win, int y, int x, chtype ch); + + int insrawch(chtype ch); + int winsrawch(WINDOW *win, chtype ch); + int mvinsrawch(int y, int x, chtype ch); + int mvwinsrawch(WINDOW *win, int y, int x, chtype ch); + + int ins_wch(const cchar_t *wch); + int wins_wch(WINDOW *win, const cchar_t *wch); + int mvins_wch(int y, int x, const cchar_t *wch); + int mvwins_wch(WINDOW *win, int y, int x, const cchar_t *wch); + +### Description + + The insch() functions insert a chtype into the window at the + current or specified cursor position. The cursor is NOT + advanced. A newline is equivalent to clrtoeol(); tabs are + expanded; other control characters are converted as with + unctrl(). + + The ins_wch() functions are the wide-character + equivalents, taking cchar_t pointers rather than chtypes. + + Video attributes can be combined with a character by ORing + them into the parameter. Text, including attributes, can be + copied from one place to another using inch() and insch(). + + insrawch() etc. are PDCurses-specific wrappers for insch() etc. + that disable the translation of control characters. + +### Return Value + + All functions return OK on success and ERR on error. + +### Portability + X/Open BSD SYS V + insch Y Y Y + winsch Y Y Y + mvinsch Y Y Y + mvwinsch Y Y Y + insrawch - - - + winsrawch - - - + ins_wch Y + wins_wch Y + mvins_wch Y + mvwins_wch Y + +**man-end****************************************************************/ + +#include + +int winsch(WINDOW *win, chtype ch) +{ + int x, y; + chtype attr; + bool xlat; + + PDC_LOG(("winsch() - called: win=%p ch=%x (text=%c attr=0x%x)\n", + win, ch, ch & A_CHARTEXT, ch & A_ATTRIBUTES)); + + if (!win) + return ERR; + + x = win->_curx; + y = win->_cury; + + if (y > win->_maxy || x > win->_maxx || y < 0 || x < 0) + return ERR; + + xlat = !SP->raw_out && !(ch & A_ALTCHARSET); + attr = ch & A_ATTRIBUTES; + ch &= A_CHARTEXT; + + if (xlat && (ch < ' ' || ch == 0x7f)) + { + int x2; + + switch (ch) + { + case '\t': + for (x2 = ((x / TABSIZE) + 1) * TABSIZE; x < x2; x++) + { + if (winsch(win, attr | ' ') == ERR) + return ERR; + } + return OK; + + case '\n': + wclrtoeol(win); + break; + + case 0x7f: + if (winsch(win, attr | '?') == ERR) + return ERR; + + return winsch(win, attr | '^'); + + default: + /* handle control chars */ + + if (winsch(win, attr | (ch + '@')) == ERR) + return ERR; + + return winsch(win, attr | '^'); + } + } + else + { + int maxx; + chtype *temp; + + /* If the incoming character doesn't have its own attribute, + then use the current attributes for the window. If it has + attributes but not a color component, OR the attributes to + the current attributes for the window. If it has a color + component, use the attributes solely from the incoming + character. */ + + if (!(attr & A_COLOR)) + attr |= win->_attrs; + + /* wrs (4/10/93): Apply the same sort of logic for the window + background, in that it only takes precedence if other color + attributes are not there and that the background character + will only print if the printing character is blank. */ + + if (!(attr & A_COLOR)) + attr |= win->_bkgd & A_ATTRIBUTES; + else + attr |= win->_bkgd & (A_ATTRIBUTES ^ A_COLOR); + + if (ch == ' ') + ch = win->_bkgd & A_CHARTEXT; + + /* Add the attribute back into the character. */ + + ch |= attr; + + maxx = win->_maxx; + temp = &win->_y[y][x]; + + memmove(temp + 1, temp, (maxx - x - 1) * sizeof(chtype)); + + win->_lastch[y] = maxx - 1; + + if ((win->_firstch[y] == _NO_CHANGE) || (win->_firstch[y] > x)) + win->_firstch[y] = x; + + *temp = ch; + } + + PDC_sync(win); + + return OK; +} + +int insch(chtype ch) +{ + PDC_LOG(("insch() - called\n")); + + return winsch(stdscr, ch); +} + +int mvinsch(int y, int x, chtype ch) +{ + PDC_LOG(("mvinsch() - called\n")); + + if (move(y, x) == ERR) + return ERR; + + return winsch(stdscr, ch); +} + +int mvwinsch(WINDOW *win, int y, int x, chtype ch) +{ + PDC_LOG(("mvwinsch() - called\n")); + + if (wmove(win, y, x) == ERR) + return ERR; + + return winsch(win, ch); +} + +int winsrawch(WINDOW *win, chtype ch) +{ + PDC_LOG(("winsrawch() - called: win=%p ch=%x " + "(char=%c attr=0x%x)\n", win, ch, + ch & A_CHARTEXT, ch & A_ATTRIBUTES)); + + if ((ch & A_CHARTEXT) < ' ' || (ch & A_CHARTEXT) == 0x7f) + ch |= A_ALTCHARSET; + + return winsch(win, ch); +} + +int insrawch(chtype ch) +{ + PDC_LOG(("insrawch() - called\n")); + + return winsrawch(stdscr, ch); +} + +int mvinsrawch(int y, int x, chtype ch) +{ + PDC_LOG(("mvinsrawch() - called\n")); + + if (move(y, x) == ERR) + return ERR; + + return winsrawch(stdscr, ch); +} + +int mvwinsrawch(WINDOW *win, int y, int x, chtype ch) +{ + PDC_LOG(("mvwinsrawch() - called\n")); + + if (wmove(win, y, x) == ERR) + return ERR; + + return winsrawch(win, ch); +} + +#ifdef PDC_WIDE +int wins_wch(WINDOW *win, const cchar_t *wch) +{ + PDC_LOG(("wins_wch() - called\n")); + + return wch ? winsch(win, *wch) : ERR; +} + +int ins_wch(const cchar_t *wch) +{ + PDC_LOG(("ins_wch() - called\n")); + + return wins_wch(stdscr, wch); +} + +int mvins_wch(int y, int x, const cchar_t *wch) +{ + PDC_LOG(("mvins_wch() - called\n")); + + if (move(y, x) == ERR) + return ERR; + + return wins_wch(stdscr, wch); +} + +int mvwins_wch(WINDOW *win, int y, int x, const cchar_t *wch) +{ + PDC_LOG(("mvwins_wch() - called\n")); + + if (wmove(win, y, x) == ERR) + return ERR; + + return wins_wch(win, wch); +} +#endif diff --git a/modules/ncurses/pdcurses/pdcurses/insstr.c b/modules/ncurses/pdcurses/pdcurses/insstr.c new file mode 100644 index 00000000..e93d6aec --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/insstr.c @@ -0,0 +1,264 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +insstr +------ + +### Synopsis + + int insstr(const char *str); + int insnstr(const char *str, int n); + int winsstr(WINDOW *win, const char *str); + int winsnstr(WINDOW *win, const char *str, int n); + int mvinsstr(int y, int x, const char *str); + int mvinsnstr(int y, int x, const char *str, int n); + int mvwinsstr(WINDOW *win, int y, int x, const char *str); + int mvwinsnstr(WINDOW *win, int y, int x, const char *str, int n); + + int ins_wstr(const wchar_t *wstr); + int ins_nwstr(const wchar_t *wstr, int n); + int wins_wstr(WINDOW *win, const wchar_t *wstr); + int wins_nwstr(WINDOW *win, const wchar_t *wstr, int n); + int mvins_wstr(int y, int x, const wchar_t *wstr); + int mvins_nwstr(int y, int x, const wchar_t *wstr, int n); + int mvwins_wstr(WINDOW *win, int y, int x, const wchar_t *wstr); + int mvwins_nwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n); + +### Description + + The insstr() functions insert a character string into a window + at the current cursor position, by repeatedly calling winsch(). + When PDCurses is built with wide-character support enabled, the + narrow-character functions treat the string as a multibyte + string in the current locale, and convert it first. All + characters to the right of the cursor are moved to the right, + with the possibility of the rightmost characters on the line + being lost. The cursor position does not change (after moving + to y, x, if specified). The routines with n as the last + argument insert at most n characters; if n is negative, then the + entire string is inserted. + +### Return Value + + All functions return OK on success and ERR on error. + +### Portability + X/Open BSD SYS V + insstr Y - 4.0 + winsstr Y - 4.0 + mvinsstr Y - 4.0 + mvwinsstr Y - 4.0 + insnstr Y - 4.0 + winsnstr Y - 4.0 + mvinsnstr Y - 4.0 + mvwinsnstr Y - 4.0 + ins_wstr Y + wins_wstr Y + mvins_wstr Y + mvwins_wstr Y + ins_nwstr Y + wins_nwstr Y + mvins_nwstr Y + mvwins_nwstr Y + +**man-end****************************************************************/ + +#include + +int winsnstr(WINDOW *win, const char *str, int n) +{ +#ifdef PDC_WIDE + wchar_t wstr[513], *p; + int i; +#endif + int len; + + PDC_LOG(("winsnstr() - called: string=\"%s\" n %d \n", str, n)); + + if (!win || !str) + return ERR; + + len = strlen(str); + + if (n < 0 || n < len) + n = len; + +#ifdef PDC_WIDE + if (n > 512) + n = 512; + + p = wstr; + i = 0; + + while (str[i] && i < n) + { + int retval = PDC_mbtowc(p, str + i, n - i); + + if (retval <= 0) + break; + p++; + i += retval; + } + + while (p > wstr) + if (winsch(win, *--p) == ERR) +#else + while (n) + if (winsch(win, (unsigned char)(str[--n])) == ERR) +#endif + return ERR; + + return OK; +} + +int insstr(const char *str) +{ + PDC_LOG(("insstr() - called: string=\"%s\"\n", str)); + + return winsnstr(stdscr, str, -1); +} + +int winsstr(WINDOW *win, const char *str) +{ + PDC_LOG(("winsstr() - called: string=\"%s\"\n", str)); + + return winsnstr(win, str, -1); +} + +int mvinsstr(int y, int x, const char *str) +{ + PDC_LOG(("mvinsstr() - called: y %d x %d string=\"%s\"\n", y, x, str)); + + if (move(y, x) == ERR) + return ERR; + + return winsnstr(stdscr, str, -1); +} + +int mvwinsstr(WINDOW *win, int y, int x, const char *str) +{ + PDC_LOG(("mvwinsstr() - called: string=\"%s\"\n", str)); + + if (wmove(win, y, x) == ERR) + return ERR; + + return winsnstr(win, str, -1); +} + +int insnstr(const char *str, int n) +{ + PDC_LOG(("insnstr() - called: string=\"%s\" n %d \n", str, n)); + + return winsnstr(stdscr, str, n); +} + +int mvinsnstr(int y, int x, const char *str, int n) +{ + PDC_LOG(("mvinsnstr() - called: y %d x %d string=\"%s\" n %d \n", + y, x, str, n)); + + if (move(y, x) == ERR) + return ERR; + + return winsnstr(stdscr, str, n); +} + +int mvwinsnstr(WINDOW *win, int y, int x, const char *str, int n) +{ + PDC_LOG(("mvwinsnstr() - called: y %d x %d string=\"%s\" n %d \n", + y, x, str, n)); + + if (wmove(win, y, x) == ERR) + return ERR; + + return winsnstr(win, str, n); +} + +#ifdef PDC_WIDE +int wins_nwstr(WINDOW *win, const wchar_t *wstr, int n) +{ + const wchar_t *p; + int len; + + PDC_LOG(("wins_nwstr() - called\n")); + + if (!win || !wstr) + return ERR; + + for (len = 0, p = wstr; *p; p++) + len++; + + if (n < 0 || n < len) + n = len; + + while (n) + if (winsch(win, wstr[--n]) == ERR) + return ERR; + + return OK; +} + +int ins_wstr(const wchar_t *wstr) +{ + PDC_LOG(("ins_wstr() - called\n")); + + return wins_nwstr(stdscr, wstr, -1); +} + +int wins_wstr(WINDOW *win, const wchar_t *wstr) +{ + PDC_LOG(("wins_wstr() - called\n")); + + return wins_nwstr(win, wstr, -1); +} + +int mvins_wstr(int y, int x, const wchar_t *wstr) +{ + PDC_LOG(("mvins_wstr() - called\n")); + + if (move(y, x) == ERR) + return ERR; + + return wins_nwstr(stdscr, wstr, -1); +} + +int mvwins_wstr(WINDOW *win, int y, int x, const wchar_t *wstr) +{ + PDC_LOG(("mvwinsstr() - called\n")); + + if (wmove(win, y, x) == ERR) + return ERR; + + return wins_nwstr(win, wstr, -1); +} + +int ins_nwstr(const wchar_t *wstr, int n) +{ + PDC_LOG(("ins_nwstr() - called\n")); + + return wins_nwstr(stdscr, wstr, n); +} + +int mvins_nwstr(int y, int x, const wchar_t *wstr, int n) +{ + PDC_LOG(("mvinsnstr() - called\n")); + + if (move(y, x) == ERR) + return ERR; + + return wins_nwstr(stdscr, wstr, n); +} + +int mvwins_nwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n) +{ + PDC_LOG(("mvwinsnstr() - called\n")); + + if (wmove(win, y, x) == ERR) + return ERR; + + return wins_nwstr(win, wstr, n); +} +#endif diff --git a/modules/ncurses/pdcurses/pdcurses/instr.c b/modules/ncurses/pdcurses/pdcurses/instr.c new file mode 100644 index 00000000..babb35e2 --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/instr.c @@ -0,0 +1,246 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +instr +----- + +### Synopsis + + int instr(char *str); + int innstr(char *str, int n); + int winstr(WINDOW *win, char *str); + int winnstr(WINDOW *win, char *str, int n); + int mvinstr(int y, int x, char *str); + int mvinnstr(int y, int x, char *str, int n); + int mvwinstr(WINDOW *win, int y, int x, char *str); + int mvwinnstr(WINDOW *win, int y, int x, char *str, int n); + + int inwstr(wchar_t *wstr); + int innwstr(wchar_t *wstr, int n); + int winwstr(WINDOW *win, wchar_t *wstr); + int winnwstr(WINDOW *win, wchar_t *wstr, int n); + int mvinwstr(int y, int x, wchar_t *wstr); + int mvinnwstr(int y, int x, wchar_t *wstr, int n); + int mvwinwstr(WINDOW *win, int y, int x, wchar_t *wstr); + int mvwinnwstr(WINDOW *win, int y, int x, wchar_t *wstr, int n); + +### Description + + These functions take characters (or wide characters) from the + current or specified position in the window, and return them as + a string in str (or wstr). Attributes are ignored. The functions + with n as the last argument return a string at most n characters + long. + +### Return Value + + Upon successful completion, innstr(), mvinnstr(), mvwinnstr() + and winnstr() return the number of characters actually read into + the string; instr(), mvinstr(), mvwinstr() and winstr() return + OK. Otherwise, all these functions return ERR. + +### Portability + X/Open BSD SYS V + instr Y - 4.0 + winstr Y - 4.0 + mvinstr Y - 4.0 + mvwinstr Y - 4.0 + innstr Y - 4.0 + winnstr Y - 4.0 + mvinnstr Y - 4.0 + mvwinnstr Y - 4.0 + inwstr Y + winwstr Y + mvinwstr Y + mvwinwstr Y + innwstr Y + winnwstr Y + mvinnwstr Y + mvwinnwstr Y + +**man-end****************************************************************/ + +int winnstr(WINDOW *win, char *str, int n) +{ +#ifdef PDC_WIDE + wchar_t wstr[513]; + + if (n < 0 || n > 512) + n = 512; + + if (winnwstr(win, wstr, n) == ERR) + return ERR; + + return PDC_wcstombs(str, wstr, n); +#else + chtype *src; + int i; + + PDC_LOG(("winnstr() - called: n %d \n", n)); + + if (!win || !str) + return ERR; + + if (n < 0 || (win->_curx + n) > win->_maxx) + n = win->_maxx - win->_curx; + + src = win->_y[win->_cury] + win->_curx; + + for (i = 0; i < n; i++) + str[i] = src[i] & A_CHARTEXT; + + str[i] = '\0'; + + return i; +#endif +} + +int instr(char *str) +{ + PDC_LOG(("instr() - called: string=\"%s\"\n", str)); + + return (ERR == winnstr(stdscr, str, stdscr->_maxx)) ? ERR : OK; +} + +int winstr(WINDOW *win, char *str) +{ + PDC_LOG(("winstr() - called: \n")); + + return (ERR == winnstr(win, str, win->_maxx)) ? ERR : OK; +} + +int mvinstr(int y, int x, char *str) +{ + PDC_LOG(("mvinstr() - called: y %d x %d \n", y, x)); + + if (move(y, x) == ERR) + return ERR; + + return (ERR == winnstr(stdscr, str, stdscr->_maxx)) ? ERR : OK; +} + +int mvwinstr(WINDOW *win, int y, int x, char *str) +{ + PDC_LOG(("mvwinstr() - called: y %d x %d \n", y, x)); + + if (wmove(win, y, x) == ERR) + return ERR; + + return (ERR == winnstr(win, str, win->_maxx)) ? ERR : OK; +} + +int innstr(char *str, int n) +{ + PDC_LOG(("innstr() - called: n %d \n", n)); + + return winnstr(stdscr, str, n); +} + +int mvinnstr(int y, int x, char *str, int n) +{ + PDC_LOG(("mvinnstr() - called: y %d x %d n %d \n", y, x, n)); + + if (move(y, x) == ERR) + return ERR; + + return winnstr(stdscr, str, n); +} + +int mvwinnstr(WINDOW *win, int y, int x, char *str, int n) +{ + PDC_LOG(("mvwinnstr() - called: y %d x %d n %d \n", y, x, n)); + + if (wmove(win, y, x) == ERR) + return ERR; + + return winnstr(win, str, n); +} + +#ifdef PDC_WIDE +int winnwstr(WINDOW *win, wchar_t *wstr, int n) +{ + chtype *src; + int i; + + PDC_LOG(("winnstr() - called: n %d \n", n)); + + if (!win || !wstr) + return ERR; + + if (n < 0 || (win->_curx + n) > win->_maxx) + n = win->_maxx - win->_curx; + + src = win->_y[win->_cury] + win->_curx; + + for (i = 0; i < n; i++) + wstr[i] = src[i] & A_CHARTEXT; + + wstr[i] = L'\0'; + + return i; +} + +int inwstr(wchar_t *wstr) +{ + PDC_LOG(("inwstr() - called\n")); + + return (ERR == winnwstr(stdscr, wstr, stdscr->_maxx)) ? ERR : OK; +} + +int winwstr(WINDOW *win, wchar_t *wstr) +{ + PDC_LOG(("winwstr() - called\n")); + + return (ERR == winnwstr(win, wstr, win->_maxx)) ? ERR : OK; +} + +int mvinwstr(int y, int x, wchar_t *wstr) +{ + PDC_LOG(("mvinwstr() - called\n")); + + if (move(y, x) == ERR) + return ERR; + + return (ERR == winnwstr(stdscr, wstr, stdscr->_maxx)) ? ERR : OK; +} + +int mvwinwstr(WINDOW *win, int y, int x, wchar_t *wstr) +{ + PDC_LOG(("mvwinstr() - called\n")); + + if (wmove(win, y, x) == ERR) + return ERR; + + return (ERR == winnwstr(win, wstr, win->_maxx)) ? ERR : OK; +} + +int innwstr(wchar_t *wstr, int n) +{ + PDC_LOG(("innwstr() - called\n")); + + return winnwstr(stdscr, wstr, n); +} + +int mvinnwstr(int y, int x, wchar_t *wstr, int n) +{ + PDC_LOG(("mvinnstr() - called\n")); + + if (move(y, x) == ERR) + return ERR; + + return winnwstr(stdscr, wstr, n); +} + +int mvwinnwstr(WINDOW *win, int y, int x, wchar_t *wstr, int n) +{ + PDC_LOG(("mvwinnwstr() - called\n")); + + if (wmove(win, y, x) == ERR) + return ERR; + + return winnwstr(win, wstr, n); +} +#endif diff --git a/modules/ncurses/pdcurses/pdcurses/kernel.c b/modules/ncurses/pdcurses/pdcurses/kernel.c new file mode 100644 index 00000000..76502900 --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/kernel.c @@ -0,0 +1,259 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +kernel +------ + +### Synopsis + + int def_prog_mode(void); + int def_shell_mode(void); + int reset_prog_mode(void); + int reset_shell_mode(void); + int resetty(void); + int savetty(void); + int ripoffline(int line, int (*init)(WINDOW *, int)); + int curs_set(int visibility); + int napms(int ms); + + int draino(int ms); + int resetterm(void); + int fixterm(void); + int saveterm(void); + +### Description + + def_prog_mode() and def_shell_mode() save the current terminal + modes as the "program" (in curses) or "shell" (not in curses) + state for use by the reset_prog_mode() and reset_shell_mode() + functions. This is done automatically by initscr(). + + reset_prog_mode() and reset_shell_mode() restore the terminal to + "program" (in curses) or "shell" (not in curses) state. These + are done automatically by endwin() and doupdate() after an + endwin(), so they would normally not be called before these + functions. + + savetty() and resetty() save and restore the state of the + terminal modes. savetty() saves the current state in a buffer, + and resetty() restores the state to what it was at the last call + to savetty(). + + curs_set() alters the appearance of the cursor. A visibility of + 0 makes it disappear; 1 makes it appear "normal" (usually an + underline) and 2 makes it "highly visible" (usually a block). + + ripoffline() reduces the size of stdscr by one line. If the + "line" parameter is positive, the line is removed from the top + of the screen; if negative, from the bottom. Up to 5 lines can + be ripped off stdscr by calling ripoffline() repeatedly. The + function argument, init, is called from within initscr() or + newterm(), so ripoffline() must be called before either of these + functions. The init function receives a pointer to a one-line + WINDOW, and the width of the window. Calling ripoffline() with a + NULL init function pointer is an error. + + napms() suspends the program for the specified number of + milliseconds. draino() is an archaic equivalent. + + resetterm(), fixterm() and saveterm() are archaic equivalents + for reset_shell_mode(), reset_prog_mode() and def_prog_mode(), + respectively. + +### Return Value + + All functions return OK on success and ERR on error, except + curs_set(), which returns the previous visibility. + +### Portability + X/Open BSD SYS V + def_prog_mode Y Y Y + def_shell_mode Y Y Y + reset_prog_mode Y Y Y + reset_shell_mode Y Y Y + resetty Y Y Y + savetty Y Y Y + ripoffline Y - 3.0 + curs_set Y - 3.0 + napms Y Y Y + draino - + resetterm - + fixterm - + saveterm - + +**man-end****************************************************************/ + +#include + +RIPPEDOFFLINE linesripped[5]; +char linesrippedoff = 0; + +static struct cttyset +{ + bool been_set; + SCREEN saved; +} ctty[3]; + +enum { PDC_SH_TTY, PDC_PR_TTY, PDC_SAVE_TTY }; + +static void _save_mode(int i) +{ + ctty[i].been_set = TRUE; + + memcpy(&(ctty[i].saved), SP, sizeof(SCREEN)); + + PDC_save_screen_mode(i); +} + +static int _restore_mode(int i) +{ + if (ctty[i].been_set == TRUE) + { + memcpy(SP, &(ctty[i].saved), sizeof(SCREEN)); + + if (ctty[i].saved.raw_out) + raw(); + + PDC_restore_screen_mode(i); + + if ((LINES != ctty[i].saved.lines) || + (COLS != ctty[i].saved.cols)) + resize_term(ctty[i].saved.lines, ctty[i].saved.cols); + + PDC_curs_set(ctty[i].saved.visibility); + + PDC_gotoyx(ctty[i].saved.cursrow, ctty[i].saved.curscol); + } + + return ctty[i].been_set ? OK : ERR; +} + +int def_prog_mode(void) +{ + PDC_LOG(("def_prog_mode() - called\n")); + + _save_mode(PDC_PR_TTY); + + return OK; +} + +int def_shell_mode(void) +{ + PDC_LOG(("def_shell_mode() - called\n")); + + _save_mode(PDC_SH_TTY); + + return OK; +} + +int reset_prog_mode(void) +{ + PDC_LOG(("reset_prog_mode() - called\n")); + + _restore_mode(PDC_PR_TTY); + PDC_reset_prog_mode(); + + return OK; +} + +int reset_shell_mode(void) +{ + PDC_LOG(("reset_shell_mode() - called\n")); + + _restore_mode(PDC_SH_TTY); + PDC_reset_shell_mode(); + + return OK; +} + +int resetty(void) +{ + PDC_LOG(("resetty() - called\n")); + + return _restore_mode(PDC_SAVE_TTY); +} + +int savetty(void) +{ + PDC_LOG(("savetty() - called\n")); + + _save_mode(PDC_SAVE_TTY); + + return OK; +} + +int curs_set(int visibility) +{ + int ret_vis; + + PDC_LOG(("curs_set() - called: visibility=%d\n", visibility)); + + if ((visibility < 0) || (visibility > 2)) + return ERR; + + ret_vis = PDC_curs_set(visibility); + + /* If the cursor is changing from invisible to visible, update + its position */ + + if (visibility && !ret_vis) + PDC_gotoyx(SP->cursrow, SP->curscol); + + return ret_vis; +} + +int napms(int ms) +{ + PDC_LOG(("napms() - called: ms=%d\n", ms)); + + if (ms) + PDC_napms(ms); + + return OK; +} + +int ripoffline(int line, int (*init)(WINDOW *, int)) +{ + PDC_LOG(("ripoffline() - called: line=%d\n", line)); + + if (linesrippedoff < 5 && line && init) + { + linesripped[(int)linesrippedoff].line = line; + linesripped[(int)linesrippedoff++].init = init; + + return OK; + } + + return ERR; +} + +int draino(int ms) +{ + PDC_LOG(("draino() - called\n")); + + return napms(ms); +} + +int resetterm(void) +{ + PDC_LOG(("resetterm() - called\n")); + + return reset_shell_mode(); +} + +int fixterm(void) +{ + PDC_LOG(("fixterm() - called\n")); + + return reset_prog_mode(); +} + +int saveterm(void) +{ + PDC_LOG(("saveterm() - called\n")); + + return def_prog_mode(); +} diff --git a/modules/ncurses/pdcurses/pdcurses/keyname.c b/modules/ncurses/pdcurses/pdcurses/keyname.c new file mode 100644 index 00000000..c2df795b --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/keyname.c @@ -0,0 +1,131 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +keyname +------- + +### Synopsis + + char *keyname(int key); + + char *key_name(wchar_t c); + + bool has_key(int key); + +### Description + + keyname() returns a string corresponding to the argument key. + key may be any key returned by wgetch(). + + key_name() is the wide-character version. It takes a wchar_t + parameter, but still returns a char *. + + has_key() returns TRUE for recognized keys, FALSE otherwise. + This function is an ncurses extension. + +### Portability + X/Open BSD SYS V + keyname Y - 3.0 + key_name Y + has_key - - - + +**man-end****************************************************************/ + +#include + +char *keyname(int key) +{ + static char _keyname[14]; + + /* Key names must be in exactly the same order as in curses.h */ + + static char *key_names[] = + { + "KEY_BREAK", "KEY_DOWN", "KEY_UP", "KEY_LEFT", "KEY_RIGHT", + "KEY_HOME", "KEY_BACKSPACE", "KEY_F0", "KEY_F(1)", "KEY_F(2)", + "KEY_F(3)", "KEY_F(4)", "KEY_F(5)", "KEY_F(6)", "KEY_F(7)", + "KEY_F(8)", "KEY_F(9)", "KEY_F(10)", "KEY_F(11)", "KEY_F(12)", + "KEY_F(13)", "KEY_F(14)", "KEY_F(15)", "KEY_F(16)", "KEY_F(17)", + "KEY_F(18)", "KEY_F(19)", "KEY_F(20)", "KEY_F(21)", "KEY_F(22)", + "KEY_F(23)", "KEY_F(24)", "KEY_F(25)", "KEY_F(26)", "KEY_F(27)", + "KEY_F(28)", "KEY_F(29)", "KEY_F(30)", "KEY_F(31)", "KEY_F(32)", + "KEY_F(33)", "KEY_F(34)", "KEY_F(35)", "KEY_F(36)", "KEY_F(37)", + "KEY_F(38)", "KEY_F(39)", "KEY_F(40)", "KEY_F(41)", "KEY_F(42)", + "KEY_F(43)", "KEY_F(44)", "KEY_F(45)", "KEY_F(46)", "KEY_F(47)", + "KEY_F(48)", "KEY_F(49)", "KEY_F(50)", "KEY_F(51)", "KEY_F(52)", + "KEY_F(53)", "KEY_F(54)", "KEY_F(55)", "KEY_F(56)", "KEY_F(57)", + "KEY_F(58)", "KEY_F(59)", "KEY_F(60)", "KEY_F(61)", "KEY_F(62)", + "KEY_F(63)", "KEY_DL", "KEY_IL", "KEY_DC", "KEY_IC", "KEY_EIC", + "KEY_CLEAR", "KEY_EOS", "KEY_EOL", "KEY_SF", "KEY_SR", + "KEY_NPAGE", "KEY_PPAGE", "KEY_STAB", "KEY_CTAB", "KEY_CATAB", + "KEY_ENTER", "KEY_SRESET", "KEY_RESET", "KEY_PRINT", "KEY_LL", + "KEY_ABORT", "KEY_SHELP", "KEY_LHELP", "KEY_BTAB", "KEY_BEG", + "KEY_CANCEL", "KEY_CLOSE", "KEY_COMMAND", "KEY_COPY", + "KEY_CREATE", "KEY_END", "KEY_EXIT", "KEY_FIND", "KEY_HELP", + "KEY_MARK", "KEY_MESSAGE", "KEY_MOVE", "KEY_NEXT", "KEY_OPEN", + "KEY_OPTIONS", "KEY_PREVIOUS", "KEY_REDO", "KEY_REFERENCE", + "KEY_REFRESH", "KEY_REPLACE", "KEY_RESTART", "KEY_RESUME", + "KEY_SAVE", "KEY_SBEG", "KEY_SCANCEL", "KEY_SCOMMAND", + "KEY_SCOPY", "KEY_SCREATE", "KEY_SDC", "KEY_SDL", "KEY_SELECT", + "KEY_SEND", "KEY_SEOL", "KEY_SEXIT", "KEY_SFIND", "KEY_SHOME", + "KEY_SIC", "UNKNOWN KEY", "KEY_SLEFT", "KEY_SMESSAGE", + "KEY_SMOVE", "KEY_SNEXT", "KEY_SOPTIONS", "KEY_SPREVIOUS", + "KEY_SPRINT", "KEY_SREDO", "KEY_SREPLACE", "KEY_SRIGHT", + "KEY_SRSUME", "KEY_SSAVE", "KEY_SSUSPEND", "KEY_SUNDO", + "KEY_SUSPEND", "KEY_UNDO", "ALT_0", "ALT_1", "ALT_2", "ALT_3", + "ALT_4", "ALT_5", "ALT_6", "ALT_7", "ALT_8", "ALT_9", "ALT_A", + "ALT_B", "ALT_C", "ALT_D", "ALT_E", "ALT_F", "ALT_G", "ALT_H", + "ALT_I", "ALT_J", "ALT_K", "ALT_L", "ALT_M", "ALT_N", "ALT_O", + "ALT_P", "ALT_Q", "ALT_R", "ALT_S", "ALT_T", "ALT_U", "ALT_V", + "ALT_W", "ALT_X", "ALT_Y", "ALT_Z", "CTL_LEFT", "CTL_RIGHT", + "CTL_PGUP", "CTL_PGDN", "CTL_HOME", "CTL_END", "KEY_A1", + "KEY_A2", "KEY_A3", "KEY_B1", "KEY_B2", "KEY_B3", "KEY_C1", + "KEY_C2", "KEY_C3", "PADSLASH", "PADENTER", "CTL_PADENTER", + "ALT_PADENTER", "PADSTOP", "PADSTAR", "PADMINUS", "PADPLUS", + "CTL_PADSTOP", "CTL_PADCENTER", "CTL_PADPLUS", "CTL_PADMINUS", + "CTL_PADSLASH", "CTL_PADSTAR", "ALT_PADPLUS", "ALT_PADMINUS", + "ALT_PADSLASH", "ALT_PADSTAR", "ALT_PADSTOP", "CTL_INS", + "ALT_DEL", "ALT_INS", "CTL_UP", "CTL_DOWN", "CTL_TAB", + "ALT_TAB", "ALT_MINUS", "ALT_EQUAL", "ALT_HOME", "ALT_PGUP", + "ALT_PGDN", "ALT_END", "ALT_UP", "ALT_DOWN", "ALT_RIGHT", + "ALT_LEFT", "ALT_ENTER", "ALT_ESC", "ALT_BQUOTE", + "ALT_LBRACKET", "ALT_RBRACKET", "ALT_SEMICOLON", "ALT_FQUOTE", + "ALT_COMMA", "ALT_STOP", "ALT_FSLASH", "ALT_BKSP", "CTL_BKSP", + "PAD0", "CTL_PAD0", "CTL_PAD1", "CTL_PAD2", "CTL_PAD3", + "CTL_PAD4", "CTL_PAD5", "CTL_PAD6", "CTL_PAD7","CTL_PAD8", + "CTL_PAD9", "ALT_PAD0", "ALT_PAD1", "ALT_PAD2", "ALT_PAD3", + "ALT_PAD4", "ALT_PAD5", "ALT_PAD6", "ALT_PAD7", "ALT_PAD8", + "ALT_PAD9", "CTL_DEL", "ALT_BSLASH", "CTL_ENTER", + "SHF_PADENTER", "SHF_PADSLASH", "SHF_PADSTAR", "SHF_PADPLUS", + "SHF_PADMINUS", "SHF_UP", "SHF_DOWN", "SHF_IC", "SHF_DC", + "KEY_MOUSE", "KEY_SHIFT_L", "KEY_SHIFT_R", "KEY_CONTROL_L", + "KEY_CONTROL_R", "KEY_ALT_L", "KEY_ALT_R", "KEY_RESIZE", + "KEY_SUP", "KEY_SDOWN" + }; + + PDC_LOG(("keyname() - called: key %d\n", key)); + + strcpy(_keyname, ((key >= 0) && (key < 0x80)) ? unctrl((chtype)key) : + has_key(key) ? key_names[key - KEY_MIN] : "UNKNOWN KEY"); + + return _keyname; +} + +bool has_key(int key) +{ + PDC_LOG(("has_key() - called: key %d\n", key)); + + return (key >= KEY_MIN && key <= KEY_MAX); +} + +#ifdef PDC_WIDE +char *key_name(wchar_t c) +{ + PDC_LOG(("key_name() - called\n")); + + return keyname((int)c); +} +#endif diff --git a/modules/ncurses/pdcurses/pdcurses/mouse.c b/modules/ncurses/pdcurses/pdcurses/mouse.c new file mode 100644 index 00000000..ca04c9be --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/mouse.c @@ -0,0 +1,431 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +mouse +----- + +### Synopsis + + int mouse_set(unsigned long mbe); + int mouse_on(unsigned long mbe); + int mouse_off(unsigned long mbe); + int request_mouse_pos(void); + int map_button(unsigned long button); + void wmouse_position(WINDOW *win, int *y, int *x); + unsigned long getmouse(void); + unsigned long getbmap(void); + + int mouseinterval(int wait); + bool wenclose(const WINDOW *win, int y, int x); + bool wmouse_trafo(const WINDOW *win, int *y, int *x, bool to_screen); + bool mouse_trafo(int *y, int *x, bool to_screen); + mmask_t mousemask(mmask_t mask, mmask_t *oldmask); + int nc_getmouse(MEVENT *event); + int ungetmouse(MEVENT *event); + +### Description + + As of PDCurses 3.0, there are two separate mouse interfaces: the + classic interface, which is based on the undocumented Sys V + mouse functions; and an ncurses-compatible interface. Both are + active at all times, and you can mix and match functions from + each, though it's not recommended. The ncurses interface is + essentially an emulation layer built on top of the classic + interface; it's here to allow easier porting of ncurses apps. + + The classic interface: mouse_set(), mouse_on(), mouse_off(), + request_mouse_pos(), map_button(), wmouse_position(), + getmouse(), and getbmap(). An application using this interface + would start by calling mouse_set() or mouse_on() with a non-zero + value, often ALL_MOUSE_EVENTS. Then it would check for a + KEY_MOUSE return from getch(). If found, it would call + request_mouse_pos() to get the current mouse status. + + mouse_set(), mouse_on() and mouse_off() are analagous to + attrset(), attron() and attroff(). These functions set the + mouse button events to trap. The button masks used in these + functions are defined in curses.h and can be or'ed together. + They are the group of masks starting with BUTTON1_RELEASED. + + request_mouse_pos() requests curses to fill in the Mouse_status + structure with the current state of the mouse. + + map_button() enables the specified mouse action to activate the + Soft Label Keys if the action occurs over the area of the screen + where the Soft Label Keys are displayed. The mouse actions are + defined in curses.h in the group that starts with BUTTON_RELEASED. + + wmouse_position() determines if the current mouse position is + within the window passed as an argument. If the mouse is + outside the current window, -1 is returned in the y and x + arguments; otherwise the y and x coordinates of the mouse + (relative to the top left corner of the window) are returned in + y and x. + + getmouse() returns the current status of the trapped mouse + buttons as set by mouse_set() or mouse_on(). + + getbmap() returns the current status of the button action used + to map a mouse action to the Soft Label Keys as set by the + map_button() function. + + The ncurses interface: mouseinterval(), wenclose(), + wmouse_trafo(), mouse_trafo(), mousemask(), nc_getmouse(), and + ungetmouse(). A typical application using this interface would + start by calling mousemask() with a non-zero value, often + ALL_MOUSE_EVENTS. Then it would check for a KEY_MOUSE return + from getch(). If found, it would call nc_getmouse() to get the + current mouse status. + + mouseinterval() sets the timeout for a mouse click. On all + current platforms, PDCurses receives mouse button press and + release events, but must synthesize click events. It does this + by checking whether a release event is queued up after a press + event. If it gets a press event, and there are no more events + waiting, it will wait for the timeout interval, then check again + for a release. A press followed by a release is reported as + BUTTON_CLICKED; otherwise it's passed through as BUTTON_PRESSED. + The default timeout is 150ms; valid values are 0 (no clicks + reported) through 1000ms. In x11, the timeout can also be set + via the clickPeriod resource. The return value from + mouseinterval() is the old timeout. To check the old value + without setting a new one, call it with a parameter of -1. Note + that although there's no classic equivalent for this function + (apart from the clickPeriod resource), the value set applies in + both interfaces. + + wenclose() reports whether the given screen-relative y, x + coordinates fall within the given window. + + wmouse_trafo() converts between screen-relative and window- + relative coordinates. A to_screen parameter of TRUE means to + convert from window to screen; otherwise the reverse. The + function returns FALSE if the coordinates aren't within the + window, or if any of the parameters are NULL. The coordinates + have been converted when the function returns TRUE. + + mouse_trafo() is the stdscr version of wmouse_trafo(). + + mousemask() is nearly equivalent to mouse_set(), but instead of + OK/ERR, it returns the value of the mask after setting it. (This + isn't necessarily the same value passed in, since the mask could + be altered on some platforms.) And if the second parameter is a + non-null pointer, mousemask() stores the previous mask value + there. Also, since the ncurses interface doesn't work with + PDCurses' BUTTON_MOVED events, mousemask() filters them out. + + nc_getmouse() returns the current mouse status in an MEVENT + struct. This is equivalent to ncurses' getmouse(), renamed to + avoid conflict with PDCurses' getmouse(). But if you define + NCURSES_MOUSE_VERSION (preferably as 2) before including + curses.h, it defines getmouse() to nc_getmouse(), along with a + few other redefintions needed for compatibility with ncurses + code. nc_getmouse() calls request_mouse_pos(), which (not + getmouse()) is the classic equivalent. + + ungetmouse() is the mouse equivalent of ungetch(). However, + PDCurses doesn't maintain a queue of mouse events; only one can + be pushed back, and it can overwrite or be overwritten by real + mouse events. + +### Portability + X/Open BSD SYS V + mouse_set - - 4.0 + mouse_on - - 4.0 + mouse_off - - 4.0 + request_mouse_pos - - 4.0 + map_button - - 4.0 + wmouse_position - - 4.0 + getmouse - - 4.0 + getbmap - - 4.0 + mouseinterval - - - + wenclose - - - + wmouse_trafo - - - + mouse_trafo - - - + mousemask - - - + nc_getmouse - - - + ungetmouse - - - + +**man-end****************************************************************/ + +#include + +static bool ungot = FALSE; + +int mouse_set(unsigned long mbe) +{ + PDC_LOG(("mouse_set() - called: event %x\n", mbe)); + + SP->_trap_mbe = mbe; + return PDC_mouse_set(); +} + +int mouse_on(unsigned long mbe) +{ + PDC_LOG(("mouse_on() - called: event %x\n", mbe)); + + SP->_trap_mbe |= mbe; + return PDC_mouse_set(); +} + +int mouse_off(unsigned long mbe) +{ + PDC_LOG(("mouse_off() - called: event %x\n", mbe)); + + SP->_trap_mbe &= ~mbe; + return PDC_mouse_set(); +} + +int map_button(unsigned long button) +{ + PDC_LOG(("map_button() - called: button %x\n", button)); + +/****************** this does nothing at the moment ***************/ + SP->_map_mbe_to_key = button; + + return OK; +} + +int request_mouse_pos(void) +{ + PDC_LOG(("request_mouse_pos() - called\n")); + + Mouse_status = pdc_mouse_status; + + return OK; +} + +void wmouse_position(WINDOW *win, int *y, int *x) +{ + PDC_LOG(("wmouse_position() - called\n")); + + if (win && wenclose(win, MOUSE_Y_POS, MOUSE_X_POS)) + { + if (y) + *y = MOUSE_Y_POS - win->_begy; + if (x) + *x = MOUSE_X_POS - win->_begx; + } + else + { + if (y) + *y = -1; + if (x) + *x = -1; + } +} + +unsigned long getmouse(void) +{ + PDC_LOG(("getmouse() - called\n")); + + return SP->_trap_mbe; +} + +unsigned long getbmap(void) +{ + PDC_LOG(("getbmap() - called\n")); + + return SP->_map_mbe_to_key; +} + +/* ncurses mouse interface */ + +int mouseinterval(int wait) +{ + int old_wait; + + PDC_LOG(("mouseinterval() - called: %d\n", wait)); + + old_wait = SP->mouse_wait; + + if (wait >= 0 && wait <= 1000) + SP->mouse_wait = wait; + + return old_wait; +} + +bool wenclose(const WINDOW *win, int y, int x) +{ + PDC_LOG(("wenclose() - called: %p %d %d\n", win, y, x)); + + return (win && y >= win->_begy && y < win->_begy + win->_maxy + && x >= win->_begx && x < win->_begx + win->_maxx); +} + +bool wmouse_trafo(const WINDOW *win, int *y, int *x, bool to_screen) +{ + int newy, newx; + + PDC_LOG(("wmouse_trafo() - called\n")); + + if (!win || !y || !x) + return FALSE; + + newy = *y; + newx = *x; + + if (to_screen) + { + newy += win->_begy; + newx += win->_begx; + + if (!wenclose(win, newy, newx)) + return FALSE; + } + else + { + if (wenclose(win, newy, newx)) + { + newy -= win->_begy; + newx -= win->_begx; + } + else + return FALSE; + } + + *y = newy; + *x = newx; + + return TRUE; +} + +bool mouse_trafo(int *y, int *x, bool to_screen) +{ + PDC_LOG(("mouse_trafo() - called\n")); + + return wmouse_trafo(stdscr, y, x, to_screen); +} + +mmask_t mousemask(mmask_t mask, mmask_t *oldmask) +{ + PDC_LOG(("mousemask() - called\n")); + + if (oldmask) + *oldmask = SP->_trap_mbe; + + /* The ncurses interface doesn't work with our move events, so + filter them here */ + + mask &= ~(BUTTON1_MOVED | BUTTON2_MOVED | BUTTON3_MOVED); + + mouse_set(mask); + + return SP->_trap_mbe; +} + +int nc_getmouse(MEVENT *event) +{ + int i; + mmask_t bstate = 0; + + PDC_LOG(("nc_getmouse() - called\n")); + + if (!event) + return ERR; + + ungot = FALSE; + + request_mouse_pos(); + + event->id = 0; + + event->x = Mouse_status.x; + event->y = Mouse_status.y; + event->z = 0; + + for (i = 0; i < 3; i++) + { + if (Mouse_status.changes & (1 << i)) + { + int shf = i * 5; + short button = Mouse_status.button[i] & BUTTON_ACTION_MASK; + + if (button == BUTTON_RELEASED) + bstate |= (BUTTON1_RELEASED << shf); + else if (button == BUTTON_PRESSED) + bstate |= (BUTTON1_PRESSED << shf); + else if (button == BUTTON_CLICKED) + bstate |= (BUTTON1_CLICKED << shf); + else if (button == BUTTON_DOUBLE_CLICKED) + bstate |= (BUTTON1_DOUBLE_CLICKED << shf); + + button = Mouse_status.button[i] & BUTTON_MODIFIER_MASK; + + if (button & PDC_BUTTON_SHIFT) + bstate |= BUTTON_MODIFIER_SHIFT; + if (button & PDC_BUTTON_CONTROL) + bstate |= BUTTON_MODIFIER_CONTROL; + if (button & PDC_BUTTON_ALT) + bstate |= BUTTON_MODIFIER_ALT; + } + } + + if (MOUSE_WHEEL_UP) + bstate |= BUTTON4_PRESSED; + else if (MOUSE_WHEEL_DOWN) + bstate |= BUTTON5_PRESSED; + + /* extra filter pass -- mainly for button modifiers */ + + event->bstate = bstate & SP->_trap_mbe; + + return OK; +} + +int ungetmouse(MEVENT *event) +{ + int i; + unsigned long bstate; + + PDC_LOG(("ungetmouse() - called\n")); + + if (!event || ungot) + return ERR; + + ungot = TRUE; + + pdc_mouse_status.x = event->x; + pdc_mouse_status.y = event->y; + + pdc_mouse_status.changes = 0; + bstate = event->bstate; + + for (i = 0; i < 3; i++) + { + int shf = i * 5; + short button = 0; + + if (bstate & ((BUTTON1_RELEASED | BUTTON1_PRESSED | + BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED) << shf)) + { + pdc_mouse_status.changes |= 1 << i; + + if (bstate & (BUTTON1_PRESSED << shf)) + button = BUTTON_PRESSED; + if (bstate & (BUTTON1_CLICKED << shf)) + button = BUTTON_CLICKED; + if (bstate & (BUTTON1_DOUBLE_CLICKED << shf)) + button = BUTTON_DOUBLE_CLICKED; + + if (bstate & BUTTON_MODIFIER_SHIFT) + button |= PDC_BUTTON_SHIFT; + if (bstate & BUTTON_MODIFIER_CONTROL) + button |= PDC_BUTTON_CONTROL; + if (bstate & BUTTON_MODIFIER_ALT) + button |= PDC_BUTTON_ALT; + } + + pdc_mouse_status.button[i] = button; + } + + if (bstate & BUTTON4_PRESSED) + pdc_mouse_status.changes |= PDC_MOUSE_WHEEL_UP; + else if (bstate & BUTTON5_PRESSED) + pdc_mouse_status.changes |= PDC_MOUSE_WHEEL_DOWN; + + return ungetch(KEY_MOUSE); +} diff --git a/modules/ncurses/pdcurses/pdcurses/move.c b/modules/ncurses/pdcurses/pdcurses/move.c new file mode 100644 index 00000000..062f115c --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/move.c @@ -0,0 +1,57 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +move +---- + +### Synopsis + + int move(int y, int x); + int wmove(WINDOW *win, int y, int x); + +### Description + + The cursor associated with the window is moved to the given + location. This does not move the physical cursor of the + terminal until refresh() is called. The position specified is + relative to the upper left corner of the window, which is (0,0). + +### Return Value + + All functions return OK on success and ERR on error. + +### Portability + X/Open BSD SYS V + move Y Y Y + wmove Y Y Y + +**man-end****************************************************************/ + +int move(int y, int x) +{ + PDC_LOG(("move() - called: y=%d x=%d\n", y, x)); + + if (!stdscr || x < 0 || y < 0 || x >= stdscr->_maxx || y >= stdscr->_maxy) + return ERR; + + stdscr->_curx = x; + stdscr->_cury = y; + + return OK; +} + +int wmove(WINDOW *win, int y, int x) +{ + PDC_LOG(("wmove() - called: y=%d x=%d\n", y, x)); + + if (!win || x < 0 || y < 0 || x >= win->_maxx || y >= win->_maxy) + return ERR; + + win->_curx = x; + win->_cury = y; + + return OK; +} diff --git a/modules/ncurses/pdcurses/pdcurses/outopts.c b/modules/ncurses/pdcurses/pdcurses/outopts.c new file mode 100644 index 00000000..605e8872 --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/outopts.c @@ -0,0 +1,159 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +outopts +------- + +### Synopsis + + int clearok(WINDOW *win, bool bf); + int idlok(WINDOW *win, bool bf); + void idcok(WINDOW *win, bool bf); + void immedok(WINDOW *win, bool bf); + int leaveok(WINDOW *win, bool bf); + int setscrreg(int top, int bot); + int wsetscrreg(WINDOW *win, int top, int bot); + int scrollok(WINDOW *win, bool bf); + + int raw_output(bool bf); + +### Description + + With clearok(), if bf is TRUE, the next call to wrefresh() with + this window will clear the screen completely and redraw the + entire screen. + + immedok(), called with a second argument of TRUE, causes an + automatic wrefresh() every time a change is made to the + specified window. + + Normally, the hardware cursor is left at the location of the + window being refreshed. leaveok() allows the cursor to be + left wherever the update happens to leave it. It's useful + for applications where the cursor is not used, since it reduces + the need for cursor motions. If possible, the cursor is made + invisible when this option is enabled. + + wsetscrreg() sets a scrolling region in a window; "top" and + "bot" are the line numbers for the top and bottom margins. If + this option and scrollok() are enabled, any attempt to move off + the bottom margin will cause all lines in the scrolling region + to scroll up one line. setscrreg() is the stdscr version. + + idlok() and idcok() do nothing in PDCurses, but are provided for + compatibility with other curses implementations. + + raw_output() enables the output of raw characters using the + standard *add* and *ins* curses functions (that is, it disables + translation of control characters). + +### Return Value + + All functions return OK on success and ERR on error. + +### Portability + X/Open BSD SYS V + clearok Y Y Y + idlok Y Y Y + idcok Y - 4.0 + immedok Y - 4.0 + leaveok Y Y Y + setscrreg Y Y Y + wsetscrreg Y Y Y + scrollok Y Y Y + raw_output - - - + +**man-end****************************************************************/ + +int clearok(WINDOW *win, bool bf) +{ + PDC_LOG(("clearok() - called\n")); + + if (!win) + return ERR; + + win->_clear = bf; + + return OK; +} + +int idlok(WINDOW *win, bool bf) +{ + PDC_LOG(("idlok() - called\n")); + + return OK; +} + +void idcok(WINDOW *win, bool bf) +{ + PDC_LOG(("idcok() - called\n")); +} + +void immedok(WINDOW *win, bool bf) +{ + PDC_LOG(("immedok() - called\n")); + + if (win) + win->_immed = bf; +} + +int leaveok(WINDOW *win, bool bf) +{ + PDC_LOG(("leaveok() - called\n")); + + if (!win) + return ERR; + + win->_leaveit = bf; + + curs_set(!bf); + + return OK; +} + +int setscrreg(int top, int bottom) +{ + PDC_LOG(("setscrreg() - called: top %d bottom %d\n", top, bottom)); + + return wsetscrreg(stdscr, top, bottom); +} + +int wsetscrreg(WINDOW *win, int top, int bottom) +{ + PDC_LOG(("wsetscrreg() - called: top %d bottom %d\n", top, bottom)); + + if (win && 0 <= top && top <= win->_cury && + win->_cury <= bottom && bottom < win->_maxy) + { + win->_tmarg = top; + win->_bmarg = bottom; + + return OK; + } + else + return ERR; +} + +int scrollok(WINDOW *win, bool bf) +{ + PDC_LOG(("scrollok() - called\n")); + + if (!win) + return ERR; + + win->_scroll = bf; + + return OK; +} + +int raw_output(bool bf) +{ + PDC_LOG(("raw_output() - called\n")); + + SP->raw_out = bf; + + return OK; +} diff --git a/modules/ncurses/pdcurses/pdcurses/overlay.c b/modules/ncurses/pdcurses/pdcurses/overlay.c new file mode 100644 index 00000000..cd98f45c --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/overlay.c @@ -0,0 +1,214 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +overlay +------- + +### Synopsis + + int overlay(const WINDOW *src_w, WINDOW *dst_w) + int overwrite(const WINDOW *src_w, WINDOW *dst_w) + int copywin(const WINDOW *src_w, WINDOW *dst_w, int src_tr, + int src_tc, int dst_tr, int dst_tc, int dst_br, + int dst_bc, int _overlay) + +### Description + + overlay() and overwrite() copy all the text from src_w into + dst_w. The windows need not be the same size. Those characters + in the source window that intersect with the destination window + are copied, so that the characters appear in the same physical + position on the screen. The difference between the two functions + is that overlay() is non-destructive (blanks are not copied) + while overwrite() is destructive (blanks are copied). + + copywin() is similar, but doesn't require that the two windows + overlap. The arguments src_tc and src_tr specify the top left + corner of the region to be copied. dst_tc, dst_tr, dst_br, and + dst_bc specify the region within the destination window to copy + to. The argument "overlay", if TRUE, indicates that the copy is + done non-destructively (as in overlay()); blanks in the source + window are not copied to the destination window. When overlay is + FALSE, blanks are copied. + +### Return Value + + All functions return OK on success and ERR on error. + +### Portability + X/Open BSD SYS V + overlay Y Y Y + overwrite Y Y Y + copywin Y - 3.0 + +**man-end****************************************************************/ + +/* Thanks to Andreas Otte for the + corrected overlay()/overwrite() behavior. */ + +static int _copy_win(const WINDOW *src_w, WINDOW *dst_w, int src_tr, + int src_tc, int src_br, int src_bc, int dst_tr, + int dst_tc, bool _overlay) +{ + int col, line, y1, fc, *minchng, *maxchng; + chtype *w1ptr, *w2ptr; + + int lc = 0; + int xdiff = src_bc - src_tc; + int ydiff = src_br - src_tr; + + if (!src_w || !dst_w) + return ERR; + + minchng = dst_w->_firstch; + maxchng = dst_w->_lastch; + + for (y1 = 0; y1 < dst_tr; y1++) + { + minchng++; + maxchng++; + } + + for (line = 0; line < ydiff; line++) + { + w1ptr = src_w->_y[line + src_tr] + src_tc; + w2ptr = dst_w->_y[line + dst_tr] + dst_tc; + + fc = _NO_CHANGE; + + for (col = 0; col < xdiff; col++) + { + if ((*w1ptr) != (*w2ptr) && + !((*w1ptr & A_CHARTEXT) == ' ' && _overlay)) + { + *w2ptr = *w1ptr; + + if (fc == _NO_CHANGE) + fc = col + dst_tc; + + lc = col + dst_tc; + } + + w1ptr++; + w2ptr++; + } + + if (*minchng == _NO_CHANGE) + { + *minchng = fc; + *maxchng = lc; + } + else if (fc != _NO_CHANGE) + { + if (fc < *minchng) + *minchng = fc; + if (lc > *maxchng) + *maxchng = lc; + } + + minchng++; + maxchng++; + } + + return OK; +} + +int _copy_overlap(const WINDOW *src_w, WINDOW *dst_w, bool overlay) +{ + int first_line, first_col, last_line, last_col; + int src_start_x, src_start_y, dst_start_x, dst_start_y; + int xdiff, ydiff; + + if (!src_w || !dst_w) + return ERR; + + first_col = max(dst_w->_begx, src_w->_begx); + first_line = max(dst_w->_begy, src_w->_begy); + + last_col = min(src_w->_begx + src_w->_maxx, dst_w->_begx + dst_w->_maxx); + last_line = min(src_w->_begy + src_w->_maxy, dst_w->_begy + dst_w->_maxy); + + /* determine the overlapping region of the two windows in real + coordinates */ + + /* if no overlapping region, do nothing */ + + if ((last_col < first_col) || (last_line < first_line)) + return OK; + + /* size of overlapping region */ + + xdiff = last_col - first_col; + ydiff = last_line - first_line; + + if (src_w->_begx <= dst_w->_begx) + { + src_start_x = dst_w->_begx - src_w->_begx; + dst_start_x = 0; + } + else + { + dst_start_x = src_w->_begx - dst_w->_begx; + src_start_x = 0; + } + + if (src_w->_begy <= dst_w->_begy) + { + src_start_y = dst_w->_begy - src_w->_begy; + dst_start_y = 0; + } + else + { + dst_start_y = src_w->_begy - dst_w->_begy; + src_start_y = 0; + } + + return _copy_win(src_w, dst_w, src_start_y, src_start_x, + src_start_y + ydiff, src_start_x + xdiff, + dst_start_y, dst_start_x, overlay); +} + +int overlay(const WINDOW *src_w, WINDOW *dst_w) +{ + PDC_LOG(("overlay() - called\n")); + + return _copy_overlap(src_w, dst_w, TRUE); +} + +int overwrite(const WINDOW *src_w, WINDOW *dst_w) +{ + PDC_LOG(("overwrite() - called\n")); + + return _copy_overlap(src_w, dst_w, FALSE); +} + +int copywin(const WINDOW *src_w, WINDOW *dst_w, int src_tr, int src_tc, + int dst_tr, int dst_tc, int dst_br, int dst_bc, int _overlay) +{ + int src_end_x, src_end_y; + int src_rows, src_cols, dst_rows, dst_cols; + int min_rows, min_cols; + + PDC_LOG(("copywin() - called\n")); + + if (!src_w || !dst_w || dst_w == curscr || dst_br >= dst_w->_maxy + || dst_bc >= dst_w->_maxx || dst_tr < 0 || dst_tc < 0) + return ERR; + + src_rows = src_w->_maxy - src_tr; + src_cols = src_w->_maxx - src_tc; + dst_rows = dst_br - dst_tr + 1; + dst_cols = dst_bc - dst_tc + 1; + + min_rows = min(src_rows, dst_rows); + min_cols = min(src_cols, dst_cols); + + src_end_y = src_tr + min_rows; + src_end_x = src_tc + min_cols; + + return _copy_win(src_w, dst_w, src_tr, src_tc, src_end_y, src_end_x, + dst_tr, dst_tc, _overlay); +} diff --git a/modules/ncurses/pdcurses/pdcurses/pad.c b/modules/ncurses/pdcurses/pdcurses/pad.c new file mode 100644 index 00000000..77bdec4c --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/pad.c @@ -0,0 +1,260 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +pad +--- + +### Synopsis + + WINDOW *newpad(int nlines, int ncols); + WINDOW *subpad(WINDOW *orig, int nlines, int ncols, + int begy, int begx); + int prefresh(WINDOW *win, int py, int px, int sy1, int sx1, + int sy2, int sx2); + int pnoutrefresh(WINDOW *w, int py, int px, int sy1, int sx1, + int sy2, int sx2); + int pechochar(WINDOW *pad, chtype ch); + int pecho_wchar(WINDOW *pad, const cchar_t *wch); + +### Description + + A pad is a special kind of window, which is not restricted by + the screen size, and is not necessarily associated with a + particular part of the screen. You can use a pad when you need + a large window, and only a part of the window will be on the + screen at one time. Pads are not refreshed automatically (e.g., + from scrolling or echoing of input). You can't call wrefresh() + with a pad as an argument; use prefresh() or pnoutrefresh() + instead. Note that these routines require additional parameters + to specify the part of the pad to be displayed, and the location + to use on the screen. + + newpad() creates a new pad data structure. + + subpad() creates a new sub-pad within a pad, at position (begy, + begx), with dimensions of nlines lines and ncols columns. This + position is relative to the pad, and not to the screen as with + subwin. Changes to either the parent pad or sub-pad will affect + both. When using sub-pads, you may need to call touchwin() + before calling prefresh(). + + pnoutrefresh() copies the specified pad to the virtual screen. + + prefresh() calls pnoutrefresh(), followed by doupdate(). + + These routines are analogous to wnoutrefresh() and wrefresh(). + (py, px) specifies the upper left corner of the part of the pad + to be displayed; (sy1, sx1) and (sy2, sx2) describe the screen + rectangle that will contain the selected part of the pad. + + pechochar() is functionally equivalent to addch() followed by + a call to prefresh(), with the last-used coordinates and + dimensions. pecho_wchar() is the wide-character version. + +### Return Value + + All functions return OK on success and ERR on error. + +### Portability + X/Open BSD SYS V + newpad Y - Y + subpad Y - Y + prefresh Y - Y + pnoutrefresh Y - Y + pechochar Y - 3.0 + pecho_wchar Y + +**man-end****************************************************************/ + +#include + +/* save values for pechochar() */ + +static int save_pminrow, save_pmincol; +static int save_sminrow, save_smincol, save_smaxrow, save_smaxcol; + +WINDOW *newpad(int nlines, int ncols) +{ + WINDOW *win; + + PDC_LOG(("newpad() - called: lines=%d cols=%d\n", nlines, ncols)); + + if ( !(win = PDC_makenew(nlines, ncols, 0, 0)) + || !(win = PDC_makelines(win)) ) + return (WINDOW *)NULL; + + werase(win); + + win->_flags = _PAD; + + /* save default values in case pechochar() is the first call to + prefresh(). */ + + save_pminrow = 0; + save_pmincol = 0; + save_sminrow = 0; + save_smincol = 0; + save_smaxrow = min(LINES, nlines) - 1; + save_smaxcol = min(COLS, ncols) - 1; + + return win; +} + +WINDOW *subpad(WINDOW *orig, int nlines, int ncols, int begy, int begx) +{ + WINDOW *win; + int i; + + PDC_LOG(("subpad() - called: lines=%d cols=%d begy=%d begx=%d\n", + nlines, ncols, begy, begx)); + + if (!orig || !(orig->_flags & _PAD)) + return (WINDOW *)NULL; + + /* make sure window fits inside the original one */ + + if (begy < 0 || begx < 0 || + (begy + nlines) > orig->_maxy || + (begx + ncols) > orig->_maxx) + return (WINDOW *)NULL; + + if (!nlines) + nlines = orig->_maxy - begy; + + if (!ncols) + ncols = orig->_maxx - begx; + + if ( !(win = PDC_makenew(nlines, ncols, begy, begx)) ) + return (WINDOW *)NULL; + + /* initialize window variables */ + + win->_attrs = orig->_attrs; + win->_leaveit = orig->_leaveit; + win->_scroll = orig->_scroll; + win->_nodelay = orig->_nodelay; + win->_use_keypad = orig->_use_keypad; + win->_parent = orig; + + for (i = 0; i < nlines; i++) + win->_y[i] = orig->_y[begy + i] + begx; + + win->_flags = _SUBPAD; + + /* save default values in case pechochar() is the first call + to prefresh(). */ + + save_pminrow = 0; + save_pmincol = 0; + save_sminrow = 0; + save_smincol = 0; + save_smaxrow = min(LINES, nlines) - 1; + save_smaxcol = min(COLS, ncols) - 1; + + return win; +} + +int prefresh(WINDOW *win, int py, int px, int sy1, int sx1, int sy2, int sx2) +{ + PDC_LOG(("prefresh() - called\n")); + + if (pnoutrefresh(win, py, px, sy1, sx1, sy2, sx2) == ERR) + return ERR; + + doupdate(); + return OK; +} + +int pnoutrefresh(WINDOW *w, int py, int px, int sy1, int sx1, int sy2, int sx2) +{ + int num_cols; + int sline = sy1; + int pline = py; + + PDC_LOG(("pnoutrefresh() - called\n")); + + if (!w || !(w->_flags & (_PAD|_SUBPAD)) || (sy2 >= LINES) || (sx2 >= COLS)) + return ERR; + + if (py < 0) + py = 0; + if (px < 0) + px = 0; + if (sy1 < 0) + sy1 = 0; + if (sx1 < 0) + sx1 = 0; + + if (sy2 < sy1 || sx2 < sx1) + return ERR; + + num_cols = min((sx2 - sx1 + 1), (w->_maxx - px)); + + while (sline <= sy2) + { + if (pline < w->_maxy) + { + memcpy(curscr->_y[sline] + sx1, w->_y[pline] + px, + num_cols * sizeof(chtype)); + + if ((curscr->_firstch[sline] == _NO_CHANGE) + || (curscr->_firstch[sline] > sx1)) + curscr->_firstch[sline] = sx1; + + if (sx2 > curscr->_lastch[sline]) + curscr->_lastch[sline] = sx2; + + w->_firstch[pline] = _NO_CHANGE; /* updated now */ + w->_lastch[pline] = _NO_CHANGE; /* updated now */ + } + + sline++; + pline++; + } + + if (w->_clear) + { + w->_clear = FALSE; + curscr->_clear = TRUE; + } + + /* position the cursor to the pad's current position if possible -- + is the pad current position going to end up displayed? if not, + then don't move the cursor; if so, move it to the correct place */ + + if (!w->_leaveit && w->_cury >= py && w->_curx >= px && + w->_cury <= py + (sy2 - sy1) && w->_curx <= px + (sx2 - sx1)) + { + curscr->_cury = (w->_cury - py) + sy1; + curscr->_curx = (w->_curx - px) + sx1; + } + + return OK; +} + +int pechochar(WINDOW *pad, chtype ch) +{ + PDC_LOG(("pechochar() - called\n")); + + if (waddch(pad, ch) == ERR) + return ERR; + + return prefresh(pad, save_pminrow, save_pmincol, save_sminrow, + save_smincol, save_smaxrow, save_smaxcol); +} + +#ifdef PDC_WIDE +int pecho_wchar(WINDOW *pad, const cchar_t *wch) +{ + PDC_LOG(("pecho_wchar() - called\n")); + + if (!wch || (waddch(pad, *wch) == ERR)) + return ERR; + + return prefresh(pad, save_pminrow, save_pmincol, save_sminrow, + save_smincol, save_smaxrow, save_smaxcol); +} +#endif diff --git a/modules/ncurses/pdcurses/pdcurses/panel.c b/modules/ncurses/pdcurses/pdcurses/panel.c new file mode 100644 index 00000000..95b3e600 --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/panel.c @@ -0,0 +1,641 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +panel +----- + +### Synopsis + + int bottom_panel(PANEL *pan); + int del_panel(PANEL *pan); + int hide_panel(PANEL *pan); + int move_panel(PANEL *pan, int starty, int startx); + PANEL *new_panel(WINDOW *win); + PANEL *panel_above(const PANEL *pan); + PANEL *panel_below(const PANEL *pan); + int panel_hidden(const PANEL *pan); + const void *panel_userptr(const PANEL *pan); + WINDOW *panel_window(const PANEL *pan); + int replace_panel(PANEL *pan, WINDOW *win); + int set_panel_userptr(PANEL *pan, const void *uptr); + int show_panel(PANEL *pan); + int top_panel(PANEL *pan); + void update_panels(void); + +### Description + + The panel library is built using the curses library, and any + program using panels routines must call one of the curses + initialization routines such as initscr(). A program using these + routines must be linked with the panels and curses libraries. + The header includes the header . + + The panels package gives the applications programmer a way to + have depth relationships between curses windows; a curses window + is associated with every panel. The panels routines allow curses + windows to overlap without making visible the overlapped + portions of underlying windows. The initial curses window, + stdscr, lies beneath all panels. The set of currently visible + panels is the 'deck' of panels. + + The panels package allows the applications programmer to create + panels, fetch and set their associated windows, shuffle panels + in the deck, and manipulate panels in other ways. + + bottom_panel() places pan at the bottom of the deck. The size, + location and contents of the panel are unchanged. + + del_panel() deletes pan, but not its associated winwow. + + hide_panel() removes a panel from the deck and thus hides it + from view. + + move_panel() moves the curses window associated with pan, so + that its upper lefthand corner is at the supplied coordinates. + (Do not use mvwin() on the window.) + + new_panel() creates a new panel associated with win and returns + the panel pointer. The new panel is placed at the top of the + deck. + + panel_above() returns a pointer to the panel in the deck above + pan, or NULL if pan is the top panel. If the value of pan passed + is NULL, this function returns a pointer to the bottom panel in + the deck. + + panel_below() returns a pointer to the panel in the deck below + pan, or NULL if pan is the bottom panel. If the value of pan + passed is NULL, this function returns a pointer to the top panel + in the deck. + + panel_hidden() returns OK if pan is hidden and ERR if it is not. + + panel_userptr() - Each panel has a user pointer available for + maintaining relevant information. This function returns a + pointer to that information previously set up by + set_panel_userptr(). + + panel_window() returns a pointer to the curses window associated + with the panel. + + replace_panel() replaces the current window of pan with win. + + set_panel_userptr() - Each panel has a user pointer available + for maintaining relevant information. This function sets the + value of that information. + + show_panel() makes a previously hidden panel visible and places + it back in the deck on top. + + top_panel() places pan on the top of the deck. The size, + location and contents of the panel are unchanged. + + update_panels() refreshes the virtual screen to reflect the + depth relationships between the panels in the deck. The user + must use doupdate() to refresh the physical screen. + +### Return Value + + Each routine that returns a pointer to an object returns NULL if + an error occurs. Each panel routine that returns an integer, + returns OK if it executes successfully and ERR if it does not. + +### Portability + X/Open BSD SYS V + bottom_panel - - Y + del_panel - - Y + hide_panel - - Y + move_panel - - Y + new_panel - - Y + panel_above - - Y + panel_below - - Y + panel_hidden - - Y + panel_userptr - - Y + panel_window - - Y + replace_panel - - Y + set_panel_userptr - - Y + show_panel - - Y + top_panel - - Y + update_panels - - Y + + Credits: + Original Author - Warren Tucker + +**man-end****************************************************************/ + +#include +#include + +PANEL *_bottom_panel = (PANEL *)0; +PANEL *_top_panel = (PANEL *)0; +PANEL _stdscr_pseudo_panel = { (WINDOW *)0 }; + +#ifdef PANEL_DEBUG + +static void dPanel(char *text, PANEL *pan) +{ + PDC_LOG(("%s id=%s b=%s a=%s y=%d x=%d", text, pan->user, + pan->below ? pan->below->user : "--", + pan->above ? pan->above->user : "--", + pan->wstarty, pan->wstartx)); +} + +static void dStack(char *fmt, int num, PANEL *pan) +{ + char s80[80]; + + sprintf(s80, fmt, num, pan); + PDC_LOG(("%s b=%s t=%s", s80, _bottom_panel ? _bottom_panel->user : "--", + _top_panel ? _top_panel->user : "--")); + + if (pan) + PDC_LOG(("pan id=%s", pan->user)); + + pan = _bottom_panel; + + while (pan) + { + dPanel("stk", pan); + pan = pan->above; + } +} + +/* debugging hook for wnoutrefresh */ + +static void Wnoutrefresh(PANEL *pan) +{ + dPanel("wnoutrefresh", pan); + wnoutrefresh(pan->win); +} + +static void Touchpan(PANEL *pan) +{ + dPanel("Touchpan", pan); + touchwin(pan->win); +} + +static void Touchline(PANEL *pan, int start, int count) +{ + char s80[80]; + + sprintf(s80, "Touchline s=%d c=%d", start, count); + dPanel(s80, pan); + touchline(pan->win, start, count); +} + +#else /* PANEL_DEBUG */ + +#define dPanel(text, pan) +#define dStack(fmt, num, pan) +#define Wnoutrefresh(pan) wnoutrefresh((pan)->win) +#define Touchpan(pan) touchwin((pan)->win) +#define Touchline(pan, start, count) touchline((pan)->win, start, count) + +#endif /* PANEL_DEBUG */ + +static bool _panels_overlapped(PANEL *pan1, PANEL *pan2) +{ + if (!pan1 || !pan2) + return FALSE; + + return ((pan1->wstarty >= pan2->wstarty && pan1->wstarty < pan2->wendy) + || (pan2->wstarty >= pan1->wstarty && pan2->wstarty < pan1->wendy)) + && ((pan1->wstartx >= pan2->wstartx && pan1->wstartx < pan2->wendx) + || (pan2->wstartx >= pan1->wstartx && pan2->wstartx < pan1->wendx)); +} + +static void _free_obscure(PANEL *pan) +{ + PANELOBS *tobs = pan->obscure; /* "this" one */ + PANELOBS *nobs; /* "next" one */ + + while (tobs) + { + nobs = tobs->above; + free((char *)tobs); + tobs = nobs; + } + pan->obscure = (PANELOBS *)0; +} + +static void _override(PANEL *pan, int show) +{ + int y; + PANEL *pan2; + PANELOBS *tobs = pan->obscure; /* "this" one */ + + if (show == 1) + Touchpan(pan); + else if (!show) + { + Touchpan(pan); + Touchpan(&_stdscr_pseudo_panel); + } + else if (show == -1) + while (tobs && (tobs->pan != pan)) + tobs = tobs->above; + + while (tobs) + { + if ((pan2 = tobs->pan) != pan) + for (y = pan->wstarty; y < pan->wendy; y++) + if ((y >= pan2->wstarty) && (y < pan2->wendy) && + ((is_linetouched(pan->win, y - pan->wstarty)) || + (is_linetouched(stdscr, y)))) + Touchline(pan2, y - pan2->wstarty, 1); + + tobs = tobs->above; + } +} + +static void _calculate_obscure(void) +{ + PANEL *pan, *pan2; + PANELOBS *tobs; /* "this" one */ + PANELOBS *lobs; /* last one */ + + pan = _bottom_panel; + + while (pan) + { + if (pan->obscure) + _free_obscure(pan); + + lobs = (PANELOBS *)0; + pan2 = _bottom_panel; + + while (pan2) + { + if (_panels_overlapped(pan, pan2)) + { + if ((tobs = malloc(sizeof(PANELOBS))) == NULL) + return; + + tobs->pan = pan2; + dPanel("obscured", pan2); + tobs->above = (PANELOBS *)0; + + if (lobs) + lobs->above = tobs; + else + pan->obscure = tobs; + + lobs = tobs; + } + + pan2 = pan2->above; + } + + _override(pan, 1); + pan = pan->above; + } +} + +/* check to see if panel is in the stack */ + +static bool _panel_is_linked(const PANEL *pan) +{ + PANEL *pan2 = _bottom_panel; + + while (pan2) + { + if (pan2 == pan) + return TRUE; + + pan2 = pan2->above; + } + + return FALSE; +} + +/* link panel into stack at top */ + +static void _panel_link_top(PANEL *pan) +{ +#ifdef PANEL_DEBUG + dStack("", 1, pan); + if (_panel_is_linked(pan)) + return; +#endif + pan->above = (PANEL *)0; + pan->below = (PANEL *)0; + + if (_top_panel) + { + _top_panel->above = pan; + pan->below = _top_panel; + } + + _top_panel = pan; + + if (!_bottom_panel) + _bottom_panel = pan; + + _calculate_obscure(); + dStack("", 9, pan); +} + +/* link panel into stack at bottom */ + +static void _panel_link_bottom(PANEL *pan) +{ +#ifdef PANEL_DEBUG + dStack("", 1, pan); + if (_panel_is_linked(pan)) + return; +#endif + pan->above = (PANEL *)0; + pan->below = (PANEL *)0; + + if (_bottom_panel) + { + _bottom_panel->below = pan; + pan->above = _bottom_panel; + } + + _bottom_panel = pan; + + if (!_top_panel) + _top_panel = pan; + + _calculate_obscure(); + dStack("", 9, pan); +} + +static void _panel_unlink(PANEL *pan) +{ + PANEL *prev; + PANEL *next; + +#ifdef PANEL_DEBUG + dStack("", 1, pan); + if (!_panel_is_linked(pan)) + return; +#endif + _override(pan, 0); + _free_obscure(pan); + + prev = pan->below; + next = pan->above; + + /* if non-zero, we will not update the list head */ + + if (prev) + { + prev->above = next; + if(next) + next->below = prev; + } + else if (next) + next->below = prev; + + if (pan == _bottom_panel) + _bottom_panel = next; + + if (pan == _top_panel) + _top_panel = prev; + + _calculate_obscure(); + + pan->above = (PANEL *)0; + pan->below = (PANEL *)0; + dStack("", 9, pan); + +} + +/************************************************************************ + * The following are the public functions for the panels library. * + ************************************************************************/ + +int bottom_panel(PANEL *pan) +{ + if (!pan) + return ERR; + + if (pan == _bottom_panel) + return OK; + + if (_panel_is_linked(pan)) + hide_panel(pan); + + _panel_link_bottom(pan); + + return OK; +} + +int del_panel(PANEL *pan) +{ + if (pan) + { + if (_panel_is_linked(pan)) + hide_panel(pan); + + free((char *)pan); + return OK; + } + + return ERR; +} + +int hide_panel(PANEL *pan) +{ + if (!pan) + return ERR; + + if (!_panel_is_linked(pan)) + { + pan->above = (PANEL *)0; + pan->below = (PANEL *)0; + return ERR; + } + + _panel_unlink(pan); + + return OK; +} + +int move_panel(PANEL *pan, int starty, int startx) +{ + WINDOW *win; + int maxy, maxx; + + if (!pan) + return ERR; + + if (_panel_is_linked(pan)) + _override(pan, 0); + + win = pan->win; + + if (mvwin(win, starty, startx) == ERR) + return ERR; + + getbegyx(win, pan->wstarty, pan->wstartx); + getmaxyx(win, maxy, maxx); + pan->wendy = pan->wstarty + maxy; + pan->wendx = pan->wstartx + maxx; + + if (_panel_is_linked(pan)) + _calculate_obscure(); + + return OK; +} + +PANEL *new_panel(WINDOW *win) +{ + PANEL *pan; + + if (!win) + return (PANEL *)NULL; + + pan = malloc(sizeof(PANEL)); + + if (!_stdscr_pseudo_panel.win) + { + _stdscr_pseudo_panel.win = stdscr; + _stdscr_pseudo_panel.wstarty = 0; + _stdscr_pseudo_panel.wstartx = 0; + _stdscr_pseudo_panel.wendy = LINES; + _stdscr_pseudo_panel.wendx = COLS; + _stdscr_pseudo_panel.user = "stdscr"; + _stdscr_pseudo_panel.obscure = (PANELOBS *)0; + } + + if (pan) + { + int maxy, maxx; + + pan->win = win; + pan->above = (PANEL *)0; + pan->below = (PANEL *)0; + getbegyx(win, pan->wstarty, pan->wstartx); + getmaxyx(win, maxy, maxx); + pan->wendy = pan->wstarty + maxy; + pan->wendx = pan->wstartx + maxx; +#ifdef PANEL_DEBUG + pan->user = "new"; +#else + pan->user = (char *)0; +#endif + pan->obscure = (PANELOBS *)0; + show_panel(pan); + } + + return pan; +} + +PANEL *panel_above(const PANEL *pan) +{ + return pan ? pan->above : _bottom_panel; +} + +PANEL *panel_below(const PANEL *pan) +{ + return pan ? pan->below : _top_panel; +} + +int panel_hidden(const PANEL *pan) +{ + if (!pan) + return ERR; + + return _panel_is_linked(pan) ? ERR : OK; +} + +const void *panel_userptr(const PANEL *pan) +{ + return pan ? pan->user : NULL; +} + +WINDOW *panel_window(const PANEL *pan) +{ + PDC_LOG(("panel_window() - called\n")); + + if (!pan) + return (WINDOW *)NULL; + + return pan->win; +} + +int replace_panel(PANEL *pan, WINDOW *win) +{ + int maxy, maxx; + + if (!pan) + return ERR; + + if (_panel_is_linked(pan)) + _override(pan, 0); + + pan->win = win; + getbegyx(win, pan->wstarty, pan->wstartx); + getmaxyx(win, maxy, maxx); + pan->wendy = pan->wstarty + maxy; + pan->wendx = pan->wstartx + maxx; + + if (_panel_is_linked(pan)) + _calculate_obscure(); + + return OK; +} + +int set_panel_userptr(PANEL *pan, const void *uptr) +{ + if (!pan) + return ERR; + + pan->user = uptr; + return OK; +} + +int show_panel(PANEL *pan) +{ + if (!pan) + return ERR; + + if (pan == _top_panel) + return OK; + + if (_panel_is_linked(pan)) + hide_panel(pan); + + _panel_link_top(pan); + + return OK; +} + +int top_panel(PANEL *pan) +{ + return show_panel(pan); +} + +void update_panels(void) +{ + PANEL *pan; + + PDC_LOG(("update_panels() - called\n")); + + pan = _bottom_panel; + + while (pan) + { + _override(pan, -1); + pan = pan->above; + } + + if (is_wintouched(stdscr)) + Wnoutrefresh(&_stdscr_pseudo_panel); + + pan = _bottom_panel; + + while (pan) + { + if (is_wintouched(pan->win) || !pan->above) + Wnoutrefresh(pan); + + pan = pan->above; + } +} diff --git a/modules/ncurses/pdcurses/pdcurses/printw.c b/modules/ncurses/pdcurses/pdcurses/printw.c new file mode 100644 index 00000000..3961faa7 --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/printw.c @@ -0,0 +1,126 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +printw +------ + +### Synopsis + + int printw(const char *fmt, ...); + int wprintw(WINDOW *win, const char *fmt, ...); + int mvprintw(int y, int x, const char *fmt, ...); + int mvwprintw(WINDOW *win, int y, int x, const char *fmt,...); + int vwprintw(WINDOW *win, const char *fmt, va_list varglist); + int vw_printw(WINDOW *win, const char *fmt, va_list varglist); + +### Description + + The printw() functions add a formatted string to the window at + the current or specified cursor position. The format strings are + the same as used in the standard C library's printf(). (printw() + can be used as a drop-in replacement for printf().) + +### Return Value + + All functions return the number of characters printed, or + ERR on error. + +### Portability + X/Open BSD SYS V + printw Y Y Y + wprintw Y Y Y + mvprintw Y Y Y + mvwprintw Y Y Y + vwprintw Y - 4.0 + vw_printw Y + +**man-end****************************************************************/ + +#include + +int vwprintw(WINDOW *win, const char *fmt, va_list varglist) +{ + char printbuf[513]; + int len; + + PDC_LOG(("vwprintw() - called\n")); + +#ifdef HAVE_VSNPRINTF + len = vsnprintf(printbuf, 512, fmt, varglist); +#else + len = vsprintf(printbuf, fmt, varglist); +#endif + return (waddstr(win, printbuf) == ERR) ? ERR : len; +} + +int printw(const char *fmt, ...) +{ + va_list args; + int retval; + + PDC_LOG(("printw() - called\n")); + + va_start(args, fmt); + retval = vwprintw(stdscr, fmt, args); + va_end(args); + + return retval; +} + +int wprintw(WINDOW *win, const char *fmt, ...) +{ + va_list args; + int retval; + + PDC_LOG(("wprintw() - called\n")); + + va_start(args, fmt); + retval = vwprintw(win, fmt, args); + va_end(args); + + return retval; +} + +int mvprintw(int y, int x, const char *fmt, ...) +{ + va_list args; + int retval; + + PDC_LOG(("mvprintw() - called\n")); + + if (move(y, x) == ERR) + return ERR; + + va_start(args, fmt); + retval = vwprintw(stdscr, fmt, args); + va_end(args); + + return retval; +} + +int mvwprintw(WINDOW *win, int y, int x, const char *fmt, ...) +{ + va_list args; + int retval; + + PDC_LOG(("mvwprintw() - called\n")); + + if (wmove(win, y, x) == ERR) + return ERR; + + va_start(args, fmt); + retval = vwprintw(win, fmt, args); + va_end(args); + + return retval; +} + +int vw_printw(WINDOW *win, const char *fmt, va_list varglist) +{ + PDC_LOG(("vw_printw() - called\n")); + + return vwprintw(win, fmt, varglist); +} diff --git a/modules/ncurses/pdcurses/pdcurses/refresh.c b/modules/ncurses/pdcurses/pdcurses/refresh.c new file mode 100644 index 00000000..feba35d3 --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/refresh.c @@ -0,0 +1,279 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +refresh +------- + +### Synopsis + + 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); + +### Description + + wrefresh() copies the named window to the physical terminal + screen, taking into account what is already there in order to + optimize cursor movement. refresh() does the same, using stdscr. + These routines must be called to get any output on the terminal, + as other routines only manipulate data structures. Unless + leaveok() has been enabled, the physical cursor of the terminal + is left at the location of the window's cursor. + + wnoutrefresh() and doupdate() allow multiple updates with more + efficiency than wrefresh() alone. wrefresh() works by first + calling wnoutrefresh(), which copies the named window to the + virtual screen. It then calls doupdate(), which compares the + virtual screen to the physical screen and does the actual + update. A series of calls to wrefresh() will result in + alternating calls to wnoutrefresh() and doupdate(), causing + several bursts of output to the screen. By first calling + wnoutrefresh() for each window, it is then possible to call + doupdate() only once. + + In PDCurses, redrawwin() is equivalent to touchwin(), and + wredrawln() is the same as touchline(). In some other curses + implementations, there's a subtle distinction, but it has no + meaning in PDCurses. + +### Return Value + + All functions return OK on success and ERR on error. + +### Portability + X/Open BSD SYS V + refresh Y Y Y + wrefresh Y Y Y + wnoutrefresh Y Y Y + doupdate Y Y Y + redrawwin Y - 4.0 + wredrawln Y - 4.0 + +**man-end****************************************************************/ + +#include + +int wnoutrefresh(WINDOW *win) +{ + int begy, begx; /* window's place on screen */ + int i, j; + + PDC_LOG(("wnoutrefresh() - called: win=%p\n", win)); + + if ( !win || (win->_flags & (_PAD|_SUBPAD)) ) + return ERR; + + begy = win->_begy; + begx = win->_begx; + + for (i = 0, j = begy; i < win->_maxy; i++, j++) + { + if (win->_firstch[i] != _NO_CHANGE) + { + chtype *src = win->_y[i]; + chtype *dest = curscr->_y[j] + begx; + + int first = win->_firstch[i]; /* first changed */ + int last = win->_lastch[i]; /* last changed */ + + /* ignore areas on the outside that are marked as changed, + but really aren't */ + + while (first <= last && src[first] == dest[first]) + first++; + + while (last >= first && src[last] == dest[last]) + last--; + + /* if any have really changed... */ + + if (first <= last) + { + memcpy(dest + first, src + first, + (last - first + 1) * sizeof(chtype)); + + first += begx; + last += begx; + + if (first < curscr->_firstch[j] || + curscr->_firstch[j] == _NO_CHANGE) + curscr->_firstch[j] = first; + + if (last > curscr->_lastch[j]) + curscr->_lastch[j] = last; + } + + win->_firstch[i] = _NO_CHANGE; /* updated now */ + } + + win->_lastch[i] = _NO_CHANGE; /* updated now */ + } + + if (win->_clear) + win->_clear = FALSE; + + if (!win->_leaveit) + { + curscr->_cury = win->_cury + begy; + curscr->_curx = win->_curx + begx; + } + + return OK; +} + +int doupdate(void) +{ + int y; + bool clearall; + + PDC_LOG(("doupdate() - called\n")); + + if (!curscr) + return ERR; + + if (isendwin()) /* coming back after endwin() called */ + { + reset_prog_mode(); + clearall = TRUE; + SP->alive = TRUE; /* so isendwin() result is correct */ + } + else + clearall = curscr->_clear; + + for (y = 0; y < SP->lines; y++) + { + PDC_LOG(("doupdate() - Transforming line %d of %d: %s\n", + y, SP->lines, (curscr->_firstch[y] != _NO_CHANGE) ? + "Yes" : "No")); + + if (clearall || curscr->_firstch[y] != _NO_CHANGE) + { + int first, last; + + chtype *src = curscr->_y[y]; + chtype *dest = pdc_lastscr->_y[y]; + + if (clearall) + { + first = 0; + last = COLS - 1; + } + else + { + first = curscr->_firstch[y]; + last = curscr->_lastch[y]; + } + + while (first <= last) + { + int len = 0; + + /* build up a run of changed cells; if two runs are + separated by a single unchanged cell, ignore the + break */ + + if (clearall) + len = last - first + 1; + else + while (first + len <= last && + (src[first + len] != dest[first + len] || + (len && first + len < last && + src[first + len + 1] != dest[first + len + 1]) + ) + ) + len++; + + /* update the screen, and pdc_lastscr */ + + if (len) + { + PDC_transform_line(y, first, len, src + first); + memcpy(dest + first, src + first, len * sizeof(chtype)); + first += len; + } + + /* skip over runs of unchanged cells */ + + while (first <= last && src[first] == dest[first]) + first++; + } + + curscr->_firstch[y] = _NO_CHANGE; + curscr->_lastch[y] = _NO_CHANGE; + } + } + + curscr->_clear = FALSE; + + if (SP->visibility) + PDC_gotoyx(curscr->_cury, curscr->_curx); + + SP->cursrow = curscr->_cury; + SP->curscol = curscr->_curx; + + return OK; +} + +int wrefresh(WINDOW *win) +{ + bool save_clear; + + PDC_LOG(("wrefresh() - called\n")); + + if ( !win || (win->_flags & (_PAD|_SUBPAD)) ) + return ERR; + + save_clear = win->_clear; + + if (win == curscr) + curscr->_clear = TRUE; + else + wnoutrefresh(win); + + if (save_clear && win->_maxy == SP->lines && win->_maxx == SP->cols) + curscr->_clear = TRUE; + + return doupdate(); +} + +int refresh(void) +{ + PDC_LOG(("refresh() - called\n")); + + return wrefresh(stdscr); +} + +int wredrawln(WINDOW *win, int start, int num) +{ + int i; + + PDC_LOG(("wredrawln() - called: win=%p start=%d num=%d\n", + win, start, num)); + + if (!win || start > win->_maxy || start + num > win->_maxy) + return ERR; + + for (i = start; i < start + num; i++) + { + win->_firstch[i] = 0; + win->_lastch[i] = win->_maxx - 1; + } + + return OK; +} + +int redrawwin(WINDOW *win) +{ + PDC_LOG(("redrawwin() - called: win=%p\n", win)); + + if (!win) + return ERR; + + return wredrawln(win, 0, win->_maxy); +} diff --git a/modules/ncurses/pdcurses/pdcurses/scanw.c b/modules/ncurses/pdcurses/pdcurses/scanw.c new file mode 100644 index 00000000..659b121b --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/scanw.c @@ -0,0 +1,578 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +scanw +----- + +### Synopsis + + int scanw(const char *fmt, ...); + int wscanw(WINDOW *win, const char *fmt, ...); + int mvscanw(int y, int x, const char *fmt, ...); + int mvwscanw(WINDOW *win, int y, int x, const char *fmt, ...); + int vwscanw(WINDOW *win, const char *fmt, va_list varglist); + int vw_scanw(WINDOW *win, const char *fmt, va_list varglist); + +### Description + + These routines correspond to the standard C library's scanf() + family. Each gets a string from the window via wgetnstr(), and + uses the resulting line as input for the scan. + +### Return Value + + On successful completion, these functions return the number of + items successfully matched. Otherwise they return ERR. + +### Portability + X/Open BSD SYS V + scanw Y Y Y + wscanw Y Y Y + mvscanw Y Y Y + mvwscanw Y Y Y + vwscanw Y - 4.0 + vw_scanw Y + +**man-end****************************************************************/ + +#include + +#ifndef HAVE_VSSCANF +# include +# include +# include + +static int _pdc_vsscanf(const char *, const char *, va_list); + +# define vsscanf _pdc_vsscanf +#endif + +int vwscanw(WINDOW *win, const char *fmt, va_list varglist) +{ + char scanbuf[256]; + + PDC_LOG(("vwscanw() - called\n")); + + if (wgetnstr(win, scanbuf, 255) == ERR) + return ERR; + + return vsscanf(scanbuf, fmt, varglist); +} + +int scanw(const char *fmt, ...) +{ + va_list args; + int retval; + + PDC_LOG(("scanw() - called\n")); + + va_start(args, fmt); + retval = vwscanw(stdscr, fmt, args); + va_end(args); + + return retval; +} + +int wscanw(WINDOW *win, const char *fmt, ...) +{ + va_list args; + int retval; + + PDC_LOG(("wscanw() - called\n")); + + va_start(args, fmt); + retval = vwscanw(win, fmt, args); + va_end(args); + + return retval; +} + +int mvscanw(int y, int x, const char *fmt, ...) +{ + va_list args; + int retval; + + PDC_LOG(("mvscanw() - called\n")); + + if (move(y, x) == ERR) + return ERR; + + va_start(args, fmt); + retval = vwscanw(stdscr, fmt, args); + va_end(args); + + return retval; +} + +int mvwscanw(WINDOW *win, int y, int x, const char *fmt, ...) +{ + va_list args; + int retval; + + PDC_LOG(("mvscanw() - called\n")); + + if (wmove(win, y, x) == ERR) + return ERR; + + va_start(args, fmt); + retval = vwscanw(win, fmt, args); + va_end(args); + + return retval; +} + +int vw_scanw(WINDOW *win, const char *fmt, va_list varglist) +{ + PDC_LOG(("vw_scanw() - called\n")); + + return vwscanw(win, fmt, varglist); +} + +#ifndef HAVE_VSSCANF + +/* _pdc_vsscanf() - Internal routine to parse and format an input + buffer. It scans a series of input fields; each field is formatted + according to a supplied format string and the formatted input is + stored in the variable number of addresses passed. Returns the number + of input fields or EOF on error. + + Don't compile this unless required. Some compilers (at least Borland + C++ 3.0) have to link with math libraries due to the use of floats. + + Based on vsscanf.c and input.c from emx 0.8f library source, + Copyright (c) 1990-1992 by Eberhard Mattes, who has kindly agreed to + its inclusion in PDCurses. */ + +#define WHITE(x) ((x) == ' ' || (x) == '\t' || (x) == '\n') + +#define NEXT(x) \ + do { \ + x = *buf++; \ + if (!x) \ + return (count ? count : EOF); \ + ++chars; \ + } while (0) + +#define UNGETC() \ + do { \ + --buf; --chars; \ + } while (0) + +static int _pdc_vsscanf(const char *buf, const char *fmt, va_list arg_ptr) +{ + int count, chars, c, width, radix, d, i; + int *int_ptr; + long *long_ptr; + short *short_ptr; + char *char_ptr; + unsigned char f; + char neg, assign, ok, size; + long n; + char map[256], end; + double dx, dd, *dbl_ptr; + float *flt_ptr; + int exp; + char eneg; + + count = 0; + chars = 0; + c = 0; + while ((f = *fmt) != 0) + { + if (WHITE(f)) + { + do + { + ++fmt; + f = *fmt; + } + while (WHITE(f)); + do + { + c = *buf++; + if (!c) + { + if (!f || count) + return count; + else + return EOF; + } else + ++chars; + } + while (WHITE(c)); + UNGETC(); + } else if (f != '%') + { + NEXT(c); + if (c != f) + return count; + ++fmt; + } else + { + assign = TRUE; + width = INT_MAX; + char_ptr = NULL; + ++fmt; + if (*fmt == '*') + { + assign = FALSE; + ++fmt; + } + if (isdigit(*fmt)) + { + width = 0; + while (isdigit(*fmt)) + width = width * 10 + (*fmt++ - '0'); + if (!width) + width = INT_MAX; + } + size = 0; + if (*fmt == 'h' || *fmt == 'l') + size = *fmt++; + f = *fmt; + switch (f) + { + case 'c': + if (width == INT_MAX) + width = 1; + if (assign) + char_ptr = va_arg(arg_ptr, char *); + while (width > 0) + { + --width; + NEXT(c); + if (assign) + { + *char_ptr++ = (char) c; + ++count; + } + } + break; + case '[': + memset(map, 0, 256); + end = 0; + ++fmt; + if (*fmt == '^') + { + ++fmt; + end = 1; + } + i = 0; + for (;;) + { + f = (unsigned char) *fmt; + switch (f) + { + case 0: + /* avoid skipping past 0 */ + --fmt; + NEXT(c); + goto string; + case ']': + if (i > 0) + { + NEXT(c); + goto string; + } + /* no break */ + default: + if (fmt[1] == '-' && fmt[2] + && f < (unsigned char)fmt[2]) + { + memset(map + f, 1, (unsigned char)fmt[2] - f); + fmt += 2; + } + else + map[f] = 1; + break; + } + ++fmt; + ++i; + } + case 's': + memset(map, 0, 256); + map[' '] = 1; + map['\n'] = 1; + map['\r'] = 1; + map['\t'] = 1; + end = 1; + do + { + NEXT(c); + } + while (WHITE(c)); + string: + if (assign) + char_ptr = va_arg(arg_ptr, char *); + while (width > 0 && map[(unsigned char) c] != end) + { + --width; + if (assign) + *char_ptr++ = (char) c; + c = *buf++; + if (!c) + break; + else + ++chars; + } + if (assign) + { + *char_ptr = 0; + ++count; + } + if (!c) + return count; + else + UNGETC(); + break; + case 'f': + case 'e': + case 'E': + case 'g': + case 'G': + neg = ok = FALSE; + dx = 0.0; + do + { + NEXT(c); + } + while (WHITE(c)); + if (c == '+') + { + NEXT(c); + --width; + } else if (c == '-') + { + neg = TRUE; + NEXT(c); + --width; + } + while (width > 0 && isdigit(c)) + { + --width; + dx = dx * 10.0 + (double) (c - '0'); + ok = TRUE; + c = *buf++; + if (!c) + break; + else + ++chars; + } + if (width > 0 && c == '.') + { + --width; + dd = 10.0; + NEXT(c); + while (width > 0 && isdigit(c)) + { + --width; + dx += (double) (c - '0') / dd; + dd *= 10.0; + ok = TRUE; + c = *buf++; + if (!c) + break; + else + ++chars; + } + } + if (!ok) + return count; + if (width > 0 && (c == 'e' || c == 'E')) + { + eneg = FALSE; + exp = 0; + NEXT(c); + --width; + if (width > 0 && c == '+') + { + NEXT(c); + --width; + } else if (width > 0 && c == '-') + { + eneg = TRUE; + NEXT(c); + --width; + } + if (!(width > 0 && isdigit(c))) + { + UNGETC(); + return count; + } + while (width > 0 && isdigit(c)) + { + --width; + exp = exp * 10 + (c - '0'); + c = *buf++; + if (!c) + break; + else + ++chars; + } + if (eneg) + exp = -exp; + while (exp > 0) + { + dx *= 10.0; + --exp; + } + while (exp < 0) + { + dx /= 10.0; + ++exp; + } + } + if (assign) + { + if (neg) + dx = -dx; + if (size == 'l') + { + dbl_ptr = va_arg(arg_ptr, double *); + *dbl_ptr = dx; + } + else + { + flt_ptr = va_arg(arg_ptr, float *); + *flt_ptr = (float)dx; + } + ++count; + } + if (!c) + return count; + else + UNGETC(); + break; + case 'i': + neg = FALSE; + radix = 10; + do + { + NEXT(c); + } + while (WHITE(c)); + if (!(width > 0 && c == '0')) + goto scan_complete_number; + NEXT(c); + --width; + if (width > 0 && (c == 'x' || c == 'X')) + { + NEXT(c); + radix = 16; + --width; + } + else if (width > 0 && (c >= '0' && c <= '7')) + radix = 8; + goto scan_unsigned_number; + case 'd': + case 'u': + case 'o': + case 'x': + case 'X': + do + { + NEXT(c); + } + while (WHITE(c)); + switch (f) + { + case 'o': + radix = 8; + break; + case 'x': + case 'X': + radix = 16; + break; + default: + radix = 10; + break; + } + scan_complete_number: + neg = FALSE; + if (width > 0 && c == '+') + { + NEXT(c); + --width; + } + else if (width > 0 && c == '-' && radix == 10) + { + neg = TRUE; + NEXT(c); + --width; + } + scan_unsigned_number: + n = 0; + ok = FALSE; + while (width > 0) + { + --width; + if (isdigit(c)) + d = c - '0'; + else if (isupper(c)) + d = c - 'A' + 10; + else if (islower(c)) + d = c - 'a' + 10; + else + break; + if (d < 0 || d >= radix) + break; + ok = TRUE; + n = n * radix + d; + c = *buf++; + if (!c) + break; + else + ++chars; + } + if (!ok) + return count; + if (assign) + { + if (neg) + n = -n; + switch (size) + { + case 'h': + short_ptr = va_arg(arg_ptr, short *); + *short_ptr = (short) n; + break; + case 'l': + long_ptr = va_arg(arg_ptr, long *); + *long_ptr = (long) n; + break; + default: + int_ptr = va_arg(arg_ptr, int *); + *int_ptr = (int) n; + } + ++count; + } + if (!c) + return count; + else + UNGETC(); + break; + case 'n': + if (assign) + { + int_ptr = va_arg(arg_ptr, int *); + *int_ptr = chars; + ++count; + } + break; + default: + if (!f) /* % at end of string */ + return count; + NEXT(c); + if (c != f) + return count; + break; + } + ++fmt; + } + } + return count; +} +#endif /* HAVE_VSSCANF */ diff --git a/modules/ncurses/pdcurses/pdcurses/scr_dump.c b/modules/ncurses/pdcurses/pdcurses/scr_dump.c new file mode 100644 index 00000000..4411cbb1 --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/scr_dump.c @@ -0,0 +1,213 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +scr_dump +-------- + +### Synopsis + + int putwin(WINDOW *win, FILE *filep); + WINDOW *getwin(FILE *filep); + int scr_dump(const char *filename); + int scr_init(const char *filename); + int scr_restore(const char *filename); + int scr_set(const char *filename); + +### Description + + getwin() reads window-related data previously stored in a file + by putwin(). It then creates and initialises a new window using + that data. + + putwin() writes all data associated with a window into a file, + using an unspecified format. This information can be retrieved + later using getwin(). + + scr_dump() writes the current contents of the virtual screen to + the file named by filename in an unspecified format. + + scr_restore() function sets the virtual screen to the contents + of the file named by filename, which must have been written + using scr_dump(). The next refresh operation restores the screen + to the way it looked in the dump file. + + In PDCurses, scr_init() does nothing, and scr_set() is a synonym + for scr_restore(). Also, scr_dump() and scr_restore() save and + load from curscr. This differs from some other implementations, + where scr_init() works with curscr, and scr_restore() works with + newscr; but the effect should be the same. (PDCurses has no + newscr.) + +### Return Value + + On successful completion, getwin() returns a pointer to the + window it created. Otherwise, it returns a null pointer. Other + functions return OK or ERR. + +### Portability + X/Open BSD SYS V + putwin Y + getwin Y + scr_dump Y + scr_init Y + scr_restore Y + scr_set Y + +**man-end****************************************************************/ + +#include +#include + +#define DUMPVER 1 /* Should be updated whenever the WINDOW struct is + changed */ + +int putwin(WINDOW *win, FILE *filep) +{ + static const char *marker = "PDC"; + static const unsigned char version = DUMPVER; + + PDC_LOG(("putwin() - called\n")); + + /* write the marker and the WINDOW struct */ + + if (filep && fwrite(marker, strlen(marker), 1, filep) + && fwrite(&version, 1, 1, filep) + && fwrite(win, sizeof(WINDOW), 1, filep)) + { + int i; + + /* write each line */ + + for (i = 0; i < win->_maxy && win->_y[i]; i++) + if (!fwrite(win->_y[i], win->_maxx * sizeof(chtype), 1, filep)) + return ERR; + + return OK; + } + + return ERR; +} + +WINDOW *getwin(FILE *filep) +{ + WINDOW *win; + char marker[4]; + int i, nlines, ncols; + + PDC_LOG(("getwin() - called\n")); + + if ( !(win = malloc(sizeof(WINDOW))) ) + return (WINDOW *)NULL; + + /* check for the marker, and load the WINDOW struct */ + + if (!filep || !fread(marker, 4, 1, filep) || strncmp(marker, "PDC", 3) + || marker[3] != DUMPVER || !fread(win, sizeof(WINDOW), 1, filep)) + { + free(win); + return (WINDOW *)NULL; + } + + nlines = win->_maxy; + ncols = win->_maxx; + + /* allocate the line pointer array */ + + if ( !(win->_y = malloc(nlines * sizeof(chtype *))) ) + { + free(win); + return (WINDOW *)NULL; + } + + /* allocate the minchng and maxchng arrays */ + + if ( !(win->_firstch = malloc(nlines * sizeof(int))) ) + { + free(win->_y); + free(win); + return (WINDOW *)NULL; + } + + if ( !(win->_lastch = malloc(nlines * sizeof(int))) ) + { + free(win->_firstch); + free(win->_y); + free(win); + return (WINDOW *)NULL; + } + + /* allocate the lines */ + + if ( !(win = PDC_makelines(win)) ) + return (WINDOW *)NULL; + + /* read them */ + + for (i = 0; i < nlines; i++) + { + if (!fread(win->_y[i], ncols * sizeof(chtype), 1, filep)) + { + delwin(win); + return (WINDOW *)NULL; + } + } + + touchwin(win); + + return win; +} + +int scr_dump(const char *filename) +{ + FILE *filep; + + PDC_LOG(("scr_dump() - called: filename %s\n", filename)); + + if (filename && (filep = fopen(filename, "wb")) != NULL) + { + int result = putwin(curscr, filep); + fclose(filep); + return result; + } + + return ERR; +} + +int scr_init(const char *filename) +{ + PDC_LOG(("scr_init() - called: filename %s\n", filename)); + + return OK; +} + +int scr_restore(const char *filename) +{ + FILE *filep; + + PDC_LOG(("scr_restore() - called: filename %s\n", filename)); + + if (filename && (filep = fopen(filename, "rb")) != NULL) + { + WINDOW *replacement = getwin(filep); + fclose(filep); + + if (replacement) + { + int result = overwrite(replacement, curscr); + delwin(replacement); + return result; + } + } + + return ERR; +} + +int scr_set(const char *filename) +{ + PDC_LOG(("scr_set() - called: filename %s\n", filename)); + + return scr_restore(filename); +} diff --git a/modules/ncurses/pdcurses/pdcurses/scroll.c b/modules/ncurses/pdcurses/pdcurses/scroll.c new file mode 100644 index 00000000..a80f3751 --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/scroll.c @@ -0,0 +1,101 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +scroll +------ + +### Synopsis + + int scroll(WINDOW *win); + int scrl(int n); + int wscrl(WINDOW *win, int n); + +### Description + + scroll() causes the window to scroll up one line. This involves + moving the lines in the window data strcture. + + With a positive n, scrl() and wscrl() scroll the window up n + lines (line i + n becomes i); otherwise they scroll the window + down n lines. + + For these functions to work, scrolling must be enabled via + scrollok(). Note also that scrolling is not allowed if the + supplied window is a pad. + +### Return Value + + All functions return OK on success and ERR on error. + +### Portability + X/Open BSD SYS V + scroll Y Y Y + scrl Y - 4.0 + wscrl Y - 4.0 + +**man-end****************************************************************/ + +int wscrl(WINDOW *win, int n) +{ + int i, l, dir, start, end; + chtype blank, *temp; + + /* Check if window scrolls. Valid for window AND pad */ + + if (!win || !win->_scroll || !n) + return ERR; + + blank = win->_bkgd; + + if (n > 0) + { + start = win->_tmarg; + end = win->_bmarg; + dir = 1; + } + else + { + start = win->_bmarg; + end = win->_tmarg; + dir = -1; + } + + for (l = 0; l < (n * dir); l++) + { + temp = win->_y[start]; + + /* re-arrange line pointers */ + + for (i = start; i != end; i += dir) + win->_y[i] = win->_y[i + dir]; + + win->_y[end] = temp; + + /* make a blank line */ + + for (i = 0; i < win->_maxx; i++) + *temp++ = blank; + } + + touchline(win, win->_tmarg, win->_bmarg - win->_tmarg + 1); + + PDC_sync(win); + return OK; +} + +int scrl(int n) +{ + PDC_LOG(("scrl() - called\n")); + + return wscrl(stdscr, n); +} + +int scroll(WINDOW *win) +{ + PDC_LOG(("scroll() - called\n")); + + return wscrl(win, 1); +} diff --git a/modules/ncurses/pdcurses/pdcurses/slk.c b/modules/ncurses/pdcurses/pdcurses/slk.c new file mode 100644 index 00000000..67aecfbe --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/slk.c @@ -0,0 +1,646 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +slk +--- + +### Synopsis + + int slk_init(int fmt); + int slk_set(int labnum, const char *label, int justify); + int slk_refresh(void); + int slk_noutrefresh(void); + char *slk_label(int labnum); + int slk_clear(void); + int slk_restore(void); + int slk_touch(void); + int slk_attron(const chtype attrs); + int slk_attr_on(const attr_t attrs, void *opts); + int slk_attrset(const chtype attrs); + int slk_attr_set(const attr_t attrs, short color_pair, void *opts); + int slk_attroff(const chtype attrs); + int slk_attr_off(const attr_t attrs, void *opts); + int slk_color(short color_pair); + + int slk_wset(int labnum, const wchar_t *label, int justify); + + int PDC_mouse_in_slk(int y, int x); + void PDC_slk_free(void); + void PDC_slk_initialize(void); + + wchar_t *slk_wlabel(int labnum) + +### Description + + These functions manipulate a window that contain Soft Label Keys + (SLK). To use the SLK functions, a call to slk_init() must be + made BEFORE initscr() or newterm(). slk_init() removes 1 or 2 + lines from the useable screen, depending on the format selected. + + The line(s) removed from the screen are used as a separate + window, in which SLKs are displayed. + + slk_init() requires a single parameter which describes the + format of the SLKs as follows: + + 0 3-2-3 format + 1 4-4 format + 2 4-4-4 format (ncurses extension) + 3 4-4-4 format with index line (ncurses extension) + 2 lines used + 55 5-5 format (pdcurses format) + + slk_refresh(), slk_noutrefresh() and slk_touch() are analogous + to refresh(), noutrefresh() and touch(). + +### Return Value + + All functions return OK on success and ERR on error. + +### Portability + X/Open BSD SYS V + slk_init Y - Y + slk_set Y - Y + slk_refresh Y - Y + slk_noutrefresh Y - Y + slk_label Y - Y + slk_clear Y - Y + slk_restore Y - Y + slk_touch Y - Y + slk_attron Y - Y + slk_attrset Y - Y + slk_attroff Y - Y + slk_attr_on Y + slk_attr_set Y + slk_attr_off Y + slk_wset Y + PDC_mouse_in_slk - - - + PDC_slk_free - - - + PDC_slk_initialize - - - + slk_wlabel - - - + +**man-end****************************************************************/ + +#include + +enum { LABEL_NORMAL = 8, LABEL_EXTENDED = 10, LABEL_NCURSES_EXTENDED = 12 }; + +static int label_length = 0; +static int labels = 0; +static int label_fmt = 0; +static int label_line = 0; +static bool hidden = FALSE; + +static struct SLK { + chtype label[32]; + int len; + int format; + int start_col; +} *slk = (struct SLK *)NULL; + +/* slk_init() is the slk initialization routine. + This must be called before initscr(). + + label_fmt = 0, 1 or 55. + 0 = 3-2-3 format + 1 = 4 - 4 format + 2 = 4-4-4 format (ncurses extension for PC 12 function keys) + 3 = 4-4-4 format (ncurses extension for PC 12 function keys - + with index line) + 55 = 5 - 5 format (extended for PC, 10 function keys) */ + +int slk_init(int fmt) +{ + PDC_LOG(("slk_init() - called\n")); + + if (SP) + return ERR; + + switch (fmt) + { + case 0: /* 3 - 2 - 3 */ + labels = LABEL_NORMAL; + break; + + case 1: /* 4 - 4 */ + labels = LABEL_NORMAL; + break; + + case 2: /* 4 4 4 */ + labels = LABEL_NCURSES_EXTENDED; + break; + + case 3: /* 4 4 4 with index */ + labels = LABEL_NCURSES_EXTENDED; + break; + + case 55: /* 5 - 5 */ + labels = LABEL_EXTENDED; + break; + + default: + return ERR; + } + + label_fmt = fmt; + + slk = calloc(labels, sizeof(struct SLK)); + + if (!slk) + labels = 0; + + return slk ? OK : ERR; +} + +/* draw a single button */ + +static void _drawone(int num) +{ + int i, col, slen; + + if (hidden) + return; + + slen = slk[num].len; + + switch (slk[num].format) + { + case 0: /* LEFT */ + col = 0; + break; + + case 1: /* CENTER */ + col = (label_length - slen) / 2; + + if (col + slen > label_length) + --col; + break; + + default: /* RIGHT */ + col = label_length - slen; + } + + wmove(SP->slk_winptr, label_line, slk[num].start_col); + + for (i = 0; i < label_length; ++i) + waddch(SP->slk_winptr, (i >= col && i < (col + slen)) ? + slk[num].label[i - col] : ' '); +} + +/* redraw each button */ + +static void _redraw(void) +{ + int i; + + for (i = 0; i < labels; ++i) + _drawone(i); +} + +/* slk_set() Used to set a slk label to a string. + + labnum = 1 - 8 (or 10) (number of the label) + label = string (8 or 7 bytes total), or NULL + justify = 0 : left, 1 : center, 2 : right */ + +int slk_set(int labnum, const char *label, int justify) +{ +#ifdef PDC_WIDE + wchar_t wlabel[32]; + + PDC_mbstowcs(wlabel, label, 31); + return slk_wset(labnum, wlabel, justify); +#else + PDC_LOG(("slk_set() - called\n")); + + if (labnum < 1 || labnum > labels || justify < 0 || justify > 2) + return ERR; + + labnum--; + + if (!label || !(*label)) + { + /* Clear the label */ + + *slk[labnum].label = 0; + slk[labnum].format = 0; + slk[labnum].len = 0; + } + else + { + int i, j = 0; + + /* Skip leading spaces */ + + while (label[j] == ' ') + j++; + + /* Copy it */ + + for (i = 0; i < label_length; i++) + { + chtype ch = label[i + j]; + + slk[labnum].label[i] = ch; + + if (!ch) + break; + } + + /* Drop trailing spaces */ + + while ((i + j) && (label[i + j - 1] == ' ')) + i--; + + slk[labnum].label[i] = 0; + slk[labnum].format = justify; + slk[labnum].len = i; + } + + _drawone(labnum); + + return OK; +#endif +} + +int slk_refresh(void) +{ + PDC_LOG(("slk_refresh() - called\n")); + + return (slk_noutrefresh() == ERR) ? ERR : doupdate(); +} + +int slk_noutrefresh(void) +{ + PDC_LOG(("slk_noutrefresh() - called\n")); + + return wnoutrefresh(SP->slk_winptr); +} + +char *slk_label(int labnum) +{ + static char temp[33]; +#ifdef PDC_WIDE + wchar_t *wtemp = slk_wlabel(labnum); + + PDC_wcstombs(temp, wtemp, 32); +#else + chtype *p; + int i; + + PDC_LOG(("slk_label() - called\n")); + + if (labnum < 1 || labnum > labels) + return (char *)0; + + for (i = 0, p = slk[labnum - 1].label; *p; i++) + temp[i] = *p++; + + temp[i] = '\0'; +#endif + return temp; +} + +int slk_clear(void) +{ + PDC_LOG(("slk_clear() - called\n")); + + hidden = TRUE; + werase(SP->slk_winptr); + return wrefresh(SP->slk_winptr); +} + +int slk_restore(void) +{ + PDC_LOG(("slk_restore() - called\n")); + + hidden = FALSE; + _redraw(); + return wrefresh(SP->slk_winptr); +} + +int slk_touch(void) +{ + PDC_LOG(("slk_touch() - called\n")); + + return touchwin(SP->slk_winptr); +} + +int slk_attron(const chtype attrs) +{ + int rc; + + PDC_LOG(("slk_attron() - called\n")); + + rc = wattron(SP->slk_winptr, attrs); + _redraw(); + + return rc; +} + +int slk_attr_on(const attr_t attrs, void *opts) +{ + PDC_LOG(("slk_attr_on() - called\n")); + + return slk_attron(attrs); +} + +int slk_attroff(const chtype attrs) +{ + int rc; + + PDC_LOG(("slk_attroff() - called\n")); + + rc = wattroff(SP->slk_winptr, attrs); + _redraw(); + + return rc; +} + +int slk_attr_off(const attr_t attrs, void *opts) +{ + PDC_LOG(("slk_attr_off() - called\n")); + + return slk_attroff(attrs); +} + +int slk_attrset(const chtype attrs) +{ + int rc; + + PDC_LOG(("slk_attrset() - called\n")); + + rc = wattrset(SP->slk_winptr, attrs); + _redraw(); + + return rc; +} + +int slk_color(short color_pair) +{ + int rc; + + PDC_LOG(("slk_color() - called\n")); + + rc = wcolor_set(SP->slk_winptr, color_pair, NULL); + _redraw(); + + return rc; +} + +int slk_attr_set(const attr_t attrs, short color_pair, void *opts) +{ + PDC_LOG(("slk_attr_set() - called\n")); + + return slk_attrset(attrs | COLOR_PAIR(color_pair)); +} + +static void _slk_calc(void) +{ + int i, center, col = 0; + label_length = COLS / labels; + + if (label_length > 31) + label_length = 31; + + switch (label_fmt) + { + case 0: /* 3 - 2 - 3 F-Key layout */ + + --label_length; + + slk[0].start_col = col; + slk[1].start_col = (col += label_length); + slk[2].start_col = (col += label_length); + + center = COLS / 2; + + slk[3].start_col = center - label_length + 1; + slk[4].start_col = center + 1; + + col = COLS - (label_length * 3) + 1; + + slk[5].start_col = col; + slk[6].start_col = (col += label_length); + slk[7].start_col = (col += label_length); + break; + + case 1: /* 4 - 4 F-Key layout */ + + for (i = 0; i < 8; i++) + { + slk[i].start_col = col; + col += label_length; + + if (i == 3) + col = COLS - (label_length * 4) + 1; + } + + break; + + case 2: /* 4 4 4 F-Key layout */ + case 3: /* 4 4 4 F-Key layout with index */ + + for (i = 0; i < 4; i++) + { + slk[i].start_col = col; + col += label_length; + } + + center = COLS / 2; + + slk[4].start_col = center - (label_length * 2) + 1; + slk[5].start_col = center - label_length + 1; + slk[6].start_col = center + 1; + slk[7].start_col = center + label_length + 1; + + col = COLS - (label_length * 4) + 1; + + for (i = 8; i < 12; i++) + { + slk[i].start_col = col; + col += label_length; + } + + break; + + default: /* 5 - 5 F-Key layout */ + + for (i = 0; i < 10; i++) + { + slk[i].start_col = col; + col += label_length; + + if (i == 4) + col = COLS - (label_length * 5) + 1; + } + } + + --label_length; + + /* make sure labels are all in window */ + + _redraw(); +} + +void PDC_slk_initialize(void) +{ + if (slk) + { + if (label_fmt == 3) + { + SP->slklines = 2; + label_line = 1; + } + else + SP->slklines = 1; + + if (!SP->slk_winptr) + { + if ( !(SP->slk_winptr = newwin(SP->slklines, COLS, + LINES - SP->slklines, 0)) ) + return; + + wattrset(SP->slk_winptr, A_REVERSE); + } + + _slk_calc(); + + /* if we have an index line, display it now */ + + if (label_fmt == 3) + { + chtype save_attr; + int i; + + save_attr = SP->slk_winptr->_attrs; + wattrset(SP->slk_winptr, A_NORMAL); + wmove(SP->slk_winptr, 0, 0); + whline(SP->slk_winptr, 0, COLS); + + for (i = 0; i < labels; i++) + mvwprintw(SP->slk_winptr, 0, slk[i].start_col, "F%d", i + 1); + + SP->slk_winptr->_attrs = save_attr; + } + + touchwin(SP->slk_winptr); + } +} + +void PDC_slk_free(void) +{ + if (slk) + { + if (SP->slk_winptr) + { + delwin(SP->slk_winptr); + SP->slk_winptr = (WINDOW *)NULL; + } + + free(slk); + slk = (struct SLK *)NULL; + + label_length = 0; + labels = 0; + label_fmt = 0; + label_line = 0; + hidden = FALSE; + } +} + +int PDC_mouse_in_slk(int y, int x) +{ + int i; + + PDC_LOG(("PDC_mouse_in_slk() - called: y->%d x->%d\n", y, x)); + + /* If the line on which the mouse was clicked is NOT the last line + of the screen, we are not interested in it. */ + + if (!slk || !SP->slk_winptr || (y != SP->slk_winptr->_begy + label_line)) + return 0; + + for (i = 0; i < labels; i++) + if (x >= slk[i].start_col && x < (slk[i].start_col + label_length)) + return i + 1; + + return 0; +} + +#ifdef PDC_WIDE +int slk_wset(int labnum, const wchar_t *label, int justify) +{ + PDC_LOG(("slk_wset() - called\n")); + + if (labnum < 1 || labnum > labels || justify < 0 || justify > 2) + return ERR; + + labnum--; + + if (!label || !(*label)) + { + /* Clear the label */ + + *slk[labnum].label = 0; + slk[labnum].format = 0; + slk[labnum].len = 0; + } + else + { + int i, j = 0; + + /* Skip leading spaces */ + + while (label[j] == L' ') + j++; + + /* Copy it */ + + for (i = 0; i < label_length; i++) + { + chtype ch = label[i + j]; + + slk[labnum].label[i] = ch; + + if (!ch) + break; + } + + /* Drop trailing spaces */ + + while ((i + j) && (label[i + j - 1] == L' ')) + i--; + + slk[labnum].label[i] = 0; + slk[labnum].format = justify; + slk[labnum].len = i; + } + + _drawone(labnum); + + return OK; +} + +wchar_t *slk_wlabel(int labnum) +{ + static wchar_t temp[33]; + chtype *p; + int i; + + PDC_LOG(("slk_wlabel() - called\n")); + + if (labnum < 1 || labnum > labels) + return (wchar_t *)0; + + for (i = 0, p = slk[labnum - 1].label; *p; i++) + temp[i] = *p++; + + temp[i] = '\0'; + + return temp; +} +#endif diff --git a/modules/ncurses/pdcurses/pdcurses/termattr.c b/modules/ncurses/pdcurses/pdcurses/termattr.c new file mode 100644 index 00000000..53cc2b68 --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/termattr.c @@ -0,0 +1,172 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +termattr +-------- + +### Synopsis + + int baudrate(void); + char erasechar(void); + bool has_ic(void); + bool has_il(void); + char killchar(void); + char *longname(void); + chtype termattrs(void); + attr_t term_attrs(void); + char *termname(void); + + int erasewchar(wchar_t *ch); + int killwchar(wchar_t *ch); + + char wordchar(void); + +### Description + + baudrate() is supposed to return the output speed of the + terminal. In PDCurses, it simply returns INT_MAX. + + has_ic and has_il() return TRUE. These functions have meaning in + some other implementations of curses. + + erasechar() and killchar() return ^H and ^U, respectively -- the + ERASE and KILL characters. In other curses implementations, + these may vary by terminal type. erasewchar() and killwchar() + are the wide-character versions; they take a pointer to a + location in which to store the character, and return OK or ERR. + + longname() returns a pointer to a static area containing a + verbose description of the current terminal. The maximum length + of the string is 128 characters. It is defined only after the + call to initscr() or newterm(). + + termname() returns a pointer to a static area containing a + short description of the current terminal (14 characters). + + termattrs() returns a logical OR of all video attributes + supported by the terminal. + + wordchar() is a PDCurses extension of the concept behind the + functions erasechar() and killchar(), returning the "delete + word" character, ^W. + +### Portability + X/Open BSD SYS V + baudrate Y Y Y + erasechar Y Y Y + has_ic Y Y Y + has_il Y Y Y + killchar Y Y Y + longname Y Y Y + termattrs Y Y Y + termname Y Y Y + erasewchar Y + killwchar Y + term_attrs Y + wordchar - - - + +**man-end****************************************************************/ + +#include +#include + +int baudrate(void) +{ + PDC_LOG(("baudrate() - called\n")); + + return INT_MAX; +} + +char erasechar(void) +{ + PDC_LOG(("erasechar() - called\n")); + + return _ECHAR; /* character delete char (^H) */ +} + +bool has_ic(void) +{ + PDC_LOG(("has_ic() - called\n")); + + return TRUE; +} + +bool has_il(void) +{ + PDC_LOG(("has_il() - called\n")); + + return TRUE; +} + +char killchar(void) +{ + PDC_LOG(("killchar() - called\n")); + + return _DLCHAR; /* line delete char (^U) */ +} + +char *longname(void) +{ + PDC_LOG(("longname() - called\n")); + + return ttytype + 9; /* skip "pdcurses|" */ +} + +chtype termattrs(void) +{ + PDC_LOG(("termattrs() - called\n")); + + return SP->termattrs; +} + +attr_t term_attrs(void) +{ + PDC_LOG(("term_attrs() - called\n")); + + return SP->termattrs; +} + +char *termname(void) +{ + static char _termname[14] = "pdcurses"; + + PDC_LOG(("termname() - called\n")); + + return _termname; +} + +char wordchar(void) +{ + PDC_LOG(("wordchar() - called\n")); + + return _DWCHAR; /* word delete char */ +} + +#ifdef PDC_WIDE +int erasewchar(wchar_t *ch) +{ + PDC_LOG(("erasewchar() - called\n")); + + if (!ch) + return ERR; + + *ch = (wchar_t)_ECHAR; + + return OK; +} + +int killwchar(wchar_t *ch) +{ + PDC_LOG(("killwchar() - called\n")); + + if (!ch) + return ERR; + + *ch = (wchar_t)_DLCHAR; + + return OK; +} +#endif diff --git a/modules/ncurses/pdcurses/pdcurses/terminfo.c b/modules/ncurses/pdcurses/pdcurses/terminfo.c new file mode 100644 index 00000000..fadba230 --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/terminfo.c @@ -0,0 +1,217 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +terminfo +-------- + +### Synopsis + + int mvcur(int oldrow, int oldcol, int newrow, int newcol); + int vidattr(chtype attr); + int vid_attr(attr_t attr, short color_pair, void *opt); + int vidputs(chtype attr, int (*putfunc)(int)); + int vid_puts(attr_t attr, short color_pair, void *opt, + int (*putfunc)(int)); + + int del_curterm(TERMINAL *); + int putp(const char *); + int restartterm(const char *, int, int *); + TERMINAL *set_curterm(TERMINAL *); + int setterm(const char *term); + int setupterm(const char *, int, int *); + int tgetent(char *, const char *); + int tgetflag(const char *); + int tgetnum(const char *); + char *tgetstr(const char *, char **); + char *tgoto(const char *, int, int); + int tigetflag(const char *); + int tigetnum(const char *); + char *tigetstr(const char *); + char *tparm(const char *,long, long, long, long, long, long, + long, long, long); + int tputs(const char *, int, int (*)(int)); + +### Description + + mvcur() lets you move the physical cursor without updating any + window cursor positions. It returns OK or ERR. + + The rest of these functions are currently implemented as stubs, + returning the appropriate errors and doing nothing else. + +### Portability + X/Open BSD SYS V + mvcur Y Y Y + +**man-end****************************************************************/ + +#include + +TERMINAL *cur_term = NULL; + +int mvcur(int oldrow, int oldcol, int newrow, int newcol) +{ + PDC_LOG(("mvcur() - called: oldrow %d oldcol %d newrow %d newcol %d\n", + oldrow, oldcol, newrow, newcol)); + + if ((newrow >= LINES) || (newcol >= COLS) || (newrow < 0) || (newcol < 0)) + return ERR; + + PDC_gotoyx(newrow, newcol); + SP->cursrow = newrow; + SP->curscol = newcol; + + return OK; +} + +int vidattr(chtype attr) +{ + PDC_LOG(("vidattr() - called: attr %d\n", attr)); + + return ERR; +} + +int vid_attr(attr_t attr, short color_pair, void *opt) +{ + PDC_LOG(("vid_attr() - called\n")); + + return ERR; +} + +int vidputs(chtype attr, int (*putfunc)(int)) +{ + PDC_LOG(("vidputs() - called: attr %d\n", attr)); + + return ERR; +} + +int vid_puts(attr_t attr, short color_pair, void *opt, int (*putfunc)(int)) +{ + PDC_LOG(("vid_puts() - called\n")); + + return ERR; +} + +int del_curterm(TERMINAL *oterm) +{ + PDC_LOG(("del_curterm() - called\n")); + + return ERR; +} + +int putp(const char *str) +{ + PDC_LOG(("putp() - called: str %s\n", str)); + + return ERR; +} + +int restartterm(const char *term, int filedes, int *errret) +{ + PDC_LOG(("restartterm() - called\n")); + + if (errret) + *errret = -1; + + return ERR; +} + +TERMINAL *set_curterm(TERMINAL *nterm) +{ + PDC_LOG(("set_curterm() - called\n")); + + return (TERMINAL *)NULL; +} + +int setterm(const char *term) +{ + PDC_LOG(("setterm() - called\n")); + + return ERR; +} + +int setupterm(const char *term, int filedes, int *errret) +{ + PDC_LOG(("setupterm() - called\n")); + + if (errret) + *errret = -1; + else + fprintf(stderr, "There is no terminfo database\n"); + + return ERR; +} + +int tgetent(char *bp, const char *name) +{ + PDC_LOG(("tgetent() - called: name %s\n", name)); + + return ERR; +} + +int tgetflag(const char *id) +{ + PDC_LOG(("tgetflag() - called: id %s\n", id)); + + return ERR; +} + +int tgetnum(const char *id) +{ + PDC_LOG(("tgetnum() - called: id %s\n", id)); + + return ERR; +} + +char *tgetstr(const char *id, char **area) +{ + PDC_LOG(("tgetstr() - called: id %s\n", id)); + + return (char *)NULL; +} + +char *tgoto(const char *cap, int col, int row) +{ + PDC_LOG(("tgoto() - called\n")); + + return (char *)NULL; +} + +int tigetflag(const char *capname) +{ + PDC_LOG(("tigetflag() - called: capname %s\n", capname)); + + return -1; +} + +int tigetnum(const char *capname) +{ + PDC_LOG(("tigetnum() - called: capname %s\n", capname)); + + return -2; +} + +char *tigetstr(const char *capname) +{ + PDC_LOG(("tigetstr() - called: capname %s\n", capname)); + + return (char *)(-1); +} + +char *tparm(const char *cap, long p1, long p2, long p3, long p4, + long p5, long p6, long p7, long p8, long p9) +{ + PDC_LOG(("tparm() - called: cap %s\n", cap)); + + return (char *)NULL; +} + +int tputs(const char *str, int affcnt, int (*putfunc)(int)) +{ + PDC_LOG(("tputs() - called\n")); + + return ERR; +} diff --git a/modules/ncurses/pdcurses/pdcurses/touch.c b/modules/ncurses/pdcurses/pdcurses/touch.c new file mode 100644 index 00000000..f773557a --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/touch.c @@ -0,0 +1,163 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +touch +----- + +### Synopsis + + int touchwin(WINDOW *win); + int touchline(WINDOW *win, int start, int count); + int untouchwin(WINDOW *win); + int wtouchln(WINDOW *win, int y, int n, int changed); + bool is_linetouched(WINDOW *win, int line); + bool is_wintouched(WINDOW *win); + +### Description + + touchwin() and touchline() throw away all information about + which parts of the window have been touched, pretending that the + entire window has been drawn on. This is sometimes necessary + when using overlapping windows, since a change to one window + will affect the other window, but the records of which lines + have been changed in the other window will not reflect the + change. + + untouchwin() marks all lines in the window as unchanged since + the last call to wrefresh(). + + wtouchln() makes n lines in the window, starting at line y, look + as if they have (changed == 1) or have not (changed == 0) been + changed since the last call to wrefresh(). + + is_linetouched() returns TRUE if the specified line in the + specified window has been changed since the last call to + wrefresh(). + + is_wintouched() returns TRUE if the specified window + has been changed since the last call to wrefresh(). + +### Return Value + + All functions return OK on success and ERR on error except + is_wintouched() and is_linetouched(). + +### Portability + X/Open BSD SYS V + touchwin Y Y Y + touchline Y - 3.0 + untouchwin Y - 4.0 + wtouchln Y Y Y + is_linetouched Y - 4.0 + is_wintouched Y - 4.0 + +**man-end****************************************************************/ + +int touchwin(WINDOW *win) +{ + int i; + + PDC_LOG(("touchwin() - called: Win=%x\n", win)); + + if (!win) + return ERR; + + for (i = 0; i < win->_maxy; i++) + { + win->_firstch[i] = 0; + win->_lastch[i] = win->_maxx - 1; + } + + return OK; +} + +int touchline(WINDOW *win, int start, int count) +{ + int i; + + PDC_LOG(("touchline() - called: win=%p start %d count %d\n", + win, start, count)); + + if (!win || start > win->_maxy || start + count > win->_maxy) + return ERR; + + for (i = start; i < start + count; i++) + { + win->_firstch[i] = 0; + win->_lastch[i] = win->_maxx - 1; + } + + return OK; +} + +int untouchwin(WINDOW *win) +{ + int i; + + PDC_LOG(("untouchwin() - called: win=%p", win)); + + if (!win) + return ERR; + + for (i = 0; i < win->_maxy; i++) + { + win->_firstch[i] = _NO_CHANGE; + win->_lastch[i] = _NO_CHANGE; + } + + return OK; +} + +int wtouchln(WINDOW *win, int y, int n, int changed) +{ + int i; + + PDC_LOG(("wtouchln() - called: win=%p y=%d n=%d changed=%d\n", + win, y, n, changed)); + + if (!win || y > win->_maxy || y + n > win->_maxy) + return ERR; + + for (i = y; i < y + n; i++) + { + if (changed) + { + win->_firstch[i] = 0; + win->_lastch[i] = win->_maxx - 1; + } + else + { + win->_firstch[i] = _NO_CHANGE; + win->_lastch[i] = _NO_CHANGE; + } + } + + return OK; +} + +bool is_linetouched(WINDOW *win, int line) +{ + PDC_LOG(("is_linetouched() - called: win=%p line=%d\n", win, line)); + + if (!win || line > win->_maxy || line < 0) + return FALSE; + + return (win->_firstch[line] != _NO_CHANGE) ? TRUE : FALSE; +} + +bool is_wintouched(WINDOW *win) +{ + int i; + + PDC_LOG(("is_wintouched() - called: win=%p\n", win)); + + if (win) + for (i = 0; i < win->_maxy; i++) + if (win->_firstch[i] != _NO_CHANGE) + return TRUE; + + return FALSE; +} diff --git a/modules/ncurses/pdcurses/pdcurses/util.c b/modules/ncurses/pdcurses/pdcurses/util.c new file mode 100644 index 00000000..a206d9b4 --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/util.c @@ -0,0 +1,307 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +util +---- + +### Synopsis + + char *unctrl(chtype c); + void filter(void); + void use_env(bool x); + int delay_output(int ms); + + int getcchar(const cchar_t *wcval, wchar_t *wch, attr_t *attrs, + short *color_pair, void *opts); + int setcchar(cchar_t *wcval, const wchar_t *wch, const attr_t attrs, + short color_pair, const void *opts); + wchar_t *wunctrl(cchar_t *wc); + + int PDC_mbtowc(wchar_t *pwc, const char *s, size_t n); + size_t PDC_mbstowcs(wchar_t *dest, const char *src, size_t n); + size_t PDC_wcstombs(char *dest, const wchar_t *src, size_t n); + +### Description + + unctrl() expands the text portion of the chtype c into a + printable string. Control characters are changed to the "^X" + notation; others are passed through. wunctrl() is the wide- + character version of the function. + + filter() and use_env() are no-ops in PDCurses. + + delay_output() inserts an ms millisecond pause in output. + + getcchar() works in two modes: When wch is not NULL, it reads + the cchar_t pointed to by wcval and stores the attributes in + attrs, the color pair in color_pair, and the text in the + wide-character string wch. When wch is NULL, getcchar() merely + returns the number of wide characters in wcval. In either mode, + the opts argument is unused. + + setcchar constructs a cchar_t at wcval from the wide-character + text at wch, the attributes in attr and the color pair in + color_pair. The opts argument is unused. + + Currently, the length returned by getcchar() is always 1 or 0. + Similarly, setcchar() will only take the first wide character + from wch, and ignore any others that it "should" take (i.e., + combining characters). Nor will it correctly handle any + character outside the basic multilingual plane (UCS-2). + +### Return Value + + unctrl() and wunctrl() return NULL on failure. delay_output() + always returns OK. + + getcchar() returns the number of wide characters wcval points to + when wch is NULL; when it's not, getcchar() returns OK or ERR. + + setcchar() returns OK or ERR. + +### Portability + X/Open BSD SYS V + unctrl Y Y Y + filter Y - 3.0 + use_env Y - 4.0 + delay_output Y Y Y + getcchar Y + setcchar Y + wunctrl Y + PDC_mbtowc - - - + PDC_mbstowcs - - - + PDC_wcstombs - - - + +**man-end****************************************************************/ + +#include +#include + +char *unctrl(chtype c) +{ + static char strbuf[3] = {0, 0, 0}; + + chtype ic; + + PDC_LOG(("unctrl() - called\n")); + + ic = c & A_CHARTEXT; + + if (ic >= 0x20 && ic != 0x7f) /* normal characters */ + { + strbuf[0] = (char)ic; + strbuf[1] = '\0'; + return strbuf; + } + + strbuf[0] = '^'; /* '^' prefix */ + + if (ic == 0x7f) /* 0x7f == DEL */ + strbuf[1] = '?'; + else /* other control */ + strbuf[1] = (char)(ic + '@'); + + return strbuf; +} + +void filter(void) +{ + PDC_LOG(("filter() - called\n")); +} + +void use_env(bool x) +{ + PDC_LOG(("use_env() - called: x %d\n", x)); +} + +int delay_output(int ms) +{ + PDC_LOG(("delay_output() - called: ms %d\n", ms)); + + return napms(ms); +} + +#ifdef PDC_WIDE +int getcchar(const cchar_t *wcval, wchar_t *wch, attr_t *attrs, + short *color_pair, void *opts) +{ + if (!wcval) + return ERR; + + if (wch) + { + if (!attrs || !color_pair) + return ERR; + + *wch = (*wcval & A_CHARTEXT); + *attrs = (*wcval & (A_ATTRIBUTES & ~A_COLOR)); + *color_pair = PAIR_NUMBER(*wcval & A_COLOR); + + if (*wch) + *++wch = L'\0'; + + return OK; + } + else + return ((*wcval & A_CHARTEXT) != L'\0'); +} + +int setcchar(cchar_t *wcval, const wchar_t *wch, const attr_t attrs, + short color_pair, const void *opts) +{ + if (!wcval || !wch) + return ERR; + + *wcval = *wch | attrs | COLOR_PAIR(color_pair); + + return OK; +} + +wchar_t *wunctrl(cchar_t *wc) +{ + static wchar_t strbuf[3] = {0, 0, 0}; + + cchar_t ic; + + PDC_LOG(("wunctrl() - called\n")); + + ic = *wc & A_CHARTEXT; + + if (ic >= 0x20 && ic != 0x7f) /* normal characters */ + { + strbuf[0] = (wchar_t)ic; + strbuf[1] = L'\0'; + return strbuf; + } + + strbuf[0] = '^'; /* '^' prefix */ + + if (ic == 0x7f) /* 0x7f == DEL */ + strbuf[1] = '?'; + else /* other control */ + strbuf[1] = (wchar_t)(ic + '@'); + + return strbuf; +} + +int PDC_mbtowc(wchar_t *pwc, const char *s, size_t n) +{ +# ifdef PDC_FORCE_UTF8 + wchar_t key; + int i = -1; + const unsigned char *string; + + if (!s || (n < 1)) + return -1; + + if (!*s) + return 0; + + string = (const unsigned char *)s; + + key = string[0]; + + /* Simplistic UTF-8 decoder -- only does the BMP, minimal validation */ + + if (key & 0x80) + { + if ((key & 0xe0) == 0xc0) + { + if (1 < n) + { + key = ((key & 0x1f) << 6) | (string[1] & 0x3f); + i = 2; + } + } + else if ((key & 0xe0) == 0xe0) + { + if (2 < n) + { + key = ((key & 0x0f) << 12) | ((string[1] & 0x3f) << 6) | + (string[2] & 0x3f); + i = 3; + } + } + } + else + i = 1; + + if (i) + *pwc = key; + + return i; +# else + return mbtowc(pwc, s, n); +# endif +} + +size_t PDC_mbstowcs(wchar_t *dest, const char *src, size_t n) +{ +# ifdef PDC_FORCE_UTF8 + size_t i = 0, len; + + if (!src || !dest) + return 0; + + len = strlen(src); + + while (*src && i < n) + { + int retval = PDC_mbtowc(dest + i, src, len); + + if (retval < 1) + return -1; + + src += retval; + len -= retval; + i++; + } +# else + size_t i = mbstowcs(dest, src, n); +# endif + dest[i] = 0; + return i; +} + +size_t PDC_wcstombs(char *dest, const wchar_t *src, size_t n) +{ +# ifdef PDC_FORCE_UTF8 + size_t i = 0; + + if (!src || !dest) + return 0; + + while (*src && i < n) + { + chtype code = *src++; + + if (code < 0x80) + { + dest[i] = code; + i++; + } + else + if (code < 0x800) + { + dest[i] = ((code & 0x07c0) >> 6) | 0xc0; + dest[i + 1] = (code & 0x003f) | 0x80; + i += 2; + } + else + { + dest[i] = ((code & 0xf000) >> 12) | 0xe0; + dest[i + 1] = ((code & 0x0fc0) >> 6) | 0x80; + dest[i + 2] = (code & 0x003f) | 0x80; + i += 3; + } + } +# else + size_t i = wcstombs(dest, src, n); +# endif + dest[i] = '\0'; + return i; +} +#endif diff --git a/modules/ncurses/pdcurses/pdcurses/window.c b/modules/ncurses/pdcurses/pdcurses/window.c new file mode 100644 index 00000000..34ae0287 --- /dev/null +++ b/modules/ncurses/pdcurses/pdcurses/window.c @@ -0,0 +1,569 @@ +/* Public Domain Curses */ + +#include + +/*man-start************************************************************** + +window +------ + +### Synopsis + + WINDOW *newwin(int nlines, int ncols, int begy, int begx); + WINDOW *derwin(WINDOW* orig, int nlines, int ncols, + int begy, int begx); + WINDOW *subwin(WINDOW* orig, int nlines, int ncols, + int begy, int begx); + WINDOW *dupwin(WINDOW *win); + int delwin(WINDOW *win); + int mvwin(WINDOW *win, int y, int x); + int mvderwin(WINDOW *win, int pary, int parx); + int syncok(WINDOW *win, bool bf); + void wsyncup(WINDOW *win); + void wcursyncup(WINDOW *win); + void wsyncdown(WINDOW *win); + + WINDOW *resize_window(WINDOW *win, int nlines, int ncols); + int wresize(WINDOW *win, int nlines, int ncols); + WINDOW *PDC_makelines(WINDOW *win); + WINDOW *PDC_makenew(int nlines, int ncols, int begy, int begx); + void PDC_sync(WINDOW *win); + +### Description + + newwin() creates a new window with the given number of lines, + nlines and columns, ncols. The upper left corner of the window + is at line begy, column begx. If nlines is zero, it defaults to + LINES - begy; ncols to COLS - begx. Create a new full-screen + window by calling newwin(0, 0, 0, 0). + + delwin() deletes the named window, freeing all associated + memory. In the case of overlapping windows, subwindows should be + deleted before the main window. + + mvwin() moves the window so that the upper left-hand corner is + at position (y,x). If the move would cause the window to be off + the screen, it is an error and the window is not moved. Moving + subwindows is allowed. + + subwin() creates a new subwindow within a window. The + dimensions of the subwindow are nlines lines and ncols columns. + The subwindow is at position (begy, begx) on the screen. This + position is relative to the screen, and not to the window orig. + Changes made to either window will affect both. When using this + routine, you will often need to call touchwin() before calling + wrefresh(). + + derwin() is the same as subwin(), except that begy and begx are + relative to the origin of the window orig rather than the + screen. There is no difference between subwindows and derived + windows. + + mvderwin() moves a derived window (or subwindow) inside its + parent window. The screen-relative parameters of the window are + not changed. This routine is used to display different parts of + the parent window at the same physical position on the screen. + + dupwin() creates an exact duplicate of the window win. + + wsyncup() causes a touchwin() of all of the window's parents. + + If wsyncok() is called with a second argument of TRUE, this + causes a wsyncup() to be called every time the window is + changed. + + wcursyncup() causes the current cursor position of all of a + window's ancestors to reflect the current cursor position of the + current window. + + wsyncdown() causes a touchwin() of the current window if any of + its parent's windows have been touched. + + resize_window() allows the user to resize an existing window. It + returns the pointer to the new window, or NULL on failure. + + wresize() is an ncurses-compatible wrapper for resize_window(). + Note that, unlike ncurses, it will NOT process any subwindows of + the window. (However, you still can call it _on_ subwindows.) It + returns OK or ERR. + + PDC_makenew() allocates all data for a new WINDOW * except the + actual lines themselves. If it's unable to allocate memory for + the window structure, it will free all allocated memory and + return a NULL pointer. + + PDC_makelines() allocates the memory for the lines. + + PDC_sync() handles wrefresh() and wsyncup() calls when a window + is changed. + +### Return Value + + newwin(), subwin(), derwin() and dupwin() return a pointer + to the new window, or NULL on failure. delwin(), mvwin(), + mvderwin() and syncok() return OK or ERR. wsyncup(), + wcursyncup() and wsyncdown() return nothing. + +### Errors + + It is an error to call resize_window() before calling initscr(). + Also, an error will be generated if we fail to create a newly + sized replacement window for curscr, or stdscr. This could + happen when increasing the window size. NOTE: If this happens, + the previously successfully allocated windows are left alone; + i.e., the resize is NOT cancelled for those windows. + +### Portability + X/Open BSD SYS V + newwin Y Y Y + delwin Y Y Y + mvwin Y Y Y + subwin Y Y Y + derwin Y - Y + mvderwin Y - Y + dupwin Y - 4.0 + wsyncup Y - 4.0 + syncok Y - 4.0 + wcursyncup Y - 4.0 + wsyncdown Y - 4.0 + resize_window - - - + wresize - - - + PDC_makelines - - - + PDC_makenew - - - + PDC_sync - - - + +**man-end****************************************************************/ + +#include + +WINDOW *PDC_makenew(int nlines, int ncols, int begy, int begx) +{ + WINDOW *win; + + PDC_LOG(("PDC_makenew() - called: lines %d cols %d begy %d begx %d\n", + nlines, ncols, begy, begx)); + + /* allocate the window structure itself */ + + if ((win = calloc(1, sizeof(WINDOW))) == (WINDOW *)NULL) + return win; + + /* allocate the line pointer array */ + + if ((win->_y = malloc(nlines * sizeof(chtype *))) == NULL) + { + free(win); + return (WINDOW *)NULL; + } + + /* allocate the minchng and maxchng arrays */ + + if ((win->_firstch = malloc(nlines * sizeof(int))) == NULL) + { + free(win->_y); + free(win); + return (WINDOW *)NULL; + } + + if ((win->_lastch = malloc(nlines * sizeof(int))) == NULL) + { + free(win->_firstch); + free(win->_y); + free(win); + return (WINDOW *)NULL; + } + + /* initialize window variables */ + + win->_maxy = nlines; /* real max screen size */ + win->_maxx = ncols; /* real max screen size */ + win->_begy = begy; + win->_begx = begx; + win->_bkgd = ' '; /* wrs 4/10/93 -- initialize background to blank */ + win->_clear = (bool) ((nlines == LINES) && (ncols == COLS)); + win->_bmarg = nlines - 1; + win->_parx = win->_pary = -1; + + /* init to say window all changed */ + + touchwin(win); + + return win; +} + +WINDOW *PDC_makelines(WINDOW *win) +{ + int i, j, nlines, ncols; + + PDC_LOG(("PDC_makelines() - called\n")); + + if (!win) + return (WINDOW *)NULL; + + nlines = win->_maxy; + ncols = win->_maxx; + + for (i = 0; i < nlines; i++) + { + if ((win->_y[i] = malloc(ncols * sizeof(chtype))) == NULL) + { + /* if error, free all the data */ + + for (j = 0; j < i; j++) + free(win->_y[j]); + + free(win->_firstch); + free(win->_lastch); + free(win->_y); + free(win); + + return (WINDOW *)NULL; + } + } + + return win; +} + +void PDC_sync(WINDOW *win) +{ + PDC_LOG(("PDC_sync() - called:\n")); + + if (win->_immed) + wrefresh(win); + if (win->_sync) + wsyncup(win); +} + +WINDOW *newwin(int nlines, int ncols, int begy, int begx) +{ + WINDOW *win; + + PDC_LOG(("newwin() - called:lines=%d cols=%d begy=%d begx=%d\n", + nlines, ncols, begy, begx)); + + if (!nlines) + nlines = LINES - begy; + if (!ncols) + ncols = COLS - begx; + + if ( (begy + nlines > SP->lines || begx + ncols > SP->cols) + || !(win = PDC_makenew(nlines, ncols, begy, begx)) + || !(win = PDC_makelines(win)) ) + return (WINDOW *)NULL; + + werase(win); + + return win; +} + +int delwin(WINDOW *win) +{ + int i; + + PDC_LOG(("delwin() - called\n")); + + if (!win) + return ERR; + + /* subwindows use parents' lines */ + + if (!(win->_flags & (_SUBWIN|_SUBPAD))) + for (i = 0; i < win->_maxy && win->_y[i]; i++) + if (win->_y[i]) + free(win->_y[i]); + + free(win->_firstch); + free(win->_lastch); + free(win->_y); + free(win); + + return OK; +} + +int mvwin(WINDOW *win, int y, int x) +{ + PDC_LOG(("mvwin() - called\n")); + + if (!win || (y + win->_maxy > LINES || y < 0) + || (x + win->_maxx > COLS || x < 0)) + return ERR; + + win->_begy = y; + win->_begx = x; + touchwin(win); + + return OK; +} + +WINDOW *subwin(WINDOW *orig, int nlines, int ncols, int begy, int begx) +{ + WINDOW *win; + int i; + int j = begy - orig->_begy; + int k = begx - orig->_begx; + + PDC_LOG(("subwin() - called: lines %d cols %d begy %d begx %d\n", + nlines, ncols, begy, begx)); + + /* make sure window fits inside the original one */ + + if (!orig || (begy < orig->_begy) || (begx < orig->_begx) || + (begy + nlines) > (orig->_begy + orig->_maxy) || + (begx + ncols) > (orig->_begx + orig->_maxx)) + return (WINDOW *)NULL; + + if (!nlines) + nlines = orig->_maxy - 1 - j; + if (!ncols) + ncols = orig->_maxx - 1 - k; + + if ( !(win = PDC_makenew(nlines, ncols, begy, begx)) ) + return (WINDOW *)NULL; + + /* initialize window variables */ + + win->_attrs = orig->_attrs; + win->_bkgd = orig->_bkgd; + win->_leaveit = orig->_leaveit; + win->_scroll = orig->_scroll; + win->_nodelay = orig->_nodelay; + win->_delayms = orig->_delayms; + win->_use_keypad = orig->_use_keypad; + win->_immed = orig->_immed; + win->_sync = orig->_sync; + win->_pary = j; + win->_parx = k; + win->_parent = orig; + + for (i = 0; i < nlines; i++, j++) + win->_y[i] = orig->_y[j] + k; + + win->_flags |= _SUBWIN; + + return win; +} + +WINDOW *derwin(WINDOW *orig, int nlines, int ncols, int begy, int begx) +{ + return subwin(orig, nlines, ncols, begy + orig->_begy, begx + orig->_begx); +} + +int mvderwin(WINDOW *win, int pary, int parx) +{ + int i, j; + WINDOW *mypar; + + if (!win || !(win->_parent)) + return ERR; + + mypar = win->_parent; + + if (pary < 0 || parx < 0 || (pary + win->_maxy) > mypar->_maxy || + (parx + win->_maxx) > mypar->_maxx) + return ERR; + + j = pary; + + for (i = 0; i < win->_maxy; i++) + win->_y[i] = (mypar->_y[j++]) + parx; + + win->_pary = pary; + win->_parx = parx; + + return OK; +} + +WINDOW *dupwin(WINDOW *win) +{ + WINDOW *new; + chtype *ptr, *ptr1; + int nlines, ncols, begy, begx, i; + + if (!win) + return (WINDOW *)NULL; + + nlines = win->_maxy; + ncols = win->_maxx; + begy = win->_begy; + begx = win->_begx; + + if ( !(new = PDC_makenew(nlines, ncols, begy, begx)) + || !(new = PDC_makelines(new)) ) + return (WINDOW *)NULL; + + /* copy the contents of win into new */ + + for (i = 0; i < nlines; i++) + { + for (ptr = new->_y[i], ptr1 = win->_y[i]; + ptr < new->_y[i] + ncols; ptr++, ptr1++) + *ptr = *ptr1; + + new->_firstch[i] = 0; + new->_lastch[i] = ncols - 1; + } + + new->_curx = win->_curx; + new->_cury = win->_cury; + new->_maxy = win->_maxy; + new->_maxx = win->_maxx; + new->_begy = win->_begy; + new->_begx = win->_begx; + new->_flags = win->_flags; + new->_attrs = win->_attrs; + new->_clear = win->_clear; + new->_leaveit = win->_leaveit; + new->_scroll = win->_scroll; + new->_nodelay = win->_nodelay; + new->_delayms = win->_delayms; + new->_use_keypad = win->_use_keypad; + new->_tmarg = win->_tmarg; + new->_bmarg = win->_bmarg; + new->_parx = win->_parx; + new->_pary = win->_pary; + new->_parent = win->_parent; + new->_bkgd = win->_bkgd; + new->_flags = win->_flags; + + return new; +} + +WINDOW *resize_window(WINDOW *win, int nlines, int ncols) +{ + WINDOW *new; + int i, save_cury, save_curx, new_begy, new_begx; + + PDC_LOG(("resize_window() - called: nlines %d ncols %d\n", + nlines, ncols)); + + if (!win) + return (WINDOW *)NULL; + + if (win->_flags & _SUBPAD) + { + if ( !(new = subpad(win->_parent, nlines, ncols, + win->_begy, win->_begx)) ) + return (WINDOW *)NULL; + } + else if (win->_flags & _SUBWIN) + { + if ( !(new = subwin(win->_parent, nlines, ncols, + win->_begy, win->_begx)) ) + return (WINDOW *)NULL; + } + else + { + if (win == SP->slk_winptr) + { + new_begy = SP->lines - SP->slklines; + new_begx = 0; + } + else + { + new_begy = win->_begy; + new_begx = win->_begx; + } + + if ( !(new = PDC_makenew(nlines, ncols, new_begy, new_begx)) ) + return (WINDOW *)NULL; + } + + save_curx = min(win->_curx, (new->_maxx - 1)); + save_cury = min(win->_cury, (new->_maxy - 1)); + + if (!(win->_flags & (_SUBPAD|_SUBWIN))) + { + if ( !(new = PDC_makelines(new)) ) + return (WINDOW *)NULL; + + werase(new); + + copywin(win, new, 0, 0, 0, 0, min(win->_maxy, new->_maxy) - 1, + min(win->_maxx, new->_maxx) - 1, FALSE); + + for (i = 0; i < win->_maxy && win->_y[i]; i++) + if (win->_y[i]) + free(win->_y[i]); + } + + new->_flags = win->_flags; + new->_attrs = win->_attrs; + new->_clear = win->_clear; + new->_leaveit = win->_leaveit; + new->_scroll = win->_scroll; + new->_nodelay = win->_nodelay; + new->_delayms = win->_delayms; + new->_use_keypad = win->_use_keypad; + new->_tmarg = (win->_tmarg > new->_maxy - 1) ? 0 : win->_tmarg; + new->_bmarg = (win->_bmarg == win->_maxy - 1) ? + new->_maxy - 1 : min(win->_bmarg, (new->_maxy - 1)); + new->_parent = win->_parent; + new->_immed = win->_immed; + new->_sync = win->_sync; + new->_bkgd = win->_bkgd; + + new->_curx = save_curx; + new->_cury = save_cury; + + free(win->_firstch); + free(win->_lastch); + free(win->_y); + + *win = *new; + free(new); + + return win; +} + +int wresize(WINDOW *win, int nlines, int ncols) +{ + return (resize_window(win, nlines, ncols) ? OK : ERR); +} + +void wsyncup(WINDOW *win) +{ + WINDOW *tmp; + + PDC_LOG(("wsyncup() - called\n")); + + for (tmp = win; tmp; tmp = tmp->_parent) + touchwin(tmp); +} + +int syncok(WINDOW *win, bool bf) +{ + PDC_LOG(("syncok() - called\n")); + + if (!win) + return ERR; + + win->_sync = bf; + + return OK; +} + +void wcursyncup(WINDOW *win) +{ + WINDOW *tmp; + + PDC_LOG(("wcursyncup() - called\n")); + + for (tmp = win; tmp && tmp->_parent; tmp = tmp->_parent) + wmove(tmp->_parent, tmp->_pary + tmp->_cury, tmp->_parx + tmp->_curx); +} + +void wsyncdown(WINDOW *win) +{ + WINDOW *tmp; + + PDC_LOG(("wsyncdown() - called\n")); + + for (tmp = win; tmp; tmp = tmp->_parent) + { + if (is_wintouched(tmp)) + { + touchwin(win); + break; + } + } +} diff --git a/modules/ncurses/pdcurses/term.h b/modules/ncurses/pdcurses/term.h new file mode 100644 index 00000000..bda25b13 --- /dev/null +++ b/modules/ncurses/pdcurses/term.h @@ -0,0 +1,47 @@ +/* Public Domain Curses */ + +/* PDCurses doesn't operate with terminfo, but we need these functions for + compatibility, to allow some things (notably, interface libraries for + other languages) to be compiled. Anyone who tries to actually _use_ + them will be disappointed, since they only return ERR. */ + +#ifndef __PDCURSES_TERM_H__ +#define __PDCURSES_TERM_H__ 1 + +#include + +#if defined(__cplusplus) || defined(__cplusplus__) || defined(__CPLUSPLUS) +extern "C" +{ +#endif + +typedef struct +{ + const char *_termname; +} TERMINAL; + +PDCEX TERMINAL *cur_term; + +PDCEX int del_curterm(TERMINAL *); +PDCEX int putp(const char *); +PDCEX int restartterm(const char *, int, int *); +PDCEX TERMINAL *set_curterm(TERMINAL *); +PDCEX int setterm(const char *); +PDCEX int setupterm(const char *, int, int *); +PDCEX int tgetent(char *, const char *); +PDCEX int tgetflag(const char *); +PDCEX int tgetnum(const char *); +PDCEX char *tgetstr(const char *, char **); +PDCEX char *tgoto(const char *, int, int); +PDCEX int tigetflag(const char *); +PDCEX int tigetnum(const char *); +PDCEX char *tigetstr(const char *); +PDCEX char *tparm(const char *, long, long, long, long, long, + long, long, long, long); +PDCEX int tputs(const char *, int, int (*)(int)); + +#if defined(__cplusplus) || defined(__cplusplus__) || defined(__CPLUSPLUS) +} +#endif + +#endif /* __PDCURSES_TERM_H__ */ diff --git a/modules/ncurses/pdcurses/wincon/Makefile b/modules/ncurses/pdcurses/wincon/Makefile new file mode 100644 index 00000000..2a51ebdb --- /dev/null +++ b/modules/ncurses/pdcurses/wincon/Makefile @@ -0,0 +1,113 @@ +# GNU MAKE Makefile for PDCurses library - Windows console GCC +# +# Usage: make [-f path\Makefile] [DEBUG=Y] [DLL=Y] [WIDE=Y] [UTF8=Y] [tgt] +# +# where tgt can be any of: +# [all|demos|pdcurses.a|testcurs.exe...] + +O = o +E = .exe + +ifeq ($(OS),Windows_NT) + RM = cmd /c del +else + RM = rm -f +endif + +ifndef PDCURSES_SRCDIR + PDCURSES_SRCDIR = .. +endif + +include $(PDCURSES_SRCDIR)/version.mif +include $(PDCURSES_SRCDIR)/libobjs.mif + +osdir = $(PDCURSES_SRCDIR)/wincon + +PDCURSES_WIN_H = $(osdir)/pdcwin.h + +CC = gcc + +ifeq ($(DEBUG),Y) + CFLAGS = -g -Wall -DPDCDEBUG + LDFLAGS = -g +else + CFLAGS = -O2 -Wall + LDFLAGS = +endif + +CFLAGS += -I$(PDCURSES_SRCDIR) + +ifeq ($(WIDE),Y) + CFLAGS += -DPDC_WIDE +endif + +ifeq ($(UTF8),Y) + CFLAGS += -DPDC_FORCE_UTF8 +endif + +LINK = gcc + +ifeq ($(DLL),Y) + CFLAGS += -DPDC_DLL_BUILD + LIBEXE = gcc + LIBFLAGS = -Wl,--out-implib,pdcurses.a -shared -o + LIBCURSES = pdcurses.dll + LIBDEPS = $(LIBOBJS) $(PDCOBJS) + CLEAN = $(LIBCURSES) *.a +else + LIBEXE = ar + LIBFLAGS = rcv + LIBCURSES = pdcurses.a + LIBDEPS = $(LIBOBJS) $(PDCOBJS) + CLEAN = *.a +endif + +.PHONY: all libs clean demos dist + +all: libs demos + +libs: $(LIBCURSES) + +clean: + -$(RM) *.o + -$(RM) *.exe + -$(RM) $(CLEAN) + +demos: $(DEMOS) +ifneq ($(DEBUG),Y) + strip *.exe +endif + +$(LIBCURSES) : $(LIBDEPS) + $(LIBEXE) $(LIBFLAGS) $@ $? + +$(LIBOBJS) $(PDCOBJS) : $(PDCURSES_HEADERS) +$(PDCOBJS) : $(PDCURSES_WIN_H) +$(DEMOS) : $(PDCURSES_CURSES_H) $(LIBCURSES) +panel.o : $(PANEL_HEADER) +terminfo.o: $(TERM_HEADER) + +$(LIBOBJS) : %.o: $(srcdir)/%.c + $(CC) -c $(CFLAGS) $< + +$(PDCOBJS) : %.o: $(osdir)/%.c + $(CC) -c $(CFLAGS) $< + +firework.exe ozdemo.exe rain.exe testcurs.exe worm.exe xmas.exe \ +ptest.exe: %.exe: $(demodir)/%.c + $(CC) $(CFLAGS) -o$@ $< $(LIBCURSES) + +tuidemo.exe: tuidemo.o tui.o + $(LINK) $(LDFLAGS) -o$@ tuidemo.o tui.o $(LIBCURSES) + +tui.o: $(demodir)/tui.c $(demodir)/tui.h $(PDCURSES_CURSES_H) + $(CC) -c $(CFLAGS) -I$(demodir) -o$@ $< + +tuidemo.o: $(demodir)/tuidemo.c $(PDCURSES_CURSES_H) + $(CC) -c $(CFLAGS) -I$(demodir) -o$@ $< + +PLATFORM1 = GCC Wincon +PLATFORM2 = GCC for Windows console +ARCNAME = pdc$(VER)_gcc_wincon + +include $(PDCURSES_SRCDIR)/makedist.mif diff --git a/modules/ncurses/pdcurses/wincon/Makefile.bcc b/modules/ncurses/pdcurses/wincon/Makefile.bcc new file mode 100644 index 00000000..49a9a663 --- /dev/null +++ b/modules/ncurses/pdcurses/wincon/Makefile.bcc @@ -0,0 +1,86 @@ +# Borland MAKE Makefile for PDCurses library - Windows console BC++ 7.0+ +# +# Usage: make -f [path\]Makefile.bcc [DEBUG=] [WIDE=] [UTF8=] [target] +# +# where target can be any of: +# [all|demos|pdcurses.lib|testcurs.exe...] + +O = obj +E = .exe +RM = del + +!ifndef PDCURSES_SRCDIR +PDCURSES_SRCDIR = .. +!endif + +!include $(PDCURSES_SRCDIR)\version.mif +!include $(PDCURSES_SRCDIR)\libobjs.mif + +osdir = $(PDCURSES_SRCDIR)\wincon + +CC = bcc32c -q + +!ifdef DEBUG +CFLAGS = -N -v -y -DPDCDEBUG +!else +CFLAGS = -O +!endif + +!ifdef WIDE +WIDEOPT = -DPDC_WIDE +!endif + +!ifdef UTF8 +UTF8OPT = -DPDC_FORCE_UTF8 +!endif + +BUILD = $(CC) -I$(PDCURSES_SRCDIR) -c -Tpe $(CFLAGS) \ +$(WIDEOPT) $(UTF8OPT) + +LIBEXE = tlib /C /E /0 /a + +LIBCURSES = pdcurses.lib + +all: $(LIBCURSES) $(DEMOS) + +clean: + -$(RM) *.obj + -$(RM) *.lib + -$(RM) *.tds + -$(RM) *.exe + +$(LIBCURSES) : $(LIBOBJS) $(PDCOBJS) + -$(RM) $@ + $(LIBEXE) $@ $(LIBOBJS) $(PDCOBJS) + +.autodepend + +{$(srcdir)\}.c.obj: + $(BUILD) $< + +{$(osdir)\}.c.obj: + $(BUILD) $< + +{$(demodir)\}.c.obj: + $(BUILD) $< + +.c.obj: + $(BUILD) $< + +.obj.exe: + $(CC) -e$@ $** $(LIBCURSES) + +tuidemo.exe: tuidemo.obj tui.obj $(LIBCURSES) + $(CC) -e$@ $** + +tui.obj: $(demodir)\tui.c $(demodir)\tui.h $(PDCURSES_CURSES_H) + $(BUILD) -I$(demodir) $(demodir)\tui.c + +tuidemo.obj: $(demodir)\tuidemo.c $(PDCURSES_CURSES_H) + $(BUILD) -I$(demodir) $(demodir)\tuidemo.c + +PLATFORM1 = Borland C++ Wincon +PLATFORM2 = Borland C/C++ 7.2 for Windows console +ARCNAME = pdc$(VER)_bcc_wincon + +!include $(PDCURSES_SRCDIR)\makedist.mif diff --git a/modules/ncurses/pdcurses/wincon/Makefile.vc b/modules/ncurses/pdcurses/wincon/Makefile.vc new file mode 100644 index 00000000..dedb4023 --- /dev/null +++ b/modules/ncurses/pdcurses/wincon/Makefile.vc @@ -0,0 +1,120 @@ +# Visual C++ NMakefile for PDCurses library - Windows console VC++ 2.0+ +# +# Usage: nmake -f [path\]Makefile.vc [DEBUG=] [DLL=] [WIDE=] [UTF8=] [target] +# +# where target can be any of: +# [all|demos|pdcurses.lib|testcurs.exe...] + +O = obj +E = .exe +RM = del + +!ifndef PDCURSES_SRCDIR +PDCURSES_SRCDIR = .. +!endif + +!include $(PDCURSES_SRCDIR)\version.mif +!include $(PDCURSES_SRCDIR)\libobjs.mif + +osdir = $(PDCURSES_SRCDIR)\wincon + +PDCURSES_WIN_H = $(osdir)\pdcwin.h + +CC = cl.exe -nologo + +!ifdef DEBUG +CFLAGS = -Z7 -DPDCDEBUG +LDFLAGS = -debug -pdb:none +!else +CFLAGS = -O1 +LDFLAGS = +!endif + +!ifdef WIDE +WIDEOPT = -DPDC_WIDE +!endif + +!ifdef UTF8 +UTF8OPT = -DPDC_FORCE_UTF8 +!endif + +SHL_LD = link $(LDFLAGS) /NOLOGO /DLL /OUT:pdcurses.dll + +LINK = link.exe -nologo + +CCLIBS = user32.lib advapi32.lib +# may need to add msvcrt.lib for VC 2.x, VC 5.0 doesn't want it +#CCLIBS = msvcrt.lib user32.lib advapi32.lib + +LIBEXE = lib -nologo + +LIBCURSES = pdcurses.lib +CURSESDLL = pdcurses.dll + +!ifdef DLL +DLLOPT = -DPDC_DLL_BUILD +PDCLIBS = $(CURSESDLL) +!else +PDCLIBS = $(LIBCURSES) +!endif + +BUILD = $(CC) -I$(PDCURSES_SRCDIR) -c $(CFLAGS) $(DLLOPT) \ +$(WIDEOPT) $(UTF8OPT) + +all: $(PDCLIBS) $(DEMOS) + +clean: + -$(RM) *.obj + -$(RM) *.lib + -$(RM) *.exe + -$(RM) *.dll + -$(RM) *.exp + -$(RM) *.res + +DEMOOBJS = $(DEMOS:.exe=.obj) tui.obj + +$(LIBOBJS) $(PDCOBJS) : $(PDCURSES_HEADERS) +$(PDCOBJS) : $(PDCURSES_WIN_H) +$(DEMOOBJS) : $(PDCURSES_CURSES_H) +$(DEMOS) : $(LIBCURSES) +panel.obj : $(PANEL_HEADER) +terminfo.obj: $(TERM_HEADER) + +!ifndef DLL +$(LIBCURSES) : $(LIBOBJS) $(PDCOBJS) + $(LIBEXE) -out:$@ $(LIBOBJS) $(PDCOBJS) +!endif + +$(CURSESDLL) : $(LIBOBJS) $(PDCOBJS) pdcurses.obj + $(SHL_LD) $(LIBOBJS) $(PDCOBJS) pdcurses.obj $(CCLIBS) + +pdcurses.res pdcurses.obj: $(osdir)\pdcurses.rc $(osdir)\pdcurses.ico + rc /r /fopdcurses.res $(osdir)\pdcurses.rc + cvtres /NOLOGO /OUT:pdcurses.obj pdcurses.res + +{$(srcdir)\}.c{}.obj:: + $(BUILD) $< + +{$(osdir)\}.c{}.obj:: + $(BUILD) $< + +{$(demodir)\}.c{}.obj:: + $(BUILD) $< + +.obj.exe: + $(LINK) $(LDFLAGS) $< $(LIBCURSES) $(CCLIBS) + +tuidemo.exe: tuidemo.obj tui.obj + $(LINK) $(LDFLAGS) $*.obj tui.obj $(LIBCURSES) $(CCLIBS) + +tui.obj: $(demodir)\tui.c $(demodir)\tui.h + $(BUILD) -I$(demodir) $(demodir)\tui.c + +tuidemo.obj: $(demodir)\tuidemo.c + $(BUILD) -I$(demodir) $(demodir)\tuidemo.c + +PLATFORM1 = Visual C++ +PLATFORM2 = Microsoft Visual C/C++ for Windows console +ARCNAME = pdc$(VER)_vc_wincon + +!include $(PDCURSES_SRCDIR)\makedist.mif diff --git a/modules/ncurses/pdcurses/wincon/Makefile.wcc b/modules/ncurses/pdcurses/wincon/Makefile.wcc new file mode 100644 index 00000000..e93391ff --- /dev/null +++ b/modules/ncurses/pdcurses/wincon/Makefile.wcc @@ -0,0 +1,52 @@ +# Watcom WMAKE Makefile for PDCurses library - Windows console Open Watcom 1.8+ +# +# Usage: wmake -f [path\]Makefile.wcc [DEBUG=Y] [WIDE=Y] [UTF8=Y] [target] +# +# where target can be any of: +# [all|demos|pdcurses.lib|testcurs.exe...] + +RM = del + +!ifdef %PDCURSES_SRCDIR +PDCURSES_SRCDIR = $(%PDCURSES_SRCDIR) +!else +PDCURSES_SRCDIR = .. +!endif + +!include $(PDCURSES_SRCDIR)/version.mif + +osdir = $(PDCURSES_SRCDIR)/wincon + +CC = wcc386 +TARGET = nt + +CFLAGS = -ei -zq -wx -i=$(PDCURSES_SRCDIR) + +!ifeq DEBUG Y +CFLAGS += -d2 -DPDCDEBUG +LDFLAGS = D W A op q sys $(TARGET) +!else +CFLAGS += -oneatx +LDFLAGS = op q sys $(TARGET) +!endif + +!ifeq WIDE Y +CFLAGS += -DPDC_WIDE +!endif + +!ifeq UTF8 Y +CFLAGS += -DPDC_FORCE_UTF8 +!endif + +LIBEXE = wlib -q -n -t + +!include $(PDCURSES_SRCDIR)/watcom.mif + +$(LIBCURSES) : $(LIBOBJS) $(PDCOBJS) + $(LIBEXE) $@ $(LIBOBJS) $(PDCOBJS) + +PLATFORM1 = Watcom C++ Wincon +PLATFORM2 = Open Watcom 2.0 for Windows console +ARCNAME = pdc$(VER)_wcc_wincon + +!include $(PDCURSES_SRCDIR)/makedist.mif diff --git a/modules/ncurses/pdcurses/wincon/README.md b/modules/ncurses/pdcurses/wincon/README.md new file mode 100644 index 00000000..118c8985 --- /dev/null +++ b/modules/ncurses/pdcurses/wincon/README.md @@ -0,0 +1,70 @@ +PDCurses for Windows console +============================ + +This directory contains PDCurses source code files specific to the +Microsoft Windows console. Although historically called "Win32", this +port can just as easily be built for 64-bit systems. Windows 95 through +Windows 10 are covered. (Some features require later versions.) + + +Building +-------- + +- Choose the appropriate makefile for your compiler: + + Makefile - GNU Compiler (MinGW or Cygnus) + Makefile.bcc - Borland C++ 7.0+ + Makefile.vc - Microsoft Visual C++ 2.0+ + Makefile.wcc - Open Watcom 1.8+ + +- Optionally, you can build in a different directory than the platform + directory by setting PDCURSES_SRCDIR to point to the directory where + you unpacked PDCurses, and changing to your target directory: + + set PDCURSES_SRCDIR=c:\pdcurses + +- Build it: + + make -f makefilename + + (For Watcom, use "wmake" instead of "make"; for MSVC, "nmake".) You'll + get the libraries (pdcurses.lib or .a, depending on your compiler), + the demos (*.exe), and a lot of object files. + + You can also give the optional parameter "WIDE=Y", to build the + library with wide-character (Unicode) support: + + wmake -f Makefile.wcc WIDE=Y + + When built this way, the library is not compatible with Windows 9x, + unless you also link with the Microsoft Layer for Unicode (not + tested). + + Another option, "UTF8=Y", makes PDCurses ignore the system locale, and + treat all narrow-character strings as UTF-8. This option has no effect + unless WIDE=Y is also set. Use it to get around the poor support for + UTF-8 in the Windows console: + + make -f Makefile.bcc WIDE=Y UTF8=Y + + You can also use the optional parameter "DLL=Y" with Visual C++, + MinGW or Cygwin, to build the library as a DLL: + + nmake -f Makefile.vc WIDE=Y DLL=Y + + When you build the library as a Windows DLL, you must always define + PDC_DLL_BUILD when linking against it. (Or, if you only want to use + the DLL, you could add this definition to your curses.h.) + + +Distribution Status +------------------- + +The files in this directory are released to the Public Domain. + + +Acknowledgements +---------------- + +Windows console port was originally provided by Chris Szurgot + diff --git a/modules/ncurses/pdcurses/wincon/pdcclip.c b/modules/ncurses/pdcurses/wincon/pdcclip.c new file mode 100644 index 00000000..9dbf695a --- /dev/null +++ b/modules/ncurses/pdcurses/wincon/pdcclip.c @@ -0,0 +1,150 @@ +/* Public Domain Curses */ + +#include "pdcwin.h" + +#include + +/*man-start************************************************************** + +clipboard +--------- + +### Synopsis + + int PDC_getclipboard(char **contents, long *length); + int PDC_setclipboard(const char *contents, long length); + int PDC_freeclipboard(char *contents); + int PDC_clearclipboard(void); + +### Description + + PDC_getclipboard() gets the textual contents of the system's + clipboard. This function returns the contents of the clipboard + in the contents argument. It is the responsibility of the + caller to free the memory returned, via PDC_freeclipboard(). + The length of the clipboard contents is returned in the length + argument. + + PDC_setclipboard copies the supplied text into the system's + clipboard, emptying the clipboard prior to the copy. + + PDC_clearclipboard() clears the internal clipboard. + +### Return Values + + indicator of success/failure of call. + PDC_CLIP_SUCCESS the call was successful + PDC_CLIP_MEMORY_ERROR unable to allocate sufficient memory for + the clipboard contents + PDC_CLIP_EMPTY the clipboard contains no text + PDC_CLIP_ACCESS_ERROR no clipboard support + +### Portability + X/Open BSD SYS V + PDC_getclipboard - - - + PDC_setclipboard - - - + PDC_freeclipboard - - - + PDC_clearclipboard - - - + +**man-end****************************************************************/ + +#ifdef PDC_WIDE +# define PDC_TEXT CF_UNICODETEXT +#else +# define PDC_TEXT CF_OEMTEXT +#endif + +int PDC_getclipboard(char **contents, long *length) +{ + HANDLE handle; + long len; + + PDC_LOG(("PDC_getclipboard() - called\n")); + + if (!OpenClipboard(NULL)) + return PDC_CLIP_ACCESS_ERROR; + + if ((handle = GetClipboardData(PDC_TEXT)) == NULL) + { + CloseClipboard(); + return PDC_CLIP_EMPTY; + } + +#ifdef PDC_WIDE + len = wcslen((wchar_t *)handle) * 3; +#else + len = strlen((char *)handle); +#endif + *contents = (char *)GlobalAlloc(GMEM_FIXED, len + 1); + + if (!*contents) + { + CloseClipboard(); + return PDC_CLIP_MEMORY_ERROR; + } + +#ifdef PDC_WIDE + len = PDC_wcstombs((char *)*contents, (wchar_t *)handle, len); +#else + strcpy((char *)*contents, (char *)handle); +#endif + *length = len; + CloseClipboard(); + + return PDC_CLIP_SUCCESS; +} + +int PDC_setclipboard(const char *contents, long length) +{ + HGLOBAL ptr1; + LPTSTR ptr2; + + PDC_LOG(("PDC_setclipboard() - called\n")); + + if (!OpenClipboard(NULL)) + return PDC_CLIP_ACCESS_ERROR; + + ptr1 = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE, + (length + 1) * sizeof(TCHAR)); + + if (!ptr1) + return PDC_CLIP_MEMORY_ERROR; + + ptr2 = GlobalLock(ptr1); + +#ifdef PDC_WIDE + PDC_mbstowcs((wchar_t *)ptr2, contents, length); +#else + memcpy((char *)ptr2, contents, length + 1); +#endif + GlobalUnlock(ptr1); + EmptyClipboard(); + + if (!SetClipboardData(PDC_TEXT, ptr1)) + { + GlobalFree(ptr1); + return PDC_CLIP_ACCESS_ERROR; + } + + CloseClipboard(); + GlobalFree(ptr1); + + return PDC_CLIP_SUCCESS; +} + +int PDC_freeclipboard(char *contents) +{ + PDC_LOG(("PDC_freeclipboard() - called\n")); + + GlobalFree(contents); + return PDC_CLIP_SUCCESS; +} + +int PDC_clearclipboard(void) +{ + PDC_LOG(("PDC_clearclipboard() - called\n")); + + EmptyClipboard(); + + return PDC_CLIP_SUCCESS; +} diff --git a/modules/ncurses/pdcurses/wincon/pdcdisp.c b/modules/ncurses/pdcurses/wincon/pdcdisp.c new file mode 100644 index 00000000..d1cdde35 --- /dev/null +++ b/modules/ncurses/pdcurses/wincon/pdcdisp.c @@ -0,0 +1,160 @@ +/* Public Domain Curses */ + +#include "pdcwin.h" + +#include +#include + +#ifdef CHTYPE_LONG + +# define A(x) ((chtype)x | A_ALTCHARSET) + +chtype acs_map[128] = +{ + A(0), A(1), A(2), A(3), A(4), A(5), A(6), A(7), A(8), A(9), A(10), + A(11), A(12), A(13), A(14), A(15), A(16), A(17), A(18), A(19), + A(20), A(21), A(22), A(23), A(24), A(25), A(26), A(27), A(28), + A(29), A(30), A(31), ' ', '!', '"', '#', '$', '%', '&', '\'', '(', + ')', '*', + +# ifdef PDC_WIDE + 0x2192, 0x2190, 0x2191, 0x2193, +# else + A(0x1a), A(0x1b), A(0x18), A(0x19), +# endif + + '/', + +# ifdef PDC_WIDE + 0x2588, +# else + 0xdb, +# endif + + '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', + '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', + 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', + 'X', 'Y', 'Z', '[', '\\', ']', '^', '_', + +# ifdef PDC_WIDE + 0x2666, 0x2592, +# else + A(0x04), 0xb1, +# endif + + 'b', 'c', 'd', 'e', + +# ifdef PDC_WIDE + 0x00b0, 0x00b1, 0x2591, 0x00a4, 0x2518, 0x2510, 0x250c, 0x2514, + 0x253c, 0x23ba, 0x23bb, 0x2500, 0x23bc, 0x23bd, 0x251c, 0x2524, + 0x2534, 0x252c, 0x2502, 0x2264, 0x2265, 0x03c0, 0x2260, 0x00a3, + 0x00b7, +# else + 0xf8, 0xf1, 0xb0, A(0x0f), 0xd9, 0xbf, 0xda, 0xc0, 0xc5, 0x2d, 0x2d, + 0xc4, 0x2d, 0x5f, 0xc3, 0xb4, 0xc1, 0xc2, 0xb3, 0xf3, 0xf2, 0xe3, + 0xd8, 0x9c, 0xf9, +# endif + + A(127) +}; + +# undef A + +#endif + +DWORD pdc_last_blink; +static bool blinked_off = FALSE; + +/* position hardware cursor at (y, x) */ + +void PDC_gotoyx(int row, int col) +{ + COORD coord; + + PDC_LOG(("PDC_gotoyx() - called: row %d col %d from row %d col %d\n", + row, col, SP->cursrow, SP->curscol)); + + coord.X = col; + coord.Y = row; + + SetConsoleCursorPosition(pdc_con_out, coord); +} + +/* update the given physical line to look like the corresponding line in + curscr */ + +void PDC_transform_line(int lineno, int x, int len, const chtype *srcp) +{ + CHAR_INFO ci[512]; + int j; + COORD bufSize, bufPos; + SMALL_RECT sr; + bool sysblink; + + PDC_LOG(("PDC_transform_line() - called: lineno=%d\n", lineno)); + + bufPos.X = bufPos.Y = 0; + + bufSize.X = len; + bufSize.Y = 1; + + sr.Top = lineno; + sr.Bottom = lineno; + sr.Left = x; + sr.Right = x + len - 1; + + sysblink = !!(SP->termattrs & A_BLINK); + + for (j = 0; j < len; j++) + { + chtype att, ch = srcp[j]; + att = ch; + + if (sysblink && (att & A_BLINK)) + { + att &= ~A_BLINK; + if (blinked_off) + att &= ~(A_UNDERLINE | A_RIGHT | A_LEFT); + } + + ci[j].Attributes = pdc_atrtab[att >> PDC_ATTR_SHIFT]; + +#ifdef CHTYPE_LONG + if (ch & A_ALTCHARSET && !(ch & 0xff80)) + ch = acs_map[ch & 0x7f]; +#endif + if (sysblink && blinked_off && (ch & A_BLINK)) + ch = ' '; + + ci[j].Char.UnicodeChar = ch & A_CHARTEXT; + } + + WriteConsoleOutput(pdc_con_out, ci, bufSize, bufPos, &sr); +} + +void PDC_blink_text(void) +{ + int i, j, k; + + if (!(SP->termattrs & A_BLINK)) + blinked_off = FALSE; + else + blinked_off = !blinked_off; + + for (i = 0; i < SP->lines; i++) + { + const chtype *srcp = curscr->_y[i]; + + for (j = 0; j < SP->cols; j++) + if (srcp[j] & A_BLINK) + { + k = j; + while (k < SP->cols && (srcp[k] & A_BLINK)) + k++; + PDC_transform_line(i, j, k - j, srcp + j); + j = k; + } + } + + pdc_last_blink = GetTickCount(); +} diff --git a/modules/ncurses/pdcurses/wincon/pdcgetsc.c b/modules/ncurses/pdcurses/wincon/pdcgetsc.c new file mode 100644 index 00000000..eabd60e9 --- /dev/null +++ b/modules/ncurses/pdcurses/wincon/pdcgetsc.c @@ -0,0 +1,55 @@ +/* Public Domain Curses */ + +#include "pdcwin.h" + +/* get the cursor size/shape */ + +int PDC_get_cursor_mode(void) +{ + CONSOLE_CURSOR_INFO ci; + + PDC_LOG(("PDC_get_cursor_mode() - called\n")); + + GetConsoleCursorInfo(pdc_con_out, &ci); + + return ci.dwSize; +} + +/* return number of screen rows */ + +int PDC_get_rows(void) +{ + CONSOLE_SCREEN_BUFFER_INFO scr; + + PDC_LOG(("PDC_get_rows() - called\n")); + + GetConsoleScreenBufferInfo(pdc_con_out, &scr); + + return scr.srWindow.Bottom - scr.srWindow.Top + 1; +} + +/* return number of buffer rows */ + +int PDC_get_buffer_rows(void) +{ + CONSOLE_SCREEN_BUFFER_INFO scr; + + PDC_LOG(("PDC_get_buffer_rows() - called\n")); + + GetConsoleScreenBufferInfo(pdc_con_out, &scr); + + return scr.dwSize.Y; +} + +/* return width of screen/viewport */ + +int PDC_get_columns(void) +{ + CONSOLE_SCREEN_BUFFER_INFO scr; + + PDC_LOG(("PDC_get_columns() - called\n")); + + GetConsoleScreenBufferInfo(pdc_con_out, &scr); + + return scr.srWindow.Right - scr.srWindow.Left + 1; +} diff --git a/modules/ncurses/pdcurses/wincon/pdckbd.c b/modules/ncurses/pdcurses/wincon/pdckbd.c new file mode 100644 index 00000000..e041d311 --- /dev/null +++ b/modules/ncurses/pdcurses/wincon/pdckbd.c @@ -0,0 +1,680 @@ +/* Public Domain Curses */ + +#include "pdcwin.h" + +/*man-start************************************************************** + +pdckbd +------ + +### Synopsis + + unsigned long PDC_get_input_fd(void); + +### Description + + PDC_get_input_fd() returns the file descriptor that PDCurses + reads its input from. It can be used for select(). + +### Portability + X/Open BSD SYS V + PDC_get_input_fd - - - + +**man-end****************************************************************/ + +unsigned long pdc_key_modifiers = 0L; + +/* These variables are used to store information about the next + Input Event. */ + +static INPUT_RECORD save_ip; +static MOUSE_STATUS old_mouse_status; +static DWORD event_count = 0; +static SHORT left_key; +static int key_count = 0; +static int save_press = 0; + +#define KEV save_ip.Event.KeyEvent +#define MEV save_ip.Event.MouseEvent +#define REV save_ip.Event.WindowBufferSizeEvent + +/************************************************************************ + * Table for key code translation of function keys in keypad mode * + * These values are for strict IBM keyboard compatibles only * + ************************************************************************/ + +typedef struct +{ + unsigned short normal; + unsigned short shift; + unsigned short control; + unsigned short alt; + unsigned short extended; +} KPTAB; + +static KPTAB kptab[] = +{ + {0, 0, 0, 0, 0 }, /* 0 */ + {0, 0, 0, 0, 0 }, /* 1 VK_LBUTTON */ + {0, 0, 0, 0, 0 }, /* 2 VK_RBUTTON */ + {0, 0, 0, 0, 0 }, /* 3 VK_CANCEL */ + {0, 0, 0, 0, 0 }, /* 4 VK_MBUTTON */ + {0, 0, 0, 0, 0 }, /* 5 */ + {0, 0, 0, 0, 0 }, /* 6 */ + {0, 0, 0, 0, 0 }, /* 7 */ + {0x08, 0x08, 0x7F, ALT_BKSP, 0 }, /* 8 VK_BACK */ + {0x09, KEY_BTAB, CTL_TAB, ALT_TAB, 999 }, /* 9 VK_TAB */ + {0, 0, 0, 0, 0 }, /* 10 */ + {0, 0, 0, 0, 0 }, /* 11 */ + {KEY_B2, 0x35, CTL_PAD5, ALT_PAD5, 0 }, /* 12 VK_CLEAR */ + {0x0D, 0x0D, CTL_ENTER, ALT_ENTER, 1 }, /* 13 VK_RETURN */ + {0, 0, 0, 0, 0 }, /* 14 */ + {0, 0, 0, 0, 0 }, /* 15 */ + {0, 0, 0, 0, 0 }, /* 16 VK_SHIFT HANDLED SEPARATELY */ + {0, 0, 0, 0, 0 }, /* 17 VK_CONTROL HANDLED SEPARATELY */ + {0, 0, 0, 0, 0 }, /* 18 VK_MENU HANDLED SEPARATELY */ + {0, 0, 0, 0, 0 }, /* 19 VK_PAUSE */ + {0, 0, 0, 0, 0 }, /* 20 VK_CAPITAL HANDLED SEPARATELY */ + {0, 0, 0, 0, 0 }, /* 21 VK_HANGUL */ + {0, 0, 0, 0, 0 }, /* 22 */ + {0, 0, 0, 0, 0 }, /* 23 VK_JUNJA */ + {0, 0, 0, 0, 0 }, /* 24 VK_FINAL */ + {0, 0, 0, 0, 0 }, /* 25 VK_HANJA */ + {0, 0, 0, 0, 0 }, /* 26 */ + {0x1B, 0x1B, 0x1B, ALT_ESC, 0 }, /* 27 VK_ESCAPE */ + {0, 0, 0, 0, 0 }, /* 28 VK_CONVERT */ + {0, 0, 0, 0, 0 }, /* 29 VK_NONCONVERT */ + {0, 0, 0, 0, 0 }, /* 30 VK_ACCEPT */ + {0, 0, 0, 0, 0 }, /* 31 VK_MODECHANGE */ + {0x20, 0x20, 0x20, 0x20, 0 }, /* 32 VK_SPACE */ + {KEY_A3, 0x39, CTL_PAD9, ALT_PAD9, 3 }, /* 33 VK_PRIOR */ + {KEY_C3, 0x33, CTL_PAD3, ALT_PAD3, 4 }, /* 34 VK_NEXT */ + {KEY_C1, 0x31, CTL_PAD1, ALT_PAD1, 5 }, /* 35 VK_END */ + {KEY_A1, 0x37, CTL_PAD7, ALT_PAD7, 6 }, /* 36 VK_HOME */ + {KEY_B1, 0x34, CTL_PAD4, ALT_PAD4, 7 }, /* 37 VK_LEFT */ + {KEY_A2, 0x38, CTL_PAD8, ALT_PAD8, 8 }, /* 38 VK_UP */ + {KEY_B3, 0x36, CTL_PAD6, ALT_PAD6, 9 }, /* 39 VK_RIGHT */ + {KEY_C2, 0x32, CTL_PAD2, ALT_PAD2, 10 }, /* 40 VK_DOWN */ + {0, 0, 0, 0, 0 }, /* 41 VK_SELECT */ + {0, 0, 0, 0, 0 }, /* 42 VK_PRINT */ + {0, 0, 0, 0, 0 }, /* 43 VK_EXECUTE */ + {0, 0, 0, 0, 0 }, /* 44 VK_SNAPSHOT*/ + {PAD0, 0x30, CTL_PAD0, ALT_PAD0, 11 }, /* 45 VK_INSERT */ + {PADSTOP, 0x2E, CTL_PADSTOP, ALT_PADSTOP,12 }, /* 46 VK_DELETE */ + {0, 0, 0, 0, 0 }, /* 47 VK_HELP */ + {0x30, 0x29, 0, ALT_0, 0 }, /* 48 */ + {0x31, 0x21, 0, ALT_1, 0 }, /* 49 */ + {0x32, 0x40, 0, ALT_2, 0 }, /* 50 */ + {0x33, 0x23, 0, ALT_3, 0 }, /* 51 */ + {0x34, 0x24, 0, ALT_4, 0 }, /* 52 */ + {0x35, 0x25, 0, ALT_5, 0 }, /* 53 */ + {0x36, 0x5E, 0, ALT_6, 0 }, /* 54 */ + {0x37, 0x26, 0, ALT_7, 0 }, /* 55 */ + {0x38, 0x2A, 0, ALT_8, 0 }, /* 56 */ + {0x39, 0x28, 0, ALT_9, 0 }, /* 57 */ + {0, 0, 0, 0, 0 }, /* 58 */ + {0, 0, 0, 0, 0 }, /* 59 */ + {0, 0, 0, 0, 0 }, /* 60 */ + {0, 0, 0, 0, 0 }, /* 61 */ + {0, 0, 0, 0, 0 }, /* 62 */ + {0, 0, 0, 0, 0 }, /* 63 */ + {0, 0, 0, 0, 0 }, /* 64 */ + {0x61, 0x41, 0x01, ALT_A, 0 }, /* 65 */ + {0x62, 0x42, 0x02, ALT_B, 0 }, /* 66 */ + {0x63, 0x43, 0x03, ALT_C, 0 }, /* 67 */ + {0x64, 0x44, 0x04, ALT_D, 0 }, /* 68 */ + {0x65, 0x45, 0x05, ALT_E, 0 }, /* 69 */ + {0x66, 0x46, 0x06, ALT_F, 0 }, /* 70 */ + {0x67, 0x47, 0x07, ALT_G, 0 }, /* 71 */ + {0x68, 0x48, 0x08, ALT_H, 0 }, /* 72 */ + {0x69, 0x49, 0x09, ALT_I, 0 }, /* 73 */ + {0x6A, 0x4A, 0x0A, ALT_J, 0 }, /* 74 */ + {0x6B, 0x4B, 0x0B, ALT_K, 0 }, /* 75 */ + {0x6C, 0x4C, 0x0C, ALT_L, 0 }, /* 76 */ + {0x6D, 0x4D, 0x0D, ALT_M, 0 }, /* 77 */ + {0x6E, 0x4E, 0x0E, ALT_N, 0 }, /* 78 */ + {0x6F, 0x4F, 0x0F, ALT_O, 0 }, /* 79 */ + {0x70, 0x50, 0x10, ALT_P, 0 }, /* 80 */ + {0x71, 0x51, 0x11, ALT_Q, 0 }, /* 81 */ + {0x72, 0x52, 0x12, ALT_R, 0 }, /* 82 */ + {0x73, 0x53, 0x13, ALT_S, 0 }, /* 83 */ + {0x74, 0x54, 0x14, ALT_T, 0 }, /* 84 */ + {0x75, 0x55, 0x15, ALT_U, 0 }, /* 85 */ + {0x76, 0x56, 0x16, ALT_V, 0 }, /* 86 */ + {0x77, 0x57, 0x17, ALT_W, 0 }, /* 87 */ + {0x78, 0x58, 0x18, ALT_X, 0 }, /* 88 */ + {0x79, 0x59, 0x19, ALT_Y, 0 }, /* 89 */ + {0x7A, 0x5A, 0x1A, ALT_Z, 0 }, /* 90 */ + {0, 0, 0, 0, 0 }, /* 91 VK_LWIN */ + {0, 0, 0, 0, 0 }, /* 92 VK_RWIN */ + {0, 0, 0, 0, 0 }, /* 93 VK_APPS */ + {0, 0, 0, 0, 0 }, /* 94 */ + {0, 0, 0, 0, 0 }, /* 95 */ + {0x30, 0, CTL_PAD0, ALT_PAD0, 0 }, /* 96 VK_NUMPAD0 */ + {0x31, 0, CTL_PAD1, ALT_PAD1, 0 }, /* 97 VK_NUMPAD1 */ + {0x32, 0, CTL_PAD2, ALT_PAD2, 0 }, /* 98 VK_NUMPAD2 */ + {0x33, 0, CTL_PAD3, ALT_PAD3, 0 }, /* 99 VK_NUMPAD3 */ + {0x34, 0, CTL_PAD4, ALT_PAD4, 0 }, /* 100 VK_NUMPAD4 */ + {0x35, 0, CTL_PAD5, ALT_PAD5, 0 }, /* 101 VK_NUMPAD5 */ + {0x36, 0, CTL_PAD6, ALT_PAD6, 0 }, /* 102 VK_NUMPAD6 */ + {0x37, 0, CTL_PAD7, ALT_PAD7, 0 }, /* 103 VK_NUMPAD7 */ + {0x38, 0, CTL_PAD8, ALT_PAD8, 0 }, /* 104 VK_NUMPAD8 */ + {0x39, 0, CTL_PAD9, ALT_PAD9, 0 }, /* 105 VK_NUMPAD9 */ + {PADSTAR, SHF_PADSTAR,CTL_PADSTAR, ALT_PADSTAR,999 }, /* 106 VK_MULTIPLY*/ + {PADPLUS, SHF_PADPLUS,CTL_PADPLUS, ALT_PADPLUS,999 }, /* 107 VK_ADD */ + {0, 0, 0, 0, 0 }, /* 108 VK_SEPARATOR */ + {PADMINUS, SHF_PADMINUS,CTL_PADMINUS,ALT_PADMINUS,999}, /* 109 VK_SUBTRACT*/ + {0x2E, 0, CTL_PADSTOP, ALT_PADSTOP,0 }, /* 110 VK_DECIMAL */ + {PADSLASH, SHF_PADSLASH,CTL_PADSLASH,ALT_PADSLASH,2 }, /* 111 VK_DIVIDE */ + {KEY_F(1), KEY_F(13), KEY_F(25), KEY_F(37), 0 }, /* 112 VK_F1 */ + {KEY_F(2), KEY_F(14), KEY_F(26), KEY_F(38), 0 }, /* 113 VK_F2 */ + {KEY_F(3), KEY_F(15), KEY_F(27), KEY_F(39), 0 }, /* 114 VK_F3 */ + {KEY_F(4), KEY_F(16), KEY_F(28), KEY_F(40), 0 }, /* 115 VK_F4 */ + {KEY_F(5), KEY_F(17), KEY_F(29), KEY_F(41), 0 }, /* 116 VK_F5 */ + {KEY_F(6), KEY_F(18), KEY_F(30), KEY_F(42), 0 }, /* 117 VK_F6 */ + {KEY_F(7), KEY_F(19), KEY_F(31), KEY_F(43), 0 }, /* 118 VK_F7 */ + {KEY_F(8), KEY_F(20), KEY_F(32), KEY_F(44), 0 }, /* 119 VK_F8 */ + {KEY_F(9), KEY_F(21), KEY_F(33), KEY_F(45), 0 }, /* 120 VK_F9 */ + {KEY_F(10), KEY_F(22), KEY_F(34), KEY_F(46), 0 }, /* 121 VK_F10 */ + {KEY_F(11), KEY_F(23), KEY_F(35), KEY_F(47), 0 }, /* 122 VK_F11 */ + {KEY_F(12), KEY_F(24), KEY_F(36), KEY_F(48), 0 }, /* 123 VK_F12 */ + + /* 124 through 218 */ + + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + + {0x5B, 0x7B, 0x1B, ALT_LBRACKET,0 }, /* 219 */ + {0x5C, 0x7C, 0x1C, ALT_BSLASH, 0 }, /* 220 */ + {0x5D, 0x7D, 0x1D, ALT_RBRACKET,0 }, /* 221 */ + {0, 0, 0x27, ALT_FQUOTE, 0 }, /* 222 */ + {0, 0, 0, 0, 0 }, /* 223 */ + {0, 0, 0, 0, 0 }, /* 224 */ + {0, 0, 0, 0, 0 } /* 225 */ +}; + +static KPTAB ext_kptab[] = +{ + {0, 0, 0, 0, }, /* MUST BE EMPTY */ + {PADENTER, SHF_PADENTER, CTL_PADENTER, ALT_PADENTER}, /* 13 */ + {PADSLASH, SHF_PADSLASH, CTL_PADSLASH, ALT_PADSLASH}, /* 111 */ + {KEY_PPAGE, KEY_SPREVIOUS, CTL_PGUP, ALT_PGUP }, /* 33 */ + {KEY_NPAGE, KEY_SNEXT, CTL_PGDN, ALT_PGDN }, /* 34 */ + {KEY_END, KEY_SEND, CTL_END, ALT_END }, /* 35 */ + {KEY_HOME, KEY_SHOME, CTL_HOME, ALT_HOME }, /* 36 */ + {KEY_LEFT, KEY_SLEFT, CTL_LEFT, ALT_LEFT }, /* 37 */ + {KEY_UP, KEY_SUP, CTL_UP, ALT_UP }, /* 38 */ + {KEY_RIGHT, KEY_SRIGHT, CTL_RIGHT, ALT_RIGHT }, /* 39 */ + {KEY_DOWN, KEY_SDOWN, CTL_DOWN, ALT_DOWN }, /* 40 */ + {KEY_IC, KEY_SIC, CTL_INS, ALT_INS }, /* 45 */ + {KEY_DC, KEY_SDC, CTL_DEL, ALT_DEL }, /* 46 */ + {PADSLASH, SHF_PADSLASH, CTL_PADSLASH, ALT_PADSLASH}, /* 191 */ +}; + +/* End of kptab[] */ + +unsigned long PDC_get_input_fd(void) +{ + PDC_LOG(("PDC_get_input_fd() - called\n")); + + return 0L; +} + +void PDC_set_keyboard_binary(bool on) +{ + PDC_LOG(("PDC_set_keyboard_binary() - called\n")); +} + +/* check if a key or mouse event is waiting */ + +bool PDC_check_key(void) +{ + if (key_count > 0) + return TRUE; + + GetNumberOfConsoleInputEvents(pdc_con_in, &event_count); + + return (event_count != 0); +} + +/* _get_key_count returns 0 if save_ip doesn't contain an event which + should be passed back to the user. This function filters "useless" + events. + + The function returns the number of keys waiting. This may be > 1 + if the repetition of real keys pressed so far are > 1. + + Returns 0 on NUMLOCK, CAPSLOCK, SCROLLLOCK. + + Returns 1 for SHIFT, ALT, CTRL only if no other key has been pressed + in between, and SP->return_key_modifiers is set; these are returned + on keyup. + + Normal keys are returned on keydown only. The number of repetitions + are returned. Dead keys (diacritics) are omitted. See below for a + description. +*/ + +static int _get_key_count(void) +{ + int num_keys = 0, vk; + + PDC_LOG(("_get_key_count() - called\n")); + + vk = KEV.wVirtualKeyCode; + + if (KEV.bKeyDown) + { + /* key down */ + + save_press = 0; + + if (vk == VK_CAPITAL || vk == VK_NUMLOCK || vk == VK_SCROLL) + { + /* throw away these modifiers */ + } + else if (vk == VK_SHIFT || vk == VK_CONTROL || vk == VK_MENU) + { + /* These keys are returned on keyup only. */ + + save_press = vk; + switch (vk) + { + case VK_SHIFT: + left_key = GetKeyState(VK_LSHIFT); + break; + case VK_CONTROL: + left_key = GetKeyState(VK_LCONTROL); + break; + case VK_MENU: + left_key = GetKeyState(VK_LMENU); + } + } + else + { + /* Check for diacritics. These are dead keys. Some locales + have modified characters like umlaut-a, which is an "a" + with two dots on it. In some locales you have to press a + special key (the dead key) immediately followed by the + "a" to get a composed umlaut-a. The special key may have + a normal meaning with different modifiers. */ + + if (KEV.uChar.UnicodeChar || !(MapVirtualKey(vk, 2) & 0x80000000)) + num_keys = KEV.wRepeatCount; + } + } + else + { + /* key up */ + + /* Only modifier keys or the results of ALT-numpad entry are + returned on keyup */ + + if ((vk == VK_MENU && KEV.uChar.UnicodeChar) || + ((vk == VK_SHIFT || vk == VK_CONTROL || vk == VK_MENU) && + vk == save_press)) + { + save_press = 0; + num_keys = 1; + } + } + + PDC_LOG(("_get_key_count() - returning: num_keys %d\n", num_keys)); + + return num_keys; +} + +/* _process_key_event returns -1 if the key in save_ip should be + ignored. Otherwise it returns the keycode which should be returned + by PDC_get_key(). save_ip must be a key event. + + CTRL-ALT support has been disabled, when is it emitted plainly? */ + +static int _process_key_event(void) +{ + int key = (unsigned short)KEV.uChar.UnicodeChar; + WORD vk = KEV.wVirtualKeyCode; + DWORD state = KEV.dwControlKeyState; + + int idx; + BOOL enhanced; + + SP->key_code = TRUE; + + /* Save the key modifiers if required. Do this first to allow to + detect e.g. a pressed CTRL key after a hit of NUMLOCK. */ + + if (SP->save_key_modifiers) + { + if (state & (LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED)) + pdc_key_modifiers |= PDC_KEY_MODIFIER_ALT; + + if (state & SHIFT_PRESSED) + pdc_key_modifiers |= PDC_KEY_MODIFIER_SHIFT; + + if (state & (LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED)) + pdc_key_modifiers |= PDC_KEY_MODIFIER_CONTROL; + + if (state & NUMLOCK_ON) + pdc_key_modifiers |= PDC_KEY_MODIFIER_NUMLOCK; + } + + /* Handle modifier keys hit by themselves */ + + switch (vk) + { + case VK_SHIFT: /* shift */ + if (!SP->return_key_modifiers) + return -1; + + return (left_key & 0x8000) ? KEY_SHIFT_L : KEY_SHIFT_R; + + case VK_CONTROL: /* control */ + if (!SP->return_key_modifiers) + return -1; + + return (left_key & 0x8000) ? KEY_CONTROL_L : KEY_CONTROL_R; + + case VK_MENU: /* alt */ + if (!key) + { + if (!SP->return_key_modifiers) + return -1; + + return (left_key & 0x8000) ? KEY_ALT_L : KEY_ALT_R; + } + } + + /* The system may emit Ascii or Unicode characters depending on + whether ReadConsoleInputA or ReadConsoleInputW is used. + + Normally, if key != 0 then the system did the translation + successfully. But this is not true for LEFT_ALT (different to + RIGHT_ALT). In case of LEFT_ALT we can get key != 0. So + check for this first. */ + + if (key && ( !(state & LEFT_ALT_PRESSED) || + (state & RIGHT_ALT_PRESSED) )) + { + /* This code should catch all keys returning a printable + character. Characters above 0x7F should be returned as + positive codes. */ + + if (kptab[vk].extended == 0) + { + SP->key_code = FALSE; + return key; + } + } + + /* This case happens if a functional key has been entered. */ + + if ((state & ENHANCED_KEY) && (kptab[vk].extended != 999)) + { + enhanced = TRUE; + idx = kptab[vk].extended; + } + else + { + enhanced = FALSE; + idx = vk; + } + + if (state & SHIFT_PRESSED) + key = enhanced ? ext_kptab[idx].shift : kptab[idx].shift; + + else if (state & (LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED)) + key = enhanced ? ext_kptab[idx].control : kptab[idx].control; + + else if (state & (LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED)) + key = enhanced ? ext_kptab[idx].alt : kptab[idx].alt; + + else + key = enhanced ? ext_kptab[idx].normal : kptab[idx].normal; + + if (key < KEY_CODE_YES) + SP->key_code = FALSE; + + return key; +} + +static int _process_mouse_event(void) +{ + static const DWORD button_mask[] = {1, 4, 2}; + short action, shift_flags = 0; + int i; + + save_press = 0; + SP->key_code = TRUE; + + memset(&pdc_mouse_status, 0, sizeof(MOUSE_STATUS)); + + /* Handle scroll wheel */ + + if (MEV.dwEventFlags == 4) + { + pdc_mouse_status.changes = (MEV.dwButtonState & 0xFF000000) ? + PDC_MOUSE_WHEEL_DOWN : PDC_MOUSE_WHEEL_UP; + + pdc_mouse_status.x = -1; + pdc_mouse_status.y = -1; + + memset(&old_mouse_status, 0, sizeof(old_mouse_status)); + + return KEY_MOUSE; + } + + if (MEV.dwEventFlags == 8) + { + pdc_mouse_status.changes = (MEV.dwButtonState & 0xFF000000) ? + PDC_MOUSE_WHEEL_RIGHT : PDC_MOUSE_WHEEL_LEFT; + + pdc_mouse_status.x = -1; + pdc_mouse_status.y = -1; + + memset(&old_mouse_status, 0, sizeof(old_mouse_status)); + + return KEY_MOUSE; + } + + action = (MEV.dwEventFlags == 2) ? BUTTON_DOUBLE_CLICKED : + ((MEV.dwEventFlags == 1) ? BUTTON_MOVED : BUTTON_PRESSED); + + for (i = 0; i < 3; i++) + pdc_mouse_status.button[i] = + (MEV.dwButtonState & button_mask[i]) ? action : 0; + + if (action == BUTTON_PRESSED && MEV.dwButtonState & 7 && SP->mouse_wait) + { + /* Check for a click -- a PRESS followed immediately by a release */ + + if (!event_count) + { + napms(SP->mouse_wait); + + GetNumberOfConsoleInputEvents(pdc_con_in, &event_count); + } + + if (event_count) + { + INPUT_RECORD ip; + DWORD count; + bool have_click = FALSE; + + PeekConsoleInput(pdc_con_in, &ip, 1, &count); + + for (i = 0; i < 3; i++) + { + if (pdc_mouse_status.button[i] == BUTTON_PRESSED && + !(ip.Event.MouseEvent.dwButtonState & button_mask[i])) + { + pdc_mouse_status.button[i] = BUTTON_CLICKED; + have_click = TRUE; + } + } + + /* If a click was found, throw out the event */ + + if (have_click) + ReadConsoleInput(pdc_con_in, &ip, 1, &count); + } + } + + pdc_mouse_status.x = MEV.dwMousePosition.X; + pdc_mouse_status.y = MEV.dwMousePosition.Y; + + pdc_mouse_status.changes = 0; + + for (i = 0; i < 3; i++) + { + if (old_mouse_status.button[i] != pdc_mouse_status.button[i]) + pdc_mouse_status.changes |= (1 << i); + + if (pdc_mouse_status.button[i] == BUTTON_MOVED) + { + /* Discard non-moved "moves" */ + + if (pdc_mouse_status.x == old_mouse_status.x && + pdc_mouse_status.y == old_mouse_status.y) + return -1; + + /* Motion events always flag the button as changed */ + + pdc_mouse_status.changes |= (1 << i); + pdc_mouse_status.changes |= PDC_MOUSE_MOVED; + break; + } + } + + old_mouse_status = pdc_mouse_status; + + /* Treat click events as release events for comparison purposes */ + + for (i = 0; i < 3; i++) + { + if (old_mouse_status.button[i] == BUTTON_CLICKED || + old_mouse_status.button[i] == BUTTON_DOUBLE_CLICKED) + old_mouse_status.button[i] = BUTTON_RELEASED; + } + + /* Check for SHIFT/CONTROL/ALT */ + + if (MEV.dwControlKeyState & (LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED)) + shift_flags |= BUTTON_ALT; + + if (MEV.dwControlKeyState & (LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED)) + shift_flags |= BUTTON_CONTROL; + + if (MEV.dwControlKeyState & SHIFT_PRESSED) + shift_flags |= BUTTON_SHIFT; + + if (shift_flags) + { + for (i = 0; i < 3; i++) + { + if (pdc_mouse_status.changes & (1 << i)) + pdc_mouse_status.button[i] |= shift_flags; + } + } + + return KEY_MOUSE; +} + +/* return the next available key or mouse event */ + +int PDC_get_key(void) +{ + pdc_key_modifiers = 0L; + + if (!key_count) + { + DWORD count; + + ReadConsoleInput(pdc_con_in, &save_ip, 1, &count); + event_count--; + + if (save_ip.EventType == MOUSE_EVENT || + save_ip.EventType == WINDOW_BUFFER_SIZE_EVENT) + key_count = 1; + else if (save_ip.EventType == KEY_EVENT) + key_count = _get_key_count(); + } + + if (key_count) + { + key_count--; + + switch (save_ip.EventType) + { + case KEY_EVENT: + return _process_key_event(); + + case MOUSE_EVENT: + return _process_mouse_event(); + + case WINDOW_BUFFER_SIZE_EVENT: + if (REV.dwSize.Y != LINES || REV.dwSize.X != COLS) + { + if (!SP->resized) + { + SP->resized = TRUE; + return KEY_RESIZE; + } + } + } + } + + return -1; +} + +/* discard any pending keyboard or mouse input -- this is the core + routine for flushinp() */ + +void PDC_flushinp(void) +{ + PDC_LOG(("PDC_flushinp() - called\n")); + + FlushConsoleInputBuffer(pdc_con_in); +} + +int PDC_mouse_set(void) +{ + /* If turning on mouse input: Set ENABLE_MOUSE_INPUT, and clear + all other flags, including the extended flags; + If turning off the mouse: Set QuickEdit Mode to the status it + had on startup, and clear all other flags */ + + SetConsoleMode(pdc_con_in, SP->_trap_mbe ? + (ENABLE_MOUSE_INPUT|0x0088) : (pdc_quick_edit|0x0088)); + + memset(&old_mouse_status, 0, sizeof(old_mouse_status)); + + return OK; +} + +int PDC_modifiers_set(void) +{ + return OK; +} diff --git a/modules/ncurses/pdcurses/wincon/pdcscrn.c b/modules/ncurses/pdcurses/wincon/pdcscrn.c new file mode 100644 index 00000000..ead7e908 --- /dev/null +++ b/modules/ncurses/pdcurses/wincon/pdcscrn.c @@ -0,0 +1,677 @@ +/* Public Domain Curses */ + +#include "pdcwin.h" + +#include + +#ifdef CHTYPE_LONG +# define PDC_OFFSET 128 +#else +# define PDC_OFFSET 8 +#endif + +/* COLOR_PAIR to attribute encoding table. */ + +WORD *pdc_atrtab = (WORD *)NULL; + +HANDLE std_con_out = INVALID_HANDLE_VALUE; +HANDLE pdc_con_out = INVALID_HANDLE_VALUE; +HANDLE pdc_con_in = INVALID_HANDLE_VALUE; + +DWORD pdc_quick_edit; + +static short curstoreal[16], realtocurs[16] = +{ + COLOR_BLACK, COLOR_BLUE, COLOR_GREEN, COLOR_CYAN, COLOR_RED, + COLOR_MAGENTA, COLOR_YELLOW, COLOR_WHITE, COLOR_BLACK + 8, + COLOR_BLUE + 8, COLOR_GREEN + 8, COLOR_CYAN + 8, COLOR_RED + 8, + COLOR_MAGENTA + 8, COLOR_YELLOW + 8, COLOR_WHITE + 8 +}; + +enum { PDC_RESTORE_NONE, PDC_RESTORE_BUFFER }; + +/* Struct for storing console registry keys, and for use with the + undocumented WM_SETCONSOLEINFO message. Originally by James Brown, + www.catch22.net. */ + +static struct +{ + ULONG Length; + COORD ScreenBufferSize; + COORD WindowSize; + ULONG WindowPosX; + ULONG WindowPosY; + + COORD FontSize; + ULONG FontFamily; + ULONG FontWeight; + WCHAR FaceName[32]; + + ULONG CursorSize; + ULONG FullScreen; + ULONG QuickEdit; + ULONG AutoPosition; + ULONG InsertMode; + + USHORT ScreenColors; + USHORT PopupColors; + ULONG HistoryNoDup; + ULONG HistoryBufferSize; + ULONG NumberOfHistoryBuffers; + + COLORREF ColorTable[16]; + + ULONG CodePage; + HWND Hwnd; + + WCHAR ConsoleTitle[0x100]; +} console_info; + +typedef BOOL (WINAPI *SetConsoleScreenBufferInfoExFn)(HANDLE hConsoleOutput, + PCONSOLE_SCREEN_BUFFER_INFOEX lpConsoleScreenBufferInfoEx); +typedef BOOL (WINAPI *GetConsoleScreenBufferInfoExFn)(HANDLE hConsoleOutput, + PCONSOLE_SCREEN_BUFFER_INFOEX lpConsoleScreenBufferInfoEx); + +static SetConsoleScreenBufferInfoExFn pSetConsoleScreenBufferInfoEx = NULL; +static GetConsoleScreenBufferInfoExFn pGetConsoleScreenBufferInfoEx = NULL; + +static CONSOLE_SCREEN_BUFFER_INFO orig_scr; +static CONSOLE_SCREEN_BUFFER_INFOEX console_infoex; + +static LPTOP_LEVEL_EXCEPTION_FILTER xcpt_filter; + +static DWORD old_console_mode = 0; + +static bool is_nt; + +static HWND _find_console_handle(void) +{ + TCHAR orgtitle[1024], temptitle[1024]; + HWND wnd; + + GetConsoleTitle(orgtitle, 1024); + + wsprintf(temptitle, TEXT("%d/%d"), GetTickCount(), GetCurrentProcessId()); + SetConsoleTitle(temptitle); + + Sleep(40); + + wnd = FindWindow(NULL, temptitle); + + SetConsoleTitle(orgtitle); + + return wnd; +} + +/* Undocumented console message */ + +#define WM_SETCONSOLEINFO (WM_USER + 201) + +/* Wrapper around WM_SETCONSOLEINFO. We need to create the necessary + section (file-mapping) object in the context of the process which + owns the console, before posting the message. Originally by JB. */ + +static void _set_console_info(void) +{ + CONSOLE_SCREEN_BUFFER_INFO csbi; + CONSOLE_CURSOR_INFO cci; + DWORD dwConsoleOwnerPid; + HANDLE hProcess; + HANDLE hSection, hDupSection; + PVOID ptrView; + + /* Each-time initialization for console_info */ + + GetConsoleCursorInfo(pdc_con_out, &cci); + console_info.CursorSize = cci.dwSize; + + GetConsoleScreenBufferInfo(pdc_con_out, &csbi); + console_info.ScreenBufferSize = csbi.dwSize; + + console_info.WindowSize.X = csbi.srWindow.Right - csbi.srWindow.Left + 1; + console_info.WindowSize.Y = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; + + console_info.WindowPosX = csbi.srWindow.Left; + console_info.WindowPosY = csbi.srWindow.Top; + + /* Open the process which "owns" the console */ + + GetWindowThreadProcessId(console_info.Hwnd, &dwConsoleOwnerPid); + + hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwConsoleOwnerPid); + + /* Create a SECTION object backed by page-file, then map a view of + this section into the owner process so we can write the contents + of the CONSOLE_INFO buffer into it */ + + hSection = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, + 0, sizeof(console_info), 0); + + /* Copy our console structure into the section-object */ + + ptrView = MapViewOfFile(hSection, FILE_MAP_WRITE|FILE_MAP_READ, + 0, 0, sizeof(console_info)); + + memcpy(ptrView, &console_info, sizeof(console_info)); + + UnmapViewOfFile(ptrView); + + /* Map the memory into owner process */ + + DuplicateHandle(GetCurrentProcess(), hSection, hProcess, &hDupSection, + 0, FALSE, DUPLICATE_SAME_ACCESS); + + /* Send console window the "update" message */ + + SendMessage(console_info.Hwnd, WM_SETCONSOLEINFO, (WPARAM)hDupSection, 0); + + CloseHandle(hSection); + CloseHandle(hProcess); +} + +static int _set_console_infoex(void) +{ + if (!pSetConsoleScreenBufferInfoEx(pdc_con_out, &console_infoex)) + return ERR; + + return OK; +} + +static int _set_colors(void) +{ + if (pSetConsoleScreenBufferInfoEx) + return _set_console_infoex(); + else + { + _set_console_info(); + return OK; + } +} + +/* One-time initialization for console_info -- color table and font info + from the registry; other values from functions. */ + +static void _init_console_info(void) +{ + DWORD scrnmode, len; + HKEY reghnd; + int i; + + console_info.Hwnd = _find_console_handle(); + console_info.Length = sizeof(console_info); + + GetConsoleMode(pdc_con_in, &scrnmode); + console_info.QuickEdit = !!(scrnmode & 0x0040); + console_info.InsertMode = !!(scrnmode & 0x0020); + + console_info.FullScreen = FALSE; + console_info.AutoPosition = 0x10000; + console_info.ScreenColors = SP->orig_back << 4 | SP->orig_fore; + console_info.PopupColors = 0xf5; + + console_info.HistoryNoDup = FALSE; + console_info.HistoryBufferSize = 50; + console_info.NumberOfHistoryBuffers = 4; + + console_info.CodePage = GetConsoleOutputCP(); + + RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Console"), 0, + KEY_QUERY_VALUE, ®hnd); + + len = sizeof(DWORD); + + /* Default color table */ + + for (i = 0; i < 16; i++) + { + char tname[13]; + + sprintf(tname, "ColorTable%02d", i); + RegQueryValueExA(reghnd, tname, NULL, NULL, + (LPBYTE)(&(console_info.ColorTable[i])), &len); + } + + /* Font info */ + + RegQueryValueEx(reghnd, TEXT("FontSize"), NULL, NULL, + (LPBYTE)(&console_info.FontSize), &len); + RegQueryValueEx(reghnd, TEXT("FontFamily"), NULL, NULL, + (LPBYTE)(&console_info.FontFamily), &len); + RegQueryValueEx(reghnd, TEXT("FontWeight"), NULL, NULL, + (LPBYTE)(&console_info.FontWeight), &len); + + len = sizeof(WCHAR) * 32; + RegQueryValueExW(reghnd, L"FaceName", NULL, NULL, + (LPBYTE)(console_info.FaceName), &len); + + RegCloseKey(reghnd); +} + +static int _init_console_infoex(void) +{ + console_infoex.cbSize = sizeof(console_infoex); + + if (!pGetConsoleScreenBufferInfoEx(pdc_con_out, &console_infoex)) + return ERR; + + console_infoex.srWindow.Right++; + console_infoex.srWindow.Bottom++; + + return OK; +} + +static COLORREF *_get_colors(void) +{ + if (pGetConsoleScreenBufferInfoEx) + { + int status = OK; + if (!console_infoex.cbSize) + status = _init_console_infoex(); + return (status == ERR) ? NULL : + (COLORREF *)(&(console_infoex.ColorTable)); + } + else + { + if (!console_info.Hwnd) + _init_console_info(); + return (COLORREF *)(&(console_info.ColorTable)); + } +} + +/* restore the original console buffer in the event of a crash */ + +static LONG WINAPI _restore_console(LPEXCEPTION_POINTERS ep) +{ + PDC_scr_close(); + + return EXCEPTION_CONTINUE_SEARCH; +} + +/* restore the original console buffer on Ctrl+Break (or Ctrl+C, + if it gets re-enabled) */ + +static BOOL WINAPI _ctrl_break(DWORD dwCtrlType) +{ + if (dwCtrlType == CTRL_BREAK_EVENT || dwCtrlType == CTRL_C_EVENT) + PDC_scr_close(); + + return FALSE; +} + +/* close the physical screen -- may restore the screen to its state + before PDC_scr_open(); miscellaneous cleanup */ + +void PDC_scr_close(void) +{ + PDC_LOG(("PDC_scr_close() - called\n")); + + if (SP->visibility != 1) + curs_set(1); + + PDC_reset_shell_mode(); + + /* Position cursor to the bottom left of the screen. */ + + if (SP->_restore == PDC_RESTORE_NONE) + { + SMALL_RECT win; + + win.Left = orig_scr.srWindow.Left; + win.Right = orig_scr.srWindow.Right; + win.Top = 0; + win.Bottom = orig_scr.srWindow.Bottom - orig_scr.srWindow.Top; + SetConsoleWindowInfo(pdc_con_out, TRUE, &win); + PDC_gotoyx(win.Bottom, 0); + } +} + +void PDC_scr_free(void) +{ + if (SP) + free(SP); + if (pdc_atrtab) + free(pdc_atrtab); + + pdc_atrtab = (WORD *)NULL; + + if (pdc_con_out != std_con_out) + { + CloseHandle(pdc_con_out); + pdc_con_out = std_con_out; + } + + SetUnhandledExceptionFilter(xcpt_filter); + SetConsoleCtrlHandler(_ctrl_break, FALSE); +} + +/* open the physical screen -- allocate SP, miscellaneous intialization, + and may save the existing screen for later restoration */ + +int PDC_scr_open(int argc, char **argv) +{ + const char *str; + CONSOLE_SCREEN_BUFFER_INFO csbi; + HMODULE h_kernel; + BOOL result; + int i; + + PDC_LOG(("PDC_scr_open() - called\n")); + + SP = calloc(1, sizeof(SCREEN)); + pdc_atrtab = calloc(PDC_COLOR_PAIRS * PDC_OFFSET, sizeof(WORD)); + + if (!SP || !pdc_atrtab) + return ERR; + + for (i = 0; i < 16; i++) + curstoreal[realtocurs[i]] = i; + + std_con_out = + pdc_con_out = GetStdHandle(STD_OUTPUT_HANDLE); + pdc_con_in = GetStdHandle(STD_INPUT_HANDLE); + + if (GetFileType(pdc_con_in) != FILE_TYPE_CHAR) + { + fprintf(stderr, "\nRedirection is not supported.\n"); + exit(1); + } + + is_nt = !(GetVersion() & 0x80000000); + + GetConsoleScreenBufferInfo(pdc_con_out, &csbi); + GetConsoleScreenBufferInfo(pdc_con_out, &orig_scr); + GetConsoleMode(pdc_con_in, &old_console_mode); + + /* preserve QuickEdit Mode setting for use in PDC_mouse_set() when + the mouse is not enabled -- other console input settings are + cleared */ + + pdc_quick_edit = old_console_mode & 0x0040; + + SP->lines = (str = getenv("LINES")) ? atoi(str) : PDC_get_rows(); + SP->cols = (str = getenv("COLS")) ? atoi(str) : PDC_get_columns(); + + SP->mouse_wait = PDC_CLICK_PERIOD; + SP->audible = TRUE; + + SP->termattrs = A_COLOR; + + if (SP->lines < 2 || SP->lines > csbi.dwMaximumWindowSize.Y) + { + fprintf(stderr, "LINES value must be >= 2 and <= %d: got %d\n", + csbi.dwMaximumWindowSize.Y, SP->lines); + + return ERR; + } + + if (SP->cols < 2 || SP->cols > csbi.dwMaximumWindowSize.X) + { + fprintf(stderr, "COLS value must be >= 2 and <= %d: got %d\n", + csbi.dwMaximumWindowSize.X, SP->cols); + + return ERR; + } + + SP->orig_fore = csbi.wAttributes & 0x0f; + SP->orig_back = (csbi.wAttributes & 0xf0) >> 4; + + SP->orig_attr = TRUE; + + SP->_restore = PDC_RESTORE_NONE; + + if ((str = getenv("PDC_RESTORE_SCREEN")) == NULL || *str != '0') + { + /* Create a new console buffer */ + + pdc_con_out = + CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, CONSOLE_TEXTMODE_BUFFER, NULL); + + if (pdc_con_out == INVALID_HANDLE_VALUE) + { + PDC_LOG(("PDC_scr_open() - screen buffer failure\n")); + + pdc_con_out = std_con_out; + } + else + SP->_restore = PDC_RESTORE_BUFFER; + } + + xcpt_filter = SetUnhandledExceptionFilter(_restore_console); + SetConsoleCtrlHandler(_ctrl_break, TRUE); + + SP->_preserve = (getenv("PDC_PRESERVE_SCREEN") != NULL); + + /* ENABLE_LVB_GRID_WORLDWIDE */ + result = SetConsoleMode(pdc_con_out, 0x0010); + if (result) + SP->termattrs |= A_UNDERLINE | A_LEFT | A_RIGHT | A_REVERSE; + + PDC_reset_prog_mode(); + + SP->mono = FALSE; + + h_kernel = GetModuleHandleA("kernel32.dll"); + pGetConsoleScreenBufferInfoEx = + (GetConsoleScreenBufferInfoExFn)GetProcAddress(h_kernel, + "GetConsoleScreenBufferInfoEx"); + pSetConsoleScreenBufferInfoEx = + (SetConsoleScreenBufferInfoExFn)GetProcAddress(h_kernel, + "SetConsoleScreenBufferInfoEx"); + + return OK; +} + + /* Calls SetConsoleWindowInfo with the given parameters, but fits them + if a scoll bar shrinks the maximum possible value. The rectangle + must at least fit in a half-sized window. */ + +static BOOL _fit_console_window(HANDLE con_out, CONST SMALL_RECT *rect) +{ + SMALL_RECT run; + SHORT mx, my; + + if (SetConsoleWindowInfo(con_out, TRUE, rect)) + return TRUE; + + run = *rect; + run.Right /= 2; + run.Bottom /= 2; + + mx = run.Right; + my = run.Bottom; + + if (!SetConsoleWindowInfo(con_out, TRUE, &run)) + return FALSE; + + for (run.Right = rect->Right; run.Right >= mx; run.Right--) + if (SetConsoleWindowInfo(con_out, TRUE, &run)) + break; + + if (run.Right < mx) + return FALSE; + + for (run.Bottom = rect->Bottom; run.Bottom >= my; run.Bottom--) + if (SetConsoleWindowInfo(con_out, TRUE, &run)) + return TRUE; + + return FALSE; +} + +/* the core of resize_term() */ + +int PDC_resize_screen(int nlines, int ncols) +{ + SMALL_RECT rect; + COORD size, max; + + if (nlines || ncols) + { + if (nlines < 2 || ncols < 2) + return ERR; + + max = GetLargestConsoleWindowSize(pdc_con_out); + + rect.Left = rect.Top = 0; + rect.Right = ncols - 1; + + if (rect.Right > max.X) + rect.Right = max.X; + + rect.Bottom = nlines - 1; + + if (rect.Bottom > max.Y) + rect.Bottom = max.Y; + + size.X = rect.Right + 1; + size.Y = rect.Bottom + 1; + + _fit_console_window(pdc_con_out, &rect); + SetConsoleScreenBufferSize(pdc_con_out, size); + _fit_console_window(pdc_con_out, &rect); + SetConsoleScreenBufferSize(pdc_con_out, size); + SetConsoleActiveScreenBuffer(pdc_con_out); + } + + PDC_flushinp(); + + SP->resized = FALSE; + SP->cursrow = SP->curscol = 0; + + return OK; +} + +void PDC_reset_prog_mode(void) +{ + PDC_LOG(("PDC_reset_prog_mode() - called.\n")); + + if (pdc_con_out != std_con_out) + SetConsoleActiveScreenBuffer(pdc_con_out); + else if (is_nt) + { + COORD bufsize; + SMALL_RECT rect; + + bufsize.X = orig_scr.srWindow.Right - orig_scr.srWindow.Left + 1; + bufsize.Y = orig_scr.srWindow.Bottom - orig_scr.srWindow.Top + 1; + + rect.Top = rect.Left = 0; + rect.Bottom = bufsize.Y - 1; + rect.Right = bufsize.X - 1; + + SetConsoleScreenBufferSize(pdc_con_out, bufsize); + SetConsoleWindowInfo(pdc_con_out, TRUE, &rect); + SetConsoleScreenBufferSize(pdc_con_out, bufsize); + SetConsoleActiveScreenBuffer(pdc_con_out); + } + + PDC_mouse_set(); +} + +void PDC_reset_shell_mode(void) +{ + PDC_LOG(("PDC_reset_shell_mode() - called.\n")); + + if (pdc_con_out != std_con_out) + SetConsoleActiveScreenBuffer(std_con_out); + else if (is_nt) + { + SetConsoleScreenBufferSize(pdc_con_out, orig_scr.dwSize); + SetConsoleWindowInfo(pdc_con_out, TRUE, &orig_scr.srWindow); + SetConsoleScreenBufferSize(pdc_con_out, orig_scr.dwSize); + SetConsoleWindowInfo(pdc_con_out, TRUE, &orig_scr.srWindow); + SetConsoleActiveScreenBuffer(pdc_con_out); + } + + SetConsoleMode(pdc_con_in, old_console_mode); +} + +void PDC_restore_screen_mode(int i) +{ +} + +void PDC_save_screen_mode(int i) +{ +} + +void PDC_init_pair(short pair, short fg, short bg) +{ + WORD att; + chtype i; + + fg = curstoreal[fg]; + bg = curstoreal[bg]; + + for (i = 0; i < PDC_OFFSET; i++) + { + short f = fg, b = bg; + + if (i & (A_BOLD >> PDC_ATTR_SHIFT)) + f |= 8; + if (i & (A_BLINK >> PDC_ATTR_SHIFT)) + b |= 8; + + if (i & (A_REVERSE >> PDC_ATTR_SHIFT)) + att = b | (f << 4); + else + att = f | (b << 4); + + if (i & (A_UNDERLINE >> PDC_ATTR_SHIFT)) + att |= COMMON_LVB_UNDERSCORE; + if (i & (A_LEFT >> PDC_ATTR_SHIFT)) + att |= COMMON_LVB_GRID_LVERTICAL; + if (i & (A_RIGHT >> PDC_ATTR_SHIFT)) + att |= COMMON_LVB_GRID_RVERTICAL; + + pdc_atrtab[pair * PDC_OFFSET + i] = att; + } +} + +int PDC_pair_content(short pair, short *fg, short *bg) +{ + *fg = realtocurs[pdc_atrtab[pair * PDC_OFFSET] & 0x0F]; + *bg = realtocurs[(pdc_atrtab[pair * PDC_OFFSET] & 0xF0) >> 4]; + + return OK; +} + +bool PDC_can_change_color(void) +{ + return is_nt; +} + +int PDC_color_content(short color, short *red, short *green, short *blue) +{ + COLORREF *color_table = _get_colors(); + + if (color_table) + { + DWORD col = color_table[curstoreal[color]]; + + *red = DIVROUND(GetRValue(col) * 1000, 255); + *green = DIVROUND(GetGValue(col) * 1000, 255); + *blue = DIVROUND(GetBValue(col) * 1000, 255); + + return OK; + } + + return ERR; +} + +int PDC_init_color(short color, short red, short green, short blue) +{ + COLORREF *color_table = _get_colors(); + + if (color_table) + { + color_table[curstoreal[color]] = + RGB(DIVROUND(red * 255, 1000), + DIVROUND(green * 255, 1000), + DIVROUND(blue * 255, 1000)); + + return _set_colors(); + } + + return ERR; +} diff --git a/modules/ncurses/pdcurses/wincon/pdcsetsc.c b/modules/ncurses/pdcurses/wincon/pdcsetsc.c new file mode 100644 index 00000000..66cc13d7 --- /dev/null +++ b/modules/ncurses/pdcurses/wincon/pdcsetsc.c @@ -0,0 +1,117 @@ +/* Public Domain Curses */ + +#include "pdcwin.h" + +/*man-start************************************************************** + +pdcsetsc +-------- + +### Synopsis + + int PDC_set_blink(bool blinkon); + int PDC_set_bold(bool boldon); + void PDC_set_title(const char *title); + +### Description + + PDC_set_blink() toggles whether the A_BLINK attribute sets an + actual blink mode (TRUE), or sets the background color to high + intensity (FALSE). The default is platform-dependent (FALSE in + most cases). It returns OK if it could set the state to match + the given parameter, ERR otherwise. + + PDC_set_bold() toggles whether the A_BOLD attribute selects an actual + bold font (TRUE), or sets the foreground color to high intensity + (FALSE). It returns OK if it could set the state to match the given + parameter, ERR otherwise. + + PDC_set_title() sets the title of the window in which the curses + program is running. This function may not do anything on some + platforms. + +### Portability + X/Open BSD SYS V + PDC_set_blink - - - + PDC_set_title - - - + +**man-end****************************************************************/ + +int PDC_curs_set(int visibility) +{ + CONSOLE_CURSOR_INFO cci; + int ret_vis; + + PDC_LOG(("PDC_curs_set() - called: visibility=%d\n", visibility)); + + ret_vis = SP->visibility; + + if (GetConsoleCursorInfo(pdc_con_out, &cci) == FALSE) + return ERR; + + switch(visibility) + { + case 0: /* invisible */ + cci.bVisible = FALSE; + break; + case 2: /* highly visible */ + cci.bVisible = TRUE; + cci.dwSize = 95; + break; + default: /* normal visibility */ + cci.bVisible = TRUE; + cci.dwSize = SP->orig_cursor; + break; + } + + if (SetConsoleCursorInfo(pdc_con_out, &cci) == FALSE) + return ERR; + + SP->visibility = visibility; + return ret_vis; +} + +void PDC_set_title(const char *title) +{ +#ifdef PDC_WIDE + wchar_t wtitle[512]; +#endif + PDC_LOG(("PDC_set_title() - called:<%s>\n", title)); + +#ifdef PDC_WIDE + PDC_mbstowcs(wtitle, title, 511); + SetConsoleTitleW(wtitle); +#else + SetConsoleTitleA(title); +#endif +} + +int PDC_set_blink(bool blinkon) +{ + if (pdc_color_started) + COLORS = 16; + + if (blinkon) + { + if (!(SP->termattrs & A_BLINK)) + { + SP->termattrs |= A_BLINK; + pdc_last_blink = GetTickCount(); + } + } + else + { + if (SP->termattrs & A_BLINK) + { + SP->termattrs &= ~A_BLINK; + PDC_blink_text(); + } + } + + return OK; +} + +int PDC_set_bold(bool boldon) +{ + return boldon ? ERR : OK; +} diff --git a/modules/ncurses/pdcurses/wincon/pdcurses.ico b/modules/ncurses/pdcurses/wincon/pdcurses.ico new file mode 100644 index 0000000000000000000000000000000000000000..53a6dde3c94615729ec2657a6bd871c98b6da449 GIT binary patch literal 1078 zcmeHGy$-=(6g|Z(O+0{3V)p{x!(g!KU@%&~uy_Q6FqsUUj7>g~h{4a`0gROxE$DEa ztJLBJgxj8b&UepE(=?}mgA6>+h1M|xl*q1|oXZZ7&jMx6JfccC$gu;4yPwO@q+?7% z?3A$9lGTvM4G~oYFCA(7*H3=|W+1I?YZ%P}zZM3kI1C0+7 literal 0 HcmV?d00001 diff --git a/modules/ncurses/pdcurses/wincon/pdcurses.rc b/modules/ncurses/pdcurses/wincon/pdcurses.rc new file mode 100644 index 00000000..53ec6ab5 --- /dev/null +++ b/modules/ncurses/pdcurses/wincon/pdcurses.rc @@ -0,0 +1,28 @@ +#include "winver.h" + +1 VERSIONINFO + FILEVERSION 3,5,0,0 + PRODUCTVERSION 3,5,0,0 + FILEFLAGSMASK 0x3fL + FILEFLAGS 0x0L + FILEOS VOS_UNKNOWN + FILETYPE VFT_DLL + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "Maintainer", "William McBrine\0" + VALUE "FileDescription", "Public Domain Curses\0" + VALUE "FileVersion", "3.5.0\0" + VALUE "InternalName", "PDCurses\0" + VALUE "LegalCopyright", "Public Domain\0" + VALUE "OriginalFilename", "PDCURSES.DLL\0" + VALUE "ProductName", "Public Domain Curses Library\0" + VALUE "ProductVersion", "3.5.0\0" + END + END +END + +1 ICON DISCARDABLE "PDCURSES.ico" diff --git a/modules/ncurses/pdcurses/wincon/pdcutil.c b/modules/ncurses/pdcurses/wincon/pdcutil.c new file mode 100644 index 00000000..5da99029 --- /dev/null +++ b/modules/ncurses/pdcurses/wincon/pdcutil.c @@ -0,0 +1,26 @@ +/* Public Domain Curses */ + +#include "pdcwin.h" + +void PDC_beep(void) +{ + PDC_LOG(("PDC_beep() - called\n")); + +/* MessageBeep(MB_OK); */ + MessageBeep(0XFFFFFFFF); +} + +void PDC_napms(int ms) +{ + PDC_LOG(("PDC_napms() - called: ms=%d\n", ms)); + + if ((SP->termattrs & A_BLINK) && (GetTickCount() >= pdc_last_blink + 500)) + PDC_blink_text(); + + Sleep(ms); +} + +const char *PDC_sysname(void) +{ + return "Windows"; +} diff --git a/modules/ncurses/pdcurses/wincon/pdcwin.h b/modules/ncurses/pdcurses/wincon/pdcwin.h new file mode 100644 index 00000000..3496cafe --- /dev/null +++ b/modules/ncurses/pdcurses/wincon/pdcwin.h @@ -0,0 +1,28 @@ +/* Public Domain Curses */ + +#if defined(PDC_WIDE) && !defined(UNICODE) +# define UNICODE +#endif + +#define WIN32_LEAN_AND_MEAN +#include +#undef MOUSE_MOVED +#include + +#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) +# define _CRT_SECURE_NO_DEPRECATE 1 /* kill nonsense warnings */ +#endif + +#ifdef CHTYPE_LONG +# define PDC_ATTR_SHIFT 17 +#else +# define PDC_ATTR_SHIFT 8 +#endif + +extern WORD *pdc_atrtab; +extern HANDLE pdc_con_out, pdc_con_in; +extern DWORD pdc_quick_edit; +extern DWORD pdc_last_blink; + +extern int PDC_get_buffer_rows(void); +extern void PDC_blink_text(void); diff --git a/modules/ncurses/tests/test01.wx b/modules/ncurses/tests/test01.wx new file mode 100644 index 00000000..ea01a125 --- /dev/null +++ b/modules/ncurses/tests/test01.wx @@ -0,0 +1,85 @@ +#Import "" +Using ncurses.. + +Function Main() + + Local mainwin:Window + Local childwin:Window + Local ch:Int + + + '/* Set the dimensions and initial + ' position for our child window */ + + Local width:Int = 23 + Local height:Int = 7 + Local rows:Int = 25 + Local cols:Int = 80 + Local x:Int = (cols - width) / 2 + Local y:Int = (rows - height) / 2 + + + '/* Initialize ncurses */ + mainwin=initscr() + If Not mainwin + Print("Error initialising ncurses") + Return + Endif + + '/* Switch of echoing and enable keypad (for arrow keys) */ + + noecho() + keypad(mainwin, True) + + + '/* Make our child window, and add + ' a border and some text to it. */ + + childwin = subwin(mainwin, height, width, y, x) + box(childwin, 0, 0) + mvwaddstr(childwin, 1, 4, "Move the window") + mvwaddstr(childwin, 2, 2, "with the arrow keys") + mvwaddstr(childwin, 3, 6, "or HOME/END") + mvwaddstr(childwin, 5, 3, "Press 'q' to quit") + + 'refresh() + + '/* Loop until user hits 'q' to quit */ + + While ch<>"q"[0] + ch=getch() + + Select ch + Case KEY_UP + If y>0 Then y-=1 + + Case KEY_DOWN + If y0 x-=1 + + Case KEY_RIGHT + If x" +Using ncurses.. + +Function Main() + + initscr() + nodelay( stdscr, True ) + noecho() + + curs_set(0) + start_color() +' assume_default_colors(8,-1) +' use_default_colors() + + + + Local w:=newwin(10,32,4,(COLS-32)/2) + 'Local p:=init_pair(1, COLOR_GREEN, COLOR_BLACK) + + init_pair(1, COLOR_RED, COLOR_BLACK) + init_pair(2, COLOR_GREEN, COLOR_BLACK) + init_pair(3, COLOR_CYAN, COLOR_BLACK) + + wattron(w,COLOR_PAIR(0)) + + Local oldmask:mmask_t + Local newmask:=mousemask(ALL_MOUSE_EVENTS, Varptr oldmask) + + box(w,0,0) + wattron(w,COLOR_PAIR(1)) + mvwprintw(w,1,2,"has_colors="+(has_colors()?"True"Else"false")) + wattroff(w,COLOR_PAIR(1)) + mvwprintw(w,2,2,"can_change_colors="+(can_change_color()?"True"Else"false")) + wattron(w,A_BOLD) + mvwprintw(w,4,2,"("+LINES+","+COLS+")") + wattroff(w,A_BOLD) + mvwprintw(w,8,2,"Escape/Q To Quit") + + mvwprintw(w,6,2,"press a key") + mvwprintw(w,5,2,"click the mouse") + + wrefresh(w) + + keypad(w,True) + + Local e:MouseEvent + + While True + Local key:=wgetch(w) + wattron(w, COLOR_PAIR(2) ) + mvwprintw(w,6,2,"key="+key+" ") + wattroff(w, COLOR_PAIR(2) ) + If key=27 exit + If key=113 exit + #rem + If key=KEY_MOUSE + Local r:=getmouse(Varptr e) + If r=OK + Local bits:Int'=e.bstate + wattron(w, COLOR_PAIR(3) ) + mvwprintw(w,5,2,"mouse="+e.id+","+e.x+","+e.y+","+e.z+","+bits) + wattroff(w, COLOR_PAIR(3) ) + Endif + Endif + #end + Wend + + endwin() +End