From 51ffecc181005cb45a40108612ee28d1daaeeb86 Mon Sep 17 00:00:00 2001 From: Ben Gras Date: Thu, 21 Jul 2011 16:29:08 +0200 Subject: [PATCH] import elf-only -lcurses . abandons mixer, gomoku, talk, talkd, top from base system . compile top with clang so no ack-compiled program needs -lcurses any more --- commands/Makefile | 10 +- commands/gomoku/Makefile | 7 - commands/gomoku/gomoku.c | 739 ---------- commands/life/Makefile | 7 - commands/life/life.c | 241 ---- commands/mixer/Makefile | 7 - commands/mixer/mixer.c | 658 --------- commands/talk/Makefile | 13 - commands/talk/net.c | 264 ---- commands/talk/net.h | 15 - commands/talk/proto.c | 142 -- commands/talk/proto.h | 3 - commands/talk/screen.c | 208 --- commands/talk/screen.h | 13 - commands/talk/talk.c | 242 ---- commands/talk/talk.h | 57 - commands/talkd/Makefile | 10 - commands/talkd/finduser.c | 48 - commands/talkd/finduser.h | 3 - commands/talkd/net.c | 188 --- commands/talkd/net.h | 5 - commands/talkd/process.c | 269 ---- commands/talkd/process.h | 3 - commands/talkd/talk.h | 57 - commands/talkd/talkd.c | 54 - commands/talkd/talkd.h | 4 - commands/top/Makefile | 7 - common/include/Makefile.inc | 2 +- common/include/curses.h | 226 --- etc/mtree/minix.tree | 3 + include/Makefile | 2 +- lib/Makefile | 4 +- lib/libcurses/EXAMPLES/Makefile | 54 + lib/libcurses/EXAMPLES/ex1.c | 342 +++++ lib/libcurses/EXAMPLES/view.c | 527 +++++++ lib/libcurses/Makefile | 227 ++- lib/libcurses/PSD.doc/Makefile | 40 + lib/libcurses/PSD.doc/Master | 52 + lib/libcurses/PSD.doc/appen.A | 77 + lib/libcurses/PSD.doc/appen.B | 199 +++ lib/libcurses/PSD.doc/appen.C | 126 ++ lib/libcurses/PSD.doc/c_macros | 68 + lib/libcurses/PSD.doc/doc.I | 347 +++++ lib/libcurses/PSD.doc/doc.II | 140 ++ lib/libcurses/PSD.doc/doc.III | 341 +++++ lib/libcurses/PSD.doc/doc.IV | 108 ++ lib/libcurses/PSD.doc/ex1.c | 100 ++ lib/libcurses/PSD.doc/ex2.c | 208 +++ lib/libcurses/PSD.doc/fns.doc | 1757 +++++++++++++++++++++++ lib/libcurses/PSD.doc/intro.0 | 104 ++ lib/libcurses/PSD.doc/intro.1 | 247 ++++ lib/libcurses/PSD.doc/intro.2 | 82 ++ lib/libcurses/PSD.doc/intro.3 | 228 +++ lib/libcurses/PSD.doc/intro.4 | 67 + lib/libcurses/PSD.doc/intro.5 | 90 ++ lib/libcurses/PSD.doc/intro.6 | 44 + lib/libcurses/PSD.doc/life.c | 161 +++ lib/libcurses/PSD.doc/macros | 143 ++ lib/libcurses/PSD.doc/twinkle1.c | 161 +++ lib/libcurses/PSD.doc/twinkle2.c | 207 +++ lib/libcurses/PSD.doc/win_st.c | 56 + lib/libcurses/acs.c | 309 ++++ lib/libcurses/add_wch.c | 124 ++ lib/libcurses/add_wchstr.c | 338 +++++ lib/libcurses/addbytes.c | 586 ++++++++ lib/libcurses/addch.c | 128 ++ lib/libcurses/addchnstr.c | 175 +++ lib/libcurses/addnstr.c | 155 ++ lib/libcurses/addwstr.c | 201 +++ lib/libcurses/attributes.c | 449 ++++++ lib/libcurses/background.c | 285 ++++ lib/libcurses/beep.c | 13 - lib/libcurses/bell.c | 80 ++ lib/libcurses/border.c | 606 ++++++++ lib/libcurses/box.c | 62 + lib/libcurses/cchar.c | 138 ++ lib/libcurses/charpick.c | 39 - lib/libcurses/chgat.c | 93 ++ lib/libcurses/clear.c | 70 + lib/libcurses/clearok.c | 52 + lib/libcurses/clrtobot.c | 115 ++ lib/libcurses/clrtoeol.c | 118 ++ lib/libcurses/color.c | 687 +++++++++ lib/libcurses/copywin.c | 135 ++ lib/libcurses/cr_put.c | 480 +++++++ lib/libcurses/ctrace.c | 120 ++ lib/libcurses/cur_hash.c | 65 + lib/libcurses/curs_set.c | 122 +- lib/libcurses/curses.3 | 338 +++++ lib/libcurses/curses.c | 160 +++ lib/libcurses/curses.h | 933 ++++++++++++ lib/libcurses/curses_addch.3 | 187 +++ lib/libcurses/curses_addchstr.3 | 155 ++ lib/libcurses/curses_addstr.3 | 159 +++ lib/libcurses/curses_attributes.3 | 342 +++++ lib/libcurses/curses_background.3 | 124 ++ lib/libcurses/curses_border.3 | 159 +++ lib/libcurses/curses_chgat.3 | 119 ++ lib/libcurses/curses_clear.3 | 141 ++ lib/libcurses/curses_color.3 | 232 +++ lib/libcurses/curses_cursor.3 | 223 +++ lib/libcurses/curses_default_colors.3 | 73 + lib/libcurses/curses_delch.3 | 90 ++ lib/libcurses/curses_deleteln.3 | 110 ++ lib/libcurses/curses_echochar.3 | 123 ++ lib/libcurses/curses_fileio.3 | 93 ++ lib/libcurses/curses_inch.3 | 257 ++++ lib/libcurses/curses_input.3 | 584 ++++++++ lib/libcurses/curses_insdelln.3 | 115 ++ lib/libcurses/curses_insertch.3 | 113 ++ lib/libcurses/curses_insertln.3 | 109 ++ lib/libcurses/curses_keyname.3 | 72 + lib/libcurses/curses_line.3 | 171 +++ lib/libcurses/curses_pad.3 | 142 ++ lib/libcurses/curses_print.3 | 124 ++ lib/libcurses/curses_private.h | 360 +++++ lib/libcurses/curses_refresh.3 | 157 +++ lib/libcurses/curses_scanw.3 | 114 ++ lib/libcurses/curses_screen.3 | 204 +++ lib/libcurses/curses_scroll.3 | 169 +++ lib/libcurses/curses_standout.3 | 104 ++ lib/libcurses/curses_termcap.3 | 103 ++ lib/libcurses/curses_touch.3 | 199 +++ lib/libcurses/curses_tty.3 | 360 +++++ lib/libcurses/curses_underscore.3 | 100 ++ lib/libcurses/curses_window.3 | 259 ++++ lib/libcurses/cursesio.c | 223 --- lib/libcurses/curspriv.h | 36 - lib/libcurses/delch.c | 147 ++ lib/libcurses/deleteln.c | 65 + lib/libcurses/delwin.c | 113 ++ lib/libcurses/echo_wchar.c | 97 ++ lib/libcurses/echochar.c | 83 ++ lib/libcurses/endwin.c | 18 - lib/libcurses/erase.c | 107 ++ lib/libcurses/fileio.c | 249 ++++ lib/libcurses/fileio.h | 8 + lib/libcurses/flash.c | 14 - lib/libcurses/flushok.c | 52 + lib/libcurses/fullname.c | 64 + lib/libcurses/genfileioh.awk | 66 + lib/libcurses/get_wch.c | 658 +++++++++ lib/libcurses/get_wstr.c | 291 ++++ lib/libcurses/getch.c | 967 +++++++++++++ lib/libcurses/getstr.c | 251 ++++ lib/libcurses/getyx.c | 134 ++ lib/libcurses/id_subwins.c | 60 + lib/libcurses/idcok.c | 58 + lib/libcurses/idlok.c | 57 + lib/libcurses/in_wch.c | 119 ++ lib/libcurses/in_wchstr.c | 197 +++ lib/libcurses/inch.c | 94 ++ lib/libcurses/inchstr.c | 154 ++ lib/libcurses/initscr.c | 96 +- lib/libcurses/ins_wch.c | 253 ++++ lib/libcurses/ins_wstr.c | 333 +++++ lib/libcurses/insch.c | 131 ++ lib/libcurses/insdelln.c | 181 +++ lib/libcurses/insertln.c | 66 + lib/libcurses/insstr.c | 209 +++ lib/libcurses/instr.c | 168 +++ lib/libcurses/inwstr.c | 194 +++ lib/libcurses/keymap.h | 116 ++ lib/libcurses/keyname.c | 508 +++++++ lib/libcurses/keypad.c | 59 + lib/libcurses/leaveok.c | 52 + lib/libcurses/line.c | 305 ++++ lib/libcurses/longname.c | 92 +- lib/libcurses/meta.c | 77 + lib/libcurses/move.c | 98 +- lib/libcurses/mvcursor.c | 20 - lib/libcurses/mvwin.c | 103 ++ lib/libcurses/newwin.c | 530 +++++-- lib/libcurses/nodelay.c | 50 + lib/libcurses/notimeout.c | 51 + lib/libcurses/options.c | 84 -- lib/libcurses/overlay.c | 178 +-- lib/libcurses/overwrite.c | 60 + lib/libcurses/pause.c | 82 ++ lib/libcurses/printw.c | 152 ++ lib/libcurses/prntscan.c | 129 -- lib/libcurses/putchar.c | 97 ++ lib/libcurses/refresh.c | 1883 ++++++++++++++++++++++++- lib/libcurses/resize.c | 361 +++++ lib/libcurses/scanw.c | 125 ++ lib/libcurses/screen.c | 246 ++++ lib/libcurses/scroll.c | 158 +++ lib/libcurses/scrollok.c | 52 + lib/libcurses/scrreg.c | 58 - lib/libcurses/setterm.c | 404 +++++- lib/libcurses/shlib_version | 8 + lib/libcurses/standout.c | 94 ++ lib/libcurses/tabsize.c | 50 - lib/libcurses/termmisc.c | 63 - lib/libcurses/timeout.c | 76 + lib/libcurses/toucholap.c | 79 ++ lib/libcurses/touchwin.c | 237 ++++ lib/libcurses/tscroll.c | 253 ++++ lib/libcurses/tstp.c | 356 +++++ lib/libcurses/tty.c | 682 +++++++++ lib/libcurses/unctrl.c | 195 ++- lib/libcurses/unctrl.h | 58 + lib/libcurses/underscore.c | 98 ++ lib/libcurses/update.c | 170 --- lib/libcurses/waddch.c | 95 -- lib/libcurses/waddstr.c | 18 - lib/libcurses/wbox.c | 65 - lib/libcurses/wclear.c | 14 - lib/libcurses/wclrtobot.c | 35 - lib/libcurses/wclrtoeol.c | 36 - lib/libcurses/wdelch.c | 28 - lib/libcurses/wdeleteln.c | 28 - lib/libcurses/werase.c | 26 - lib/libcurses/wgetch.c | 26 - lib/libcurses/wgetstr.c | 22 - lib/libcurses/windel.c | 41 - lib/libcurses/winmove.c | 36 - lib/libcurses/winsch.c | 31 - lib/libcurses/winscrol.c | 55 - lib/libcurses/winsertln.c | 26 - lib/libcurses/wintouch.c | 40 - man/man1/Makefile | 2 +- man/man1/top.1 | 72 - man/man3/Makefile | 2 +- man/man3/curses.3 | 248 ---- share/mk/Makefile | 2 +- share/mk/bsd.doc.mk | 73 + tools/nbsd_ports | 1 + usr.bin/Makefile | 3 + usr.bin/Makefile.inc | 2 +- usr.bin/top/Makefile | 7 + {commands => usr.bin}/top/top.c | 15 +- 232 files changed, 32855 insertions(+), 5892 deletions(-) delete mode 100644 commands/gomoku/Makefile delete mode 100644 commands/gomoku/gomoku.c delete mode 100644 commands/life/Makefile delete mode 100644 commands/life/life.c delete mode 100644 commands/mixer/Makefile delete mode 100644 commands/mixer/mixer.c delete mode 100644 commands/talk/Makefile delete mode 100644 commands/talk/net.c delete mode 100644 commands/talk/net.h delete mode 100644 commands/talk/proto.c delete mode 100644 commands/talk/proto.h delete mode 100644 commands/talk/screen.c delete mode 100644 commands/talk/screen.h delete mode 100644 commands/talk/talk.c delete mode 100644 commands/talk/talk.h delete mode 100644 commands/talkd/Makefile delete mode 100644 commands/talkd/finduser.c delete mode 100644 commands/talkd/finduser.h delete mode 100644 commands/talkd/net.c delete mode 100644 commands/talkd/net.h delete mode 100644 commands/talkd/process.c delete mode 100644 commands/talkd/process.h delete mode 100644 commands/talkd/talk.h delete mode 100644 commands/talkd/talkd.c delete mode 100644 commands/talkd/talkd.h delete mode 100644 commands/top/Makefile delete mode 100644 common/include/curses.h create mode 100644 lib/libcurses/EXAMPLES/Makefile create mode 100644 lib/libcurses/EXAMPLES/ex1.c create mode 100644 lib/libcurses/EXAMPLES/view.c create mode 100644 lib/libcurses/PSD.doc/Makefile create mode 100644 lib/libcurses/PSD.doc/Master create mode 100644 lib/libcurses/PSD.doc/appen.A create mode 100644 lib/libcurses/PSD.doc/appen.B create mode 100644 lib/libcurses/PSD.doc/appen.C create mode 100644 lib/libcurses/PSD.doc/c_macros create mode 100644 lib/libcurses/PSD.doc/doc.I create mode 100644 lib/libcurses/PSD.doc/doc.II create mode 100644 lib/libcurses/PSD.doc/doc.III create mode 100644 lib/libcurses/PSD.doc/doc.IV create mode 100644 lib/libcurses/PSD.doc/ex1.c create mode 100644 lib/libcurses/PSD.doc/ex2.c create mode 100644 lib/libcurses/PSD.doc/fns.doc create mode 100644 lib/libcurses/PSD.doc/intro.0 create mode 100644 lib/libcurses/PSD.doc/intro.1 create mode 100644 lib/libcurses/PSD.doc/intro.2 create mode 100644 lib/libcurses/PSD.doc/intro.3 create mode 100644 lib/libcurses/PSD.doc/intro.4 create mode 100644 lib/libcurses/PSD.doc/intro.5 create mode 100644 lib/libcurses/PSD.doc/intro.6 create mode 100644 lib/libcurses/PSD.doc/life.c create mode 100644 lib/libcurses/PSD.doc/macros create mode 100644 lib/libcurses/PSD.doc/twinkle1.c create mode 100644 lib/libcurses/PSD.doc/twinkle2.c create mode 100644 lib/libcurses/PSD.doc/win_st.c create mode 100644 lib/libcurses/acs.c create mode 100644 lib/libcurses/add_wch.c create mode 100644 lib/libcurses/add_wchstr.c create mode 100644 lib/libcurses/addbytes.c create mode 100644 lib/libcurses/addch.c create mode 100644 lib/libcurses/addchnstr.c create mode 100644 lib/libcurses/addnstr.c create mode 100644 lib/libcurses/addwstr.c create mode 100644 lib/libcurses/attributes.c create mode 100644 lib/libcurses/background.c delete mode 100644 lib/libcurses/beep.c create mode 100644 lib/libcurses/bell.c create mode 100644 lib/libcurses/border.c create mode 100644 lib/libcurses/box.c create mode 100644 lib/libcurses/cchar.c delete mode 100644 lib/libcurses/charpick.c create mode 100644 lib/libcurses/chgat.c create mode 100644 lib/libcurses/clear.c create mode 100644 lib/libcurses/clearok.c create mode 100644 lib/libcurses/clrtobot.c create mode 100644 lib/libcurses/clrtoeol.c create mode 100644 lib/libcurses/color.c create mode 100644 lib/libcurses/copywin.c create mode 100644 lib/libcurses/cr_put.c create mode 100644 lib/libcurses/ctrace.c create mode 100644 lib/libcurses/cur_hash.c create mode 100644 lib/libcurses/curses.3 create mode 100644 lib/libcurses/curses.c create mode 100644 lib/libcurses/curses.h create mode 100644 lib/libcurses/curses_addch.3 create mode 100644 lib/libcurses/curses_addchstr.3 create mode 100644 lib/libcurses/curses_addstr.3 create mode 100644 lib/libcurses/curses_attributes.3 create mode 100644 lib/libcurses/curses_background.3 create mode 100644 lib/libcurses/curses_border.3 create mode 100644 lib/libcurses/curses_chgat.3 create mode 100644 lib/libcurses/curses_clear.3 create mode 100644 lib/libcurses/curses_color.3 create mode 100644 lib/libcurses/curses_cursor.3 create mode 100644 lib/libcurses/curses_default_colors.3 create mode 100644 lib/libcurses/curses_delch.3 create mode 100644 lib/libcurses/curses_deleteln.3 create mode 100644 lib/libcurses/curses_echochar.3 create mode 100644 lib/libcurses/curses_fileio.3 create mode 100644 lib/libcurses/curses_inch.3 create mode 100644 lib/libcurses/curses_input.3 create mode 100644 lib/libcurses/curses_insdelln.3 create mode 100644 lib/libcurses/curses_insertch.3 create mode 100644 lib/libcurses/curses_insertln.3 create mode 100644 lib/libcurses/curses_keyname.3 create mode 100644 lib/libcurses/curses_line.3 create mode 100644 lib/libcurses/curses_pad.3 create mode 100644 lib/libcurses/curses_print.3 create mode 100644 lib/libcurses/curses_private.h create mode 100644 lib/libcurses/curses_refresh.3 create mode 100644 lib/libcurses/curses_scanw.3 create mode 100644 lib/libcurses/curses_screen.3 create mode 100644 lib/libcurses/curses_scroll.3 create mode 100644 lib/libcurses/curses_standout.3 create mode 100644 lib/libcurses/curses_termcap.3 create mode 100644 lib/libcurses/curses_touch.3 create mode 100644 lib/libcurses/curses_tty.3 create mode 100644 lib/libcurses/curses_underscore.3 create mode 100644 lib/libcurses/curses_window.3 delete mode 100644 lib/libcurses/cursesio.c delete mode 100644 lib/libcurses/curspriv.h create mode 100644 lib/libcurses/delch.c create mode 100644 lib/libcurses/deleteln.c create mode 100644 lib/libcurses/delwin.c create mode 100644 lib/libcurses/echo_wchar.c create mode 100644 lib/libcurses/echochar.c delete mode 100644 lib/libcurses/endwin.c create mode 100644 lib/libcurses/erase.c create mode 100644 lib/libcurses/fileio.c create mode 100644 lib/libcurses/fileio.h delete mode 100644 lib/libcurses/flash.c create mode 100644 lib/libcurses/flushok.c create mode 100644 lib/libcurses/fullname.c create mode 100644 lib/libcurses/genfileioh.awk create mode 100644 lib/libcurses/get_wch.c create mode 100644 lib/libcurses/get_wstr.c create mode 100644 lib/libcurses/getch.c create mode 100644 lib/libcurses/getstr.c create mode 100644 lib/libcurses/getyx.c create mode 100644 lib/libcurses/id_subwins.c create mode 100644 lib/libcurses/idcok.c create mode 100644 lib/libcurses/idlok.c create mode 100644 lib/libcurses/in_wch.c create mode 100644 lib/libcurses/in_wchstr.c create mode 100644 lib/libcurses/inch.c create mode 100644 lib/libcurses/inchstr.c create mode 100644 lib/libcurses/ins_wch.c create mode 100644 lib/libcurses/ins_wstr.c create mode 100644 lib/libcurses/insch.c create mode 100644 lib/libcurses/insdelln.c create mode 100644 lib/libcurses/insertln.c create mode 100644 lib/libcurses/insstr.c create mode 100644 lib/libcurses/instr.c create mode 100644 lib/libcurses/inwstr.c create mode 100644 lib/libcurses/keymap.h create mode 100644 lib/libcurses/keyname.c create mode 100644 lib/libcurses/keypad.c create mode 100644 lib/libcurses/leaveok.c create mode 100644 lib/libcurses/line.c create mode 100644 lib/libcurses/meta.c delete mode 100644 lib/libcurses/mvcursor.c create mode 100644 lib/libcurses/mvwin.c create mode 100644 lib/libcurses/nodelay.c create mode 100644 lib/libcurses/notimeout.c delete mode 100644 lib/libcurses/options.c create mode 100644 lib/libcurses/overwrite.c create mode 100644 lib/libcurses/pause.c create mode 100644 lib/libcurses/printw.c delete mode 100644 lib/libcurses/prntscan.c create mode 100644 lib/libcurses/putchar.c create mode 100644 lib/libcurses/resize.c create mode 100644 lib/libcurses/scanw.c create mode 100644 lib/libcurses/screen.c create mode 100644 lib/libcurses/scroll.c create mode 100644 lib/libcurses/scrollok.c delete mode 100644 lib/libcurses/scrreg.c create mode 100644 lib/libcurses/shlib_version create mode 100644 lib/libcurses/standout.c delete mode 100644 lib/libcurses/tabsize.c delete mode 100644 lib/libcurses/termmisc.c create mode 100644 lib/libcurses/timeout.c create mode 100644 lib/libcurses/toucholap.c create mode 100644 lib/libcurses/touchwin.c create mode 100644 lib/libcurses/tscroll.c create mode 100644 lib/libcurses/tstp.c create mode 100644 lib/libcurses/tty.c create mode 100644 lib/libcurses/unctrl.h create mode 100644 lib/libcurses/underscore.c delete mode 100644 lib/libcurses/update.c delete mode 100644 lib/libcurses/waddch.c delete mode 100644 lib/libcurses/waddstr.c delete mode 100644 lib/libcurses/wbox.c delete mode 100644 lib/libcurses/wclear.c delete mode 100644 lib/libcurses/wclrtobot.c delete mode 100644 lib/libcurses/wclrtoeol.c delete mode 100644 lib/libcurses/wdelch.c delete mode 100644 lib/libcurses/wdeleteln.c delete mode 100644 lib/libcurses/werase.c delete mode 100644 lib/libcurses/wgetch.c delete mode 100644 lib/libcurses/wgetstr.c delete mode 100644 lib/libcurses/windel.c delete mode 100644 lib/libcurses/winmove.c delete mode 100644 lib/libcurses/winsch.c delete mode 100644 lib/libcurses/winscrol.c delete mode 100644 lib/libcurses/winsertln.c delete mode 100644 lib/libcurses/wintouch.c delete mode 100644 man/man1/top.1 delete mode 100644 man/man3/curses.3 create mode 100644 share/mk/bsd.doc.mk create mode 100644 usr.bin/top/Makefile rename {commands => usr.bin}/top/top.c (98%) diff --git a/commands/Makefile b/commands/Makefile index 268baa625..14adf8075 100644 --- a/commands/Makefile +++ b/commands/Makefile @@ -12,10 +12,10 @@ SUBDIR= aal add_route adduser advent arp ash at autil awk \ dhrystone diff dirname dis386 dis88 diskctl du dumpcore \ ed eject elle elvis env expand factor file \ find finger fingerd fix fold format fortune fsck.mfs \ - ftp101 ftpd200 gcov-pull getty grep gomoku head hexdump host \ + ftp101 ftpd200 gcov-pull getty grep head hexdump host \ hostaddr id ifconfig ifdef install \ intr ipcrm ipcs irdpd isoread join kill last leave \ - less lex life loadkeys loadramdisk logger login look lp \ + less lex loadkeys loadramdisk logger login look lp \ lpd ls lspci M mail make MAKEDEV man \ mdb mdocml mesg mined ackmkdep mkdir mkfifo mkfs.mfs mknod \ mkproto modem mount mt netconf newroot nice acknm nohup \ @@ -27,8 +27,8 @@ SUBDIR= aal add_route adduser advent arp ash at autil awk \ rotate rsh rshd sed service setup shar acksize \ sleep slip sort spell split srccrc ackstrip \ stty su sum svclog swapfs swifi sync synctree sysenv \ - syslogd tail talk talkd tar tcpd tcpdp tcpstat tee telnet \ - telnetd term termcap tget time tinyhalt top touch tr \ + syslogd tail tar tcpd tcpdp tcpstat tee telnet \ + telnetd term termcap tget time tinyhalt touch tr \ truncate tsort ttt tty udpstat umount uname unexpand \ unstack update uud uue version vol wc \ whereis which who write writeisofs fetch \ @@ -41,7 +41,7 @@ SUBDIR += elf2aout .if ${ARCH} == "i386" SUBDIR+= atnormalize dosread fdisk loadfont \ - mixer autopart part partition playwave postmort \ + autopart part partition playwave postmort \ recwave repartition screendump padtext SUBDIR+= acd asmconv gas2ack .endif diff --git a/commands/gomoku/Makefile b/commands/gomoku/Makefile deleted file mode 100644 index 71e41aafe..000000000 --- a/commands/gomoku/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -PROG= gomoku -MAN= - -DPADD+= ${LIBCURSES} -LDADD+= -lcurses - -.include diff --git a/commands/gomoku/gomoku.c b/commands/gomoku/gomoku.c deleted file mode 100644 index 3c2996eaf..000000000 --- a/commands/gomoku/gomoku.c +++ /dev/null @@ -1,739 +0,0 @@ -/* gomoku - 5 in a row game Author: ? */ - -/* This program plays a very old Japanese game called GO-MOKU, - perhaps better known as 5-in-line. The game is played on - a board with 19 x 19 squares, and the object of the game is - to get 5 stones in a row. -*/ - -#include -#include -#include -#include -#include - -/* Size of the board */ -#define SIZE 19 - -/* Importance of attack (1..16) */ -#define AttackFactor 4 - -/* Value of having 0, 1,2,3,4 or 5 pieces in line */ -int Weight[7] = {0, 0, 4, 20, 100, 500, 0}; - -#define Null 0 -#define Horiz 1 -#define DownLeft 2 -#define DownRight 3 -#define Vert 4 - -/* The two players */ -#define Empty 0 -#define Cross 1 -#define Nought 2 - -char PieceChar[Nought + 1] = {' ', 'X', '0'}; - -int Board[SIZE + 1][SIZE + 1];/* The board */ -int Player; /* The player whose move is next */ -int TotalLines; /* The number of Empty lines left */ -int GameWon; /* Set if one of the players has won */ - -int Line[4][SIZE + 1][SIZE + 1][Nought + 1]; - -/* Value of each square for each player */ -int Value[SIZE + 1][SIZE + 1][Nought + 1]; - -int X, Y; /* Move coordinates */ -char Command; /* Command from keyboard */ -int AutoPlay = FALSE; /* The program plays against itself */ - -_PROTOTYPE(void Initialize, (void)); -_PROTOTYPE(int Abort, (char *s)); -_PROTOTYPE(void WriteLetters, (void)); -_PROTOTYPE(void WriteLine, (int j, int *s)); -_PROTOTYPE(void WriteBoard, (int N, int *Top, int *Middle, int *Bottom)); -_PROTOTYPE(void SetUpScreen, (void)); -_PROTOTYPE(void GotoSquare, (int x, int y)); -_PROTOTYPE(void PrintMove, (int Piece, int X, int Y)); -_PROTOTYPE(void ClearMove, (void)); -_PROTOTYPE(void PrintMsg, (char *Str)); -_PROTOTYPE(void ClearMsg, (void)); -_PROTOTYPE(void WriteCommand, (char *S)); -_PROTOTYPE(void ResetGame, (int FirstGame)); -_PROTOTYPE(int OpponentColor, (int Player)); -_PROTOTYPE(void BlinkRow, (int X, int Y, int Dx, int Dy, int Piece)); -_PROTOTYPE(void BlinkWinner, (int Piece, int X, int Y, int WinningLine)); -_PROTOTYPE(int Random, (int x)); -_PROTOTYPE(void Add, (int *Num)); -_PROTOTYPE(void Update, (int Lin[], int Valu[], int Opponent)); -_PROTOTYPE(void MakeMove, (int X, int Y)); -_PROTOTYPE(int GameOver, (void)); -_PROTOTYPE(void FindMove, (int *X, int *Y)); -_PROTOTYPE(char GetChar, (void)); -_PROTOTYPE(void ReadCommand, (int X, int Y, char *Command)); -_PROTOTYPE(void InterpretCommand, (int Command)); -_PROTOTYPE(void PlayerMove, (void)); -_PROTOTYPE(void ProgramMove, (void)); -_PROTOTYPE(int main, (void)); - -/* Set terminal to raw mode. */ -void Initialize() -{ - srand(getpid() + 13); /* Initialize the random seed with our pid */ - initscr(); - raw(); - noecho(); - clear(); -} - -/* Reset terminal and exit from the program. */ -int Abort(s) -char *s; -{ - move(LINES - 1, 0); - refresh(); - endwin(); - exit(0); -} - -/* Set up the screen ----------------------------------------------- */ - -/* Write the letters */ -void WriteLetters() -{ - int i; - - addch(' '); - addch(' '); - for (i = 1; i <= SIZE; i++) printw(" %c", 'A' + i - 1); - addch('\n'); -} - -/* Write one line of the board */ -void WriteLine(j, s) -int j; -int *s; -{ - int i; - - printw("%2d ", j); - addch(s[0]); - for (i = 2; i <= SIZE - 1; i++) { - addch(s[1]); - addch(s[2]); - } - addch(s[1]); - addch(s[3]); - printw(" %-2d\n", j); -} - -/* Print the Empty board and the border */ -void WriteBoard(N, Top, Middle, Bottom) -int N; -int *Top, *Middle, *Bottom; -{ - int j; - - move(1, 0); - WriteLetters(); - WriteLine(N, Top); - for (j = N - 1; j >= 2; j--) WriteLine(j, Middle); - WriteLine(1, Bottom); - WriteLetters(); -} - -/* Sets up the screen with an Empty board */ -void SetUpScreen() -{ - int top[4], middle[4], bottom[4]; - - top[0] = ACS_ULCORNER; - top[1] = ACS_HLINE; - top[2] = ACS_TTEE; - top[3] = ACS_URCORNER; - - middle[0] = ACS_LTEE; - middle[1] = ACS_HLINE; - middle[2] = ACS_PLUS; - middle[3] = ACS_RTEE; - - bottom[0] = ACS_LLCORNER; - bottom[1] = ACS_HLINE; - bottom[2] = ACS_BTEE; - bottom[3] = ACS_LRCORNER; - - WriteBoard(SIZE, top, middle, bottom); -} - -/* Show moves ----------------------------------------------- */ - -void GotoSquare(x, y) -int x, y; -{ - move(SIZE + 2 - y, 1 + x * 2); -} - -/* Prints a move */ -void PrintMove(Piece, X, Y) -int Piece; -int X, Y; -{ - move(22, 49); - printw("%c %c %d", PieceChar[Piece], 'A' + X - 1, Y); - clrtoeol(); - GotoSquare(X, Y); - addch(PieceChar[Piece]); - GotoSquare(X, Y); - refresh(); -} - -/* Clears the line where a move is displayed */ -void ClearMove() -{ - move(22, 49); - clrtoeol(); -} - -/* Message handling ---------------------------------------------- */ - -/* Prints a message */ -void PrintMsg(Str) -char *Str; -{ - mvprintw(23, 1, "%s", Str); -} - -/* Clears the message about the winner */ -void ClearMsg() -{ - move(23, 1); - clrtoeol(); -} - -/* Highlights the first letter of S */ -void WriteCommand(S) -char *S; -{ - standout(); - addch(*S); - standend(); - printw("%s", S + 1); -} - -/* Display the board ----------------------------------------------- */ - -/* Resets global variables to start a new game */ -void ResetGame(FirstGame) -int FirstGame; -{ - int I, J; - int C, D; - - SetUpScreen(); - if (FirstGame) { - move(1, 49); - addstr("G O M O K U"); - move(3, 49); - WriteCommand("Newgame "); - WriteCommand("Quit "); - move(5, 49); - WriteCommand("Auto"); - move(7, 49); - WriteCommand("Play"); - move(9, 49); - WriteCommand("Hint"); - move(14, 60); - WriteCommand("Left, "); - WriteCommand("Right, "); - move(16, 60); - WriteCommand("Up, "); - WriteCommand("Down"); - move(18, 60); - standout(); - addstr("SPACE"); - move(20, 49); - WriteCommand(" NOTE: Use Num Lock & arrows"); - standend(); - mvaddstr(14, 49, "7 8 9"); - mvaddch(15, 52, ACS_UARROW); - mvaddch(16, 49, '4'); - addch(ACS_LARROW); - mvaddch(16, 54, ACS_RARROW); - addch('6'); - mvaddch(17, 52, ACS_DARROW); - mvaddstr(18, 49, "1 2 3"); - FirstGame = FALSE; - } else { - ClearMsg(); - ClearMove(); - } - - /* Clear tables */ - for (I = 1; I <= SIZE; I++) for (J = 1; J <= SIZE; J++) { - Board[I][J] = Empty; - for (C = Cross; C <= Nought; C++) { - Value[I][J][C] = 0; - for (D = 0; D <= 3; D++) Line[D][I][J][C] = 0; - } - } - - /* Cross starts */ - Player = Cross; - /* Total number of lines */ - TotalLines = 2 * 2 * (SIZE * (SIZE - 4) + (SIZE - 4) * (SIZE - 4)); - GameWon = FALSE; -} - -int OpponentColor(Player) -int Player; -{ - if (Player == Cross) - return Nought; - else - return Cross; -} - -/* Blink the row of 5 stones */ -void BlinkRow(X, Y, Dx, Dy, Piece) -int X, Y, Dx, Dy, Piece; -{ - int I; - - attron(A_BLINK); - for (I = 1; I <= 5; I++) { - GotoSquare(X, Y); - addch(PieceChar[Piece]); - X = X - Dx; - Y = Y - Dy; - } - attroff(A_BLINK); -} - -/* Prints the 5 winning stones in blinking color */ -void BlinkWinner(Piece, X, Y, WinningLine) -int Piece, X, Y, WinningLine; -{ - /* Used to store the position of the winning move */ - int XHold, YHold; - /* Change in X and Y */ - int Dx, Dy; - - /* Display winning move */ - PrintMove(Piece, X, Y); - /* Preserve winning position */ - XHold = X; - YHold = Y; - switch (WinningLine) { - case Horiz: - { - Dx = 1; - Dy = 0; - break; - } - - case DownLeft: - { - Dx = 1; - Dy = 1; - break; - } - - case Vert: - { - Dx = 0; - Dy = 1; - break; - } - - case DownRight: - { - Dx = -1; - Dy = 1; - break; - } - } - - /* Go to topmost, leftmost */ - while (Board[X + Dx][Y + Dy] != Empty && Board[X + Dx][Y + Dy] == Piece) { - X = X + Dx; - Y = Y + Dy; - } - BlinkRow(X, Y, Dx, Dy, Piece); - /* Restore winning position */ - X = XHold; - Y = YHold; - /* Go back to winning square */ - GotoSquare(X, Y); -} - -/* Functions for playing a game -------------------------------- */ - -int Random(x) -int x; -{ - return((rand() / 19) % x); -} - -/* Adds one to the number of pieces in a line */ -void Add(Num) -int *Num; -{ - /* Adds one to the number. */ - *Num = *Num + 1; - /* If it is the first piece in the line, then the opponent cannot use - * it any more. */ - if (*Num == 1) TotalLines = TotalLines - 1; - /* The game is won if there are 5 in line. */ - if (*Num == 5) GameWon = TRUE; -} - -/* Updates the value of a square for each player, taking into - account that player has placed an extra piece in the square. - The value of a square in a usable line is Weight[Lin[Player]+1] - where Lin[Player] is the number of pieces already placed -in the line */ -void Update(Lin, Valu, Opponent) -int Lin[]; -int Valu[]; -int Opponent; -{ - /* If the opponent has no pieces in the line, then simply update the - * value for player */ - if (Lin[Opponent] == 0) - Valu[Player] += Weight[Lin[Player] + 1] - Weight[Lin[Player]]; - else - /* If it is the first piece in the line, then the line is - * spoiled for the opponent */ - if (Lin[Player] == 1) Valu[Opponent] -= Weight[Lin[Opponent] + 1]; -} - -/* Performs the move X,Y for player, and updates the global variables -(Board, Line, Value, Player, GameWon, TotalLines and the screen) */ -void MakeMove(X, Y) -int X, Y; -{ - int Opponent; - int X1, Y1; - int K, L, WinningLine; - - WinningLine = Null; - Opponent = OpponentColor(Player); - GameWon = FALSE; - - /* Each square of the board is part of 20 different lines. The adds - * one to the number of pieces in each of these lines. Then it - * updates the value for each of the 5 squares in each of the 20 - * lines. Finally Board is updated, and the move is printed on the - * screen. */ - - /* Horizontal lines, from left to right */ - for (K = 0; K <= 4; K++) { - X1 = X - K; /* Calculate starting point */ - Y1 = Y; - if ((1 <= X1) && (X1 <= SIZE - 4)) { /* Check starting point */ - Add(&Line[0][X1][Y1][Player]); /* Add one to line */ - if (GameWon && (WinningLine == Null)) /* Save winning line */ - WinningLine = Horiz; - for (L = 0; L <= 4; L++) /* Update value for the - * 5 squares in the line */ - Update(Line[0][X1][Y1], Value[X1 + L][Y1], Opponent); - } - } - - for (K = 0; K <= 4; K++) { /* Diagonal lines, from lower left to - * upper right */ - X1 = X - K; - Y1 = Y - K; - if ((1 <= X1) && (X1 <= SIZE - 4) && - (1 <= Y1) && (Y1 <= SIZE - 4)) { - Add(&Line[1][X1][Y1][Player]); - if (GameWon && (WinningLine == Null)) /* Save winning line */ - WinningLine = DownLeft; - for (L = 0; L <= 4; L++) - Update(Line[1][X1][Y1], Value[X1 + L][Y1 + L], Opponent); - } - } /* for */ - - for (K = 0; K <= 4; K++) { /* Diagonal lines, down right to upper left */ - X1 = X + K; - Y1 = Y - K; - if ((5 <= X1) && (X1 <= SIZE) && - (1 <= Y1) && (Y1 <= SIZE - 4)) { - Add(&Line[3][X1][Y1][Player]); - if (GameWon && (WinningLine == Null)) /* Save winning line */ - WinningLine = DownRight; - for (L = 0; L <= 4; L++) - Update(Line[3][X1][Y1], Value[X1 - L][Y1 + L], Opponent); - } - } /* for */ - - for (K = 0; K <= 4; K++) { /* Vertical lines, from down to up */ - X1 = X; - Y1 = Y - K; - if ((1 <= Y1) && (Y1 <= SIZE - 4)) { - Add(&Line[2][X1][Y1][Player]); - if (GameWon && (WinningLine == Null)) /* Save winning line */ - WinningLine = Vert; - for (L = 0; L <= 4; L++) - Update(Line[2][X1][Y1], Value[X1][Y1 + L], Opponent); - } - } - - Board[X][Y] = Player; /* Place piece in board */ - if (GameWon) - BlinkWinner(Player, X, Y, WinningLine); - else - PrintMove(Player, X, Y);/* Print move on screen */ - Player = Opponent; /* The opponent is next to move */ -} - -int GameOver() -/* A game is over if one of the players have -won, or if there are no more Empty lines */ -{ - return(GameWon || (TotalLines <= 0)); -} - -/* Finds a move X,Y for player, simply by picking the one with the -highest value */ -void FindMove(X, Y) -int *X, *Y; -{ - int Opponent; - int I, J; - int Max, Valu; - - Opponent = OpponentColor(Player); - Max = -10000; - /* If no square has a high value then pick the one in the middle */ - *X = (SIZE + 1) / 2; - *Y = (SIZE + 1) / 2; - if (Board[*X][*Y] == Empty) Max = 4; - /* The evaluation for a square is simply the value of the square for - * the player (attack points) plus the value for the opponent - * (defense points). Attack is more important than defense, since it - * is better to get 5 in line yourself than to prevent the op- ponent - * from getting it. */ - - /* For all Empty squares */ - for (I = 1; I <= SIZE; I++) for (J = 1; J <= SIZE; J++) - if (Board[I][J] == Empty) { - /* Calculate evaluation */ - Valu = Value[I][J][Player] * (16 + AttackFactor) / 16 + Value[I][J][Opponent] + Random(4); - /* Pick move with highest value */ - if (Valu > Max) { - *X = I; - *Y = J; - Max = Valu; - } - } -} - -char GetChar() -/* Get a character from the keyboard */ -{ - int c; - - c = getch(); - if (c < 0) abort(); - if (c == '\033') { /* arrow key */ - if ((c = getch()) == '[') { - c = getch(); - switch (c) { - case 'A': c = 'U'; break; - case 'B': c = 'D'; break; - case 'C': c = 'R'; break; - case 'D': c = 'L'; break; - default: - c = '?'; - break; - } - } - else - c = '?'; - } - if (islower(c)) - return toupper(c); - else - return c; -} - -/* Reads in a valid command character */ -void ReadCommand(X, Y, Command) -int X, Y; -char *Command; -{ - int ValidCommand; - - do { - ValidCommand = TRUE; - GotoSquare(X, Y); /* Goto square */ - refresh(); - *Command = GetChar(); /* Read from keyboard */ - switch (*Command) { - case '\n': /* '\n', '\r' or space means place a */ - case '\r': - case ' ': - *Command = 'E'; - break; /* stone at the cursor position */ - - case 'L': - case 'R': - case 'U': - case 'D': - case '7': - case '9': - case '1': - case '3': - case 'N': - case 'Q': - case 'A': - case 'P': - case 'H': - break; - - case '8': *Command = 'U'; break; - case '2': *Command = 'D'; break; - case '4': *Command = 'L'; break; - case '6': *Command = 'R'; break; - default: - { - if (GameOver()) - *Command = 'P'; - else - ValidCommand = FALSE; - break; - } - } - } while (!ValidCommand); -} - -void InterpretCommand(Command) -char Command; -{ - int Temp; - - switch (Command) { - case 'N':{ /* Start new game */ - ResetGame(FALSE); /* ResetGame but only redraw - * the board */ - X = (SIZE + 1) / 2; - Y = X; - break; - } - case 'H': - FindMove(&X, &Y); - break; /* Give the user a hint */ - case 'L': - X = (X + SIZE - 2) % SIZE + 1; - break; /* Left */ - case 'R': - X = X % SIZE + 1; - break; /* Right */ - case 'D': - Y = (Y + SIZE - 2) % SIZE + 1; - break; /* Down */ - case 'U': - Y = Y % SIZE + 1; - break; /* Up */ - case '7':{ - if ((X == 1) || (Y == SIZE)) { /* Move diagonally *//* t - * owards upper left */ - Temp = X; - X = Y; - Y = Temp; - } else { - X = X - 1; - Y = Y + 1; - } - break; - } - case '9':{ /* Move diagonally */ - if (X == SIZE) {/* toward upper right */ - X = (SIZE - Y) + 1; - Y = 1; - } else if (Y == SIZE) { - Y = (SIZE - X) + 1; - X = 1; - } else { - X = X + 1; - Y = Y + 1; - } - break; - } - case '1':{ /* Move diagonally */ - if (Y == 1) { /* toward lower left */ - Y = (SIZE - X) + 1; - X = SIZE; - } else if (X == 1) { - X = (SIZE - Y) + 1; - Y = SIZE; - } else { - X = X - 1; - Y = Y - 1; - } - break; - } - case '3':{ /* Move diagonally */ - if ((X == SIZE) || (Y == 1)) { /* toward lower right */ - Temp = X; - X = Y; - Y = Temp; - } else { - X = X + 1; - Y = Y - 1; - } - break; - } - case 'A': - AutoPlay = TRUE; - break; /* Auto play mode */ - } /* case */ -} /* InterpretCommand */ - -void PlayerMove() -/* Enter and make a move */ -{ - if (Board[X][Y] == Empty) { - MakeMove(X, Y); - if (GameWon) PrintMsg("Congratulations, You won!"); - Command = 'P'; - } - refresh(); -} /* PlayerMove */ - -void ProgramMove() -/* Find and perform programs move */ -{ - do { - if (GameOver()) { - AutoPlay = FALSE; - if ((Command != 'Q') && (!GameWon)) PrintMsg("Tie game!"); - } else { - FindMove(&X, &Y); - MakeMove(X, Y); - if (GameWon) PrintMsg("I won!"); - } - refresh(); - } while (AutoPlay); -} - -int main() -{ - Initialize(); - ResetGame(TRUE); /* ResetGame and draw the entire screen */ - refresh(); - X = (SIZE + 1) / 2; /* Set starting position to */ - Y = X; /* the middle of the board */ - do { - ReadCommand(X, Y, &Command); - if (GameOver()) - if (Command != 'Q') Command = 'N'; - InterpretCommand(Command); - if (Command == 'E') PlayerMove(); - if (Command == 'P' || Command == 'A') ProgramMove(); - } while (Command != 'Q'); - Abort("Good bye!"); - return(0); -} diff --git a/commands/life/Makefile b/commands/life/Makefile deleted file mode 100644 index 43e00bda4..000000000 --- a/commands/life/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -PROG= life -MAN= - -DPADD+= ${LIBCURSES} -LDADD+= -lcurses - -.include diff --git a/commands/life/life.c b/commands/life/life.c deleted file mode 100644 index 31bfbcd92..000000000 --- a/commands/life/life.c +++ /dev/null @@ -1,241 +0,0 @@ -/* life - Conway's game of life Author: Jim King */ - -/* clife.c - curses life simulator. Translated from Pascal to C implementing - * curses Oct 1988 by pulsar@lsrhs, not jek5036@ritvax.isc.rit.edu - * life needs about 18kb stack space on MINIX. - * - * Flags: -d draw your own screen using arrows and space bar - * -p print statistics on the bottom line during the game - */ - -#include -#include -#include -#include -#include -#include -#include - -#if __minix_vmd /* Use a more random rand(). */ -#define srand(seed) srandom(seed) -#define rand() random() -#endif - -/* A value of -1 will make it go forever */ -/* A value of 0 will make it exit immediately */ -#define REPSTOP -1 /* number of repetitions before stop */ - -int present[23][80]; /* screen 1 cycle ago */ -int past[23][80]; /* screen this cycle */ -int total; /* total # of changes */ -int icnt; /* counter to check for repetition */ -int maxrow = 22; /* some defines to represent the screen */ -int maxcol = 79; -int minrow = 0; -int mincol = 0; -int pri = 0; /* flag for printing stats on bottom line */ -int draw = 0; /* flag for drawing your own screen */ -int i, j, k; /* loop counters */ -int cycle; /* current cycle # */ -int changes; /* # of changes this cycle (live + die) */ -int die; /* number of deaths this cycle */ -int live; /* number of births this cycle */ - -WINDOW *mns; /* Main Screen */ -WINDOW *info; /* Bottom line */ - -_PROTOTYPE(void cleanup, (int s)); -_PROTOTYPE(void initialize, (void)); -_PROTOTYPE(void makscr, (void)); -_PROTOTYPE(void update, (void)); -_PROTOTYPE(void print, (void)); -_PROTOTYPE(int main, (int ac, char *av[])); - -/* Cleanup - cleanup then exit */ -void cleanup(s) -int s; -{ - move(23, 0); /* go to bottom of screen */ - refresh(); /* update cursor */ - - endwin(); /* shutdown curses */ - exit(1); /* exit */ -} - -/* Initialize - init windows, variables, and signals */ - -void initialize() -{ - srand(getpid()); /* init random seed */ - initscr(); /* init curses */ - noecho(); - curs_set(0); - signal(SIGINT, cleanup); /* catch ^C */ - mns = newwin(maxrow, maxcol, 0, 0); /* new window */ - scrollok(mns, FALSE); - info = newwin(1, 80, 23, 0); - scrollok(info, FALSE); - wclear(mns); - wclear(info); - wmove(info, 0, 0); - wrefresh(info); - if (!draw) { /* if no draw, make random pattern */ - for (j = 0; j < maxrow; j++) { - for (k = 0; k < maxcol; k++) { - present[j][k] = rand() % 2; - if (present[j][k] == 1) changes++, live++; - } - } - } -} - -/* Makscr - make your own screen using arrow keys and space bar */ -void makscr() -{ - int curx, cury; /* current point on screen */ - char c; /* input char */ - - wclear(info); - wmove(info, 0, 0); - wprintw(info, "Use arrow keys to move, space to place / erase, ^D to start", NULL); - wrefresh(info); - curx = cury = 1; - wmove(mns, cury - 1, curx - 1); - wrefresh(mns); - noecho(); - for (;;) { - c = wgetch(mns); - if (c == '\004') - break; - else if (c == ' ') { - if (present[cury][curx]) { - --present[cury][curx]; - changes++; - die++; - mvwaddch(mns, cury, curx, ' '); - } else { - ++present[cury][curx]; - changes++; - live++; - mvwaddch(mns, cury, curx, '*'); - } - } else if (c == '\033') { - wgetch(mns); - switch (wgetch(mns)) { - case 'A': --cury; break; - case 'B': ++cury; break; - case 'C': ++curx; break; - case 'D': --curx; break; - default: break; - } - } - if (cury > maxrow) cury = minrow; - if (cury < minrow) cury = maxrow; - if (curx > maxcol) curx = mincol; - if (curx < mincol) curx = maxcol; - wmove(mns, cury, curx); - wrefresh(mns); - } - wclear(info); -} - -/* Update rules: 2 or 3 adjacent alive --- stay alive - * 3 adjacent alive -- dead to live - * all else die or stay dead - */ -void update() -{ /* Does all mathmatical calculations */ - int howmany, w, x, y, z; - changes = die = live = 0; - for (j = 0; j < maxrow; j++) { - for (k = 0; k < maxcol; k++) { - w = j - 1; - x = j + 1; - y = k - 1; - z = k + 1; - - howmany = (past[w][y] + past[w][k] + past[w][z] + - past[j][y] + past[j][z] + past[x][y] + - past[x][k] + past[x][z]); - - switch (howmany) { - case 0: - case 1: - case 4: - case 5: - case 6: - case 7: - case 8: - present[j][k] = 0; - if (past[j][k]) changes++, die++; - break; - case 3: - present[j][k] = 1; - if (!past[j][k]) changes++, live++; - break; - default: break; - } - } - } - if (live == die) - ++icnt; - else - icnt = 0; - - if (icnt == REPSTOP) cleanup(0); -} - -/* Print - updates the screen according to changes from past to present */ -void print() -{ -/* Updates the screen, greatly improved using curses */ - if (pri) { - wmove(info, 0, 0); - total += changes; - cycle++; - wprintw(info, "Cycle %5d | %5d changes: %5d died + %5d born = %5u total changes", (char *) cycle, changes, die, live, total); - wclrtoeol(info); - } - for (j = 1; j < maxrow; j++) { - for (k = 1; k < maxcol; k++) { - if (present[j][k] != past[j][k] && present[j][k] == 1) { - wmove(mns, j, k); - wprintw(mns, "*", NULL); - } else if (present[j][k] != past[j][k] && present[j][k] == 0) { - wmove(mns, j, k); - wprintw(mns, " ", NULL); - } - } - } - if (pri) wrefresh(info); - wrefresh(mns); -} - -/* Main - main procedure */ -int main(ac, av) -int ac; -char *av[]; -{ - if (ac > 1) { - for (j = 1; j < ac; j++) { - switch (av[j][1]) { - case 'd': ++draw; break; - case 'p': ++pri; break; - default: - fprintf(stderr, "%s: usage: %s [-d] [-p]\n", av[0], av[0]); - exit(1); - } - } - } - - initialize(); - if (draw) makscr(); - - for (;;) { - print(); - for (j = 0; j < maxrow; j++) { - for (k = 0; k < maxcol; k++) past[j][k] = present[j][k]; - } - update(); - } -} diff --git a/commands/mixer/Makefile b/commands/mixer/Makefile deleted file mode 100644 index 306ca146f..000000000 --- a/commands/mixer/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -PROG= mixer -MAN= - -DPADD+= ${LIBCURSES} -LDADD+= -lcurses - -.include diff --git a/commands/mixer/mixer.c b/commands/mixer/mixer.c deleted file mode 100644 index a02699724..000000000 --- a/commands/mixer/mixer.c +++ /dev/null @@ -1,658 +0,0 @@ -/* - * mixer - * - * Michel R. Prevenier. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define CURS_CTRL '\033' -#define ESCAPE 27 -#define UP 'A' -#define DOWN 'B' -#define LEFT 'D' -#define RIGHT 'C' -#define SPACE ' ' - - -_PROTOTYPE ( int main, (int arg, char **argv)); -_PROTOTYPE ( void usage, (void)); -_PROTOTYPE ( void non_interactive, (void)); -_PROTOTYPE ( void setup_screen, (void)); -_PROTOTYPE ( int read_settings, (void)); -_PROTOTYPE ( int write_settings, (void)); -_PROTOTYPE ( void rdwr_levels, (int flag)); -_PROTOTYPE ( void rdwr_inputs, (int flag)); -_PROTOTYPE ( void rdwr_outputs, (int flag)); -_PROTOTYPE ( void create_slider, (int x, int y, enum Device device)); -_PROTOTYPE ( void show_inputs, (int x, int y)); -_PROTOTYPE ( void show_outputs, (int x, int y)); -_PROTOTYPE ( char *d_name, (enum Device device, char *name)); -_PROTOTYPE ( void user_interface, (void)); -_PROTOTYPE ( void terminate, (int s)); - -WINDOW *main_win; -int old_stdin; -int fd; -char name[9]; -char *file_name; -struct volume_level levels[9]; -struct inout_ctrl inputs_left[9]; -struct inout_ctrl inputs_right[9]; -struct inout_ctrl outputs[9]; - - -void usage() -{ - fprintf(stderr, "Usage: mixer [-r]\n"); - exit(-1); -} - - -void terminate(s) -int s; -{ - /* Restore terminal parameters and exit */ - - (void) fcntl(0,F_SETFL,old_stdin); - move(23, 0); - refresh(); - resetty(); - endwin(); - exit(1); -} - - -int write_settings() -{ - /* Write the current mixer settings to $HOME/.mixer */ - - int fd; - - if ((fd = creat(file_name, 0x124)) > 0) - { - write(fd, levels, sizeof(levels)); - write(fd, inputs_left, sizeof(inputs_left)); - write(fd, inputs_right, sizeof(inputs_right)); - write(fd, outputs, sizeof(outputs)); - close(fd); - return 1; - } - - return 0; -} - - -int read_settings() -{ - /* Restore mixer settings saved in $HOME/.mixer */ - - int fd; - - if ((fd = open(file_name, O_RDONLY)) > 0) - { - read(fd, levels, sizeof(levels)); - read(fd, inputs_left, sizeof(inputs_left)); - read(fd, inputs_right, sizeof(inputs_right)); - read(fd, outputs, sizeof(outputs)); - close(fd); - rdwr_levels(1); - rdwr_outputs(1); - rdwr_inputs(1); - return 1; - } - return 0; -} - - -void rdwr_levels(flag) -int flag; /* 0 = read, 1 = write */ -{ - /* Get or set mixer settings */ - - int i; - int cmd; - - cmd = (flag == 0 ? MIXIOGETVOLUME : MIXIOSETVOLUME); - - for(i = Master; i <= Bass; i++) - (void) (ioctl(fd, cmd, &levels[i])); -} - - -void rdwr_inputs(flag) -int flag; /* 0 = read, 1 = write */ -{ - /* Get or set input settings */ - - int i; - int cmd_left, cmd_right; - - cmd_left = (flag == 0 ? MIXIOGETINPUTLEFT : MIXIOSETINPUTLEFT); - cmd_right = (flag == 0 ? MIXIOGETINPUTRIGHT : MIXIOSETINPUTRIGHT); - - for(i = Fm; i <= Mic; i++) - { - (void) (ioctl(fd, cmd_left, &inputs_left[i])); - (void) (ioctl(fd, cmd_right, &inputs_right[i])); - } -} - - -void rdwr_outputs(flag) -int flag; /* 0 = read, 1 = write */ -{ - /* Get or set output settings */ - - int i; - int cmd; - - cmd = (flag == 0 ? MIXIOGETOUTPUT : MIXIOSETOUTPUT); - - for(i = Cd; i <= Mic; i++) - (void) (ioctl(fd, cmd, &outputs[i])); -} - - -int main(argc, argv) -int argc; -char **argv; - -{ - int i; - char *home_ptr; - int fd2; - - /* Open mixer */ - if ((fd = open("/dev/mixer",O_RDONLY)) < 0) - { - fprintf(stderr, "Cannot open /dev/mixer\n"); - exit(-1); - } - - /* Get user's home directory and construct the $HOME/.mixer - * file name - */ - home_ptr = getenv("HOME"); - file_name = malloc(strlen(home_ptr)+strlen("mixer.ini\0")); - if (file_name == (char *)0) - { - fprintf(stderr, "Not enough memory\n"); - exit(-1); - } - strncpy(file_name, home_ptr, strlen(home_ptr)); - strncpy(file_name+strlen(home_ptr), "/.mixer\0", 9); - - /* Fill in the device numbers */ - for(i = Master; i <= Bass; i++) - { - levels[i].device = i; - inputs_left[i].device = i; - inputs_right[i].device = i; - outputs[i].device = i; - } - - /* Get arguments */ - if (argc > 1) - { - if (strncmp(argv[1], "-r", 2) == 0) - { - if (read_settings()) - { - printf("Mixer settings restored\n"); - exit(0); - } - else - { - fprintf(stderr, "Could not restore mixer settings\n"); - exit(-1); - } - } - else usage(); - } - - /* Initialize windows. */ - (void) initscr(); - signal(SIGINT, terminate); - old_stdin = fcntl(0,F_GETFL); - cbreak(); - noecho(); - main_win = newwin(23,80,0,0); - scrollok(main_win, FALSE); - - /* Read all current mixer settings */ - rdwr_levels(0); - rdwr_inputs(0); - rdwr_outputs(0); - - /* Set up the user screen and handle user input */ - setup_screen(); - user_interface(); -} - - -void user_interface() -{ - /* This is the user interface. */ - - char c; - int x,y; - int right; - int input_scr, input_pos; - int output_scr, output_pos; - int max_level; - enum Device device; - int fd2; - - device = Master; - right = 0; - input_scr = 0; - output_scr = 0; - input_pos = 0; - output_pos = 0; - - while(1) - { - if (input_scr) - { - y = device + 9; - x = 51 + input_pos + (device == Mic ? 2 : 0); - } - else if (output_scr) - { - y = device + 15; - x = 53 + output_pos + (device == Mic ? 4 : 0); - } - else - { - y = (device != Speaker ? 2 : 1) + - (device - (device < Treble ? 0 : Treble)) * 3 + - (right == 0 ? 0 : 1); - if (!right) - x = 9 + levels[device].left / (device < Speaker ? 2 : 1 ) + - (device > Speaker ? 39 : 0); - else - x = 9 + levels[device].right / (device < Speaker ? 2 : 1) + - (device > Speaker ? 39 : 0); - } - - wmove(main_win,y,x); - wrefresh(main_win); - c = wgetch(main_win); - - switch(c) - { - case CURS_CTRL: - { - (void) wgetch(main_win); - c = wgetch(main_win); - - switch(c) - { - case DOWN: - { - if (output_scr) - { - if (device < Mic) - { - device++; - if (device == Mic) output_pos = 0; - } - } - else if (right || input_scr) - { - if (!input_scr) - { - if (device < Bass) - { - device++; - right = 0; - } - else - { - input_scr = 1; - input_pos = 0; - device = Fm; - } - } - else - { - if (device < Mic) - { - device++; - if (device == Mic && input_pos > 8) input_pos = 8; - } - else - { - device = Cd; - output_scr = 1; - input_scr = 0; - output_pos = 0; - } - } - } - else - { - if (device != Mic && device != Speaker) right = 1; - else { device++; right = 0; } - } - };break; - case UP: - { - if (output_scr) - { - if (device > Cd) device--; - else - { - device = Mic; - output_scr = 0; - input_scr = 1; - } - } - else if (!right || input_scr) - { - if (input_scr) - { - if (device > Fm) device--; - else - { - input_scr = 0; - device = Bass; - right = 1; - } - } - else - { - if (device > Master) - { - device--; - if (device != Mic && device != Speaker) right = 1; - } - } - } - else - right = 0; - };break; - case RIGHT: - { - if (output_scr) - { - if (output_pos < 8 && device != Mic) output_pos = 8; - } - else if (!input_scr) - { - if (device < Speaker) max_level = 31; - else if (device > Speaker) max_level = 15; - else max_level = 4; - - if (!right) - { - if (levels[device].left < max_level) levels[device].left+= - (device < Speaker ? 2 : 1); - } - else - { - if (levels[device].right < max_level) levels[device].right+= - (device < Speaker ? 2 : 1); - } - ioctl(fd, MIXIOSETVOLUME, &levels[device]); - ioctl(fd, MIXIOGETVOLUME, &levels[device]); - create_slider(1 + (device < Treble ? 0 : 39), - (device - (device < Treble ? 0 : Treble))*3 + - (device != Speaker ? 2 : 1), device); - } - else - { - if ((device != Mic && input_pos < 12) || - (device == Mic && input_pos < 8)) - input_pos += (4 + (device == Mic ? 4 : 0)); - } - };break; - case LEFT: - { - if (output_scr) - { - if (output_pos > 0) output_pos = 0; - } - else if (!input_scr) - { - if (!right) - { - if (levels[device].left > 0) levels[device].left-= - (device < Speaker ? 2 : 1); - } - else - { - if (levels[device].right > 0) levels[device].right-= - (device < Speaker ? 2 : 1); - } - ioctl(fd, MIXIOSETVOLUME, &levels[device]); - ioctl(fd, MIXIOGETVOLUME, &levels[device]); - create_slider(1 + (device < Treble ? 0 : 39), - (device - (device < Treble ? 0 : Treble))*3 + - (device != Speaker ? 2 : 1), device); - } - else - { - if (input_pos > 0) - input_pos -= (4 + (device == Mic ? 4 : 0)); - } - };break; - } - };break; - case SPACE: - { - if (output_scr) - { - switch(output_pos) - { - case 0: - case 4: - { - outputs[device].left = - (outputs[device].left == ON ? OFF : ON); - ioctl(fd, MIXIOSETOUTPUT, &outputs[device]); - };break; - case 8: - { - outputs[device].right = - (outputs[device].right == ON ? OFF : ON); - ioctl(fd, MIXIOSETOUTPUT, &outputs[device]); - };break; - } - ioctl(fd, MIXIOGETOUTPUT, &outputs[device]); - show_outputs(41,16); - } - else if (input_scr) - { - switch(input_pos) - { - case 0: - { - inputs_left[device].left = - (inputs_left[device].left == ON ? OFF : ON); - ioctl(fd, MIXIOSETINPUTLEFT, &inputs_left[device]); - };break; - case 4: - { - inputs_left[device].right = - (inputs_left[device].right == ON ? OFF : ON); - ioctl(fd, MIXIOSETINPUTLEFT, &inputs_left[device]); - };break; - case 8: - { - inputs_right[device].left = - (inputs_right[device].left == ON ? OFF : ON); - ioctl(fd, MIXIOSETINPUTRIGHT, &inputs_right[device]); - };break; - case 12: - { - inputs_right[device].right = - (inputs_right[device].right == ON ? OFF : ON); - ioctl(fd, MIXIOSETINPUTRIGHT, &inputs_right[device]); - };break; - } - ioctl(fd, MIXIOGETINPUTLEFT, &inputs_left[device]); - ioctl(fd, MIXIOGETINPUTRIGHT, &inputs_right[device]); - show_inputs(41,8); - } - };break; - case 's': - { - if (write_settings()) - mvwprintw(main_win,22,28, "mixer settings saved"); - else - mvwprintw(main_win,22,28, "error: file not saved"); - wrefresh(main_win); - sleep(1); - mvwprintw(main_win,22,28, " "); - };break; - case 'r': - { - if (read_settings()) - mvwprintw(main_win,22,28, "mixer settings restored"); - else - mvwprintw(main_win,22,28, "error: could not open"); - wrefresh(main_win); - sleep(1); - setup_screen(); - };break; - case 'e': terminate(1); - } - } -} - - -char *d_name(device, name) -enum Device device; -char *name; -{ - /* Convert the device number to a name */ - - switch (device) - { - case Master: strncpy(name, "Master \0", 9);break; - case Dac: strncpy(name, "Dac \0", 9);break; - case Fm: strncpy(name, "Fm \0", 9);break; - case Cd: strncpy(name, "CD \0", 9);break; - case Line: strncpy(name, "Line \0", 9);break; - case Mic: strncpy(name, "Mic \0", 9);break; - case Speaker: strncpy(name, "Speaker \0", 9);break; - case Treble: strncpy(name, "Treble \0", 9);break; - case Bass: strncpy(name, "Bass \0", 9);break; - } - return name; -} - - -void create_slider(x, y, device) -int x; -int y; -enum Device device; -{ - /* Create a slider on the screen */ - - int left; - int right; - int i; - - mvwprintw(main_win,y,x, "%s", d_name(device, name)); - - left = levels[device].left / (device < Speaker ? 2 : 1); - right = levels[device].right / (device < Speaker ? 2 : 1); - - for (i = 0; i < 16; i++) - { - if (device != Speaker || i < 4) - mvwprintw(main_win,y,x+i+8, (i == left ? "*" : "-")); - if (device < Mic || device > Speaker) - mvwprintw(main_win,y+1,x+i+8, (i == right ? "*" : "-")); - } - - if (device < Mic || device > Speaker) - { - mvwprintw(main_win,y,x+i+10, "left"); - mvwprintw(main_win,y+1,x+i+10, "right"); - } - wrefresh(main_win); -} - -void show_inputs(x,y) -int x; -int y; -{ - /* Show the input settings */ - - int i; - - mvwprintw(main_win,y,x, " Rec-In "); - mvwprintw(main_win,y+1,x," left right"); - mvwprintw(main_win,y+2,x," l r l r"); - for (i = Fm; i <= Line; i++) - { - mvwprintw(main_win,y+i+1,x, "%s %d %d %d %d", - d_name(i, (char *)name), - (inputs_left[i].left == ON ? 1 : 0), - (inputs_left[i].right == ON ? 1 : 0), - (inputs_right[i].left == ON ? 1 : 0), - (inputs_right[i].right == ON ? 1 : 0)); - } - mvwprintw(main_win,y+i+1,x, "%s %d %d", - d_name(Mic, (char *)name), - (inputs_left[Mic].left == ON ? 1 : 0), - (inputs_right[Mic].left == ON ? 1 : 0)); - wrefresh(main_win); -} - -void show_outputs(x,y) -int x; -int y; -{ - /* Show the output settings */ - - int i; - - mvwprintw(main_win,y,x, " Mix-Out "); - mvwprintw(main_win,y+1,x, " left right"); - for (i = Cd; i <= Line; i++) - { - mvwprintw(main_win,y+i-1,x,"%s %d %d", - d_name(i, (char *)name), - (outputs[i].left == ON ? 1 : 0), - (outputs[i].right == ON ? 1 : 0)); - } - mvwprintw(main_win,y+i-1,x,"%s %d", - d_name(Mic, (char *)name), - (outputs[Mic].left == ON ? 1 : 0)); - - wrefresh(main_win); -} - - -void setup_screen() -{ - int i; - - wclear(main_win); - mvwprintw(main_win,0,23,"------- Mixer Controls -------"); - wrefresh(main_win); - - for(i = 0; i <= Speaker; i++) - create_slider(1, i*3+(i <= Mic ? 2 : 1), i); - - create_slider(40, 2, Treble); - create_slider(40, 5, Bass); - - show_inputs(41,8); - show_outputs(41,16); -} diff --git a/commands/talk/Makefile b/commands/talk/Makefile deleted file mode 100644 index bc1d015ff..000000000 --- a/commands/talk/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# Makefile for talk -# -# 08/01/96 Michael Temari, -# - -PROG= talk -SRCS= talk.c screen.c net.c proto.c -MAN= - -DPADD+= ${LIBCURSES} -LDADD+= -lcurses - -.include diff --git a/commands/talk/net.c b/commands/talk/net.c deleted file mode 100644 index eee4acfc5..000000000 --- a/commands/talk/net.c +++ /dev/null @@ -1,264 +0,0 @@ -/* net.c Copyright Michael Temari 08/01/1996 All Rights Reserved */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "talk.h" -#include "net.h" - -_PROTOTYPE(void TimeOut, (int sig)); - -static unsigned char buffer[8192]; - -static int udp_ctl; -int tcp_fd; - -static udpport_t ntalk_port; - -char luser[USER_SIZE+1], ruser[USER_SIZE+1]; -char lhost[HOST_SIZE+1], rhost[HOST_SIZE+1]; -char ltty[TTY_SIZE+1], rtty[TTY_SIZE+1]; -udpport_t ctlport; -tcpport_t dataport; -ipaddr_t laddr, raddr; - -int NetInit() -{ -int s; -struct servent *servent; -char *udp_device; -char *tcp_device; -nwio_udpopt_t udpopt; -nwio_tcpconf_t tcpconf; - - if((udp_device = getenv("UDP_DEVICE")) == (char *)NULL) - udp_device = UDP_DEVICE; - - if((udp_ctl = open(udp_device, O_RDWR)) < 0) { - fprintf(stderr, "talk: Could not open %s: %s\n", - udp_device, strerror(errno)); - return(-1); - } - - if((servent = getservbyname("ntalk", "udp")) == (struct servent *)NULL) { - fprintf(stderr, "talk: Could not find ntalk udp service\n"); - close(udp_ctl); - return(-1); - } - - ntalk_port = (udpport_t)servent->s_port; - - udpopt.nwuo_flags = NWUO_NOFLAGS; - udpopt.nwuo_flags |= NWUO_COPY | NWUO_LP_SEL | NWUO_EN_LOC; - udpopt.nwuo_flags |= NWUO_DI_BROAD | NWUO_RP_SET | NWUO_RA_SET; - udpopt.nwuo_flags |= NWUO_RWDATONLY | NWUO_DI_IPOPT; - udpopt.nwuo_remaddr = raddr; - udpopt.nwuo_remport = ntalk_port; - - s = ioctl(udp_ctl, NWIOSUDPOPT, &udpopt); - if(s < 0) { - perror("talk: ioctl NWIOSUDPOPT"); - close(udp_ctl); - return(-1); - } - - s = ioctl(udp_ctl, NWIOGUDPOPT, &udpopt); - if(s < 0) { - perror("talk: ioctl NWIOGUDPOPT"); - close(udp_ctl); - return(-1); - } - laddr = udpopt.nwuo_locaddr; - ctlport = udpopt.nwuo_locport; - - if((tcp_device = getenv("TCP_DEVICE")) == (char *)NULL) - tcp_device = TCP_DEVICE; - - if((tcp_fd = open(tcp_device, O_RDWR)) < 0) { - fprintf(stderr, "talk: Could not open %s: %s\n", - tcp_device, strerror(errno)); - close(udp_ctl); - return(-1); - } - - tcpconf.nwtc_flags = NWTC_NOFLAGS; - tcpconf.nwtc_flags |= NWTC_LP_SEL | NWTC_SET_RA | NWTC_UNSET_RP; - tcpconf.nwtc_remaddr = raddr; - - s = ioctl(tcp_fd, NWIOSTCPCONF, &tcpconf); - if(s < 0) { - perror("talk: ioctl NWIOSTCPCONF"); - close(udp_ctl); - close(tcp_fd); - return(-1); - } - - s = ioctl(tcp_fd, NWIOGTCPCONF, &tcpconf); - if(s < 0) { - perror("talk: ioctl NWIOGTCPCONF"); - close(udp_ctl); - close(tcp_fd); - return(-1); - } - - dataport = tcpconf.nwtc_locport; - - return(0); -} - -int getreply(reply, timeout) -struct talk_reply *reply; -int timeout; -{ -int s; -int terrno; -udp_io_hdr_t *udp_io_hdr; - - signal(SIGALRM, TimeOut); - alarm(timeout); - s = read(udp_ctl, buffer, sizeof(buffer)); - terrno = errno; - alarm(0); - errno = terrno; - if(s < 0 && errno == EINTR) - return(1); - if(s < 0) { - perror("talk: Read error in getreply"); - return(-1); - } - - if(s == sizeof(struct talk_reply)) - memcpy((char *)reply, buffer, s); - - return(0); -} - -int sendrequest(request, here) -struct talk_request *request; -int here; -{ -int s; -nwio_udpopt_t udpopt; -udp_io_hdr_t *udp_io_hdr; - - udpopt.nwuo_flags = NWUO_NOFLAGS; - udpopt.nwuo_flags |= NWUO_COPY | NWUO_LP_SET | NWUO_EN_LOC; - udpopt.nwuo_flags |= NWUO_DI_BROAD | NWUO_RP_SET | NWUO_RA_SET; - udpopt.nwuo_flags |= NWUO_RWDATONLY | NWUO_DI_IPOPT; - udpopt.nwuo_locport = ctlport; - if(here) - udpopt.nwuo_remaddr = laddr; - else - udpopt.nwuo_remaddr = raddr; - udpopt.nwuo_remport = ntalk_port; - - s = ioctl(udp_ctl, NWIOSUDPOPT, &udpopt); - if(s < 0) { - perror("talk: ioctl NWIOSUDPOPT"); - return(-1); - } - - s = ioctl(udp_ctl, NWIOGUDPOPT, &udpopt); - if(s < 0) { - perror("talk: ioctl NWIOGUDPOPT"); - return(-1); - } - - s = write(udp_ctl, request, sizeof(struct talk_request)); - if(s < 0) { - perror("talk: write error in sendrequest"); - return(-1); - } - - if(s != sizeof(struct talk_request)) { - fprintf(stderr, "talk: sendrequest size mismatch %d %d\n", s, sizeof(struct talk_request)); - return(-1); - } - - return(0); -} - -void TimeOut(int sig) -{ -} - -int NetConnect(u16_t port) -{ - int s; - nwio_tcpconf_t tcpconf; - nwio_tcpcl_t tcpcopt; - - tcpconf.nwtc_flags = NWTC_NOFLAGS; - tcpconf.nwtc_flags |= NWTC_LP_SET | NWTC_SET_RA | NWTC_SET_RP; - tcpconf.nwtc_locport = dataport; - tcpconf.nwtc_remaddr = raddr; - tcpconf.nwtc_remport = port; - - s = ioctl(tcp_fd, NWIOSTCPCONF, &tcpconf); - if(s < 0) { - perror("talk: ioctl NWIOSTCPCONF"); - return(-1); - } - - s = ioctl(tcp_fd, NWIOGTCPCONF, &tcpconf); - if(s < 0) { - perror("talk: ioctl NWIOGTCPCONF"); - return(-1); - } - - tcpcopt.nwtcl_flags = 0; - - s = ioctl(tcp_fd, NWIOTCPCONN, &tcpcopt); - if(s < 0 && errno == ECONNREFUSED) - return(1); - if(s < 0) { - perror("talk: ioctl NWIOTCPCONN"); - return(-1); - } - - return(0); -} - -int NetListen(timeout) -int timeout; -{ -int s; -nwio_tcpcl_t tcplopt; -int terrno; - - tcplopt.nwtcl_flags = 0; - - signal(SIGALRM, TimeOut); - alarm(timeout); - s = ioctl(tcp_fd, NWIOTCPLISTEN, &tcplopt); - terrno = errno; - alarm(0); - errno = terrno; - - if(s < 0 && errno == EINTR) - return(1); - - if(s < 0) { - perror("talk: ioctl NWIOTCPLISTEN"); - return(-1); - } - - return(0); -} diff --git a/commands/talk/net.h b/commands/talk/net.h deleted file mode 100644 index 8d7d725be..000000000 --- a/commands/talk/net.h +++ /dev/null @@ -1,15 +0,0 @@ -/* net.h Copyright Michael Temari 08/01/1996 All Rights Reserved */ - -extern char luser[], ruser[]; -extern char lhost[], rhost[]; -extern char ltty[], rtty[]; -extern udpport_t ctlport; -extern tcpport_t dataport; -extern ipaddr_t laddr, raddr; -extern int tcp_fd; - -_PROTOTYPE(int NetInit, (void)); -_PROTOTYPE(int getreply, (struct talk_reply *reply, int timeout)); -_PROTOTYPE(int sendrequest, (struct talk_request *request, int here)); -_PROTOTYPE(int NetConnect, (u16_t port)); -_PROTOTYPE(int NetListen, (int timeout)); diff --git a/commands/talk/proto.c b/commands/talk/proto.c deleted file mode 100644 index 0e79a1647..000000000 --- a/commands/talk/proto.c +++ /dev/null @@ -1,142 +0,0 @@ -/* proto.c Copyright Michael Temari 08/01/1996 All Rights Reserved */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "talk.h" -#include "proto.h" -#include "net.h" -#include "screen.h" - -_PROTOTYPE(static int TalkChk, (int gotreply, struct talk_reply *reply, char *msg)); -_PROTOTYPE(static int TalkTrans, (int type, long id, struct talk_reply *reply, int here)); - -static char *AnswerMsgs[] = { - "Success", - "User Not Logged In", - "Failure", - "Remote Does Not Know who we are", - "User is not accepting calls", - "Are request was not know", - "Incorrect Version", - "Bad Address", - "Bad Control Address" -}; - -static int TalkChk(gotreply, reply, msg) -int gotreply; -struct talk_reply *reply; -char *msg; -{ - if(!gotreply) { - ScreenMsg(msg); - return(-1); - } - if(reply->answer == SUCCESS) return(0); - if(reply->answer < (sizeof(AnswerMsgs) / sizeof(AnswerMsgs[0]))) - ScreenMsg(AnswerMsgs[reply->answer]); - else - ScreenMsg("Bad Answer"); - - return(-1); -} - -static int TalkTrans(type, id, reply, here) -int type; -long id; -struct talk_reply *reply; -int here; -{ -struct talk_request request; -int tries; -int gotreply; - - memset(&request, 0, sizeof(request)); - - request.version = TALK_VERSION; - request.type = type; - request.id = id; - request.addr.sa_family = htons(AF_INET); - request.addr.sin_port = dataport; - request.addr.sin_addr = laddr; - request.ctl_addr.sa_family = htons(AF_INET); - request.ctl_addr.sin_port = ctlport; - request.ctl_addr.sin_addr = laddr; - request.pid = getpid(); - strncpy(request.luser, luser, USER_SIZE); - strncpy(request.ruser, ruser, USER_SIZE); - strncpy(request.rtty, rtty, TTY_SIZE); - - tries = 0; - gotreply = 0; - while(!ScreenDone && tries++ < 3 && !gotreply) { - if(!sendrequest(&request, here)) - if(!getreply(reply, 5)) - gotreply = 1; - if(!gotreply) continue; - if(reply->version != request.version || - reply->type != request.type) - gotreply = 0; - } - return(gotreply); -} - -int TalkInit() -{ -struct talk_reply reply; -long id = 0; -long rid; -int s; -int ring; -char buff[32]; - - /* Check if someone was calling us */ - ScreenMsg("Initiating Talk Protocol"); - - /* Check is someone was calling us */ - s = TalkTrans(LOOK_UP, ++id, &reply, 0); - - /* Someone was calling us */ - if(s && reply.answer == SUCCESS) { - s = NetConnect(reply.addr.sin_port); - if(s == 1) { - ScreenMsg("Your party has hung up"); - TalkTrans(DELETE, reply.id, &reply, 0); - } - return(s == 0 ? 0 : -1); - } - - ScreenMsg("Ringing User"); - - ring = 0; - while(!ScreenDone && ring++ < 5) { - if(TalkChk(TalkTrans(ANNOUNCE, -1, &reply, 0), - &reply, "No response to are ring")) - return(-1); - rid = reply.id; - sprintf(buff, "Ring #%d", ring); - ScreenMsg(buff); - if(ring == 1) { - if(TalkChk(TalkTrans(LEAVE_INVITE, ++id, &reply, 1), - &reply, "Could not leave are invitaion locally")) - return(-1); - } - s = NetListen(RING_WAIT); - if(s <= 0) { - TalkTrans(DELETE, reply.id, &reply, 1); - TalkTrans(DELETE, rid, &reply, 0); - return(s); - } - } - - return(-1); -} diff --git a/commands/talk/proto.h b/commands/talk/proto.h deleted file mode 100644 index 27442bc33..000000000 --- a/commands/talk/proto.h +++ /dev/null @@ -1,3 +0,0 @@ -/* proto.h Copyright Michael Temari 08/01/1996 All Rights Reserved */ - -_PROTOTYPE(int TalkInit, (void)); diff --git a/commands/talk/screen.c b/commands/talk/screen.c deleted file mode 100644 index c7f689392..000000000 --- a/commands/talk/screen.c +++ /dev/null @@ -1,208 +0,0 @@ -/* screen.c Copyright Michael Temari 08/01/1996 All Rights Reserved */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "screen.h" - -_PROTOTYPE(void gotsig, (int sig)); -_PROTOTYPE(static char *delword, (WINDOW *w)); - -struct { - WINDOW *win; - char erase; - char kill; - char werase; -} window[2]; - -static char line[80+1]; - -int ScreenDone = 0; - -static WINDOW *dwin; - -void gotsig(sig) -int sig; -{ - ScreenDone = 1; - signal(sig, gotsig); -} - -int ScreenInit() -{ -int i; - - if(initscr() == (WINDOW *)NULL) { - fprintf(stderr, "talk: Could not initscr\n"); - return(-1); - } - signal(SIGINT, gotsig); - signal(SIGQUIT, gotsig); - signal(SIGPIPE, gotsig); - signal(SIGHUP, gotsig); - clear(); - refresh(); - noecho(); - cbreak(); - - /* local window */ - window[LOCALWIN].win = newwin(LINES / 2, COLS, 0, 0); - scrollok(window[LOCALWIN].win, TRUE); - wclear(window[LOCALWIN].win); - - /* divider between windows */ - dwin = newwin(1, COLS, LINES / 2, 0); - i = COLS; - while(i-- > 0) - waddch(dwin, '-'); - wrefresh(dwin); - - /* remote window */ - window[REMOTEWIN].win = newwin(LINES - (LINES / 2) - 1, COLS, LINES / 2 + 1, 0); - scrollok(window[REMOTEWIN].win, TRUE); - wclear(window[REMOTEWIN].win); - - return(0); -} - -void ScreenMsg(msg) -char *msg; -{ -WINDOW *w; - - w =window[LOCALWIN].win; - - wmove(w, 0, 0); - - if(*msg != '\0') { - wprintw(w, "[%s]", msg); - wclrtoeol(w); - } else - werase(w); - - wrefresh(w); -} - -void ScreenWho(user, host) -char *user; -char *host; -{ - if(*host != '\0') { - wmove(dwin, 0, (COLS - (1 + strlen(user) + 1 + strlen(host) + 1)) / 2); - wprintw(dwin, " %s@%s ", user, host); - } else { - wmove(dwin, 0, (COLS - (1 + strlen(user) + 1)) / 2); - wprintw(dwin, " %s ", user); - } - wrefresh(dwin); -} - -void ScreenEdit(lcc, rcc) -char lcc[]; -char rcc[]; -{ - window[LOCALWIN].erase = lcc[0]; - window[LOCALWIN].kill = lcc[1]; - window[LOCALWIN].werase = lcc[2]; - window[REMOTEWIN].erase = rcc[0]; - window[REMOTEWIN].kill = rcc[1]; - window[REMOTEWIN].werase = rcc[2]; -} - -void ScreenPut(data, len, win) -char *data; -int len; -int win; -{ -WINDOW *w; -unsigned char ch; -int r, c; - - w = window[win].win; - - while(len-- > 0) { - ch = *data++; - /* new line CR, NL */ - if(ch == '\r' || ch == '\n') { - waddch(w, '\n'); - } else - /* erase a character, BS, DEL */ - if(ch == 0x08 || ch == 0x7f || ch == window[win].erase) { - getyx(w, r, c); - if(c > 0) - c--; - wmove(w, r, c); - waddch(w, ' '); - wmove(w, r, c); - } else - /* erase line CTL-U */ - if(ch == 0x15 || ch == window[win].kill) { - getyx(w, r, c); - wmove(w, r, 0); - wclrtoeol(w); - } else - /* refresh CTL-L */ - if(ch == 0x0c) { - if(win == LOCALWIN) { - touchwin(w); - wrefresh(w); - touchwin(window[REMOTEWIN].win); - wrefresh(window[REMOTEWIN].win); - } - } else - /* bell CTL-G */ - if(ch == 0x07) { - putchar(ch); - } - else - /* erase last word CTL-W */ - if(ch == 0x17 || ch == window[win].werase) { - (void) delword(w); - } else { - getyx(w, r, c); - if(1 || isprint(ch)) { - if(ch != ' ' && c == (COLS - 1)) - wprintw(w, "\n%s", delword(w)); - waddch(w, ch); - } - } - } - wrefresh(w); -} - -static char *delword(w) -WINDOW *w; -{ -int r, c; -int i = 0; -char ch; -char *p = &line[80]; - - *p-- = '\0'; - getyx(w, r, c); - if(c == 0) return NULL; - while(c >= 0) { - c--; - ch = mvwinch(w, r, c); - if(ch == ' ') break; - *p-- = ch; - i = 1; - waddch(w, ' '); - } - c += i; - wmove(w, r, c); - return(++p); -} - -void ScreenEnd() -{ - move(LINES - 1, 0); - refresh(); - endwin(); -} diff --git a/commands/talk/screen.h b/commands/talk/screen.h deleted file mode 100644 index a01eb418f..000000000 --- a/commands/talk/screen.h +++ /dev/null @@ -1,13 +0,0 @@ -/* screen.h Copyright Michael Temari 08/01/1996 All Rights Reserved */ - -_PROTOTYPE(int ScreenInit, (void)); -_PROTOTYPE(void ScreenMsg, (char *msg)); -_PROTOTYPE(void ScreenWho, (char *user, char *host)); -_PROTOTYPE(void ScreenEdit, (char lcc[], char rcc[])); -_PROTOTYPE(void ScreenPut, (char *data, int len, int mywin)); -_PROTOTYPE(void ScreenEnd, (void)); - -extern int ScreenDone; - -#define LOCALWIN 0 -#define REMOTEWIN 1 diff --git a/commands/talk/talk.c b/commands/talk/talk.c deleted file mode 100644 index 832922f76..000000000 --- a/commands/talk/talk.c +++ /dev/null @@ -1,242 +0,0 @@ -/* talk.c Copyright Michael Temari 08/01/1996 All Rights Reserved */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "talk.h" -#include "proto.h" -#include "net.h" -#include "screen.h" - -_PROTOTYPE(int main, (int argc, char *argv[])); -_PROTOTYPE(void DoTalk, (void)); - -int main(argc, argv) -int argc; -char *argv[]; -{ -char *p; -struct hostent *hp; -struct stat st; -struct utmp utmp; -int slot; -FILE *fp; - - if(argc < 2 || argc > 3) { - fprintf(stderr, "Usage: talk user[@host] [tty]\n"); - return(-1); - } - - /* get local host name */ - if(gethostname(lhost, HOST_SIZE) < 0) { - fprintf(stderr, "talk: Error getting local host name\n"); - return(-1); - } - - /* get local user name and tty */ - if((slot = ttyslot()) < 0) { - fprintf(stderr, "talk: You are not on a terminal\n"); - return(-1); - } - if((fp = fopen(UTMP, "r")) == (FILE *)NULL) { - fprintf(stderr, "talk: Could not open %s\n", UTMP); - return(-1); - } - if(fseek(fp, (off_t) sizeof(utmp) * slot, SEEK_SET)) { - fprintf(stderr, "talk: Could not seek %s\n", UTMP); - fclose(fp); - return(-1); - } - if(fread((char *)&utmp, sizeof(utmp), 1 , fp) != 1) { - fprintf(stderr, "talk: Could not read %s\n", UTMP); - fclose(fp); - return(-1); - } - fclose(fp); -#ifdef __NBSD_LIBC - strncpy(luser, utmp.ut_name, USER_SIZE < sizeof(utmp.ut_name) ? - USER_SIZE : sizeof(utmp.ut_name)); -#else - strncpy(luser, utmp.ut_user, USER_SIZE < sizeof(utmp.ut_user) ? - USER_SIZE : sizeof(utmp.ut_user)); -#endif - luser[USER_SIZE] = '\0'; - - /* get local tty */ - if((p = ttyname(0)) == (char *)NULL) { - fprintf(stderr, "talk: You are not on a terminal\n"); - return(-1); - } - strncpy(ltty, p+5, TTY_SIZE); - ltty[TTY_SIZE] = '\0'; - - /* check if local tty is going to be writable */ - if(stat(p, &st) < 0) { - perror("talk: Could not stat local tty"); - return(-1); - } - if((st.st_mode & S_IWGRP) == 0) { - fprintf(stderr, "talk: Your terminal is not writable. Use: mesg y\n"); - return(-1); - } - - /* get remote user and host name */ - if((p = strchr(argv[1], '@')) != (char *)NULL) - *p++ = '\0'; - else - p = lhost; - strncpy(ruser, argv[1], USER_SIZE); - ruser[USER_SIZE] = '\0'; - strncpy(rhost, p, HOST_SIZE); - rhost[HOST_SIZE] = '\0'; - - /* get remote tty */ - if(argc > 2) - strncpy(rtty, argv[2], TTY_SIZE); - else - rtty[0] = '\0'; - rtty[TTY_SIZE] = '\0'; - - if((hp = gethostbyname(rhost)) == (struct hostent *)NULL) { - fprintf(stderr, "talk: Could not determine address of %s\n", rhost); - return(-1); - } - memcpy((char *)&raddr, (char *)hp->h_addr, hp->h_length); - - if(NetInit()) { - fprintf(stderr, "talk: Error in NetInit\n"); - return(-1); - } - - if(ScreenInit()) - return(-1); - - if(!TalkInit()) - DoTalk(); - - ScreenEnd(); - - return(0); -} - -struct pdata { - int win; - int len; - char buffer[64]; -} pdata; - -void DoTalk() -{ -int s; -int s2; -int kid; -int pfd[2]; -int win; -int len; -struct termios termios; -char lcc[3]; -char rcc[3]; - - ScreenMsg(""); - ScreenWho(ruser, rhost); - - /* Get and send edit characters */ - s = tcgetattr(0, &termios); - if(s < 0) { - perror("talk: tcgetattr"); - return; - } - lcc[0] = termios.c_cc[VERASE]; - lcc[1] = termios.c_cc[VKILL]; - lcc[2] = 0x17; /* Control - W */ - s = write(tcp_fd, lcc, sizeof(lcc)); - if(s != sizeof(lcc)) { - ScreenMsg("Connection Closing due to error"); - return; - } - s = read(tcp_fd, rcc, sizeof(rcc)); - if(s != sizeof(rcc)) { - ScreenMsg("Connection Closing due to error"); - return; - } - ScreenEdit(lcc, rcc); - - s = pipe(pfd); - if(s < 0) { - ScreenMsg("Could not create pipes"); - return; - } - - if((kid = fork()) < 0) { - ScreenMsg("Could not fork"); - close(pfd[0]); - close(pfd[1]); - return; - } - - if(kid == 0) { - close(tcp_fd); - close(pfd[1]); - while(1) { - s = read(pfd[0], &pdata, sizeof(pdata)); - if(s != sizeof(pdata)) { - close(pfd[0]); - exit(-1); - } - ScreenPut(pdata.buffer, pdata.len, pdata.win); - } - } - - close(pfd[0]); - - if((kid = fork()) < 0) { - ScreenMsg("Could not fork"); - close(pfd[1]); - return; - } - - if(kid == 0) { - pdata.win = REMOTEWIN; - while(!ScreenDone) { - s = read(tcp_fd, pdata.buffer, sizeof(pdata.buffer)); - if(s <= 0) - break; - pdata.len = s; - write(pfd[1], &pdata, sizeof(pdata)); - } - close(pfd[1]); - close(tcp_fd); - kill(getppid(), SIGINT); - exit(-1); - } - - pdata.win = LOCALWIN; - while(!ScreenDone) { - s = read(0, pdata.buffer, sizeof(pdata.buffer)); - if(s <= 0) - break; - pdata.len = s; - write(pfd[1], &pdata, sizeof(pdata)); - s2 = write(tcp_fd, pdata.buffer, s); - if(s2 != s) - break; - } - kill(kid, SIGINT); - close(pfd[1]); - close(tcp_fd); - return; -} diff --git a/commands/talk/talk.h b/commands/talk/talk.h deleted file mode 100644 index e7ecbab11..000000000 --- a/commands/talk/talk.h +++ /dev/null @@ -1,57 +0,0 @@ -/* talk.h Copyright Michael Temari 07/22/1996 All Rights Reserved */ - -#define USER_SIZE 12 -#define TTY_SIZE 16 -#define HOST_SIZE 255 - -struct osockaddr { - u16_t sa_family; - u16_t sin_port; - ipaddr_t sin_addr; - char junk[8]; -}; - -struct talk_request { - u8_t version; - u8_t type; - u8_t answer; - u8_t junk; - u32_t id; - struct osockaddr addr; - struct osockaddr ctl_addr; - long pid; - char luser[USER_SIZE]; - char ruser[USER_SIZE]; - char rtty[TTY_SIZE]; -}; - -struct talk_reply { - u8_t version; - u8_t type; - u8_t answer; - u8_t junk; - u32_t id; - struct osockaddr addr; -}; - -#define TALK_VERSION 1 - -/* message type values */ -#define LEAVE_INVITE 0 /* leave invitation with server */ -#define LOOK_UP 1 /* check for invitation by callee */ -#define DELETE 2 /* delete invitation by caller */ -#define ANNOUNCE 3 /* announce invitation by caller */ - -/* answer values */ -#define SUCCESS 0 /* operation completed properly */ -#define NOT_HERE 1 /* callee not logged in */ -#define FAILED 2 /* operation failed for unexplained reason */ -#define MACHINE_UNKNOWN 3 /* caller's machine name unknown */ -#define PERMISSION_DENIED 4 /* callee's tty doesn't permit announce */ -#define UNKNOWN_REQUEST 5 /* request has invalid type value */ -#define BADVERSION 6 /* request has invalid protocol version */ -#define BADADDR 7 /* request has invalid addr value */ -#define BADCTLADDR 8 /* request has invalid ctl_addr value */ - -#define MAX_LIFE 60 /* max time daemon saves invitations */ -#define RING_WAIT 30 /* time to wait before resending invitation */ diff --git a/commands/talkd/Makefile b/commands/talkd/Makefile deleted file mode 100644 index 367e3692f..000000000 --- a/commands/talkd/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -# Makefile for talkd -# -# 07/22/96 Michael Temari, -# - -PROG= talkd -SRCS= talkd.c net.c process.c finduser.c -MAN= - -.include diff --git a/commands/talkd/finduser.c b/commands/talkd/finduser.c deleted file mode 100644 index 7bb0145a0..000000000 --- a/commands/talkd/finduser.c +++ /dev/null @@ -1,48 +0,0 @@ -/* finduser.c Copyright Michael Temari 07/22/1996 All Rights Reserved */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "talk.h" -#include "finduser.h" - -int find_user(name, tty) -char *name; -char *tty; -{ -int fd; -int ret; -struct utmp utmp; - - /* Now find out if the requested user is logged in. */ - if((fd = open(UTMP, O_RDONLY)) < 0) { - perror("talkd: opening UTMP file"); - return(FAILED); - } - - ret = NOT_HERE; - - while(read(fd, &utmp, sizeof(struct utmp)) == sizeof(struct utmp)) { - if(utmp.ut_type != USER_PROCESS) continue; -#ifdef __NBSD_LIBC - if(strncmp(utmp.ut_name, name, sizeof(utmp.ut_name))) continue; -#else - if(strncmp(utmp.ut_user, name, sizeof(utmp.ut_user))) continue; -#endif - if(*tty && strncmp(utmp.ut_line, tty, sizeof(utmp.ut_line))) continue; - strcpy(tty, utmp.ut_line); - ret = SUCCESS; - break; - } - - close(fd); - - return(ret); -} diff --git a/commands/talkd/finduser.h b/commands/talkd/finduser.h deleted file mode 100644 index 7fd68bd5f..000000000 --- a/commands/talkd/finduser.h +++ /dev/null @@ -1,3 +0,0 @@ -/* finduser.h Copyright Michael Temari 07/22/1996 All Rights Reserved */ - -_PROTOTYPE(int find_user, (char *name, char *tty)); diff --git a/commands/talkd/net.c b/commands/talkd/net.c deleted file mode 100644 index 4eb136cce..000000000 --- a/commands/talkd/net.c +++ /dev/null @@ -1,188 +0,0 @@ -/* net.c Copyright Michael Temari 07/22/1996 All Rights Reserved */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "talk.h" -#include "talkd.h" -#include "net.h" - -static unsigned char buffer[8192]; - -static int udp_in; -static int udp_out; - -static udpport_t ntalk_port; - -int NetInit() -{ -int s; -struct servent *servent; -char *udp_device; -nwio_udpopt_t udpopt; - - if((udp_device = getenv("UDP_DEVICE")) == (char *)NULL) - udp_device = UDP_DEVICE; - - if((udp_in = open(udp_device, O_RDWR)) < 0) { - fprintf(stderr, "talkd: Could not open %s: %s\n", - udp_device, strerror(errno)); - return(-1); - } - - if((udp_out = open(udp_device, O_RDWR)) < 0) { - fprintf(stderr, "talkd: Could not open %s: %s\n", - udp_device, strerror(errno)); - close(udp_in); - return(-1); - } - - if((servent = getservbyname("ntalk", "udp")) == (struct servent *)NULL) { - fprintf(stderr, "talkd: Could not find ntalk udp service\n"); - close(udp_in); - close(udp_out); - return(-1); - } - - ntalk_port = (udpport_t)servent->s_port; - - udpopt.nwuo_flags = NWUO_NOFLAGS; - udpopt.nwuo_flags |= NWUO_COPY | NWUO_LP_SET | NWUO_EN_LOC; - udpopt.nwuo_flags |= NWUO_DI_BROAD | NWUO_RP_ANY | NWUO_RA_ANY; - udpopt.nwuo_flags |= NWUO_RWDATALL | NWUO_DI_IPOPT; - udpopt.nwuo_locport = ntalk_port; - - s = ioctl(udp_in, NWIOSUDPOPT, &udpopt); - if(s < 0) { - perror("talkd: ioctl NWIOSUDPOPT"); - close(udp_in); - close(udp_out); - return(-1); - } - - s = ioctl(udp_in, NWIOGUDPOPT, &udpopt); - if(s < 0) { - perror("talkd: ioctl NWIOGUDPOPT"); - close(udp_in); - close(udp_out); - return(-1); - } - - return(0); -} - -int getrequest(request) -struct talk_request *request; -{ -int s; -udp_io_hdr_t *udp_io_hdr; - - s = read(udp_in, buffer, sizeof(buffer)); - if(s < 0) { - perror("talkd: Read error in getrequest"); - return(-1); - } - if(s < sizeof(udp_io_hdr_t)) { - fprintf(stderr, "talkd: Packet size read %d is smaller the udp_io_hdr\n", s); - return(-1); - } - udp_io_hdr = (udp_io_hdr_t *)buffer; - s = s - sizeof(udp_io_hdr_t); - - /* why is uih_data_len already in host order??? */ - - if(udp_io_hdr->uih_data_len != s) { - fprintf(stderr, "talkd: Size mismatch Packet %d Udp Data %d\n", - s, udp_io_hdr->uih_data_len); - return(-1); - } - - if(s != sizeof(struct talk_request)) { - fprintf(stderr, "talkd: Size mismatch in request %d %d\n", - s, sizeof(struct talk_request)); - return(-1); - } - - memcpy((char *)request, buffer + sizeof(udp_io_hdr_t), s); - - if(opt_d) { - fprintf(stderr, "Request: "); - fprintf(stderr, "%02x %02x %02x %02x ", - request->version, request->type, request->answer, request->junk); - fprintf(stderr, "%08lx ", request->id); - fprintf(stderr, "%04x %08lx:%04x\n", - request->addr.sa_family, request->addr.sin_addr, request->addr.sin_port); - fprintf(stderr, " %08lx ", request->pid); - fprintf(stderr, "%04x %08lx:%04x\n", - request->ctl_addr.sa_family, request->ctl_addr.sin_addr, request->ctl_addr.sin_port); - fprintf(stderr, " %-12.12s %-12.12s %-16.16s\n", - request->luser, request->ruser, request->rtty); - } - - return(0); -} - -int sendreply(request, reply) -struct talk_request *request; -struct talk_reply *reply; -{ -int s; -nwio_udpopt_t udpopt; -udp_io_hdr_t *udp_io_hdr; - - udpopt.nwuo_flags = NWUO_NOFLAGS; - udpopt.nwuo_flags |= NWUO_COPY | NWUO_LP_SET | NWUO_EN_LOC; - udpopt.nwuo_flags |= NWUO_DI_BROAD | NWUO_RP_SET | NWUO_RA_SET; - udpopt.nwuo_flags |= NWUO_RWDATONLY | NWUO_DI_IPOPT; - udpopt.nwuo_locport = ntalk_port; - udpopt.nwuo_remaddr = request->ctl_addr.sin_addr; - udpopt.nwuo_remport = request->ctl_addr.sin_port; - - s = ioctl(udp_out, NWIOSUDPOPT, &udpopt); - if(s < 0) { - perror("talkd: ioctl NWIOSUDPOPT"); - return(-1); - } - - s = ioctl(udp_out, NWIOGUDPOPT, &udpopt); - if(s < 0) { - perror("talkd: ioctl NWIOGUDPOPT"); - return(-1); - } - - if(opt_d) { - fprintf(stderr, "Reply: "); - fprintf(stderr, "%02x %02x %02x %02x ", - reply->version, reply->type, reply->answer, reply->junk); - fprintf(stderr, "%08lx ", reply->id); - fprintf(stderr, "%04x %08lx:%04x", - reply->addr.sa_family, reply->addr.sin_addr, reply->addr.sin_port); - fprintf(stderr, "\n"); - } - - s = write(udp_out, reply, sizeof(struct talk_reply)); - if(s < 0) { - perror("talkd: write"); - return(-1); - } - if(s != sizeof(struct talk_reply)) { - fprintf(stderr, "talkd: write size mismatch %d %d\n", - s, sizeof(struct talk_reply)); - return(-1); - } - - return(0); -} diff --git a/commands/talkd/net.h b/commands/talkd/net.h deleted file mode 100644 index 9254d3ca8..000000000 --- a/commands/talkd/net.h +++ /dev/null @@ -1,5 +0,0 @@ -/* net.h Copyright Michael Temari 07/22/1996 All Rights Reserved */ - -_PROTOTYPE(int NetInit, (void)); -_PROTOTYPE(int getrequest, (struct talk_request *request)); -_PROTOTYPE(int sendreply, (struct talk_request *request, struct talk_reply *reply)); diff --git a/commands/talkd/process.c b/commands/talkd/process.c deleted file mode 100644 index 02715c507..000000000 --- a/commands/talkd/process.c +++ /dev/null @@ -1,269 +0,0 @@ -/* process.c Copyright Michael Temari 07/22/1996 All Rights Reserved */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "talk.h" -#include "talkd.h" -#include "process.h" -#include "finduser.h" - -struct entry { - struct entry *prev; - struct talk_request rq; - time_t expire; - struct entry *next; -}; - -_PROTOTYPE(static int announce, (struct talk_request *request, char *rhost)); -_PROTOTYPE(static struct talk_request *lookup, (struct talk_request *request, int type)); -_PROTOTYPE(static int addreq, (struct talk_request *request)); -_PROTOTYPE(static delete_invite, (long id)); -_PROTOTYPE(static long nextid, (void)); -_PROTOTYPE(static void delete, (struct entry *e)); - -static struct entry *entry = (struct entry *)NULL; - -int processrequest(request, reply) -struct talk_request *request; -struct talk_reply *reply; -{ -char *p; -struct talk_request *rq; -struct hostent *hp; - - reply->version = TALK_VERSION; - reply->type = request->type; - reply->answer = 0; - reply->junk = 0; - reply->id = htonl(0); - - - /* check version */ - if(request->version != TALK_VERSION) { - reply->answer = BADVERSION; - return(0); - } - - /* check address family */ - if(ntohs(request->addr.sa_family) != AF_INET) { - reply->answer = BADADDR; - return(0); - } - - /* check control address family */ - if(ntohs(request->ctl_addr.sa_family) != AF_INET) { - reply->answer = BADCTLADDR; - return(0); - } - - /* check local name */ - p = request->luser; - while(*p) - if(!isprint(*p)) { - reply->answer = FAILED; - return(0); - } else - p++; - - switch(request->type) { - case ANNOUNCE: - reply->answer = find_user(request->ruser, request->rtty); - if(reply->answer != SUCCESS) break; - hp = gethostbyaddr((char *)&request->ctl_addr.sin_addr, sizeof(ipaddr_t), AF_INET); - if(hp == (struct hostent *)NULL) { - reply->answer = MACHINE_UNKNOWN; - break; - } - if((rq = lookup(request, 1)) == (struct talk_request *)NULL) { - reply->id = addreq(request); - reply->answer = announce(request, hp->h_name); - break; - } - if(ntohl(request->id) > ntohl(rq->id)) { - rq->id = nextid(); - reply->id = rq->id; - reply->answer = announce(request, hp->h_name); - } else { - reply->id = rq->id; - reply->answer = SUCCESS; - } - break; - case LEAVE_INVITE: - rq = lookup(request, 1); - if(rq == (struct talk_request *)NULL) - reply->id = addreq(request); - else { - reply->id = rq->id; - reply->answer = SUCCESS; - } - break; - case LOOK_UP: - if((rq = lookup(request, 0)) == (struct talk_request *)NULL) - reply->answer = NOT_HERE; - else { - reply->id = rq->id; - memcpy((char *)&reply->addr, (char *)&rq->addr, sizeof(reply->addr)); - reply->answer = SUCCESS; - } - break; - case DELETE: - reply->answer = delete_invite(request->id); - break; - default: - reply->answer = UNKNOWN_REQUEST; - } - - return(0); -} - -static int announce(request, rhost) -struct talk_request *request; -char *rhost; -{ -char tty[5+TTY_SIZE+1]; -struct stat st; -FILE *fp; -time_t now; -struct tm *tm; - - sprintf(tty, "/dev/%s", request->rtty); - - if(stat(tty, &st) < 0) - return(PERMISSION_DENIED); - - if(!(st.st_mode & S_IWGRP)) - return(PERMISSION_DENIED); - - if((fp = fopen(tty, "w")) == (FILE *)NULL) - return(PERMISSION_DENIED); - - (void) time(&now); - - tm = localtime(&now); - - fprintf(fp, "\007\007\007\rtalkd: Message from talkd@%s at %d:%02d:%02d\r\n", - myhostname, tm->tm_hour, tm->tm_min, tm->tm_sec); - fprintf(fp, "talkd: %s@%s would like to talk to you\r\n", - request->luser, rhost); - fprintf(fp, "talkd: to answer type: talk %s@%s\r\n", - request->luser, rhost); - - fclose(fp); - - return(SUCCESS); -} - -static struct talk_request *lookup(request, type) -struct talk_request *request; -int type; -{ -time_t now; -struct entry *e; - - (void) time(&now); - - for(e = entry; e != (struct entry *)NULL; e = e->next) { - if(now > e->expire) { - delete(e); - continue; - } - if(type == 0) { - if(!strncmp(request->luser, e->rq.ruser, USER_SIZE) && - !strncmp(request->ruser, e->rq.luser, USER_SIZE) && - e->rq.type == LEAVE_INVITE) - return(&e->rq); - } else { - if(request->type == e->rq.type && - request->pid == e->rq.pid && - !strncmp(request->luser, e->rq.luser, USER_SIZE) && - !strncmp(request->ruser, e->rq.ruser, USER_SIZE)) { - e->expire = now + MAX_LIFE; - return(&e->rq); - } - } - } - return((struct talk_request *)NULL); -} - -static int addreq(request) -struct talk_request *request; -{ -time_t now; -struct entry *e; - - (void) time(&now); - request->id = nextid(); - e = (struct entry *) malloc(sizeof(struct entry)); - if(e == (struct entry *)NULL) { - fprintf(stderr, "talkd: out of memory in insert table\n"); - exit(1); - } - e->expire = now + MAX_LIFE; - memcpy((char *)&e->rq, (char *)request, sizeof(struct talk_request)); - e->next = entry; - if(e->next != (struct entry *)NULL) - e->next->prev = e; - e->prev = (struct entry *)NULL; - entry = e; - return(request->id); -} - -static int delete_invite(id) -long id; -{ -time_t now; -struct entry *e; - - (void) time(&now); - - for(e = entry; e != (struct entry *)NULL; e = e->next) { - if(now > e->expire) { - delete(e); - continue; - } - if(e->rq.id == id) { - delete(e); - return(SUCCESS); - } - } - return(NOT_HERE); -} - -static void delete(e) -struct entry *e; -{ - if(e == (struct entry *)NULL) return; - - if(entry == e) - entry = e->next; - else - if(e->prev != (struct entry *)NULL) - e->prev->next = e->next; - - if(e->next != (struct entry *)NULL) - e->next->prev = e->prev; - - free((char *)e); - - return; -} - -static long nextid() -{ -static long id = 0; - - id++; - if(id <= 0) id = 1; - return(htonl(id)); -} diff --git a/commands/talkd/process.h b/commands/talkd/process.h deleted file mode 100644 index 79e02d28e..000000000 --- a/commands/talkd/process.h +++ /dev/null @@ -1,3 +0,0 @@ -/* process.h Copyright Michael Temari 07/22/1996 All Rights Reserved */ - -_PROTOTYPE(int processrequest, (struct talk_request *request, struct talk_reply *reply)); diff --git a/commands/talkd/talk.h b/commands/talkd/talk.h deleted file mode 100644 index e7ecbab11..000000000 --- a/commands/talkd/talk.h +++ /dev/null @@ -1,57 +0,0 @@ -/* talk.h Copyright Michael Temari 07/22/1996 All Rights Reserved */ - -#define USER_SIZE 12 -#define TTY_SIZE 16 -#define HOST_SIZE 255 - -struct osockaddr { - u16_t sa_family; - u16_t sin_port; - ipaddr_t sin_addr; - char junk[8]; -}; - -struct talk_request { - u8_t version; - u8_t type; - u8_t answer; - u8_t junk; - u32_t id; - struct osockaddr addr; - struct osockaddr ctl_addr; - long pid; - char luser[USER_SIZE]; - char ruser[USER_SIZE]; - char rtty[TTY_SIZE]; -}; - -struct talk_reply { - u8_t version; - u8_t type; - u8_t answer; - u8_t junk; - u32_t id; - struct osockaddr addr; -}; - -#define TALK_VERSION 1 - -/* message type values */ -#define LEAVE_INVITE 0 /* leave invitation with server */ -#define LOOK_UP 1 /* check for invitation by callee */ -#define DELETE 2 /* delete invitation by caller */ -#define ANNOUNCE 3 /* announce invitation by caller */ - -/* answer values */ -#define SUCCESS 0 /* operation completed properly */ -#define NOT_HERE 1 /* callee not logged in */ -#define FAILED 2 /* operation failed for unexplained reason */ -#define MACHINE_UNKNOWN 3 /* caller's machine name unknown */ -#define PERMISSION_DENIED 4 /* callee's tty doesn't permit announce */ -#define UNKNOWN_REQUEST 5 /* request has invalid type value */ -#define BADVERSION 6 /* request has invalid protocol version */ -#define BADADDR 7 /* request has invalid addr value */ -#define BADCTLADDR 8 /* request has invalid ctl_addr value */ - -#define MAX_LIFE 60 /* max time daemon saves invitations */ -#define RING_WAIT 30 /* time to wait before resending invitation */ diff --git a/commands/talkd/talkd.c b/commands/talkd/talkd.c deleted file mode 100644 index b7afb88f5..000000000 --- a/commands/talkd/talkd.c +++ /dev/null @@ -1,54 +0,0 @@ -/* talkd.c Copyright Michael Temari 07/22/1996 All Rights Reserved */ - -#include -#include -#include -#include -#include - -#include "talk.h" -#include "talkd.h" -#include "net.h" -#include "process.h" - -_PROTOTYPE(int main, (int argc, char *argv[])); - -int opt_d = 0; -char myhostname[HOST_SIZE+1]; - -int main(argc, argv) -int argc; -char *argv[]; -{ -struct talk_request request; -struct talk_reply reply; - - if(argc > 1) - if(strcmp(argv[1], "-d") || argc > 2) { - fprintf(stderr, "Usage: talkd [-d]\n"); - return(-1); - } else - opt_d = 1; - - if(getuid() != 0) { - fprintf(stderr, "talkd: Must be run as super user\n"); - return(-1); - } - - if(gethostname(myhostname, HOST_SIZE) < 0) { - fprintf(stderr, "talkd: Error getting hostname\n"); - return(-1); - } - - if(NetInit()) { - fprintf(stderr, "talkd: Error in NetInit\n"); - return(-1); - } - - while(getrequest(&request) == 0) { - if(processrequest(&request, &reply)) break; - if(sendreply(&request, &reply)) break; - } - - return(-1); -} diff --git a/commands/talkd/talkd.h b/commands/talkd/talkd.h deleted file mode 100644 index 075d9736a..000000000 --- a/commands/talkd/talkd.h +++ /dev/null @@ -1,4 +0,0 @@ -/* talkd.h Copyright Michael Temari 07/22/1996 All Rights Reserved */ - -extern int opt_d; /* debug option */ -extern char myhostname[]; diff --git a/commands/top/Makefile b/commands/top/Makefile deleted file mode 100644 index 75cd7e3e2..000000000 --- a/commands/top/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -PROG= top -MAN= - -DPADD+= ${LIBCURSES} -LDADD+= -lcurses - -.include diff --git a/common/include/Makefile.inc b/common/include/Makefile.inc index 15bfd7098..399e62ca7 100644 --- a/common/include/Makefile.inc +++ b/common/include/Makefile.inc @@ -2,7 +2,7 @@ .PATH: ${MINIXSRCDIR}/common/include -INCS+= curses.h env.h fetch.h hgfs.h lib.h libutil.h timers.h +INCS+= env.h fetch.h hgfs.h lib.h libutil.h timers.h INCS+= minix/acpi.h minix/ansi.h minix/audio_fw.h minix/bitmap.h \ minix/callnr.h minix/com.h minix/compiler.h minix/config.h \ diff --git a/common/include/curses.h b/common/include/curses.h deleted file mode 100644 index af1b0b329..000000000 --- a/common/include/curses.h +++ /dev/null @@ -1,226 +0,0 @@ -/* curses.h - defines macros and prototypes for curses */ - -#ifndef _CURSES_H -#define _CURSES_H - -#include -#include -#include - -typedef int bool; - -#ifndef TRUE -#define TRUE 1 -#endif -#ifndef FALSE -#define FALSE 0 -#endif -#ifndef ERR -#define ERR (-1) /* general error flag */ -#endif -#ifndef OK -#define OK 0 /* general OK flag */ -#endif - -/* Macros. */ -#define box(win,vc,hc) wbox(win,0,0,0,0,vc,hc) -#define addch(ch) waddch(stdscr,ch) -#define mvaddch(y,x,ch) (wmove(stdscr,y,x)==ERR?ERR:waddch(stdscr,ch)) -#define mvwaddch(win,y,x,ch) (wmove(win,y,x)==ERR?ERR:waddch(win,ch)) -#define getch() wgetch(stdscr) -#define mvgetch(y,x) (wmove(stdscr,y,x)==ERR?ERR:wgetch(stdscr)) -#define mvwgetch(win,y,x) (wmove(win,y,x)==ERR?ERR:wgetch(win)) -#define addstr(str) waddstr(stdscr,str) -#define mvaddstr(y,x,str) (wmove(stdscr,y,x)==ERR?ERR:waddstr(stdscr,str)) -#define mvwaddstr(win,y,x,str) (wmove(win,y,x)==ERR?ERR:waddstr(win,str)) -#define getstr(str) wgetstr(stdscr,str) -#define mvgetstr(y,x,str) (wmove(stdscr,y,x)==ERR?ERR:wgetstr(stdscr,str)) -#define mvwgetstr(win,y,x,str) (wmove(win,y,x)==ERR?ERR:wgetstr(win,str)) -#define move(y,x) wmove(stdscr,y,x) -#define clear() wclear(stdscr) -#define erase() werase(stdscr) -#define clrtobot() wclrtobot(stdscr) -#define mvclrtobot(y,x) (wmove(stdscr,y,x)==ERR?ERR:wclrtobot(stdscr)) -#define mvwclrtobot(win,y,x) (wmove(win,y,x)==ERR?ERR:wclrtobot(win)) -#define clrtoeol() wclrtoeol(stdscr) -#define mvclrtoeol(y,x) (wmove(stdscr,y,x)==ERR?ERR:wclrtoeol(stdscr)) -#define mvwclrtoeol(win,y,x) (wmove(win,y,x)==ERR?ERR:wclrtoeol(win)) -#define insertln() winsertln(stdscr) -#define mvinsertln(y,x) (wmove(stdscr,y,x)==ERR?ERR:winsertln(stdscr)) -#define mvwinsertln(win,y,x) (wmove(win,y,x)==ERR?ERR:winsertln(win)) -#define deleteln() wdeleteln(stdscr) -#define mvdeleteln(y,x) (wmove(stdscr,y,x)==ERR?ERR:wdeleteln(stdscr)) -#define mvwdeleteln(win,y,x) (wmove(win,y,x)==ERR?ERR:wdeleteln(win)) -#define refresh() wrefresh(stdscr) -#define inch() winch(stdscr) -#define insch(ch) winsch(stdscr,ch) -#define mvinsch(y,x,ch) (wmove(stdscr,y,x)==ERR?ERR:winsch(stdscr,ch)) -#define mvwinsch(win,y,x,ch) (wmove(win,y,x)==ERR?ERR:winsch(win,ch)) -#define delch() wdelch(stdscr) -#define mvdelch(y,x) (wmove(stdscr,y,x)==ERR?ERR:wdelch(stdscr)) -#define mvwdelch(win,y,x) (wmove(win,y,x)==ERR?ERR:wdelch(win)) -#define standout() wstandout(stdscr) -#define wstandout(win) ((win)->_attrs |= A_STANDOUT) -#define standend() wstandend(stdscr) -#define wstandend(win) ((win)->_attrs &= ~A_STANDOUT) -#define attrset(attrs) wattrset(stdscr, attrs) -#define wattrset(win, attrs) ((win)->_attrs = (attrs)) -#define attron(attrs) wattron(stdscr, attrs) -#define wattron(win, attrs) ((win)->_attrs |= (attrs)) -#define attroff(attrs) wattroff(stdscr,attrs) -#define wattroff(win, attrs) ((win)->_attrs &= ~(attrs)) -#define resetty() tcsetattr(1, TCSANOW, &_orig_tty) -#define getyx(win,y,x) (y = (win)->_cury, x = (win)->_curx) - -/* Video attribute definitions. */ -#define A_BLINK 0x0100 -#define A_BLANK 0 -#define A_BOLD 0x0200 -#define A_DIM 0 -#define A_PROTECT 0 -#define A_REVERSE 0x0400 -#define A_STANDOUT 0x0800 -#define A_UNDERLINE 0x1000 -#define A_ALTCHARSET 0x2000 - -/* Type declarations. */ -typedef struct { - int _cury; /* current pseudo-cursor */ - int _curx; - int _maxy; /* max coordinates */ - int _maxx; - int _begy; /* origin on screen */ - int _begx; - int _flags; /* window properties */ - int _attrs; /* attributes of written characters */ - int _tabsize; /* tab character size */ - bool _clear; /* causes clear at next refresh */ - bool _leave; /* leaves cursor as it happens */ - bool _scroll; /* allows window scrolling */ - bool _nodelay; /* input character wait flag */ - bool _keypad; /* flags keypad key mode active */ - int **_line; /* pointer to line pointer array */ - int *_minchng; /* First changed character in line */ - int *_maxchng; /* Last changed character in line */ - int _regtop; /* Top/bottom of scrolling region */ - int _regbottom; -} WINDOW; - -/* External variables */ -extern int LINES; /* terminal height */ -extern int COLS; /* terminal width */ -extern bool NONL; /* \n causes CR too ? */ -extern WINDOW *curscr; /* the current screen image */ -extern WINDOW *stdscr; /* the default screen window */ -extern struct termios _orig_tty, _tty; - -extern unsigned int ACS_ULCORNER; /* terminal dependent block grafic */ -extern unsigned int ACS_LLCORNER; /* charcters. Forget IBM, we are */ -extern unsigned int ACS_URCORNER; /* independent of their charset. :-) */ -extern unsigned int ACS_LRCORNER; -extern unsigned int ACS_RTEE; -extern unsigned int ACS_LTEE; -extern unsigned int ACS_BTEE; -extern unsigned int ACS_TTEE; -extern unsigned int ACS_HLINE; -extern unsigned int ACS_VLINE; -extern unsigned int ACS_PLUS; -extern unsigned int ACS_S1; -extern unsigned int ACS_S9; -extern unsigned int ACS_DIAMOND; -extern unsigned int ACS_CKBOARD; -extern unsigned int ACS_DEGREE; -extern unsigned int ACS_PLMINUS; -extern unsigned int ACS_BULLET; -extern unsigned int ACS_LARROW; -extern unsigned int ACS_RARROW; -extern unsigned int ACS_DARROW; -extern unsigned int ACS_UARROW; -extern unsigned int ACS_BOARD; -extern unsigned int ACS_LANTERN; -extern unsigned int ACS_BLOCK; - -_PROTOTYPE( char *unctrl, (int _c) ); -_PROTOTYPE( int baudrate, (void)); -_PROTOTYPE( void beep, (void)); -_PROTOTYPE( void cbreak, (void)); -_PROTOTYPE( void clearok, (WINDOW *_win, bool _flag) ); -_PROTOTYPE( void clrscr, (void)); -_PROTOTYPE( void curs_set, (int _visibility) ); -_PROTOTYPE( void delwin, (WINDOW *_win) ); -_PROTOTYPE( void doupdate, (void)); -_PROTOTYPE( void echo, (void)); -_PROTOTYPE( int endwin, (void)); -_PROTOTYPE( int erasechar, (void)); -_PROTOTYPE( void fatal, (char *_s) ); -_PROTOTYPE( int fixterm, (void)); -_PROTOTYPE( void flash, (void)); -_PROTOTYPE( void gettmode, (void)); -_PROTOTYPE( void idlok, (WINDOW *_win, bool _flag) ); -_PROTOTYPE( WINDOW *initscr, (void)); -_PROTOTYPE( void keypad, (WINDOW *_win, bool _flag) ); -_PROTOTYPE( int killchar, (void)); -_PROTOTYPE( void leaveok, (WINDOW *_win, bool _flag) ); -_PROTOTYPE( char *longname, (void)); -_PROTOTYPE( void meta, (WINDOW *_win, bool _flag) ); -_PROTOTYPE( int mvcur, (int _oldy, int _oldx, int _newy, int _newx) ); -_PROTOTYPE( int mvinch, (int _y, int _x) ); -_PROTOTYPE( int mvprintw, (int _y, int _x, const char *_fmt, ...) ); -_PROTOTYPE( int mvscanw, (int _y, int _x, const char *_fmt, ...) ); -_PROTOTYPE( int mvwin, (WINDOW *_win, int _begy, int _begx) ); -_PROTOTYPE( int mvwinch, (WINDOW *_win, int _y, int _x) ); -_PROTOTYPE( int mvwprintw, (WINDOW *_win, int _y, int _x, const char *_fmt, - ...) ); -_PROTOTYPE( int mvwscanw, (WINDOW *_win, int _y, int _x, const char *_fmt, - ...) ); -_PROTOTYPE( WINDOW *newwin, (int _num_lines, int _num_cols, int _y, int _x)); -_PROTOTYPE( void nl, (void)); -_PROTOTYPE( void nocbreak, (void)); -_PROTOTYPE( void nodelay, (WINDOW *_win, bool _flag) ); -_PROTOTYPE( void noecho, (void)); -_PROTOTYPE( void nonl, (void)); -_PROTOTYPE( void noraw, (void)); -_PROTOTYPE( void outc, (int _c) ); -_PROTOTYPE( void overlay, (WINDOW *_win1, WINDOW *_win2) ); -_PROTOTYPE( void overwrite, (WINDOW *_win1, WINDOW *_win2) ); -_PROTOTYPE( void poscur, (int _r, int _c) ); -_PROTOTYPE( int printw, (const char *_fmt, ...) ); -_PROTOTYPE( void raw, (void)); -_PROTOTYPE( int resetterm, (void)); -_PROTOTYPE( int saveoldterm, (void)); -_PROTOTYPE( int saveterm, (void)); -_PROTOTYPE( int savetty, (void)); -_PROTOTYPE( int scanw, (const char *_fmt, ...) ); -_PROTOTYPE( void scroll, (WINDOW *_win) ); -_PROTOTYPE( void scrollok, (WINDOW *_win, bool _flag) ); -_PROTOTYPE( int setscrreg, (int _top, int _bottom) ); -_PROTOTYPE( int setterm, (char *_type) ); -_PROTOTYPE( int setupterm, (void)); -_PROTOTYPE( WINDOW *subwin, (WINDOW *_orig, int _nlines, int _ncols, int _y, - int _x)); -_PROTOTYPE( int tabsize, (int _ts) ); -_PROTOTYPE( void touchwin, (WINDOW *_win) ); -_PROTOTYPE( int waddch, (WINDOW *_win, int _c) ); -_PROTOTYPE( int waddstr, (WINDOW *_win, char *_str) ); -_PROTOTYPE( int wbox, (WINDOW *_win, int _ymin, int _xmin, int _ymax, - int _xmax, unsigned int _v, unsigned int _h) ); -_PROTOTYPE( void wclear, (WINDOW *_win) ); -_PROTOTYPE( int wclrtobot, (WINDOW *_win) ); -_PROTOTYPE( int wclrtoeol, (WINDOW *_win) ); -_PROTOTYPE( int wdelch, (WINDOW *_win) ); -_PROTOTYPE( int wdeleteln, (WINDOW *_win) ); -_PROTOTYPE( void werase, (WINDOW *_win) ); -_PROTOTYPE( int wgetch, (WINDOW *_win) ); -_PROTOTYPE( int wgetstr, (WINDOW *_win, char *_str) ); -_PROTOTYPE( int winch, (WINDOW *_win) ); -_PROTOTYPE( int winsch, (WINDOW *_win, int _c) ); -_PROTOTYPE( int winsertln, (WINDOW *_win) ); -_PROTOTYPE( int wmove, (WINDOW *_win, int _y, int _x) ); -_PROTOTYPE( void wnoutrefresh, (WINDOW *_win) ); -_PROTOTYPE( int wprintw, (WINDOW *_win, const char *_fmt, ...)); -_PROTOTYPE( void wrefresh, (WINDOW *_win) ); -_PROTOTYPE( int wscanw, (WINDOW *_win, const char *_fmt, ...)); -_PROTOTYPE( int wsetscrreg, (WINDOW *_win, int _top, int _bottom) ); -_PROTOTYPE( int wtabsize, (WINDOW *_win, int _ts) ); - -#endif /* _CURSES_H */ diff --git a/etc/mtree/minix.tree b/etc/mtree/minix.tree index b8ccec598..5963990b4 100644 --- a/etc/mtree/minix.tree +++ b/etc/mtree/minix.tree @@ -72,6 +72,9 @@ 700 root operator /usr/preserve 755 root operator /usr/run 755 root operator /usr/share +755 root operator /usr/share/doc +755 root operator /usr/share/doc/psd +755 root operator /usr/share/doc/psd/19.curses 755 root operator /usr/share/mk 755 root operator /usr/share/terminfo 755 root operator /usr/share/zoneinfo diff --git a/include/Makefile b/include/Makefile index 4ed6f85fa..1d3026ef7 100644 --- a/include/Makefile +++ b/include/Makefile @@ -1,7 +1,7 @@ # Doing a make includes builds /usr/include INCS= alloca.h a.out.h ar.h assert.h configfile.h ctype.h \ - curses.h dirent.h env.h err.h errno.h fcntl.h fenv.h \ + dirent.h env.h err.h errno.h fcntl.h fenv.h \ float.h fnmatch.h fts.h getopt.h glob.h grp.h ifaddrs.h \ inttypes.h libgen.h libutil.h limits.h locale.h \ mathconst.h math.h midiparser.h netdb.h pwd.h regex.h \ diff --git a/lib/Makefile b/lib/Makefile index 6f3832608..afa06c13b 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -14,14 +14,14 @@ LIBCOMPAT_DIR?= LIBMINLIB_DIR?= LIBASYN_DIR?= -SUBDIR= csu ${LIBCOMPAT_DIR} ${LIBC_DIR} libcurses libdriver libnetdriver \ +SUBDIR= csu ${LIBCOMPAT_DIR} ${LIBC_DIR} libdriver libnetdriver \ libedit ${LIBM_DIR} libsys libtimers libutil libbz2 libl libhgfs \ libz libfetch libarchive libvtreefs libaudiodriver libmthread \ libexec libdevman libusb ${LIBMINLIB_DIR} ${LIBASYN_DIR} \ libddekit .if defined(NBSD_LIBC) && (${NBSD_LIBC} != "no") -SUBDIR+= libelf libminc libcrypt libterminfo +SUBDIR+= libelf libminc libcrypt libterminfo libcurses .endif .if ${COMPILER_TYPE} == "ack" diff --git a/lib/libcurses/EXAMPLES/Makefile b/lib/libcurses/EXAMPLES/Makefile new file mode 100644 index 000000000..b3759fdc5 --- /dev/null +++ b/lib/libcurses/EXAMPLES/Makefile @@ -0,0 +1,54 @@ +#$Id: Makefile,v 1.2 2007/05/28 15:01:58 blymn Exp $ +#$Log: Makefile,v $ +#Revision 1.2 2007/05/28 15:01:58 blymn +#Merge in wide curses code done as a Summer of Code project by +#Ruibiao Qiu. +# +#Revision 1.1.2.2 2007/01/31 10:08:47 blymn +#Fix up build errors. +# +#Revision 1.1.2.1 2007/01/21 12:05:54 blymn +#Merge wide curses. +# +#Revision 1.1 2007/01/21 11:38:59 blymn +#Wide curses merge +# +#Revision 1.1 2005/08/31 14:52:08 ruibiao +# +#A patach for the current source +# +#Revision 1.2 2005/08/23 21:29:08 ruibiao +# +#Changed to the right libraries +# +#Revision 1.1 2005/08/23 16:38:22 ruibiao +# +#Initial version, to build all versions of file views and the unit tester +# + +RM = /bin/rm -f +CFLAGS = + +.if defined(DEBUG) +CFLAGS+= -g +.endif + +all: wcview nwview ccview tcview ncview ex1 + +wcview: view.c + gcc -DHAVE_WCHAR -o wcview view.c -I.. $(CFLAGS) -lcurses -Wl,-rpath,.. -L.. + +nwview: view.c + gcc -DHAVE_WCHAR -o nwview view.c -DNCURSES -I/usr/pkg/include $(CFLAGS) -lcurses -Wl,-rpath,/usr/pkg/lib -L/usr/pkg/lib + +ccview: view.c + gcc -o ccview view.c -I.. $(CFLAGS) -lcurses -Wl,-rpath,.. -L.. + +tcview: view.c + gcc -o tcview view.c -L/usr/lib -Wl,-rpath,/usr/lib $(CFLAGS) -lcurses + +ncview: view.c + gcc -o ncview view.c -I/usr/pkg/include -DNCURSES -L/usr/pkg/lib -Wl,-rpath,/usr/pkg/lib $(CFLAGS) -lncurses + +ex1: ex1.c + gcc -DHAVE_WCHAR -o ex1 ex1.c -I.. $(CFLAGS) -lcurses -Wl,-rpath,.. -L.. diff --git a/lib/libcurses/EXAMPLES/ex1.c b/lib/libcurses/EXAMPLES/ex1.c new file mode 100644 index 000000000..e71ed33d0 --- /dev/null +++ b/lib/libcurses/EXAMPLES/ex1.c @@ -0,0 +1,342 @@ +/* $NetBSD: ex1.c,v 1.5 2007/05/28 15:01:58 blymn Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +static char copyright[] = +"@(#) Copyright (c) 1992, 1993\n\ + The Regents of the University of California. All rights reserved.\n"; +#endif /* not lint */ + +#ifndef lint +static char sccsid[] = "@(#)ex1.c 8.1 (Berkeley) 6/4/93"; +#endif /* not lint */ +#include +#include +#include +#include +#include +#include +#include +#include + +#define YSIZE 4 +#define XSIZE 30 + +void quit( int ); + +main() +{ + int i, j, c, n = 0, ac = 0; + size_t len; + char id[100]; + FILE *fp; + char *s; + cchar_t cc, ncc, cstr[ 128 ], icc, icstr[ 128 ], bcc; + int wc_on = 0, wgc_on = 0; + char mbs[] = "´ó"; + char mbstr[] = "´óѧ֮µÀ£¬ÔÚÃ÷Ã÷µÂ£¬ÔÚÇ×Ãñ£¬ÔÚÖ¹ÓÚÖÁÉÆ¡£ (Liji)"; + wchar_t wstr[ 128 ], owstr[ 4 ], gwstr[ 128 ], iwstr[ 128 ]; + int wslen = 0; + wint_t wc; + char nostr[ 128 ]; + attr_t al[ 15 ] = { WA_BLINK, + WA_BOLD, + WA_DIM, + WA_LOW, + WA_TOP, + WA_INVIS, + WA_HORIZONTAL, + WA_VERTICAL, + WA_LEFT, + WA_RIGHT, + WA_PROTECT, + WA_REVERSE, + WA_STANDOUT, + WA_UNDERLINE }; + + fprintf( stderr, "Current locale: %s\n", setlocale(LC_ALL, "")); + if (( wslen = mbstowcs( &cc.vals[ 0 ], mbs, strlen( mbs ))) < 0 ) { + fprintf( stderr, "mbstowcs() failed\n" ); + return -1; + } + fprintf( stderr, "WC string length: %d\n", wslen ); + fprintf( stderr, "WC width: %d\n", wcwidth( cc.vals[ 0 ])); + cc.elements = ncc.elements = 8; + cc.attributes = ncc.attributes = 0; + ncc.vals[ 0 ] = 0xda00; + cc.vals[ 1 ] = ncc.vals[ 1 ] = 0xda01; + cc.vals[ 2 ] = ncc.vals[ 2 ] = 0xda02; + cc.vals[ 3 ] = ncc.vals[ 3 ] = 0xda03; + cc.vals[ 4 ] = ncc.vals[ 4 ] = 0xda04; + cc.vals[ 5 ] = ncc.vals[ 5 ] = 0xda05; + cc.vals[ 6 ] = ncc.vals[ 6 ] = 0xda06; + cc.vals[ 7 ] = ncc.vals[ 7 ] = 0xda07; + + if (( wslen = mbstowcs( wstr, mbstr, strlen( mbstr ))) < 0 ) { + fprintf( stderr, "mbstowcs() failed\n" ); + return -1; + } + + for ( i = 0; i < wslen; i++ ) { + cstr[ i ].vals[ 0 ] = wstr[ i ]; + } + cstr[ wslen ].vals[ 0 ] = 0; + + bcc.elements = 8; + bcc.attributes = 0; + bcc.vals[ 0 ] = L'_'; + bcc.vals[ 1 ] = 0xda01; + bcc.vals[ 2 ] = 0xda02; + bcc.vals[ 3 ] = 0xda03; + bcc.vals[ 4 ] = 0xda04; + bcc.vals[ 5 ] = 0xda05; + bcc.vals[ 6 ] = 0xda06; + bcc.vals[ 7 ] = 0xda07; + + initscr(); /* Always call initscr() first */ + signal(SIGINT, quit); /* Make sure wou have a 'cleanup' fn */ + crmode(); /* We want cbreak mode */ + noecho(); /* We want to have control of chars */ + delwin(stdscr); /* Create our own stdscr */ + stdscr = newwin(YSIZE, XSIZE, 1, 1); + flushok(stdscr, TRUE); /* Enable flushing of stdout */ + scrollok(stdscr, TRUE); /* Enable scrolling */ + erase(); /* Initially, clear the screen */ + + standout(); + move(0,0); + while (1) { + if ( !wgc_on ) { + c = getchar(); + switch(c) { + case 'q': /* Quit on 'q' */ + quit( 0 ); + break; + case 'p': + keypad( stdscr, TRUE ); + break; + case 'P': + keypad( stdscr, FALSE ); + break; + case 'g': + wgc_on = 1; + echo(); + break; + case 'b': + get_wstr( gwstr ); + move( 1, 0 ); + addstr( "Input:" ); + addwstr( gwstr ); + refresh(); + break; + case 'h': + move( 0, 0 ); + in_wch( &icc ); + move( 1, 0 ); + add_wch( &icc ); + refresh(); + break; + case 'y': + move( 0, 0 ); + in_wchstr( icstr ); + move( 1, 0 ); + add_wchstr( icstr ); + refresh(); + break; + case 'u': + move( 0, 0 ); + inwstr( iwstr ); + move( 1, 0 ); + addwstr( iwstr ); + refresh(); + break; + case 'i': + move( 0, 0 ); + hline_set( &cc, 20 ); + move( 0, 0 ); + vline_set( &cc, 20 ); + refresh(); + break; + case 'o': + clrtobot(); + refresh(); + break; + case 's': /* Go into standout mode on 's' */ + standout(); + break; + case 'e': /* Exit standout mode on 'e' */ + standend(); + break; + case 'r': /* Force a refresh on 'r' */ + wrefresh(curscr); + break; + case 'w': /* Turn on/off add_wch() tests */ + wc_on = 1 - wc_on; + break; + case 'd': + add_wchstr(( const cchar_t *)&cstr ); + refresh(); + break; + case 'c': + addwstr(( const wchar_t *)&wstr ); + refresh(); + break; + case 'z': + move( 0, 1 ); + if ( wc_on ) + add_wch( &cc ); + else + addch( c ); + refresh(); + break; + case 'x': + move( 0, 3 ); + if ( wc_on ) + add_wch( &cc ); + else + addch( c ); + refresh(); + break; + case 'n': + add_wch( &ncc ); + refresh(); + break; + case 'm': + //border( 0, 0, 0, 0, 0, 0, 0, 0 ); + border_set( NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ); + refresh(); + break; + case 'j': + box_set( stdscr, &cc, &cc ); + refresh(); + break; + case 'k': + erase(); + refresh(); + break; + case '1': + move( 0, 0 ); + clrtoeol(); + refresh(); + break; + case '2': + move( 0, 0 ); + sprintf( nostr, "Orig:%x", al[ ac ]); + addstr( nostr ); + ac = ( ac + 1 ) % 16; + bcc.attributes = al[ ac ]; + bkgrnd( &bcc ); + move( 1, 0 ); + sprintf( nostr, "New:%x", al[ ac ]); + //addstr( nostr ); + insstr( nostr ); + refresh(); + break; + case 'v': + if ( wc_on ) + ins_wch( &cc ); + else + insch( c ); + refresh(); + break; + case 'f': + ins_wstr(( const wchar_t *)&wstr ); + refresh(); + break; + case 't': + for ( i = 0; i < 4; i++ ) { + owstr[ i ] = wstr[ i + 5 ]; + wstr[ i + 5 ] = i + 0xda05; + } + ins_wstr(( const wchar_t *)&wstr ); + refresh(); + for ( i = 0; i < 4; i++ ) + wstr[ i + 5 ] = owstr[ i ]; + break; + default: /* By default output the character */ + if ( wc_on ) + add_wch( &cc ); + else { + if ( c < 0x7F ) + addch( c ); + else { + addstr( keyname( c )); + } + } + refresh(); + } + } else { + get_wch( &wc ); + switch ( wc ) { + case L'w': + wgc_on = 0; + noecho(); + break; + case L'q': + quit( 0 ); + break; + case L't': + notimeout( stdscr, TRUE ); + break; + case L'T': + notimeout( stdscr, FALSE ); + break; + case L'd': + nodelay( stdscr, TRUE ); + break; + case L'D': + nodelay( stdscr, FALSE ); + break; + case L'p': + keypad( stdscr, TRUE ); + break; + case L'P': + keypad( stdscr, FALSE ); + break; + default: + break; + } + } + } +} + +void quit( int sig ) +{ + erase(); /* Terminate by erasing the screen */ + refresh(); + endwin(); /* Always end with endwin() */ + delwin(curscr); /* Return storage */ + delwin(stdscr); + putchar('\n'); + exit( sig ); +} + diff --git a/lib/libcurses/EXAMPLES/view.c b/lib/libcurses/EXAMPLES/view.c new file mode 100644 index 000000000..74df2a83d --- /dev/null +++ b/lib/libcurses/EXAMPLES/view.c @@ -0,0 +1,527 @@ +/* + * view.c -- a silly little viewer program + * + * written by Eric S. Raymond December 1994 + * to test the scrolling code in ncurses. + * + * modified by Thomas Dickey July 1995 to demonstrate + * the use of 'resizeterm()', and May 2000 to illustrate wide-character + * handling. + * + * Takes a filename argument. It's a simple file-viewer with various + * scroll-up and scroll-down commands. + * + * n -- scroll one line forward + * p -- scroll one line back + * + * Either command accepts a numeric prefix interpreted as a repeat count. + * Thus, typing `5n' should scroll forward 5 lines in the file. + * + * The way you can tell this is working OK is that, in the trace file, + * there should be one scroll operation plus a small number of line + * updates, as opposed to a whole-page update. This means the physical + * scroll operation worked, and the refresh() code only had to do a + * partial repaint. + * + * $Id: view.c,v 1.2 2007/05/28 15:01:58 blymn Exp $ + */ + +#include +#include +#include +#include +#ifdef NCURSES +#define _XOPEN_SOURCE_EXTENDED +#include +#include +#else +#include +#endif /* NCURSES */ +#include +#include +#include +#include +#include +#include +#ifdef HAVE_WCHAR +#include +#endif /* HAVE_WCHAR */ +#ifdef DEBUG +#include +#endif /* DEBUG */ + +#define UChar(c) ((unsigned char)(c)) +#define SIZEOF(table) (sizeof(table)/sizeof(table[0])) +#define typeMalloc(type,n) (type *) malloc((n) * sizeof(type)) + +#define my_pair 1 + +#undef CURSES_CH_T +#ifdef HAVE_WCHAR +#define CURSES_CH_T cchar_t +#else +#define CURSES_CH_T chtype +#endif /* HAVE_WCHAR */ + +static void finish(int sig); +static void show_all(const char *tag); + +static int shift = 0; +static bool try_color = FALSE; + +static char *fname; +static CURSES_CH_T **my_lines; +static CURSES_CH_T **lptr; +static unsigned num_lines; + +static void usage(void) +{ + static const char *msg[] = { + "Usage: view [options] file" + ,"" + ,"Options:" + ," -c use color if terminal supports it" + ," -i ignore INT, QUIT, TERM signals" + ," -n NUM specify maximum number of lines (default 1000)" +#if defined(KEY_RESIZE) + ," -r use old-style sigwinch handler rather than KEY_RESIZE" +#endif +#ifdef TRACE + ," -t trace screen updates" + ," -T NUM specify trace mask" +#endif + }; + size_t n; + for (n = 0; n < SIZEOF(msg); n++) + fprintf(stderr, "%s\n", msg[n]); + exit( 1 ); +} + +static int ch_len(CURSES_CH_T * src) +{ + int result = 0; + +#ifdef HAVE_WCHAR + while (getcchar(src++, NULL, NULL, NULL, NULL) > 0) + result++; +#else + while (*src++) + result++; +#endif + return result; +} + +/* + * Allocate a string into an array of chtype's. If UTF-8 mode is + * active, translate the string accordingly. + */ +static CURSES_CH_T * ch_dup(char *src) +{ + unsigned len = strlen(src); + CURSES_CH_T *dst = typeMalloc(CURSES_CH_T, len + 1); + unsigned j, k; +#ifdef HAVE_WCHAR + wchar_t wstr[CCHARW_MAX + 1]; + wchar_t wch; + int l = 0; + mbstate_t state; + size_t rc; + int width; +#endif + +#ifdef HAVE_WCHAR + mbrtowc( NULL, NULL, 1, &state ); +#endif + for (j = k = 0; j < len; j++) { +#ifdef HAVE_WCHAR + rc = mbrtowc(&wch, src + j, len - j, &state); +#ifdef DEBUG + syslog( LOG_INFO, "[ch_dup]mbrtowc() returns %d", rc ); +#endif /* DEBUG */ + if (rc == (size_t) -1 || rc == (size_t) -2) + break; + j += rc - 1; + if ((width = wcwidth(wch)) < 0) + break; + if ((width > 0 && l > 0) || l == CCHARW_MAX) { + wstr[l] = L'\0'; + l = 0; + if (setcchar(dst + k, wstr, 0, 0, NULL) != OK) + break; + ++k; + } + if (width == 0 && l == 0) + wstr[l++] = L' '; + wstr[l++] = wch; +#ifdef DEBUG + syslog( LOG_INFO, "[ch_dup]wch=%x", wch ); +#endif /* DEBUG */ +#else + dst[k++] = src[j]; +#endif + } +#ifdef HAVE_WCHAR + if (l > 0) { + wstr[l] = L'\0'; + if (setcchar(dst + k, wstr, 0, 0, NULL) == OK) + ++k; + } + setcchar(dst + k, L"", 0, 0, NULL); +#else + dst[k] = 0; +#endif + return dst; +} + +int main(int argc, char *argv[]) +{ + int MAXLINES = 1000; + FILE *fp; + char buf[BUFSIZ]; + int i; + int my_delay = 0; + CURSES_CH_T **olptr; + int length = 0; + int value = 0; + bool done = FALSE; + bool got_number = FALSE; + const char *my_label = "Input"; +#ifdef HAVE_WCHAR + cchar_t icc; +#endif /* HAVE_WCHAR */ + + setlocale(LC_ALL, ""); + + (void) signal(SIGINT, finish); /* arrange interrupts to terminate */ + + while ((i = getopt(argc, argv, "cin:rtT:")) != EOF) { + switch (i) { + case 'c': + try_color = TRUE; + break; + case 'i': + signal(SIGINT, SIG_IGN); + signal(SIGQUIT, SIG_IGN); + signal(SIGTERM, SIG_IGN); + break; + case 'n': + if ((MAXLINES = atoi(optarg)) < 1) + usage(); + break; +#ifdef TRACE + case 'T': + trace(atoi(optarg)); + break; + case 't': + trace(TRACE_CALLS); + break; +#endif + default: + usage(); + } + } + if (optind + 1 != argc) + usage(); + + if ((my_lines = typeMalloc(CURSES_CH_T *, MAXLINES + 2)) == 0) + usage(); + + fname = argv[optind]; + if ((fp = fopen(fname, "r")) == 0) { + perror(fname); + exit( 1 ); + } + + /* slurp the file */ + num_lines = 0; + for (lptr = &my_lines[0]; (lptr - my_lines) < MAXLINES; lptr++) { + char temp[BUFSIZ], *s, *d; + int col; + + if (fgets(buf, sizeof(buf), fp) == 0) + break; + + /* convert tabs so that shift will work properly */ + for (s = buf, d = temp, col = 0; (*d = *s) != '\0'; s++) { + if (*d == '\n') { + *d = '\0'; + break; + } else if (*d == '\t') { + col = (col | 7) + 1; + while ((d - temp) != col) + *d++ = ' '; + } else +#ifdef HAVE_WCHAR + col++, d++; +#else + if (isprint(UChar(*d))) { + col++; + d++; + } else { + sprintf(d, "\\%03o", UChar(*s)); + d += strlen(d); + col = (d - temp); + } +#endif + } + *lptr = ch_dup(temp); + num_lines++; + } + (void) fclose(fp); + length = lptr - my_lines; + + (void) initscr(); /* initialize the curses library */ + keypad(stdscr, TRUE); /* enable keyboard mapping */ + (void) nonl(); /* tell curses not to do NL->CR/NL on output */ + (void) cbreak(); /* take input chars one at a time, no wait for \n */ + (void) noecho(); /* don't echo input */ + nodelay(stdscr, TRUE); + idlok(stdscr, TRUE); /* allow use of insert/delete line */ + + if (try_color) { + if (has_colors()) { + start_color(); + init_pair(my_pair, COLOR_WHITE, COLOR_BLUE); + bkgd(COLOR_PAIR(my_pair)); + } else { + try_color = FALSE; + } + } + + lptr = my_lines; + while (!done) { + int n; +#ifdef HAVE_WCHAR + wint_t c = 0; + int ret; +#else + int c = 0; +#endif /* HAVE_WCHAR */ + + if (!got_number) + show_all(my_label); + + n = 0; + for (;;) { + c = 0; +#ifdef HAVE_WCHAR + ret = get_wch( &c ); + if ( ret == ERR ) { + if (!my_delay) + napms(50); + continue; + } +#ifdef DEBUG + else if ( ret == KEY_CODE_YES ) + syslog( LOG_INFO, "[main]Func key(%x)", c ); + else + syslog( LOG_INFO, "[main]c=%x", c ); +#endif /* DEBUG */ +#else + c = getch(); +#ifdef DEBUG + syslog( LOG_INFO, "[main]c='%c'", c ); +#endif /* DEBUG */ +#endif /* HAVE_WCHAR */ + if ((c < 127) && isdigit(c)) { + if (!got_number) { + mvprintw(0, 0, "Count: "); + clrtoeol(); + } + addch(c); + value = 10 * value + (c - '0'); + got_number = TRUE; + } else + break; + } + if (got_number && value) { + n = value; + } else { + n = 1; + } + +#ifdef HAVE_WCHAR + if (ret != ERR) + my_label = key_name( c ); + else + if (!my_delay) + napms(50); +#else + if (c != ERR) + my_label = keyname(c); +#endif /* HAVE_WCHAR */ + switch (c) { + case KEY_DOWN: +#ifdef HAVE_WCHAR + case L'n': +#else + case 'n': +#endif /* HAVE_WCHAR */ + olptr = lptr; + for (i = 0; i < n; i++) + if ((lptr - my_lines) < (length - LINES + 1)) + lptr++; + else + break; + wscrl(stdscr, lptr - olptr); + break; + + case KEY_UP: +#ifdef HAVE_WCHAR + case L'p': +#else + case 'p': +#endif /* HAVE_WCHAR */ + olptr = lptr; + for (i = 0; i < n; i++) + if (lptr > my_lines) + lptr--; + else + break; + wscrl(stdscr, lptr - olptr); + break; + +#ifdef HAVE_WCHAR + case L'h': +#else + case 'h': +#endif /* HAVE_WCHAR */ + case KEY_HOME: + lptr = my_lines; + break; + +#ifdef HAVE_WCHAR + case L'e': +#else + case 'e': +#endif /* HAVE_WCHAR */ + case KEY_END: + if (length > LINES) + lptr = my_lines + length - LINES + 1; + else + lptr = my_lines; + break; + +#ifdef HAVE_WCHAR + case L'r': +#else + case 'r': +#endif /* HAVE_WCHAR */ + case KEY_RIGHT: + shift += n; + break; + +#ifdef HAVE_WCHAR + case L'l': +#else + case 'l': +#endif /* HAVE_WCHAR */ + case KEY_LEFT: + shift -= n; + if (shift < 0) { + shift = 0; + beep(); + } + break; + +#ifdef HAVE_WCHAR + case L'q': +#else + case 'q': +#endif /* HAVE_WCHAR */ + done = TRUE; + break; + +#ifdef KEY_RESIZE + case KEY_RESIZE: + //refresh(); + break; +#endif +#ifdef HAVE_WCHAR + case L's': +#else + case 's': +#endif /* HAVE_WCHAR */ + if (got_number) { + halfdelay(my_delay = n); + } else { + nodelay(stdscr, FALSE); + my_delay = -1; + } + break; +#ifdef HAVE_WCHAR + case L' ': +#else + case ' ': +#endif /* HAVE_WCHAR */ + nodelay(stdscr, TRUE); + my_delay = 0; + break; +#ifndef HAVE_WCHAR + case ERR: + if (!my_delay) + napms(50); + break; +#endif /* HAVE_WCHAR */ + default: + beep(); + break; + } + if (c >= KEY_MIN || (c > 0 && !isdigit(c))) { + got_number = FALSE; + value = 0; + } + } + + finish(0); /* we're done */ +} + +static void finish(int sig) +{ + endwin(); + exit(sig != 0 ? 1 : 0 ); +} + +static void show_all(const char *tag) +{ + int i; + char temp[BUFSIZ]; + CURSES_CH_T *s; + time_t this_time; + + sprintf(temp, "%s (%3dx%3d) col %d ", tag, LINES, COLS, shift); + i = strlen(temp); + sprintf(temp + i, "view %.*s", (int) (sizeof(temp) - 7 - i), fname); + move(0, 0); + printw("%.*s", COLS, temp); + clrtoeol(); + this_time = time((time_t *) 0); + strcpy(temp, ctime(&this_time)); + if ((i = strlen(temp)) != 0) { + temp[--i] = 0; + if (move(0, COLS - i - 2) != ERR) + printw(" %s", temp); + } + + scrollok(stdscr, FALSE); /* prevent screen from moving */ + for (i = 1; i < LINES; i++) { + move(i, 0); + printw("%3ld:", (long) (lptr + i - my_lines)); + clrtoeol(); + if ((s = lptr[i - 1]) != 0) { + if (i < num_lines) { + int len = ch_len(s); + if (len > shift) { +#ifdef HAVE_WCHAR + add_wchstr(s + shift); +#else + addchstr(s + shift); +#endif + } + } + } + } + setscrreg(1, LINES - 1); + scrollok(stdscr, TRUE); + refresh(); +} diff --git a/lib/libcurses/Makefile b/lib/libcurses/Makefile index f2f945b3d..3f696e2d0 100644 --- a/lib/libcurses/Makefile +++ b/lib/libcurses/Makefile @@ -1,45 +1,186 @@ -# Makefile for libcurses - -LIB= curses - -SRCS= \ - beep.c \ - charpick.c \ - curs_set.c \ - cursesio.c \ - endwin.c \ - flash.c \ - initscr.c \ - longname.c \ - move.c \ - mvcursor.c \ - newwin.c \ - options.c \ - overlay.c \ - prntscan.c \ - refresh.c \ - scrreg.c \ - setterm.c \ - tabsize.c \ - termmisc.c \ - unctrl.c \ - update.c \ - waddch.c \ - waddstr.c \ - wbox.c \ - wclear.c \ - wclrtobot.c \ - wclrtoeol.c \ - wdelch.c \ - wdeleteln.c \ - werase.c \ - wgetch.c \ - wgetstr.c \ - windel.c \ - winmove.c \ - winsch.c \ - winscrol.c \ - winsertln.c \ - wintouch.c +# $NetBSD: Makefile,v 1.64 2010/02/03 15:34:40 roy Exp $ +# @(#)Makefile 8.2 (Berkeley) 1/2/94 + +.include + +WARNS= 2 + +CPPFLAGS+=-I${.CURDIR} -I${NETBSDSRCDIR}/lib/libterminfo +.if defined(DEBUG_CURSES) +CPPFLAGS+=-g -DDEBUG +.endif +.if defined(SMALL) +CPPFLAGS+=-DSMALL +.endif +LIB= curses +SRCS= acs.c addbytes.c addch.c addchnstr.c addnstr.c attributes.c \ + background.c bell.c border.c box.c chgat.c clear.c clearok.c \ + clrtobot.c clrtoeol.c color.c copywin.c cr_put.c \ + ctrace.c cur_hash.c curs_set.c \ + curses.c delch.c deleteln.c delwin.c echochar.c erase.c fileio.c \ + flushok.c fullname.c getch.c getstr.c getyx.c id_subwins.c idlok.c \ + idcok.c inch.c inchstr.c initscr.c insch.c insdelln.c insertln.c \ + instr.c keypad.c keyname.c leaveok.c line.c meta.c move.c \ + mvwin.c newwin.c nodelay.c notimeout.c overlay.c overwrite.c pause.c \ + printw.c putchar.c refresh.c resize.c scanw.c screen.c scroll.c \ + scrollok.c setterm.c standout.c timeout.c toucholap.c touchwin.c \ + tstp.c tty.c unctrl.c underscore.c + +MAN= curses.3 curses_addch.3 curses_addchstr.3 curses_addstr.3 \ + curses_attributes.3 curses_background.3 curses_border.3 \ + curses_chgat.3 curses_clear.3 curses_color.3 \ + curses_cursor.3 curses_default_colors.3 \ + curses_delch.3 curses_deleteln.3 curses_echochar.3 curses_fileio.3 \ + curses_inch.3 curses_input.3 curses_insertch.3 curses_insertln.3 \ + curses_insdelln.3 curses_keyname.3 curses_line.3 curses_pad.3 \ + curses_print.3 curses_refresh.3 curses_scanw.3 curses_screen.3 \ + curses_scroll.3 curses_standout.3 curses_termcap.3 curses_touch.3 \ + curses_tty.3 curses_underscore.3 curses_window.3 +INCS= curses.h unctrl.h +INCSDIR=/usr/include + +LIBDPLIBS+= terminfo ${.CURDIR}/../libterminfo + +.if !defined(DISABLE_WCHAR) +CPPFLAGS+=-DHAVE_WCHAR +SRCS+= cchar.c add_wch.c add_wchstr.c addwstr.c echo_wchar.c ins_wch.c \ + insstr.c ins_wstr.c get_wch.c get_wstr.c in_wch.c in_wchstr.c \ + inwstr.c +.else +CPPFLAGS+=-DDISABLE_WCHAR +.endif + +MLINKS+= curses_addch.3 addch.3 curses_addchstr.3 addchnstr.3 \ + curses_addchstr.3 addchstr.3 curses_addstr.3 addnstr.3 \ + curses_addstr.3 addstr.3 \ + curses_default_colors.3 assume_default_colors.3 \ + curses_attributes.3 attr_get.3 curses_attributes.3 attr_off.3 \ + curses_attributes.3 attr_on.3 curses_attributes.3 attr_set.3 \ + curses_attributes.3 attron.3 curses_attributes.3 attroff.3 \ + curses_attributes.3 attrset.3 curses_tty.3 beep.3 \ + curses_background.3 bkgd.3 curses_background.3 bkgdset.3 \ + curses_border.3 border.3 curses_border.3 box.3 \ + curses_chgat.3 chgat.3 curses_chgat.3 mvchgat.3 \ + curses_chgat.3 mvwchgat.3 curses_chgat.3 wchgat.3 \ + curses_color.3 can_change_color.3 curses_tty.3 cbreak.3 \ + curses_clear.3 clear.3 curses_clear.3 clearok.3 \ + curses_clear.3 clrtobot.3 curses_clear.3 clrtoeol.3 \ + curses_color.3 color_content.3 curses_attributes.3 color_set.3 \ + curses_window.3 copywin.3 curses_tty.3 curs_set.3 \ + curses_tty.3 delay_output.3 curses_tty.3 def_prog_mode.3 \ + curses_tty.3 def_shell_mode.3 curses_delch.3 delch.3 \ + curses_deleteln.3 deleteln.3 curses_screen.3 delscreen.3 \ + curses_window.3 delwin.3 curses_window.3 derwin.3 \ + curses_refresh.3 doupdate.3 curses_window.3 dupwin.3 \ + curses_tty.3 echo.3 curses_echochar.3 echochar.3 \ + curses_screen.3 endwin.3 curses_clear.3 erase.3 \ + curses_tty.3 erasechar.3 \ + curses_tty.3 flash.3 curses_tty.3 flushinp.3 \ + curses_refresh.3 flushok.3 \ + curses_termcap.3 fullname.3 curses_attributes.3 getattrs.3 \ + curses_background.3 getbkgd.3 curses_termcap.3 getcap.3 \ + curses_input.3 getch.3 curses_cursor.3 getcury.3 \ + curses_cursor.3 getcurx.3 curses_cursor.3 getbegy.3 \ + curses_cursor.3 getbegx.3 curses_cursor.3 getmaxx.3 \ + curses_cursor.3 getmaxy.3 curses_cursor.3 getmaxyx.3 \ + curses_input.3 getnstr.3 \ + curses_cursor.3 getpary.3 curses_cursor.3 getparx.3 \ + curses_cursor.3 getparyx.3 curses_fileio.3 getwin.3 \ + curses_input.3 getstr.3 \ + curses_tty.3 gettmode.3 curses_cursor.3 getyx.3 \ + curses_color.3 has_colors.3 curses_tty.3 has_ic.3 \ + curses_tty.3 halfdelay.3 curses_tty.3 has_il.3 \ + curses_line.3 hline.3 curses_tty.3 idcok.3 \ + curses_tty.3 idlok.3 curses_inch.3 inch.3 \ + curses_inch.3 inchnstr.3 curses_inch.3 inchstr.3 \ + curses_inch.3 innstr.3 curses_color.3 init_color.3 \ + curses_color.3 init_pair.3 curses_screen.3 initscr.3 \ + curses_insertch.3 insch.3 curses_insdelln.3 insdelln.3 \ + curses_insertln.3 insertln.3 curses_inch.3 instr.3 \ + curses_tty.3 intrflush.3 curses_touch.3 is_linetouched.3 \ + curses_touch.3 is_wintouched.3 curses_screen.3 isendwin.3 \ + curses_keyname.3 keyname.3 \ + curses_input.3 keypad.3 curses_tty.3 killchar.3 \ + curses_refresh.3 leaveok.3 curses_termcap.3 longname.3 \ + curses_tty.3 meta.3 curses_cursor.3 move.3 \ + curses_addch.3 mvaddch.3 curses_addchstr.3 mvaddchnstr.3 \ + curses_addchstr.3 mvaddchstr.3 curses_addstr.3 mvaddnstr.3 \ + curses_addstr.3 mvaddstr.3 \ + curses_cursor.3 mvcur.3 curses_window.3 mvderwin.3 \ + curses_input.3 mvgetch.3 \ + curses_input.3 mvgetnstr.3 curses_input.3 mvgetstr.3 \ + curses_line.3 mvhline.3 curses_print.3 mvprintw.3 \ + curses_line.3 mvvline.3 curses_addch.3 mvwaddch.3 \ + curses_addchstr.3 mvwaddchnstr.3 curses_addchstr.3 mvwaddchstr.3 \ + curses_addstr.3 mvwaddnstr.3 curses_addstr.3 mvwaddstr.3 \ + curses_input.3 mvwgetch.3 \ + curses_input.3 mvwgetnstr.3 curses_input.3 mvwgetstr.3 \ + curses_line.3 mvwhline.3 curses_window.3 mvwin.3 \ + curses_inch.3 mvinchnstr.3 \ + curses_inch.3 mvinchstr.3 curses_inch.3 mvinnstr.3 \ + curses_inch.3 mvinstr.3 curses_inch.3 mvwinchnstr.3 \ + curses_inch.3 mvwinchstr.3 curses_inch.3 mvwinnstr.3 \ + curses_inch.3 mvwinstr.3 curses_print.3 mvwprintw.3 \ + curses_line.3 mvwvline.3 curses_tty.3 napms.3 \ + curses_pad.3 newpad.3 curses_screen.3 newterm.3 \ + curses_window.3 newwin.3 curses_tty.3 nl.3 \ + curses_tty.3 nocbreak.3 curses_input.3 nodelay.3 \ + curses_tty.3 noecho.3 curses_tty.3 nonl.3 \ + curses_tty.3 noqiflush.3 \ + curses_tty.3 noraw.3 curses_input.3 notimeout.3 \ + curses_window.3 overlay.3 curses_window.3 overwrite.3 \ + curses_color.3 pair_content.3 curses_echochar.3 pechochar.3 \ + curses_pad.3 pnoutrefresh.3 \ + curses_pad.3 prefresh.3 curses_print.3 printw.3 \ + curses_fileio.3 putwin.3 curses_tty.3 qiflush.3 \ + curses_tty.3 raw.3 curses_refresh.3 refresh.3 \ + curses_tty.3 reset_prog_mode.3 curses_tty.3 reset_shell_mode.3 \ + curses_tty.3 resetty.3 curses_screen.3 resizeterm.3 \ + curses_tty.3 savetty.3 curses_scanw.3 scanw.3 \ + curses_scroll.3 scrl.3 curses_scroll.3 scroll.3 \ + curses_scroll.3 scrollok.3 curses_scroll.3 setscrreg.3 \ + curses_screen.3 set_term.3 curses_screen.3 setterm.3 \ + curses_standout.3 standend.3 curses_standout.3 standout.3 \ + curses_color.3 start_color.3 curses_pad.3 subpad.3 \ + curses_window.3 subwin.3 curses_input.3 timeout.3 \ + curses_touch.3 touchline.3 curses_touch.3 touchoverlap.3 \ + curses_touch.3 touchwin.3 curses_print.3 unctrl.3 \ + curses_underscore.3 underend.3 curses_underscore.3 underscore.3 \ + curses_input.3 ungetch.3 curses_touch.3 untouchwin.3 \ + curses_default_colors.3 use_default_colors.3 curses_line.3 vline.3 \ + curses_addch.3 waddch.3 curses_addchstr.3 waddchnstr.3 \ + curses_addchstr.3 waddchstr.3 curses_addstr.3 waddnstr.3 \ + curses_addstr.3 waddstr.3 \ + curses_attributes.3 wattr_get.3 curses_attributes.3 wattr_off.3 \ + curses_attributes.3 wattr_on.3 curses_attributes.3 wattr_set.3 \ + curses_attributes.3 wattron.3 curses_attributes.3 wattroff.3 \ + curses_attributes.3 wattrset.3 curses_background.3 wbkgd.3 \ + curses_background.3 wbkgdset.3 curses_border.3 wborder.3 \ + curses_clear.3 wclear.3 curses_clear.3 wclrtobot.3 \ + curses_clear.3 wclrtoeol.3 curses_attributes.3 wcolor_set.3 \ + curses_delch.3 wdelch.3 curses_deleteln.3 wdeleteln.3 \ + curses_echochar.3 wechochar.3 \ + curses_clear.3 werase.3 curses_input.3 wgetch.3 \ + curses_input.3 wgetnstr.3 curses_input.3 wgetstr.3 \ + curses_line.3 whline.3 curses_inch.3 winch.3 \ + curses_inch.3 winchnstr.3 curses_inch.3 winchstr.3 \ + curses_inch.3 winnstr.3 curses_insertch.3 winsch.3 \ + curses_insdelln.3 winsdelln.3 curses_insertln.3 winsertln.3 \ + curses_inch.3 winstr.3 curses_cursor.3 wmove.3 \ + curses_refresh.3 wnoutrefresh.3 curses_print.3 wprintw.3 \ + curses_refresh.3 wrefresh.3 curses_window.3 wresize.3 \ + curses_scanw.3 wscanw.3 curses_scroll.3 wscrl.3 \ + curses_scroll.3 wsetscrreg.3 curses_standout.3 wstandend.3 \ + curses_standout.3 wstandout.3 curses_input.3 wtimeout.3 \ + curses_touch.3 wtouchln.3 curses_underscore.3 wunderend.3 \ + curses_underscore.3 wunderscore.3 curses_line.3 wvline.3 + +.if make(install) +SUBDIR+= PSD.doc +.endif + +fileio.h: shlib_version genfileioh.awk + ${TOOL_AWK} -f ${.CURDIR}/genfileioh.awk < ${.CURDIR}/shlib_version > ${.CURDIR}/fileio.h .include +.include diff --git a/lib/libcurses/PSD.doc/Makefile b/lib/libcurses/PSD.doc/Makefile new file mode 100644 index 000000000..0bf9ac935 --- /dev/null +++ b/lib/libcurses/PSD.doc/Makefile @@ -0,0 +1,40 @@ +# $NetBSD: Makefile,v 1.10 2003/07/10 10:34:22 lukem Exp $ +# from: @(#)Makefile 8.2 (Berkeley) 5/23/94 + +DIR= psd/19.curses +SRCS= Master +MACROS= -me +OTHER= appen.A appen.B appen.C doc.I doc.II doc.III doc.IV fns.doc \ + intro.0 intro.1 intro.3 intro.4 intro.5 intro.6 \ + macros c_macros +CEXAMPLES= ex1.gr ex2.gr life.gr twinkle1.gr twinkle2.gr win_st.gr +TBLFILES= intro.2.tbl +EXTRA= ${OTHER} ${CEXAMPLES:R:S/$/.c/g} ${TBLFILES:R} + +CLEANFILES+= ${CEXAMPLES} ${TBLFILES} + +.SUFFIXES: +.SUFFIXES: .c .gr + +# +# this section formats C input source into nice troffable (or nroffable) +# versions. It uses the capabilites of "vgrind", which sets keywords in +# bold font, and comments in italics. +# + + +# Don't re-run vgrind unless you want to patch the output files. +# XXXBUILDSH: can we use TOOL_VGRIND here ? +VFONT= /usr/libexec/vfontedpr +.c.gr: + ${VFONT} ${.IMPSRC} | grep -v "^'wh" > ${.TARGET} + +paper.ps: ${SRCS} ${OTHER} ${CEXAMPLES} ${TBLFILES} + ${TOOL_SOELIM} -I${.CURDIR} Master | \ + ${TOOL_ROFF_PS} ${MACROS} > ${.TARGET} + +# Unfortunately our make doesn't handle single-suffix rules. +intro.2.tbl: intro.2 + ${TOOL_TBL} ${.ALLSRC} > ${.TARGET} + +.include diff --git a/lib/libcurses/PSD.doc/Master b/lib/libcurses/PSD.doc/Master new file mode 100644 index 000000000..0af37df05 --- /dev/null +++ b/lib/libcurses/PSD.doc/Master @@ -0,0 +1,52 @@ +.\" $NetBSD: Master,v 1.5 2003/08/07 16:44:26 agc Exp $ +.\" +.\" Copyright (c) 1980, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)Master 8.2 (Berkeley) 5/24/94 +.\" +.ds Ln Screen Package +.so macros +.so c_macros +.so intro.0 +.pn 3 +.bp +.so intro.1 +.so intro.2.tbl +.so intro.3 +.so intro.4 +.so intro.5 +.so intro.6 +.bp +.so appen.A +.pn 2 +.oh '\*(Ln''PSD:19-%' +.eh 'PSD:19-%''\*(Ln' +.bp +.bi Contents +.sp +.xp diff --git a/lib/libcurses/PSD.doc/appen.A b/lib/libcurses/PSD.doc/appen.A new file mode 100644 index 000000000..c707d85bd --- /dev/null +++ b/lib/libcurses/PSD.doc/appen.A @@ -0,0 +1,77 @@ +.\" $NetBSD: appen.A,v 1.7 2003/08/07 16:44:26 agc Exp $ +.\" +.\" Copyright (c) 1980, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)appen.A 8.1 (Berkeley) 6/8/93 +.\" +.ie t .oh '\*(Ln Appendix A''PS1:19-%' +.eh 'PS1:19-%''\*(Ln Appendix A' +.el .he ''\fIAppendix A\fR'' +.bp +.(x +.ti 0 +.b "Appendix A" +.)x +.sh 1 "Examples" 1 +.pp +Here we present a few examples +of how to use the package. +They attempt to be representative, +though not comprehensive. +Further examples can be found in the games section +of the source tree and in various utilities that use the screen such as +.i systat(1) . +.pp +The following examples are intended to demonstrate +the basic structure of a program +using the package. +An additional, more comprehensive, program can be found in +the source code in the +\fIexamples\fP subdirectory. +.sh 2 "Simple Character Output" +.pp +This program demonstrates how to set up a window and output characters to it. +Also, it demonstrates how one might control the output to the window. +If you run this program, you will get a demonstration of the character output +chracteristics discussed in the above Character Output section. +.(l I +.so ex1.gr +.)l +.sh 2 "Twinkle" +.pp +This is a moderately simple program which prints +patterns on the screen. +It switches between patterns of asterisks, +putting them on one by one in random order, +and then taking them off in the same fashion. +It is more efficient to write this +using only the motion optimization, +as is demonstrated below. +.(l I +.so twinkle1.gr +.)l diff --git a/lib/libcurses/PSD.doc/appen.B b/lib/libcurses/PSD.doc/appen.B new file mode 100644 index 000000000..5a41fe035 --- /dev/null +++ b/lib/libcurses/PSD.doc/appen.B @@ -0,0 +1,199 @@ +.\" $NetBSD: appen.B,v 1.5 2003/08/07 16:44:26 agc Exp $ +.\" +.\" Copyright (c) 1980, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)appen.B 8.1 (Berkeley) 6/8/93 +.\" +.ie t .oh '\*(Ln Appendix B''PS1:19-%' +.eh 'PS1:19-%''\*(Ln Appendix B' +.el .he ''\fIAppendix B\fR'' +.bp +.(x +.ti 0 +.b "Appendix B" +.)x +.nr $1 0 +.sh 1 "The WINDOW structure" +.pp +The WINDOW structure is defined as follows: +.(l I +.so win_st.gr +.)l +.pp +.Vn \*_cury \\* +.(f +\** +All variables not normally accessed directly by the user +are named with an initial +.Bq \*_ +to avoid conflicts with the user's variables. +.)f +and +.Vn \*_curx +are the current \*y for the window. +New characters added to the screen +are added at this point. +.Vn \*_maxy +and +.Vn \*_maxx +are the maximum values allowed for +.Vn \*_cury\*,\*_curx ). ( +.Vn \*_begy +and +.Vn \*_begx +are the starting \*y on the terminal for the window, +.i i.e. , +the window's home. +.Vn \*_cury , +.Vn \*_curx , +.Vn \*_maxy , +and +.Vn \*_maxx +are measured relative to +.Vn \*_begy\*,\*_begx ), ( +not the terminal's home. +.pp +.Vn \*_clear +tells if a clear-screen sequence is to be generated +on the next +.Fn refresh +call. +This is only meaningful for screens. +The initial clear-screen for the first +.Fn refresh +call is generated by initially setting clear to be TRUE for +.Vn curscr , +which always generates a clear-screen if set, +irrelevant of the dimensions of the window involved. +.Vn \*_leave +is TRUE if the current \*y and the cursor +are to be left after the last character changed on the terminal, +or not moved if there is no change. +.Vn \*_scroll +is TRUE +if scrolling is allowed. +.pp +.Vn \*_y +is a pointer to an array of lines which describe the terminal. +Thus: +.(l +\*_y[i] +.)l +.lp +is a pointer to the +.Vn i th +line, and +.(l +\*_y[i][j] +.)l +.lp +is the +.Vn j th +character on the +.Vn i th +line. +.Vn \*_flags +can have one or more values +or'd into it. +.pp +For windows that are not subwindows, +.Vn \*_orig +is +NULL . +For subwindows, +it points to the main window +to which the window is subsidiary. +.Vn \*_nextp +is a pointer in a circularly linked list +of all the windows which are subwindows of the same main window, +plus the main window itself. +.pp +.Vn \*_firstch +and +.Vn \*_lastch +are +.Fn malloc ed +arrays which contain the index of the +first and last changed characters +on the line. +.Vn \*_ch\*_off +is the x offset for the window +in the +.Vn \*_firstch +and +.Vn \*_lastch +arrays for this window. +For main windows, +this is always 0; +for subwindows +it is the difference between the starting point of the main window +and that of the subindow, +so that change markers can be set relative to the main window. +This makes these markers global in scope. +.pp +All subwindows share the appropriate portions of +.Vn _y , +.Vn _firstch , +.Vn _lastch , +and +.Vn _insdel +with their main window. +.pp +.b \*_ENDLINE +says that the end of the line for this window +is also the end of a screen. +.b \*_FULLWIN +says that this window is a screen. +.b \*_SCROLLWIN +indicates that the last character of this screen +is at the lower right-hand corner of the terminal; +.i i.e. , +if a character was put there, +the terminal would scroll. +.b \*_FULLLINE +says that the width of a line is the same as the width of the terminal. +If +.b \*_FLUSH +is set, +it says that +.Fn fflush "" "" stdout +should be called at the end of each +.Fn refresh +.b \*_STANDOUT +says that all characters added to the screen +are in standout mode. +.b \*_INSDEL +is reserved for future use, +and is set by +.Fn idlok . +.Vn \*_firstch +is set to +.b \*_NOCHANGE +for lines on which there has been no change +since the last +.Fn refresh . diff --git a/lib/libcurses/PSD.doc/appen.C b/lib/libcurses/PSD.doc/appen.C new file mode 100644 index 000000000..ce12a2ea7 --- /dev/null +++ b/lib/libcurses/PSD.doc/appen.C @@ -0,0 +1,126 @@ +.\" $NetBSD: appen.C,v 1.7 2003/08/07 16:44:26 agc Exp $ +.\" +.\" Copyright (c) 1980, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)appen.C 8.1 (Berkeley) 6/8/93 +.\" +.ie t .oh '\*(Ln Appendix A''PS1:19-%' +.eh 'PS1:19-%''\*(Ln Appendix A' +.el .he ''\fIAppendix A\fR'' +.bp +.(x +.ti 0 +.b "Appendix A" +.)x +.sh 1 "Examples" 1 +.pp +Here we present a few examples +of how to use the package. +They attempt to be representative, +though not comprehensive. +Further examples can be found in the games section +of the source tree and in various utilities that use the screen such as +.i systat(1) . +.sh 2 "Screen Updating" +.pp +The following examples are intended to demonstrate +the basic structure of a program +using the screen updating sections of the package. +Several of the programs require calculational sections +which are irrelevant of to the example, +and are therefore usually not included. +It is hoped that the data structure definitions +give enough of an idea to allow understanding +of what the relevant portions do. +.sh 3 "Simple Character Output" +.pp +This program demonstrates how to set up a window and output characters to it. +Also, it demonstrates how one might control the output to the window. +If you run this program, you will get a demonstration of the character output +chracteristics discussed in the above Character Output section. +.(l I +.so t2.gr +.)l +.sh 3 "A Small Screen Manipulator" +.pp +The next example follows the lines of the previous one but extends then to +demonstrate the various othe uses of the package. +Make sure you understand how this program works as it encompasses most of +anything you will need to do with the package. +.(l I +.so t3.gr +.)l +.sh 3 "Twinkle" +.pp +This is a moderately simple program which prints +patterns on the screen. +It switches between patterns of asterisks, +putting them on one by one in random order, +and then taking them off in the same fashion. +It is more efficient to write this +using only the motion optimization, +as is demonstrated below. +.(l I +.so twinkle1.gr +.)l +.sh 3 "Life" +.pp +This program fragment models the famous computer pattern game of life +(Scientific American, May, 1974). +The calculational routines create a linked list of structures +defining where each piece is. +Nothing here claims to be optimal, +merely demonstrative. +This code, however, +is a very good place to use the screen updating routines, +as it allows them to worry about what the last position looked like, +so you don't have to. +It also demonstrates some of the input routines. +.(l I +.so life.gr +.)l +.sh 2 "Motion optimization" +.pp +The following example shows how motion optimization +is written on its own. +Programs which flit from one place to another without +regard for what is already there +usually do not need the overhead of both space and time +associated with screen updating. +They should instead use motion optimization. +.sh 3 "Twinkle" +.pp +The +.b twinkle +program +is a good candidate for simple motion optimization. +Here is how it could be written +(only the routines that have been changed are shown): +.(l +.so twinkle2.gr +.)l diff --git a/lib/libcurses/PSD.doc/c_macros b/lib/libcurses/PSD.doc/c_macros new file mode 100644 index 000000000..ba039363e --- /dev/null +++ b/lib/libcurses/PSD.doc/c_macros @@ -0,0 +1,68 @@ +.\" $NetBSD: c_macros,v 1.5 2003/08/07 16:44:26 agc Exp $ +.\" +.\" Copyright (c) 1980, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)c_macros 8.1 (Berkeley) 6/4/93 +.\" +'ie t 'ds _ \d\(mi\u +'el 'ds _ _ +'tr *\(** +'ps 9p +'vs 10p +'ds - \(mi +'ds /* \\h'\\w' 'u-\\w'/'u'/* +'bd B 3 +'bd S B 3 +'nr cm 0 +'nf +'de () +'pn 1 +.. +'de +C +'nr cm 1 +'ft 2 +'ds +K +'ds -K +.. +'de -C +'nr cm 0 +'ft 1 +.ie t 'ds +K \f3 +.el 'ds +K \fI +'ds -K \fP +.. +'+C +'-C +'am +C +'ne 3 +.. +'de -F +'rm =f +.. +'ft 1 +'lg 0 diff --git a/lib/libcurses/PSD.doc/doc.I b/lib/libcurses/PSD.doc/doc.I new file mode 100644 index 000000000..01bb3fc17 --- /dev/null +++ b/lib/libcurses/PSD.doc/doc.I @@ -0,0 +1,347 @@ +.\" $NetBSD: doc.I,v 1.5 2003/08/07 16:44:27 agc Exp $ +.\" +.\" Copyright (c) 1980, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)doc.I 8.1 (Berkeley) 6/4/93 +.\" +.Ds +.Fd addch ch \*m +char ch; +.Fd waddch win\*,ch +WINDOW *win; +char ch; +.De +Add the character +.Vn ch +on the window +at the current \*y. +If the character is a newline +(\'\en\') +the line will be cleared to the end, +and the current \*y will be changed to the +beginning off the next line +if newline mapping is on, +or to the next line at the same x co-ordinate +if it is off. +A return +(\'\er\') +will move to the beginning of the line on the window. +Tabs +(\'\et\') +will be expanded into spaces +in the normal tabstop positions of +every eight characters. +\*(Es +.Ds +.Fd addstr str \*m +char *str; +.Fd waddstr win\*,str +WINDOW *win; +char *str; +.De +Add the string pointed to by +.Vn str +on the window at the current \*y. +\*(Es +In this case, it will put on as much as it can. +.Ds +.Fd box win\*,vert\*,hor +WINDOW *win; +char vert\*,hor; +.De +.Pp +Draws a box around the window using +.Vn vert +as the character for drawing the vertical sides, and +.Vn hor +for drawing the horizontal lines. +If scrolling is not allowed, +and the window encompasses the lower right-hand corner of the terminal, +the corners are left blank to avoid a scroll. +.Ds +.Fd clear "" \*m +.Fd wclear win +WINDOW *win; +.De +Resets the entire window to blanks. +If +.Vn win +is a screen, +this sets the clear flag, +which will cause a clear-screen sequence to be sent +on the next +.Fn refresh +call. +This also moves the current \*y +to (0\*,0). +.Ds +.Fd clearok scr\*,boolf \*m +WINDOW *scr; +bool boolf; +.De +Sets the clear flag for the screen +.Vn scr . +If +.Vn boolf +is TRUE, +this will force a clear-screen to be printed on the next +.Fn refresh , +or stop it from doing so if +.Vn boolf +is FALSE. +This only works on screens, +and, +unlike +.Fn clear , +does not alter the contents of the screen. +If +.Vn scr +is +.Vn curscr , +the next +.Fn refresh +call will cause a clear-screen, +even if the window passed to +.Fn refresh +is not a screen. +.Ds +.Fd clrtobot "" \*m +.Fd wclrtobot win +WINDOW *win; +.De +Wipes the window clear from the current \*y to the bottom. +This does not force a clear-screen sequence on the next refresh +under any circumstances. +\*(Nm +.Ds +.Fd clrtoeol "" \*m +.Fd wclrtoeol win +WINDOW *win; +.De +Wipes the window clear from the current \*y to the end of the line. +\*(Nm +.Ds +.Fd delch +.Fd wdelch win +WINDOW *win; +.De +Delete the character at the current \*y. +Each character after it on the line shifts to the left, +and the last character becomes blank. +.Ds +.Fd deleteln +.Fd wdeleteln win +WINDOW *win; +.De +Delete the current line. +Every line below the current one will move up, +and the bottom line will become blank. +The current \*y will remain unchanged. +.Ds +.Fd erase "" \*m +.Fd werase win +WINDOW *win; +.De +Erases the window to blanks without setting the clear flag. +This is analagous to +.Fn clear , +except that it never causes a clear-screen sequence to be generated +on a +.Fn refresh . +\*(Nm +.Ds +.Fd flushok win\*,boolf \*m +WINDOW *win; +bool boolf; +.De +Normally, +.Fn refresh +.Fn fflush 's +.Vn stdout +when it is finished. +.Fn flushok +allows you to control this. +if +.Vn boolf +is TRUE +(\c +.i i.e. , +non-zero) +it will do the +.Fn fflush ; +if it is FALSE. +it will not. +.Ds +.Fd idlok win\*,boolf +WINDOW *win; +bool boolf; +.De +Reserved for future use. +This will eventually signal to +.Fn refresh +that it is all right to use the insert and delete line sequences +when updating the window. +.Ds +.Fd insch c +char c; +.Fd winsch win\*,c +WINDOW *win; +char c; +.De +Insert +.Vn c +at the current \*y +Each character after it shifts to the right, +and the last character disappears. +\*(Es +.Ds +.Fd insertln +.Fd winsertln win +WINDOW *win; +.De +Insert a line above the current one. +Every line below the current line +will be shifted down, +and the bottom line will disappear. +The current line will become blank, +and the current \*y will remain unchanged. +.Ds +.Fd move y\*,x \*m +int y\*,x; +.Fd wmove win\*,y\*,x +WINDOW *win; +int y\*,x; +.De +Change the current \*y of the window to +.Vn y\*,x ). ( +\*(Es +.Ds +.Fd overlay win1\*,win2 +WINDOW *win1\*,*win2; +.De +Overlay +.Vn win1 +on +.Vn win2 . +The contents of +.Vn win1 , +insofar as they fit, +are placed on +.Vn win2 +at their starting \*y. +This is done non-destructively, +i.e., blanks on +.Vn win1 +leave the contents of the space on +.Vn win2 +untouched. +.Ds +.Fd overwrite win1\*,win2 +WINDOW *win1\*,*win2; +.De +Overwrite +.Vn win1 +on +.Vn win2 . +The contents of +.Vn win1 , +insofar as they fit, +are placed on +.Vn win2 +at their starting \*y. +This is done destructively, +.i i.e. , +blanks on +.Vn win1 +become blank on +.Vn win2 . +.Ds +.Fd printw fmt\*,arg1\*,arg2\*,... +char *fmt; +.Fd wprintw win\*,fmt\*,arg1\*,arg2\*,... +WINDOW *win; +char *fmt; +.De +Performs a +.Fn printf +on the window starting at the current \*y. +It uses +.Fn addstr +to add the string on the window. +It is often advisable to use the field width options of +.Fn printf +to avoid leaving things on the window from earlier calls. +\*(Es +.Ds +.Fd refresh "" \*m +.Fd wrefresh win +WINDOW *win; +.De +Synchronize the terminal screen with the desired window. +If the window is not a screen, +only that part covered by it is updated. +\*(Es +In this case, it will update whatever it can +without causing the scroll. +.sp +As a special case, +if +.Fn wrefresh +is called with the window +.Vn curscr +the screen is cleared +and repainted as it is currently. +This is very useful for allowing the redrawing of the screen +when the user has garbage dumped on his terminal. +.Ds +.Fd standout "" \*m +.Fd wstandout win +WINDOW *win; +.Fd standend "" \*m +.Fd wstandend win +WINDOW *win; +.De +Start and stop putting characters onto +.i win +in standout mode. +.Fn standout +causes any characters added to the window +to be put in standout mode on the terminal +(if it has that capability). +.Fn standend +stops this. +The sequences +.Vn SO +and +.Vn SE +(or +.Vn US +and +.Vn UE +if they are not defined) +are used (see Appendix A). diff --git a/lib/libcurses/PSD.doc/doc.II b/lib/libcurses/PSD.doc/doc.II new file mode 100644 index 000000000..7209da0d6 --- /dev/null +++ b/lib/libcurses/PSD.doc/doc.II @@ -0,0 +1,140 @@ +.\" $NetBSD: doc.II,v 1.5 2003/08/07 16:44:27 agc Exp $ +.\" +.\" Copyright (c) 1980, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)doc.II 8.1 (Berkeley) 6/4/93 +.\" +.Ds +.Fd cbreak "" \*m +.Fd nocbreak "" \*m +.Fd crmode "" \*m +.Fd nocrmode "" \*m +.De +Set or unset the terminal to/from cbreak mode. +The misnamed macros +.Fn crmode +and +.Fn nocrmode +are retained for backwards compatibility +with ealier versions of the library. +.Ds +.Fd echo "" \*m +.Fd noecho "" \*m +.De +Sets the terminal to echo or not echo characters. +.Ds +.Fd getch "" \*m +.Fd wgetch win +WINDOW *win; +.De +Gets a character from the terminal and (if necessary) +echos it on the window. +\*(Es +Otherwise, the character gotten is returned. +If +.i noecho +has been set, then the window is left unaltered. +In order to retain control of the terminal, +it is necessary to have one of +.i noecho , +.i cbreak , +or +.i rawmode +set. +If you do not set one, +whatever routine you call to read characters will set +.i cbreak +for you, +and then reset to the original mode when finished. +.Ds +.Fd getstr str \*m +char *str; +.Fd wgetstr win\*,str +WINDOW *win; +char *str; +.De +Get a string through the window +and put it in the location pointed to by +.Vn str , +which is assumed to be large enough to handle it. +It sets tty modes if necessary, +and then calls +.Fn getch +(or +.Fn wgetch ) "" win +to get the characters needed to fill in the string +until a newline or EOF is encountered. +The newline stripped off the string. +\*(Es +.Ds +.Fd \*_putchar c +char c; +.De +Put out a character using the +.Fn putchar +macro. +This function is used to output every character +that +.b curses +generates. +Thus, +it can be redefined by the user who wants to do non-standard things +with the output. +It is named with an initial \*(lq\*_\*(rq +because it usually should be invisible to the programmer. +.Ds +.Fd raw "" \*m +.Fd noraw "" \*m +.De +Set or unset the terminal to/from raw mode. +On version 7 +.Un \** +.(f +\** +.Un +is a trademark of Bell Laboratories. +.)f +this also turns of newline mapping +(see +.Fn nl ). +.Ds +.Fd scanw fmt\*,arg1\*,arg2\*,... +char *fmt; +.Fd wscanw win\*,fmt\*,arg1\*,arg2\*,... +WINDOW *win; +char *fmt; +.De +Perform a +.Fn scanf +through the window using +.Vn fmt . +It does this using consecutive +.Fn getch 's +(or +.Fn wgetch 's). "" win +\*(Es diff --git a/lib/libcurses/PSD.doc/doc.III b/lib/libcurses/PSD.doc/doc.III new file mode 100644 index 000000000..94d4dd267 --- /dev/null +++ b/lib/libcurses/PSD.doc/doc.III @@ -0,0 +1,341 @@ +.\" $NetBSD: doc.III,v 1.5 2003/08/07 16:44:27 agc Exp $ +.\" +.\" Copyright (c) 1980, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)doc.III 8.1 (Berkeley) 6/4/93 +.\" +.Ds +.Fd baudrate "" \*m +.De +Returns the output baud rate of the terminal. +This is a system dependent constant +(defined in +.b +on BSD systems, +which is included by +.b ). +.Ds +.Fd delwin win +WINDOW *win; +.De +Deletes the window from existence. +All resources are freed for future use by +.b calloc (3). +If a window has a +.Fn subwin +allocated window inside of it, +deleting the outer window +the subwindow is not affected, +even though this does invalidate it. +Therefore, +subwindows should be deleted before their +outer windows are. +.Ds +.Fd endwin +.De +Finish up window routines before exit. +This restores the terminal to the state it was before +.Fn initscr +(or +.Fn gettmode +and +.Fn setterm ) +was called. +It should always be called before exiting. +It does not exit. +This is especially useful for resetting tty stats +when trapping rubouts via +.b signal (2). +.Ds +.Fd erasechar "" \*m +.De +Returns the erase character +for the terminal, +.i i.e. , +the character used by the user to erase a single character from the input. +.Ds +.Fd getcap str "" "char *" +char *str; +.De +Return a pointer to the +.b termcap +capability described by +.Vn str +(see +.b termcap (5) +for details). +.Ds +.Fd getyx win\*,y\*,x \*m +WINDOW *win; +int y\*,x; +.De +Puts the current \*y of +.Vn win +in the variables +.Vn y +and +.Vn x . +Since it is a macro, +not a function, +you do not pass the address +of +.Vn y +and +.Vn x . +.Ds +.Fd inch "" \*m +.Fd winch win \*m +WINDOW *win; +.De +Returns the character at the current \*(y +on the given window. +This does not make any changes to the window. +.Ds +.Fd initscr +.De +Initialize the screen routines. +This must be called before any of the screen routines are used. +It initializes the terminal-type data and such, +and without it none of the routines can operate. +If standard input is not a tty, +it sets the specifications to the terminal +whose name is pointed to by +.Vn Def\*_term +(initialy "dumb"). +If the boolean +.Vn My\*_term +is true, +.Vn Def\*_term +is always used. +If the system supports the +.b TIOCGWINSZ +.Fn ioctl "" "" 2 +call, +it is used to get the number of lines and columns for the terminal, +otherwise it is taken from the +.b termcap +description. +.Ds +.Fd killchar "" \*m +.De +Returns the line kill character +for the terminal, +.i i.e. , +the character used by the user to erase an entire line from the input. +.Ds +.Fd leaveok win\*,boolf \*m +WINDOW *win; +bool boolf; +.De +Sets the boolean flag for leaving the cursor after the last change. +If +.Vn boolf +is TRUE, +the cursor will be left after the last update on the terminal, +and the current \*y for +.Vn win +will be changed accordingly. +If it is FALSE, +it will be moved to the current \*y. +This flag +(initialy FALSE) +retains its value until changed by the user. +.Ds +.Fd longname termbuf\*,name +char *termbuf\*,*name; +.Fd fullname termbuf\*,name +char *termbuf\*,*name; +.De +.Fn longname +fills in +.Vn name +with the long name of the terminal described by the +.b termcap +entry in +.Vn termbuf . +It is generally of little use, +but is nice for telling the user in a readable format what terminal +we think he has. +This is available in the global variable +.Vn ttytype . +.Vn termbuf +is usually set via the termlib routine +.Fn tgetent . +.Fn fullname +is the same as +.Fn longname , +except that it gives the fullest name given in the entry, +which can be quite verbose. +.Ds +.Fd mvwin win\*,y\*,x +WINDOW *win; +int y, x; +.De +Move the home position of the window +.Vn win +from its current starting coordinates +to +.Vn y\*,x ). ( +If that would put part or all of the window +off the edge of the terminal screen, +.Fn mvwin +returns ERR and does not change anything. +For subwindows, +.Fn mvwin +also returns ERR if you attempt to move it off its main window. +If you move a main window, +all subwindows are moved along with it. +.Ds +.Fd newwin lines\*,cols\*,begin\*_y\*,begin\*_x "" "WINDOW *" +int lines\*,cols\*,begin\*_y\*,begin\*_x; +.De +Create a new window with +.Vn lines +lines and +.Vn cols +columns starting at position +.Vn begin\*_y\*,begin\*_x ). ( +If either +.Vn lines +or +.Vn cols +is 0 (zero), +that dimension will be set to +.Vn "LINES \- begin\*_y" ) ( +or +.Vn "COLS \- begin\*_x" ) ( +respectively. +Thus, to get a new window of dimensions +.Vn LINES +\(mu +.Vn COLS , +use +.Fn newwin . "" 0\*,0\*,0\*,0 +.Ds +.Fd nl "" \*m +.Fd nonl "" \*m +.De +Set or unset the terminal to/from nl mode, +.i i.e. , +start/stop the system from mapping +.b +to +.b . +If the mapping is not done, +.Fn refresh +can do more optimization, +so it is recommended, but not required, to turn it off. +.Ds +.Fd scrollok win\*,boolf \*m +WINDOW *win; +bool boolf; +.De +Set the scroll flag for the given window. +If +.Vn boolf +is FALSE, scrolling is not allowed. +This is its default setting. +.Ds +.Fd touchline win\*,y\*,startx\*,endx +WINDOW *win; +int y\*,startx\*,endx; +.De +This function performs a function similar to +.Fn touchwin +on a single line. +It marks the first change for the given line +to be +.Vn startx , +if it is before the current first change mark, +and +the last change mark is set to be +.Vn endx +if it is currently less than +.Vn endx . +.Ds +.Fd touchoverlap win1\*,win2 +WINDOW *win1, *win2; +.De +Touch the window +.Vn win2 +in the area which overlaps with +.Vn win1 . +If they do not overlap, +no changes are made. +.Ds +.Fd touchwin win +WINDOW *win; +.De +Make it appear that the every location on the window +has been changed. +This is usually only needed for refreshes with overlapping windows. +.Ds +.Fd subwin win\*,lines\*,cols\*,begin\*_y\*,begin\*_x "" "WINDOW *" +WINDOW *win; +int lines\*,cols\*,begin\*_y\*,begin\*_x; +.De +Create a new window with +.Vn lines +lines and +.Vn cols +columns starting at position +.Vn begin\*_y\*,begin\*_x ) ( +inside the window +.i win . +This means that any change made to either window +in the area covered +by the subwindow will be made on both windows. +.Vn begin\*_y\*,begin\*_x +are specified relative to the overall screen, +not the relative (0\*,0) of +.Vn win . +If either +.Vn lines +or +.Vn cols +is 0 (zero), +that dimension will be set to +.Vn "LINES \- begin\*_y" ) ( +or +.Vn "COLS \- begin\*_x" ) ( +respectively. +.Ds +.Fd unctrl ch \*m +char ch; +.De +This is actually a debug function for the library, +but it is of general usefulness. +It returns a string which is a representation of +.Vn ch . +Control characters become their upper-case equivalents preceded by a "^". +Other letters stay just as they are. +To use +.Fn unctrl , +you may have to have +.b #include\ +in your file. diff --git a/lib/libcurses/PSD.doc/doc.IV b/lib/libcurses/PSD.doc/doc.IV new file mode 100644 index 000000000..8f60c0e7a --- /dev/null +++ b/lib/libcurses/PSD.doc/doc.IV @@ -0,0 +1,108 @@ +.\" $NetBSD: doc.IV,v 1.5 2003/08/07 16:44:27 agc Exp $ +.\" +.\" Copyright (c) 1980, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)doc.IV 8.1 (Berkeley) 6/4/93 +.\" +.Ds +.Fd gettmode +.De +Get the tty stats. +This is normally called by +.Fn initscr . +.Ds +.Fd mvcur lasty\*,lastx\*,newy\*,newx +int lasty\*,lastx\*,newy\*,newx; +.De +Moves the terminal's cursor from +.Vn lasty\*,lastx ) ( +to +.Vn newy\*,newx ) ( +in an approximation of optimal fashion. +This routine uses the functions borrowed from +.i ex +version 2.6. +It is possible to use this optimization +without the benefit of the screen routines. +With the screen routines, this should not be called by the user. +.Fn move +and +.Fn refresh +should be used to move the cursor position, +so that the routines know what's going on. +.Ds +.Fd scroll win +WINDOW *win; +.De +Scroll the window upward one line. +This is normally not used by the user. +.Ds +.Fd savetty "" \*m +.Fd resetty "" \*m +.De +.Fn savetty +saves the current tty characteristic flags. +.Fn resetty +restores them to what +.Fn savetty +stored. +These functions are performed automatically by +.Fn initscr +and +.Fn endwin . +.Ds +.Fd setterm name +char *name; +.De +Set the terminal characteristics to be those of the terminal named +.Vn name , +getting the terminal size from the +.b TIOCGWINSZ +.Fn ioctl "" "" 2 +if it exists, +otherwise from the environment. +This is normally called by +.Fn initscr . +.Ds +.Fd tstp +.De +If the new +.b tty (4) +driver is in use, +this function +will save the current tty state +and then put the process to sleep. +When the process gets restarted, +it restores the tty state +and then calls +.Fn wrefresh "" "" curscr +to redraw the screen. +.Fn initscr +sets the signal +SIGTSTP +to trap to this routine. diff --git a/lib/libcurses/PSD.doc/ex1.c b/lib/libcurses/PSD.doc/ex1.c new file mode 100644 index 000000000..27f2583da --- /dev/null +++ b/lib/libcurses/PSD.doc/ex1.c @@ -0,0 +1,100 @@ +.\" $NetBSD: ex1.c,v 1.6 2003/08/07 16:44:27 agc Exp $ +.\" +.\" Copyright (c) 1992, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)ex1.c 8.1 (Berkeley) 6/8/93 +.\" +#include +#include +#include +#include + + +#define YSIZE 10 +#define XSIZE 20 + +int quit(); + +main() +{ + int i, j, c; + size_t len; + char id[100]; + FILE *fp; + char *s; + + initscr(); /* Always call initscr() first */ + signal(SIGINT, quit); /* Make sure wou have a 'cleanup' fn */ + crmode(); /* We want cbreak mode */ + noecho(); /* We want to have control of chars */ + delwin(stdscr); /* Create our own stdscr */ + stdscr = newwin(YSIZE, XSIZE, 10, 35); + flushok(stdscr, TRUE); /* Enable flushing of stdout */ + scrollok(stdscr, TRUE); /* Enable scrolling */ + erase(); /* Initially, clear the screen */ + + standout(); + move(0,0); + while (1) { + c = getchar(); + switch(c) { + case 'q': /* Quit on 'q' */ + quit(); + break; + case 's': /* Go into standout mode on 's' */ + standout(); + break; + case 'e': /* Exit standout mode on 'e' */ + standend(); + break; + case 'r': /* Force a refresh on 'r' */ + wrefresh(curscr); + break; + default: /* By default output the character */ + addch(c); + refresh(); + } + } +} + + +int +quit() +{ + erase(); /* Terminate by erasing the screen */ + refresh(); + endwin(); /* Always end with endwin() */ + delwin(curscr); /* Return storage */ + delwin(stdscr); + putchar('\n'); + exit(0); +} + + + + diff --git a/lib/libcurses/PSD.doc/ex2.c b/lib/libcurses/PSD.doc/ex2.c new file mode 100644 index 000000000..f2e6e7d9e --- /dev/null +++ b/lib/libcurses/PSD.doc/ex2.c @@ -0,0 +1,208 @@ +.\" $NetBSD: ex2.c,v 1.7 2003/08/07 16:44:27 agc Exp $ +.\" +.\" Copyright (c) 1992, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)ex2.c 8.1 (Berkeley) 6/8/93 +.\" +#include +#include +#include + +#define YSIZE LINES +#define XSIZE COLS + +static int quit(); + +/* + * This program fills the screen up with characters and the allows the user to + * manipulate the text on the screen using some basic commands. + * Nothing fancy, just a demonstration of the elementary features of the + * curses(3) package. + */ +main() +{ + int i, j, c, n, d = 0; + char id[100]; + int hh = 0; + int curx, cury, base, arg; + + initscr(); + signal(SIGINT, quit); + crmode(); + noecho(); + nonl(); + delwin(stdscr); + stdscr = newwin(YSIZE, XSIZE, 0, 0); + flushok(stdscr, TRUE); + scrollok(stdscr, TRUE); + erase(); + refresh(); + + move(0,0); + refresh(); + for (i = 0; i < YSIZE + 2; i++) { + (void)snprintf(id, sizeof id, "%d: ", i); + addstr(id); + for (j = 0; j < XSIZE - strlen(id); j++) + addch('0' + (i % 10)); + } + c = getchar(); + base = 2; + curx = cury = 0; + move(0, 0); + refresh(); + + /* + * The screen manipulator has the following commands: + * 'D' - clear to the end of the current line. + * 'B' - clear to the bottom of the screen. + * 'E' - erase the screen. + * 's' - enter standout mode. + * 'e' - exit standout mode. + * 'd' n - delete n lines below cursor line. + * 'i' n - insert n lines below cursor line. + * 'q' - quit. + * 'f' - move cursor one position to the right. + * 'b' - move cursor one position to the left. + * 'n' - move cursor one line down. + * 'p' - move cursor one line up. + * 'h' - home cusor. + * 'l' - force refresh. + * 'r' - simulate a carriage return. + * + * All other characters are ignored. + */ + for(;;) { + switch(c = getchar()) { + case 'D': + clrtoeol(); + refresh(); + continue; + case 'B': + clrtobot(); + refresh(); + continue; + case 'E': + erase(); + refresh(); + continue; + case 's': + standout(); + continue; + case 'e': + standend(); + continue; + case 'd': + arg = getchar() - '0'; + for (i = 0; i < arg; i++) + deleteln(); + refresh(); + continue; + case 'i': + arg = getchar() - '0'; + for (i = 0; i < arg; i++) + insertln(); + refresh(); + continue; + case 'q': + quit(); + case 'f': + if (curx < XSIZE - 1) + curx++; + else { + cury++; + curx = 0; + } + break; + case 'b': + if (curx == 0) { + cury--; + curx = XSIZE - 1; + } else + curx--; + break; + case 'n': + cury++; + break; + case 'p': + cury--; + break; + case 'h': + curx = cury = 0; + break; + case 'l': + wrefresh(curscr); + continue; + case 'r': /* return */ + { + int x, y; + getyx(stdscr, y, x); + move(y+1, 0); + insertln(); + move(y, x); + clrtoeol(); + refresh(); + continue; + } + default: + continue; + } + + if (cury < 0) { + base--; + move(0, 0); + insertln(); + (void)snprintf(id, sizeof id, "%d: ", base); + addstr(id); + for (j = 0; j < XSIZE - strlen(id) - 2; j++) + addch('0' + (base % 10)); + cury++; + } else if (cury >= YSIZE) { + move(0, 0); + deleteln(); + move(YSIZE - 1, 0); + (void)snprintf(id, sizeof id, "%d: ", base + YSIZE); + addstr(id); + for (j = 0; j < XSIZE - strlen(id) - 2; j++) + addch('0' + ((base + YSIZE) % 10)); + cury--; + base++; + } + move(cury, curx); + refresh(); + } +} + +int +quit() +{ + erase(); + refresh(); + endwin(); + exit(0); +} diff --git a/lib/libcurses/PSD.doc/fns.doc b/lib/libcurses/PSD.doc/fns.doc new file mode 100644 index 000000000..8880dcfb1 --- /dev/null +++ b/lib/libcurses/PSD.doc/fns.doc @@ -0,0 +1,1757 @@ +.\" Copyright (c) 1992, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)fns.doc 8.2 (Berkeley) 6/1/94 +.\" +.Ds +.Fn addbytes "char *str" "int len" +.De +This function is the low level character output function. +.Vn Len +characters of the string +.Vn str +are output to the current \*y position of the window. +.Ds +.Fn addch "chtype ch" \(dg +.De +Add the character +.Vn ch +on the window +at the current \*y. +If the character is a newline +(\'\en\') +the line will be cleared to the end, +and the current \*y will be changed to the +beginning off the next line +if newline mapping is on, +or to the next line at the same x co-ordinate +if it is off. +A return +(\'\er\') +will move to the beginning of the line on the window. +Tabs +(\'\et\') +will be expanded into spaces +in the normal tabstop positions of +every eight characters. +\*(Es +.Ds +.Fn addchstr "chtype *str" \(dg +.De +Add the characters and attributes in the string pointed to by +.Vn str +on the window at the current \*y. +\*(Es +In this case, it will put on as much as it can. +.Ds +.Fn addchnstr "chtype *str" "int len" \(dg +.De +Add no more than +.Vn len +characters and attributes of the string pointed to by +.Vn str +on the window at the current \*y. +\*(Es +In this case, it will put on as much as it can. +.Ds +.Fn addstr "char *str" \(dg +.De +Add the string pointed to by +.Vn str +on the window at the current \*y. +\*(Es +In this case, it will put on as much as it can. +.Ds +.Fn addnstr "char *str" "int len" \(dg +.De +Add no more than +.Vn len +characters of the string pointed to by +.Vn str +on the window at the current \*y. +\*(Es +In this case, it will put on as much as it can. +.Ds +.Fn assume_default_colors "short fore" "short back" +.De +Set the curses default foreground and background colors to +.Vn fore +and +.Vn back . +.Ds +.Fn attr_get "attr_t *attr" "short *pair" "void *opt" \(dg +.De +Get the attributes and colour pair for the window. +Either +.Vn attr +or +.Vn pair +may be NULL. +The +.Vn opt +argument is not used. +.Ds +.Fn attr_off "attr_t attr" "void *opt" \(dg +.De +Remove character attributes set by +.Fn attr_on +or +.Fn attr_set . +.Ds +.Fn attr_on "attr_t attr" "void *opt" \(dg +.De +Add character attributes for any characters +added to the window (if it has that capability). +The attributes that can be set are \fBA_UNDERLINE\fR, +\fBA_REVERSE\fR, \fBA_BLINK\fR, \fBA_DIM\fR, +\fBA_BOLD\fR, \fBA_BLANK\fR, \fBA_PROTECT\fB, +\fBA_ALTCHARSET\fR and \fBCOLOR_PAIR(n)\fR. +.Ds +.Fn attr_set "attr_t attr" "short pair" "void *opt" \(dg +.De +Set character attributes and color pair for any characters +added to the window (if it has that capability). +.Ds +.Fn attroff "int attribute" \(dg +.De +Remove character attributes set by +.Fn attron +or +.Fn attrset . +To clear all character attributes, use +.Fn attroff "A_ATTRIBUTES" . +.Fn attroff "A_STANDOUT" +is equivalent to +.Fn standend . +.Fn attroff "A_UNDERLINE" +is equivalent to +.Fn underend . +.Ds +.Fn attron "int attribute" \(dg +.De +Add character attributes for any characters +added to the window (if it has that capability). +.Fn attron "A_STANDOUT" +is equivalent to +.Fn standout . +.Fn attron "A_UNDERLINE" +is equivalent to +.Fn underscore . +.Ds +.Fn attrset "int attribute" \(dg +.De +Set character attributes for any characters +added to the window (if it has that capability). +.Ds +.Fn baudrate "" \(dg +.De +Returns the output baud rate of the terminal. +This is a system dependent constant +(defined in +.b +on BSD systems, +which is included by +.b ). +.Ds +.Fn beep "" +.De +Sound the terminal bell. If the terminal has no bell capability, +but has the ability to flash the screen, do that instead. See also +.Fn flash +.Ds +.Fn bkgd "chtype ch" +.De +Sets the background rendition to +.Vn ch . +.Ds +.Fn bkgdset "chtype ch" +.De +Sets the background rendition to +.Vn ch +and applies this rendition to the window. +.Ds +.Fn border "chtype left" "chtype right" "chtype top" "chtype bottom" "chtype topleft" "chtype topright" "chtype botleft" "chtype botright" +.De +.Pp +Draws a border around the window using the characters: +.Vn left +for drawing the left side, +.Vn right +for drawing the left side, +.Vn top +for drawing the top edge, +.Vn bottom +for drawing the top edge, +.Vn topleft +for drawing the top-left corner, +.Vn topright +for drawing the top-right corner, +.Vn botleft +for drawing the bottom-left corner, and +.Vn botright +for drawing the bottom-right corner. If scrolling is not allowed, +and the window encompasses the lower right-hand corner of the terminal, +the corners are left blank to avoid a scroll. +.Ds +.Fn box "WINDOW win" "chtype vert" "chtype hor" +.De +.Pp +Draws a box around the window using +.Vn vert +as the character for drawing the vertical sides, and +.Vn hor +for drawing the horizontal lines. +If scrolling is not allowed, +and the window encompasses the lower right-hand corner of the terminal, +the corners are left blank to avoid a scroll. +.Ds +.Fn can_change_color "" +.De +Check if terminal can change colors. +.Ds +.Fn cbreak "" +.De +Set the terminal to cbreak mode. +.Ds +.Fn clear "" \(dg +.De +Resets the entire window to blanks. +If +.Vn win +is a screen, +this sets the clear flag, +which will cause a clear-screen sequence to be sent +on the next +.Fn refresh +call. +This also moves the current \*y +to (0\*,0). +.Ds +.Fn clearok "WINDOW *scr" "int boolf" \(dg +.De +Sets the clear flag for the screen +.Vn scr . +If +.Vn boolf +is non-zero, +this will force a clear-screen to be printed on the next +.Fn refresh , +or stop it from doing so if +.Vn boolf +is 0. +This only works on screens, +and, +unlike +.Fn clear , +does not alter the contents of the screen. +If +.Vn scr +is +.Vn curscr , +the next +.Fn refresh +call will cause a clear-screen, +even if the window passed to +.Fn refresh +is not a screen. +.Ds +.Fn clrtobot "" \(dg +.De +Wipes the window clear from the current \*y to the bottom. +This does not force a clear-screen sequence on the next refresh +under any circumstances. +\*(Nm +.Ds +.Fn clrtoeol "" \(dg +.De +Wipes the window clear from the current \*y to the end of the line. +\*(Nm +.Ds +.Fn color_content "short color" "short *red" "short *green" "short *blue" +.De +Get the red, green and blue values of color +.Vn color . +.Ds +.Fn color_set "short pair" "void *opt" \(dg +.De +Set color pair for any characters added to the window (if it has +that capability). +.Ds +.Fn copywin "const WINDOW *src" "WINDOW *dst" "int sminrow" "int smincol" "int dminrow" "int dmincol" "int dmaxrow" "int dmaxcol" "int overlay" +.De +Copies the contents of the window +.Vn src +starting at ( +.Vn sminrow , +.Vn smincol ) +to the destination window +.Vn dst +starting at ( +.Vn dminrow , +.Vn dmincol ) +and ending at either the end of the source window or ( +.Vn dmaxrow , +.Vn dmaxcol ) +whichever is the lesser. The parameter +.Vn overlay +determines the nature of the copy. If +.Vn overlay +is TRUE then only the non-space characters from +.Vn src +are copied to +.Vn dst . +If +.Vn overlay +is FALSE then all characters are copied from +.Vn src +to +.Vn dst. +.Ds +.Fn curs_set "int visibility" +.De +Sets the visibility of the screen cursor. The parameter +.Vn visibility +can be one of three values, 0 means make the cursor invisible, 1 means +set the cursor to normal visibility and 2 sets the cursor to high +visibility. In all cases the old mode of the cursor is returned if +the call was successful and +.b ERR +is returned if the terminal cannot support the requested visibility +mode. +.Ds +.Fn crmode "" \(dg +.De +Identical to +.Fn cbreak . +The misnamed macro +.Fn crmode +and +.Fn nocrmode +is retained for backwards compatibility +with ealier versions of the library. +.Ds +.Fn delay_output "int ms" +.De +Pause output for +.Vn ms +milliseconds using the terminal pad character. +.Ds +.Fn def_prog_mode "" +.De +Save the current terminal modes as the \'in curses\' state for use with +.Fn reset_prog_mode . +.Ds +.Fn def_shell_mode "" +.De +Save the current terminal modes as the \'not in curses\' state for use with +.Fn reset_shell_mode . +.Ds +.Fn define_key "char *sequence" "int key_symbol" +.De +Assigns the character sequence given in +.Vn sequence +to the key symbol +.Vn key_symbol . +If +.Fn keypad +has set been set TRUE and the character sequence is found in the input +stream then the key symbol defined will be returned. Normally the +sequences are found in the +.b termcap +database but this function allows extensions to be added by the +application. If +.Vn sequence +is a NULL pointer then all the sequences associated with +.Vn key_symbol +will be removed, including any definitions inserted by +.b termcap . +.Ds +.Fn delch "" +.De +Delete the character at the current \*y. +Each character after it on the line shifts to the left, +and the last character becomes blank. +.Ds +.Fn deleteln "" +.De +Delete the current line. +Every line below the current one will move up, +and the bottom line will become blank. +The current \*y will remain unchanged. +.Ds +.Fn delscreen "SCREEN *screen" +.De +Delete the screen and frees all associated resources. +.Ds +.Fn delwin "WINDOW *win" +.De +Deletes the window from existence. +All resources are freed for future use by +.b calloc (3). +If a window has a +.Fn subwin +allocated window inside of it, +deleting the outer window +the subwindow is not affected, +even though this does invalidate it. +Therefore, +subwindows should be deleted before their +outer windows are. +.Ds +.Fn derwin "WINDOW *orig" "int nlines" "int ncols" "int by" "int bx" +.De +Performs a function very similar to that of +.Fn subwin . +The difference being that with +.Fn derwin +the origin of the child window given by ( +.Vn by , +.Vn bx ) +is relative to the origin of the parent window +.Vn orig +instead of being absolute screen coordinates as they are in +.Fn subwin . +.Ds +.Fn doupdate "" +.De +Synchronize the terminal screen with the virtual screen that +has had window contents added to it by calls to +.Fn wnoutrefresh . +.Ds +.Fn dupwin "WINDOW *win" +.De +Creates an exact copy of the window +.Vn win . +.Ds +.Fn echo "" \(dg +.De +Sets the terminal to echo characters. +.Ds +.Fn echochar "const chtype ch" \(dg +.De +Add the character +.Vn ch +on the window +at the current \*y and immediately refresh the window. +.Ds +.Fn endwin "" +.De +Finish up window routines before exit. +This restores the terminal to the state it was before +.Fn initscr +(or +.Fn gettmode +and +.Fn setterm ) +was called. +It should always be called before exiting and before the final calls to +.Fn delwin . +It does not exit. +This is especially useful for resetting tty stats +when trapping rubouts via +.b signal (2). +.Ds +.Fn erase "" \(dg +.De +Erases the window to blanks without setting the clear flag. +This is analagous to +.Fn clear , +except that it never causes a clear-screen sequence to be generated +on a +.Fn refresh . +\*(Nm +.Ds +.Fn erasechar "" \(dg +.De +Returns the erase character +for the terminal, +.i i.e. , +the character used by the user to erase a single character from the input. +.Ds +.Fn flash "" +.De +Flash the terminal screen. If the terminal has no flash capability, +but has the ability to sound the bell, do that instead. See also +.Fn bell +.Ds +.Fn flushinp "" +.De +Throw away any input that has been typed by the user but has not yet +been read by the program. +.Ds +.Fn flushok "WINDOW *win" "int boolf" +.De +Normally, +.Fn refresh +.Fn fflush 's +.Vn stdout +when it is finished. +.Fn flushok +allows you to control this. +if +.Vn boolf +is non-zero +(\c +.i i.e. , +non-zero) +it will do the +.Fn fflush , +otherwise it will not. +.Ds +.Fn getattrs "WINDOW *win" +.De +Gets the attributes for +.Vn win . +.Ds +.Fn getbkgd "WINDOW *win" +.De +Gets the background rendition for +.Vn win . +.Ds +.Fn getcap "char *name" +.De +Get the terminal capability +.Vn name . +.Ds +.Fn getch "" \(dg +.De +Gets a character from the terminal and (if necessary) +echos it on the window. +\*(Es +Otherwise, the character gotten is returned. +If +.i noecho +has been set, then the window is left unaltered. +In order to retain control of the terminal, +it is necessary to have one of +.i noecho , +.i cbreak , +or +.i rawmode +set. +If you do not set one, +whatever routine you call to read characters will set +.i cbreak +for you, +and then reset to the original mode when finished. +.Ds +.Fn getcury "WINDOW *win" +.De +Get current y position on +.Vn win . +.Ds +.Fn getcurx "WINDOW *win" +.De +Get current x position on +.Vn win . +.Ds +.Fn getbegy "WINDOW *win" +.De +Get start y position on +.Vn win . +.Ds +.Fn getbegx "WINDOW *win" +.De +Get start x position on +.Vn win . +.Ds +.Fn getmaxy "WINDOW *win" +.De +Get maximum y position on +.Vn win . +.Ds +.Fn getmaxx "WINDOW *win" +.De +Get maximum x position on +.Vn win . +.Ds +.Fn getnstr "char *str" \(dg +.De +Get a string through the window +and put it in the location pointed to by +.Vn str . +A maximum of +.Vn n +characters is returned (including the trailing null). +It sets tty modes if necessary, +and then calls +.Fn getch +(or +.Fn wgetch ) +to get the characters needed to fill in the string +until a newline or EOF is encountered. +The newline stripped off the string. +\*(Es +.Ds +.Fn getstr "char *str" \(dg +.De +Get a string through the window +and put it in the location pointed to by +.Vn str , +which is assumed to be large enough to handle it. +It sets tty modes if necessary, +and then calls +.Fn getch +(or +.Fn wgetch ) +to get the characters needed to fill in the string +until a newline or EOF is encountered. +The newline stripped off the string. +\*(Es +.Ds +.Fn getparx "WINDOW *win" +.De +Returns the x location of the given subwindow relative to the parent +window. If the window is not a subwindow then -1 is returned. +.Ds +.Fn getpary "WINDOW *win" +.De +Returns the y location of the given subwindow relative to the parent +window. If the window is not a subwindow then -1 is returned. +.Ds +.Fn getpary "WINDOW *win" "int y" "int x" +.De +Is a macro that sets the +.Vn y +and +.Vn x +parameters to the respective coordinates of the top left hand corner +of the subwindow relative to the parent window. If the given window +.Vn win +is not a subwindow then both +.Vn y +and +.Vn x +will be set to -1. +.Ds +.Fn gettmode "" +.De +Get the tty stats. +This is normally called by +.Fn initscr . +.Ds +.Fn getwin "FILE *fp" +.De +Creates a window from a file written by +.Fn putwin . +.Ds +.Fn getyx "WINDOW *win" "int y" "int x" +.De +Puts the current \*y of +.Vn win +in the variables +.Vn y +and +.Vn x . +Since it is a macro, +not a function, +you do not pass the address +of +.Vn y +and +.Vn x . +.Ds +.Fn halfdelay "int timeout" +.De +Sets the terminal into a mode similar to that done by +.Fn cbreak +with the exception that the input routines will wait for +.Vn timeout +number of tenths of a second, if at this time there is no input then +ERR will be returned. +.Ds +.Fn has_colors "" +.De +Check if terminal has colors. +.Ds +.Fn hline "chtype ch" "int count" +.De +Draw a horizontal line of the character ch starting at the current +cursor position and moving towards the rightmost column. At most +.Vn count +characters will be written, less if the edge of the screen is reached +before +.Vn count +is reached. +.Ds +.Fn idcok "WINDOW *win" "int boolf" +.De +Reserved for future use. +This will eventually signal to +.Fn refresh +that it is all right to use the insert and delete char sequences +when updating the window. +.Ds +.Fn idlok "WINDOW *win" "int boolf" +.De +Reserved for future use. +This will eventually signal to +.Fn refresh +that it is all right to use the insert and delete line sequences +when updating the window. +.ne 1i +.Ds +.Fn inch "" \(dg +.De +Returns the character at the current position on the given window. +This does not make any changes to the window. +.Ds +.Fn inchnstr "chtype *chstr" "int n" +.De +Get an array of at most +.Vn n +characters and renditions starting at the current cursor position and +ending at the end of the line and put it in the location pointed to by +.Vn chstr . +.Ds +.Fn inchstr "chtype *chstr" +.De +Get an array of characters and renditions starting at the current cursor +position and ending at the end of the line and put it in the location +pointed to by +.Vn chstr , +which is assumed to be large enough to handle it. +.Ds +.Fn innstr "char *str" "int n" +.De +Get a string of at most +.Vn n +characters starting at the current cursor position and ending at the end +of the line and put it in the location pointed to by +.Vn str . +.Ds +.Fn init_color "short color" "short red" "short green" "short blue" +.De +Set the red, green and blue values of color +.Vn color . +.Ds +.Fn init_pair "short pair" "short fore" "short back" +.De +Set the foreground and background colors of pair +.Vn pair . +.Ds +.Fn initscr "" +.De +Initialize the screen routines. +This must be called before any of the screen routines are used. +It initializes the terminal-type data and such, +and without it none of the routines can operate. +If standard input is not a tty, +it sets the specifications to the terminal +whose name is pointed to by +.Vn Def\*_term +(initially "dumb"). +If the boolean +.Vn My\*_term +is non-zero, +.Vn Def\*_term +is always used. +If the system supports the +.b TIOCGWINSZ +.i ioctl(2) +call, +it is used to get the number of lines and columns for the terminal, +otherwise it is taken from the +.b termcap +description. +.Ds +.Fn insch "char c" +.De +Insert +.Vn c +at the current \*y +Each character after it shifts to the right, +and the last character disappears. +\*(Es +.Ds +.Fn insdelln "int n" +.De +If +.Vn n +is positive insert +.Vn n +lines above the current one. +Every line below the current line +will be shifted down, +and the last +.Vn n +lines will disappear. +If +.Vn n +is negative, delete +.Vn n +lines starting from the current one. +The last +.Vn n +lines are cleared. +The current \*y will remain unchanged. +.Ds +.Fn insertln "" +.De +Insert a line above the current one. +Every line below the current line +will be shifted down, +and the bottom line will disappear. +The current line will become blank, +and the current \*y will remain unchanged. +.Ds +.Fn instr "char *str" +.De +Get an string starting at the current cursor position and ending at the +end of the line and put it in the location pointed to by +.Vn str , +which is assumed to be large enough to handle it. +.Ds +.Fn is_linetouched "WINDOW *win" "int line" +.De +Returns TRUE if +.Vn line +in the window +.Vn win +has been modified since the last call to +.Fn wrefresh . +.Ds +.Fn is_wintouched "WINDOW *win" "int line" +.De +Returns TRUE if the window +.Vn win +has been modified since the last call to +.Fn wrefresh . +.Ds +.Fn isendwin "" +.De +Returns TRUE if +.Fn endwin +has been called without a subsequent call to +.Fn wrefresh , +and FALSE otherwise. +.Ds +.Fn intrflush "WINDOW *win" "int boolf" +.De +Sets the terminal flush on interrupt mode. If +.Vn boolf +is non-zero, flushing of the output buffer will occur when an +interrupt key is pressed. The default is inherited from the +terminal settings. +.Ds +.Fn keyok "int key_symbol" "bool flag" +.De +Controls the recognition of the key symbol +.Vn key_symbol . +By setting +.Vn flag +to FALSE the recognition of any sequence of characters +that have been associated with the key symbol will be disabled. +By default, this flag is TRUE so sequences will be recognised. +.Ds +.Fn keyname "int key" +.De +Returns a description of the key +.Vn key . +.Ds +.Fn keypad "WINDOW *win" "int boolf" +.De +Sets the boolean flag for interpretation of escape sequences. If +.Vn boolf +is non-zero, escape sequences from terminal keypad and function +keys will be interpreted by the library. Escape sequences are not +interpreted by default. The include file +.b +contains the list of recognised keypad and function keys. See also +.Fn notimeout . +.Ds +.Fn killchar "" \(dg +.De +Returns the line kill character +for the terminal, +.i i.e. , +the character used by the user to erase an entire line from the input. +.Ds +.Fn leaveok "WINDOW *win" "int boolf" \(dg +.De +Sets the boolean flag for leaving the cursor after the last change. +If +.Vn boolf +is non-zero, +the cursor will be left after the last update on the terminal, +and the current \*y for +.Vn win +will be changed accordingly. +If +.Vn boolf + is 0 the cursor will be moved to the current \*y. +This flag +(initially 0) +retains its value until changed by the user. +.Ds +.Fn longname "" \(dg +.De +Returns a string containing the verbose description of the terminal. +.Ds +.Fn meta "WINDOW *win" "bool bf" +.De +Manipulates the meta mode on terminals that support this capability. +Note that +.Vn win +is always ignored. +.Ds +.Fn move "int y" "int x" +.De +Change the current \*y of the window to +.Vn y\*,x ). ( +\*(Es +.Ds +.Fn mvaddch "int y" "int x" "chtype ch" +.De +Moves the cursor to the position +.Vn (y , +.Vn x ) +and then adds a character in the same manner as +.Fn addch . +.Ds +.Fn mvaddchstr "int y" "int x" "chtype *str" \(dg +.De +Moves the cursor to the position +.Vn (y , +.Vn x ) +and then adds characters and attributes in the same manner as +.Fn addchstr . +.Ds +.Fn mvaddchnstr "int y" "int x" "chtype *str" \(dg +.De +Moves the cursor to the position +.Vn (y , +.Vn x ) +and then adds characters and attributes in the same manner as +.Fn addchnstr . +.Ds +.Fn mvaddstr "int y" "int x" "char *str" \(dg +.De +Moves the cursor to the position +.Vn (y , +.Vn x ) +and then adds a string in the same manner as +.Fn addstr . +.Ds +.Fn mvaddnstr "int y" "int x" "char *str" \(dg +.De +Moves the cursor to the position +.Vn (y , +.Vn x ) +and then adds a string in the same manner as +.Fn addnstr . +.Ds +.Fn mvcur "int lasty" "int lastx" "int newy" "int newx" +.De +Moves the terminal's cursor from +.Vn lasty\*,lastx ) ( +to +.Vn newy\*,newx ) ( +in an approximation of optimal fashion. +This routine uses the functions borrowed from +.i ex +version 2.6. +It is possible to use this optimization +without the benefit of the screen routines. +With the screen routines, this should not be called by the user. +.Fn move +and +.Fn refresh +should be used to move the cursor position, +so that the routines know what's going on. +.Ds +.Fn mvderwin "WINDOW *win" "int y" "int x" +.De +Moves the subwindow +.Vn win +to the location +.Vn y\*,x ) ( +where the location is relative to the top left hand corner of the +parent window. This call will return ERR if +.Vn win +is not a subwindow or if the relocated window would lie outside the +parent window. +.Ds +.Fn mvhline "int y" "int x" "chtype ch" "int count" +.De +Moves the cursor to the position +.Vn (y , +.Vn x ) +and then draws a horizontal line in the same manner as +.Fn hline . +.Ds +.Fn mvprintw "int y" "int x" "const char *fmt" "..." +.De +Equivalent to: +.(l +move(y, x); +printw(fmt, ...); +.)l +.Ds +.Fn mvscanw "int y" "int x" "const char *fmt" "..." +.De +Equivalent to: +.(l +move(y, x); +scanw(fmt, ...); +.)l +.Ds +.Fn mvvline "int y" "int x" "chtype ch" "int count" +.De +Moves the cursor to the position +.Vn (y , +.Vn x ) +and then draws a vertical line in the same manner as +.Fn vline . +.Ds +.Fn mvwhline "WINDOW *win" "int y" "int x" "chtype ch" "int count" +.De +Moves the cursor to the position +.Vn (y , +.Vn x ) +on window +.Vn win +and then draws a horizontal line in the same manner as +.Fn whline . +.Ds +.Fn mvwvline "WINDOW *win" "int y" "int x" "chtype ch" "int count" +.De +Moves the cursor to the position +.Vn (y , +.Vn x ) +on window +.Vn win +and then draws a horizontal line in the same manner as +.Fn wvline . +.Ds +.Fn mvwin "WINDOW *win" "int y" "int x" +.De +Move the home position of the window +.Vn win +from its current starting coordinates +to +.Vn y\*,x ). ( +If that would put part or all of the window +off the edge of the terminal screen, +.Fn mvwin +returns ERR and does not change anything. +For subwindows, +.Fn mvwin +also returns ERR if you attempt to move it off its main window. +If you move a main window, +all subwindows are moved along with it. +.Ds +.Fn mvwprintw "WINDOW *win" "int y" "int x" "const char *fmt" "..." +.De +Equivalent to: +.(l +wmove(win, y, x); +printw(fmt, ...); +.)l +.Ds +.Fn mvwscanw "WINDOW *win" "int y" "int x" "const char *fmt" "..." +.De +Equivalent to: +.(l +wmove(win, y, x); +scanw(fmt, ...); +.)l +.Ds +.Fn napms "int ms" +.De +Sleep for +.Vn ms +milliseconds. +.Ds +.Ft "WINDOW *" +.Fn newpad "int lines" "int cols" +.De +Create a new pad with +.Vn lines +lines and +.Vn cols +columns. +.Ds +.Ft "SCREEN *" +.Fn newterm "char *type" "FILE *outfd" "FILE *infd" +.De +Iinitialise the curses subsystem to use the terminal of type +.Vn type +connected via the input and output streams +.Vn infd,outfd. +The +.Fn newterm +is used in multi-terminal applications and returns a pointer to a +.Ft "SCREEN" +structure that holds the state for that particular terminal. The +application may swap between the terminals by calling the +.Fn set_term +function. If the +.Vn type +parameter is NULL then the $TERM variable is used as the terminal type. +.Ds +.Ft "WINDOW *" +.Fn newwin "int lines" "int cols" "int begin_y" "int begin_x" +.De +Create a new window with +.Vn lines +lines and +.Vn cols +columns starting at position +.Vn begin\*_y\*,begin\*_x ). ( +If either +.Vn lines +or +.Vn cols +is 0 (zero), +that dimension will be set to +.Vn "LINES \- begin\*_y" ) ( +or +.Vn "COLS \- begin\*_x" ) ( +respectively. +Thus, to get a new window of dimensions +.Vn LINES +\(mu +.Vn COLS , +use +.Fn newwin 0 0 0 0 . +.Ds +.Fn nl "" +.De +Set the terminal to nl mode, +.i i.e. , +start/stop the system from mapping +.b +to +.b . +If the mapping is not done, +.Fn refresh +can do more optimization, +so it is recommended, but not required, to turn it off. +.Ds +.Fn no_color_video "" +.De +Return attributes that cannot be combined with color. +.Ds +.Fn nocbreak "" +.De +Unset the terminal from cbreak mode. +.Ds +.Fn nocrmode "" \(dg +.De +Identical to +.Fn nocbreak . +The misnamed macro +.Fn nocrmode +is retained for backwards compatibility +with ealier versions of the library. +.Ds +.Fn nodelay "WINDOW *win1" "int boolf" +.De +Sets the boolean flag for non-blocking +.Fn getch . +If +.Vn boolf +is non-zero, +.Fn getch +will return ERR is no input is waiting. The default +is to for +.Fn getch +to block indefinitely. See also +.Fn timeout . +.Ds +.Fn noecho "" \(dg +.De +Turn echoing of characters off. +.Ds +.Fn nonl "" +.De +Unset the terminal to from nl mode. See +.Fn nl . +.ne 1i +.Ds +.Fn noqiflush \(dg +.De +Unset the terminal flush on interrupt mode. +This is equivalent to +.Fn intrflush stdscr FALSE . +.Ds +.Fn noraw "" +.De +Unset the terminal from raw mode. See +.Fn raw . +.Ds +.Fn notimeout "WINDOW *win1" "int boolf" +.De +Sets the boolean flag for inter-key timeouts +for escape sequences interpreted when +.Fn keypad +is set. +By default, +.Fn keypad +sets a timer while waiting for the next character of +an escape sequence. +If +.Vn boolf +is non-zero, +.Fn getch +will wait indefinitely between escape sequence characters, +or until a delay set by +.Fn timeout +expires. +.Ds +.Fn overlay "WINDOW *win1" "WINDOW *win2" +.De +Overlay +.Vn win1 +on +.Vn win2 . +The contents of +.Vn win1 , +insofar as they fit, +are placed on +.Vn win2 +at their starting \*y. +This is done non-destructively, +i.e., blanks on +.Vn win1 +leave the contents of the space on +.Vn win2 +untouched. Note that all non-blank characters are overwritten +destructively in the overlay. +.Ds +.Fn overwrite "WINDOW *win1" "WINDOW *win2" +.De +Overwrite +.Vn win1 +on +.Vn win2 . +The contents of +.Vn win1 , +insofar as they fit, +are placed on +.Vn win2 +at their starting \*y. +This is done destructively, +.i i.e. , +blanks on +.Vn win1 +become blank on +.Vn win2 . +.Ds +.Fn pair_content "short pair" "short *fore" "short *back" +.De +Get the foreground and background colors of pair +.Vn pair . +.Ds +.Fn pechochar "const chtype ch" \(dg +.De +Add the character +.Vn ch +on the pad +at the current \*y and immediately refresh the pad. +.Ds +.Fn pnoutrefresh "WINDOW *pad" "int pbeg_y" "int pbeg_x" "int sbeg_y" "int sbeg_x" "int smax_y" "int smax_x" +.De +Add the pad contents to a virtual screen. Several pads can be added +before a call to +.Fn doupdate , +thus allowing the screen to updated in an efficient manner. +.Ds +.Fn prefresh "WINDOW *pad" "int pbeg_y" "int pbeg_x" "int sbeg_y" "int sbeg_x" "int smax_y" "int smax_x" +.De +Synchronize the terminal screen with the desired pad. +.Ds +.Fn printw "char *fmt" "..." +.De +Performs a +.Fn printf +on the window starting at the current \*y. +It uses +.Fn addstr +to add the string on the window. +It is often advisable to use the field width options of +.Fn printf +to avoid leaving things on the window from earlier calls. +\*(Es +.Ds +.Fn putwin "WINDOW *win" "FILE *fp" +.De +Writes the window data to a file. +.Ds +.Fn qiflush \(dg +.De +Set the terminal flush on interrupt mode. +This is equivalent to +.Fn intrflush stdscr TRUE . +.Ds +.Fn raw "" +.De +Set the terminal to raw mode. +On version 7 +.Un \** +.(f +\** +.Un +is a trademark of Unix System Laboratories. +.)f +this also turns off newline mapping +(see +.Fn nl ). +.Ds +.Fn redrawwin "WINDOW *win" \(dg +.De +Mark the entire window as having been corrupted. +This is equivalent to the +.Fn touchwin +function. +.Ds +.Fn refresh "" \(dg +.De +Synchronize the terminal screen with the desired window. +If the window is not a screen, +only that part covered by it is updated. +\*(Es +In this case, it will update whatever it can +without causing the scroll. +.sp +As a special case, +if +.Fn wrefresh +is called with the window +.Vn curscr +the screen is cleared +and repainted as it is currently. +This is very useful for allowing the redrawing of the screen +when the user has garbage dumped on his terminal. +.Ds +.Fn reset_prog_mode "" +.De +Restore the terminal to the \'in curses\' state. +.Ds +.Fn reset_shell_mode "" +.De +Restore the terminal to the \'not in curses\' state. +.Ds +.Fn resetty "" \(dg +.De +.Fn resetty +restores them to what +.Fn savetty +stored. +These functions are performed automatically by +.Fn initscr +and +.Fn endwin . +This function should not be used by the user. +.Ds +.Fn resizeterm "int lines" "int columns" \(dg +.De +Resizes the curses terminal to the given size. All internal curses +structures are resized to the new dimensions and all curses windows that +would have boundaries outside the new terminal size will be resized to fit +within the new boundaries. All windows will be cleared and it is expected +that the application will redraw the window contents. +.Ds +.Fn savetty "" \(dg +.De +.Fn savetty +saves the current tty characteristic flags. See +.Fn resetty . +This function should not be used by the user. +.Ds +.Fn scanw "char *fmt" "..." +.De +Perform a +.Fn scanf +through the window using +.Vn fmt . +It does this using consecutive calls to +.Fn getch +(or +.Fn wgetch ). +\*(Es +.ne 1i +.Ds +.Fn scrl "int n" +.De +Scroll the window by +.Vn n +lines. If +.Vn n +is positive, scroll upward, otherwise +scroll downward. +.Ds +.Fn scroll "WINDOW *win" +.De +Scroll the window upward one line. +This is normally not used by the user. +.Ds +.Fn scrollok "WINDOW *win" "int boolf" \(dg +.De +Set the scroll flag for the given window. +If +.Vn boolf +is 0, scrolling is not allowed. +This is its default setting. +.Ds +.Ft "SCREEN *" +.Fn set_term "SCREEN *new" +.De +Sets the current screen for input and output to be the one given. The +.Vn new +structure must be one that has been previously created by the +.Fn newterm +function. The +.Fn set_term +function returns the previous screen on successful completion. +.Ds +.Fn standend "" \(dg +.De +End standout mode initiated by +.Fn standout . +This function is provided for compatibility +with older curses implementations. +.Ds +.Fn standout "" \(dg +.De +Causes any characters added to the window +to be put in standout mode on the terminal +(if it has that capability). This function +is provided for compatibility with older curses +implementations. A larger range of character +attributes supported by modern terminals can be +accessed using +.Fn attron +and +.Fn attrset . +.Ds +.Fn start_color "" +.De +Initialize the color routines. +This must be called before any of the color routines are used. +The terminal is setup to use the curses default colors of white foreground +on black background, unless +.Fn assume_default_colors +or +.Fn use_default_colors +are called. +.Ds +.Ft "WINDOW *" +.Fn subpad "WINDOW *win" "int lines" "int cols" "int begin_y" "int begin_x" +.De +Create a new pad with +.Vn lines +lines and +.Vn cols +columns starting at position +.Vn begin\*_y\*,begin\*_x ) ( +inside the pad +.i win . +This means that any change made to either pad +in the area covered +by the subpad will be made on both pads. +.Vn begin\*_y\*,begin\*_x +are specified relative to the relative (0\*,0) of +.Vn win . +.Ds +.Ft "WINDOW *" +.Fn subwin "WINDOW *win" "int lines" "int cols" "int begin_y" "int begin_x" +.De +Create a new window with +.Vn lines +lines and +.Vn cols +columns starting at position +.Vn begin\*_y\*,begin\*_x ) ( +inside the window +.i win . +This means that any change made to either window +in the area covered +by the subwindow will be made on both windows. +.Vn begin\*_y\*,begin\*_x +are specified relative to the overall screen, +not the relative (0\*,0) of +.Vn win . +If either +.Vn lines +or +.Vn cols +is 0 (zero), +that dimension will be set to +.Vn "LINES \- begin\*_y" ) ( +or +.Vn "COLS \- begin\*_x" ) ( +respectively. +.Ds +.Fn termattrs "" +.De +Returns the attributes that can be applied to the screen. +.Ds +.Fn term_attrs "" +.De +Returns the wide attributes that can be applied to the screen. +.Ds +.Fn timeout "int delay" \(dg +.De +Sets blocking or non-blocking +.Fn getch . +If +.Vn delay +is positive, +.Fn getch +will block for +.Vn delay +milliseconds before returning. If +.Vn delay +is zero, +.Fn getch +will return ERR is no input is waiting. If +.Vn delay +is negative, +.Fn getch +will block indefinitely. See also +.Fn keypad , +.Fn nodelay +and +.Fn notimeout . +.Ds +.Fn touchline "WINDOW *win" "int y" "int startx" "int endx" +.De +This function performs a function similar to +.Fn touchwin +on a single line. +It marks the first change for the given line +to be +.Vn startx , +if it is before the current first change mark, +and +the last change mark is set to be +.Vn endx +if it is currently less than +.Vn endx . +.Ds +.Fn touchoverlap "WINDOW *win1" "WINDOW *win2" +.De +Touch the window +.Vn win2 +in the area which overlaps with +.Vn win1 . +If they do not overlap, +no changes are made. +.Ds +.Fn touchwin "WINDOW *win" +.De +Make it appear that the every location on the window +has been changed. +This is usually only needed for refreshes with overlapping windows. +.Ds +.Fn tstp +.De +This function +will save the current tty state +and then put the process to sleep. +When the process gets restarted, +it restores the saved tty state +and then calls +.Fn wrefresh "curscr" +to redraw the screen. +.Fn Initscr +sets the signal +SIGTSTP +to trap to this routine. +.Ds +.Fn unctrl "char *ch" \(dg +.De +Returns a string which is an ASCII representation of +.Vn ch . +Characters are 8 bits long. +.Ds +.Fn unctrllen "char *ch" \(dg +.De +Returns the length of the ASCII representation of +.Vn ch . +.ne 1i +.Ds +.Fn underend "" \(dg +.De +End underscore mode initiated by +.Fn underscore . +This is equivalent to +.Fn attroff "A_UNDERLINE" . +.Ds +.Fn underscore "" \(dg +.De +Causes any characters added to the window +to be put in underscore mode on the terminal +(if it has that capability). +This is equivalent to +.Fn attron "A_UNDERLINE" . +.Ds +.Fn ungetch "int c" +.De +Places the contents of +.Vn c +converted to a character back into the input queue. Only one +character of push back before a subsequent call to +.Fn getch +or +.Fn wgetch +is guaranteed to function correctly. The results of attempting more +than one character of push back is undefined. +.Ds +.Fn untouchwin "WINDOW *win" +.De +Make the window appear to have not been updated even if it has been. +.Ds +.Fn use_default_colors "" +.De +Use the terminal foreground and background colors as the curses default +foreground and background colors. +.Ds +.Fn vline "chtype ch" "int count" +.De +Draws a vertical line of character +.Vn ch +starting at the current cursor location and moving towards the bottom +of the screen. At most +.Vn count +characters are drawn, less if the bottom of the screen is reached +before +.Vn count +expires. +.Ds +.Fn vwprintw "WINDOW *win" "const char *fmt" "va_list ap" +.De +Identical to +.Fn printw +except that it takes both a window specification and a pointer to a variable +length argument list. +.Ds +.Fn vwscanw "WINDOW *win" "const char *fmt" "va_list ap" +.De +Identical to +.Fn scanw +except that it takes both a window specification and a pointer to a variable +length argument list. +.Ds +.Fn wnoutrefresh "WINDOW *win" +.De +Add the window contents to a virtual screen. Several windows can be added +before a call to +.Fn doupdate , +thus allowing the screen to updated in an efficient manner. +.Ds +.Fn wredrawln "WINDOW *win" "int line" "int n" \(dg +.De +Mark +.Vn n +lines starting at +.Vn line +in the window as corrupted. +This is equivalent to +.Fn wtouchln "win" "line" "n" "1" . +.Ds +.Fn wresize "WINDOW *win" "int lines" "int columns" +.De +Resize the specified window to the given dimensions. The window will be +cleared and the application is expected to redraw the window contents. +.Ds +.Fn wtouchln "WINDOW *win" "int line" "int n" "int changed" +.De +If +.Vn changed +is 1 then +.Vn n +lines starting at +.Vn line +in the window are touched. If +.Vn changed +is 0 then +.Vn n +lines starting at +.Vn line +in the window are untouched. +.sp 2 +.pp +\fIThe following functions differ from the standard functions only in their +specification of a window, rather than the use of the default +.Vn stdscr.\fP +.Ds +.Fn waddbytes "WINDOW *win" "char* str" "int len" +.Fn waddch "WINDOW *win" "chtype ch" +.Fn waddchnstr "WINDOW *win" "chtype *str" "int len" +.Fn waddchstr "WINDOW *win" "chtype *str" "int len" +.Fn waddnstr "WINDOW *win" "char *str" "int len" +.Fn waddstr "WINDOW *win" "char *str" +.Fn wattroff "WINDOW *win" "int attr" +.Fn wattron "WINDOW *win" "int attr" +.Fn wattrset "WINDOW *win" "int attr" +.Fn wbkgd "WINDOW *win" "chtype ch" +.Fn wbkgdset "WINDOW *win" "chtype ch" +.Fn wborder "WINDOW *win" "chtype left" "chtype right" "chtype top" "chtype bottom" "chtype topleft" "chtype topright" "chtype botleft" "chtype botright" +.Fn wclear "WINDOW *win" +.Fn wclrtobot "WINDOW *win" +.Fn wclrtoeol "WINDOW *win" +.Fn wdelch "WINDOW *win" +.Fn wdeleteln "WINDOW *win" +.Fn wechochar "WINDOW *win" "chtype ch" +.Fn werase "WINDOW *win" +.Fn wgetch "WINDOW *win" +.Fn wgetnstr "WINDOW *win" "char *str" "int len" +.Fn wgetstr "WINDOW *win" "char *str" +.Fn whline "WINDOW *win" "chtype ch" "int count" +.Fn winch "WINDOW *win" \(dg +.Fn winchnstr "WINDOW *win" "chtype *chstr" "int n" +.Fn winchstr "WINDOW *win" "chtype *chstr" +.Fn winnstr "WINDOW *win" "char *str" "int n" +.Fn winsch "WINDOW *win" "char c" +.Fn winsdelln "WINDOW *win" "int n" +.Fn winsertln "WINDOW *win" +.Fn winstr "WINDOW *win" "char *str" +.Fn wmove "WINDOW *win" "int y" int x" +.Fn wprintw "WINDOW *win" "char *fmt" "..." +.Fn wrefresh "WINDOW *win" +.Fn wscanw "WINDOW *win" "char *fmt" "..." +.Fn wscrl "WINDOW *win" "int n" +.Fn wstandend "WINDOW *win" +.Fn wstandout "WINDOW *win" +.Fn wtimeout "WINDOW *win" "int delay" +.Fn wunderend "WINDOW *win" +.Fn wunderscore "WINDOW *win" +.Fn wvline "WINDOW *win" "chtype ch" "int count" +.Fn mvwaddch "WINDOW *win" "int y" "int x" "chtype ch" +.Fn mvwaddchstr "WINDOW *win" "int y" "int x" "chtype *str" \(dg +.Fn mvwaddchnstr "WINDOW *win" "int y" "int x" "chtype *str" \(dg +.Fn mvwaddnstr "WINDOW *win" "int y" "int x" "char *str" "int len" +.Fn mvwaddstr "WINDOW *win" "int y" "int x" "char *str" +.Fn mvwgetnstr "WINDOW *win" "int y" "int x" "char *str" "int len" +.Fn mvwgetstr "WINDOW *win" "int y" "int x" "char *str" +.Fn mvwhline "WINDOW *win" "int y" "int x" "chtype ch" "int count" +.Fn mvwvline "WINDOW *win" "int y" "int x" "chtype ch" "int count" + +.Dg diff --git a/lib/libcurses/PSD.doc/intro.0 b/lib/libcurses/PSD.doc/intro.0 new file mode 100644 index 000000000..ae6b808cc --- /dev/null +++ b/lib/libcurses/PSD.doc/intro.0 @@ -0,0 +1,104 @@ +.\" $NetBSD: intro.0,v 1.6 2003/08/07 16:44:27 agc Exp $ +.\" +.\" Copyright (c) 1980, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)intro.0 8.1 (Berkeley) 6/4/93 +.\" +.tp +.(l C +.ps 12 +.ft B +Screen Updating and Cursor Movement Optimization: +.fl +A Library Package +.ft +.ps +.sp +.i "Kenneth C. R. C. Arnold" +.i "Elan Amir" +.sp +Computer Science Division +Department of Electrical Engineering and Computer Science +University of California, Berkeley +Berkeley, California 94720 +.sp 3 +.bi ABSTRACT +.sp 2 +.)l +.(q +.pp +This document describes a package of C library functions +which allow the user to: +.ie t .ip \ \ \ \(bu +.el .ip 1) +update a screen with reasonable optimization, +.ie t .ip \ \ \ \(bu +.el .ip 2) +get input from the terminal +in a screen-oriented fashion, +and +.ie t .ip \ \ \ \(bu +.el .ip 3) +independent from the above, move the cursor optimally +from one point to another. +.pp +These routines all use the +\*(tc \*(db to describe the capabilities of the terminal. +.)q +.b Acknowledgements +.pp +This package would not exist +without the work of Bill Joy, +who, +in writing his editor, +created the capability to generally describe terminals, +wrote the routines which read this \*(db, +and, most importantly, +those which implement optimal cursor movement, +which routines I have simply lifted nearly intact. +Doug Merritt and Kurt Shoens also were extremely important, +as were both willing to waste time listening to me rant and rave. +The help and/or support of +Ken Abrams, +Alan Char, +Mark Horton, +and +Joe Kalash, +was, and is, +also greatly appreciated. +.i "Ken Arnold 16 April 1986" +.pp +The help and/or support of Kirk McKusick and Keith Bostic (public vi!) +was invaluable in bringing the package ``into the 90's'', which now +includes completely new data structures and screen refresh optimization +routines. +.i "Elan Amir 29 December 1992" + + + + diff --git a/lib/libcurses/PSD.doc/intro.1 b/lib/libcurses/PSD.doc/intro.1 new file mode 100644 index 000000000..14d1e39b0 --- /dev/null +++ b/lib/libcurses/PSD.doc/intro.1 @@ -0,0 +1,247 @@ +.\" $NetBSD: intro.1,v 1.7 2003/08/07 16:44:27 agc Exp $ +.\" +.\" Copyright (c) 1980, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)intro.1 8.1 (Berkeley) 6/4/93 +.\" +.bp +.sh 1 Overview +.pp +In making available the generalized terminal descriptions in \*(tc, +much information was made available to the programmer, +but little work was taken out of one's hands. +The purpose of this package is to allow the C programmer +to do the most common type of terminal dependent functions, +those of movement optimization and optimal screen updating, +without doing any of the dirty work, +and with nearly as much ease as is necessary to simply print +or read things. +.sh 2 "Terminology" +.pp +In this document, the following terminology is used: +.de Ip +.sp +.in 5n +.ti 0n +.b "\\$1" : +.. +.Ip window +An internal representation +containing an image of what a section of the terminal screen may look like +at some point in time. +This subsection can either encompass the entire terminal screen, +or any smaller portion down to a single character within that screen. +.Ip terminal +Sometimes called +.b terminal +.b screen . +The package's idea of what the terminal's screen currently looks like, +.i i.e. , +what the user sees now. +This is a special +.i screen : +.Ip screen +This is a subset of windows which are as large as the terminal screen, +.i i.e. , +they start at the upper left hand corner +and encompass the lower right hand corner. +One of these, +.Vn stdscr , +is automatically provided for the programmer. +.rm Ip +.sh 2 "Compiling Applications" +.pp +In order to use the library, +it is necessary to have certain types and variables defined. +Therefore, the programmer must have a line: +.(l +.b "#include " +.)l +at the top of the program source. +Compilations should have the following form: +.(l +.ie t \fBcc\fR [ \fIflags\fR ] file ... \fB\-lcurses \-ltermcap\fR +.el \fIcc\fR [ flags ] file ... \fI\-lcurses \-ltermcap\fR +.)l +.sh 2 "Screen Updating" +.pp +In order to update the screen optimally, +it is necessary for the routines to know what the screen currently looks like +and what the programmer wants it to look like next. +For this purpose, +a data type +(structure) +named +.Vn WINDOW +is defined +which describes a window image to the routines, +including its starting position on the screen +(the \*y of the upper left hand corner) +and its size. +One of these +(called +.Vn curscr +for +.i "current screen" ) +is a screen image of what the terminal currently looks like. +Another screen +(called +.Vn stdscr , +for +.i "standard screen" ) +is provided +by default +to make changes on. +.pp +A window is a purely internal representation. +It is used to build and store +a potential image of a portion of the terminal. +It doesn't bear any necessary relation +to what is really on the terminal screen. +It is more like an array of characters on which to make changes. +.pp +When one has a window which describes +what some part the terminal should look like, +the routine +.Fn refresh +(or +.Fn wrefresh +if the window is not +.Vn stdscr ) +is called. +.Fn refresh +makes the terminal, +in the area covered by the window, +look like that window. +Note, therefore, that changing something on a window +.i does +.bi not +.i "change the terminal" . +Actual updates to the terminal screen +are made only by calling +.Fn refresh +or +.Fn wrefresh . +This allows the programmer to maintain several different ideas +of what a portion of the terminal screen should look like. +Also, changes can be made to windows in any order, +without regard to motion efficiency. +Then, at will, +the programmer can effectively say +.q "make it look like this" , +and the package will execute the changes in an optimal way. +.sh 2 "Naming Conventions" +.pp +As hinted above, +the routines can use several windows, +but two are always available: +.Vn curscr , +which is the image of what the terminal looks like at present, +and +.Vn stdscr , +which is the image of what the programmer wants the terminal to look like next. +The user should not access +.Vn curscr +directly. +Changes should be made to +the appropriate screen, +and then the routine +.Fn refresh +(or +.Fn wrefresh ) +should be called. +.pp +Many functions are set up to deal with +.Vn stdscr +as a default screen. +For example, to add a character to +.Vn stdscr , +one calls +.Fn addch +with the desired character. +If a different window is to be used, +the routine +.Fn waddch +(for +.b w indow-specific +.Fn addch ) +is provided\**. +.(f +\** +Actually, +.Fn addch +is really a +.q #define +macro with arguments, +as are most of the "functions" which act upon +.Vn stdscr . +.)f +This convention of prepending function names with a +.Bq w +when they are to be applied to specific windows +is consistent. +The only routines which do +.i not +do this are those +to which a window must always be specified. +.pp +In order to move the current \*y from one point to another, +the routines +.Fn move +and +.Fn wmove +are provided. +However, +it is often desirable to first move and then perform some I/O operation. +In order to avoid clumsiness, +most I/O routines can be preceded by the prefix +.Bq mv +and the desired \*y can then be added to the arguments to the function. +For example, +the calls +.(l +move(y\*,x); +addch(ch); +.)l +can be replaced by +.(l +mvaddch(y\*,x\*,ch); +.)l +and +.(l +wmove(win\*,y\*,x); +waddch(win\*,ch); +.)l +can be replaced by +.(l +mvwaddch(win\*,y\*,x\*,ch); +.)l +Note that the window description pointer +.Vn win ) ( +comes before the added \*y. +If a window pointer is needed, it is always the first parameter passed. diff --git a/lib/libcurses/PSD.doc/intro.2 b/lib/libcurses/PSD.doc/intro.2 new file mode 100644 index 000000000..be3d46800 --- /dev/null +++ b/lib/libcurses/PSD.doc/intro.2 @@ -0,0 +1,82 @@ +.\" $NetBSD: intro.2,v 1.8 2003/08/07 16:44:28 agc Exp $ +.\" +.\" Copyright (c) 1980, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)intro.2 8.1 (Berkeley) 6/4/93 +.\" +.sh 1 Variables +.pp +Many variables which are used to describe the terminal environment +are available to the programmer. +They are: +.(b +.TS +expand; +lw(6m) lw(8n) lw(50n). +type name description +_ +WINDOW * curscr T{ +.fi +current version of the screen (terminal screen). +T} +WINDOW * stdscr T{ +standard screen. +Most updates are usually done here. +T} +char * Def\*_term T{ +default terminal type if type cannot be determined +T} +bool My\*_term T{ +use the terminal specification in \fIDef\*_term\fR as terminal, +irrelevant of real terminal type +T} +char * ttytype T{ +full name of the current terminal. +T} +int LINES T{ +number of lines on the terminal +T} +int COLS T{ +number of columns on the terminal +T} +int COLORS T{ +number of colors on the terminal +T} +int COLOR_PAIRS T{ +number of color pairs on the terminal +T} +int ERR T{ +error flag returned by routines on a fail. +T} +int OK T{ +flag returned by routines upon success. +T} +.TE +.fi +.)b +.lp diff --git a/lib/libcurses/PSD.doc/intro.3 b/lib/libcurses/PSD.doc/intro.3 new file mode 100644 index 000000000..2d67b822b --- /dev/null +++ b/lib/libcurses/PSD.doc/intro.3 @@ -0,0 +1,228 @@ +.\" $NetBSD: intro.3,v 1.9 2003/11/02 11:16:03 wiz Exp $ +.\" +.\" Copyright (c) 1980, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)intro.3 8.1 (Berkeley) 6/4/93 +.\" +.sh 1 Usage +.pp +This is a description of how to actually use the screen package. +For simplicity, we assume all updating, reading, etc. +is applied to +.Vn stdscr , +although a different window can of course be specified. +.sh 2 "Initialization" +.pp +In order to use the screen package, +the routines must know about terminal characteristics, +and the space for +.Vn curscr +and +.Vn stdscr +must be allocated. +These functions are performed by +.Fn initscr . +Since it must allocate space for the windows, +it can overflow core when attempting to do so. +On this rather rare occasion, +.Fn initscr +returns ERR. +.Fn initscr +must +.bi always +be called before any of the routines which affect windows are used. +If it is not, +the program will core dump as soon as either +.Vn curscr +or +.Vn stdscr +are referenced. +However, it is usually best to wait to call it +until after you are sure you will need it, +like after checking for startup errors. +Terminal status changing routines +like +.Fn nl +and +.Fn cbreak +should be called after +.Fn initscr . +.pp +After the initial window allocation done by +.Fn initscr , +specific window characteristics can be set. +Scrolling can be enabled by calling +.Fn scrollok . +If you want the cursor to be left after the last change, use +.Fn leaveok . +If this isn't done, +.Fn refresh +will move the cursor to the window's current \*y after updating it. +Additional windows can be created by using the functions +.Fn newwin +and +.Fn subwin . +.Fn delwin +allows you to delete an existing window. +The variables +.Vn LINES +and +.Vn COLS +control the size of the terminal. +They are initially implicitly set by +.Fn initscr , +but can be altered explicitly by the user followed by a call to +.Fn initscr . +Note that any call to +.Fn initscr , +will always delete any existing +.Vn stdscr +and/or +.Vn curscr +before creating new ones so this change is best done before the initial call to +.Fn initscr . +.pp +.sh 2 "Output" +.pp +The basic functions +used to change what will go on a window are +.Fn addch +and +.Fn move . +.Fn addch +adds a character at the current \*y, +returning ERR if it would cause the window to illegally scroll, +.i i.e. , +printing a character in the lower right-hand corner +of a terminal which automatically scrolls +if scrolling is not allowed. +.Fn move +changes the current \*y to whatever you want them to be. +It returns ERR if you try to move off the window. +As mentioned above, you can combine the two into +.Fn mvaddch +to do both things in one call. +.pp +The other output functions +(such as +.Fn addstr +and +.Fn printw ) +all call +.Fn addch +to add characters to the window. +.pp +After a change has been made to the window, +you must call +.Fn refresh . +when you want the portion of the terminal covered by the window +to reflect the change. +In order to optimize finding changes, +.Fn refresh +assumes that any part of the window not changed +since the last +.Fn refresh +of that window has not been changed on the terminal, +.i i.e. , +that you have not refreshed a portion of the terminal +with an overlapping window. +If this is not the case, +the routines +.Fn touchwin , +.Fn touchline , +and +.Fn touchoverlap +are provided to make it look like a desired part of window has been changed, +thus forcing +.Fn refresh +to check that whole subsection of the terminal for changes. +.pp +If you call +.Fn wrefresh +with +.Vn curscr , +it will make the screen look like the image of +.Vn curscr . +This is useful for implementing a command +which would redraw the screen in case it got messed up. +.sh 2 Input +.pp +Input is essentially a mirror image of output. +The complementary function to +.Fn addch +is +.Fn getch +which, +if echo is set, +will call +.Fn addch +to echo the character. +Since the screen package needs to know what is on the terminal at all times, +if characters are to be echoed, +the tty must be in raw or cbreak mode. +If it is not, +.Fn getch +sets it to be cbreak, +and then reads in the character. +.sh 2 "Termination" +.pp +In order to perform certain optimizations, +and, +on some terminals, +to work at all, +some things must be done +before the screen routines start up. +These functions are performed in +.Fn getttmode +and +.Fn setterm , +which are called by +.Fn initscr . +In order to clean up after the routines, +the routine +.Fn endwin +is provided. +It restores tty modes to what they were +when +.Fn initscr +was first called. +The terminal state module uses the variable +.Vn curses_termios +to save the original terminal state which is then restored upon a call to +.Fn endwin . +Thus, +anytime after the call to initscr, +.Fn endwin +should be called before exiting. +Note however, that +.Fn endwin +should always be called +.b before +the final calls to +.Fn delwin , +which free the storage of the windows. diff --git a/lib/libcurses/PSD.doc/intro.4 b/lib/libcurses/PSD.doc/intro.4 new file mode 100644 index 000000000..af62690ae --- /dev/null +++ b/lib/libcurses/PSD.doc/intro.4 @@ -0,0 +1,67 @@ +.\" $NetBSD: intro.4,v 1.5 2003/08/07 16:44:28 agc Exp $ +.\" +.\" Copyright (c) 1980, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)intro.4 8.1 (Berkeley) 6/4/93 +.\" +.sh 1 "Cursor Movement Optimizations" +.pp +One of the most difficult things to do properly is motion optimization. +After using +.Fn gettmode +and +.Fn setterm +to get the terminal descriptions, +the function +.Fn mvcur +deals with this task. +It usage is simple: +simply tell it where you are now and where you want to go. +For example +.(l +mvcur(0\*,0\*,LINES/2\*,COLS/2); +.)l +.lp +would move the cursor from the home position (0\*,0) +to the middle of the screen. +If you wish to force absolute addressing, +you can use the function +.Fn tgoto +from the +.b termlib (7) +routines, +or you can tell +.Fn mvcur +that you are impossibly far away, +For example, +to absolutely address the lower left hand corner of the screen +from anywhere +just claim that you are in the upper right hand corner: +.(l +mvcur(0\*,COLS\-1\*,LINES\-1\*,0); +.)l diff --git a/lib/libcurses/PSD.doc/intro.5 b/lib/libcurses/PSD.doc/intro.5 new file mode 100644 index 000000000..50bd75adb --- /dev/null +++ b/lib/libcurses/PSD.doc/intro.5 @@ -0,0 +1,90 @@ +.\" $NetBSD: intro.5,v 1.8 2003/11/02 11:16:03 wiz Exp $ +.\" +.\" Copyright (c) 1980, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)intro.5 8.1 (Berkeley) 6/4/93 +.\" +.sh 1 "Character Output and Scrolling" +.pp +The character output policy deals with the following problems. +First, where is the location of the cursor after a character is printed, and +secondly, when does the screen scroll if scrolling is enabled. +.pp +In the normal case the characters are output as expected, with the cursor +occupying the position of the next character to be output. +However, when the +cursor is on the last column of the line, the cursor will remain on that +position after the last character on the line is output and will only assume +the position on the next line when the next character (the first on the next +line) is output. +.pp +Likewise, if scrolling is enabled, a scroll will be invoked only when the +first character on he first line past the bottom line of the window is +output. +If scrolling is not enabled the chracters will to be output to the +bottom right corner of the window which is the cursor location. +.pp +This policy allows consistent behavior of the cursor at the boundary +conditions. +Furthermore, it prevents a scroll from happening before it is +actually needed (the old package used to scroll when the bottom right position +was output a character). +As a precedent, it models the +.i xterm +character output conventions. +.sh 1 "Terminal State Handling" +.pp +The variable +.Vn curses_termios +contains the terminal state of the terminal. +Certain historical routines return information: +.Fn baudrate , +.Fn erasechar , +.Fn killchar , +and +.Fn ospeed . +These routines are obsolete and exist only for backward compatibility. +If you wish to use the information in the +.Vn curses_termios +structure, you should use the +\fItsetattr\fP(3) +routines. +.sh 1 "Subwindows" +.pp +Subwindows are windows which do not have an independent text structure, +.i i.e. , +they are windows whose text is a subset of the text of a larger window: the +.i parent +window. +One consequence of this is that changes to either the parent or the +child window are destructive to the other, +.i i.e. , +a change to the subwindow is also a change to the parent window and a change +to the parent window in the region defined by the subwindow is implicitly a +change to the subwindow as well. +Apart from this detail, subwindows function like any other window. diff --git a/lib/libcurses/PSD.doc/intro.6 b/lib/libcurses/PSD.doc/intro.6 new file mode 100644 index 000000000..7a16ebacd --- /dev/null +++ b/lib/libcurses/PSD.doc/intro.6 @@ -0,0 +1,44 @@ +.\" $NetBSD: intro.6,v 1.6 2003/08/07 16:44:28 agc Exp $ +.\" +.\" Copyright (c) 1980, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)intro.6 8.1 (Berkeley) 6/4/93 +.\" +.sh 1 "The Functions" +.pp +In the following definitions, +.q \*m +means that if +.Vn _CURSES_USE_MACROS +is defined, the +.q function +is really a +.q #define +macro with arguments. +.ta 11m 17m 25m 33m 41m 49m 57m 65m 73m +.so fns.doc diff --git a/lib/libcurses/PSD.doc/life.c b/lib/libcurses/PSD.doc/life.c new file mode 100644 index 000000000..72a15945e --- /dev/null +++ b/lib/libcurses/PSD.doc/life.c @@ -0,0 +1,161 @@ +.\" $NetBSD: life.c,v 1.6 2003/08/07 16:44:28 agc Exp $ +.\" +.\" Copyright (c) 1980, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)life.c 8.1 (Berkeley) 6/8/93 +.\" +# include +# include + +/* + * Run a life game. This is a demonstration program for + * the Screen Updating section of the -lcurses cursor package. + */ + +typedef struct lst_st { /* linked list element */ + int y, x; /* (y, x) position of piece */ + struct lst_st *next, *last; /* doubly linked */ +} LIST; + +LIST *Head; /* head of linked list */ + +int die(); + +main(ac, av) +int ac; +char *av[]; +{ + evalargs(ac, av); /* evaluate arguments */ + + initscr(); /* initialize screen package */ + signal(SIGINT, die); /* set to restore tty stats */ + cbreak(); /* set for char-by-char */ + noecho(); /* input */ + nonl(); /* for optimization */ + + getstart(); /* get starting position */ + for (;;) { + prboard(); /* print out current board */ + update(); /* update board position */ + } +} + +/* + * This is the routine which is called when rubout is hit. + * It resets the tty stats to their original values. This + * is the normal way of leaving the program. + */ +die() +{ + signal(SIGINT, SIG_IGN); /* ignore rubouts */ + mvcur(0, COLS - 1, LINES - 1, 0); /* go to bottom of screen */ + endwin(); /* set terminal to good state */ + exit(0); +} + +/* + * Get the starting position from the user. They keys u, i, o, j, l, + * m, ,, and . are used for moving their relative directions from the + * k key. Thus, u move diagonally up to the left, , moves directly down, + * etc. x places a piece at the current position, " " takes it away. + * The input can also be from a file. The list is built after the + * board setup is ready. + */ +getstart() +{ + reg char c; + reg int x, y; + auto char buf[100]; + + box(stdscr, '|', '_'); /* box in the screen */ + move(1, 1); /* move to upper left corner */ + + for (;;) { + refresh(); /* print current position */ + if ((c = getch()) == 'q') + break; + switch (c) { + case 'u': + case 'i': + case 'o': + case 'j': + case 'l': + case 'm': + case ',': + case '.': + adjustyx(c); + break; + case 'f': + mvaddstr(0, 0, "File name: "); + getstr(buf); + readfile(buf); + break; + case 'x': + addch('X'); + break; + case ' ': + addch(' '); + break; + } + } + + if (Head != NULL) /* start new list */ + dellist(Head); + Head = malloc(sizeof (LIST)); + + /* + * loop through the screen looking for 'x's, and add a list + * element for each one + */ + for (y = 1; y < LINES - 1; y++) + for (x = 1; x < COLS - 1; x++) { + move(y, x); + if (inch() == 'x') + addlist(y, x); + } +} + +/* + * Print out the current board position from the linked list + */ +prboard() { + + reg LIST *hp; + + erase(); /* clear out last position */ + box(stdscr, '|', '_'); /* box in the screen */ + + /* + * go through the list adding each piece to the newly + * blank board + */ + for (hp = Head; hp; hp = hp->next) + mvaddch(hp->y, hp->x, 'X'); + + refresh(); +} diff --git a/lib/libcurses/PSD.doc/macros b/lib/libcurses/PSD.doc/macros new file mode 100644 index 000000000..a4773b4cf --- /dev/null +++ b/lib/libcurses/PSD.doc/macros @@ -0,0 +1,143 @@ +.\" $NetBSD: macros,v 1.8 2004/04/27 02:15:04 uwe Exp $ +.\" +.\" Copyright (c) 1980, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)macros 8.1 (Berkeley) 8/14/93 +.\" +.\" this is the uncommented version. The commented one is in "macros.coms" +.ie t .ds _ \d\(mi\u +.el .ds _ _ +.ds , ,\ \" attention: trailing space +.ds y (y\*,x) co-ordinates +.ds db database +.ie n .ds f \fI +.el .ds f \fB +.ds tc \*ftermcap\fP(5) +.ds Es This returns ERR if it would cause the screen to scroll illegally. +.ds Nm This has no associated \*(lq\fBmv\fP\*(rq command. +.ie t .ds m \fB\s-2\(dg\s+2\fP +.el .ds m [*] +.\" .hy WINDOW +.\".he ''\*(Ln'' +.\".fo ''\- % \-'' +.oh '\*(Ln''PS1:19-%' +.eh 'PS1:19-%''\*(Ln' +.de Un +.b +\s-2\\$2UNIX\\$1\s+2 +.ft +.. +.de Ds +.sp +.lp +.ev 1 +.nf +.ft I +.in 0 +.di +.Df +.. +.de De +.di +.Df +.ne \n(dn+2 +.ev +.ip +.. +.de Dg +.di +.Df +.ne \n(dn+2 +.ev +.. +.de Fd +.br +\&\\$4 +.fi +.b +\&\\$1(\\$2) +.ft +\&\\$3 +.br +.nf +.. +.de Vn +\&\\$3\c +.i "\\$1" \\$2 +.. +.de Bq +.ie t \&\*(lq\fB\\$1\fP\*(rq +.el \&\*(lq\fI\\$1\fP\*(rq +.. +.de $0 +.(x +.in \\n(Xs +\\*($n \\$1 +.)x +.. +.de $1 +.nr Xs 0 +.. +.de $2 +.nr Xs 3 +.. +.de $3 +.nr Xs 6 +.. +.de Fn +.if \\n(.$==0 .tm error +.nr ll 0 +.nr dg 0 +.ft R +.if '\\$\\n(.$'.' .nr ll 1 +.if '\\$\\n(.$',' .nr ll 1 +.if '\\$\\n(.$')' .nr ll 1 +.if '\\$\\n(.$').' .nr ll 1 +.if '\\$\\n(.$';' .nr ll 1 +.if '\\$\\n(.$':' .nr ll 1 +.if '\\$\\n(.$'\'s' .nr ll 1 +.if '\\$\\n(.$'\(dg' .nr ll 1 +.\" .if '\\$\\n(.$'' .nr ll 1 +.nr al \\n(.$-\\n(ll +.ds ot \f(CB\\$1\fP( +.if \\n(al>1 .as ot \fI\\$2\fP +.if \\n(al>2 .as ot ", \fI\\$3\fP +.if \\n(al>3 .as ot ", \fI\\$4\fP +.if \\n(al>4 .as ot ", \fI\\$5\fP +.if \\n(al>5 .as ot ", \fI\\$6\fP +.if \\n(al>6 .as ot ", \fI\\$7\fP +.if \\n(al>7 .as ot ", \fI\\$8\fP +.if \\n(al>8 .as ot ", \fI\\$9\fP +.as ot ) +.if \\n(.$>1 \{\ +. if \\n(ll==0 .as ot ; +. if '\\$\\n(.$'\(dg' .as ot ; +.\} +.if \\n(ll==1 .as ot \\$\\n(.$ +\\*(ot +.. diff --git a/lib/libcurses/PSD.doc/twinkle1.c b/lib/libcurses/PSD.doc/twinkle1.c new file mode 100644 index 000000000..c37d2a02b --- /dev/null +++ b/lib/libcurses/PSD.doc/twinkle1.c @@ -0,0 +1,161 @@ +/* $NetBSD: twinkle1.c,v 1.6 2005/05/23 04:04:49 christos Exp $ */ + +/* + * + * Copyright (c) 1980, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)twinkle1.c 8.1 (Berkeley) 6/8/93 + */ +#include +#include + +/* + * the idea for this program was a product of the imagination of + * Kurt Schoens. Not responsible for minds lost or stolen. + */ + +#define NCOLS 80 +#define NLINES 24 +#define MAXPATTERNS 4 + +typedef struct { + int y, x; +} LOCS; + +static LOCS Layout[NCOLS * NLINES]; /* current board layout */ + +static int Pattern, /* current pattern number */ + Numstars; /* number of stars in pattern */ + +static void puton(char); +static void makeboard(void); +static int ison(int, int); +static void die(int); + +int +main(void) +{ + srand(getpid()); /* initialize random sequence */ + + initscr(); + signal(SIGINT, die); + noecho(); + nonl(); + leaveok(stdscr, TRUE); + scrollok(stdscr, FALSE); + + for (;;) { + makeboard(); /* make the board setup */ + puton('*'); /* put on '*'s */ + puton(' '); /* cover up with ' 's */ + } +} + +/* + * On program exit, move the cursor to the lower left corner by + * direct addressing, since current location is not guaranteed. + * We lie and say we used to be at the upper right corner to guarantee + * absolute addressing. + */ +static void +die(int n) +{ + signal(SIGINT, SIG_IGN); + mvcur(0, COLS - 1, LINES - 1, 0); + endwin(); + exit(n); +} + + +/* + * Make the current board setup. It picks a random pattern and + * calls ison() to determine if the character is on that pattern + * or not. + */ +static void +makeboard(void) +{ + int y, x; + LOCS *lp; + + Pattern = rand() % MAXPATTERNS; + lp = Layout; + for (y = 0; y < NLINES; y++) + for (x = 0; x < NCOLS; x++) + if (ison(y, x)) { + lp->y = y; + lp->x = x; + lp++; + } + Numstars = lp - Layout; +} + +/* + * Return TRUE if (y, x) is on the current pattern. + */ +static int +ison(int y, int x) +{ + switch (Pattern) { + case 0: /* alternating lines */ + return !(y & 01); + case 1: /* box */ + if (x >= LINES && y >= NCOLS) + return FALSE; + if (y < 3 || y >= NLINES - 3) + return TRUE; + return (x < 3 || x >= NCOLS - 3); + case 2: /* holy pattern! */ + return ((x + y) & 01); + case 3: /* bar across center */ + return (y >= 9 && y <= 15); + } + /* NOTREACHED */ +} + +static void +puton(char ch) +{ + LOCS *lp; + int r; + LOCS *end; + LOCS temp; + + end = &Layout[Numstars]; + for (lp = Layout; lp < end; lp++) { + r = rand() % Numstars; + temp = *lp; + *lp = Layout[r]; + Layout[r] = temp; + } + + for (lp = Layout; lp < end; lp++) { + mvaddch(lp->y, lp->x, ch); + refresh(); + } +} diff --git a/lib/libcurses/PSD.doc/twinkle2.c b/lib/libcurses/PSD.doc/twinkle2.c new file mode 100644 index 000000000..6fdc7695d --- /dev/null +++ b/lib/libcurses/PSD.doc/twinkle2.c @@ -0,0 +1,207 @@ +/* $NetBSD: twinkle2.c,v 1.6 2005/05/23 04:04:49 christos Exp $ */ + +/* + * + * Copyright (c) 1980, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)twinkle2.c 8.1 (Berkeley) 6/8/93 + */ + +#include +#include +#include +#include + +#define NCOLS 80 +#define NLINES 24 +#define MAXPATTERNS 4 + +typedef struct { + int y, x; +} LOCS; + +static LOCS Layout[NCOLS * NLINES]; /* current board layout */ + +static int Pattern, /* current pattern number */ + Numstars; /* number of stars in pattern */ + +static void puton(char); +static void die(int); +static void makeboard(void); +static int ison(int, int); + +static int AM; +static char *VS; +static char *TI; +static char *CL; + +int +main(void) +{ + char *sp; + char buf[1024]; + char *ptr = buf; + + srand(getpid()); /* initialize random sequence */ + + if (isatty(0)) { + initscr(); + gettmode(); + if ((sp = getenv("TERM")) != NULL) + setterm(sp); + signal(SIGINT, die); + } + else { + printf("Need a terminal on fd=%d\n", 0); + exit(1); + } + + tgetent(buf, sp); + + AM = tgetflag("am"); + TI = tgetstr("ti", &ptr); + if (TI == NULL) { + printf("terminal does not have the ti capability\n"); + exit(1); + } + VS = tgetstr("vs", &ptr); + if (VS == NULL) { + printf("terminal does not have the vs capability\n"); + exit(1); + } + CL = tgetstr("cl", &ptr); + if (CL == NULL) { + printf("terminal does not have the cl capability\n"); + exit(1); + } + puts(TI); + puts(VS); + + noecho(); + nonl(); + tputs(CL, NLINES, putchar); + for (;;) { + makeboard(); /* make the board setup */ + puton('*'); /* put on '*'s */ + puton(' '); /* cover up with ' 's */ + } +} + +/* + * On program exit, move the cursor to the lower left corner by + * direct addressing, since current location is not guaranteed. + * We lie and say we used to be at the upper right corner to guarantee + * absolute addressing. + */ +static void +die(int n) +{ + signal(SIGINT, SIG_IGN); + mvcur(0, COLS - 1, LINES - 1, 0); + endwin(); + exit(n); +} + +static void +puton(char ch) +{ + LOCS *lp; + int r; + LOCS *end; + LOCS temp; + static int lasty, lastx; + + end = &Layout[Numstars]; + for (lp = Layout; lp < end; lp++) { + r = rand() % Numstars; + temp = *lp; + *lp = Layout[r]; + Layout[r] = temp; + } + + for (lp = Layout; lp < end; lp++) + /* prevent scrolling */ + if (!AM || (lp->y < NLINES - 1 || lp->x < NCOLS - 1)) { + mvcur(lasty, lastx, lp->y, lp->x); + putchar(ch); + lasty = lp->y; + if ((lastx = lp->x + 1) >= NCOLS) + if (AM) { + lastx = 0; + lasty++; + } + else + lastx = NCOLS - 1; + } +} + +/* + * Make the current board setup. It picks a random pattern and + * calls ison() to determine if the character is on that pattern + * or not. + */ +static void +makeboard(void) +{ + int y, x; + LOCS *lp; + + Pattern = rand() % MAXPATTERNS; + lp = Layout; + for (y = 0; y < NLINES; y++) + for (x = 0; x < NCOLS; x++) + if (ison(y, x)) { + lp->y = y; + lp->x = x; + lp++; + } + Numstars = lp - Layout; +} + +/* + * Return TRUE if (y, x) is on the current pattern. + */ +static int +ison(int y, int x) +{ + switch (Pattern) { + case 0: /* alternating lines */ + return !(y & 01); + case 1: /* box */ + if (x >= LINES && y >= NCOLS) + return FALSE; + if (y < 3 || y >= NLINES - 3) + return TRUE; + return (x < 3 || x >= NCOLS - 3); + case 2: /* holy pattern! */ + return ((x + y) & 01); + case 3: /* bar across center */ + return (y >= 9 && y <= 15); + } + /* NOTREACHED */ +} diff --git a/lib/libcurses/PSD.doc/win_st.c b/lib/libcurses/PSD.doc/win_st.c new file mode 100644 index 000000000..2bca05415 --- /dev/null +++ b/lib/libcurses/PSD.doc/win_st.c @@ -0,0 +1,56 @@ +.\" $NetBSD: win_st.c,v 1.5 2003/08/07 16:44:29 agc Exp $ +.\" +.\" Copyright (c) 1980, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)win_st.c 8.1 (Berkeley) 6/8/93 +.\" +# define WINDOW struct _win_st + +struct _win_st { + short _cury, _curx; + short _maxy, _maxx; + short _begy, _begx; + short _flags; + short _ch_off; + bool _clear; + bool _leave; + bool _scroll; + char **_y; + short *_firstch; + short *_lastch; + struct _win_st *_nextp, *_orig; +}; + +# define _ENDLINE 001 +# define _FULLWIN 002 +# define _SCROLLWIN 004 +# define _FLUSH 010 +# define _FULLLINE 020 +# define _IDLINE 040 +# define _STANDOUT 0200 +# define _NOCHANGE -1 diff --git a/lib/libcurses/acs.c b/lib/libcurses/acs.c new file mode 100644 index 000000000..87e02db07 --- /dev/null +++ b/lib/libcurses/acs.c @@ -0,0 +1,309 @@ +/* $NetBSD: acs.c,v 1.19 2010/02/25 10:56:24 drochner Exp $ */ + +/* + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Julian Coleman. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: acs.c,v 1.19 2010/02/25 10:56:24 drochner Exp $"); +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +chtype _acs_char[NUM_ACS]; +#ifdef HAVE_WCHAR +#include +#include +#include +#include + +cchar_t _wacs_char[ NUM_ACS ]; +#endif /* HAVE_WCHAR */ + +/* + * __init_acs -- + * Fill in the ACS characters. The 'ac' termcap entry is a list of + * character pairs - ACS definition then terminal representation. + */ +void +__init_acs(SCREEN *screen) +{ + int count; + const char *aofac; /* Address of 'ac' */ + unsigned char acs, term; + + /* Default value '+' for all ACS characters */ + for (count=0; count < NUM_ACS; count++) + _acs_char[count]= '+'; + + /* Add the SUSv2 defaults (those that are not '+') */ + ACS_RARROW = '>'; + ACS_LARROW = '<'; + ACS_UARROW = '^'; + ACS_DARROW = 'v'; + ACS_BLOCK = '#'; +/* ACS_DIAMOND = '+'; */ + ACS_CKBOARD = ':'; + ACS_DEGREE = 39; /* ' */ + ACS_PLMINUS = '#'; + ACS_BOARD = '#'; + ACS_LANTERN = '#'; +/* ACS_LRCORNER = '+'; */ +/* ACS_URCORNER = '+'; */ +/* ACS_ULCORNER = '+'; */ +/* ACS_LLCORNER = '+'; */ +/* ACS_PLUS = '+'; */ + ACS_HLINE = '-'; + ACS_S1 = '-'; + ACS_S9 = '_'; +/* ACS_LTEE = '+'; */ +/* ACS_RTEE = '+'; */ +/* ACS_BTEE = '+'; */ +/* ACS_TTEE = '+'; */ + ACS_VLINE = '|'; + ACS_BULLET = 'o'; + /* Add the extensions defaults */ + ACS_S3 = '-'; + ACS_S7 = '-'; + ACS_LEQUAL = '<'; + ACS_GEQUAL = '>'; + ACS_PI = '*'; + ACS_NEQUAL = '!'; + ACS_STERLING = 'f'; + + if (t_acs_chars(screen->term) == NULL) + goto out; + + aofac = t_acs_chars(screen->term); + + while (*aofac != '\0') { + if ((acs = *aofac) == '\0') + return; + if ((term = *++aofac) == '\0') + return; + /* Only add characters 1 to 127 */ + if (acs < NUM_ACS) + _acs_char[acs] = term | __ALTCHARSET; + aofac++; +#ifdef DEBUG + __CTRACE(__CTRACE_INIT, "__init_acs: %c = %c\n", acs, term); +#endif + } + + if (t_ena_acs(screen->term) != NULL) + ti_puts(screen->term, t_ena_acs(screen->term), 0, + __cputchar_args, screen->outfd); + +out: + for (count=0; count < NUM_ACS; count++) + screen->acs_char[count]= _acs_char[count]; +} + +void +_cursesi_reset_acs(SCREEN *screen) +{ + int count; + + for (count=0; count < NUM_ACS; count++) + _acs_char[count]= screen->acs_char[count]; +} + +#ifdef HAVE_WCHAR +/* + * __init_wacs -- + * Fill in the ACS characters. The 'ac' termcap entry is a list of + * character pairs - ACS definition then terminal representation. + */ +void +__init_wacs(SCREEN *screen) +{ + int count; + const char *aofac; /* Address of 'ac' */ + unsigned char acs, term; + char *lstr; + + /* Default value '+' for all ACS characters */ + for (count=0; count < NUM_ACS; count++) { + _wacs_char[ count ].vals[ 0 ] = ( wchar_t )btowc( '+' ); + _wacs_char[ count ].attributes = 0; + _wacs_char[ count ].elements = 1; + } + + /* Add the SUSv2 defaults (those that are not '+') */ + if (!strcmp(setlocale(LC_CTYPE, NULL), "C")) + setlocale(LC_CTYPE, ""); + lstr = nl_langinfo(CODESET); + _DIAGASSERT(lstr); + if (strcasecmp(lstr, "UTF-8")) { +#ifdef DEBUG + __CTRACE(__CTRACE_INIT, "__init_wacs: setting defaults\n" ); +#endif /* DEBUG */ + WACS_RARROW->vals[0] = ( wchar_t )btowc( '>' ); + WACS_LARROW->vals[0] = ( wchar_t )btowc( '<' ); + WACS_UARROW->vals[0] = ( wchar_t )btowc( '^' ); + WACS_DARROW->vals[0] = ( wchar_t )btowc( 'v' ); + WACS_BLOCK->vals[0] = ( wchar_t )btowc( '#' ); + WACS_CKBOARD->vals[0] = ( wchar_t )btowc( ':' ); + WACS_DEGREE->vals[0] = ( wchar_t )btowc( 39 ); /* ' */ + WACS_PLMINUS->vals[0] = ( wchar_t )btowc( '#' ); + WACS_BOARD->vals[0] = ( wchar_t )btowc( '#' ); + WACS_LANTERN->vals[0] = ( wchar_t )btowc( '#' ); + WACS_HLINE->vals[0] = ( wchar_t )btowc( '-' ); + WACS_S1->vals[0] = ( wchar_t )btowc( '-' ); + WACS_S9->vals[0] = ( wchar_t )btowc( '_' ); + WACS_VLINE->vals[0] = ( wchar_t )btowc( '|' ); + WACS_BULLET->vals[0] = ( wchar_t )btowc( 'o' ); + WACS_S3->vals[0] = ( wchar_t )btowc( 'p' ); + WACS_S7->vals[0] = ( wchar_t )btowc( 'r' ); + WACS_LEQUAL->vals[0] = ( wchar_t )btowc( 'y' ); + WACS_GEQUAL->vals[0] = ( wchar_t )btowc( 'z' ); + WACS_PI->vals[0] = ( wchar_t )btowc( '{' ); + WACS_NEQUAL->vals[0] = ( wchar_t )btowc( '|' ); + WACS_STERLING->vals[0]= ( wchar_t )btowc( '}' ); + } else { + /* Unicode defaults */ +#ifdef DEBUG + __CTRACE(__CTRACE_INIT, + "__init_wacs: setting Unicode defaults\n" ); +#endif /* DEBUG */ + WACS_RARROW->vals[0] = 0x2192; + ACS_RARROW = '+' | __ACS_IS_WACS; + WACS_LARROW->vals[0] = 0x2190; + ACS_LARROW = ',' | __ACS_IS_WACS; + WACS_UARROW->vals[0] = 0x2191; + ACS_UARROW = '-' | __ACS_IS_WACS; + WACS_DARROW->vals[0] = 0x2193; + ACS_DARROW = '.' | __ACS_IS_WACS; + WACS_BLOCK->vals[0] = 0x25ae; + ACS_BLOCK = '0' | __ACS_IS_WACS; + WACS_DIAMOND->vals[0] = 0x25c6; + ACS_DIAMOND = '`' | __ACS_IS_WACS; + WACS_CKBOARD->vals[0] = 0x2592; + ACS_CKBOARD = 'a' | __ACS_IS_WACS; + WACS_DEGREE->vals[0] = 0x00b0; + ACS_DEGREE = 'f' | __ACS_IS_WACS; + WACS_PLMINUS->vals[0] = 0x00b1; + ACS_PLMINUS = 'g' | __ACS_IS_WACS; + WACS_BOARD->vals[0] = 0x2592; + ACS_BOARD = 'h' | __ACS_IS_WACS; + WACS_LANTERN->vals[0] = 0x2603; + ACS_LANTERN = 'i' | __ACS_IS_WACS; + WACS_LRCORNER->vals[0]= 0x2518; + ACS_LRCORNER = 'j' | __ACS_IS_WACS; + WACS_URCORNER->vals[0]= 0x2510; + ACS_URCORNER = 'k' | __ACS_IS_WACS; + WACS_ULCORNER->vals[0]= 0x250c; + ACS_ULCORNER = 'l' | __ACS_IS_WACS; + WACS_LLCORNER->vals[0]= 0x2514; + ACS_LLCORNER = 'm' | __ACS_IS_WACS; + WACS_PLUS->vals[0] = 0x253c; + ACS_PLUS = 'n' | __ACS_IS_WACS; + WACS_HLINE->vals[0] = 0x2500; + ACS_HLINE = 'q' | __ACS_IS_WACS; + WACS_S1->vals[0] = 0x23ba; + ACS_S1 = 'o' | __ACS_IS_WACS; + WACS_S9->vals[0] = 0x23bd; + ACS_S9 = 's' | __ACS_IS_WACS; + WACS_LTEE->vals[0] = 0x251c; + ACS_LTEE = 't' | __ACS_IS_WACS; + WACS_RTEE->vals[0] = 0x2524; + ACS_RTEE = 'u' | __ACS_IS_WACS; + WACS_BTEE->vals[0] = 0x2534; + ACS_BTEE = 'v' | __ACS_IS_WACS; + WACS_TTEE->vals[0] = 0x252c; + ACS_TTEE = 'w' | __ACS_IS_WACS; + WACS_VLINE->vals[0] = 0x2502; + ACS_VLINE = 'x' | __ACS_IS_WACS; + WACS_BULLET->vals[0] = 0x00b7; + ACS_BULLET = '~' | __ACS_IS_WACS; + WACS_S3->vals[0] = 0x23bb; + ACS_S3 = 'p' | __ACS_IS_WACS; + WACS_S7->vals[0] = 0x23bc; + ACS_S7 = 'r' | __ACS_IS_WACS; + WACS_LEQUAL->vals[0] = 0x2264; + ACS_LEQUAL = 'y' | __ACS_IS_WACS; + WACS_GEQUAL->vals[0] = 0x2265; + ACS_GEQUAL = 'z' | __ACS_IS_WACS; + WACS_PI->vals[0] = 0x03C0; + ACS_PI = '{' | __ACS_IS_WACS; + WACS_NEQUAL->vals[0] = 0x2260; + ACS_NEQUAL = '|' | __ACS_IS_WACS; + WACS_STERLING->vals[0]= 0x00A3; + ACS_STERLING = '}' | __ACS_IS_WACS; + } + + if (t_acs_chars(screen->term) == NULL) { +#ifdef DEBUG + __CTRACE(__CTRACE_INIT, + "__init_wacs: no alternative characters\n" ); +#endif /* DEBUG */ + goto out; + } + + aofac = t_acs_chars(screen->term); + + while (*aofac != '\0') { + if ((acs = *aofac) == '\0') + return; + if ((term = *++aofac) == '\0') + return; + /* Only add characters 1 to 127 */ + if (acs < NUM_ACS) { + _wacs_char[acs].vals[ 0 ] = term; + _wacs_char[acs].attributes |= WA_ALTCHARSET; + } + aofac++; +#ifdef DEBUG + __CTRACE(__CTRACE_INIT, "__init_wacs: %c = %c\n", acs, term); +#endif + } + + if (t_ena_acs(screen->term) != NULL) + ti_puts(screen->term, t_ena_acs(screen->term), 0, + __cputchar_args, screen->outfd); + +out: + for (count=0; count < NUM_ACS; count++) { + memcpy(&screen->wacs_char[count], &_wacs_char[count], + sizeof(cchar_t)); + screen->acs_char[count]= _acs_char[count]; + } +} + +void +_cursesi_reset_wacs(SCREEN *screen) +{ + int count; + + for (count=0; count < NUM_ACS; count++) + memcpy( &_wacs_char[count], &screen->wacs_char[count], + sizeof( cchar_t )); +} +#endif /* HAVE_WCHAR */ diff --git a/lib/libcurses/add_wch.c b/lib/libcurses/add_wch.c new file mode 100644 index 000000000..064808b39 --- /dev/null +++ b/lib/libcurses/add_wch.c @@ -0,0 +1,124 @@ +/* $NetBSD: add_wch.c,v 1.3 2009/07/22 16:57:14 roy Exp $ */ + +/* + * Copyright (c) 2005 The NetBSD Foundation Inc. + * All rights reserved. + * + * This code is derived from code donated to the NetBSD Foundation + * by Ruibiao Qiu . + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND + * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: add_wch.c,v 1.3 2009/07/22 16:57:14 roy Exp $"); +#endif /* not lint */ + +#include +#include "curses.h" +#include "curses_private.h" +#ifdef DEBUG +#include +#endif + +/* + * add_wch -- + * Add the wide character to the current position in stdscr. + * + */ +int +add_wch(const cchar_t *wch) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return wadd_wch(stdscr, wch); +#endif /* HAVE_WCHAR */ +} + + +/* + * mvadd_wch -- + * Add the wide character to stdscr at the given location. + */ +int +mvadd_wch(int y, int x, const cchar_t *wch) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return mvwadd_wch(stdscr, y, x, wch); +#endif /* HAVE_WCHAR */ +} + + +/* + * mvwadd_wch -- + * Add the character to the given window at the given location. + */ +int +mvwadd_wch(WINDOW *win, int y, int x, const cchar_t *wch) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + if (wmove(win, y, x) == ERR) + return ERR; + + return wadd_wch(win, wch); +#endif /* HAVE_WCHAR */ +} + + +/* + * wadd_wch -- + * Add the wide character to the current position in the + * given window. + * + */ +int +wadd_wch(WINDOW *win, const cchar_t *wch) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + int x = win->curx, y = win->cury; + __LINE *lnp = NULL; + +#ifdef DEBUG + int i; + + for (i = 0; i < win->maxy; i++) { + assert(win->alines[i]->sentinel == SENTINEL_VALUE); + } + __CTRACE(__CTRACE_INPUT, "wadd_wch: win(%p)", win); +#endif + lnp = win->alines[y]; + return _cursesi_addwchar(win, &lnp, &y, &x, wch); +#endif /* HAVE_WCHAR */ +} diff --git a/lib/libcurses/add_wchstr.c b/lib/libcurses/add_wchstr.c new file mode 100644 index 000000000..d112e03d9 --- /dev/null +++ b/lib/libcurses/add_wchstr.c @@ -0,0 +1,338 @@ +/* $NetBSD: add_wchstr.c,v 1.4 2010/02/23 19:48:26 drochner Exp $ */ + +/* + * Copyright (c) 2005 The NetBSD Foundation Inc. + * All rights reserved. + * + * This code is derived from code donated to the NetBSD Foundation + * by Ruibiao Qiu . + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND + * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: add_wchstr.c,v 1.4 2010/02/23 19:48:26 drochner Exp $"); +#endif /* not lint */ + +#include + +#include "curses.h" +#include "curses_private.h" + +/* + * add_wchstr -- + * Add a wide string to stdscr starting at (_cury, _curx). + */ +int +add_wchstr(const cchar_t *wchstr) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return wadd_wchnstr(stdscr, wchstr, -1); +#endif +} + + +/* + * wadd_wchstr -- + * Add a string to the given window starting at (_cury, _curx). + */ +int +wadd_wchstr(WINDOW *win, const cchar_t *wchstr) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return wadd_wchnstr(win, wchstr, -1); +#endif +} + + +/* + * add_wchnstr -- + * Add a string (at most n characters) to stdscr starting + * at (_cury, _curx). If n is negative, add the entire string. + */ +int +add_wchnstr(const cchar_t *wchstr, int n) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return wadd_wchnstr(stdscr, wchstr, n); +#endif +} + + +/* + * mvadd_wchstr -- + * Add a string to stdscr starting at (y, x) + */ +int +mvadd_wchstr(int y, int x, const cchar_t *wchstr) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return mvwadd_wchnstr(stdscr, y, x, wchstr, -1); +#endif +} + + +/* + * mvwadd_wchstr -- + * Add a string to the given window starting at (y, x) + */ +int +mvwadd_wchstr(WINDOW *win, int y, int x, const cchar_t *wchstr) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return mvwadd_wchnstr(win, y, x, wchstr, -1); +#endif +} + + +/* + * mvadd_wchnstr -- + * Add a string of at most n characters to stdscr + * starting at (y, x). + */ +int +mvadd_wchnstr(int y, int x, const cchar_t *wchstr, int n) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return mvwadd_wchnstr(stdscr, y, x, wchstr, n); +#endif +} + + +/* + * mvwadd_wchnstr -- + * Add a string of at most n characters to the given window + * starting at (y, x). + */ +int +mvwadd_wchnstr(WINDOW *win, int y, int x, const cchar_t *wchstr, int n) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + if (wmove(win, y, x) == ERR) + return ERR; + + return wadd_wchnstr(win, wchstr, n); +#endif +} + + +/* + * wadd_wchnstr -- + * Add a string (at most n wide characters) to the given window + * starting at (_cury, _curx). If n is -1, add the entire string. + */ +int +wadd_wchnstr(WINDOW *win, const cchar_t *wchstr, int n) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + const cchar_t *chp; + wchar_t wc; + int cw, x, y, sx, ex, newx, i, cnt; + __LDATA *lp, *tp; + nschar_t *np, *tnp; + __LINE *lnp; + +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "wadd_wchnstr: win = %p, wchstr = %p, n = %d\n", win, wchstr, n); +#endif + + if (!wchstr) + return OK; + + /* compute length of the cchar string */ + if (n < -1) + return ERR; + if (n >= 0) + for (chp = wchstr, cnt = 0; n && chp->vals[0]; + n--, chp++, ++cnt); + else + for (chp = wchstr, cnt = 0; chp->vals[0]; chp++, ++cnt); +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, "wadd_wchnstr: len=%d\n", cnt); +#endif /* DEBUG */ + chp = wchstr; + x = win->curx; + y = win->cury; + lp = &win->alines[y]->line[x]; + lnp = win->alines[y]; + + cw = WCOL(*lp); + if (cw >= 0) { + sx = x; + } else { + if (wcwidth(chp->vals[0])) { + /* clear the partial character before cursor */ + for (tp = lp + cw; tp < lp; tp++) { + tp->ch = (wchar_t) btowc((int) win->bch); + if (_cursesi_copy_nsp(win->bnsp, tp) == ERR) + return ERR; + tp->attr = win->battr; + SET_WCOL(*tp, 1); + np = tp->nsp; + } + } else { + /* move to the start of current char */ + lp += cw; + x += cw; + } + sx = x + cw; + } + lnp->flags |= __ISDIRTY; + newx = sx + win->ch_off; + if (newx < *lnp->firstchp) + *lnp->firstchp = newx; + + /* add characters in the string */ + ex = x; + while (cnt) { + x = ex; + wc = chp->vals[0]; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, "wadd_wchnstr: adding %x", wc); +#endif /* DEBUG */ + cw = wcwidth(wc); + if (cw < 0) + cw = 1; + if (cw) { + /* spacing character */ +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + " as a spacing char(width=%d)\n", cw); +#endif /* DEBUG */ + if (cw > win->maxx - ex) { + /* clear to EOL */ + while (ex < win->maxx) { + lp->ch = (wchar_t) + btowc((int) win->bch); + if (_cursesi_copy_nsp(win->bnsp, lp) + == ERR) + return ERR; + lp->attr = win->battr; + SET_WCOL(*lp, 1); + lp++, ex++; + } + ex = win->maxx - 1; + break; + } + /* this could combine with the insertion of + * non-spacing char */ + np = lp->nsp; + if (np) { + while (np) { + tnp = np->next; + free(np); + np = tnp; + } + lp->nsp = NULL; + } + lp->ch = chp->vals[0]; + lp->attr = chp->attributes & WA_ATTRIBUTES; + SET_WCOL(*lp, cw); + if (chp->elements > 1) { + for (i = 1; i < chp->elements; i++) { + np = (nschar_t *) + malloc(sizeof(nschar_t)); + if (!np) + return ERR; + np->ch = chp->vals[i]; + np->next = lp->nsp; + lp->nsp = np; + } + } + lp++, ex++; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "wadd_wchnstr: ex = %d, x = %d, cw = %d\n", + ex, x, cw); +#endif /* DEBUG */ + while (ex - x <= cw - 1) { + np = lp->nsp; + if (np) { + while (np) { + tnp = np->next; + free(np); + np = tnp; + } + lp->nsp = NULL; + } + lp->ch = chp->vals[0]; + lp->attr = chp->attributes & WA_ATTRIBUTES; + SET_WCOL(*lp, x - ex); + lp++, ex++; + } + } else { + /* non-spacing character */ +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "wadd_wchnstr: as non-spacing char"); +#endif /* DEBUG */ + for (i = 0; i < chp->elements; i++) { + np = (nschar_t *)malloc(sizeof(nschar_t)); + if (!np) + return ERR; + np->ch = chp->vals[i]; + np->next = lp->nsp; + lp->nsp = np; + } + } + cnt--, chp++; + } +#ifdef DEBUG + for (i = sx; i < ex; i++) { + __CTRACE(__CTRACE_INPUT, "wadd_wchnstr: (%d,%d)=(%x,%x,%p)\n", + win->cury, i, win->alines[win->cury]->line[i].ch, + win->alines[win->cury]->line[i].attr, + win->alines[win->cury]->line[i].nsp); + } +#endif /* DEBUG */ + lnp->flags |= __ISDIRTY; + newx = ex + win->ch_off; + if (newx > *lnp->lastchp) + *lnp->lastchp = newx; + __touchline(win, y, sx, ex); + + return OK; +#endif /* HAVE_WCHAR */ +} diff --git a/lib/libcurses/addbytes.c b/lib/libcurses/addbytes.c new file mode 100644 index 000000000..5945c2c38 --- /dev/null +++ b/lib/libcurses/addbytes.c @@ -0,0 +1,586 @@ +/* $NetBSD: addbytes.c,v 1.38 2010/12/16 17:42:28 wiz Exp $ */ + +/* + * Copyright (c) 1987, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)addbytes.c 8.4 (Berkeley) 5/4/94"; +#else +__RCSID("$NetBSD: addbytes.c,v 1.38 2010/12/16 17:42:28 wiz Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#include "curses.h" +#include "curses_private.h" +#ifdef DEBUG +#include +#endif + +#define SYNCH_IN {y = win->cury; x = win->curx;} +#define SYNCH_OUT {win->cury = y; win->curx = x;} +#define PSYNCH_IN {*y = win->cury; *x = win->curx;} +#define PSYNCH_OUT {win->cury = *y; win->curx = *x;} + +#ifndef _CURSES_USE_MACROS + +/* + * addbytes -- + * Add the character to the current position in stdscr. + */ +int +addbytes(const char *bytes, int count) +{ + return __waddbytes(stdscr, bytes, count, 0); +} + +/* + * waddbytes -- + * Add the character to the current position in the given window. + */ +int +waddbytes(WINDOW *win, const char *bytes, int count) +{ + return __waddbytes(win, bytes, count, 0); +} + +/* + * mvaddbytes -- + * Add the characters to stdscr at the location given. + */ +int +mvaddbytes(int y, int x, const char *bytes, int count) +{ + return mvwaddbytes(stdscr, y, x, bytes, count); +} + +/* + * mvwaddbytes -- + * Add the characters to the given window at the location given. + */ +int +mvwaddbytes(WINDOW *win, int y, int x, const char *bytes, int count) +{ + if (wmove(win, y, x) == ERR) + return ERR; + + return __waddbytes(win, bytes, count, 0); +} + +#endif + +/* + * waddbytes -- + * Add the character to the current position in the given window. + */ +int +__waddbytes(WINDOW *win, const char *bytes, int count, attr_t attr) +{ + int x, y, err; + __LINE *lp; +#ifdef HAVE_WCHAR + int n; + cchar_t cc; + wchar_t wc; + mbstate_t st; +#else + int c; +#endif +#ifdef DEBUG + int i; + + for (i = 0; i < win->maxy; i++) { + assert(win->alines[i]->sentinel == SENTINEL_VALUE); + } + + __CTRACE(__CTRACE_INPUT, "ADDBYTES: add %d bytes\n", count); +#endif + + err = OK; + SYNCH_IN; + lp = win->alines[y]; + +#ifdef HAVE_WCHAR + (void)memset(&st, 0, sizeof(st)); +#endif + while (count > 0) { +#ifndef HAVE_WCHAR + c = *bytes++; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, "ADDBYTES('%c', %x) at (%d, %d)\n", + c, attr, y, x); +#endif + err = _cursesi_addbyte(win, &lp, &y, &x, c, attr); + count--; +#else + /* + * For wide-character support only, try and convert the + * given string into a wide character - we do this because + * this is how ncurses behaves (not that I think this is + * actually the correct thing to do but if we don't do it + * a lot of things that rely on this behaviour will break + * and we will be blamed). If the conversion succeeds + * then we eat the n characters used to make the wide char + * from the string. + */ + n = (int)mbrtowc(&wc, bytes, (size_t)count, &st); + if (n < 0) { + /* not a valid conversion just eat a char */ + wc = *bytes; + n = 1; + (void)memset(&st, 0, sizeof(&st)); + } else if (wc == 0) { + break; + } +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "ADDBYTES WIDE(0x%x [%s], %x) at (%d, %d), ate %d bytes\n", + (unsigned) wc, unctrl((unsigned) wc), attr, y, x, n); +#endif + cc.vals[0] = wc; + cc.elements = 1; + cc.attributes = attr; + err = _cursesi_addwchar(win, &lp, &y, &x, &cc); + bytes += n; + count -= n; +#endif + } + + SYNCH_OUT; + +#ifdef DEBUG + for (i = 0; i < win->maxy; i++) { + assert(win->alines[i]->sentinel == SENTINEL_VALUE); + } +#endif + + return (err); +} + +/* + * _cursesi_addbyte - + * Internal function to add a byte and update the row and column + * positions as appropriate. This function is only used in the narrow + * character version of curses. + */ +int +_cursesi_addbyte(WINDOW *win, __LINE **lp, int *y, int *x, int c, + attr_t attr) +{ + static char blanks[] = " "; + int newx; + attr_t attributes; + + switch (c) { + case '\t': + PSYNCH_OUT; + if (waddbytes(win, blanks, 8 - (*x % 8)) == ERR) + return (ERR); + PSYNCH_IN; + break; + + default: +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, "ADDBYTES(%p, %d, %d)\n", + win, *y, *x); +#endif + + if ((*lp)->flags & __ISPASTEOL) { + new_line: + *x = 0; + (*lp)->flags &= ~__ISPASTEOL; + if (*y == win->scr_b) { +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "ADDBYTES - on bottom " + "of scrolling region\n"); +#endif + if (!(win->flags & __SCROLLOK)) + return ERR; + PSYNCH_OUT; + scroll(win); + PSYNCH_IN; + } else { + (*y)++; + } + *lp = win->alines[*y]; + if (c == '\n') + break; + } + + attributes = (win->wattr | attr) & + (__ATTRIBUTES & ~__COLOR); + if (attr & __COLOR) + attributes |= attr & __COLOR; + else if (win->wattr & __COLOR) + attributes |= win->wattr & __COLOR; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "ADDBYTES: 1: y = %d, x = %d, firstch = %d, " + "lastch = %d\n", + *y, *x, *win->alines[*y]->firstchp, + *win->alines[*y]->lastchp); +#endif + /* + * Always update the change pointers. Otherwise, + * we could end up not displaying 'blank' characters + * when overlapping windows are displayed. + */ + newx = *x + win->ch_off; + (*lp)->flags |= __ISDIRTY; + /* + * firstchp/lastchp are shared between + * parent window and sub-window. + */ + if (newx < *(*lp)->firstchp) + *(*lp)->firstchp = newx; + if (newx > *(*lp)->lastchp) + *(*lp)->lastchp = newx; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "ADDBYTES: change gives f/l: %d/%d [%d/%d]\n", + *(*lp)->firstchp, *(*lp)->lastchp, + *(*lp)->firstchp - win->ch_off, + *(*lp)->lastchp - win->ch_off); +#endif + if (win->bch != ' ' && c == ' ') + (*lp)->line[*x].ch = win->bch; + else + (*lp)->line[*x].ch = c; + + if (attributes & __COLOR) + (*lp)->line[*x].attr = + attributes | (win->battr & ~__COLOR); + else + (*lp)->line[*x].attr = attributes | win->battr; + + if (*x == win->maxx - 1) + (*lp)->flags |= __ISPASTEOL; + else + (*x)++; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "ADDBYTES: 2: y = %d, x = %d, firstch = %d, " + "lastch = %d\n", + *y, *x, *win->alines[*y]->firstchp, + *win->alines[*y]->lastchp); +#endif + break; + case '\n': + PSYNCH_OUT; + wclrtoeol(win); + PSYNCH_IN; + goto new_line; + case '\r': + *x = 0; + break; + case '\b': + if (--(*x) < 0) + *x = 0; + break; + } + + return (OK); +} + +/* + * _cursesi_addwchar - + * Internal function to add a wide character and update the row + * and column positions. + */ +int +_cursesi_addwchar(WINDOW *win, __LINE **lnp, int *y, int *x, + const cchar_t *wch) +{ +#ifndef HAVE_WCHAR + return (ERR); +#else + int sx = 0, ex = 0, cw = 0, i = 0, newx = 0; + __LDATA *lp = &win->alines[*y]->line[*x], *tp = NULL; + nschar_t *np = NULL; + cchar_t cc; + attr_t attributes; + + /* special characters handling */ + switch (wch->vals[0]) { + case L'\b': + if (--*x < 0) + *x = 0; + win->curx = *x; + return OK; + case L'\r': + *x = 0; + return OK; + case L'\n': + wclrtoeol(win); + PSYNCH_IN; + *x = 0; + (*lnp)->flags &= ~__ISPASTEOL; + if (*y == win->scr_b) { + if (!(win->flags & __SCROLLOK)) + return ERR; + PSYNCH_OUT; + scroll(win); + PSYNCH_IN; + } else { + (*y)++; + } + PSYNCH_OUT; + return OK; + case L'\t': + cc.vals[0] = L' '; + cc.elements = 1; + cc.attributes = win->wattr; + for (i = 0; i < 8 - (*x % 8); i++) { + if (wadd_wch(win, &cc) == ERR) + return ERR; + } + return OK; + } + + /* check for non-spacing character */ + if (!wcwidth(wch->vals[0])) { +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "_cursesi_addwchar: char '%c' is non-spacing\n", + wch->vals[0]); +#endif /* DEBUG */ + cw = WCOL(*lp); + if (cw < 0) { + lp += cw; + *x += cw; + } + for (i = 0; i < wch->elements; i++) { + if (!(np = (nschar_t *) malloc(sizeof(nschar_t)))) + return ERR;; + np->ch = wch->vals[i]; + np->next = lp->nsp; + lp->nsp = np; + } + (*lnp)->flags |= __ISDIRTY; + newx = *x + win->ch_off; + if (newx < *(*lnp)->firstchp) + *(*lnp)->firstchp = newx; + if (newx > *(*lnp)->lastchp) + *(*lnp)->lastchp = newx; + __touchline(win, *y, *x, *x); + return OK; + } + /* check for new line first */ + if ((*lnp)->flags & __ISPASTEOL) { + *x = 0; + (*lnp)->flags &= ~__ISPASTEOL; + if (*y == win->scr_b) { + if (!(win->flags & __SCROLLOK)) + return ERR; + PSYNCH_OUT; + scroll(win); + PSYNCH_IN; + } else { + (*y)++; + } + (*lnp) = win->alines[*y]; + lp = &win->alines[*y]->line[*x]; + } + /* clear out the current character */ + cw = WCOL(*lp); + if (cw >= 0) { + sx = *x; + } else { + for (sx = *x - 1; sx >= max(*x + cw, 0); sx--) { +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "_cursesi_addwchar: clear current char (%d,%d)\n", + *y, sx); +#endif /* DEBUG */ + tp = &win->alines[*y]->line[sx]; + tp->ch = (wchar_t) btowc((int) win->bch); + if (_cursesi_copy_nsp(win->bnsp, tp) == ERR) + return ERR; + + tp->attr = win->battr; + SET_WCOL(*tp, 1); + } + sx = *x + cw; + (*lnp)->flags |= __ISDIRTY; + newx = sx + win->ch_off; + if (newx < *(*lnp)->firstchp) + *(*lnp)->firstchp = newx; + } + + /* check for enough space before the end of line */ + cw = wcwidth(wch->vals[0]); + if (cw < 0) + cw = 1; + if (cw > win->maxx - *x) { +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "_cursesi_addwchar: clear EOL (%d,%d)\n", + *y, *x); +#endif /* DEBUG */ + (*lnp)->flags |= __ISDIRTY; + newx = *x + win->ch_off; + if (newx < *(*lnp)->firstchp) + *(*lnp)->firstchp = newx; + for (tp = lp; *x < win->maxx; tp++, (*x)++) { + tp->ch = (wchar_t) btowc((int) win->bch); + if (_cursesi_copy_nsp(win->bnsp, tp) == ERR) + return ERR; + tp->attr = win->battr; + SET_WCOL(*tp, 1); + } + newx = win->maxx - 1 + win->ch_off; + if (newx > *(*lnp)->lastchp) + *(*lnp)->lastchp = newx; + __touchline(win, *y, sx, (int) win->maxx - 1); + sx = *x = 0; + if (*y == win->scr_b) { + if (!(win->flags & __SCROLLOK)) + return ERR; + PSYNCH_OUT; + scroll(win); + PSYNCH_IN; + } else { + (*y)++; + } + lp = &win->alines[*y]->line[0]; + (*lnp) = win->alines[*y]; + } + win->cury = *y; + + /* add spacing character */ +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "_cursesi_addwchar: add character (%d,%d) 0x%x\n", + *y, *x, wch->vals[0]); +#endif /* DEBUG */ + (*lnp)->flags |= __ISDIRTY; + newx = *x + win->ch_off; + if (newx < *(*lnp)->firstchp) + *(*lnp)->firstchp = newx; + if (lp->nsp) { + __cursesi_free_nsp(lp->nsp); + lp->nsp = NULL; + } + + lp->ch = wch->vals[0]; + + attributes = (win->wattr | wch->attributes) + & (WA_ATTRIBUTES & ~__COLOR); + if (wch->attributes & __COLOR) + attributes |= wch->attributes & __COLOR; + else if (win->wattr & __COLOR) + attributes |= win->wattr & __COLOR; + if (attributes & __COLOR) + lp->attr = attributes | (win->battr & ~__COLOR); + else + lp->attr = attributes | win->battr; + + SET_WCOL(*lp, cw); + +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "_cursesi_addwchar: add spacing char 0x%x, attr 0x%x\n", + lp->ch, lp->attr); +#endif /* DEBUG */ + + if (wch->elements > 1) { + for (i = 1; i < wch->elements; i++) { + np = (nschar_t *)malloc(sizeof(nschar_t)); + if (!np) + return ERR;; + np->ch = wch->vals[i]; + np->next = lp->nsp; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "_cursesi_addwchar: add non-spacing char 0x%x\n", np->ch); +#endif /* DEBUG */ + lp->nsp = np; + } + } +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, "_cursesi_addwchar: non-spacing list header: %p\n", + lp->nsp); + __CTRACE(__CTRACE_INPUT, "_cursesi_addwchar: add rest columns (%d:%d)\n", + sx + 1, sx + cw - 1); +#endif /* DEBUG */ + for (tp = lp + 1, *x = sx + 1; *x - sx <= cw - 1; tp++, (*x)++) { + if (tp->nsp) { + __cursesi_free_nsp(tp->nsp); + tp->nsp = NULL; + } + tp->ch = wch->vals[0]; + tp->attr = lp->attr & WA_ATTRIBUTES; + /* Mark as "continuation" cell */ + tp->attr |= __WCWIDTH; + } + if (*x == win->maxx) { + (*lnp)->flags |= __ISPASTEOL; + newx = win->maxx - 1 + win->ch_off; + if (newx > *(*lnp)->lastchp) + *(*lnp)->lastchp = newx; + __touchline(win, *y, sx, (int) win->maxx - 1); + win->curx = sx; + } else { + win->curx = *x; + + /* clear the remining of the current characer */ + if (*x && *x < win->maxx) { + ex = sx + cw; + tp = &win->alines[*y]->line[ex]; + while (ex < win->maxx && WCOL(*tp) < 0) { +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "_cursesi_addwchar: clear " + "remaining of current char (%d,%d)nn", + *y, ex); +#endif /* DEBUG */ + tp->ch = (wchar_t) btowc((int) win->bch); + if (_cursesi_copy_nsp(win->bnsp, tp) == ERR) + return ERR; + tp->attr = win->battr; + SET_WCOL(*tp, 1); + tp++, ex++; + } + newx = ex - 1 + win->ch_off; + if (newx > *(*lnp)->lastchp) + *(*lnp)->lastchp = newx; + __touchline(win, *y, sx, ex - 1); + } + } + +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, "add_wch: %d : 0x%x\n", lp->ch, lp->attr); +#endif /* DEBUG */ + return OK; +#endif +} diff --git a/lib/libcurses/addch.c b/lib/libcurses/addch.c new file mode 100644 index 000000000..ca24d5e23 --- /dev/null +++ b/lib/libcurses/addch.c @@ -0,0 +1,128 @@ +/* $NetBSD: addch.c,v 1.16 2010/02/23 19:48:26 drochner Exp $ */ + +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)addch.c 8.2 (Berkeley) 5/4/94"; +#else +__RCSID("$NetBSD: addch.c,v 1.16 2010/02/23 19:48:26 drochner Exp $"); +#endif +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +#ifndef _CURSES_USE_MACROS + +/* + * addch -- + * Add the character to the current position in stdscr. + * + */ +int +addch(chtype ch) +{ + return waddch(stdscr, ch); +} + +/* + * mvaddch -- + * Add the character to stdscr at the given location. + */ +int +mvaddch(int y, int x, chtype ch) +{ + return mvwaddch(stdscr, y, x, ch); +} + +/* + * mvwaddch -- + * Add the character to the given window at the given location. + */ +int +mvwaddch(WINDOW *win, int y, int x, chtype ch) +{ + if (wmove(win, y, x) == ERR) + return ERR; + + return waddch(win, ch); +} + +#endif + +/* + * waddch -- + * Add the character to the current position in the given window. + * + */ +int +waddch(WINDOW *win, chtype ch) +{ +#ifdef HAVE_WCHAR + cchar_t cc; +#else + __LDATA buf; +#endif + +#ifdef HAVE_WCHAR + __cursesi_chtype_to_cchar(ch, &cc); +#else + buf.ch = (wchar_t) ch & __CHARTEXT; + buf.attr = (attr_t) ch & __ATTRIBUTES; +#endif + +#ifdef DEBUG +#ifdef HAVE_WCHAR + __CTRACE(__CTRACE_INPUT, + "addch: %d : 0x%x (adding char as wide char)\n", + cc.vals[0], cc.attributes); +#else + __CTRACE(__CTRACE_INPUT, "addch: %d : 0x%x\n", buf.ch, buf.attr); +#endif +#endif + +#ifdef HAVE_WCHAR + return (wadd_wch(win, &cc)); +#else + return (__waddch(win, &buf)); +#endif +} + +int +__waddch(WINDOW *win, __LDATA *dp) +{ + char buf[2]; + + buf[0] = dp->ch; + buf[1] = '\0'; + return (__waddbytes(win, buf, 1, dp->attr)); +} diff --git a/lib/libcurses/addchnstr.c b/lib/libcurses/addchnstr.c new file mode 100644 index 000000000..a293cbcfa --- /dev/null +++ b/lib/libcurses/addchnstr.c @@ -0,0 +1,175 @@ +/* $NetBSD: addchnstr.c,v 1.4 2008/04/28 20:23:01 martin Exp $ */ + +/* + * Copyright (c) 2003 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Douwe Kiela (virtus@wanadoo.nl). + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: addchnstr.c,v 1.4 2008/04/28 20:23:01 martin Exp $"); +#endif /* not lint */ + +#include + +#include "curses.h" +#include "curses_private.h" + +#ifndef _CURSES_USE_MACROS + +/* + * addchstr -- + * Add a string to stdscr starting at (_cury, _curx). + */ +int +addchstr(const chtype *chstr) +{ + return waddchnstr(stdscr, chstr, -1); +} + +/* + * waddchstr -- + * Add a string to the given window starting at (_cury, _curx). + */ +int +waddchstr(WINDOW *win, const chtype *chstr) +{ + return waddchnstr(win, chstr, -1); +} + +/* + * addchnstr -- + * Add a string (at most n characters) to stdscr starting + * at (_cury, _curx). If n is negative, add the entire string. + */ +int +addchnstr(const chtype *chstr, int n) +{ + return waddchnstr(stdscr, chstr, n); +} + +/* + * mvaddchstr -- + * Add a string to stdscr starting at (y, x) + */ +int +mvaddchstr(int y, int x, const chtype *chstr) +{ + return mvwaddchnstr(stdscr, y, x, chstr, -1); +} + +/* + * mvwaddchstr -- + * Add a string to the given window starting at (y, x) + */ +int +mvwaddchstr(WINDOW *win, int y, int x, const chtype *chstr) +{ + return mvwaddchnstr(win, y, x, chstr, -1); +} + +/* + * mvaddchnstr -- + * Add a string of at most n characters to stdscr + * starting at (y, x). + */ +int +mvaddchnstr(int y, int x, const chtype *chstr, int n) +{ + return mvwaddchnstr(stdscr, y, x, chstr, n); +} + +/* + * mvwaddchnstr -- + * Add a string of at most n characters to the given window + * starting at (y, x). + */ +int +mvwaddchnstr(WINDOW *win, int y, int x, const chtype *chstr, int n) +{ + if (wmove(win, y, x) == ERR) + return ERR; + + return waddchnstr(win, chstr, n); +} + +#endif + +/* + * waddchnstr -- + * Add a string (at most n characters) to the given window + * starting at (_cury, _curx). If n is negative, add the + * entire string. + */ +int +waddchnstr(WINDOW *win, const chtype *chstr, int n) +{ + size_t len; + const chtype *chp; + attr_t attr; + char *ocp, *cp, *start; + int i, ret; + +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, "waddchnstr: win = %p, chstr = %p, n = %d\n", + win, chstr, n); +#endif + + if (n >= 0) + for (chp = chstr, len = 0; n-- && *chp++; ++len); + else + for (chp = chstr, len = 0; *chp++; ++len); + + if ((ocp = malloc(len + 1)) == NULL) + return ERR; + chp = chstr; + cp = ocp; + start = ocp; + i = 0; + attr = (*chp) & __ATTRIBUTES; + while (len) { + *cp = (*chp) & __CHARTEXT; + cp++; + chp++; + i++; + len--; + if (((*chp) & __ATTRIBUTES) != attr) { + *cp = '\0'; + if (__waddbytes(win, start, i, attr) == ERR) { + free(ocp); + return ERR; + } + attr = (*chp) & __ATTRIBUTES; + start = cp; + i = 0; + } + } + *cp = '\0'; + ret = __waddbytes(win, start, i, attr); + free(ocp); + return ret; +} diff --git a/lib/libcurses/addnstr.c b/lib/libcurses/addnstr.c new file mode 100644 index 000000000..33c4c832d --- /dev/null +++ b/lib/libcurses/addnstr.c @@ -0,0 +1,155 @@ +/* $NetBSD: addnstr.c,v 1.12 2007/05/28 15:01:54 blymn Exp $ */ + +/* + * Copyright (c) 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)addnstr.c 8.2 (Berkeley) 5/4/94"; +#else +__RCSID("$NetBSD: addnstr.c,v 1.12 2007/05/28 15:01:54 blymn Exp $"); +#endif +#endif /* not lint */ + +#include + +#include "curses.h" +#include "curses_private.h" + +#ifndef _CURSES_USE_MACROS + +/* + * addstr -- + * Add a string to stdscr starting at (_cury, _curx). + */ +int +addstr(const char *s) +{ + return waddnstr(stdscr, s, -1); +} + +/* + * waddstr -- + * Add a string to the given window starting at (_cury, _curx). + */ +int +waddstr(WINDOW *win, const char *s) +{ + return waddnstr(win, s, -1); +} + +/* + * addnstr -- + * Add a string (at most n characters) to stdscr starting + * at (_cury, _curx). If n is negative, add the entire string. + */ +int +addnstr(const char *str, int n) +{ + return waddnstr(stdscr, str, n); +} + +/* + * mvaddstr -- + * Add a string to stdscr starting at (y, x) + */ +int +mvaddstr(int y, int x, const char *str) +{ + return mvwaddnstr(stdscr, y, x, str, -1); +} + +/* + * mvwaddstr -- + * Add a string to the given window starting at (y, x) + */ +int +mvwaddstr(WINDOW *win, int y, int x, const char *str) +{ + return mvwaddnstr(win, y, x, str, -1); +} + +/* + * mvaddnstr -- + * Add a string of at most n characters to stdscr + * starting at (y, x). + */ +int +mvaddnstr(int y, int x, const char *str, int count) +{ + return mvwaddnstr(stdscr, y, x, str, count); +} + +/* + * mvwaddnstr -- + * Add a string of at most n characters to the given window + * starting at (y, x). + */ +int +mvwaddnstr(WINDOW *win, int y, int x, const char *str, int count) +{ + if (wmove(win, y, x) == ERR) + return ERR; + + return waddnstr(win, str, count); +} + +#endif + +/* + * waddnstr -- + * Add a string (at most n characters) to the given window + * starting at (_cury, _curx). If n is negative, add the + * entire string. + */ +int +waddnstr(WINDOW *win, const char *s, int n) +{ + size_t len; + const char *p; + +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, "ADDNSTR: win %p, length %d\n", + win, n); +#endif + /* + * behavior changed from traditional BSD curses, for better XCURSES + * conformance. + * + * BSD curses: if (n > 0) then "at most n", else "len = strlen(s)" + * ncurses: if (n >= 0) then "at most n", else "len = strlen(s)" + * XCURSES: if (n != -1) then "at most n", else "len = strlen(s)" + */ + if (n >= 0) + for (p = s, len = 0; n-- && *p++; ++len); + else + len = strlen(s); + return (waddbytes(win, s, (int) len)); +} diff --git a/lib/libcurses/addwstr.c b/lib/libcurses/addwstr.c new file mode 100644 index 000000000..0a433a1c7 --- /dev/null +++ b/lib/libcurses/addwstr.c @@ -0,0 +1,201 @@ +/* $NetBSD: addwstr.c,v 1.2 2007/05/28 15:01:54 blymn Exp $ */ + +/* + * Copyright (c) 2005 The NetBSD Foundation Inc. + * All rights reserved. + * + * This code is derived from code donated to the NetBSD Foundation + * by Ruibiao Qiu . + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND + * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: addwstr.c,v 1.2 2007/05/28 15:01:54 blymn Exp $"); +#endif /* not lint */ + +#include + +#include "curses.h" +#include "curses_private.h" + +/* + * addwstr -- + * Add a string to stdscr starting at (_cury, _curx). + */ +int +addwstr(const wchar_t *s) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return waddnwstr(stdscr, s, -1); +#endif /* HAVE_WCHAR */ +} + +/* + * waddwstr -- + * Add a string to the given window starting at (_cury, _curx). + */ +int +waddwstr(WINDOW *win, const wchar_t *s) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return waddnwstr(win, s, -1); +#endif /* HAVE_WCHAR */ +} + +/* + * addnwstr -- + * Add a string (at most n characters) to stdscr starting + * at (_cury, _curx). If n is negative, add the entire string. + */ +int +addnwstr(const wchar_t *str, int n) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return waddnwstr(stdscr, str, n); +#endif /* HAVE_WCHAR */ +} + +/* + * mvaddwstr -- + * Add a string to stdscr starting at (y, x) + */ +int +mvaddwstr(int y, int x, const wchar_t *str) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return mvwaddnwstr(stdscr, y, x, str, -1); +#endif /* HAVE_WCHAR */ +} + +/* + * mvwaddwstr -- + * Add a string to the given window starting at (y, x) + */ +int +mvwaddwstr(WINDOW *win, int y, int x, const wchar_t *str) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return mvwaddnwstr(win, y, x, str, -1); +#endif /* HAVE_WCHAR */ +} + +/* + * mvaddnwstr -- + * Add a string of at most n characters to stdscr + * starting at (y, x). + */ +int +mvaddnwstr(int y, int x, const wchar_t *str, int count) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return mvwaddnwstr(stdscr, y, x, str, count); +#endif /* HAVE_WCHAR */ +} + +/* + * mvwaddnwstr -- + * Add a string of at most n characters to the given window + * starting at (y, x). + */ +int +mvwaddnwstr(WINDOW *win, int y, int x, const wchar_t *str, int count) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + if (wmove(win, y, x) == ERR) + return ERR; + + return waddnwstr(win, str, count); +#endif /* HAVE_WCHAR */ +} + +/* + * waddnwstr -- + * Add a string (at most n characters) to the given window + * starting at (_cury, _curx). If n is negative, add the + * entire string. + */ +int +waddnwstr(WINDOW *win, const wchar_t *s, int n) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + size_t len; + const wchar_t *p; + cchar_t cc; + wchar_t wc[ 2 ]; + + /* + * BSD curses: if (n > 0) then "at most n", else "len = strlen(s)" + * ncurses: if (n >= 0) then "at most n", else "len = strlen(s)" + * XCURSES: if (n != -1) then "at most n", else "len = strlen(s)" + */ + /* compute the length and column width of string */ + if ( n < -1 ) + return ERR; + if (n >= 0) + for (p = s, len = 0; n-- && *p++; ++len ); + else + len = wcslen(s); +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, "waddnwstr: string len=%ld\n", (long) len); +#endif /* DEBUG */ + + p = s; + while ( len ) { + wc[ 0 ] = *p; + wc[ 1 ] = L'\0'; + if ( setcchar( &cc, wc, win->wattr, 0, NULL ) == ERR ) + return ERR; + if ( wadd_wch( win, &cc ) == ERR ) + return ERR; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, "waddnwstr: (%x,%x,%d) added\n", + cc.vals[ 0 ], cc.attributes, cc.elements ); +#endif /* DEBUG */ + p++, len--; + } + + return OK; +#endif /* HAVE_WCHAR */ +} diff --git a/lib/libcurses/attributes.c b/lib/libcurses/attributes.c new file mode 100644 index 000000000..b0bfe29f2 --- /dev/null +++ b/lib/libcurses/attributes.c @@ -0,0 +1,449 @@ +/* $NetBSD: attributes.c,v 1.21 2010/12/25 10:08:20 blymn Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Julian Coleman. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: attributes.c,v 1.21 2010/12/25 10:08:20 blymn Exp $"); +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +void __wcolor_set(WINDOW *, attr_t); + +#ifndef _CURSES_USE_MACROS +/* + * attr_get -- + * Get wide attributes and color pair from stdscr + */ +/* ARGSUSED */ +int +attr_get(attr_t *attr, short *pair, void *opt) +{ + return wattr_get(stdscr, attr, pair, opt); +} + +/* + * attr_on -- + * Test and set wide attributes on stdscr + */ +/* ARGSUSED */ +int +attr_on(attr_t attr, void *opt) +{ + return wattr_on(stdscr, attr, opt); +} + +/* + * attr_off -- + * Test and unset wide attributes on stdscr + */ +/* ARGSUSED */ +int +attr_off(attr_t attr, void *opt) +{ + return wattr_off(stdscr, attr, opt); +} + +/* + * attr_set -- + * Set wide attributes and color pair on stdscr + */ +/* ARGSUSED */ +int +attr_set(attr_t attr, short pair, void *opt) +{ + return wattr_set(stdscr, attr, pair, opt); +} + +/* + * color_set -- + * Set color pair on stdscr + */ +/* ARGSUSED */ +int +color_set(short pair, void *opt) +{ + return wcolor_set(stdscr, pair, opt); +} + +/* + * attron -- + * Test and set attributes on stdscr + */ +int +attron(int attr) +{ + return wattr_on(stdscr, (attr_t) attr, NULL); +} + +/* + * attroff -- + * Test and unset attributes on stdscr. + */ +int +attroff(int attr) +{ + return wattr_off(stdscr, (attr_t) attr, NULL); +} + +/* + * attrset -- + * Set specific attribute modes. + * Unset others. On stdscr. + */ +int +attrset(int attr) +{ + return wattrset(stdscr, attr); +} +#endif /* _CURSES_USE_MACROS */ + +/* + * wattr_get -- + * Get wide attributes and colour pair from window + * Note that attributes also includes colour. + */ +/* ARGSUSED */ +int +wattr_get(WINDOW *win, attr_t *attr, short *pair, void *opt) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_ATTR, "wattr_get: win %p\n", win); +#endif + if (attr != NULL) { + *attr = win->wattr; +#ifdef HAVE_WCHAR + *attr &= WA_ATTRIBUTES; +#endif + } + + if (pair != NULL) + *pair = PAIR_NUMBER(win->wattr); + return OK; +} + +/* + * wattr_on -- + * Test and set wide attributes on window + */ +/* ARGSUSED */ +int +wattr_on(WINDOW *win, attr_t attr, void *opt) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_ATTR, "wattr_on: win %p, attr %08x\n", win, attr); +#endif + /* If can enter modes, set the relevent attribute bits. */ + if (exit_attribute_mode != NULL) { + if (attr & __BLINK && enter_blink_mode != NULL) + win->wattr |= __BLINK; + if (attr & __BOLD && enter_bold_mode != NULL) + win->wattr |= __BOLD; + if (attr & __DIM && enter_dim_mode != NULL) + win->wattr |= __DIM; + if (attr & __BLANK && enter_secure_mode != NULL) + win->wattr |= __BLANK; + if (attr & __PROTECT && enter_protected_mode != NULL) + win->wattr |= __PROTECT; + if (attr & __REVERSE && enter_reverse_mode != NULL) + win->wattr |= __REVERSE; +#ifdef HAVE_WCHAR + if (attr & WA_LOW && enter_low_hl_mode != NULL) + win->wattr |= WA_LOW; + if (attr & WA_TOP && enter_top_hl_mode != NULL) + win->wattr |= WA_TOP; + if (attr & WA_LEFT && enter_left_hl_mode != NULL) + win->wattr |= WA_LEFT; + if (attr & WA_RIGHT && enter_right_hl_mode != NULL) + win->wattr |= WA_RIGHT; + if (attr & WA_HORIZONTAL && enter_horizontal_hl_mode != NULL) + win->wattr |= WA_HORIZONTAL; + if (attr & WA_VERTICAL && enter_vertical_hl_mode != NULL) + win->wattr |= WA_VERTICAL; +#endif /* HAVE_WCHAR */ + } + if (attr & __STANDOUT && enter_standout_mode != NULL && exit_standout_mode != NULL) + wstandout(win); + if (attr & __UNDERSCORE && enter_underline_mode != NULL && exit_underline_mode != NULL) + wunderscore(win); + if ((attr_t) attr & __COLOR) + __wcolor_set(win, (attr_t) attr); + return OK; +} + +/* + * wattr_off -- + * Test and unset wide attributes on window + * + * Note that the 'me' sequence unsets all attributes. We handle + * which attributes should really be set in refresh.c:makech(). + */ +/* ARGSUSED */ +int +wattr_off(WINDOW *win, attr_t attr, void *opt) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_ATTR, "wattr_off: win %p, attr %08x\n", win, attr); +#endif + /* If can do exit modes, unset the relevent attribute bits. */ + if (exit_attribute_mode != NULL) { + if (attr & __BLINK) + win->wattr &= ~__BLINK; + if (attr & __BOLD) + win->wattr &= ~__BOLD; + if (attr & __DIM) + win->wattr &= ~__DIM; + if (attr & __BLANK) + win->wattr &= ~__BLANK; + if (attr & __PROTECT) + win->wattr &= ~__PROTECT; + if (attr & __REVERSE) + win->wattr &= ~__REVERSE; +#ifdef HAVE_WCHAR + if (attr & WA_LOW) + win->wattr &= ~WA_LOW; + if (attr & WA_TOP) + win->wattr &= ~WA_TOP; + if (attr & WA_LEFT) + win->wattr &= ~WA_LEFT; + if (attr & WA_RIGHT) + win->wattr &= ~WA_RIGHT; + if (attr & WA_HORIZONTAL) + win->wattr &= ~WA_HORIZONTAL; + if (attr & WA_VERTICAL) + win->wattr &= ~WA_VERTICAL; +#endif /* HAVE_WCHAR */ + } + if (attr & __STANDOUT) + wstandend(win); + if (attr & __UNDERSCORE) + wunderend(win); + if ((attr_t) attr & __COLOR) { + if (max_colors != 0) + win->wattr &= ~__COLOR; + } + return OK; +} + +/* + * wattr_set -- + * Set wide attributes and color pair on window + */ +int +wattr_set(WINDOW *win, attr_t attr, short pair, void *opt) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_ATTR, "wattr_set: win %p, attr %08x, pair %d\n", + win, attr, pair); +#endif + wattr_off(win, __ATTRIBUTES, opt); + /* + * This overwrites any colour setting from the attributes + * and is compatible with ncurses. + */ + attr = (attr & ~__COLOR) | COLOR_PAIR(pair); + wattr_on(win, attr, opt); + return OK; +} + +/* + * wattron -- + * Test and set attributes. + */ +int +wattron(WINDOW *win, int attr) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_ATTR, "wattron: win %p, attr %08x\n", win, attr); +#endif + return wattr_on(win, (attr_t) attr, NULL); +} + +/* + * wattroff -- + * Test and unset attributes. + */ +int +wattroff(WINDOW *win, int attr) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_ATTR, "wattroff: win %p, attr %08x\n", win, attr); +#endif + return wattr_off(win, (attr_t) attr, NULL); +} + +/* + * wattrset -- + * Set specific attribute modes. + * Unset others. + */ +int +wattrset(WINDOW *win, int attr) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_ATTR, "wattrset: win %p, attr %08x\n", win, attr); +#endif + wattr_off(win, __ATTRIBUTES, NULL); + wattr_on(win, (attr_t) attr, NULL); + return OK; +} + +/* + * wcolor_set -- + * Set color pair on window + */ +/* ARGSUSED */ +int +wcolor_set(WINDOW *win, short pair, void *opt) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_COLOR, "wolor_set: win %p, pair %d\n", win, pair); +#endif + __wcolor_set(win, (attr_t) COLOR_PAIR(pair)); + return OK; +} + +/* + * getattrs -- + * Get window attributes. + */ +chtype +getattrs(WINDOW *win) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_ATTR, "getattrs: win %p\n", win); +#endif + return((chtype) win->wattr); +} + +/* + * termattrs -- + * Get terminal attributes + */ +chtype +termattrs(void) +{ + chtype ch = 0; + +#ifdef DEBUG + __CTRACE(__CTRACE_ATTR, "termattrs\n"); +#endif + if (exit_attribute_mode != NULL) { +#ifdef DEBUG + __CTRACE(__CTRACE_ATTR, "termattrs: have exit attribute mode\n"); +#endif + if (enter_blink_mode != NULL) + ch |= __BLINK; + if (enter_bold_mode != NULL) + ch |= __BOLD; + if (enter_dim_mode != NULL) + ch |= __DIM; + if (enter_secure_mode != NULL) + ch |= __BLANK; + if (enter_protected_mode != NULL) + ch |= __PROTECT; + if (enter_reverse_mode != NULL) + ch |= __REVERSE; + } + if (enter_standout_mode != NULL && exit_standout_mode != NULL) + ch |= __STANDOUT; + if (enter_underline_mode != NULL && exit_underline_mode != NULL) + ch |= __UNDERSCORE; + if (enter_alt_charset_mode != NULL && exit_alt_charset_mode != NULL) + ch |= __ALTCHARSET; + + return ch; +} + +/* + * term_attrs -- + * Get terminal wide attributes + */ +attr_t +term_attrs(void) +{ + attr_t attr = 0; + +#ifdef DEBUG + __CTRACE(__CTRACE_ATTR, "term_attrs\n"); +#endif + if (exit_attribute_mode != NULL) { + if (enter_blink_mode != NULL) + attr |= __BLINK; + if (enter_bold_mode != NULL) + attr |= __BOLD; + if (enter_dim_mode != NULL) + attr |= __DIM; + if (enter_secure_mode != NULL) + attr |= __BLANK; + if (enter_protected_mode != NULL) + attr |= __PROTECT; + if (enter_reverse_mode != NULL) + attr |= __REVERSE; +#ifdef HAVE_WCHAR + if (enter_low_hl_mode != NULL) + attr |= WA_LOW; + if (enter_top_hl_mode != NULL) + attr |= WA_TOP; + if (enter_left_hl_mode != NULL) + attr |= WA_LEFT; + if (enter_right_hl_mode != NULL) + attr |= WA_RIGHT; + if (enter_horizontal_hl_mode != NULL) + attr |= WA_HORIZONTAL; + if (enter_vertical_hl_mode != NULL) + attr |= WA_VERTICAL; +#endif /* HAVE_WCHAR */ + } + if (enter_standout_mode != NULL && exit_standout_mode != NULL) + attr |= __STANDOUT; + if (enter_underline_mode != NULL && exit_underline_mode != NULL) + attr |= __UNDERSCORE; + if (enter_alt_charset_mode != NULL && exit_alt_charset_mode != NULL) + attr |= __ALTCHARSET; + + return attr; +} + +/* + * __wcolor_set -- + * Set color attribute on window + */ +void +__wcolor_set(WINDOW *win, attr_t attr) +{ + /* If another color pair is set, turn that off first. */ + win->wattr &= ~__COLOR; + /* If can do color video, set the color pair bits. */ + if (max_colors != 0 && attr & __COLOR) + win->wattr |= attr & __COLOR; +} diff --git a/lib/libcurses/background.c b/lib/libcurses/background.c new file mode 100644 index 000000000..3e3469d21 --- /dev/null +++ b/lib/libcurses/background.c @@ -0,0 +1,285 @@ +/* $NetBSD: background.c,v 1.15 2009/07/22 16:57:14 roy Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Julian Coleman. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: background.c,v 1.15 2009/07/22 16:57:14 roy Exp $"); +#endif /* not lint */ + +#include +#include "curses.h" +#include "curses_private.h" + +/* + * bkgdset + * Set new background attributes on stdscr. + */ +void +bkgdset(chtype ch) +{ + wbkgdset(stdscr, ch); +} + +/* + * bkgd -- + * Set new background and new background attributes on stdscr. + */ +int +bkgd(chtype ch) +{ + return(wbkgd(stdscr, ch)); +} + +/* + * wbkgdset + * Set new background attributes. + */ +void +wbkgdset(WINDOW *win, chtype ch) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_ATTR, "wbkgdset: (%p), '%s', %08x\n", + win, unctrl(ch & +__CHARTEXT), ch & __ATTRIBUTES); +#endif + + /* Background character. */ + if (ch & __CHARTEXT) + win->bch = (wchar_t) ch & __CHARTEXT; + + /* Background attributes (check colour). */ + if (__using_color && !(ch & __COLOR)) + ch |= __default_color; + win->battr = (attr_t) ch & __ATTRIBUTES; +} + +/* + * wbkgd -- + * Set new background and new background attributes. + */ +int +wbkgd(WINDOW *win, chtype ch) +{ + int y, x; + +#ifdef DEBUG + __CTRACE(__CTRACE_ATTR, "wbkgd: (%p), '%s', %08x\n", + win, unctrl(ch & +__CHARTEXT), ch & __ATTRIBUTES); +#endif + + /* Background attributes (check colour). */ + if (__using_color && !(ch & __COLOR)) + ch |= __default_color; + + win->battr = (attr_t) ch & __ATTRIBUTES; + wbkgdset(win, ch); + for (y = 0; y < win->maxy; y++) + for (x = 0; x < win->maxx; x++) { + /* Copy character if space */ + if (ch & A_CHARTEXT && win->alines[y]->line[x].ch == ' ') + win->alines[y]->line[x].ch = ch & __CHARTEXT; + /* Merge attributes */ + if (win->alines[y]->line[x].attr & __ALTCHARSET) + win->alines[y]->line[x].attr = + (ch & __ATTRIBUTES) | __ALTCHARSET; + else + win->alines[y]->line[x].attr = + ch & __ATTRIBUTES; +#ifdef HAVE_WCHAR + SET_WCOL(win->alines[y]->line[x], 1); +#endif + } + __touchwin(win); + return(OK); +} + +/* + * getbkgd -- + * Get current background attributes. + */ +chtype +getbkgd(WINDOW *win) +{ + attr_t battr; + + /* Background attributes (check colour). */ + battr = win->battr & A_ATTRIBUTES; + if (__using_color && ((battr & __COLOR) == __default_color)) + battr &= ~__default_color; + + return ((chtype) ((win->bch & A_CHARTEXT) | battr)); +} + +int bkgrnd(const cchar_t *wch) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return wbkgrnd( stdscr, wch ); +#endif /* HAVE_WCHAR */ +} + +void bkgrndset(const cchar_t *wch) +{ +#ifdef HAVE_WCHAR + wbkgrndset( stdscr, wch ); +#endif /* HAVE_WCHAR */ +} + +int getbkgrnd(cchar_t *wch) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return wgetbkgrnd( stdscr, wch ); +#endif /* HAVE_WCHAR */ +} + +int wbkgrnd(WINDOW *win, const cchar_t *wch) +{ +#ifndef HAVE_WCHAR + return ERR; +#else +/* int y, x, i; */ + attr_t battr; +/* nschar_t *np, *tnp, *pnp; */ + +#ifdef DEBUG + __CTRACE(__CTRACE_ATTR, "wbkgrnd: (%p), '%s', %x\n", + win, (const char *) wunctrl(wch), wch->attributes); +#endif + + /* ignore multi-column characters */ + if ( !wch->elements || wcwidth( wch->vals[ 0 ]) > 1 ) + return ERR; + + /* Background attributes (check colour). */ + battr = wch->attributes & WA_ATTRIBUTES; + if (__using_color && !( battr & __COLOR)) + battr |= __default_color; + + win->battr = battr; + wbkgrndset(win, wch); + __touchwin(win); + return OK; +#endif /* HAVE_WCHAR */ +} + +void wbkgrndset(WINDOW *win, const cchar_t *wch) +{ +#ifdef HAVE_WCHAR + attr_t battr; + nschar_t *np, *tnp; + int i; + +#ifdef DEBUG + __CTRACE(__CTRACE_ATTR, "wbkgrndset: (%p), '%s', %x\n", + win, (const char *) wunctrl(wch), wch->attributes); +#endif + + /* ignore multi-column characters */ + if ( !wch->elements || wcwidth( wch->vals[ 0 ]) > 1 ) + return; + + /* Background character. */ + tnp = np = win->bnsp; + if ( wcwidth( wch->vals[ 0 ])) + win->bch = wch->vals[ 0 ]; + else { + if ( !np ) { + np = (nschar_t *)malloc(sizeof(nschar_t)); + if (!np) + return; + np->next = NULL; + win->bnsp = np; + } + np->ch = wch->vals[ 0 ]; + tnp = np; + np = np->next; + } + /* add non-spacing characters */ + if ( wch->elements > 1 ) { + for ( i = 1; i < wch->elements; i++ ) { + if ( !np ) { + np = (nschar_t *)malloc(sizeof(nschar_t)); + if (!np) + return; + np->next = NULL; + if ( tnp ) + tnp->next = np; + else + win->bnsp = np; + } + np->ch = wch->vals[ i ]; + tnp = np; + np = np->next; + } + } + /* clear the old non-spacing characters */ + while ( np ) { + tnp = np->next; + free( np ); + np = tnp; + } + + /* Background attributes (check colour). */ + battr = wch->attributes & WA_ATTRIBUTES; + if (__using_color && !( battr & __COLOR)) + battr |= __default_color; + win->battr = battr; + SET_BGWCOL((*win), 1); +#endif /* HAVE_WCHAR */ +} + +int wgetbkgrnd(WINDOW *win, cchar_t *wch) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + nschar_t *np; + + /* Background attributes (check colour). */ + wch->attributes = win->battr & WA_ATTRIBUTES; + if (__using_color && (( wch->attributes & __COLOR ) + == __default_color)) + wch->attributes &= ~__default_color; + wch->vals[ 0 ] = win->bch; + wch->elements = 1; + np = win->bnsp; + if (np) { + while ( np && wch->elements < CURSES_CCHAR_MAX ) { + wch->vals[ wch->elements++ ] = np->ch; + np = np->next; + } + } + + return OK; +#endif /* HAVE_WCHAR */ +} diff --git a/lib/libcurses/beep.c b/lib/libcurses/beep.c deleted file mode 100644 index aa6fced2e..000000000 --- a/lib/libcurses/beep.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include - -extern char *bl, *vb; - -/* Beep() sounds the terminal bell. */ -void beep() -{ - if (bl) - tputs(bl, 1, outc); - else if (vb) - tputs(vb, 1, outc); -} diff --git a/lib/libcurses/bell.c b/lib/libcurses/bell.c new file mode 100644 index 000000000..42571671d --- /dev/null +++ b/lib/libcurses/bell.c @@ -0,0 +1,80 @@ +/* $NetBSD: bell.c,v 1.8 2010/02/03 15:34:40 roy Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Julian Coleman. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: bell.c,v 1.8 2010/02/03 15:34:40 roy Exp $"); +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +/* + * beep + * Ring the terminal bell + */ +int +beep(void) +{ + if (bell != NULL) { +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "beep: bl\n"); +#endif + tputs(bell, 0, __cputchar); + } else if (flash_screen != NULL) { +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "beep: vb\n"); +#endif + tputs(flash_screen, 0, __cputchar); + } + return (1); +} + +/* + * flash + * Flash the terminal screen + */ +int +flash(void) +{ + if (flash_screen != NULL) { +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "flash: vb\n"); +#endif + tputs(flash_screen, 0, __cputchar); + } else if (bell != NULL) { +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "flash: bl\n"); +#endif + tputs(bell, 0, __cputchar); + } + return (1); +} diff --git a/lib/libcurses/border.c b/lib/libcurses/border.c new file mode 100644 index 000000000..041e9dc12 --- /dev/null +++ b/lib/libcurses/border.c @@ -0,0 +1,606 @@ +/* $NetBSD: border.c,v 1.14 2010/12/25 09:59:52 blymn Exp $ */ + +/* + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Julian Coleman. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: border.c,v 1.14 2010/12/25 09:59:52 blymn Exp $"); +#endif /* not lint */ + +#include +#include + +#include "curses.h" +#include "curses_private.h" + +#ifndef _CURSES_USE_MACROS + +/* + * border -- + * Draw a border around stdscr using the specified + * delimiting characters. + */ +int +border(chtype left, chtype right, chtype top, chtype bottom, chtype topleft, + chtype topright, chtype botleft, chtype botright) +{ + return wborder(stdscr, left, right, top, bottom, topleft, topright, + botleft, botright); +} + +#endif + +/* + * wborder -- + * Draw a border around the given window using the specified delimiting + * characters. + */ +int +wborder(WINDOW *win, chtype left, chtype right, chtype top, chtype bottom, + chtype topleft, chtype topright, chtype botleft, chtype botright) +{ +#ifndef HAVE_WCHAR + int endy, endx, i; + __LDATA *fp, *lp; + + if (!(left & __CHARTEXT)) + left |= ACS_VLINE; + if (!(right & __CHARTEXT)) + right |= ACS_VLINE; + if (!(top & __CHARTEXT)) + top |= ACS_HLINE; + if (!(bottom & __CHARTEXT)) + bottom |= ACS_HLINE; + if (!(topleft & __CHARTEXT)) + topleft |= ACS_ULCORNER; + if (!(topright & __CHARTEXT)) + topright |= ACS_URCORNER; + if (!(botleft & __CHARTEXT)) + botleft |= ACS_LLCORNER; + if (!(botright & __CHARTEXT)) + botright |= ACS_LRCORNER; + +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, "wborder: left = %c, 0x%x\n", + left & __CHARTEXT, left & __ATTRIBUTES); + __CTRACE(__CTRACE_INPUT, "wborder: right = %c, 0x%x\n", + right & __CHARTEXT, right & __ATTRIBUTES); + __CTRACE(__CTRACE_INPUT, "wborder: top = %c, 0x%x\n", + top & __CHARTEXT, top & __ATTRIBUTES); + __CTRACE(__CTRACE_INPUT, "wborder: bottom = %c, 0x%x\n", + bottom & __CHARTEXT, bottom & __ATTRIBUTES); + __CTRACE(__CTRACE_INPUT, "wborder: topleft = %c, 0x%x\n", + topleft & __CHARTEXT, topleft & __ATTRIBUTES); + __CTRACE(__CTRACE_INPUT, "wborder: topright = %c, 0x%x\n", + topright & __CHARTEXT, topright & __ATTRIBUTES); + __CTRACE(__CTRACE_INPUT, "wborder: botleft = %c, 0x%x\n", + botleft & __CHARTEXT, botleft & __ATTRIBUTES); + __CTRACE(__CTRACE_INPUT, "wborder: botright = %c, 0x%x\n", + botright & __CHARTEXT, botright & __ATTRIBUTES); +#endif + + /* Merge window and background attributes */ + left |= (left & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr; + left |= (left & __COLOR) ? (win->battr & ~__COLOR) : win->battr; + right |= (right & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr; + right |= (right & __COLOR) ? (win->battr & ~__COLOR) : win->battr; + top |= (top & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr; + top |= (top & __COLOR) ? (win->battr & ~__COLOR) : win->battr; + bottom |= (bottom & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr; + bottom |= (bottom & __COLOR) ? (win->battr & ~__COLOR) : win->battr; + topleft |= (topleft & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr; + topleft |= (topleft & __COLOR) ? (win->battr & ~__COLOR) : win->battr; + topright |= (topright & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr; + topright |= (topright & __COLOR) ? (win->battr & ~__COLOR) : win->battr; + botleft |= (botleft & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr; + botleft |= (botleft & __COLOR) ? (win->battr & ~__COLOR) : win->battr; + botright |= (botright & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr; + botright |= (botright & __COLOR) ? (win->battr & ~__COLOR) : win->battr; + + endx = win->maxx - 1; + endy = win->maxy - 1; + fp = win->alines[0]->line; + lp = win->alines[endy]->line; + + /* Sides */ + for (i = 1; i < endy; i++) { + win->alines[i]->line[0].ch = (wchar_t) left & __CHARTEXT; + win->alines[i]->line[0].attr = (attr_t) left & __ATTRIBUTES; + win->alines[i]->line[endx].ch = (wchar_t) right & __CHARTEXT; + win->alines[i]->line[endx].attr = (attr_t) right & __ATTRIBUTES; + } + for (i = 1; i < endx; i++) { + fp[i].ch = (wchar_t) top & __CHARTEXT; + fp[i].attr = (attr_t) top & __ATTRIBUTES; + lp[i].ch = (wchar_t) bottom & __CHARTEXT; + lp[i].attr = (attr_t) bottom & __ATTRIBUTES; + } + + /* Corners */ + if (!(win->maxx == LINES && win->maxy == COLS && + (win->flags & __SCROLLOK) && (win->flags & __SCROLLWIN))) { + fp[0].ch = (wchar_t) topleft & __CHARTEXT; + fp[0].attr = (attr_t) topleft & __ATTRIBUTES; + fp[endx].ch = (wchar_t) topright & __CHARTEXT; + fp[endx].attr = (attr_t) topright & __ATTRIBUTES; + lp[0].ch = (wchar_t) botleft & __CHARTEXT; + lp[0].attr = (attr_t) botleft & __ATTRIBUTES; + lp[endx].ch = (wchar_t) botright & __CHARTEXT; + lp[endx].attr = (attr_t) botright & __ATTRIBUTES; + } + __touchwin(win); + return (OK); +#else /* HAVE_WCHAR */ + cchar_t ls, rs, ts, bs, tl, tr, bl, br; + cchar_t *lsp, *rsp, *tsp, *bsp, *tlp, *trp, *blp, *brp; + +#define S(in, out, def) \ + if (in & __CHARTEXT) { \ + __cursesi_chtype_to_cchar(in, &out); \ + } else { \ + memcpy(&out, def, sizeof(cchar_t)); \ + out.attributes |= in & __ATTRIBUTES; \ + } \ + out##p = &out; + + S(left, ls, WACS_VLINE); + S(right, rs, WACS_VLINE); + S(top, ts, WACS_HLINE); + S(bottom, bs, WACS_HLINE); + S(topleft, tl, WACS_ULCORNER); + S(topright, tr, WACS_URCORNER); + S(botleft, bl, WACS_LLCORNER); + S(botright, br, WACS_LRCORNER); +#undef S + return wborder_set(win, lsp, rsp, tsp, bsp, tlp, trp, blp, brp); +#endif /* HAVE_WCHAR */ +} + +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) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return wborder_set(stdscr, ls, rs, ts, bs, tl, tr, bl, br); +#endif /* HAVE_WCHAR */ +} + +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) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + int endy, endx, i, j, k, cw, pcw, tlcw, blcw, trcw, brcw; + cchar_t left, right, bottom, top, topleft, topright, botleft, botright; + nschar_t *np, *tnp; + + if ( ls && wcwidth( ls->vals[ 0 ])) + memcpy( &left, ls, sizeof( cchar_t )); + else + memcpy( &left, WACS_VLINE, sizeof( cchar_t )); + if ( rs && wcwidth( rs->vals[ 0 ])) + memcpy( &right, rs, sizeof( cchar_t )); + else + memcpy( &right, WACS_VLINE, sizeof( cchar_t )); + if ( ts && wcwidth( ts->vals[ 0 ])) + memcpy( &top, ts, sizeof( cchar_t )); + else + memcpy( &top, WACS_HLINE, sizeof( cchar_t )); + if ( bs && wcwidth( bs->vals[ 0 ])) + memcpy( &bottom, bs, sizeof( cchar_t )); + else + memcpy( &bottom, WACS_HLINE, sizeof( cchar_t )); + if ( tl && wcwidth( tl->vals[ 0 ])) + memcpy( &topleft, tl, sizeof( cchar_t )); + else + memcpy( &topleft, WACS_ULCORNER, sizeof( cchar_t )); + if ( tr && wcwidth( tr->vals[ 0 ])) + memcpy( &topright, tr, sizeof( cchar_t )); + else + memcpy( &topright, WACS_URCORNER, sizeof( cchar_t )); + if ( bl && wcwidth( bl->vals[ 0 ])) + memcpy( &botleft, bl, sizeof( cchar_t )); + else + memcpy( &botleft, WACS_LLCORNER, sizeof( cchar_t )); + if ( br && wcwidth( br->vals[ 0 ])) + memcpy( &botright, br, sizeof( cchar_t )); + else + memcpy( &botright, WACS_LRCORNER, sizeof( cchar_t )); + +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, "wborder_set: left = %c, 0x%x\n", + left.vals[0], left.attributes ); + __CTRACE(__CTRACE_INPUT, "wborder_set: right = %c, 0x%x\n", + right.vals[0], right.attributes ); + __CTRACE(__CTRACE_INPUT, "wborder_set: top = %c, 0x%x\n", + top.vals[0], top.attributes ); + __CTRACE(__CTRACE_INPUT, "wborder_set: bottom = %c, 0x%x\n", + bottom.vals[0], bottom.attributes ); + __CTRACE(__CTRACE_INPUT, "wborder_set: topleft = %c, 0x%x\n", + topleft.vals[0], topleft.attributes ); + __CTRACE(__CTRACE_INPUT, "wborder_set: topright = %c, 0x%x\n", + topright.vals[0], topright.attributes ); + __CTRACE(__CTRACE_INPUT, "wborder_set: botleft = %c, 0x%x\n", + botleft.vals[0], botleft.attributes ); + __CTRACE(__CTRACE_INPUT, "wborder_set: botright = %c, 0x%x\n", + botright.vals[0], botright.attributes ); +#endif + + /* Merge window attributes */ + left.attributes |= (left.attributes & __COLOR) ? + (win->wattr & ~__COLOR) : win->wattr; + right.attributes |= (right.attributes & __COLOR) ? + (win->wattr & ~__COLOR) : win->wattr; + top.attributes |= (top.attributes & __COLOR) ? + (win->wattr & ~__COLOR) : win->wattr; + bottom.attributes |= (bottom.attributes & __COLOR) ? + (win->wattr & ~__COLOR) : win->wattr; + topleft.attributes |= (topleft.attributes & __COLOR) ? + (win->wattr & ~__COLOR) : win->wattr; + topright.attributes |= (topright.attributes & __COLOR) ? + (win->wattr & ~__COLOR) : win->wattr; + botleft.attributes |= (botleft.attributes & __COLOR) ? + (win->wattr & ~__COLOR) : win->wattr; + botright.attributes |= (botright.attributes & __COLOR) ? + (win->wattr & ~__COLOR) : win->wattr; + + endx = win->maxx - 1; + endy = win->maxy - 1; + + /* Sides */ + for (i = 1; i < endy; i++) { + /* left border */ + cw = wcwidth( left.vals[ 0 ]); + if (cw < 0) + cw = 1; + for ( j = 0; j < cw; j++ ) { + win->alines[i]->line[j].ch = left.vals[ 0 ]; + win->alines[i]->line[j].attr = left.attributes; + np = win->alines[i]->line[j].nsp; + if (np) { + while ( np ) { + tnp = np->next; + free( np ); + np = tnp; + } + win->alines[i]->line[j].nsp = NULL; + } + if ( j ) + SET_WCOL( win->alines[i]->line[j], -j ); + else { + SET_WCOL( win->alines[i]->line[j], cw ); + if ( left.elements > 1 ) { + for (k = 1; k < left.elements; k++) { + np = (nschar_t *)malloc(sizeof(nschar_t)); + if (!np) + return ERR; + np->ch = left.vals[ k ]; + np->next = win->alines[i]->line[j].nsp; + win->alines[i]->line[j].nsp + = np; + } + } + } + } + for ( j = cw; WCOL( win->alines[i]->line[j]) < 0; j++ ) { +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "wborder_set: clean out partial char[%d]", j); +#endif /* DEBUG */ + win->alines[i]->line[j].ch = ( wchar_t )btowc(win->bch); + if (_cursesi_copy_nsp(win->bnsp, + &win->alines[i]->line[j]) == ERR) + return ERR; + SET_WCOL( win->alines[i]->line[j], 1 ); + } + /* right border */ + cw = wcwidth( right.vals[ 0 ]); + if (cw < 0) + cw = 1; + pcw = WCOL( win->alines[i]->line[endx - cw]); + for ( j = endx - cw + 1; j <= endx; j++ ) { + win->alines[i]->line[j].ch = right.vals[ 0 ]; + win->alines[i]->line[j].attr = right.attributes; + np = win->alines[i]->line[j].nsp; + if (np) { + while ( np ) { + tnp = np->next; + free( np ); + np = tnp; + } + win->alines[i]->line[j].nsp = NULL; + } + if ( j == endx - cw + 1 ) { + SET_WCOL( win->alines[i]->line[j], cw ); + if ( right.elements > 1 ) { + for (k = 1; k < right.elements; k++) { + np = (nschar_t *)malloc(sizeof(nschar_t)); + if (!np) + return ERR; + np->ch = right.vals[ k ]; + np->next = win->alines[i]->line[j].nsp; + win->alines[i]->line[j].nsp + = np; + } + } + } else + SET_WCOL( win->alines[i]->line[j], + endx - cw + 1 - j ); + } + if ( pcw != 1 ) { +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "wborder_set: clean out partial chars[%d:%d]", + endx - cw + pcw, endx - cw ); +#endif /* DEBUG */ + k = pcw < 0 ? endx -cw + pcw : endx - cw; + for ( j = endx - cw; j >= k; j-- ) { + win->alines[i]->line[j].ch + = (wchar_t)btowc(win->bch); + if (_cursesi_copy_nsp(win->bnsp, + &win->alines[i]->line[j]) == ERR) + return ERR; + win->alines[i]->line[j].attr = win->battr; + SET_WCOL( win->alines[i]->line[j], 1 ); + } + } + } + tlcw = wcwidth( topleft.vals[ 0 ]); + if (tlcw < 0) + tlcw = 1; + blcw = wcwidth( botleft.vals[ 0 ]); + if (blcw < 0) + blcw = 1; + trcw = wcwidth( topright.vals[ 0 ]); + if (trcw < 0) + trcw = 1; + brcw = wcwidth( botright.vals[ 0 ]); + if (brcw < 0) + brcw = 1; + /* upper border */ + cw = wcwidth( top.vals[ 0 ]); + if (cw < 0) + cw = 1; + for (i = tlcw; i <= min( endx - cw, endx - trcw ); i += cw ) { + for ( j = 0; j < cw; j++ ) { + win->alines[ 0 ]->line[i + j].ch = top.vals[ 0 ]; + win->alines[ 0 ]->line[i + j].attr = top.attributes; + np = win->alines[ 0 ]->line[i + j].nsp; + if (np) { + while ( np ) { + tnp = np->next; + free( np ); + np = tnp; + } + win->alines[ 0 ]->line[i + j].nsp = NULL; + } + if ( j ) + SET_WCOL( win->alines[ 0 ]->line[ i + j ], -j ); + else { + SET_WCOL( win->alines[ 0 ]->line[ i + j ], cw ); + if ( top.elements > 1 ) { + for ( k = 1; k < top.elements; k++ ) { + np = (nschar_t *)malloc(sizeof(nschar_t)); + if (!np) + return ERR; + np->ch = top.vals[ k ]; + np->next = win->alines[0]->line[i + j].nsp; + win->alines[0]->line[i + j].nsp + = np; + } + } + } + } + } + while ( i <= endx - trcw ) { + win->alines[0]->line[i].ch = + ( wchar_t )btowc(( int ) win->bch ); + if (_cursesi_copy_nsp(win->bnsp, + &win->alines[0]->line[i]) == ERR) + return ERR; + win->alines[ 0 ]->line[ i ].attr = win->battr; + SET_WCOL( win->alines[ 0 ]->line[ i ], 1 ); + i++; + } + /* lower border */ + for (i = blcw; i <= min( endx - cw, endx - brcw ); i += cw ) { + for ( j = 0; j < cw; j++ ) { + win->alines[ endy ]->line[i + j].ch = bottom.vals[ 0 ]; + win->alines[endy]->line[i + j].attr = bottom.attributes; + np = win->alines[ endy ]->line[i + j].nsp; + if (np) { + while ( np ) { + tnp = np->next; + free( np ); + np = tnp; + } + win->alines[ endy ]->line[i + j].nsp = NULL; + } + if ( j ) + SET_WCOL( win->alines[endy]->line[i + j], -j); + else { + SET_WCOL( win->alines[endy]->line[i + j], cw ); + if ( bottom.elements > 1 ) { + for ( k = 1; k < bottom.elements; + k++ ) { + if ( !( np = ( nschar_t *)malloc( sizeof( nschar_t )))) + return ERR; + np->ch = bottom.vals[ k ]; + np->next = win->alines[endy]->line[i + j].nsp; + win->alines[endy]->line[i + j].nsp = np; + } + } + } + } + } + while ( i <= endx - brcw ) { + win->alines[endy]->line[i].ch = + (wchar_t)btowc((int) win->bch ); + if (_cursesi_copy_nsp(win->bnsp, + &win->alines[endy]->line[i]) == ERR) + return ERR; + win->alines[ endy ]->line[ i ].attr = win->battr; + SET_WCOL( win->alines[ endy ]->line[ i ], 1 ); + i++; + } + + /* Corners */ + if (!(win->maxx == LINES && win->maxy == COLS && + (win->flags & __SCROLLOK) && (win->flags & __SCROLLWIN))) { + for ( i = 0; i < tlcw; i++ ) { + win->alines[ 0 ]->line[i].ch = topleft.vals[ 0 ]; + win->alines[ 0 ]->line[i].attr = topleft.attributes; + np = win->alines[ 0 ]->line[i].nsp; + if (np) { + while ( np ) { + tnp = np->next; + free( np ); + np = tnp; + } + win->alines[ 0 ]->line[i].nsp = NULL; + } + if ( i ) + SET_WCOL( win->alines[ 0 ]->line[ i ], -i ); + else { + SET_WCOL( win->alines[ 0 ]->line[ i ], tlcw ); + if ( topleft.elements > 1 ) { + for ( k = 1; k < topleft.elements; + k++ ) { + np = (nschar_t *)malloc(sizeof(nschar_t)); + if (!np) + return ERR; + np->ch = topleft.vals[ k ]; + np->next = win->alines[ 0 ]->line[i].nsp; + win->alines[ 0 ]->line[i].nsp + = np; + } + } + } + } + for ( i = endx - trcw + 1; i <= endx; i++ ) { + win->alines[ 0 ]->line[i].ch = topright.vals[ 0 ]; + win->alines[ 0 ]->line[i].attr = topright.attributes; + np = win->alines[ 0 ]->line[i].nsp; + if (np) { + while ( np ) { + tnp = np->next; + free( np ); + np = tnp; + } + win->alines[ 0 ]->line[i].nsp = NULL; + } + if ( i == endx - trcw + 1 ) { + SET_WCOL( win->alines[ 0 ]->line[ i ], trcw ); + if ( topright.elements > 1 ) { + for ( k = 1; k < topright.elements; + k++ ) { + np = (nschar_t *)malloc(sizeof(nschar_t)); + if (!np) + return ERR; + np->ch = topright.vals[ k ]; + np->next = win->alines[0]->line[i].nsp; + win->alines[ 0 ]->line[i].nsp + = np; + } + } + } else + SET_WCOL( win->alines[ 0 ]->line[ i ], + endx - trcw + 1 - i ); + } + for ( i = 0; i < blcw; i++ ) { + win->alines[ endy ]->line[i].ch = botleft.vals[ 0 ]; + win->alines[ endy ]->line[i].attr = botleft.attributes; + np = win->alines[ endy ]->line[i].nsp; + if (np) { + while ( np ) { + tnp = np->next; + free( np ); + np = tnp; + } + win->alines[ endy ]->line[i].nsp = NULL; + } + if ( i ) + SET_WCOL( win->alines[endy]->line[i], -i ); + else { + SET_WCOL( win->alines[endy]->line[i], blcw ); + if ( botleft.elements > 1 ) { + for ( k = 1; k < botleft.elements; + k++ ) { + np = (nschar_t *)malloc(sizeof(nschar_t)); + if (!np) + return ERR; + np->ch = botleft.vals[ k ]; + np->next = win->alines[endy]->line[i].nsp; + win->alines[endy]->line[i].nsp + = np; + } + } + } + } + for ( i = endx - brcw + 1; i <= endx; i++ ) { + win->alines[ endy ]->line[i].ch = botright.vals[ 0 ]; + win->alines[ endy ]->line[i].attr = botright.attributes; + np = win->alines[ endy ]->line[i].nsp; + if (np) { + while ( np ) { + tnp = np->next; + free( np ); + np = tnp; + } + win->alines[ endy ]->line[i].nsp = NULL; + } + if ( i == endx - brcw + 1 ) { + SET_WCOL( win->alines[ endy ]->line[ i ], + brcw ); + if ( botright.elements > 1 ) { + for ( k = 1; k < botright.elements; k++ ) { + np = (nschar_t *)malloc(sizeof(nschar_t)); + if (!np) + return ERR; + np->ch = botright.vals[ k ]; + np->next = win->alines[endy]->line[i].nsp; + win->alines[endy]->line[i].nsp + = np; + } + } + } else + SET_WCOL( win->alines[ endy ]->line[ i ], + endx - brcw + 1 - i ); + } + } + __touchwin(win); + return (OK); +#endif /* HAVE_WCHAR */ +} diff --git a/lib/libcurses/box.c b/lib/libcurses/box.c new file mode 100644 index 000000000..9ffe7106a --- /dev/null +++ b/lib/libcurses/box.c @@ -0,0 +1,62 @@ +/* $NetBSD: box.c,v 1.14 2007/05/28 15:01:54 blymn Exp $ */ + +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)box.c 8.2 (Berkeley) 5/4/94"; +#else +__RCSID("$NetBSD: box.c,v 1.14 2007/05/28 15:01:54 blymn Exp $"); +#endif +#endif /* not lint */ + +#include "curses.h" + +/* + * box -- + * Draw a box around the given window with "vert" as the vertical + * delimiting char, and "hor", as the horizontal one. Uses wborder(). + */ +int +box(WINDOW *win, chtype vert, chtype hor) +{ + return (wborder(win, vert, vert, hor, hor, 0, 0, 0, 0)); +} + +int +box_set(WINDOW *win, const cchar_t *verch, const cchar_t *horch) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return wborder_set(win, verch, verch, horch, horch, NULL, NULL, NULL, NULL); +#endif /* HAVE_WCHAR */ +} diff --git a/lib/libcurses/cchar.c b/lib/libcurses/cchar.c new file mode 100644 index 000000000..3f7230648 --- /dev/null +++ b/lib/libcurses/cchar.c @@ -0,0 +1,138 @@ +/* $NetBSD: cchar.c,v 1.5 2010/12/16 17:42:28 wiz Exp $ */ + +/* + * Copyright (c) 2005 The NetBSD Foundation Inc. + * All rights reserved. + * + * This code is derived from code donated to the NetBSD Foundation + * by Ruibiao Qiu . + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND + * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: cchar.c,v 1.5 2010/12/16 17:42:28 wiz Exp $"); +#endif /* not lint */ + +#include + +#include "curses.h" +#include "curses_private.h" + +/* + * getcchar -- + * get a wide-character string and rendition from a cchar_t + */ +int +getcchar(const cchar_t *wcval, wchar_t *wch, attr_t *attrs, + short *color_pair, void *opts) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + wchar_t *wp; + size_t len; + + if ( opts ) + return ERR; + + len = (wp = wmemchr(wcval->vals, L'\0', CCHARW_MAX)) + ? wp - wcval->vals : CCHARW_MAX; + + if (wch == NULL) + return (int) len; + if (attrs == 0 || color_pair == 0) + return ERR; + if (len > 0) { + *attrs = wcval->attributes; + *color_pair = COLOR_PAIR( wcval -> attributes ); + wmemcpy(wch, wcval->vals, (unsigned) len); + wch[len] = L'\0'; + } + return OK; +#endif /* HAVE_WCHAR */ +} + +/* + * setcchar -- + * set cchar_t from a wide-character string and rendition + */ +int +setcchar(cchar_t *wcval, const wchar_t *wch, const attr_t attrs, + short color_pair, const void *opts) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + int i; + size_t len; + + if (opts || (len = wcslen(wch)) > CCHARW_MAX + || (len > 1 && wcwidth(wch[0]) < 0)) { + return ERR; + } + + /* + * If we have a following spacing-character, stop at that point. We + * are only interested in adding non-spacing characters. + */ + for (i = 1; i < len; ++i) { + if (wcwidth(wch[i]) != 0) { + len = i; + break; + } + } + + memset(wcval, 0, sizeof(*wcval)); + if (len != 0) { + wcval -> attributes = attrs | color_pair; + wcval -> elements = 1; + memcpy(&wcval->vals, wch, len * sizeof(wchar_t)); + } + + return OK; +#endif /* HAVE_WCHAR */ +} + +void +__cursesi_chtype_to_cchar(chtype in, cchar_t *out) +{ + unsigned int idx; + + if (in & __ACS_IS_WACS) { + idx = in & __CHARTEXT; + if (idx < NUM_ACS) { + memcpy(out, &_wacs_char[idx], sizeof(cchar_t)); + out->attributes |= in & __ATTRIBUTES; + return; + } + } + out->vals[0] = in & __CHARTEXT; + out->attributes = in & __ATTRIBUTES; + out->elements = 1; +} diff --git a/lib/libcurses/charpick.c b/lib/libcurses/charpick.c deleted file mode 100644 index 4b464a382..000000000 --- a/lib/libcurses/charpick.c +++ /dev/null @@ -1,39 +0,0 @@ -#include - -/****************************************************************/ -/* Winch(win) returns the character at the current position in */ -/* Window 'win'. */ -/****************************************************************/ - -int winch(win) -WINDOW *win; -{ - return((win->_line[win->_cury][win->_curx]) & 0xff); -} /* winch */ - -/****************************************************************/ -/* Mvinch() moves the stdscr cursor to a new position, then */ -/* Returns the character at that position. */ -/****************************************************************/ - -int mvinch(y, x) -int y; -int x; -{ - if (wmove(stdscr, y, x) == ERR) return(ERR); - return((stdscr->_line[stdscr->_cury][stdscr->_curx]) & 0xff); -} - -/****************************************************************/ -/* Mvwinch() moves the cursor of window 'win' to a new posi- */ -/* Tion, then returns the character at that position. */ -/****************************************************************/ - -int mvwinch(win, y, x) -WINDOW *win; -int y; -int x; -{ - if (wmove(win, y, x) == ERR) return(ERR); - return((win->_line[win->_cury][win->_curx]) & 0xff); -} diff --git a/lib/libcurses/chgat.c b/lib/libcurses/chgat.c new file mode 100644 index 000000000..5a2c42baf --- /dev/null +++ b/lib/libcurses/chgat.c @@ -0,0 +1,93 @@ +/* $NetBSD: chgat.c,v 1.4 2009/07/22 16:57:14 roy Exp $ */ + +/* + * Copyright (c) 2009 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Joerg Sonnenberger. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__RCSID("$NetBSD: chgat.c,v 1.4 2009/07/22 16:57:14 roy Exp $"); + +#include "curses.h" +#include "curses_private.h" + +int +chgat(int n, attr_t attr, short color, const void *opts) +{ + return wchgat(stdscr, n, attr, color, opts); +} + +int +mvchgat(int y, int x, int n, attr_t attr, short color, + const void *opts) +{ + return mvwchgat(stdscr, y, x, n, attr, color, opts); +} + +int +wchgat(WINDOW *win, int n, attr_t attr, short color, const void *opts) +{ + return mvwchgat(win, win->cury, win->curx, n, attr, color, opts); +} + +int +mvwchgat(WINDOW *win , int y, int x, int count, attr_t attr, short color, + const void *opts) +{ + __LINE *lp; + __LDATA *lc; + + if (x < 0 || y < 0) + return (ERR); + if (x >= win->maxx || y >= win->maxy) + return (ERR); + + attr = (attr & ~__COLOR) | COLOR_PAIR(color); + + if (count < 0 || count > win->maxx - x) + count = win->maxx - x; + + lp = win->alines[y]; + lc = &lp->line[x]; + + if (x + win->ch_off < *lp->firstchp) + *lp->firstchp = x + win->ch_off; + if (x + win->ch_off + count > *lp->lastchp) + *lp->lastchp = x + win->ch_off + count; + + while (count-- > 0) { + lp->flags |= __ISDIRTY; +#ifdef HAVE_WCHAR + lc->attr = (lc->attr & ~WA_ATTRIBUTES) | attr; +#else + lc->attr = attr; +#endif + ++lc; + } + + return OK; +} diff --git a/lib/libcurses/clear.c b/lib/libcurses/clear.c new file mode 100644 index 000000000..59238b1e6 --- /dev/null +++ b/lib/libcurses/clear.c @@ -0,0 +1,70 @@ +/* $NetBSD: clear.c,v 1.13 2003/08/07 16:44:19 agc Exp $ */ + +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)clear.c 8.2 (Berkeley) 5/4/94"; +#else +__RCSID("$NetBSD: clear.c,v 1.13 2003/08/07 16:44:19 agc Exp $"); +#endif +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +#ifndef _CURSES_USE_MACROS + +/* + * clear -- + * Clear stdscr + */ +int +clear(void) +{ + return wclear(_cursesi_screen->stdscr); +} + +#endif + +/* + * wclear -- + * Clear the window. + */ +int +wclear(WINDOW *win) +{ + if (werase(win) == OK) { + win->flags |= __CLEAROK; + return (OK); + } + return (ERR); +} diff --git a/lib/libcurses/clearok.c b/lib/libcurses/clearok.c new file mode 100644 index 000000000..3bf49b136 --- /dev/null +++ b/lib/libcurses/clearok.c @@ -0,0 +1,52 @@ +/* $NetBSD: clearok.c,v 1.5 2008/04/28 20:23:01 martin Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Julian Coleman. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: clearok.c,v 1.5 2008/04/28 20:23:01 martin Exp $"); +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +/* + * clearok -- + * Turn on and off clear before refresh for the given window. + */ +int +clearok(WINDOW *win, bool bf) +{ + if (bf) + win->flags |= __CLEAROK; + else + win->flags &= ~__CLEAROK; + return (OK); +} diff --git a/lib/libcurses/clrtobot.c b/lib/libcurses/clrtobot.c new file mode 100644 index 000000000..4a2d659f4 --- /dev/null +++ b/lib/libcurses/clrtobot.c @@ -0,0 +1,115 @@ +/* $NetBSD: clrtobot.c,v 1.21 2009/07/22 16:57:14 roy Exp $ */ + +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)clrtobot.c 8.2 (Berkeley) 5/4/94"; +#else +__RCSID("$NetBSD: clrtobot.c,v 1.21 2009/07/22 16:57:14 roy Exp $"); +#endif +#endif /* not lint */ + +#include +#include "curses.h" +#include "curses_private.h" + +#ifndef _CURSES_USE_MACROS + +/* + * clrtobot -- + * Erase everything on stdscr. + */ +int +clrtobot(void) +{ + return wclrtobot(stdscr); +} + +#endif + +/* + * wclrtobot -- + * Erase everything on the window. + */ +int +wclrtobot(WINDOW *win) +{ + int minx, startx, starty, y; + __LDATA *sp, *end, *maxx; + attr_t attr; + +#ifdef __GNUC__ + maxx = NULL; /* XXX gcc -Wuninitialized */ +#endif + if (win->alines[win->cury]->flags & __ISPASTEOL) { + starty = win->cury + 1; + startx = 0; + } else { + starty = win->cury; + startx = win->curx; + } + if (__using_color && win != curscr) + attr = win->battr & __COLOR; + else + attr = 0; + for (y = starty; y < win->maxy; y++) { + minx = -1; + end = &win->alines[y]->line[win->maxx]; + for (sp = &win->alines[y]->line[startx]; sp < end; sp++) { +#ifndef HAVE_WCHAR + if (sp->ch != win->bch || sp->attr != attr) { +#else + if (sp->ch != (wchar_t)btowc((int) win->bch) || + (sp->attr & WA_ATTRIBUTES) != 0 || sp->nsp) { +#endif /* HAVE_WCHAR */ + maxx = sp; + if (minx == -1) + minx = (int)(sp - win->alines[y]->line); + sp->attr = attr; +#ifdef HAVE_WCHAR + sp->ch = ( wchar_t )btowc(( int ) win->bch); + if (_cursesi_copy_nsp(win->bnsp, sp) == ERR) + return ERR; + SET_WCOL( *sp, 1 ); +#else + sp->ch = win->bch; +#endif /* HAVE_WCHAR */ + } + } + + if (minx != -1) + __touchline(win, y, minx, + (int) (maxx - win->alines[y]->line)); + startx = 0; + } + return (OK); +} diff --git a/lib/libcurses/clrtoeol.c b/lib/libcurses/clrtoeol.c new file mode 100644 index 000000000..d7d2a57b9 --- /dev/null +++ b/lib/libcurses/clrtoeol.c @@ -0,0 +1,118 @@ +/* $NetBSD: clrtoeol.c,v 1.25 2009/07/22 16:57:14 roy Exp $ */ + +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)clrtoeol.c 8.2 (Berkeley) 5/4/94"; +#else +__RCSID("$NetBSD: clrtoeol.c,v 1.25 2009/07/22 16:57:14 roy Exp $"); +#endif +#endif /* not lint */ + +#include +#include "curses.h" +#include "curses_private.h" + +#ifndef _CURSES_USE_MACROS + +/* + * clrtoeol -- + * Clear up to the end of line. + */ +int +clrtoeol(void) +{ + return wclrtoeol(stdscr); +} + +#endif + +/* + * wclrtoeol -- + * Clear up to the end of line. + */ +int +wclrtoeol(WINDOW *win) +{ + int minx, x, y; + __LDATA *end, *maxx, *sp; + attr_t attr; + + y = win->cury; + x = win->curx; + if (win->alines[y]->flags & __ISPASTEOL) { + if (y < win->maxy - 1) { + win->alines[y]->flags &= ~__ISPASTEOL; + y++; + x = 0; + win->cury = y; + win->curx = x; + } else + return (OK); + } + end = &win->alines[y]->line[win->maxx]; + minx = -1; + maxx = &win->alines[y]->line[x]; + if (__using_color && win != curscr) + attr = win->battr & __COLOR; + else + attr = 0; + for (sp = maxx; sp < end; sp++) +#ifndef HAVE_WCHAR + if (sp->ch != win->bch || sp->attr != attr) { +#else + if (sp->ch != ( wchar_t )btowc(( int ) win->bch ) || + (sp->attr & WA_ATTRIBUTES) != attr || sp->nsp + || (WCOL(*sp) < 0)) { +#endif /* HAVE_WCHAR */ + maxx = sp; + if (minx == -1) + minx = (int) (sp - win->alines[y]->line); + sp->attr = attr; +#ifdef HAVE_WCHAR + sp->ch = ( wchar_t )btowc(( int ) win->bch); + if (_cursesi_copy_nsp(win->bnsp, sp) == ERR) + return ERR; + SET_WCOL( *sp, 1 ); +#else + sp->ch = win->bch; +#endif /* HAVE_WCHAR */ + } +#ifdef DEBUG + __CTRACE(__CTRACE_ERASE, "CLRTOEOL: y = %d, minx = %d, maxx = %d, " + "firstch = %d, lastch = %d\n", + y, minx, (int) (maxx - win->alines[y]->line), + *win->alines[y]->firstchp, *win->alines[y]->lastchp); +#endif + /* Update firstch and lastch for the line. */ + return (__touchline(win, y, x, (int) win->maxx - 1)); +} diff --git a/lib/libcurses/color.c b/lib/libcurses/color.c new file mode 100644 index 000000000..36bb6ae41 --- /dev/null +++ b/lib/libcurses/color.c @@ -0,0 +1,687 @@ +/* $NetBSD: color.c,v 1.37 2011/01/06 11:29:40 blymn Exp $ */ + +/* + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Julian Coleman. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: color.c,v 1.37 2011/01/06 11:29:40 blymn Exp $"); +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +/* Have we initialised colours? */ +int __using_color = 0; + +/* Default colour number */ +attr_t __default_color = 0; + +/* Default colour pair values - white on black. */ +struct __pair __default_pair = {COLOR_WHITE, COLOR_BLACK, 0}; + +/* Default colour values */ +/* Flags for colours and pairs */ +#define __USED 0x01 + +static void +__change_pair(short); + +/* + * has_colors -- + * Check if terminal has colours. + */ +bool +has_colors(void) +{ + if (max_colors > 0 && max_pairs > 0 && + ((set_a_foreground != NULL && set_a_background != NULL) || + initialize_pair != NULL || initialize_color != NULL || + (set_background != NULL && set_foreground != NULL))) + return(TRUE); + else + return(FALSE); +} + +/* + * can_change_color -- + * Check if terminal can change colours. + */ +bool +can_change_color(void) +{ + if (can_change) + return(TRUE); + else + return(FALSE); +} + +/* + * start_color -- + * Initialise colour support. + */ +int +start_color(void) +{ + int i; + attr_t temp_nc; + struct __winlist *wlp; + WINDOW *win; + int y, x; + + if (has_colors() == FALSE) + return(ERR); + + /* Max colours and colour pairs */ + if (max_colors == -1) + COLORS = 0; + else { + COLORS = max_colors > MAX_COLORS ? MAX_COLORS : max_colors; + if (max_pairs == -1) { + COLOR_PAIRS = 0; + COLORS = 0; + } else { + COLOR_PAIRS = (max_pairs > MAX_PAIRS - 1 ? + MAX_PAIRS - 1 : max_pairs); + /* Use the last colour pair for curses default. */ + __default_color = COLOR_PAIR(MAX_PAIRS - 1); + } + } + if (!COLORS) + return (ERR); + + _cursesi_screen->COLORS = COLORS; + _cursesi_screen->COLOR_PAIRS = COLOR_PAIRS; + + /* Reset terminal colour and colour pairs. */ + if (orig_colors != NULL) + tputs(orig_colors, 0, __cputchar); + if (orig_pair != NULL) { + tputs(orig_pair, 0, __cputchar); + curscr->wattr &= _cursesi_screen->mask_op; + } + + /* Type of colour manipulation - ANSI/TEK/HP/other */ + if (set_a_foreground != NULL && set_a_background != NULL) + _cursesi_screen->color_type = COLOR_ANSI; + else if (initialize_pair != NULL) + _cursesi_screen->color_type = COLOR_HP; + else if (initialize_color != NULL) + _cursesi_screen->color_type = COLOR_TEK; + else if (set_foreground != NULL && set_background != NULL) + _cursesi_screen->color_type = COLOR_OTHER; + else + return(ERR); /* Unsupported colour method */ + +#ifdef DEBUG + __CTRACE(__CTRACE_COLOR, "start_color: COLORS = %d, COLOR_PAIRS = %d", + COLORS, COLOR_PAIRS); + switch (_cursesi_screen->color_type) { + case COLOR_ANSI: + __CTRACE(__CTRACE_COLOR, " (ANSI style)\n"); + break; + case COLOR_HP: + __CTRACE(__CTRACE_COLOR, " (HP style)\n"); + break; + case COLOR_TEK: + __CTRACE(__CTRACE_COLOR, " (Tektronics style)\n"); + break; + case COLOR_OTHER: + __CTRACE(__CTRACE_COLOR, " (Other style)\n"); + break; + } +#endif + + /* + * Attributes that cannot be used with color. + * Store these in an attr_t for wattrset()/wattron(). + */ + _cursesi_screen->nca = __NORMAL; + if (no_color_video != -1) { + temp_nc = (attr_t) t_no_color_video(_cursesi_screen->term); + if (temp_nc & 0x0001) + _cursesi_screen->nca |= __STANDOUT; + if (temp_nc & 0x0002) + _cursesi_screen->nca |= __UNDERSCORE; + if (temp_nc & 0x0004) + _cursesi_screen->nca |= __REVERSE; + if (temp_nc & 0x0008) + _cursesi_screen->nca |= __BLINK; + if (temp_nc & 0x0010) + _cursesi_screen->nca |= __DIM; + if (temp_nc & 0x0020) + _cursesi_screen->nca |= __BOLD; + if (temp_nc & 0x0040) + _cursesi_screen->nca |= __BLANK; + if (temp_nc & 0x0080) + _cursesi_screen->nca |= __PROTECT; + if (temp_nc & 0x0100) + _cursesi_screen->nca |= __ALTCHARSET; + } +#ifdef DEBUG + __CTRACE(__CTRACE_COLOR, "start_color: _cursesi_screen->nca = %08x\n", + _cursesi_screen->nca); +#endif + + /* Set up initial 8 colours */ + if (COLORS >= COLOR_BLACK) + (void) init_color(COLOR_BLACK, 0, 0, 0); + if (COLORS >= COLOR_RED) + (void) init_color(COLOR_RED, 1000, 0, 0); + if (COLORS >= COLOR_GREEN) + (void) init_color(COLOR_GREEN, 0, 1000, 0); + if (COLORS >= COLOR_YELLOW) + (void) init_color(COLOR_YELLOW, 1000, 1000, 0); + if (COLORS >= COLOR_BLUE) + (void) init_color(COLOR_BLUE, 0, 0, 1000); + if (COLORS >= COLOR_MAGENTA) + (void) init_color(COLOR_MAGENTA, 1000, 0, 1000); + if (COLORS >= COLOR_CYAN) + (void) init_color(COLOR_CYAN, 0, 1000, 1000); + if (COLORS >= COLOR_WHITE) + (void) init_color(COLOR_WHITE, 1000, 1000, 1000); + + /* Initialise other colours */ + for (i = 8; i < COLORS; i++) { + _cursesi_screen->colours[i].red = 0; + _cursesi_screen->colours[i].green = 0; + _cursesi_screen->colours[i].blue = 0; + _cursesi_screen->colours[i].flags = 0; + } + + /* Initialise pair 0 to default colours. */ + _cursesi_screen->colour_pairs[0].fore = -1; + _cursesi_screen->colour_pairs[0].back = -1; + _cursesi_screen->colour_pairs[0].flags = 0; + + /* Initialise user colour pairs to default (white on black) */ + for (i = 0; i < COLOR_PAIRS; i++) { + _cursesi_screen->colour_pairs[i].fore = COLOR_WHITE; + _cursesi_screen->colour_pairs[i].back = COLOR_BLACK; + _cursesi_screen->colour_pairs[i].flags = 0; + } + + /* Initialise default colour pair. */ + _cursesi_screen->colour_pairs[PAIR_NUMBER(__default_color)].fore = + __default_pair.fore; + _cursesi_screen->colour_pairs[PAIR_NUMBER(__default_color)].back = + __default_pair.back; + _cursesi_screen->colour_pairs[PAIR_NUMBER(__default_color)].flags = + __default_pair.flags; + + __using_color = 1; + + /* Set all positions on all windows to curses default colours. */ + for (wlp = _cursesi_screen->winlistp; wlp != NULL; wlp = wlp->nextp) { + win = wlp->winp; + if (wlp->winp != __virtscr && wlp->winp != curscr) { + /* Set color attribute on other windows */ + win->battr |= __default_color; + for (y = 0; y < win->maxy; y++) { + for (x = 0; x < win->maxx; x++) { + win->alines[y]->line[x].attr &= ~__COLOR; + win->alines[y]->line[x].attr |= __default_color; + } + } + __touchwin(win); + } + } + + return(OK); +} + +/* + * init_pair -- + * Set pair foreground and background colors. + * Our default colour ordering is ANSI - 1 = red, 4 = blue, 3 = yellow, + * 6 = cyan. The older style (Sb/Sf) uses 1 = blue, 4 = red, 3 = cyan, + * 6 = yellow, so we swap them here and in pair_content(). + */ +int +init_pair(short pair, short fore, short back) +{ + int changed; + +#ifdef DEBUG + __CTRACE(__CTRACE_COLOR, "init_pair: %d, %d, %d\n", pair, fore, back); +#endif + + if (pair < 0 || pair >= COLOR_PAIRS) + return (ERR); + + if (pair == 0) /* Ignore request for pair 0, it is default. */ + return OK; + + if (fore >= COLORS) + return (ERR); + if (back >= COLORS) + return (ERR); + + /* Swap red/blue and yellow/cyan */ + if (_cursesi_screen->color_type == COLOR_OTHER) { + switch (fore) { + case COLOR_RED: + fore = COLOR_BLUE; + break; + case COLOR_BLUE: + fore = COLOR_RED; + break; + case COLOR_YELLOW: + fore = COLOR_CYAN; + break; + case COLOR_CYAN: + fore = COLOR_YELLOW; + break; + } + switch (back) { + case COLOR_RED: + back = COLOR_BLUE; + break; + case COLOR_BLUE: + back = COLOR_RED; + break; + case COLOR_YELLOW: + back = COLOR_CYAN; + break; + case COLOR_CYAN: + back = COLOR_YELLOW; + break; + } + } + + if ((_cursesi_screen->colour_pairs[pair].flags & __USED) && + (fore != _cursesi_screen->colour_pairs[pair].fore || + back != _cursesi_screen->colour_pairs[pair].back)) + changed = 1; + else + changed = 0; + + _cursesi_screen->colour_pairs[pair].flags |= __USED; + _cursesi_screen->colour_pairs[pair].fore = fore; + _cursesi_screen->colour_pairs[pair].back = back; + + /* XXX: need to initialise HP style (Ip) */ + + if (changed) + __change_pair(pair); + return (OK); +} + +/* + * pair_content -- + * Get pair foreground and background colours. + */ +int +pair_content(short pair, short *forep, short *backp) +{ + if (pair < 0 || pair > _cursesi_screen->COLOR_PAIRS) + return(ERR); + + *forep = _cursesi_screen->colour_pairs[pair].fore; + *backp = _cursesi_screen->colour_pairs[pair].back; + + /* Swap red/blue and yellow/cyan */ + if (_cursesi_screen->color_type == COLOR_OTHER) { + switch (*forep) { + case COLOR_RED: + *forep = COLOR_BLUE; + break; + case COLOR_BLUE: + *forep = COLOR_RED; + break; + case COLOR_YELLOW: + *forep = COLOR_CYAN; + break; + case COLOR_CYAN: + *forep = COLOR_YELLOW; + break; + } + switch (*backp) { + case COLOR_RED: + *backp = COLOR_BLUE; + break; + case COLOR_BLUE: + *backp = COLOR_RED; + break; + case COLOR_YELLOW: + *backp = COLOR_CYAN; + break; + case COLOR_CYAN: + *backp = COLOR_YELLOW; + break; + } + } + return(OK); +} + +/* + * init_color -- + * Set colour red, green and blue values. + */ +int +init_color(short color, short red, short green, short blue) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_COLOR, "init_color: %d, %d, %d, %d\n", + color, red, green, blue); +#endif + if (color < 0 || color >= _cursesi_screen->COLORS) + return(ERR); + + _cursesi_screen->colours[color].red = red; + _cursesi_screen->colours[color].green = green; + _cursesi_screen->colours[color].blue = blue; + /* XXX Not yet implemented */ + return(ERR); + /* XXX: need to initialise Tek style (Ic) and support HLS */ +} + +/* + * color_content -- + * Get colour red, green and blue values. + */ +int +color_content(short color, short *redp, short *greenp, short *bluep) +{ + if (color < 0 || color >= _cursesi_screen->COLORS) + return(ERR); + + *redp = _cursesi_screen->colours[color].red; + *greenp = _cursesi_screen->colours[color].green; + *bluep = _cursesi_screen->colours[color].blue; + return(OK); +} + +/* + * use_default_colors -- + * Use terminal default colours instead of curses default colour. + */ +int +use_default_colors() +{ +#ifdef DEBUG + __CTRACE(__CTRACE_COLOR, "use_default_colors\n"); +#endif + + return(assume_default_colors(-1, -1)); +} + +/* + * assume_default_colors -- + * Set the default foreground and background colours. + */ +int +assume_default_colors(short fore, short back) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_COLOR, "assume_default_colors: %d, %d\n", + fore, back); + __CTRACE(__CTRACE_COLOR, "assume_default_colors: default_colour = %d, pair_number = %d\n", __default_color, PAIR_NUMBER(__default_color)); +#endif + + /* Swap red/blue and yellow/cyan */ + if (_cursesi_screen->color_type == COLOR_OTHER) { + switch (fore) { + case COLOR_RED: + fore = COLOR_BLUE; + break; + case COLOR_BLUE: + fore = COLOR_RED; + break; + case COLOR_YELLOW: + fore = COLOR_CYAN; + break; + case COLOR_CYAN: + fore = COLOR_YELLOW; + break; + } + switch (back) { + case COLOR_RED: + back = COLOR_BLUE; + break; + case COLOR_BLUE: + back = COLOR_RED; + break; + case COLOR_YELLOW: + back = COLOR_CYAN; + break; + case COLOR_CYAN: + back = COLOR_YELLOW; + break; + } + } + __default_pair.fore = fore; + __default_pair.back = back; + __default_pair.flags = __USED; + + if (COLOR_PAIRS) { + _cursesi_screen->colour_pairs[PAIR_NUMBER(__default_color)].fore = fore; + _cursesi_screen->colour_pairs[PAIR_NUMBER(__default_color)].back = back; + _cursesi_screen->colour_pairs[PAIR_NUMBER(__default_color)].flags = __USED; + } + + /* + * If we've already called start_color(), make sure all instances + * of the curses default colour pair are dirty. + */ + if (__using_color) + __change_pair(PAIR_NUMBER(__default_color)); + + return(OK); +} + +/* no_color_video is a terminfo macro, but we need to retain binary compat */ +#ifdef __strong_alias +#undef no_color_video +__strong_alias(no_color_video, no_color_attributes) +#endif +/* + * no_color_attributes -- + * Return attributes that cannot be combined with color. + */ +attr_t +no_color_attributes(void) +{ + return(_cursesi_screen->nca); +} + +/* + * __set_color -- + * Set terminal foreground and background colours. + */ +void +__set_color( /*ARGSUSED*/ WINDOW *win, attr_t attr) +{ + short pair; + + if ((curscr->wattr & __COLOR) == (attr & __COLOR)) + return; + + pair = PAIR_NUMBER((u_int32_t)attr); +#ifdef DEBUG + __CTRACE(__CTRACE_COLOR, "__set_color: %d, %d, %d\n", pair, + _cursesi_screen->colour_pairs[pair].fore, + _cursesi_screen->colour_pairs[pair].back); +#endif + switch (_cursesi_screen->color_type) { + /* Set ANSI forground and background colours */ + case COLOR_ANSI: + if (_cursesi_screen->colour_pairs[pair].fore < 0 || + _cursesi_screen->colour_pairs[pair].back < 0) + __unset_color(curscr); + if (_cursesi_screen->colour_pairs[pair].fore >= 0) + tputs(vtparm(t_set_a_foreground(_cursesi_screen->term), + _cursesi_screen->colour_pairs[pair].fore), + 0, __cputchar); + if (_cursesi_screen->colour_pairs[pair].back >= 0) + tputs(vtparm(t_set_a_background(_cursesi_screen->term), + _cursesi_screen->colour_pairs[pair].back), + 0, __cputchar); + break; + case COLOR_HP: + /* XXX: need to support HP style */ + break; + case COLOR_TEK: + /* XXX: need to support Tek style */ + break; + case COLOR_OTHER: + if (_cursesi_screen->colour_pairs[pair].fore < 0 || + _cursesi_screen->colour_pairs[pair].back < 0) + __unset_color(curscr); + if (_cursesi_screen->colour_pairs[pair].fore >= 0) + tputs(vtparm(t_set_foreground(_cursesi_screen->term), + _cursesi_screen->colour_pairs[pair].fore), + 0, __cputchar); + if (_cursesi_screen->colour_pairs[pair].back >= 0) + tputs(vtparm(t_set_background(_cursesi_screen->term), + _cursesi_screen->colour_pairs[pair].back), + 0, __cputchar); + break; + } + curscr->wattr &= ~__COLOR; + curscr->wattr |= attr & __COLOR; +} + +/* + * __unset_color -- + * Clear terminal foreground and background colours. + */ +void +__unset_color(WINDOW *win) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_COLOR, "__unset_color\n"); +#endif + switch (_cursesi_screen->color_type) { + /* Clear ANSI forground and background colours */ + case COLOR_ANSI: + if (orig_pair != NULL) { + tputs(orig_pair, 0, __cputchar); + win->wattr &= __mask_op; + } + break; + case COLOR_HP: + /* XXX: need to support HP style */ + break; + case COLOR_TEK: + /* XXX: need to support Tek style */ + break; + case COLOR_OTHER: + if (orig_pair != NULL) { + tputs(orig_pair, 0, __cputchar); + win->wattr &= __mask_op; + } + break; + } +} + +/* + * __restore_colors -- + * Redo color definitions after restarting 'curses' mode. + */ +void +__restore_colors(void) +{ + if (can_change != 0) + switch (_cursesi_screen->color_type) { + case COLOR_HP: + /* XXX: need to re-initialise HP style (Ip) */ + break; + case COLOR_TEK: + /* XXX: need to re-initialise Tek style (Ic) */ + break; + } +} + +/* + * __change_pair -- + * Mark dirty all positions using pair. + */ +void +__change_pair(short pair) +{ + struct __winlist *wlp; + WINDOW *win; + int y, x; + __LINE *lp; + uint32_t cl = COLOR_PAIR(pair); + + + for (wlp = _cursesi_screen->winlistp; wlp != NULL; wlp = wlp->nextp) { +#ifdef DEBUG + __CTRACE(__CTRACE_COLOR, "__change_pair: win = %p\n", + wlp->winp); +#endif + win = wlp->winp; + if (win == __virtscr) + continue; + else if (win == curscr) { + /* Reset colour attribute on curscr */ +#ifdef DEBUG + __CTRACE(__CTRACE_COLOR, + "__change_pair: win == curscr\n"); +#endif + for (y = 0; y < curscr->maxy; y++) { + lp = curscr->alines[y]; + for (x = 0; x < curscr->maxx; x++) { + if ((lp->line[x].attr & __COLOR) == cl) + lp->line[x].attr &= ~__COLOR; + } + } + } else { + /* Mark dirty those positions with colour pair "pair" */ + for (y = 0; y < win->maxy; y++) { + lp = win->alines[y]; + for (x = 0; x < win->maxx; x++) + if ((lp->line[x].attr & + __COLOR) == cl) { + if (!(lp->flags & __ISDIRTY)) + lp->flags |= __ISDIRTY; + /* + * firstchp/lastchp are shared + * between parent window and + * sub-window. + */ + if (*lp->firstchp > x) + *lp->firstchp = x; + if (*lp->lastchp < x) + *lp->lastchp = x; + } +#ifdef DEBUG + if ((win->alines[y]->flags & __ISDIRTY)) + __CTRACE(__CTRACE_COLOR, + "__change_pair: first = %d, " + "last = %d\n", + *win->alines[y]->firstchp, + *win->alines[y]->lastchp); +#endif + } + } + } +} diff --git a/lib/libcurses/copywin.c b/lib/libcurses/copywin.c new file mode 100644 index 000000000..0bec7224f --- /dev/null +++ b/lib/libcurses/copywin.c @@ -0,0 +1,135 @@ +/* $NetBSD: copywin.c,v 1.15 2009/07/22 16:57:14 roy Exp $ */ + +/*- + * Copyright (c) 1998-1999 Brett Lymn + * (blymn@baea.com.au, brett_lymn@yahoo.com.au) + * All rights reserved. + * + * This code has been donated to The NetBSD Foundation by the Author. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + */ + +#include +#ifndef lint +__RCSID("$NetBSD: copywin.c,v 1.15 2009/07/22 16:57:14 roy Exp $"); +#endif /* not lint */ + +#include +#include +#include "curses.h" +#include "curses_private.h" + +/* + * copywin -- + * Copy the box starting at (sminrow, smincol) with a size that + * matches the destination box (dminrow, dmincol) by (dmaxrow, dmaxcol) + * from the source window srcwin to the destination window dstwin. + * All these coordindinates are relative to the relevant window. + * If dooverlay is true then the copy is nondestructive otherwise the + * copy is destructive. + */ +int copywin(const WINDOW *srcwin, WINDOW *dstwin, + int sminrow, int smincol, + int dminrow, int dmincol, int dmaxrow, int dmaxcol, int dooverlay) +{ + int dcol; + __LDATA *sp, *end; +#ifdef HAVE_WCHAR + cchar_t cc; + nschar_t *np; +#endif /* HAVE_WCHAR */ + + /* overwrite() and overlay() can come here with -ve srcwin coords */ + if (sminrow < 0) { + dminrow -= sminrow; + sminrow = 0; + } + if (smincol < 0) { + dmincol -= smincol; + smincol = 0; + } + + /* for symmetry allow dstwin coords to be -ve as well */ + if (dminrow < 0) { + sminrow -= dminrow; + dminrow = 0; + } + if (dmincol < 0) { + smincol -= dmincol; + dmincol = 0; + } + + /* Bound dmaxcol for both windows (should be ok for dstwin) */ + if (dmaxcol >= dstwin->maxx) + dmaxcol = dstwin->maxx - 1; + if (smincol + (dmaxcol - dmincol) >= srcwin->maxx) + dmaxcol = srcwin->maxx + dmincol - smincol - 1; + if (dmaxcol < dmincol) + /* nothing in the intersection */ + return OK; + + /* Bound dmaxrow for both windows (should be ok for dstwin) */ + if (dmaxrow >= dstwin->maxy) + dmaxrow = dstwin->maxy - 1; + if (sminrow + (dmaxrow - dminrow) >= srcwin->maxy) + dmaxrow = srcwin->maxy + dminrow - sminrow - 1; + +#ifdef DEBUG + __CTRACE(__CTRACE_WINDOW, + "copywin %s mode: from (%d,%d) to (%d,%d-%d,%d)\n", + dooverlay ? "overlay" : "overwrite", + sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol); +#endif + + for (; dminrow <= dmaxrow; sminrow++, dminrow++) { + sp = &srcwin->alines[sminrow]->line[smincol]; + end = sp + dmaxcol - dmincol; + for (dcol = dmincol; sp <= end; dcol++, sp++) { + /* XXX: Perhaps this should check for the + * background character + */ + if ((dooverlay && !isspace(sp->ch)) || !dooverlay) { + wmove(dstwin, dminrow, dcol); +#ifndef HAVE_WCHAR + __waddch(dstwin, sp); +#else + cc.vals[0] = sp->ch; + cc.attributes = sp->attr; + cc.elements = 1; + np = sp->nsp; + if (np) { + while (np && cc.elements <= + CURSES_CCHAR_MAX) { + cc.vals[cc.elements++] = np->ch; + np = np->next; + } + } + wadd_wch(dstwin, &cc); +#endif /* HAVE_WCHAR */ + } + } + } + __touchwin(dstwin); + return OK; +} + diff --git a/lib/libcurses/cr_put.c b/lib/libcurses/cr_put.c new file mode 100644 index 000000000..10de43832 --- /dev/null +++ b/lib/libcurses/cr_put.c @@ -0,0 +1,480 @@ +/* $NetBSD: cr_put.c,v 1.30 2010/02/12 10:06:15 roy Exp $ */ + +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)cr_put.c 8.3 (Berkeley) 5/4/94"; +#else +__RCSID("$NetBSD: cr_put.c,v 1.30 2010/02/12 10:06:15 roy Exp $"); +#endif +#endif /* not lint */ + +#include + +#include "curses.h" +#include "curses_private.h" + +#define HARDTABS 8 + +/* + * Terminal driving and line formatting routines. Basic motion optimizations + * are done here as well as formatting lines (printing of control characters, + * line numbering and the like). + */ + +/* Stub function for the users. */ +int +mvcur(int ly, int lx, int y, int x) +{ + return (__mvcur(ly, lx, y, x, 0)); +} + +static void fgoto __P((int)); +static int plod __P((int, int)); +static int plodput __P((int)); +static int tabcol __P((int, int)); + +static int outcol, outline, destcol, destline; + +/* + * Sync the position of the output cursor. Most work here is rounding for + * terminal boundaries getting the column position implied by wraparound or + * the lack thereof and rolling up the screen to get destline on the screen. + */ +int +__mvcur(int ly, int lx, int y, int x, int in_refresh) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_OUTPUT, + "mvcur: moving cursor from (%d, %d) to (%d, %d)\n", ly, lx, y, x); +#endif + destcol = x; + destline = y; + outcol = lx; + outline = ly; + fgoto(in_refresh); + return (OK); +} + +static void +fgoto(in_refresh) + int in_refresh; +{ + int c, l; + char *cgp; + +#ifdef DEBUG + __CTRACE(__CTRACE_OUTPUT, "fgoto: in_refresh=%d\n", in_refresh); +#endif /* DEBUG */ + if (destcol >= COLS) { + destline += destcol / COLS; + destcol %= COLS; + } + if (outcol >= COLS) { + l = (outcol + 1) / COLS; + outline += l; + outcol %= COLS; + if (auto_left_margin == 0) { + while (l > 0) { + if (__pfast) { + if (carriage_return) + tputs(carriage_return, + 0, __cputchar); + else + __cputchar('\r'); + } + if (cursor_down) + tputs(cursor_down, 0, __cputchar); + else + __cputchar('\n'); + l--; + } + outcol = 0; + } + if (outline > LINES - 1) { + destline -= outline - (LINES - 1); + outline = LINES - 1; + } + } + if (destline >= LINES) { + l = destline; + destline = LINES - 1; + if (outline < LINES - 1) { + c = destcol; + if (__pfast == 0 && !cursor_address) + destcol = 0; + fgoto(in_refresh); + destcol = c; + } + while (l >= LINES) { + /* The following linefeed (or simulation thereof) is + * supposed to scroll up the screen, since we are on + * the bottom line. We make the assumption that + * linefeed will scroll. If ns is in the capability + * list this won't work. We should probably have an + * sc capability but sf will generally take the place + * if it works. + * + * Superbee glitch: in the middle of the screen have to + * use esc B (down) because linefeed screws up in + * "Efficient Paging" (what a joke) mode (which is + * essential in some SB's because CRLF mode puts + * garbage in at end of memory), but you must use + * linefeed to scroll since down arrow won't go past + * memory end. I turned this off after recieving Paul + * Eggert's Superbee description which wins better. */ + if (cursor_down /* && !__tc_xb */ && __pfast) + tputs(cursor_down, 0, __cputchar); + else + __cputchar('\n'); + l--; + if (__pfast == 0) + outcol = 0; + } + } + if (destline < outline && !(cursor_address || cursor_up)) + destline = outline; + + if (cursor_address && + (cgp = t_vparm(NULL, cursor_address, destline, destcol))) + { + /* + * Need this condition due to inconsistent behavior + * of backspace on the last column. + */ +#ifdef DEBUG + __CTRACE(__CTRACE_OUTPUT, "fgoto: cgp=%s\n", cgp); +#endif /* DEBUG */ + if (outcol != COLS - 1 && + plod((int) strlen(cgp), in_refresh) > 0) + plod(0, in_refresh); + else + tputs(cgp, 0, __cputchar); + } else + plod(0, in_refresh); + outline = destline; + outcol = destcol; +} +/* + * Move (slowly) to destination. + * Hard thing here is using home cursor on really deficient terminals. + * Otherwise just use cursor motions, hacking use of tabs and overtabbing + * and backspace. + * + * XXX this needs to be revisited for wide characters since we may output + * XXX more than one byte for a character. + */ + +static int plodcnt, plodflg; + +static int +plodput(c) + int c; +{ + if (plodflg) + --plodcnt; + else + __cputchar(c); + return (0); +} + +static int +plod(cnt, in_refresh) + int cnt, in_refresh; +{ + int i, j, k, soutcol, soutline; + +#ifdef DEBUG + __CTRACE(__CTRACE_OUTPUT, "plod: cnt=%d, in_refresh=%d\n", + cnt, in_refresh); +#endif /* DEBUG */ + plodcnt = plodflg = cnt; + soutcol = outcol; + soutline = outline; + + /* + * Consider homing and moving down/right from there, vs. moving + * directly with local motions to the right spot. + */ + if (cursor_home) { + /* + * i is the cost to home and tab/space to the right to get to + * the proper column. This assumes nd space costs 1 char. So + * i + destcol is cost of motion with home. + */ + if (__GT) + i = (destcol / HARDTABS) + (destcol % HARDTABS); + else + i = destcol; + + /* j is cost to move locally without homing. */ + if (destcol >= outcol) { /* if motion is to the right */ + j = destcol / HARDTABS - outcol / HARDTABS; + if (__GT && j) + j += destcol % HARDTABS; + else + j = destcol - outcol; + } else + /* leftward motion only works if we can backspace. */ + if (outcol - destcol <= i) + /* Cheaper to backspace. */ + i = j = outcol - destcol; + else + /* Impossibly expensive. */ + j = i + 1; + + /* k is the absolute value of vertical distance. */ + k = outline - destline; + if (k < 0) + k = -k; + j += k; + + /* Decision. We may not have a choice if no up. */ + if (i + destline < j || (!cursor_up && destline < outline)) { + /* + * Cheaper to home. Do it now and pretend it's a + * regular local motion. + */ + tputs(cursor_home, 0, plodput); + outcol = outline = 0; + } else + if (cursor_to_ll) { + /* + * Quickly consider homing down and moving from + * there. Assume cost of ll is 2. + */ + k = (LINES - 1) - destline; + if (i + k + 2 < j && (k <= 0 || cursor_up)) { + tputs(cursor_to_ll, 0, plodput); + outcol = 0; + outline = LINES - 1; + } + } + } else + /* No home and no up means it's impossible. */ + if (!cursor_up && destline < outline) + return (-1); + if (__GT) + i = destcol % HARDTABS + destcol / HARDTABS; + else + i = destcol; +#ifdef notdef + if (back_tab && outcol > destcol && + (j = (((outcol + 7) & ~7) - destcol - 1) >> 3)) { + j *= (k = strlen(back_tab)); + if ((k += (destcol & 7)) > 4) + j += 8 - (destcol & 7); + else + j += k; + } else +#endif + j = outcol - destcol; + + /* + * If we will later need a \n which will turn into a \r\n by the + * system or the terminal, then don't bother to try to \r. + */ + if ((__NONL || !__pfast) && outline < destline) + goto dontcr; + + /* + * If the terminal will do a \r\n and there isn't room for it, then + * we can't afford a \r. + */ + if (!carriage_return && outline >= destline) + goto dontcr; + + /* + * If it will be cheaper, or if we can't back up, then send a return + * preliminarily. + */ + if (j > i + 1 || outcol > destcol) { + /* + * BUG: this doesn't take the (possibly long) length of cr + * into account. + */ + if (carriage_return) + tputs(carriage_return, 0, plodput); + else + plodput('\r'); + if (!carriage_return) { + if (cursor_down) + tputs(cursor_down, 0, plodput); + else + plodput('\n'); + outline++; + } + outcol = 0; + } +dontcr:while (outline < destline) { + outline++; + if (cursor_down) + tputs(cursor_down, 0, plodput); + else + plodput('\n'); + if (plodcnt < 0) + goto out; + if (__NONL || __pfast == 0) + outcol = 0; + } + if (back_tab) + k = (int) strlen(back_tab); + while (outcol > destcol) { + if (plodcnt < 0) + goto out; +#ifdef notdef + if (back_tab && outcol - destcol > k + 4) { + tputs(back_tab, 0, plodput); + outcol--; + outcol &= ~7; + continue; + } +#endif + outcol--; + if (cursor_left) + tputs(cursor_left, 0, plodput); + else + plodput('\b'); + } + while (outline > destline) { + outline--; + tputs(cursor_up, 0, plodput); + if (plodcnt < 0) + goto out; + } + if (__GT && destcol - outcol > 1) { + for (;;) { + i = tabcol(outcol, HARDTABS); + if (i > destcol) + break; + if (tab) + tputs(tab, 0, plodput); + else + plodput('\t'); + outcol = i; + } + if (destcol - outcol > 4 && i < COLS) { + if (tab) + tputs(tab, 0, plodput); + else + plodput('\t'); + outcol = i; + while (outcol > destcol) { + outcol--; + if (cursor_left) + tputs(cursor_left, 0, plodput); + else + plodput('\b'); + } + } + } + while (outcol < destcol) { + /* + * Move one char to the right. We don't use nd space because + * it's better to just print the char we are moving over. + */ + if (in_refresh) + if (plodflg) /* Avoid a complex calculation. */ + plodcnt--; + else { +#ifndef HAVE_WCHAR + i = curscr->alines[outline]->line[outcol].ch + & __CHARTEXT; + if (curscr->alines[outline]->line[outcol].attr + == curscr->wattr) + __cputchar(i); +#else + if ((curscr->alines[outline]->line[outcol].attr + & WA_ATTRIBUTES) + == curscr->wattr) { + switch (WCOL(curscr->alines[outline]->line[outcol])) { + case 1: + __cputwchar(curscr->alines[outline]->line[outcol].ch); + __cursesi_putnsp(curscr->alines[outline]->line[outcol].nsp, + outline, + outcol); +#ifdef DEBUG + __CTRACE(__CTRACE_OUTPUT, + "plod: (%d,%d)WCOL(%d), " + "putwchar(%x)\n", + outline, outcol, + WCOL(curscr->alines[outline]->line[outcol]), + curscr->alines[outline]->line[outcol].ch); +#endif /* DEBUG */ + /*FALLTHROUGH*/ + case 0: + break; + default: + goto nondes; + } + } +#endif /* HAVE_WCHAR */ + else + goto nondes; + } + else + nondes: if (cursor_right) + tputs(cursor_right, 0, plodput); + else + plodput(' '); + outcol++; + if (plodcnt < 0) + goto out; + } + +out: if (plodflg) { + outcol = soutcol; + outline = soutline; + } +#ifdef DEBUG + __CTRACE(__CTRACE_OUTPUT, "plod: returns %d\n", plodcnt); +#endif /* DEBUG */ + return (plodcnt); +} +/* + * Return the column number that results from being in column col and + * hitting a tab, where tabs are set every ts columns. Work right for + * the case where col > COLS, even if ts does not divide COLS. + */ +static int +tabcol(col, ts) + int col, ts; +{ + int offset; + + if (col >= COLS) { + offset = COLS * (col / COLS); + col -= offset; + } else + offset = 0; + return (col + ts - (col % ts) + offset); +} diff --git a/lib/libcurses/ctrace.c b/lib/libcurses/ctrace.c new file mode 100644 index 000000000..04cccad15 --- /dev/null +++ b/lib/libcurses/ctrace.c @@ -0,0 +1,120 @@ +/* $NetBSD: ctrace.c,v 1.20 2009/01/17 15:25:36 christos Exp $ */ + +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)ctrace.c 8.2 (Berkeley) 10/5/93"; +#else +__RCSID("$NetBSD: ctrace.c,v 1.20 2009/01/17 15:25:36 christos Exp $"); +#endif +#endif /* not lint */ + +#ifdef DEBUG +#include +#include +#include + +#include +#include + +#include "curses.h" +#include "curses_private.h" + +static FILE *tracefp = NULL; /* Curses debugging file descriptor. */ + +static int tracemask; /* Areas of trace output we want. */ + +static int init_done = 0; + +void +__CTRACE_init() +{ + char *tf, *tm; + + tm = getenv("CURSES_TRACE_MASK"); + if (tm == NULL) + tracemask = __CTRACE_ALL; + else { + tracemask = (int) strtol(tm, NULL, 0); + } + if (tracemask < 0) + tracemask = (0 - tracemask) ^ __CTRACE_ALL; + if (tracemask == 0) + return; + + tf = getenv("CURSES_TRACE_FILE"); + + if ((tf != NULL) && !strcmp( tf, "")) + tf = NULL; + + if (tf != NULL) + tracefp = fopen(tf, "w"); + + init_done = 1; + __CTRACE(__CTRACE_ALL, "Trace mask: 0x%08x\n", tracemask); +} + +void +__CTRACE(int area, const char *fmt,...) +{ + struct timeval tv; + static int seencr = 1; + va_list ap; + + if (!init_done) + __CTRACE_init(); + if (tracefp == NULL || !(tracemask & area)) { + return; + } + gettimeofday(&tv, NULL); + if (seencr && (tracemask & __CTRACE_TSTAMP)) { + gettimeofday(&tv, NULL); + (void) fprintf(tracefp, "%llu.%06lu: ", + (long long)tv.tv_sec, (long)tv.tv_usec); + } + va_start(ap, fmt); + (void) vfprintf(tracefp, fmt, ap); + seencr = (strchr(fmt, '\n') != NULL); + va_end(ap); + (void) fflush(tracefp); +} +#else +/* this kills the empty translation unit message from lint... */ +void +__cursesi_make_lint_shut_up_if_debug_not_defined(void); + +void +__cursesi_make_lint_shut_up_if_debug_not_defined(void) +{ + return; +} +#endif diff --git a/lib/libcurses/cur_hash.c b/lib/libcurses/cur_hash.c new file mode 100644 index 000000000..caf051535 --- /dev/null +++ b/lib/libcurses/cur_hash.c @@ -0,0 +1,65 @@ +/* $NetBSD: cur_hash.c,v 1.12 2005/02/18 22:16:27 dsl Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)cur_hash.c 8.1 (Berkeley) 6/4/93"; +#else +__RCSID("$NetBSD: cur_hash.c,v 1.12 2005/02/18 22:16:27 dsl Exp $"); +#endif +#endif /* not lint */ + +#include + +#include "curses.h" +#include "curses_private.h" + +/* + * __hash_more() is "hashpjw" from the Dragon Book, Aho, Sethi & Ullman, p.436. + */ +u_int +__hash_more(const void *v_s, size_t len, u_int h) +{ + u_int g; + size_t i = 0; + const char *s = v_s; + + while (i < len) { + h = (h << 4) + s[i]; + if ((g = h & 0xf0000000) != 0) { + h = h ^ (g >> 24); + h = h ^ g; + } + i++; + } + return h; +} diff --git a/lib/libcurses/curs_set.c b/lib/libcurses/curs_set.c index e481d59b2..b59359f48 100644 --- a/lib/libcurses/curs_set.c +++ b/lib/libcurses/curs_set.c @@ -1,25 +1,105 @@ -#include -#include +/* $NetBSD: curs_set.c,v 1.9 2010/02/03 15:34:40 roy Exp $ */ -extern char *vi, *ve, *vs; +/*- + * Copyright (c) 1998-2000 Brett Lymn + * (blymn@baea.com.au, brett_lymn@yahoo.com.au) + * All rights reserved. + * + * This code has been donated to The NetBSD Foundation by the Author. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + */ -/* Sets cursor visibility to unvisible=0; normal visible=1 or very good - * visible=2. -*/ -void curs_set(visibility) -int visibility; +#include +#ifndef lint +__RCSID("$NetBSD: curs_set.c,v 1.9 2010/02/03 15:34:40 roy Exp $"); +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +/* + * curs_set -- + * Set the visibility of the cursor, 0 means invisible, 1 means normal + * visibility and 2 means high visibility. Return the previous + * visibility iff the terminal supports the new visibility otherwise + * return ERR. + */ +int +curs_set(int visibility) { - switch (visibility) { - case 0: - if (vi) tputs(vi, 1, outc); - break; - case 1: - if (ve) tputs(ve, 1, outc); - break; - case 2: - if (vs) - tputs(vs, 1, outc); - else if (ve) - tputs(ve, 1, outc); - } + int old_one; + + old_one = _cursesi_screen->old_mode; + switch (visibility) { + case 0: /* invisible */ + if (cursor_invisible != NULL) { +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, + "curs_set: invisible\n"); +#endif + _cursesi_screen->old_mode = 0; + tputs(cursor_invisible, 0, __cputchar); + return old_one; + } + break; + + case 1: /* normal */ + if (cursor_normal != NULL) { +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "curs_set: normal\n"); +#endif + _cursesi_screen->old_mode = 1; + tputs(cursor_normal, 0, __cputchar); + return old_one; + } + break; + + case 2: /* high visibility */ + if (cursor_visible != NULL) { +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, + "curs_set: high vis\n"); +#endif + _cursesi_screen->old_mode = 2; + tputs(cursor_visible, 0, __cputchar); + return old_one; + } + break; + + default: + break; + } + + return ERR; } + +/* + * __restore_cursor_vis -- + * Restore the old cursor visibility. + */ +void +__restore_cursor_vis(void) +{ + curs_set(_cursesi_screen->old_mode); +} + diff --git a/lib/libcurses/curses.3 b/lib/libcurses/curses.3 new file mode 100644 index 000000000..eaad716a1 --- /dev/null +++ b/lib/libcurses/curses.3 @@ -0,0 +1,338 @@ +.\" $NetBSD: curses.3,v 1.61 2010/12/09 13:26:27 njoly Exp $ +.\" +.\" Copyright (c) 1985, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)curses.3 8.1 (Berkeley) 6/4/93 +.\" +.Dd July 6, 2009 +.Dt CURSES 3 +.Os +.Sh NAME +.Nm curses +.Nd screen functions with +.Dq optimal +cursor motion +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.Nm cc +.Op Ar flags +.Ar files +.Fl lcurses +.Op Ar libraries +.Sh DESCRIPTION +These routines give the user a method of updating screens with reasonable +optimization. +They keep an image of the current screen, +and the user sets up an image of a new one. +Then the +.Fn refresh +tells the routines to make the current screen look like the new one. +In order to initialize the routines, the routine +.Fn initscr +must be called before any of the other routines that deal with windows and +screens are used. +The routine +.Fn endwin +should be called before exiting. +The routine +.Fn start_color +must be called before any of the other routines that deal with color are used. +.Sh FUNCTIONS +.Bl -column "subwin(win,lines,cols,begin_y,begin_x)" +.It Sy "Function Name" Ta Sy "Manual Page Name" +.It addch Ta Xr curses_addch 3 +.It addchnstr Ta Xr curses_addchstr 3 +.It addchstr Ta Xr curses_addchstr 3 +.It addnstr Ta Xr curses_addstr 3 +.It addstr Ta Xr curses_addstr 3 +.It assume_default_colors Ta Xr curses_default_colors 3 +.It attr_get Ta Xr curses_attributes 3 +.It attr_off Ta Xr curses_attributes 3 +.It attr_on Ta Xr curses_attributes 3 +.It attr_set Ta Xr curses_attributes 3 +.It attroff Ta Xr curses_attributes 3 +.It attron Ta Xr curses_attributes 3 +.It attrset Ta Xr curses_attributes 3 +.It beep Ta Xr curses_tty 3 +.It bkgd Ta Xr curses_background 3 +.It bkgdset Ta Xr curses_background 3 +.It border Ta Xr curses_border 3 +.It box Ta Xr curses_border 3 +.It can_change_color Ta Xr curses_color 3 +.It cbreak Ta Xr curses_tty 3 +.It chgat Ta Xr curses_chgat 3 +.It clear Ta Xr curses_clear 3 +.It clearok Ta Xr curses_clear 3 +.It clrtobot Ta Xr curses_clear 3 +.It clrtoeol Ta Xr curses_clear 3 +.It color_content Ta Xr curses_color 3 +.It color_set Ta Xr curses_attributes 3 +.It copywin Ta Xr curses_window 3 +.It curs_set Ta Xr curses_tty 3 +.It def_prog_mode Ta Xr curses_tty 3 +.It def_shell_mode Ta Xr curses_tty 3 +.It define_key Ta Xr curses_input 3 +.It delay_output Ta Xr curses_tty 3 +.It delch Ta Xr curses_delch 3 +.It deleteln Ta Xr curses_deleteln 3 +.It delscreen Ta Xr curses_screen 3 +.It delwin Ta Xr curses_window 3 +.It derwin Ta Xr curses_window 3 +.It doupdate Ta Xr curses_refresh 3 +.It dupwin Ta Xr curses_window 3 +.It echo Ta Xr curses_tty 3 +.It endwin Ta Xr curses_screen 3 +.It erase Ta Xr curses_clear 3 +.It erasechar Ta Xr curses_tty 3 +.It flash Ta Xr curses_tty 3 +.It flushinp Ta Xr curses_tty 3 +.It flushok Ta Xr curses_refresh 3 +.It fullname Ta Xr curses_termcap 3 +.It getattrs Ta Xr curses_attributes 3 +.It getbegx Ta Xr curses_cursor 3 +.It getbegy Ta Xr curses_cursor 3 +.It getbkgd Ta Xr curses_background 3 +.It getcap Ta Xr curses_termcap 3 +.It getch Ta Xr curses_input 3 +.It getcurx Ta Xr curses_cursor 3 +.It getcury Ta Xr curses_cursor 3 +.It getmaxx Ta Xr curses_cursor 3 +.It getmaxy Ta Xr curses_cursor 3 +.It getnstr Ta Xr curses_input 3 +.It getparx Ta Xr curses_cursor 3 +.It getpary Ta Xr curses_cursor 3 +.It getparyx Ta Xr curses_cursor 3 +.It getstr Ta Xr curses_input 3 +.It gettmode Ta Xr curses_tty 3 +.It getwin Ta Xr curses_fileio 3 +.It getyx Ta Xr curses_cursor 3 +.It has_colors Ta Xr curses_color 3 +.It has_ic Ta Xr curses_tty 3 +.It has_il Ta Xr curses_tty 3 +.It hline Ta Xr curses_line 3 +.It idcok Ta Xr curses_tty 3 +.It idlok Ta Xr curses_tty 3 +.It inch Ta Xr curses_inch 3 +.It inchnstr Ta Xr curses_inch 3 +.It inchstr Ta Xr curses_inch 3 +.It init_color Ta Xr curses_color 3 +.It init_pair Ta Xr curses_color 3 +.It initscr Ta Xr curses_screen 3 +.It innstr Ta Xr curses_inch 3 +.It insch Ta Xr curses_insertch 3 +.It insdelln Ta Xr curses_insdelln 3 +.It insertln Ta Xr curses_insertln 3 +.It instr Ta Xr curses_inch 3 +.It intrflush Ta Xr curses_tty 3 +.It is_linetouched Ta Xr curses_touch 3 +.It is_wintouched Ta Xr curses_touch 3 +.It isendwin Ta Xr curses_screen 3 +.It keyname Ta Xr curses_keyname 3 +.It keyok Ta Xr curses_input 3 +.It keypad Ta Xr curses_input 3 +.It killchar Ta Xr curses_tty 3 +.It leaveok Ta Xr curses_tty 3 +.It longname Ta Xr curses_termcap 3 +.It meta Ta Xr curses_tty 3 +.It move Ta Xr curses_cursor 3 +.It mvaddch Ta Xr curses_addch 3 +.It mvaddchnstr Ta Xr curses_addchstr 3 +.It mvaddchstr Ta Xr curses_addchstr 3 +.It mvaddnstr Ta Xr curses_addstr 3 +.It mvaddstr Ta Xr curses_addstr 3 +.It mvchgat Ta Xr curses_chgat 3 +.It mvcur Ta Xr curses_cursor 3 +.It mvderwin Ta Xr curses_window 3 +.It mvgetnstr Ta Xr curses_input 3 +.It mvgetstr Ta Xr curses_input 3 +.It mvhline Ta Xr curses_line 3 +.It mvinchstr Ta Xr curses_inch 3 +.It mvinchnstr Ta Xr curses_inch 3 +.It mvprintw Ta Xr curses_print 3 +.It mvscanw Ta Xr curses_scanw 3 +.It mvvline Ta Xr curses_line 3 +.It mvwaddch Ta Xr curses_addch 3 +.It mvwaddchnstr Ta Xr curses_addchstr 3 +.It mvwaddchstr Ta Xr curses_addchstr 3 +.It mvwaddnstr Ta Xr curses_addstr 3 +.It mvwaddstr Ta Xr curses_addstr 3 +.It mvwchgat Ta Xr curses_chgat 3 +.It mvwgetnstr Ta Xr curses_input 3 +.It mvwgetstr Ta Xr curses_input 3 +.It mvwhline Ta Xr curses_line 3 +.It mvwinchstr Ta Xr curses_inch 3 +.It mvwinchnstr Ta Xr curses_inch 3 +.It mvwprintw Ta Xr curses_print 3 +.It mvwscanw Ta Xr curses_scanw 3 +.It mvwvline Ta Xr curses_line 3 +.It napms Ta Xr curses_tty 3 +.It newpad Ta Xr curses_pad 3 +.It newterm Ta Xr curses_screen 3 +.It newwin Ta Xr curses_window 3 +.It \&nl Ta Xr curses_tty 3 +.It nocbreak Ta Xr curses_tty 3 +.It nodelay Ta Xr curses_input 3 +.It noecho Ta Xr curses_tty 3 +.It nonl Ta Xr curses_tty 3 +.It noqiflush Ta Xr curses_tty 3 +.It noraw Ta Xr curses_tty 3 +.It notimeout Ta Xr curses_input 3 +.It overlay Ta Xr curses_window 3 +.It overwrite Ta Xr curses_window 3 +.It pair_content Ta Xr curses_color 3 +.It pnoutrefresh Ta Xr curses_pad 3 +.It prefresh Ta Xr curses_pad 3 +.It printw Ta Xr curses_print 3 +.It putwin Ta Xr curses_fileio 3 +.It qiflush Ta Xr curses_tty 3 +.It raw Ta Xr curses_tty 3 +.It redrawwin Ta Xr curses_touch 3 +.It refresh Ta Xr curses_refresh 3 +.It reset_prog_mode Ta Xr curses_tty 3 +.It reset_shell_mode Ta Xr curses_tty 3 +.It resetty Ta Xr curses_tty 3 +.It resizeterm Ta Xr curses_screen 3 +.It savetty Ta Xr curses_tty 3 +.It scanw Ta Xr curses_scanw 3 +.It scrl Ta Xr curses_scroll 3 +.It scroll Ta Xr curses_scroll 3 +.It scrollok Ta Xr curses_scroll 3 +.It set_term Ta Xr curses_screen 3 +.It setscrreg Ta Xr curses_scroll 3 +.It setterm Ta Xr curses_screen 3 +.It standend Ta Xr curses_standout 3 +.It standout Ta Xr curses_standout 3 +.It start_color Ta Xr curses_color 3 +.It subpad Ta Xr curses_pad 3 +.It subwin Ta Xr curses_window 3 +.It termattrs Ta Xr curses_attributes 3 +.It timeout Ta Xr curses_input 3 +.It touchline Ta Xr curses_touch 3 +.It touchoverlap Ta Xr curses_touch 3 +.It touchwin Ta Xr curses_touch 3 +.It unctrl Ta Xr curses_print 3 +.It underend Ta Xr curses_underscore 3 +.It underscore Ta Xr curses_underscore 3 +.It ungetch Ta Xr curses_input 3 +.It untouchwin Ta Xr curses_touch 3 +.It use_default_colors Ta Xr curses_default_colors 3 +.It vline Ta Xr curses_line 3 +.It waddch Ta Xr curses_addch 3 +.It waddchnstr Ta Xr curses_addchstr 3 +.It waddchstr Ta Xr curses_addchstr 3 +.It waddnstr Ta Xr curses_addstr 3 +.It waddstr Ta Xr curses_addstr 3 +.It wattr_get Ta Xr curses_attributes 3 +.It wattr_off Ta Xr curses_attributes 3 +.It wattr_on Ta Xr curses_attributes 3 +.It wattr_set Ta Xr curses_attributes 3 +.It wattroff Ta Xr curses_attributes 3 +.It wattron Ta Xr curses_attributes 3 +.It wattrset Ta Xr curses_attributes 3 +.It wbkgd Ta Xr curses_background 3 +.It wbkgdset Ta Xr curses_background 3 +.It wborder Ta Xr curses_border 3 +.It wchgat Ta Xr curses_chgat 3 +.It wclear Ta Xr curses_clear 3 +.It wclrtobot Ta Xr curses_clear 3 +.It wclrtoeol Ta Xr curses_clear 3 +.It wcolor_set Ta Xr curses_attributes 3 +.It wdelch Ta Xr curses_delch 3 +.It wdeleteln Ta Xr curses_deleteln 3 +.It werase Ta Xr curses_clear 3 +.It wgetch Ta Xr curses_input 3 +.It wgetnstr Ta Xr curses_input 3 +.It wgetstr Ta Xr curses_input 3 +.It whline Ta Xr curses_line 3 +.It winch Ta Xr curses_inch 3 +.It winchnstr Ta Xr curses_inch 3 +.It winchstr Ta Xr curses_inch 3 +.It winnstr Ta Xr curses_inch 3 +.It winsch Ta Xr curses_insertch 3 +.It winsdelln Ta Xr curses_insdelln 3 +.It winsertln Ta Xr curses_insertln 3 +.It winstr Ta Xr curses_inch 3 +.It wmove Ta Xr curses_cursor 3 +.It wnoutrefresh Ta Xr curses_refresh 3 +.It wprintw Ta Xr curses_print 3 +.It wredrawln Ta Xr curses_touch 3 +.It wrefresh Ta Xr curses_refresh 3 +.It wresize Ta Xr curses_window 3 +.It wscanw Ta Xr curses_scanw 3 +.It wscrl Ta Xr curses_scroll 3 +.It wsetscrreg Ta Xr curses_scroll 3 +.It wstandend Ta Xr curses_standout 3 +.It wstandout Ta Xr curses_standout 3 +.It wtimeout Ta Xr curses_input 3 +.It wtouchln Ta Xr curses_touch 3 +.It wunderend Ta Xr curses_underscore 3 +.It wunderscore Ta Xr curses_underscore 3 +.It wvline Ta Xr curses_line 3 +.El +.Sh ENVIRONMENT +.Bl -tag -width CURSES_TRACE_MASK +.It COLUMNS +The number of columns in the terminal if set. +This is usually automatically configured by querying the kernel. +.It CURSES_TRACE_MASK +An integer mask that enables specific debugging traces. +Enabled only in the debug build of curses. +.It CURSES_TRACE_FILE +A file where to output debugging information. +Enabled only in the debug build of curses. +.It ESCDELAY +The maximum delay in milliseconds between characters in multi-character +keystrokes (such are arrow keys) where the adjacent characters are considered +part of the same multi-character sequence. +The default is 300 milliseconds. +.It LINES +The number of lines in the terminal if set. +is usually automatically configured by querying the kernel. +.It TERM +The terminal type of the current terminal. +.El +.Sh SEE ALSO +.Xr ioctl 2 , +.Xr getenv 3 , +.Xr tty 4 , +.Xr termcap 5 +.Rs +.%T Screen Updating and Cursor Movement Optimization: A Library Package +.%A Ken Arnold +.Re +.Sh STANDARDS +The +.Nx +Curses library complies with the X/Open Curses specification, part of the +Single Unix Specification. +.Sh HISTORY +The Curses package appeared in +.Bx 4.0 . +.Sh AUTHORS +.An Ken Arnold diff --git a/lib/libcurses/curses.c b/lib/libcurses/curses.c new file mode 100644 index 000000000..7e1e8a84e --- /dev/null +++ b/lib/libcurses/curses.c @@ -0,0 +1,160 @@ +/* $NetBSD: curses.c,v 1.24 2010/02/03 15:34:40 roy Exp $ */ + +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)curses.c 8.3 (Berkeley) 5/4/94"; +#else +__RCSID("$NetBSD: curses.c,v 1.24 2010/02/03 15:34:40 roy Exp $"); +#endif +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +/* Private. */ +int __echoit = 1; /* If stty indicates ECHO. */ +int __pfast; +int __rawmode = 0; /* If stty indicates RAW mode. */ +int __noqch = 0; + /* If terminal doesn't have + * insert/delete line capabilities + * for quick change on refresh. + */ +char __CA; + +/* + * Public. + * + * XXX + * UPPERCASE isn't used by libcurses, and is left for backward + * compatibility only. + */ +WINDOW *curscr; /* Current screen. */ +WINDOW *stdscr; /* Standard screen. */ +WINDOW *__virtscr; /* Virtual screen (for doupdate()). */ +SCREEN *_cursesi_screen; /* the current screen we are using */ +int COLS; /* Columns on the screen. */ +int LINES; /* Lines on the screen. */ +int COLORS; /* Maximum colors on the screen */ +int COLOR_PAIRS = 0; /* Maximum color pairs on the screen */ +int My_term = 0; /* Use Def_term regardless. */ +const char *Def_term = "unknown"; /* Default terminal type. */ +char __GT; /* Gtty indicates tabs. */ +char __NONL; /* Term can't hack LF doing a CR. */ +char __UPPERCASE; /* Terminal is uppercase only. */ + +#ifdef HAVE_WCHAR +/* + * Copy the non-spacing character list (src_nsp) to the given character, + * allocate or free storage as required. + */ +int +_cursesi_copy_nsp(nschar_t *src_nsp, struct __ldata *ch) +{ + nschar_t *np, *tnp, *pnp; + + pnp = NULL; + np = src_nsp; + if (np) { + tnp = ch->nsp; + while (np) { + if (tnp) { + tnp->ch = np->ch; + pnp = tnp; + tnp = tnp->next; + } else { + tnp = (nschar_t *)malloc(sizeof(nschar_t)); + if (!tnp) + return ERR; + tnp->ch = np->ch; + pnp->next = tnp; + tnp->next = NULL; + pnp = tnp; + tnp = NULL; + } + np = np->next; + } + np = tnp; + if (np) { + pnp->next = NULL; + __cursesi_free_nsp(np); + } + } else { + if (ch->nsp) { + __cursesi_free_nsp(ch->nsp); + ch->nsp = NULL; + } + } + + return OK; +} + +/* + * Free the storage associated with a non-spacing character - traverse the + * linked list until all storage is done. + */ +void +__cursesi_free_nsp(nschar_t *inp) +{ + nschar_t *tnp, *np; + + np = inp; + if (np) { + while (np) { + tnp = np->next; + free(np); + np = tnp; + } + } +} + +/* + * Traverse all the cells in the given window free'ing the non-spacing + * character storage. + */ +void +__cursesi_win_free_nsp(WINDOW *win) +{ + int i, j; + __LDATA *sp; + + for (i = 0; i < win->maxy; i++) { + for (sp = win->alines[i]->line, j = 0; j < win->maxx; + j++, sp++) { + __cursesi_free_nsp(sp->nsp); + } + } +} + +#endif diff --git a/lib/libcurses/curses.h b/lib/libcurses/curses.h new file mode 100644 index 000000000..b7b607c0d --- /dev/null +++ b/lib/libcurses/curses.h @@ -0,0 +1,933 @@ +/* $NetBSD: curses.h,v 1.101 2010/12/16 17:42:28 wiz Exp $ */ + +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)curses.h 8.5 (Berkeley) 4/29/95 + * + * Modified by Ruibiao Qiu 2005 + * to add wide-character support + * - Add complex character structure (cchar_t) + * - Add definitions of wide-character routines + * - Add KEY_CODE_YES + */ + +#ifndef _CURSES_H_ +#define _CURSES_H_ + +#include +#include +#include + +#include +#include + +/* + * attr_t must be the same size as wchar_t (see ) to avoid padding + * in __LDATA. + */ +typedef wchar_t chtype; +typedef wchar_t attr_t; + +#if !defined(HAVE_WCHAR) && !defined(DISABLE_WCHAR) +#define HAVE_WCHAR 1 +#endif + +#ifdef HAVE_WCHAR +/* + * The complex character structure required by the X/Open reference and used + * in * functions such as in_wchstr(). It includes a string of up to 8 wide + * characters and its length, an attribute, and a color-pair. + */ +#define CURSES_CCHAR_MAX 8 +#define CCHARW_MAX 5 +typedef struct { + attr_t attributes; /* character attributes */ + unsigned elements; /* number of wide char in + vals[] */ + wchar_t vals[CURSES_CCHAR_MAX]; /* wide chars including + non-spacing */ +} cchar_t; +#else +typedef chtype cchar_t; +#endif /* HAVE_WCHAR */ + +#ifndef TRUE +#define TRUE (/*CONSTCOND*/1) +#endif +#ifndef FALSE +#define FALSE (/*CONSTCOND*/0) +#endif + +#ifndef _CURSES_PRIVATE + +#define _puts(s) tputs(s, 0, __cputchar) +#define _putchar(c) __cputchar(c) + +/* Old-style terminal modes access. */ +#define crmode() cbreak() +#define nocrmode() nocbreak() +#endif /* _CURSES_PRIVATE */ + + +/* symbols for values returned by getch in keypad mode */ +#define KEY_MIN 0x101 /* minimum extended key value */ +#define KEY_BREAK 0x101 /* break key */ +#define KEY_DOWN 0x102 /* down arrow */ +#define KEY_UP 0x103 /* up arrow */ +#define KEY_LEFT 0x104 /* left arrow */ +#define KEY_RIGHT 0x105 /* right arrow*/ +#define KEY_HOME 0x106 /* home key */ +#define KEY_BACKSPACE 0x107 /* Backspace */ + +/* First function key (block of 64 follow) */ +#define KEY_F0 0x108 +/* Function defining other function key values*/ +#define KEY_F(n) (KEY_F0+(n)) + +#define KEY_DL 0x148 /* Delete Line */ +#define KEY_IL 0x149 /* Insert Line*/ +#define KEY_DC 0x14A /* Delete Character */ +#define KEY_IC 0x14B /* Insert Character */ +#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 one line forward */ +#define KEY_SR 0x151 /* Scroll one line back */ +#define KEY_NPAGE 0x152 /* Next Page */ +#define KEY_PPAGE 0x153 /* Prev 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 */ +#define KEY_SRESET 0x158 /* Soft Reset */ +#define KEY_RESET 0x159 /* Hard Reset */ +#define KEY_PRINT 0x15A /* Print */ +#define KEY_LL 0x15B /* Home Down */ + +/* + * "Keypad" keys arranged like this: + * + * A1 up A3 + * left B2 right + * C1 down C3 + * + */ +#define KEY_A1 0x15C /* Keypad upper left */ +#define KEY_A3 0x15D /* Keypad upper right */ +#define KEY_B2 0x15E /* Keypad centre key */ +#define KEY_C1 0x15F /* Keypad lower left */ +#define KEY_C3 0x160 /* Keypad lower right */ + +#define KEY_BTAB 0x161 /* Back Tab */ +#define KEY_BEG 0x162 /* Begin key */ +#define KEY_CANCEL 0x163 /* Cancel key */ +#define KEY_CLOSE 0x164 /* Close Key */ +#define KEY_COMMAND 0x165 /* Command Key */ +#define KEY_COPY 0x166 /* Copy key */ +#define KEY_CREATE 0x167 /* Create key */ +#define KEY_END 0x168 /* End key */ +#define KEY_EXIT 0x169 /* Exit key */ +#define KEY_FIND 0x16A /* Find key */ +#define KEY_HELP 0x16B /* Help key */ +#define KEY_MARK 0x16C /* Mark key */ +#define KEY_MESSAGE 0x16D /* Message key */ +#define KEY_MOVE 0x16E /* Move key */ +#define KEY_NEXT 0x16F /* Next Object key */ +#define KEY_OPEN 0x170 /* Open key */ +#define KEY_OPTIONS 0x171 /* Options key */ +#define KEY_PREVIOUS 0x172 /* Previous Object key */ +#define KEY_REDO 0x173 /* Redo key */ +#define KEY_REFERENCE 0x174 /* Ref Key */ +#define KEY_REFRESH 0x175 /* Refresh key */ +#define KEY_REPLACE 0x176 /* Replace key */ +#define KEY_RESTART 0x177 /* Restart key */ +#define KEY_RESUME 0x178 /* Resume key */ +#define KEY_SAVE 0x179 /* Save key */ +#define KEY_SBEG 0x17A /* Shift begin key */ +#define KEY_SCANCEL 0x17B /* Shift Cancel key */ +#define KEY_SCOMMAND 0x17C /* Shift Command key */ +#define KEY_SCOPY 0x17D /* Shift Copy key */ +#define KEY_SCREATE 0x17E /* Shift Create key */ +#define KEY_SDC 0x17F /* Shift Delete Character */ +#define KEY_SDL 0x180 /* Shift Delete Line */ +#define KEY_SELECT 0x181 /* Select key */ +#define KEY_SEND 0x182 /* Send key */ +#define KEY_SEOL 0x183 /* Shift Clear Line key */ +#define KEY_SEXIT 0x184 /* Shift Exit key */ +#define KEY_SFIND 0x185 /* Shift Find key */ +#define KEY_SHELP 0x186 /* Shift Help key */ +#define KEY_SHOME 0x187 /* Shift Home key */ +#define KEY_SIC 0x188 /* Shift Input key */ +#define KEY_SLEFT 0x189 /* Shift Left Arrow key */ +#define KEY_SMESSAGE 0x18A /* Shift Message key */ +#define KEY_SMOVE 0x18B /* Shift Move key */ +#define KEY_SNEXT 0x18C /* Shift Next key */ +#define KEY_SOPTIONS 0x18D /* Shift Options key */ +#define KEY_SPREVIOUS 0x18E /* Shift Previous key */ +#define KEY_SPRINT 0x18F /* Shift Print key */ +#define KEY_SREDO 0x190 /* Shift Redo key */ +#define KEY_SREPLACE 0x191 /* Shift Replace key */ +#define KEY_SRIGHT 0x192 /* Shift Right Arrow key */ +#define KEY_SRSUME 0x193 /* Shift Resume key */ +#define KEY_SSAVE 0x194 /* Shift Save key */ +#define KEY_SSUSPEND 0x195 /* Shift Suspend key */ +#define KEY_SUNDO 0x196 /* Shift Undo key */ +#define KEY_SUSPEND 0x197 /* Suspend key */ +#define KEY_UNDO 0x198 /* Undo key */ +#define KEY_MOUSE 0x199 /* Mouse event has occurred */ +#define KEY_RESIZE 0x200 /* Resize event has occurred */ +#define KEY_MAX 0x240 /* maximum extended key value */ +#define KEY_CODE_YES 0x241 /* A function key pressed */ + +#include + +/* + * A window an array of __LINE structures pointed to by the 'lines' pointer. + * A line is an array of __LDATA structures pointed to by the 'line' pointer. + */ + +/* + * Definitions for characters and attributes in __LDATA + */ +#define __CHARTEXT 0x000000ff /* bits for 8-bit characters */ +#define __NORMAL 0x00000000 /* Added characters are normal. */ +#define __STANDOUT 0x00000100 /* Added characters are standout. */ +#define __UNDERSCORE 0x00000200 /* Added characters are underscored. */ +#define __REVERSE 0x00000400 /* Added characters are reverse + video. */ +#define __BLINK 0x00000800 /* Added characters are blinking. */ +#define __DIM 0x00001000 /* Added characters are dim. */ +#define __BOLD 0x00002000 /* Added characters are bold. */ +#define __BLANK 0x00004000 /* Added characters are blanked. */ +#define __PROTECT 0x00008000 /* Added characters are protected. */ +#define __ALTCHARSET 0x00010000 /* Added characters are ACS */ +#define __COLOR 0x03fe0000 /* Color bits */ +#define __ATTRIBUTES 0x03ffff00 /* All 8-bit attribute bits */ +#ifdef HAVE_WCHAR +#define __ACS_IS_WACS 0x04000000 /* internal: use wacs table for ACS char */ +#endif + +typedef struct __ldata __LDATA; +typedef struct __line __LINE; +typedef struct __window WINDOW; +typedef struct __screen SCREEN; + +/* + * Attribute definitions + */ +#define A_NORMAL __NORMAL +#define A_STANDOUT __STANDOUT +#define A_UNDERLINE __UNDERSCORE +#define A_REVERSE __REVERSE +#define A_BLINK __BLINK +#define A_DIM __DIM +#define A_BOLD __BOLD +#define A_BLANK __BLANK +#define A_INVIS __BLANK +#define A_PROTECT __PROTECT +#define A_ALTCHARSET __ALTCHARSET +#define A_ATTRIBUTES __ATTRIBUTES +#define A_CHARTEXT __CHARTEXT +#define A_COLOR __COLOR + +#ifdef HAVE_WCHAR +#define WA_ATTRIBUTES 0x03ffffff /* Wide character attributes mask */ +#define WA_STANDOUT __STANDOUT /* Best highlighting mode */ +#define WA_UNDERLINE __UNDERSCORE /* Underlining */ +#define WA_REVERSE __REVERSE /* Reverse video */ +#define WA_BLINK __BLINK /* Blinking */ +#define WA_DIM __DIM /* Half bright */ +#define WA_BOLD __BOLD /* Extra bright or bold */ +#define WA_INVIS __BLANK /* Invisible */ +#define WA_PROTECT __PROTECT /* Protected */ +#define WA_ALTCHARSET __ALTCHARSET /* Alternate character set */ +#define WA_LOW 0x00000002 /* Low highlight */ +#define WA_TOP 0x00000004 /* Top highlight */ +#define WA_HORIZONTAL 0x00000008 /* Horizontal highlight */ +#define WA_VERTICAL 0x00000010 /* Vertical highlight */ +#define WA_LEFT 0x00000020 /* Left highlight */ +#define WA_RIGHT 0x00000040 /* Right highlight */ +#endif /* HAVE_WCHAR */ + +/* + * Alternate character set definitions + */ + +#define NUM_ACS 128 + +extern chtype _acs_char[NUM_ACS]; +#ifdef __cplusplus +#define __UC_CAST(a) static_cast(a) +#else +#define __UC_CAST(a) (unsigned char)(a) +#endif + +/* Standard definitions */ +#define ACS_RARROW _acs_char[__UC_CAST('+')] +#define ACS_LARROW _acs_char[__UC_CAST(',')] +#define ACS_UARROW _acs_char[__UC_CAST('-')] +#define ACS_DARROW _acs_char[__UC_CAST('.')] +#define ACS_BLOCK _acs_char[__UC_CAST('0')] +#define ACS_DIAMOND _acs_char[__UC_CAST('`')] +#define ACS_CKBOARD _acs_char[__UC_CAST('a')] +#define ACS_DEGREE _acs_char[__UC_CAST('f')] +#define ACS_PLMINUS _acs_char[__UC_CAST('g')] +#define ACS_BOARD _acs_char[__UC_CAST('h')] +#define ACS_LANTERN _acs_char[__UC_CAST('i')] +#define ACS_LRCORNER _acs_char[__UC_CAST('j')] +#define ACS_URCORNER _acs_char[__UC_CAST('k')] +#define ACS_ULCORNER _acs_char[__UC_CAST('l')] +#define ACS_LLCORNER _acs_char[__UC_CAST('m')] +#define ACS_PLUS _acs_char[__UC_CAST('n')] +#define ACS_HLINE _acs_char[__UC_CAST('q')] +#define ACS_S1 _acs_char[__UC_CAST('o')] +#define ACS_S9 _acs_char[__UC_CAST('s')] +#define ACS_LTEE _acs_char[__UC_CAST('t')] +#define ACS_RTEE _acs_char[__UC_CAST('u')] +#define ACS_BTEE _acs_char[__UC_CAST('v')] +#define ACS_TTEE _acs_char[__UC_CAST('w')] +#define ACS_VLINE _acs_char[__UC_CAST('x')] +#define ACS_BULLET _acs_char[__UC_CAST('~')] + +/* Extensions */ +#define ACS_S3 _acs_char[__UC_CAST('p')] +#define ACS_S7 _acs_char[__UC_CAST('r')] +#define ACS_LEQUAL _acs_char[__UC_CAST('y')] +#define ACS_GEQUAL _acs_char[__UC_CAST('z')] +#define ACS_PI _acs_char[__UC_CAST('{')] +#define ACS_NEQUAL _acs_char[__UC_CAST('|')] +#define ACS_STERLING _acs_char[__UC_CAST('}')] + +#ifdef HAVE_WCHAR +extern cchar_t _wacs_char[NUM_ACS]; + +#define WACS_RARROW (&_wacs_char[(unsigned char)'+']) +#define WACS_LARROW (&_wacs_char[(unsigned char)',']) +#define WACS_UARROW (&_wacs_char[(unsigned char)'-']) +#define WACS_DARROW (&_wacs_char[(unsigned char)'.']) +#define WACS_BLOCK (&_wacs_char[(unsigned char)'0']) +#define WACS_DIAMOND (&_wacs_char[(unsigned char)'`']) +#define WACS_CKBOARD (&_wacs_char[(unsigned char)'a']) +#define WACS_DEGREE (&_wacs_char[(unsigned char)'f']) +#define WACS_PLMINUS (&_wacs_char[(unsigned char)'g']) +#define WACS_BOARD (&_wacs_char[(unsigned char)'h']) +#define WACS_LANTERN (&_wacs_char[(unsigned char)'i']) +#define WACS_LRCORNER (&_wacs_char[(unsigned char)'j']) +#define WACS_URCORNER (&_wacs_char[(unsigned char)'k']) +#define WACS_ULCORNER (&_wacs_char[(unsigned char)'l']) +#define WACS_LLCORNER (&_wacs_char[(unsigned char)'m']) +#define WACS_PLUS (&_wacs_char[(unsigned char)'n']) +#define WACS_HLINE (&_wacs_char[(unsigned char)'q']) +#define WACS_S1 (&_wacs_char[(unsigned char)'o']) +#define WACS_S9 (&_wacs_char[(unsigned char)'s']) +#define WACS_LTEE (&_wacs_char[(unsigned char)'t']) +#define WACS_RTEE (&_wacs_char[(unsigned char)'u']) +#define WACS_BTEE (&_wacs_char[(unsigned char)'v']) +#define WACS_TTEE (&_wacs_char[(unsigned char)'w']) +#define WACS_VLINE (&_wacs_char[(unsigned char)'x']) +#define WACS_BULLET (&_wacs_char[(unsigned char)'~']) +#define WACS_S3 (&_wacs_char[(unsigned char)'p']) +#define WACS_S7 (&_wacs_char[(unsigned char)'r']) +#define WACS_LEQUAL (&_wacs_char[(unsigned char)'y']) +#define WACS_GEQUAL (&_wacs_char[(unsigned char)'z']) +#define WACS_PI (&_wacs_char[(unsigned char)'{']) +#define WACS_NEQUAL (&_wacs_char[(unsigned char)'|']) +#define WACS_STERLING (&_wacs_char[(unsigned char)'}']) +#endif /* HAVE_WCHAR */ + +/* System V compatibility */ +#define ACS_SBBS ACS_LRCORNER +#define ACS_BBSS ACS_URCORNER +#define ACS_BSSB ACS_ULCORNER +#define ACS_SSBB ACS_LLCORNER +#define ACS_SSSS ACS_PLUS +#define ACS_BSBS ACS_HLINE +#define ACS_SSSB ACS_LTEE +#define ACS_SBSS ACS_RTEE +#define ACS_SSBS ACS_BTEE +#define ACS_BSSS ACS_TTEE +#define ACS_SBSB ACS_VLINE +#define _acs_map _acs_char + +/* + * Color definitions (ANSI color numbers) + */ + +#define COLOR_BLACK 0x00 +#define COLOR_RED 0x01 +#define COLOR_GREEN 0x02 +#define COLOR_YELLOW 0x03 +#define COLOR_BLUE 0x04 +#define COLOR_MAGENTA 0x05 +#define COLOR_CYAN 0x06 +#define COLOR_WHITE 0x07 + +#ifdef __cplusplus +#define __UINT32_CAST(a) static_cast(a) +#else +#define __UINT32_CAST(a) (u_int32_t)(a) +#endif +#define COLOR_PAIR(n) (((__UINT32_CAST(n)) << 17) & A_COLOR) +#define PAIR_NUMBER(n) (((__UINT32_CAST(n)) & A_COLOR) >> 17) + +/* Curses external declarations. */ +extern WINDOW *curscr; /* Current screen. */ +extern WINDOW *stdscr; /* Standard screen. */ + +extern int __tcaction; /* If terminal hardware set. */ + +extern int COLS; /* Columns on the screen. */ +extern int LINES; /* Lines on the screen. */ +extern int COLORS; /* Max colors on the screen. */ +extern int COLOR_PAIRS; /* Max color pairs on the screen. */ + +extern int ESCDELAY; /* Delay between keys in esc seq's. */ + +#ifndef OK +#define ERR (-1) /* Error return. */ +#define OK (0) /* Success return. */ +#endif + +/* + * The following have, traditionally, been macros but X/Open say they + * need to be functions. Keep the old macros for debugging. + */ +#ifdef _CURSES_USE_MACROS +/* Standard screen pseudo functions. */ +#define addbytes(s, n) __waddbytes(stdscr, s, n, 0) +#define addch(ch) waddch(stdscr, ch) +#define addchnstr(s) waddchnstr(stdscr, s, n) +#define addchstr(s) waddchnstr(stdscr, s, -1) +#define addnstr(s, n) waddnstr(stdscr, s, n) +#define addstr(s) waddnstr(stdscr, s, -1) +#define attr_get(a, p, o) wattr_get(stdscr, a, p, o) +#define attr_off(a, o) wattr_off(stdscr, a, o) +#define attr_on(a, o) wattr_on(stdscr, a, o) +#define attr_set(a, p, o) wattr_set(stdscr, a, p, o) +#define attroff(attr) wattroff(stdscr, attr) +#define attron(attr) wattron(stdscr, attr) +#define attrset(attr) wattrset(stdscr, attr) +#define bkgd(ch) wbkgd(stdscr, ch) +#define bkgdset(ch) wbkgdset(stdscr, ch) +#define border(l, r, t, b, tl, tr, bl, br) \ + wborder(stdscr, l, r, t, b, tl, tr, bl, br) +#define clear() wclear(stdscr) +#define clrtobot() wclrtobot(stdscr) +#define clrtoeol() wclrtoeol(stdscr) +#define color_set(c, o) wcolor_set(stdscr, c, o) +#define delch() wdelch(stdscr) +#define deleteln() wdeleteln(stdscr) +#define echochar(c) wechochar(stdscr, c) +#define erase() werase(stdscr) +#define getch() wgetch(stdscr) +#define getnstr(s, n) wgetnstr(stdscr, s, n) +#define getstr(s) wgetstr(stdscr, s) +#define inch() winch(stdscr) +#define inchnstr(c) winchnstr(stdscr, c) +#define inchstr(c) winchstr(stdscr, c) +#define innstr(s, n) winnstr(stdscr, s, n) +#define insch(ch) winsch(stdscr, ch) +#define insdelln(n) winsdelln(stdscr, n) +#define insertln() winsertln(stdscr) +#define instr(s) winstr(stdscr, s) +#define move(y, x) wmove(stdscr, y, x) +#define refresh() wrefresh(stdscr) +#define scrl(n) wscrl(stdscr, n) +#define setscrreg(t, b) wsetscrreg(stdscr, t, b) +#define standend() wstandend(stdscr) +#define standout() wstandout(stdscr) +#define timeout(delay) wtimeout(stdscr, delay) +#define underscore() wunderscore(stdscr) +#define underend() wunderend(stdscr) +#define waddbytes(w, s, n) __waddbytes(w, s, n, 0) +#define waddstr(w, s) waddnstr(w, s, -1) + +/* Standard screen plus movement pseudo functions. */ +#define mvaddbytes(y, x, s, n) mvwaddbytes(stdscr, y, x, s, n) +#define mvaddch(y, x, ch) mvwaddch(stdscr, y, x, ch) +#define mvaddchnstr(y, x, s, n) mvwaddchnstr(stdscr, y, x, s, n) +#define mvaddchstr(y, x, s) mvwaddchstr(stdscr, y, x, s) +#define mvaddnstr(y, x, s, n) mvwaddnstr(stdscr, y, x, s, n) +#define mvaddstr(y, x, s) mvwaddstr(stdscr, y, x, s) +#define mvdelch(y, x) mvwdelch(stdscr, y, x) +#define mvgetch(y, x) mvwgetch(stdscr, y, x) +#define mvgetnstr(y, x, s) mvwgetnstr(stdscr, y, x, s, n) +#define mvgetstr(y, x, s) mvwgetstr(stdscr, y, x, s) +#define mvinch(y, x) mvwinch(stdscr, y, x) +#define mvinchnstr(y, x, c, n) mvwinchnstr(stdscr, y, x, c, n) +#define mvinchstr(y, x, c) mvwinchstr(stdscr, y, x, c) +#define mvinnstr(y, x, s, n) mvwinnstr(stdscr, y, x, s, n) +#define mvinsch(y, x, c) mvwinsch(stdscr, y, x, c) +#define mvinstr(y, x, s) mvwinstr(stdscr, y, x, s) +#define mvwaddbytes(w, y, x, s, n) \ + (wmove(w, y, x) == ERR ? ERR : __waddbytes(w, s, n, 0)) +#define mvwaddch(w, y, x, ch) \ + (wmove(w, y, x) == ERR ? ERR : waddch(w, ch)) +#define mvwaddchnstr(w, y, x, s, n) \ + (wmove(w, y, x) == ERR ? ERR : waddchnstr(w, s, n)) +#define mvwaddchstr(w, y, x, s) \ + (wmove(w, y, x) == ERR ? ERR : waddchnstr(w, s, -1)) +#define mvwaddnstr(w, y, x, s, n) \ + (wmove(w, y, x) == ERR ? ERR : waddnstr(w, s, n)) +#define mvwaddstr(w, y, x, s) \ + (wmove(w, y, x) == ERR ? ERR : waddnstr(w, s, -1)) +#define mvwdelch(w, y, x) \ + (wmove(w, y, x) == ERR ? ERR : wdelch(w)) +#define mvwgetch(w, y, x) \ + (wmove(w, y, x) == ERR ? ERR : wgetch(w)) +#define mvwgetnstr(w, y, x, s, n) \ + (wmove(w, y, x) == ERR ? ERR : wgetnstr(w, s, n)) +#define mvwgetstr(w, y, x, s) \ + (wmove(w, y, x) == ERR ? ERR : wgetstr(w, s)) +#define mvwinch(w, y, x) \ + (wmove(w, y, x) == ERR ? ERR : winch(w)) +#define mvwinchnstr(w, y, x, c, n) \ + (wmove(w, y, x) == ERR ? ERR : winchnstr(w, c, n)) +#define mvwinchstr(w, y, x, s) \ + (wmove(w, y, x) == ERR ? ERR : winchstr(w, c)) +#define mvwinnstr(w, y, x, s, n) \ + (wmove(w, y, x) == ERR ? ERR : winnstr(w, s, n)) +#define mvwinsch(w, y, x, c) \ + (wmove(w, y, x) == ERR ? ERR : winsch(w, c)) +#define mvwinstr(w, y, x, s) \ + (wmove(w, y, x) == ERR ? ERR : winstr(w, s)) + +/* Miscellaneous. */ +#define noqiflush() intrflush(stdscr, FALSE) +#define qiflush() intrflush(stdscr, TRUE) + +#else +/* Use functions not macros... */ +__BEGIN_DECLS +int addbytes(const char *, int); +int addch(chtype); +int addchnstr(const chtype *, int); +int addchstr(const chtype *); +int addnstr(const char *, int); +int addstr(const char *); +int attr_get(attr_t *, short *, void *); +int attr_off(attr_t, void *); +int attr_on(attr_t, void *); +int attr_set(attr_t, short, void *); +int attroff(int); +int attron(int); +int attrset(int); +int bkgd(chtype); +void bkgdset(chtype); +int border(chtype, chtype, chtype, chtype, + chtype, chtype, chtype, chtype); +int clear(void); +int clrtobot(void); +int clrtoeol(void); +int color_set(short, void *); +int delch(void); +int deleteln(void); +int echochar(const chtype); +int erase(void); +int getch(void); +int getnstr(char *, int); +int getstr(char *); +chtype inch(void); +int inchnstr(chtype *, int); +int inchstr(chtype *); +int innstr(char *, int); +int insch(chtype); +int insdelln(int); +int insertln(void); +int instr(char *); +int move(int, int); +int refresh(void); +int scrl(int); +int setscrreg(int, int); +int standend(void); +int standout(void); +void timeout(int); +int underscore(void); +int underend(void); +int waddbytes(WINDOW *, const char *, int); +int waddstr(WINDOW *, const char *); + +/* Standard screen plus movement functions. */ +int mvaddbytes(int, int, const char *, int); +int mvaddch(int, int, chtype); +int mvaddchnstr(int, int, const chtype *, int); +int mvaddchstr(int, int, const chtype *); +int mvaddnstr(int, int, const char *, int); +int mvaddstr(int, int, const char *); +int mvdelch(int, int); +int mvgetch(int, int); +int mvgetnstr(int, int, char *, int); +int mvgetstr(int, int, char *); +chtype mvinch(int, int); +int mvinchnstr(int, int, chtype *, int); +int mvinchstr(int, int, chtype *); +int mvinnstr(int, int, char *, int); +int mvinsch(int, int, chtype); +int mvinstr(int, int, char *); + +int mvwaddbytes(WINDOW *, int, int, const char *, int); +int mvwaddch(WINDOW *, int, int, chtype); +int mvwaddchnstr(WINDOW *, int, int, const chtype *, int); +int mvwaddchstr(WINDOW *, int, int, const chtype *); +int mvwaddnstr(WINDOW *, int, int, const char *, int); +int mvwaddstr(WINDOW *, int, int, const char *); +int mvwdelch(WINDOW *, int, int); +int mvwgetch(WINDOW *, int, int); +int mvwgetnstr(WINDOW *, int, int, char *, int); +int mvwgetstr(WINDOW *, int, int, char *); +chtype mvwinch(WINDOW *, int, int); +int mvwinsch(WINDOW *, int, int, chtype); +__END_DECLS +#endif /* _CURSES_USE_MACROS */ + +#define getyx(w, y, x) (y) = getcury(w), (x) = getcurx(w) +#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) + +/* Public function prototypes. */ +__BEGIN_DECLS +int assume_default_colors(short, short); +int baudrate(void); +int beep(void); +int box(WINDOW *, chtype, chtype); +bool can_change_color(void); +int cbreak(void); +int clearok(WINDOW *, bool); +int color_content(short, short *, short *, short *); +int copywin(const WINDOW *, WINDOW *, int, int, int, int, int, int, int); +int curs_set(int); +int def_prog_mode(void); +int def_shell_mode(void); +int define_key(char *, int); +int delay_output(int); +void delscreen(SCREEN *); +int delwin(WINDOW *); +WINDOW *derwin(WINDOW *, int, int, int, int); +WINDOW *dupwin(WINDOW *); +int doupdate(void); +int echo(void); +int endwin(void); +char erasechar(void); +int flash(void); +int flushinp(void); +int flushok(WINDOW *, bool); +char *fullname(const char *, char *); +chtype getattrs(WINDOW *); +chtype getbkgd(WINDOW *); +char *getcap(char *); +int getcury(WINDOW *); +int getcurx(WINDOW *); +int getbegy(WINDOW *); +int getbegx(WINDOW *); +int getmaxy(WINDOW *); +int getmaxx(WINDOW *); +int getpary(WINDOW *); +int getparx(WINDOW *); +int gettmode(void); +WINDOW *getwin(FILE *); +int halfdelay(int); +bool has_colors(void); +bool has_ic(void); +bool has_il(void); +int hline(chtype, int); +int idcok(WINDOW *, bool); +int idlok(WINDOW *, bool); +int init_color(short, short, short, short); +int init_pair(short, short, short); +WINDOW *initscr(void); +int intrflush(WINDOW *, bool); +bool isendwin(void); +bool is_linetouched(WINDOW *, int); +bool is_wintouched(WINDOW *); +int keyok(int, bool); +int keypad(WINDOW *, bool); +char *keyname(int); +char killchar(void); +int leaveok(WINDOW *, bool); +char *longname(void); +int meta(WINDOW *, bool); +int mvcur(int, int, int, int); +int mvderwin(WINDOW *, int, int); +int mvhline(int, int, chtype, int); +int mvprintw(int, int, const char *, ...) __printflike(3, 4); +int mvscanw(int, int, const char *, ...) __scanflike(3, 4); +int mvvline(int, int, chtype, int); +int mvwhline(WINDOW *, int, int, chtype, int); +int mvwvline(WINDOW *, int, int, chtype, int); +int mvwin(WINDOW *, int, int); +int mvwinchnstr(WINDOW *, int, int, chtype *, int); +int mvwinchstr(WINDOW *, int, int, chtype *); +int mvwinnstr(WINDOW *, int, int, char *, int); +int mvwinstr(WINDOW *, int, int, char *); +int mvwprintw(WINDOW *, int, int, const char *, ...) __printflike(4, 5); +int mvwscanw(WINDOW *, int, int, const char *, ...) __scanflike(4, 5); +int napms(int); +WINDOW *newpad(int, int); +SCREEN *newterm(char *, FILE *, FILE *); +WINDOW *newwin(int, int, int, int); +int nl(void); +attr_t no_color_attributes(void); +int nocbreak(void); +int nodelay(WINDOW *, bool); +int noecho(void); +int nonl(void); +void noqiflush(void); +int noraw(void); +int notimeout(WINDOW *, bool); +int overlay(const WINDOW *, WINDOW *); +int overwrite(const WINDOW *, WINDOW *); +int pair_content(short, short *, short *); +int pechochar(WINDOW *, const chtype); +int pnoutrefresh(WINDOW *, int, int, int, int, int, int); +int prefresh(WINDOW *, int, int, int, int, int, int); +int printw(const char *, ...) __printflike(1, 2); +int putwin(WINDOW *, FILE *); +void qiflush(void); +int raw(void); +int redrawwin(WINDOW *); +int reset_prog_mode(void); +int reset_shell_mode(void); +int resetty(void); +int resizeterm(int, int); +int savetty(void); +int scanw(const char *, ...) __scanflike(1, 2); +int scroll(WINDOW *); +int scrollok(WINDOW *, bool); +int setterm(char *); +SCREEN *set_term(SCREEN *); +int start_color(void); +WINDOW *subpad(WINDOW *, int, int, int, int); +WINDOW *subwin(WINDOW *, int, int, int, int); +chtype termattrs(void); +attr_t term_attrs(void); +int touchline(WINDOW *, int, int); +int touchoverlap(WINDOW *, WINDOW *); +int touchwin(WINDOW *); +int ungetch(int); +int untouchwin(WINDOW *); +int use_default_colors(void); +int vline(chtype, int); +int vw_printw(WINDOW *, const char *, _BSD_VA_LIST_) __printflike(2, 0); +int vw_scanw(WINDOW *, const char *, _BSD_VA_LIST_) __scanflike(2, 0); +int vwprintw(WINDOW *, const char *, _BSD_VA_LIST_) __printflike(2, 0); +int vwscanw(WINDOW *, const char *, _BSD_VA_LIST_) __scanflike(2, 0); +int waddch(WINDOW *, chtype); +int waddchnstr(WINDOW *, const chtype *, int); +int waddchstr(WINDOW *, const chtype *); +int waddnstr(WINDOW *, const char *, int); +int wattr_get(WINDOW *, attr_t *, short *, void *); +int wattr_off(WINDOW *, attr_t, void *); +int wattr_on(WINDOW *, attr_t, void *); +int wattr_set(WINDOW *, attr_t, short, void *); +int wattroff(WINDOW *, int); +int wattron(WINDOW *, int); +int wattrset(WINDOW *, int); +int wbkgd(WINDOW *, chtype); +void wbkgdset(WINDOW *, chtype); +int wborder(WINDOW *, chtype, chtype, chtype, chtype, chtype, chtype, + chtype, chtype); +int wclear(WINDOW *); +int wclrtobot(WINDOW *); +int wclrtoeol(WINDOW *); +int wcolor_set(WINDOW *, short, void *); +void wcursyncup(WINDOW *); +int wdelch(WINDOW *); +int wdeleteln(WINDOW *); +int wechochar(WINDOW *, const chtype); +int werase(WINDOW *); +int wgetch(WINDOW *); +int wgetnstr(WINDOW *, char *, int); +int wgetstr(WINDOW *, char *); +int whline(WINDOW *, chtype, int); +chtype winch(WINDOW *); +int winchnstr(WINDOW *, chtype *, int); +int winchstr(WINDOW *, chtype *); +int winnstr(WINDOW *, char *, int); +int winsch(WINDOW *, chtype); +int winsdelln(WINDOW *, int); +int winsertln(WINDOW *); +int winstr(WINDOW *, char *); +int wmove(WINDOW *, int, int); +int wnoutrefresh(WINDOW *); +int wprintw(WINDOW *, const char *, ...) __printflike(2, 3); +int wredrawln(WINDOW *, int, int); +int wrefresh(WINDOW *); +int wresize(WINDOW *, int, int); +int wscanw(WINDOW *, const char *, ...) __scanflike(2, 3); +int wscrl(WINDOW *, int); +int wsetscrreg(WINDOW *, int, int); +int wstandend(WINDOW *); +int wstandout(WINDOW *); +void wsyncdown(WINDOW *); +void wsyncup(WINDOW *); +void wtimeout(WINDOW *, int); +int wtouchln(WINDOW *, int, int, int); +int wunderend(WINDOW *); +int wunderscore(WINDOW *); +int wvline(WINDOW *, chtype, int); + +int insnstr(const char *, int); +int insstr(const char *); +int mvinsnstr(int, int, const char *, int); +int mvinsstr(int, int, const char *); +int mvwinsnstr(WINDOW *, int, int, const char *, int); +int mvwinsstr(WINDOW *, int, int, const char *); +int winsnstr(WINDOW *, const char *, int); +int winsstr(WINDOW *, const char *); + +int chgat(int, attr_t, short, const void *); +int wchgat(WINDOW *, int, attr_t, short, const void *); +int mvchgat(int, int, int, attr_t, short, const void *); +int mvwchgat(WINDOW *, int, int, int, attr_t, short, const void *); + +/* wide-character support routines */ +/* return ERR when HAVE_WCHAR is not defined */ +/* add */ +int add_wch(const cchar_t *); +int wadd_wch(WINDOW *, const cchar_t *); +int mvadd_wch(int, int, const cchar_t *); +int mvwadd_wch(WINDOW *, int, int, const cchar_t *); + +int add_wchnstr(const cchar_t *, int); +int add_wchstr(const cchar_t *); +int wadd_wchnstr(WINDOW *, const cchar_t *, int); +int wadd_wchstr(WINDOW *, const cchar_t *); +int mvadd_wchnstr(int, int, const cchar_t *, int); +int mvadd_wchstr(int, int, const cchar_t *); +int mvwadd_wchnstr(WINDOW *, int, int, const cchar_t *, int); +int mvwadd_wchstr(WINDOW *, int, int, const cchar_t *); + +int addnwstr(const wchar_t *, int); +int addwstr(const wchar_t *); +int mvaddnwstr(int, int x, const wchar_t *, int); +int mvaddwstr(int, int x, const wchar_t *); +int mvwaddnwstr(WINDOW *, int, int, const wchar_t *, int); +int mvwaddwstr(WINDOW *, int, int, const wchar_t *); +int waddnwstr(WINDOW *, const wchar_t *, int); +int waddwstr(WINDOW *, const wchar_t *); + +int echo_wchar(const cchar_t *); +int wecho_wchar(WINDOW *, const cchar_t *); +int pecho_wchar(WINDOW *, const cchar_t *); + +/* insert */ +int ins_wch(const cchar_t *); +int wins_wch(WINDOW *, const cchar_t *); +int mvins_wch(int, int, const cchar_t *); +int mvwins_wch(WINDOW *, int, int, const cchar_t *); + +int ins_nwstr(const wchar_t *, int); +int ins_wstr(const wchar_t *); +int mvins_nwstr(int, int, const wchar_t *, int); +int mvins_wstr(int, int, const wchar_t *); +int mvwins_nwstr(WINDOW *, int, int, const wchar_t *, int); +int mvwins_wstr(WINDOW *, int, int, const wchar_t *); +int wins_nwstr(WINDOW *, const wchar_t *, int); +int wins_wstr(WINDOW *, const wchar_t *); + +/* input */ +int get_wch(wint_t *); +int unget_wch(const wchar_t); +int mvget_wch(int, int, wint_t *); +int mvwget_wch(WINDOW *, int, int, wint_t *); +int wget_wch(WINDOW *, wint_t *); + +int getn_wstr(wchar_t *, int); +int get_wstr(wchar_t *); +int mvgetn_wstr(int, int, wchar_t *, int); +int mvget_wstr(int, int, wchar_t *); +int mvwgetn_wstr(WINDOW *, int, int, wchar_t *, int); +int mvwget_wstr(WINDOW *, int, int, wchar_t *); +int wgetn_wstr(WINDOW *, wchar_t *, int); +int wget_wstr(WINDOW *, wchar_t *); + +int in_wch(cchar_t *); +int mvin_wch(int, int, cchar_t *); +int mvwin_wch(WINDOW *, int, int, cchar_t *); +int win_wch(WINDOW *, cchar_t *); + +int in_wchnstr(cchar_t *, int); +int in_wchstr(cchar_t *); +int mvin_wchnstr(int, int, cchar_t *, int); +int mvin_wchstr(int, int, cchar_t *); +int mvwin_wchnstr(WINDOW *, int, int, cchar_t *, int); +int mvwin_wchstr(WINDOW *, int, int, cchar_t *); +int win_wchnstr(WINDOW *, cchar_t *, int); +int win_wchstr(WINDOW *, cchar_t *); + +int innwstr(wchar_t *, int); +int inwstr(wchar_t *); +int mvinnwstr(int, int, wchar_t *, int); +int mvinwstr(int, int, wchar_t *); +int mvwinnwstr(WINDOW *, int, int, wchar_t *, int); +int mvwinwstr(WINDOW *, int, int, wchar_t *); +int winnwstr(WINDOW *, wchar_t *, int); +int winwstr(WINDOW *, wchar_t *); + +/* cchar handlgin */ +int setcchar(cchar_t *, const wchar_t *, const attr_t, short, const void *); +int getcchar(const cchar_t *, wchar_t *, attr_t *, short *, void *); + +/* misc */ +char *key_name( wchar_t ); +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 *); +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 *); +int box_set(WINDOW *, const cchar_t *, const cchar_t *); +int erasewchar(wchar_t *); +int killwchar(wchar_t *); +int hline_set(const cchar_t *, int); +int mvhline_set(int, int, const cchar_t *, int); +int mvvline_set(int, int, const cchar_t *, int); +int mvwhline_set(WINDOW *, int, int, const cchar_t *, int); +int mvwvline_set(WINDOW *, int, int, const cchar_t *, int); +int vline_set(const cchar_t *, int); +int whline_set(WINDOW *, const cchar_t *, int); +int wvline_set(WINDOW *, const cchar_t *, int); +int bkgrnd(const cchar_t *); +void bkgrndset(const cchar_t *); +int getbkgrnd(cchar_t *); +int wbkgrnd(WINDOW *, const cchar_t *); +void wbkgrndset(WINDOW *, const cchar_t *); +int wgetbkgrnd(WINDOW *, cchar_t *); + +/* Private functions that are needed for user programs prototypes. */ +int __cputchar(int); +int __waddbytes(WINDOW *, const char *, int, attr_t); +#ifdef HAVE_WCHAR +int __cputwchar( wchar_t ); +#endif /* HAVE_WCHAR */ +__END_DECLS + +#endif /* !_CURSES_H_ */ diff --git a/lib/libcurses/curses_addch.3 b/lib/libcurses/curses_addch.3 new file mode 100644 index 000000000..597506a3c --- /dev/null +++ b/lib/libcurses/curses_addch.3 @@ -0,0 +1,187 @@ +.\" $NetBSD: curses_addch.3,v 1.8 2007/07/15 21:37:55 wiz Exp $ +.\" +.\" Copyright (c) 2002 +.\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au) +.\" +.\" This code is donated to the NetBSD Foundation by the Author. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. The name of the Author may not be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" +.Dd July 11, 2007 +.Dt CURSES_ADDCH 3 +.Os +.Sh NAME +.Nm curses_addch , +.Nm addch , +.Nm waddch , +.Nm mvaddch , +.Nm mvwaddch +.Nd curses add characters to windows routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft int +.Fn addch "chtype ch" +.Ft int +.Fn waddch "WINDOW *win" "chtype ch" +.Ft int +.Fn mvaddch "int y" "int x" "chtype ch" +.Ft int +.Fn mvwaddch "WINDOW *win" "int y" "int x" "chtype ch" +.Sh DESCRIPTION +These functions add characters to +.Dv stdscr +or to the specified window. +.Pp +The +.Fn addch +function adds the character given in +.Fa ch +to +.Dv stdscr +at the current cursor position and advances the current cursor position by one. +Any character attributes set in +.Fa ch +will be merged with the background attributes currently set on +.Dv stdscr . +.Pp +The +.Fn waddch +function is the same as the +.Fn addch +function, excepting that the character is added to the window specified by +.Fa win . +.Pp +The +.Fn mvaddch +and +.Fn mvwaddch +functions are the same as the +.Fn addch +and +.Fn waddch +functions, respectively, excepting that +.Fn wmove +is called to move the cursor to the position specified by +.Fa y , +.Fa x +before the character is added to the window. +.Ss LINE DRAWING CHARACTERS +Some terminals support the display of line drawing and graphics characters. +These characters can be added using their defined names, as shown in the +table below. +Where the terminal does not support a specific character, the default +(non-graphics) character is displayed instead. +.Bl -column -offset indent ".Sy System V Name" ".Sy Default" +.It Sy "Name" Ta Sy "Default" Ta Sy "Description" +.It ACS_RARROW Ta \*[Gt] Ta "Arrow pointing right" +.It ACS_LARROW Ta \*[Lt] Ta "Arrow pointing left" +.It ACS_UARROW Ta ^ Ta "Arrow pointing up" +.It ACS_DARROW Ta v Ta "Arrow pointing down" +.It ACS_BLOCK Ta # Ta "Solid square block" +.It ACS_DIAMOND Ta + Ta "Diamond" +.It ACS_CKBOARD Ta : Ta "Checker board (stipple)" +.It ACS_DEGREE Ta ' Ta "Degree symbol" +.It ACS_PLMINUS Ta # Ta "Plus/minus" +.It ACS_BOARD Ta # Ta "Board of squares" +.It ACS_LANTERN Ta # Ta "Lantern symbol" +.It ACS_LRCORNER Ta + Ta "Lower right-hand corner" +.It ACS_URCORNER Ta + Ta "Upper right-hand corner" +.It ACS_ULCORNER Ta + Ta "Upper left-hand corner" +.It ACS_LLCORNER Ta + Ta "Lower left-hand corner" +.It ACS_PLUS Ta + Ta "Plus" +.It ACS_HLINE Ta - Ta "Horizontal line" +.It ACS_S1 Ta - Ta "Scan line 1" +.It ACS_S9 Ta - Ta "Scan line 9" +.It ACS_LTEE Ta + Ta "Left tee" +.It ACS_RTEE Ta + Ta "Right tee" +.It ACS_BTEE Ta + Ta "Bottom tee" +.It ACS_TTEE Ta + Ta "Top tee" +.It ACS_VLINE Ta | Ta "Vertical line" +.It ACS_BULLET Ta o Ta "Bullet" +.El +.Pp +The following additional, +.Em ncurses +compatible, characters are also supported. +.Bl -column -offset indent ".Sy System V Name" ".Sy Default" +.It Sy "Name" Ta Sy "Default" Ta Sy "Description" +.It ACS_S3 Ta - Ta "Scan line 3" +.It ACS_S7 Ta - Ta "Scan line 7" +.It ACS_LEQUAL Ta \*[Lt] Ta "Less than or equal to" +.It ACS_GEQUAL Ta \*[Gt] Ta "Greater than or equal to" +.It ACS_PI Ta * Ta "Pi symbol" +.It ACS_NEQUAL Ta ! Ta "Not equal to" +.It ACS_STERLING Ta f Ta "Sterling symbol" +.El +.Pp +For compatibility with some +.Em System V +implementations, the following definitions are also supported. +.Bl -column -offset indent ".Sy System V Name" ".Sy Default" +.It Sy "System V Name" Ta Sy "NetBSD Curses Name" +.It ACS_SBBS Ta ACS_LRCORNER +.It ACS_BBSS Ta ACS_URCORNER +.It ACS_BSSB Ta ACS_ULCORNER +.It ACS_SSBB Ta ACS_LLCORNER +.It ACS_SSSS Ta ACS_PLUS +.It ACS_BSBS Ta ACS_HLINE +.It ACS_SSSB Ta ACS_LTEE +.It ACS_SBSS Ta ACS_RTEE +.It ACS_SSBS Ta ACS_BTEE +.It ACS_BSSS Ta ACS_TTEE +.It ACS_SBSB Ta ACS_VLINE +.El +.Sh RETURN VALUES +Functions returning pointers will return +.Dv NULL +if an error is detected. +The functions that return an int will return one of the following +values: +.Pp +.Bl -tag -width ERR -compact +.It Er OK +The function completed successfully. +.It Er ERR +An error occurred in the function. +.El +.Sh SEE ALSO +.Xr curses_addchstr 3 , +.Xr curses_addstr 3 , +.Xr curses_attributes 3 , +.Xr curses_cursor 3 , +.Xr curses_delch 3 , +.Xr curses_inch 3 , +.Xr curses_insertch 3 +.Sh STANDARDS +The +.Nx +Curses library complies with the X/Open Curses specification, part of the +Single Unix Specification. +.Sh HISTORY +The Curses package appeared in +.Bx 4.0 . diff --git a/lib/libcurses/curses_addchstr.3 b/lib/libcurses/curses_addchstr.3 new file mode 100644 index 000000000..82df0f2b0 --- /dev/null +++ b/lib/libcurses/curses_addchstr.3 @@ -0,0 +1,155 @@ +.\" $NetBSD: curses_addchstr.3,v 1.3 2008/04/30 13:10:51 martin Exp $ +.\" +.\" Copyright (c) 2003 +.\" Douwe Kiela (virtus@wanadoo.nl) +.\" Copyright (c) 2003 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Douwe Kiela (virtus@wanadoo.nl). +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.\" +.Dd May 21, 2003 +.Dt CURSES_ADDCHSTR 3 +.Os +.Sh NAME +.Nm curses_addchstr , +.Nm addchstr , +.Nm waddchstr , +.Nm addchnstr , +.Nm waddchnstr , +.Nm mvaddchstr , +.Nm mvwaddchstr , +.Nm mvaddchnstr , +.Nm mvwaddchnstr +.Nd curses add character strings to windows routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft int +.Fn addchstr "const chtype *chstr" +.Ft int +.Fn waddchstr "WINDOW *win" "const chtype *chstr" +.Ft int +.Fn mvaddchstr "int y" "int x" "const chtype *chstr" +.Ft int +.Fn mvwaddchstr "WINDOW *win" "int y" "int x" "const chtype *chstr" +.Ft int +.Fn addchnstr "const chtype *chstr" "int n" +.Ft int +.Fn waddchnstr "WINDOW *win" "const chtype *chstr" "int n" +.Ft int +.Fn mvaddchnstr "int y" "int x" "const chtype *chstr" "int n" +.Ft int +.Fn mvwaddchnstr "WINDOW *win" "int y" "int x" "const chtype *chstr" "int n" +.Sh DESCRIPTION +These functions add character strings and attributes to +.Dv stdscr +or to the specified window. +.Pp +The +.Fn addchstr +function will add the characters and their attributes passed in +.Fa chstr +to +.Dv stdscr +starting at the current cursor position. +Any character attributes set in +.Fa chstr +will be merged with the background attributes currently set on +.Dv stdscr . +The +.Fn waddstr +function does the same as +.Fn addchstr +but adds the string to the window specified by +.Fn win . +.Pp +The +.Fn addchnstr +function will add the contents of +.Fa string +to +.Dv stdscr +but will limit the number of characters added to be, at most, +.Fa n . +If +.Fa n +is \-1 then +.Fa addchnstr +will add the number of characters contained in the null terminated string +.Fa chstr . +Any character attributes set in +.Fa chstr +will be merged with the background attributes currently set on +.Dv stdscr . +.Pp +The +.Fn waddchnstr +function does the same as +.Fa addchnstr +but adds the string to the window specified by +.Fa win . +.Pp +The functions +.Fn mvaddchstr , +.Fn mwaddchnstr , +.Fn mvwaddchstr +and +.Fn mvwaddchnstr +are the same as the functions +.Fn addchstr , +.Fn waddchstr , +.Fn waddchstr +and +.Fn waddchnstr , +respectively, except that +.Fn wmove +is called to move the cursor to the position specified by +.Fa y , +.Fa x +before the string is added to the window. +.Sh RETURN VALUES +The functions will return one of the following values: +.Pp +.Bl -tag -width ERR -compact +.It Er OK +The function completed successfully. +.It Er ERR +An error occurred in the function. +.El +.Sh SEE ALSO +.Xr curses_addch 3 , +.Xr curses_addstr 3 , +.Xr curses_attributes 3 , +.Xr curses_cursor 3 , +.Xr curses_inch 3 +.Sh STANDARDS +The +.Nx +Curses library complies with the X/Open Curses specification, part of the +Single Unix Specification. +.Sh HISTORY +These functions first appeared in +.Nx 2.0 . diff --git a/lib/libcurses/curses_addstr.3 b/lib/libcurses/curses_addstr.3 new file mode 100644 index 000000000..8ed7199f2 --- /dev/null +++ b/lib/libcurses/curses_addstr.3 @@ -0,0 +1,159 @@ +.\" $NetBSD: curses_addstr.3,v 1.4 2003/05/21 21:22:15 jdc Exp $ +.\" +.\" Copyright (c) 2002 +.\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au) +.\" +.\" This code is donated to the NetBSD Foundation by the Author. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. The name of the Author may not be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" +.Dd May 21, 2003 +.Dt CURSES_ADDSTR 3 +.Os +.Sh NAME +.Nm curses_addstr , +.Nm addstr , +.Nm waddstr , +.Nm addnstr , +.Nm waddnstr , +.Nm mvaddstr , +.Nm mvwaddstr , +.Nm mvaddnstr , +.Nm mvwaddnstr +.Nd curses add character strings to windows routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft int +.Fn addstr "const char *string" +.Ft int +.Fn waddstr "WINDOW *win" "const char *string" +.Ft int +.Fn mvaddstr "int y" "int x" "const char *string" +.Ft int +.Fn mvwaddstr "WINDOW *win" "int y" "int x" "const char *string" +.Ft int +.Fn addnstr "const char *string" "int len" +.Ft int +.Fn waddnstr "WINDOW *win" "const char *string" "int len" +.Ft int +.Fn mvaddnstr "int y" "int x" "const char *string" "int len" +.Ft int +.Fn mvwaddnstr "WINDOW *win" "int y" "int x" "const char *string" "int len" +.Sh DESCRIPTION +These functions add character strings to +.Dv stdscr +or to the specified window. +.Pp +The +.Fn addstr +function +will add the characters passed in +.Fa string +to +.Dv stdscr +starting at the current cursor position. +Any background attributes currently set on +.Dv stdscr +will be applied to the added character. +The +.Fn waddstr +function does the same as +.Fn addstr +but adds the string to the window specified by +.Fn win . +.Pp +The +.Fn addnstr +function will add the contents of +.Fa string +to +.Dv stdscr +but will limit the number of characters added to be, at most, +.Fa len . +If +.Fa len +is \-1 then +.Fa addnstr +will add the number of characters contained in the null terminated string +.Fa string . +Any background attributes currently set on +.Dv stdscr +will be applied to the added character. +The +.Fn waddnstr +function +does the same as +.Fa addnstr +but adds the string to the window specified by +.Fa win . +.Pp +The functions +.Fn mvaddstr , +.Fn mwaddnstr , +.Fn mvwaddstr +and +.Fn mvwaddnstr +are the same as the functions +.Fn addstr , +.Fn waddstr , +.Fn waddstr +and +.Fn waddnstr , +respectively, excepting that +.Fn wmove +is called to move the cursor to the position specified by +.Fa y , +.Fa x +before the string is added to the window. +.Sh RETURN VALUES +Functions returning pointers will return +.Dv NULL +if an error is detected. +The functions that return an int will return one of the following +values: +.Pp +.Bl -tag -width ERR -compact +.It Er OK +The function completed successfully. +.It Er ERR +An error occurred in the function. +.El +.Sh SEE ALSO +.Xr curses_addch 3 , +.Xr curses_addchstr 3 , +.Xr curses_attributes 3 , +.Xr curses_cursor 3 , +.Xr curses_inch 3 +.Sh STANDARDS +The +.Nx +Curses library complies with the X/Open Curses specification, part of the +Single Unix Specification. +.Sh HISTORY +The Curses package appeared in +.Bx 4.0 . diff --git a/lib/libcurses/curses_attributes.3 b/lib/libcurses/curses_attributes.3 new file mode 100644 index 000000000..307ea858b --- /dev/null +++ b/lib/libcurses/curses_attributes.3 @@ -0,0 +1,342 @@ +.\" $NetBSD: curses_attributes.3,v 1.8 2008/04/30 13:10:51 martin Exp $ +.\" Copyright (c) 2002 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Julian Coleman. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd March 14, 2008 +.Dt CURSES_ATTRIBUTES 3 +.Os +.Sh NAME +.Nm curses_attributes , +.Nm attron , +.Nm attroff , +.Nm attrset , +.Nm color_set , +.Nm getattrs , +.Nm termattrs , +.Nm wattron , +.Nm wattroff , +.Nm wattrset , +.Nm wcolor_set , +.Nm attr_on , +.Nm attr_off , +.Nm attr_set , +.Nm attr_get , +.Nm term_attrs , +.Nm wattr_on , +.Nm wattr_off , +.Nm wattr_set , +.Nm wattr_get +.Nd curses general attribute manipulation routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft int +.Fn attron "int attr" +.Ft int +.Fn attroff "int attr" +.Ft int +.Fn attrset "int attr" +.Ft int +.Fn color_set "short pair" "void *opt" +.Ft chtype +.Fn getattrs "WINDOW *win" +.Ft chtype +.Fn termattrs "void" +.Ft int +.Fn wcolor_set "WINDOW *win" "short pair" "void *opt" +.Ft int +.Fn wattron "WINDOW * win" "int attr" +.Ft int +.Fn wattroff "WINDOW * win" "int attr" +.Ft int +.Fn wattrset "WINDOW * win" "int attr" +.Ft int +.Fn attr_on "attr_t attr" "void *opt" +.Ft int +.Fn attr_off "attr_t attr" "void *opt" +.Ft int +.Fn attr_set "attr_t attr" "short pair" "void *opt" +.Ft int +.Fn attr_get "attr_t *attr" "short *pair" "void *opt" +.Ft attr_t +.Fn term_attrs "void" +.Ft int +.Fn wattr_on "WINDOW *win" "attr_t attr" "void *opt" +.Ft int +.Fn wattr_off "WINDOW *win" "attr_t attr" "void *opt" +.Ft int +.Fn wattr_set "WINDOW *win" "attr_t attr" "short pair" "void *opt" +.Ft int +.Fn wattr_get "WINDOW *win" "attr_t *attr" "short *pair" "void *opt" +.Sh DESCRIPTION +These functions manipulate attributes on +.Dv stdscr +or on the specified window. +The attributes that can be manipulated are: +.Pp +.Bl -tag -width "COLOR_PAIR(n)" -compact -offset indent +.It A_NORMAL +no special attributes are applied +.It A_STANDOUT +characters are displayed in standout mode +.It A_UNDERLINE +characters are displayed underlined +.It A_REVERSE +characters are displayed in inverse video +.It A_BLINK +characters blink +.It A_DIM +characters are displayed at a lower intensity +.It A_BOLD +characters are displayed at a higher intensity +.It A_INVIS +characters are added invisibly +.It A_PROTECT +characters are protected from modification +.It A_ALTCHARSET +characters are displayed using the alternate character set (ACS) +.It COLOR_PAIR(n) +characters are displayed using color pair n. +.El +.Pp +The +.Fn attron +function turns on the attributes specified in +.Fa attr +on +.Dv stdscr , +while the +.Fn attroff +function turns off the attributes specified in +.Fa attr +on +.Dv stdscr . +.Pp +The function +.Fn attrset +sets the attributes of +.Dv stdscr +to those specified in +.Fa attr , +turning off any others. +To turn off all the attributes (including color and alternate character set), +use +.Fn attrset A_NORMAL . +.Pp +Multiple attributes can be manipulated by combining the attributes +using a logical +.Em OR . +For example, +.Fn attron "A_REVERSE | A_BOLD" +will turn on both inverse video and higher intensity. +.Pp +The function +.Fn color_set +sets the color pair attribute to the pair specified in +.Fa pair . +.Pp +The function +.Fn getattrs +returns the attributes that are currently applied to window specified by +.Fa win . +.Pp +The function +.Fn termattrs +returns the logical +.Em OR +of attributes that can be applied to the screen. +.Pp +The functions +.Fn wattron , +.Fn wattroff , +.Fn wattrset , +and +.Fn wcolor_set +are equivalent to +.Fn attron , +.Fn attroff +.Fn attrset , +and +.Fn color_set +respectively, excepting that the attributes are applied to the window +specified by +.Fa win . +.Pp +The following functions additionally manipulate wide attributes on +.Dv stdscr +or on the specified window. +The additional wide attributes that can be manipulated are: +.Pp +.Bl -tag -width "COLOR_PAIR(n)" -compact -offset indent +.It WA_STANDOUT +characters are displayed in standout mode +.It WA_UNDERLINE +characters are displayed underlined +.It WA_REVERSE +characters are displayed in inverse video +.It WA_BLINK +characters blink +.It WA_DIM +characters are displayed at a lower intensity +.It WA_BOLD +characters are displayed at a higher intensity +.It WA_INVIS +characters are added invisibly +.It WA_PROTECT +characters are protected from modification +.It WA_ALTCHARSET +characters are displayed using the alternate character set (ACS) +.It WA_LOW +characters are displayed with low highlight +.It WA_TOP +characters are displayed with top highlight +.It WA_HORIZONTAL +characters are displayed with horizontal highlight +.It WA_VERTICAL +characters are displayed with vertical highlight +.It WA_LEFT +characters are displayed with left highlight +.It WA_RIGHT +characters are displayed with right highlight +.El +.Pp +The +.Fn attr_on +function turns on the wide attributes specified in +.Fa attr +on +.Dv stdscr , +while the +.Fn attr_off +function turns off the wide attributes specified in +.Fa attr +on +.Dv stdscr . +.Pp +The function +.Fn attr_set +sets the wide attributes of +.Dv stdscr +to those specified in +.Fa attr +and +.Fa pair , +turning off any others. +Note that a color pair specified in +.Fa pair +will override any color pair specified in +.Fa attr . +.Pp +The function +.Fn attr_get +sets +.Fa attr +to the wide attributes and +.Fa pair +to the color pair currently applied to +.Dv stdscr . +Either of +.Fa attr +and +.Fa pair +can be +.Dv NULL , +if the relevant value is of no interest. +.Pp +The function +.Fn term_attrs +returns the logical +.Em OR +of wide attributes that can be applied to the screen. +.Pp +The functions +.Fn wattr_on , +.Fn wattr_off +and +.Fn wattr_set +are equivalent to +.Fn attr_on , +.Fn attr_off +and +.Fn attr_set +respectively, excepting that the character is added to the window specified by +.Fa win . +.Pp +The function +.Fn wattr_get +is equivalent to +.Fn attr_get , +excepting that the wide attributes and color pair currently applied to +.Fa win +are set. +.Pp +The following constants can be used to extract the components of a +.Dv chtype : +.Pp +.Bl -tag -width "COLOR_PAIR(n)" -compact -offset indent +.It A_ATTRIBUTES +bit-mask containing attributes part +.It A_CHARTEXT +bit-mask containing character part +.It A_COLOR +bit-mask containing color-pair part +.El +.Sh RETURN VALUES +These functions return OK on success and ERR on failure. +.Sh SEE ALSO +.Xr curses_addch 3 , +.Xr curses_addchstr 3 , +.Xr curses_addstr 3 , +.Xr curses_background 3 , +.Xr curses_color 3 , +.Xr curses_insertch 3 , +.Xr curses_standout 3 , +.Xr curses_underscore 3 +.Sh NOTES +The +.Fa opt +argument is not currently used but is reserved for a future version of the +specification. +.Sh STANDARDS +The +.Nx +Curses library complies with the X/Open Curses specification, part of the +Single Unix Specification. +.Pp +The +.Fn getattrs +function +is a +.Nx +extension. +.Sh HISTORY +These functions first appeared in +.Nx 1.5 . +.Sh BUGS +Some terminals do not support characters with both color and other attributes +set. +In this case, the other attribute is displayed instead of the color attribute. diff --git a/lib/libcurses/curses_background.3 b/lib/libcurses/curses_background.3 new file mode 100644 index 000000000..f07f6dbf2 --- /dev/null +++ b/lib/libcurses/curses_background.3 @@ -0,0 +1,124 @@ +.\" $NetBSD: curses_background.3,v 1.6 2008/04/30 13:10:51 martin Exp $ +.\" Copyright (c) 2002 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Julian Coleman. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd January 15, 2006 +.Dt CURSES_BACKGROUND 3 +.Os +.Sh NAME +.Nm curses_background , +.Nm bkgd , +.Nm bkgdset , +.Nm getbkgd , +.Nm wbkgd , +.Nm wbkgdset +.Nd curses attribute manipulation routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft int +.Fn bkgd chtype +.Ft int +.Fn bkgdset chtype +.Ft chtype +.Fn getbkgd "WINDOW *" +.Ft int +.Fn wbkgd chtype +.Ft int +.Fn wbkgdset chtype +.Sh DESCRIPTION +These functions manipulate the background attributes on +.Dv stdscr +or on the specified window. +.Pp +The function +.Fn wbkgdset win ch +sets the background attributes of the specified window +.Fa win +to +.Fa ch . +.Pp +When the background attributes are set on a window, characters are added to +the window with the logical +.Em OR +of the background attributes and the character's attributes. +If both the background attribute and the character attribute contain color, +the color of the character attribute is rendered. +If the background attribute contains a non-space character, then this +character is added where the foreground character is a space character. +.Pp +Note that subwindows created from +.Fa win +inherit the background attributes of +.Fa win . +.Pp +The function +.Fn wbkgd win ch +sets the background attributes of the specified window +.Fa win +to +.Fa ch +and also sets the rendition of every character position on that window, +as if the characters had been newly added to +.Fa win . +The rendition of characters on subwindows of +.Fa win +is also set to +.Fa ch . +.Pp +The functions +.Fn bkgdset ch +and +.Fn bkgd ch +are equivalent to +.Fn wbkgdset stdscr ch +and +.Fn wbkgd stdscr ch , +respectively. +.Pp +The function +.Fn getbkgd win +returns the background attributes for the window +.Fa win . +.Sh RETURN VALUES +The functions +.Fn wbkgdset +and +.Fn wbkgd +return OK on success and ERR on failure. +.Sh SEE ALSO +.Xr curses_attributes 3 , +.Xr curses_color 3 , +.Xr curses_window 3 +.Sh STANDARDS +The +.Nx +Curses library complies with the X/Open Curses specification, part of the +Single Unix Specification. +.Sh HISTORY +These functions first appeared in +.Nx 1.6 . diff --git a/lib/libcurses/curses_border.3 b/lib/libcurses/curses_border.3 new file mode 100644 index 000000000..25098e246 --- /dev/null +++ b/lib/libcurses/curses_border.3 @@ -0,0 +1,159 @@ +.\" $NetBSD: curses_border.3,v 1.4 2004/03/16 19:20:20 snj Exp $ +.\" +.\" Copyright (c) 2002 +.\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au) +.\" +.\" This code is donated to the NetBSD Foundation by the Author. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. The name of the Author may not be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" +.Dd August 12, 2002 +.Dt CURSES_BORDER 3 +.Os +.Sh NAME +.Nm curses_border , +.Nm border , +.Nm box , +.Nm wborder +.Nd curses border drawing routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft int +.Fo border +.Fa "chtype ls" +.Fa "chtype rs" +.Fa "chtype ts" +.Fa "chtype bs" +.Fa "chtype tl" +.Fa "chtype tr" +.Fa "chtype bl" +.Fa "chtype br" +.Fc +.Ft int +.Fn box "WINDOW *win" "chtype vertical" "chtype horizontal" +.Ft int +.Fo wborder +.Fa "WINDOW *win" +.Fa "chtype ls" +.Fa "chtype rs" +.Fa "chtype ts" +.Fa "chtype bs" +.Fa "chtype tl" +.Fa "chtype tr" +.Fa "chtype bl" +.Fa "chtype br" +.Fc +.Sh DESCRIPTION +These functions draw borders around +.Dv stdscr +or around the specified window. +.Pp +The +.Fn border +function draws a border around +.Dv stdscr +using the characters given as arguments to the function. +The +.Fa ls , +.Fa rs , +.Fa ts +and +.Fa bs +are the characters used to draw the left, right, top and bottom sides, +respectively. +The +.Fa tl , +.Fa tr , +.Fa bl +and +.Fa br +are the characters used to draw the top-left, top-right, bottom-left +and bottom-right corners, respectively. +If any of the characters have a text portion that is 0 then a default +alternate character set character is used for that character. +Note that even though the text portion of the argument is 0, the argument +can still be used to specify the attributes for that portion of the border. +The following table shows the default characters for each argument: +.Pp +.Bl -column "ls" -offset indent +.It ls ACS_VLINE +.It rs ACS_VLINE +.It ts ACS_HLINE +.It bs ACS_HLINE +.It tl ACS_ULCORNER +.It tr ACS_URCORNER +.It bl ACS_LLCORNER +.It br ACS_LRCORNER +.El +.Pp +.Fn wborder +is the same as +.Fn border +excepting that the border is drawn around the specified window. +.Pp +The +.Fn box +command draws a box around the window given in +.Fa win +using the +.Fa vertical +character for the vertical lines and the +.Fa horizontal +character for the horizontal lines. +The corner characters of this box will be the defaults as described for +.Fn border +above. +Passing characters with text portion that is 0 to +.Fn box +will result in the same defaults as those for +.Fn border +as described above. +.Sh RETURN VALUES +Functions returning pointers will return +.Dv NULL +if an error is detected. +The functions that return an int will return one of the following +values: +.Pp +.Bl -tag -width ERR -compact +.It Er OK +The function completed successfully. +.It Er ERR +An error occurred in the function. +.El +.Sh SEE ALSO +.Xr curses_attributes 3 , +.Xr curses_line 3 +.Sh STANDARDS +The +.Nx +Curses library complies with the X/Open Curses specification, part of the +Single Unix Specification. +.Sh HISTORY +The Curses package appeared in +.Bx 4.0 . diff --git a/lib/libcurses/curses_chgat.3 b/lib/libcurses/curses_chgat.3 new file mode 100644 index 000000000..2143286e7 --- /dev/null +++ b/lib/libcurses/curses_chgat.3 @@ -0,0 +1,119 @@ +.\" $NetBSD: curses_chgat.3,v 1.4 2009/07/12 23:14:06 wiz Exp $ +.\" +.\" Copyright (c) 2009 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Joerg Sonnenberger. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd July 6, 2009 +.Dt CURSES_CHGAT 3 +.Os +.Sh NAME +.Nm chgat , +.Nm wchgat , +.Nm mvchgat , +.Nm mvwchgat +.Nd curses on-screen attribute manipulation routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft int +.Fn chgat "int n" "attr_t attr" "short color" "const void *opts" +.Ft int +.Fn wchgat "WINDOW *win" "int n" "attr_t attr" "short color" \ +"const void *opts" +.Ft int +.Fn mvchgat "int y" "int x" "int n" "attr_t attr" "short color" \ +"const void *opts" +.Ft int +.Fn mvwchgat "WINDOW *win" "int y" "int x" "int n" "attr_t attr" \ +"short color" "const void *opts" +.Sh DESCRIPTION +These functions modify the attributes of the drawn content on stdscr or +on the specified window. +.Pp +The +.Fn chgat +function sets the attributes of the next +.Fa n +characters to +.Fa attr +and the color pair to +.Fa color . +If +.Fa n +is negative or larger than the reminder of the line, it gets truncated. +.Pp +The +.Fn wchgat +is the same as the +.Fn chgat +function, excepting that the attributes are changed in the window specified by +.Fa win . +.Pp +The +.Fn mvchgat +and +.Fn mvwchgat +functions are the same as the +.Fn chgat +and +.Fn wchgat +functions, respectively, excepting that they operate from the position +specified by +.Fa y , +.Fa x . +.Pp +These functions do not perform wrapping. +They do not update the cursor position. +.Sh RETURN VALUES +The functions that return an int will return one of the following +values: +.Pp +.Bl -tag -width ERR -compact +.It Er OK +The function completed successfully. +.It Er ERR +An error occurred in the function. +.El +.Sh SEE ALSO +.Xr curses_attributes 3 +.Sh STANDARDS +The +.Fn chgat , +.Fn wchgat , +.Fn mvchgat , +and +.Fn mvwchgat +functions conform to +.St -xcurses4.2 . +.Sh HISTORY +The Curses package appeared in +.Bx 4.0 . +Support for the +.Fn chgat +family was added in +.Nx 6.0 . diff --git a/lib/libcurses/curses_clear.3 b/lib/libcurses/curses_clear.3 new file mode 100644 index 000000000..1a318b79f --- /dev/null +++ b/lib/libcurses/curses_clear.3 @@ -0,0 +1,141 @@ +.\" $NetBSD: curses_clear.3,v 1.3 2003/04/16 13:35:00 wiz Exp $ +.\" +.\" Copyright (c) 2002 +.\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au) +.\" +.\" This code is donated to the NetBSD Foundation by the Author. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. The name of the Author may not be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" +.Dd August 12, 2002 +.Dt CURSES_CLEAR 3 +.Os +.Sh NAME +.Nm curses_clear , +.Nm clear , +.Nm wclear , +.Nm clearok , +.Nm clrtobot , +.Nm clrtoeol , +.Nm erase , +.Nm werase , +.Nm wclrtobot , +.Nm wclrtoeol +.Nd curses clear window routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft int +.Fn clear "void" +.Ft int +.Fn clearok "WINDOW *win" "bool flag" +.Ft int +.Fn clrtobot "void" +.Ft int +.Fn clrtoeol "void" +.Ft int +.Fn erase "void" +.Ft int +.Fn wclear "WINDOW *win" +.Ft int +.Fn werase "WINDOW *win" +.Ft int +.Fn wclrtobot "WINDOW *win" +.Ft int +.Fn wclrtoeol "WINDOW *win" +.Sh DESCRIPTION +These functions clear all or part of +.Dv stdscr +or of the specified window. +.Pp +The +.Fn clear +and +.Fn erase +functions erase all characters on +.Dv stdscr . +.Fn wclear +and +.Fn werase +perform the same function as +.Fn clear +and +.Fn erase , +respectively, excepting that the specified window is cleared. +.Pp +By setting +.Fa flag +to +.Dv TRUE , +the +.Fn clearok +function is used to force the next call to +.Fn wrefresh +to clear and completely redraw the window given in +.Fa win . +.Pp +The function +.Fn clrtobot +will clear +.Dv stdscr +from the current row to the bottom of the screen. +.Fn clrtoeol +will clear +.Dv stdscr +from the current column position to the end of the line. +.Fn wclrtobot +and +.Fn wclrtoeol +are the same as +.Fn clrtobot +and +.Fn clrtoeol , +respectively, excepting the window specified is operated on instead of +.Dv stdscr . +.Sh RETURN VALUES +Functions returning pointers will return +.Dv NULL +if an error is detected. +The functions that return an int will return one of the following +values: +.Pp +.Bl -tag -width ERR -compact +.It Er OK +The function completed successfully. +.It Er ERR +An error occurred in the function. +.El +.Sh SEE ALSO +.Xr curses_refresh 3 +.Sh STANDARDS +The +.Nx +Curses library complies with the X/Open Curses specification, part of the +Single Unix Specification. +.Sh HISTORY +The Curses package appeared in +.Bx 4.0 . diff --git a/lib/libcurses/curses_color.3 b/lib/libcurses/curses_color.3 new file mode 100644 index 000000000..19b567ad7 --- /dev/null +++ b/lib/libcurses/curses_color.3 @@ -0,0 +1,232 @@ +.\" $NetBSD: curses_color.3,v 1.12 2009/07/22 16:57:14 roy Exp $ +.\" Copyright (c) 2002 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Julian Coleman. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd July 20, 2009 +.Dt CURSES_COLOR 3 +.Os +.Sh NAME +.Nm curses_color , +.Nm has_colors , +.Nm can_change_color , +.Nm start_color , +.Nm init_pair , +.Nm pair_content , +.Nm COLOR_PAIR , +.Nm PAIR_NUMBER , +.Nm init_color , +.Nm color_content , +.Nm no_color_attributes +.Nd curses color manipulation routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft bool +.Fn has_colors void +.Ft bool +.Fn can_change_color void +.Ft int +.Fn start_color void +.Ft int +.Fn init_pair "short pair" "short fore" "short back" +.Ft int +.Fn pair_content "short pair" "short *fore" "short *back" +.Ft int +.Fn COLOR_PAIR "int n" +.Ft int +.Fn PAIR_NUMBER "int val" +.Ft int +.Fn init_color "short color" "short red" "short green" "short blue" +.Ft int +.Fn color_content "short color" "short *red" "short *green" "short *blue" +.Ft attr_t +.Fn no_color_attributes void +.Pp +.Va extern int COLOR_PAIRS ; +.Pp +.Va extern int COLORS ; +.Sh DESCRIPTION +These functions manipulate color on terminals that support color attributes. +.Pp +The function +.Fn has_colors +indicates whether a terminal is capable of displaying color attributes. +It returns +.Dv TRUE +if the terminal is capable of displaying color attributes and +.Dv FALSE +otherwise. +.Pp +The function +.Fn can_change_color +indicates whether a terminal is capable of redefining colors. +It returns +.Dv TRUE +if colors can be redefined and +.Dv FALSE +if they can not. +.Pp +The function +.Fn start_color +initializes the curses color support on a terminal. +It must be called before any color manipulation functions are called on that +terminal. +The function initializes the eight basic colors (black, red, green, yellow, +blue, magenta, cyan and white) that are specified using the color macros +(such as +.Dv COLOR_BLACK ) +defined in +.Em \*[Lt]curses.h\*[Gt] . +.Fn start_color +also initializes the global external variables +.Va COLORS +and +.Va COLOR_PAIRS . +.Va COLORS +defines the number of colors that the terminal supports and +.Va COLOR_PAIRS +defines the number of color-pairs that the terminal supports. +These color-pairs are initialized to white foreground on black background. +.Fn start_color +sets the colors on the terminal to the curses defaults of white +foreground on black background unless the functions +.Fn assume_default_colors +or +.Fn use_default_colors +have been called previously. +.Pp +The function +.Fn init_pair pair fore back +sets foreground color +.Fa fore +and background color +.Fa back +for color-pair number +.Fa pair . +The valid range for the color-pair +.Fa pair +is from 1 to +.Va COLOR_PAIRS +\&- 1 +and the valid range for the colors is any number less than +.Va COLORS . +Specifying a negative number will set that color to the default foreground +or background color. +The 8 initial colors are defined as: +.Bl -tag -width "COLOR_MAGENTA" -compact -offset indent +.It COLOR_BLACK +.It COLOR_RED +.It COLOR_GREEN +.It COLOR_YELLOW +.It COLOR_BLUE +.It COLOR_MAGENTA +.It COLOR_CYAN +.It COLOR_WHITE +.El +Color-pair 0 is used as the default color pair, so changing this will +have no effect. +Use the function +.Fn assume_default_colors +to change the default colors. +.Pp +The function +.Fn pair_content pair *fore *back +stores the foreground and background color numbers of color-pair +.Fa pair +in the variables +.Fa fore +and +.Fa back , +respectively. +.Pp +The macro +.Fn COLOR_PAIR n +gives the attribute value of color-pair number +.Fa n . +This is the value that is used to set the attribute of a character to this +color-pair. +For example, +.Dl attrset(COLOR_PAIR(2)) +will display characters using color-pair 2. +.Pp +The macro +.Fn PAIR_NUMBER val +gives the color-pair number associated with the attribute value +.Fa val . +.Pp +The function +.Fn init_color color red green blue +sets the red, green and blue intensity components of color +.Fa color +to the values +.Fa red , +.Fa green +and +.Fa blue , +respectively. +The minimum intensity value is 0 and the maximum intensity value is 1000. +.Pp +The function +.Fn color_content color *red *green *blue +stores the red, green and blue intensity components of color +.Fa color +in the variables +.Fa red , +.Fa green , +and +.Fa blue , +respectively. +.Pp +The function +.Fn no_color_attributes +returns those attributes that a terminal is unable to combine with color. +.Sh RETURN VALUES +The functions +.Fn start_color , +.Fn init_pair , +.Fn pair_content , +.Fn init_color +and +.Fn color_content +return OK on success and ERR on failure. +.Sh SEE ALSO +.Xr curses_attributes 3 , +.Xr curses_background 3 , +.Xr curses_default_colors 3 +.Sh STANDARDS +The +.Nx +Curses library complies with the X/Open Curses specification, part of the +Single Unix Specification. +.Pp +The function +.Fn no_color_attributes +and the use of negative color numbers +are extensions to the X/Open Curses specification. +.Sh HISTORY +These functions first appeared in +.Nx 1.5 . diff --git a/lib/libcurses/curses_cursor.3 b/lib/libcurses/curses_cursor.3 new file mode 100644 index 000000000..dd15d8c39 --- /dev/null +++ b/lib/libcurses/curses_cursor.3 @@ -0,0 +1,223 @@ +.\" $NetBSD: curses_cursor.3,v 1.7 2010/02/24 13:02:13 drochner Exp $ +.\" +.\" Copyright (c) 2002 +.\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au) +.\" +.\" This code is donated to the NetBSD Foundation by the Author. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. The name of the Author may not be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" +.Dd February 23, 2010 +.Dt CURSES 3 +.Os +.Sh NAME +.Nm curses_cursor , +.Nm getcury , +.Nm getcurx , +.Nm getyx , +.Nm getbegy , +.Nm getbegx , +.Nm getbegyx , +.Nm getmaxy , +.Nm getmaxx , +.Nm getmaxyx , +.Nm getpary , +.Nm getparx , +.Nm getparyx , +.Nm move , +.Nm wmove , +.Nm mvcur , +.Nm wcursyncup +.Nd curses cursor and window location and positioning routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft int +.Fn getcury "WINDOW *win" +.Ft int +.Fn getcurx "WINDOW *win" +.Ft void +.Fn getyx "WINDOW *win" "int y" "int x" +.Ft int +.Fn getbegy "WINDOW *win" +.Ft int +.Fn getbegx "WINDOW *win" +.Ft void +.Fn getbegyx "WINDOW *win" "int y" "int x" +.Ft int +.Fn getmaxy "WINDOW *win" +.Ft int +.Fn getmaxx "WINDOW *win" +.Ft void +.Fn getmaxyx "WINDOW *win" "int y" "int x" +.Ft int +.Fn getpary "WINDOW *win" +.Ft int +.Fn getparx "WINDOW *win" +.Ft void +.Fn getparyx "WINDOW *win" "int y" "int x" +.Ft int +.Fn move "int y" "int x" +.Ft int +.Fn wmove "WINDOW *win" "int y" "int x" +.Ft int +.Fn mvcur "int oldy" "int oldx" "int y" "int x" +.Ft void +.Fn wcursyncup "WINDOW *win" +.Sh DESCRIPTION +These functions and macros locate and position cursors and windows. +.Pp +The +.Fn getcury +and +.Fn getcurx +functions get the current row and column positions, respectively, of the cursor in +the window +.Fa win . +The +.Fn getyx +macro sets the values of +.Fa y +and +.Fa x +to the current row and column positions of the cursor in the window +.Fa win . +.Pp +The origin row and columns of a window +.Fa win +can be +determined by calling the +.Fn getbegy +and +.Fn getbegx +functions, respectively, and the maximum row and column for the window can be +found by calling the functions +.Fn getmaxy +and +.Fn getmaxx , +respectively. +The +.Fn getbegyx +and +.Fn getmaxyx +macros set the values of +.Fa y +and +.Fa x +to the origin and maximum row and column positions, respectively, for the window +.Fa win . +.Pp +The +.Fn getpary +and +.Fn getparx +functions return the row and column position of the given subwindow relative to +the window's parent. +The macro +.Fn getparyx +sets the values of +.Fa y +and +.Fa x +to the origin of the subwindow relative to the window's parent. +.Pp +The +.Fn move +function positions the cursor on the current window at the position given by +.Fa y , +.Fa x . +The cursor position is not changed on the screen until the next +.Fn refresh . +.Pp +The +.Fn wmove +function is the same as the +.Fn move +function, excepting that the cursor is moved in the window specified by +.Fa win . +.Pp +The function +.Fn mvcur +moves the cursor to +.Fa y , +.Fa x +on the screen. +The arguments +.Fa oldy , +.Fa oldx +define the previous cursor position for terminals that do not support +absolute cursor motions. +The curses library may optimise the cursor motion based on these values. +If the +.Fn mvcur +succeeds then the curses internal structures are updated with the new +position of the cursor. +If the destination arguments for +.Fn mvcur +exceed the terminal bounds an error will be returned and the cursor +position will be unchanged. +.Pp +The +.Fn wcursyncup +function sets the cursor positions of all ancestors of +.Fa win +to that of +.Fa win . +.Sh RETURN VALUES +Functions returning pointers will return +.Dv NULL +if an error is detected. +The functions that return an int will return one of the following +values: +.Pp +.Bl -tag -width ERR -compact +.It Er OK +The function completed successfully. +.It Er ERR +An error occurred in the function. +.El +.Sh SEE ALSO +.Xr curses_refresh 3 +.Sh STANDARDS +The +.Nx +Curses library complies with the X/Open Curses specification, part of +the Single Unix Specification. +The +.Fn getbegx , +.Fn getbegy , +.Fn getcurx , +.Fn getcury , +.Fn getmaxx , +.Fn getmaxy , +.Fn getparx , +and +.Fn getpary +functions are extensions. +.Sh HISTORY +The Curses package appeared in +.Bx 4.0 . diff --git a/lib/libcurses/curses_default_colors.3 b/lib/libcurses/curses_default_colors.3 new file mode 100644 index 000000000..2efd8c3fb --- /dev/null +++ b/lib/libcurses/curses_default_colors.3 @@ -0,0 +1,73 @@ +.\" $NetBSD: curses_default_colors.3,v 1.6 2008/04/30 13:10:51 martin Exp $ +.\" Copyright (c) 2002 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Julian Coleman. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd October 13, 2002 +.Dt CURSES_DEFAULT_COLORS 3 +.Os +.Sh NAME +.Nm curses_default_colors , +.Nm assume_default_colors , +.Nm use_default_colors +.Nd curses default colors setting routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft int +.Fn assume_default_colors "short fore" "short back" +.Ft int +.Fn use_default_colors "" +.Sh DESCRIPTION +These functions tell the curses library to set the default colors or to use +the terminal's default colors instead of using the default colors for curses +applications (which are white foreground on black background). +.Pp +The function +.Fn assume_default_colors fore back +sets the default colors to foreground color +.Fa fore +and background color +.Fa back . +If a value of \-1 is used for a color, then the terminal default color is used +for that color. +.Pp +The function +.Fn use_default_colors +sets both the foreground and background colors to the terminal default colors. +This is equivalent to +.Fn assume_default_colors \-1 \-1 . +.Sh RETURN VALUES +These functions return OK on success and ERR on failure. +.Sh SEE ALSO +.Xr curses_color 3 +.Sh STANDARDS +These functions are based on +.Em ncurses +extensions to the curses standards. +.Sh HISTORY +These functions first appeared in +.Nx 2.0 . diff --git a/lib/libcurses/curses_delch.3 b/lib/libcurses/curses_delch.3 new file mode 100644 index 000000000..5768a4fe5 --- /dev/null +++ b/lib/libcurses/curses_delch.3 @@ -0,0 +1,90 @@ +.\" $NetBSD: curses_delch.3,v 1.3 2003/04/16 13:35:01 wiz Exp $ +.\" +.\" Copyright (c) 2002 +.\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au) +.\" +.\" This code is donated to the NetBSD Foundation by the Author. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. The name of the Author may not be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" +.Dd August 12, 2002 +.Dt CURSES_DELCH 3 +.Os +.Sh NAME +.Nm curses_delch , +.Nm delch , +.Nm wdelch +.Nd curses delete characters routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft int +.Fn delch "void" +.Ft int +.Fn wdelch "WINDOW *win" +.Sh DESCRIPTION +These functions delete characters from +.Dv stdscr +or from the specified window. +.Pp +The +.Fn delch +function deletes the character at the current cursor position on +.Dv stdscr . +Characters to the right of the deleted character are moved one position +to the left. +The cursor position is unchanged. +.Pp +The +.Fn wdelch +function is the same as the +.Fn delch +function, excepting that the character is deleted from the specified window. +.Sh RETURN VALUES +Functions returning pointers will return +.Dv NULL +if an error is detected. +The functions that return an int will return one of the following +values: +.Pp +.Bl -tag -width ERR -compact +.It Er OK +The function completed successfully. +.It Er ERR +An error occurred in the function. +.El +.Sh SEE ALSO +.Xr curses_addch 3 , +.Xr curses_insertch 3 +.Sh STANDARDS +The +.Nx +Curses library complies with the X/Open Curses specification, part of the +Single Unix Specification. +.Sh HISTORY +The Curses package appeared in +.Bx 4.0 . diff --git a/lib/libcurses/curses_deleteln.3 b/lib/libcurses/curses_deleteln.3 new file mode 100644 index 000000000..c0324be15 --- /dev/null +++ b/lib/libcurses/curses_deleteln.3 @@ -0,0 +1,110 @@ +.\" $NetBSD: curses_deleteln.3,v 1.4 2003/04/16 13:35:01 wiz Exp $ +.\" +.\" Copyright (c) 2002 +.\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au) +.\" +.\" This code is donated to the NetBSD Foundation by the Author. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. The name of the Author may not be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" +.Dd August 12, 2002 +.Dt CURSES_DELETELN 3 +.Os +.Sh NAME +.Nm curses_deleteln , +.Nm deleteln , +.Nm wdeleteln +.Nd curses delete single line routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft int +.Fn deleteln "void" +.Ft int +.Fn wdeleteln "WINDOW *win" +.Sh DESCRIPTION +These functions delete a single line from +.Dv stdscr +or from the specified window. +.Pp +The +.Fn deleteln +function deletes the screen line containing the cursor in the +.Dv stdscr . +The +.Fn wdeleteln +function is the same as the +.Fn deleteln +function, excepting that the line is deleted from the window specified by +.Fa win . +.Pp +All lines following the deleted line are moved up one line toward the cursor. +The last line of the window is cleared. +The cursor position is unchanged. +.Pp +If a scrolling region has been set with the +.Fn setscrreg +or +.Fn wsetscrreg +functions and the current cursor position is inside the scrolling region, +then only the lines from the current line to the bottom of the scrolling +region are moved up and the bottom line of the scrolling region cleared. +.Pp +The functions +.Fn deleteln +and +.Fn wdeleteln win +are equivalent to +.Fn winsdelln stdscr \-1 +and +.Fn winsdelln win \-1 +respectively. +.Sh RETURN VALUES +Functions returning pointers will return +.Dv NULL +if an error is detected. +The functions that return an int will return one of the following +values: +.Pp +.Bl -tag -width ERR -compact +.It Er OK +The function completed successfully. +.It Er ERR +An error occurred in the function. +.El +.Sh SEE ALSO +.Xr curses_insdelln 3 , +.Xr curses_insertln 3 , +.Xr curses_scroll 3 +.Sh STANDARDS +The +.Nx +Curses library complies with the X/Open Curses specification, part of the +Single Unix Specification. +.Sh HISTORY +The Curses package appeared in +.Bx 4.0 . diff --git a/lib/libcurses/curses_echochar.3 b/lib/libcurses/curses_echochar.3 new file mode 100644 index 000000000..d2f8d4f87 --- /dev/null +++ b/lib/libcurses/curses_echochar.3 @@ -0,0 +1,123 @@ +.\" $NetBSD: curses_echochar.3,v 1.3 2008/04/30 13:10:51 martin Exp $ +.\" Copyright (c) 2004 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Julian Coleman. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd March 27, 2004 +.Dt CURSES_ECHOCHAR 3 +.Os +.Sh NAME +.Nm curses_echochar , +.Nm echochar , +.Nm wechochar , +.Nm pechochar +.Nd curses add characters and then refresh routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft int +.Fn echochar "const chtype ch" +.Ft int +.Fn wechochar "WINDOW *win" "const chtype ch" +.Ft int +.Fn pechochar "WINDOW *pad" "const chtype ch" +.Sh DESCRIPTION +These functions add characters to +.Dv stdscr +or to the specified window or pad and then cause an immediate +.Fn refresh +of that window or pad. +.Pp +The +.Fn echochar +function adds the character given in +.Fa ch +to +.Dv stdscr +at the current cursor position and advances the current cursor position by one. +Any character attributes set in +.Fa ch +will be merged with the background attributes currently set on +.Dv stdscr . +.Dv stdscr +is then refreshed. +Calling +.Fn echochar +is equivalent to calling +.Fn addch +followed by +.Fn refresh . +.Pp +The +.Fn wechochar +function is the same as the +.Fn echochar +function, excepting that the character is added to the window specified by +.Fa win +and +.Fa win +is refreshed. +.Pp +The +.Fn pechochar +function is the similar to the +.Fn echochar +function, excepting that the character is added to the pad specified by +.Fa pad +and +.Fa pad +is refreshed at its previous location on the screen. +Calling +.Fn pechochar +is equivalent to calling +.Fn addch +followed by +.Fn prefresh . +.Sh RETURN VALUES +These functions will return one of the following values: +.Pp +.Bl -tag -width ERR -compact +.It Er OK +The function completed successfully. +.It Er ERR +An error occurred in the function. +.El +.Sh SEE ALSO +.Xr curses_addch 3 , +.Xr curses_attributes 3 , +.Xr curses_pad 3 , +.Xr curses_refresh 3 +.Sh STANDARDS +The +.Fn echochar , +.Fn wechochar , +and +.Fn pechochar +functions comply with the X/Open Curses specification, part of the +Single Unix Specification. +.Sh HISTORY +The Curses package appeared in +.Bx 4.0 . diff --git a/lib/libcurses/curses_fileio.3 b/lib/libcurses/curses_fileio.3 new file mode 100644 index 000000000..f85c248d6 --- /dev/null +++ b/lib/libcurses/curses_fileio.3 @@ -0,0 +1,93 @@ +.\" $NetBSD: curses_fileio.3,v 1.4 2010/12/09 11:21:49 njoly Exp $ +.\" Copyright (c) 2008 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Julian Coleman. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd March 31, 2008 +.Dt CURSES_FILEIO 3 +.Os +.Sh NAME +.Nm curses_fileio , +.Nm getwin , +.Nm putwin +.Nd curses file input/output routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft WINDOW * +.Fn getwin "FILE *fp" +.Ft int +.Fn putwin "WINDOW *win" "FILE *fp" +.Sh DESCRIPTION +These functions read and write data to and from files. +.Pp +The +.Fn getwin +function reads window data that has been stored in the file to which +.Fa fp +points, and then creates a new window using that data. +.Pp +The +.Fn putwin +function writes window data from the window +.Fa win +to the file pointed to by +.Fa fp . +.Sh RETURN VALUES +The +.Fn getwin +function returns one of the following values: +.Pp +.Bl -tag -width ERR -compact +.It Er OK +The function completed successfully. +.It Er ERR +An error occurred in the function. +.El +.Pp +The +.Fn putwin +function returns +.Dv NULL +if an error is detected. +.Sh SEE ALSO +.Xr curses_window 3 , +.Xr fread 3 , +.Xr fwrite 3 +.Sh NOTES +Subwindows can not be created by the +.Fn getwin +function, nor written by the +.Fn putwin +function. +.Sh STANDARDS +The +.Nx +Curses library complies with the X/Open Curses specification, part of the +Single Unix Specification. +.Sh HISTORY +These functions first appeared in +.Nx 5.0 . diff --git a/lib/libcurses/curses_inch.3 b/lib/libcurses/curses_inch.3 new file mode 100644 index 000000000..c6d16f3df --- /dev/null +++ b/lib/libcurses/curses_inch.3 @@ -0,0 +1,257 @@ +.\" $NetBSD: curses_inch.3,v 1.10 2004/04/21 06:24:32 jdc Exp $ +.\" +.\" Copyright (c) 2002 +.\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au) +.\" +.\" This code is donated to the NetBSD Foundation by the Author. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. The name of the Author may not be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" +.Dd April 18, 2004 +.Dt CURSES_INCH 3 +.Os +.Sh NAME +.Nm curses_inch , +.Nm inch , +.Nm winch , +.Nm inchnstr , +.Nm mvinchnstr , +.Nm winchnstr , +.Nm mvwinchnstr , +.Nm inchstr , +.Nm mvinchstr , +.Nm winchstr , +.Nm mvwinchstr , +.Nm innstr , +.Nm winnstr , +.Nm mvinnstr , +.Nm mvwinnstr , +.Nm instr , +.Nm winstr +.Nm mvinstr , +.Nm mvwinstr +.Nd curses read screen contents routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft chtype +.Fn inch "void" +.Ft chtype +.Fn winch "WINDOW *win" +.Ft int +.Fn inchnstr "chtype *chars" "int n" +.Ft int +.Fn mvinchnstr "int y" "int x" "chtype *chstr" "int n" +.Ft int +.Fn winchnstr "WINDOW *win" "chtype *chars" "int n" +.Ft int +.Fn mvwinchnstr "WINDOW *win" "int y" "int x" "chtype *chstr" "int n" +.Ft int +.Fn inchstr "chtype *chars" +.Ft int +.Fn mvinchstr "int y" "int x" "chtype *chstr" +.Ft int +.Fn winchstr "WINDOW *win" "chtype *chars" +.Ft int +.Ft mvwinchstr "WINDOW *win" "int y" "int x" "chtype *chstr" +.Ft int +.Fn innstr "char *str" "int n" +.Ft int +.Fn winnstr "WINDOW *win" "char *str" "int n" +.Ft int +.Fn mvinnstr "int y" "int x" "char *str" "int n" +.Ft int +.Fn mvwinnstr "WINDOW *win" "int y" "int x" "char *str" "int n" +.Ft int +.Fn instr "char *str" +.Ft int +.Fn winstr "WINDOW *win" "char *str" +.Ft int +.Fn mvinstr "int y" "int x" "char *str" +.Ft int +.Fn mvwinstr "WINDOW *win" "int y" "int x" "char *str" +.Sh DESCRIPTION +These functions read the contents of +.Dv stdscr +or of the specified window. +.Pp +The +.Fn inch +function returns the character that is displayed on +.Dv stdscr +at the current cursor position. +.Pp +The +.Fn winch +function is the same as the +.Fn inch +function, excepting that the character is read from window specified by +.Fa win . +.Pp +The +.Fn inchnstr +function fills an array of +.Ft chtype +with characters read from +.Dv stdscr , +the characters are read starting from the current cursor position and +continuing until either n \- 1 characters are read or the right hand +side of the screen is reached. +The resulting character array will be +.Dv NULL +terminated. +.Pp +The +.Fn winchnstr +function is the same as +.Fn inchnstr +excepting that the characters are read from the window specified by +.Fa win . +.Pp +The +.Fn inchstr +and +.Fn winchstr +functions are the same as the +.Fn inchnstr +and +.Fn winchnstr +functions, respectively, excepting that they do not limit the number +of characters read. +The characters returned are those from the current starting position to +the right hand side of the screen. +The use of +.Fn inchstr +and +.Fn winchstr +is not recommended as the character buffer can be overflowed. +.Pp +The +.Fn innstr +function +is similar to the +.Fn inchstr +function, excepting that the array of characters returned is stripped of all +the curses attributes making it a plain character string. +.Pp +The +.Fn mvinchstr , +.Fn mvinchnstr , +.Fn mvwinchstr , +and +.Fn mvwinchnstr +functions are the same as the +.Fn inchstr , +.Fn inchnstr , +.Fn winchstr , +and +.Fn winchstr +functions, respectively, except that +.Fn wmove +is called to move the cursor to the position specified by +.Fa y , +.Fa x +before the output is printed on the window. +Likewise, the +.Fn mvinstr , +.Fn mvinnstr , +.Fn mvwinstr , +and +.Fn mvwinnstr +functions are the same as the +.Fn instr , +.Fn innstr , +.Fn winstr , +and +.Fn winstr +functions, respectively, except that +.Fn wmove +is called to move the cursor to the position specified by +.Fa y , +.Fa x +before the output is printed on the window. +.Pp +The +.Fn winnstr +function is the same as the +.Fn innstr +function, excepting that characters are read from the window specified by +.Fa win . +.Pp +The +.Fn instr +and +.Fn winstr +functions +are the same as the +.Fn innstr +and +.Fn winnstr +functions, respectively, excepting that there are no limits placed on the +size of the returned string, which may cause buffer overflows. +For this reason, the use of +.Fn instr +and +.Fn winstr +is not recommended. +.Sh RETURN VALUES +Functions returning pointers will return +.Dv NULL +if an error is detected. +The functions that return an int will return one of the following +values: +.Pp +.Bl -tag -width ERR -compact +.It Er OK +The function completed successfully. +.It Er ERR +An error occurred in the function. +.El +.Sh SEE ALSO +.Xr curses_addch 3 , +.Xr curses_addstr 3 , +.Xr curses_attributes 3 , +.Xr curses_insertch 3 +.Sh STANDARDS +The +.Nx +Curses library complies with the X/Open Curses specification, part +of the Single Unix Specification. +.Sh NOTES +The +.Fn inchnstr +and +.Fn innstr +function read at most n \- 1 characters from the screen so as to leave +room for +.Dv NULL +termination. +The X/Open specification is unclear as to whether or not this is the correct +behaviour. +.Sh HISTORY +The Curses package appeared in +.Bx 4.0 . diff --git a/lib/libcurses/curses_input.3 b/lib/libcurses/curses_input.3 new file mode 100644 index 000000000..8eb76a1f3 --- /dev/null +++ b/lib/libcurses/curses_input.3 @@ -0,0 +1,584 @@ +.\" $NetBSD: curses_input.3,v 1.21 2010/08/06 04:03:26 dholland Exp $ +.\" +.\" Copyright (c) 2002 +.\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au) +.\" +.\" This code is donated to the NetBSD Foundation by the Author. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. The name of the Author may not be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" +.Dd July 25, 2006 +.Dt CURSES_INPUT 3 +.Os +.Sh NAME +.Nm curses_input , +.Nm getch , +.Nm wgetch , +.Nm mvgetch , +.Nm mvwgetch , +.Nm define_key , +.Nm keyok , +.Nm getnstr , +.Nm wgetnstr , +.Nm mvgetnstr , +.Nm mvwgetnstr , +.Nm getstr , +.Nm wgetstr , +.Nm mvgetstr , +.Nm mvwgetstr , +.Nm keypad , +.Nm notimeout , +.Nm timeout , +.Nm wtimeout , +.Nm nodelay , +.Nm ungetch +.Nd curses input stream routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft int +.Fn getch "void" +.Ft int +.Fn wgetch "WINDOW *win" +.Ft int +.Fn mvgetch "int y" "int x" +.Ft int +.Fn mvwgetch "WINDOW *win" "int y" "int x" +.Ft int +.Fn keyok "int key_symbol" "bool flag" +.Ft int +.Fn define_key "char *sequence" "int key_symbol" +.Ft int +.Fn getnstr "char *str" "int limit" +.Ft int +.Fn wgetnstr "WINDOW *win" "char *str" "int limit" +.Ft int +.Fn mvgetnstr "int y" "int x" "char *str" "int limit" +.Ft int +.Fn mvwgetnstr "WINDOW *win" "int y" "int x" "char *str" "int limit" +.Ft int +.Fn getstr "char *str" +.Ft int +.Fn wgetstr "WINDOW *win" "char *str" +.Ft int +.Fn mvgetstr "int y" "int x" "char *str" +.Ft int +.Fn mvwgetstr "WINDOW *win" "int y" "int x" "char *str" +.Ft int +.Fn keypad "WINDOW *win" "boolf flag" +.Ft int +.Fn notimeout "WINDOW *win" "boolf flag" +.Ft int +.Fn timeout "int delay" +.Ft int +.Fn wtimeout "WINDOW *win" "int delay" +.Ft int +.Fn nodelay "WINDOW *win" "boolf flag" +.Ft int +.Fn ungetch "int c" +.Pp +.Va extern int ESCDELAY ; +.Sh DESCRIPTION +These functions read characters and strings from the window input file +descriptor. +.Pp +The +.Fn getch +function reads a character from the +.Dv stdscr +input file descriptor and returns it. +If the +.Fn keypad +flag has been set to +.Dv TRUE , +then +.Fn getch +will assemble multi-character key sequences into key symbols, +If the terminal is resized, +.Fn getch +will return +.Dv KEY_RESIZE , +regardless of the setting of +.Fn keypad . +Calling +.Fn getch +will cause an implicit +.Fn refresh +on +.Dv stdscr . +.Pp +The +.Fn wgetch +function is the same as the +.Fn getch +function, excepting that it reads from the input file descriptor associated +with the window specified by +.Fa win . +.Pp +If the +.Fn keypad +flag is +.Dv TRUE +then the assembly of specific key symbols can be disabled by using the +.Fn keyok +function. +If the +.Fa flag +is set to +.Dv FALSE +on a key symbol then +.Fn getch +will behave as if the character sequence associated with that key symbol +was not recognised and will return the component characters one at a time to +the caller. +.Pp +Custom associations between sequences of characters and a key symbol can +be made by using the +.Fn define_key +function. +Normally, these associations are made by the information in the +.Xr termcap 5 +database but the +.Fn define_key +function gives the capability to remove or add more associations. +If +.Fn define_key +is passed a non-NULL string in +.Fa sequence +it will associate that sequence with the key symbol passed in +.Fa key_symbol . +The key symbol may be one of the ones listed below or a custom value that +is application defined. +It is valid to have multiple character sequences map to the same key +symbol and there are no constraints on the length of the sequence allowed. +The assembly of custom sequences follow the same rules for inter-character +timing and so forth as the +.Xr termcap 5 +derived ones. +If +.Fn define_key +is passed a NULL in +.Fa sequence +then all associations for the key symbol in +.Fa key_symbol +will be deleted, this includes any associations that were derived from +.Xr termcap 5 . +.Pp +The +.Fn mvgetch +and +.Fn mvwgetch +functions are the same as the +.Fn getch +and +.Fn wgetch +functions, respectively, excepting that +.Fn wmove +is called to move the cursor to the position specified by +.Fa y , +.Fa x +before the character is read. +.Pp +Calling +.Fn getnstr , +.Fn wgetnstr , +.Fn mvgetnstr +or +.Fn mvwgetnstr +is effectively the same as calling +.Fn getch +repeatedly until a newline is received or the character limit +.Fa limit +is reached. +Once this happens the string is +.Dv NULL +terminated and returned in +.Fa str . +During input, the normal curses input key processing is performed and +affects the input buffer. +The +.Fn mvgetnstr +function calls +.Fn wmove +to move the cursor to the position given by +.Fa y , +.Fa x +before getting the string, +.Fn wgetnstr +reads the input from the designated window, +.Fn mvwgetnstr +moves the cursor to the position given by +.Fa y , +.Fa x +before getting the input from the designated window. +.Pp +The functions +.Fn getstr , +.Fn wgetstr , +.Fn mvgetstr , +and +.Fn mvwgetstr +are similar to +.Fn getnstr , +.Fn wgetnstr , +.Fn mvgetnstr , +and +.Fn mvwgetnstr , +respectively, excepting that there is no limit on the number of characters +that may be inserted into +.Fa str . +This may cause the buffer to be overflowed, so their use is not recommended. +.Pp +The +.Fn keypad +function is used to affect how +.Fn getch +processes input characters. +If +.Fa flag +is set to +.Dv TRUE , +then +.Fn getch +will scan the input stream looking for multi-character key sequences +that are emitted by some terminal function keys. +If a recognised sequence of characters is found, then +.Fn getch +will collapse that sequence into an integer key symbol, as shown below. +The default setting for the flag is +.Dv FALSE . +.Pp +The +.Fn notimeout +function controls whether or not +.Fn getch +will wait indefinitely between characters in a multi-character key +sequence or not. +If +.Fa flag +is +.Dv TRUE , +then there is no timeout applied between characters comprising a +multi-character key sequence. +If +.Fa flag +is +.Dv FALSE , +then the component characters of a multi-character sequence must not +have an inter-character gap of more than +.Va ESCDELAY . +If this timing is exceeded, then the multi-character key assembly is +deemed to have failed and the characters read thus far are returned +one at a time when +.Fn getch +is called. +The default setting for the flag is +.Dv FALSE . +The default value of +.Va ESCDELAY +is 300ms. +If +.Va ESCDELAY +is negative, no timeout is applied between characters comprising a +multi-character key sequence. +.Pp +The +.Fn timeout +function affects the behaviour of +.Fn getch +when reading a character from +.Dv stdscr . +If +.Fa delay +is negative, then +.Fn getch +will block indefinitely on a read. +If +.Fa delay +is 0, then +.Fn getch +will return immediately with +.Dv ERR +if there are no characters immediately available. +If +.Fa delay +is a positive number, then +.Fn getch +will wait for that many milliseconds before returning and, if no character +was available, then +.Dv ERR +will be returned. +Note that for a positive number, the timeout is only accurate to the nearest +tenth of a second. +Also, the maximum value of +.Fa delay +is 25500 milliseconds. +The +.Fn wtimeout +function does the same as +.Fn timeout +but applies to the specified window +.Fa win . +.Pp +The +.Fn nodelay +function turns on and off blocking reads for +.Fn getch . +If +.Fa flag +is +.Dv TRUE , +then +.Fn getch +will not block on reads, if +.Fa flag +is +.Dv FALSE , +then reads will block. +The default setting for the flag is +.Dv FALSE . +.Fn nodelay win TRUE +is equivalent to +.Fn wtimeout win 0 +and +.Fn nodelay win FALSE +is equivalent to +.Fn wtimeout win \-1 . +.Pp +.Fn ungetch +will convert +.Fa c +into an unsigned char and push that character back onto the input stream. +Only one character of push-back is guaranteed to work, more may be possible +depending on system resources. +.Sh RETURN VALUES +The functions +.Fn getch , +.Fn wgetch , +.Fn mvgetch , +and +.Fn mvwgetch +will return the value of the key pressed or +.Dv ERR +in the case of an error or a timeout. +Additionally, if +.Fn keypad TRUE +has been called on a window, then it may return one of the following values: +.Pp +.Bl -column "Termcap entry" "getch Return Value" "Key Function" -offset indent +.It Sy "Termcap entry" Ta Sy "getch Return Value" Ta Sy "Key Function" +.It \&!1 Ta KEY_SSAVE Ta Shift Save +.It \&!2 Ta KEY_SSUSPEND Ta Shift Suspend +.It \&!3 Ta KEY_SUNDO Ta Shift Undo +.It \ Ta KEY_SHELP Ta Shift Help +.It \ Ta KEY_SHOME Ta Shift Home +.It \ Ta KEY_SIC Ta Shift Insert Character +.It \ Ta KEY_SLEFT Ta Shift Left Arrow +.It \&%0 Ta KEY_REDO Ta Redo +.It \&%1 Ta KEY_HELP Ta Help +.It \&%2 Ta KEY_MARK Ta Mark +.It \&%3 Ta KEY_MESSAGE Ta Message +.It \&%4 Ta KEY_MOVE Ta Move +.It \&%5 Ta KEY_NEXT Ta Next Object +.It \&%6 Ta KEY_OPEN Ta Open +.It \&%7 Ta KEY_OPTIONS Ta Options +.It \&%8 Ta KEY_PREVIOUS Ta Previous Object +.It \&%9 Ta KEY_PRINT Ta Print +.It \&%a Ta KEY_SMESSAGE Ta Shift Message +.It \&%b Ta KEY_SMOVE Ta Shift Move +.It \&%c Ta KEY_SNEXT Ta Shift Next Object +.It \&%d Ta KEY_SOPTIONS Ta Shift Options +.It \&%e Ta KEY_SPREVIOUS Ta Shift Previous Object +.It \&%f Ta KEY_SPRINT Ta Shift Print +.It \&%g Ta KEY_SREDO Ta Shift Redo +.It \&%h Ta KEY_SREPLACE Ta Shift Replace +.It \&%i Ta KEY_SRIGHT Ta Shift Right Arrow +.It \&%j Ta KEY_SRSUME Ta Shift Resume +.It \&\*[Am]0 Ta KEY_SCANCEL Ta Shift Cancel +.It \&\*[Am]1 Ta KEY_REFERENCE Ta Reference +.It \&\*[Am]2 Ta KEY_REFRESH Ta Refresh +.It \&\*[Am]3 Ta KEY_REPLACE Ta Replace +.It \&\*[Am]4 Ta KEY_RESTART Ta Restart +.It \&\*[Am]5 Ta KEY_RESUME Ta Resume +.It \&\*[Am]6 Ta KEY_SAVE Ta Save +.It \&\*[Am]7 Ta KEY_SUSPEND Ta Suspend +.It \&\*[Am]8 Ta KEY_UNDO Ta Undo +.It \&\*[Am]9 Ta KEY_SBEG Ta Shift Begin +.It \&*0 Ta KEY_SFIND Ta Shift Find +.It \&*1 Ta KEY_SCOMMAND Ta Shift Command +.It \&*2 Ta KEY_SCOPY Ta Shift Copy +.It \&*3 Ta KEY_SCREATE Ta Shift Create +.It \&*4 Ta KEY_SDC Ta Shift Delete Character +.It \&*5 Ta KEY_SDL Ta Shift Delete Line +.It \&*6 Ta KEY_SELECT Ta Select +.It \&*7 Ta KEY_SEND Ta Shift End +.It \&*8 Ta KEY_SEOL Ta Shift Clear to EOL +.It \&*9 Ta KEY_SEXIT Ta Shift Exit +.It \&@0 Ta KEY_FIND Ta Find +.It \&@1 Ta KEY_BEG Ta Begin +.It \&@2 Ta KEY_CANCEL Ta Cancel +.It \&@3 Ta KEY_CLOSE Ta Close +.It \&@4 Ta KEY_COMMAND Ta Command +.It \&@5 Ta KEY_COPY Ta Copy +.It \&@6 Ta KEY_CREATE Ta Create +.It \&@7 Ta KEY_END Ta End +.It \&@8 Ta KEY_ENTER Ta Enter +.It \&@9 Ta KEY_EXIT Ta Exit +.It \&F1 Ta KEY_F(11) Ta Function Key 11 +.It \&F2 Ta KEY_F(12) Ta Function Key 12 +.It \&F3 Ta KEY_F(13) Ta Function Key 13 +.It \&F4 Ta KEY_F(14) Ta Function Key 14 +.It \&F5 Ta KEY_F(15) Ta Function Key 15 +.It \&F6 Ta KEY_F(16) Ta Function Key 16 +.It \&F7 Ta KEY_F(17) Ta Function Key 17 +.It \&F8 Ta KEY_F(18) Ta Function Key 18 +.It \&F9 Ta KEY_F(19) Ta Function Key 19 +.It \&FA Ta KEY_F(20) Ta Function Key 20 +.It \&FB Ta KEY_F(21) Ta Function Key 21 +.It \&FC Ta KEY_F(22) Ta Function Key 22 +.It \&FD Ta KEY_F(23) Ta Function Key 23 +.It \&FE Ta KEY_F(24) Ta Function Key 24 +.It \&FF Ta KEY_F(25) Ta Function Key 25 +.It \&FG Ta KEY_F(26) Ta Function Key 26 +.It \&FH Ta KEY_F(27) Ta Function Key 27 +.It \&FI Ta KEY_F(28) Ta Function Key 28 +.It \&FJ Ta KEY_F(29) Ta Function Key 29 +.It \&FK Ta KEY_F(30) Ta Function Key 30 +.It \&FL Ta KEY_F(31) Ta Function Key 31 +.It \&FM Ta KEY_F(32) Ta Function Key 32 +.It \&FN Ta KEY_F(33) Ta Function Key 33 +.It \&FO Ta KEY_F(34) Ta Function Key 34 +.It \&FP Ta KEY_F(35) Ta Function Key 35 +.It \&FQ Ta KEY_F(36) Ta Function Key 36 +.It \&FR Ta KEY_F(37) Ta Function Key 37 +.It \&FS Ta KEY_F(38) Ta Function Key 38 +.It \&FT Ta KEY_F(39) Ta Function Key 39 +.It \&FU Ta KEY_F(40) Ta Function Key 40 +.It \&FV Ta KEY_F(41) Ta Function Key 41 +.It \&FW Ta KEY_F(42) Ta Function Key 42 +.It \&FX Ta KEY_F(43) Ta Function Key 43 +.It \&FY Ta KEY_F(44) Ta Function Key 44 +.It \&FZ Ta KEY_F(45) Ta Function Key 45 +.It \&Fa Ta KEY_F(46) Ta Function Key 46 +.It \&Fb Ta KEY_F(47) Ta Function Key 47 +.It \&Fc Ta KEY_F(48) Ta Function Key 48 +.It \&Fd Ta KEY_F(49) Ta Function Key 49 +.It \&Fe Ta KEY_F(50) Ta Function Key 50 +.It \&Ff Ta KEY_F(51) Ta Function Key 51 +.It \&Fg Ta KEY_F(52) Ta Function Key 52 +.It \&Fh Ta KEY_F(53) Ta Function Key 53 +.It \&Fi Ta KEY_F(54) Ta Function Key 54 +.It \&Fj Ta KEY_F(55) Ta Function Key 55 +.It \&Fk Ta KEY_F(56) Ta Function Key 56 +.It \&Fl Ta KEY_F(57) Ta Function Key 57 +.It \&Fm Ta KEY_F(58) Ta Function Key 58 +.It \&Fn Ta KEY_F(59) Ta Function Key 59 +.It \&Fo Ta KEY_F(60) Ta Function Key 60 +.It \&Fp Ta KEY_F(61) Ta Function Key 61 +.It \&Fq Ta KEY_F(62) Ta Function Key 62 +.It \&Fr Ta KEY_F(63) Ta Function Key 63 +.It \&K1 Ta KEY_A1 Ta Upper left key in keypad +.It \&K2 Ta KEY_B2 Ta Centre key in keypad +.It \&K3 Ta KEY_A3 Ta Upper right key in keypad +.It \&K4 Ta KEY_C1 Ta Lower left key in keypad +.It \&K5 Ta KEY_C3 Ta Lower right key in keypad +.It \&Km Ta KEY_MOUSE Ta Mouse Event +.It \&k0 Ta KEY_F0 Ta Function Key 0 +.It \&k1 Ta KEY_F(1) Ta Function Key 1 +.It \&k2 Ta KEY_F(2) Ta Function Key 2 +.It \&k3 Ta KEY_F(3) Ta Function Key 3 +.It \&k4 Ta KEY_F(4) Ta Function Key 4 +.It \&k5 Ta KEY_F(5) Ta Function Key 5 +.It \&k6 Ta KEY_F(6) Ta Function Key 6 +.It \&k7 Ta KEY_F(7) Ta Function Key 7 +.It \&k8 Ta KEY_F(8) Ta Function Key 8 +.It \&k9 Ta KEY_F(9) Ta Function Key 9 +.It \&k; Ta KEY_F(10) Ta Function Key 10 +.It \&kA Ta KEY_IL Ta Insert Line +.It \&ka Ta KEY_CATAB Ta Clear All Tabs +.It \&kB Ta KEY_BTAB Ta Back Tab +.It \&kb Ta KEY_BACKSPACE Ta Backspace +.It \&kC Ta KEY_CLEAR Ta Clear +.It \&kD Ta KEY_DC Ta Delete Character +.It \&kd Ta KEY_DOWN Ta Down Arrow +.It \&kE Ta KEY_EOL Ta Clear to End Of Line +.It \&kF Ta KEY_SF Ta Scroll Forward one line +.It \&kH Ta KEY_LL Ta Home Down +.It \&kh Ta KEY_HOME Ta Home +.It \&kI Ta KEY_IC Ta Insert Character +.It \&kL Ta KEY_DL Ta Delete Line +.It \&kl Ta KEY_LEFT Ta Left Arrow +.It \&kM Ta KEY_EIC Ta Exit Insert Character Mode +.It \&kN Ta KEY_NPAGE Ta Next Page +.It \&kP Ta KEY_PPAGE Ta Previous Page +.It \&kR Ta KEY_SR Ta Scroll One Line Back +.It \&kr Ta KEY_RIGHT Ta Right Arrow +.It \&kS Ta KEY_EOS Ta Clear to End Of Screen +.It \&kT Ta KEY_STAB Ta Set Tab +.It \&kt Ta KEY_CTAB Ta Clear Tab +.It \&ku Ta KEY_UP Ta Up Arrow +.El +.Pp +Note that not all terminals are capable of generating all the keycodes +listed above nor are termcap entries normally configured with all the +above capabilities defined. +.Pp +Other functions that return an int will return one of the following +values: +.Pp +.Bl -tag -width ERR -compact +.It Er OK +The function completed successfully. +.It Er ERR +An error occurred in the function. +.El +.Pp +Functions returning pointers will return +.Dv NULL +if an error is detected. +.Sh SEE ALSO +.Xr curses_cursor 3 , +.Xr curses_keyname 3 , +.Xr curses_refresh 3 , +.Xr curses_tty 3 , +.Xr termcap 5 +.Sh STANDARDS +The +.Nx +Curses library complies with the X/Open Curses specification, part of the +Single Unix Specification. +.Sh NOTES +The +.Fn keyok +and +.Fn define_key +functions are implementations of extensions made by the NCurses library +to the Curses standard. +Portable implementations should avoid the use of these functions. +.Sh HISTORY +The Curses package appeared in +.Bx 4.0 . diff --git a/lib/libcurses/curses_insdelln.3 b/lib/libcurses/curses_insdelln.3 new file mode 100644 index 000000000..b590d125b --- /dev/null +++ b/lib/libcurses/curses_insdelln.3 @@ -0,0 +1,115 @@ +.\" $NetBSD: curses_insdelln.3,v 1.3 2003/04/16 13:35:01 wiz Exp $ +.\" +.\" Copyright (c) 2002 +.\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au) +.\" +.\" This code is donated to the NetBSD Foundation by the Author. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. The name of the Author may not be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" +.Dd August 12, 2002 +.Dt CURSES_INSDEL 3 +.Os +.Sh NAME +.Nm curses_insdelln , +.Nm insdelln , +.Nm winsdelln +.Nd curses insert or delete lines routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft int +.Fn insdelln "int n" +.Ft int +.Fn winsdelln "WINDOW *win" "int n" +.Sh DESCRIPTION +These functions insert or delete lines on +.Dv stdscr +or on the specified window. +.Pp +If +.Fn insdelln +is called with a positive number in +.Fa n , +then the specified number of lines are inserted before the current line on +.Dv stdscr . +The last +.Fa n +lines of the screen are no longer displayed. +If +.Fa n +is negative, then +.Fa n +lines are deleted from +.Dv stdscr , +starting at the current line. +The last +.Fa n +lines of +.Dv stdscr +are cleared. +.Pp +The +.Fn winsdelln +function is the same as the +.Fn insdelln +function, excepting that lines are inserted or deleted from the window +specified by +.Fa win . +.Pp +If a scrolling region has been set with the +.Fn setscrreg +or +.Fn wsetscrreg +functions and the current cursor position is inside the scrolling region, +then only the lines from the current line to the bottom of the scrolling +region are affected. +.Sh RETURN VALUES +Functions returning pointers will return +.Dv NULL +if an error is detected. +The functions that return an int will return one of the following +values: +.Pp +.Bl -tag -width ERR -compact +.It Er OK +The function completed successfully. +.It Er ERR +An error occurred in the function. +.El +.Sh SEE ALSO +.Xr curses_deleteln 3 , +.Xr curses_insertln 3 , +.Xr curses_scroll 3 +.Sh STANDARDS +The +.Nx +Curses library complies with the X/Open Curses specification, part of +the Single Unix Specification. +.Sh HISTORY +The Curses package appeared in +.Bx 4.0 . diff --git a/lib/libcurses/curses_insertch.3 b/lib/libcurses/curses_insertch.3 new file mode 100644 index 000000000..c5c13e712 --- /dev/null +++ b/lib/libcurses/curses_insertch.3 @@ -0,0 +1,113 @@ +.\" $NetBSD: curses_insertch.3,v 1.4 2006/02/05 17:07:13 jdc Exp $ +.\" +.\" Copyright (c) 2002 +.\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au) +.\" +.\" This code is donated to the NetBSD Foundation by the Author. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. The name of the Author may not be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" +.Dd February 5, 2006 +.Dt CURSES_INSERTCH 3 +.Os +.Sh NAME +.Nm curses_insert , +.Nm insch , +.Nm winsch , +.Nm mvinsch , +.Nm mvwinsch +.Nd curses insert characters routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft int +.Fn insch "chtype ch" +.Ft int +.Fn winsch "WINDOW *win" "chtype ch" +.Ft int +.Fn mvinsch "int y" "int x" "chtype ch" +.Ft int +.Fn mvwinsch "WINDOW *win" "int y" "int x" "chtype ch" +.Sh DESCRIPTION +These functions insert characters on +.Dv stdscr +or on the specified window. +.Pp +The +.Fn insch +function inserts the character given in +.Fa ch +at the current cursor position on +.Dv stdscr . +The cursor is not advanced and wrapping is not performed. +.Pp +The +.Fn winsch +function is the same as the +.Fn insch +function, excepting that the character is inserted on the window specified by +.Fa win . +.Pp +The +.Fn mvinsch +and +.Fn mvwinsch +functions are the same as the +.Fn insch +and +.Fn insch +functions, respectively, excepting that +.Fn wmove +is called to move the cursor to the position specified by +.Fa y , +.Fa x +before the character is inserted on the window. +.Sh RETURN VALUES +Functions returning pointers will return +.Dv NULL +if an error is detected. +The functions that return an int will return one of the following +values: +.Pp +.Bl -tag -width ERR -compact +.It Er OK +The function completed successfully. +.It Er ERR +An error occurred in the function. +.El +.Sh SEE ALSO +.Xr curses_addch 3 , +.Xr curses_cursor 3 , +.Xr curses_delch 3 +.Sh STANDARDS +The +.Nx +Curses library complies with the X/Open Curses specification, part of +the Single Unix Specification. +.Sh HISTORY +The Curses package appeared in +.Bx 4.0 . diff --git a/lib/libcurses/curses_insertln.3 b/lib/libcurses/curses_insertln.3 new file mode 100644 index 000000000..6cd325e12 --- /dev/null +++ b/lib/libcurses/curses_insertln.3 @@ -0,0 +1,109 @@ +.\" $NetBSD: curses_insertln.3,v 1.4 2006/02/05 17:07:13 jdc Exp $ +.\" +.\" Copyright (c) 2002 +.\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au) +.\" +.\" This code is donated to the NetBSD Foundation by the Author. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. The name of the Author may not be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" +.Dd February 5, 2006 +.Dt CURSES_INSERTLN 3 +.Os +.Sh NAME +.Nm curses_insertln , +.Nm insertln , +.Nm winsertln +.Nd curses insert single line routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft int +.Fn insertln "void" +.Ft int +.Fn winsertln "WINDOW *win" +.Sh DESCRIPTION +These functions insert a single line on +.Dv stdscr +or on the specified window. +.Pp +The +.Fn insertln +function inserts a blank line before the current line on +.Dv stdscr . +The current line and all lines below are moved down one line away from +the cursor and the bottom line of the window is lost. +.Pp +The +.Fn winsertln +function is the same as the +.Fn insertln +function, excepting that the line is inserted on the window +.Fa win . +.Pp +If a scrolling region has been set with the +.Fn setscrreg +or +.Fn wsetscrreg +functions and the current cursor position is inside the scrolling region, +then only the lines from the current line to the bottom of the scrolling +region are moved down and the bottom line of the scrolling region lost. +.Pp +The functions +.Fn insertln +and +.Fn winsertln win +are equivalent to +.Fn insdelln 1 +and +.Fn winsdelln win 1 , +respectively. +.Sh RETURN VALUES +Functions returning pointers will return +.Dv NULL +if an error is detected. +The functions that return an int will return one of the following +values: +.Pp +.Bl -tag -width ERR -compact +.It Er OK +The function completed successfully. +.It Er ERR +An error occurred in the function. +.El +.Sh SEE ALSO +.Xr curses_deleteln 3 , +.Xr curses_insdelln 3 , +.Xr curses_scroll 3 +.Sh STANDARDS +The +.Nx +Curses library complies with the X/Open Curses specification, part of +the Single Unix Specification. +.Sh HISTORY +The Curses package appeared in +.Bx 4.0 . diff --git a/lib/libcurses/curses_keyname.3 b/lib/libcurses/curses_keyname.3 new file mode 100644 index 000000000..bb0bda0d1 --- /dev/null +++ b/lib/libcurses/curses_keyname.3 @@ -0,0 +1,72 @@ +.\" $NetBSD: curses_keyname.3,v 1.5 2008/04/30 13:10:51 martin Exp $ +.\" Copyright (c) 2002 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Julian Coleman. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd October 17, 2007 +.Dt CURSES_KEYNAME 3 +.Os +.Sh NAME +.Nm curses_keyname , +.Nm keyname +.Nd curses report key name routine +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft "char *" +.Fn keyname "int key" +.Sh DESCRIPTION +The function +.Fn keyname +generates a character string containing a description of the key specified in +.Fa key . +.Pp +The string is formatted according to the following table: +.Bl -column "Meta + control character" "KEY_MIN - KEY_MAX" "String format" +.It "Description" Ta "Key range" Ta "String format" +.It Li "Control character" Ta "0 - 31" Ta "^X" +.It Li "Visible character" Ta "32 - 126" Ta "X" +.It Li "Delete character" Ta "127" Ta "^?" +.It Li "Meta + control character" Ta "128 - 158" Ta "M-^X" +.It Li "Meta + visible character" Ta "159 - 254" Ta "M-X" +.It Li "Meta + delete character" Ta "255" Ta "M-^?" +.It Li "Named key" Ta "KEY_MIN - KEY_MAX" Ta "KEY_EXIT" +.It Li "Unknown key" Ta "" Ta "-1" +.El +.Sh SEE ALSO +.Xr curses_input 3 +.Sh NOTE +The return value of +.Fn keyname +is a static buffer, which will be overwritten on a subsequent call. +.Sh STANDARDS +The +.Nx +Curses library complies with the X/Open Curses specification, part of the +Single Unix Specification. +.Sh HISTORY +These functions first appeared in +.Nx 2.0 . diff --git a/lib/libcurses/curses_line.3 b/lib/libcurses/curses_line.3 new file mode 100644 index 000000000..7da7b5318 --- /dev/null +++ b/lib/libcurses/curses_line.3 @@ -0,0 +1,171 @@ +.\" $NetBSD: curses_line.3,v 1.6 2010/02/20 10:23:04 wiz Exp $ +.\" +.\" Copyright (c) 2002 +.\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au) +.\" +.\" This code is donated to the NetBSD Foundation by the Author. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. The name of the Author may not be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" +.Dd February 19, 2010 +.Dt CURSES_LINE 3 +.Os +.Sh NAME +.Nm curses_line , +.Nm hline , +.Nm whline , +.Nm vline , +.Nm wvline , +.Nm mvhline , +.Nm mvwhline , +.Nm mvvline , +.Nm mvwvline +.Nd curses draw lines on windows routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft int +.Fn hline "chtype ch" "int n" +.Ft int +.Fn whline "WINDOW *win" "chtype ch" "int n" +.Ft int +.Fn mvhline "int y" "int x" "chtype ch" "int n" +.Ft int +.Fn mvwvline "WINDOW *win" "int y" "int x" "chtype c" "int n" +.Ft int +.Fn vline "chtype c" "int n" +.Ft int +.Fn wvline "WINDOW *win" "chtype c" "int n" +.Ft int +.Fn mvvline "int y" "int x" "chtype ch" "int n" +.Ft int +.Fn mvwhline "WINDOW *win" "int y" "int x" "chtype c" "int n" +.Sh DESCRIPTION +These functions draw lines on +.Dv stdscr +or on the specified window. +.Pp +The +.Fn hline +function draws a horizontal line of the character +.Fa ch +on +.Dv stdscr +starting at the current cursor position and extending for +.Fa n +characters, or until the right hand side of +.Dv stdscr +is reached. +If the text portion of +.Fa ch +is 0 then the line will be drawn with the +.Dv ACS_HLINE +character. +.Pp +The +.Fn whline +function is the same as the +.Fn hline +function, excepting that the line is drawn in the window specified by +.Fa win . +.Pp +The +.Fn vline +function draws a vertical line of character +.Fa ch +on +.Dv stdscr +starting at the current cursor position and moving down until either +.Fa n +characters have been drawn or the bottom of +.Dv stdscr +is reached. +If the text portion of +.Fa ch +is 0 then the line will be drawn with the +.Dv ACS_VLINE +character. +.Pp +The +.Fn wvline +function is the same as the +.Fn vline +function, excepting that the line is drawn on the given window. +.Pp +The +.Fn mvhline , +.Fn mvwhline , +.Fn mvvline +and +.Fn mvwvline +functions are the same as the +.Fn hline , +.Fn whline , +.Fn vline +and +.Fn wvline +functions, respectively, excepting that +.Fn wmove +is called to move the cursor to the position specified by +.Fa y , +.Fa x +before the line is drawn on the window. +.Sh RETURN VALUES +Functions returning pointers will return +.Dv NULL +if an error is detected. +The functions that return an int will return one of the following +values: +.Pp +.Bl -tag -width ERR -compact +.It Er OK +The function completed successfully. +.It Er ERR +An error occurred in the function. +.El +.Sh SEE ALSO +.Xr curses_border 3 +.Sh STANDARDS +The +.Nx +Curses library complies with the X/Open Curses specification, part of +the Single Unix Specification. +.Pp +The use of +.Dv ACS_HLINE +and +.Dv ACS_VLINE +as default drawing character in +.Fn hline +and +.Fn vline +is a +.Nx +extension which should not be relied on in portable code. +.Sh HISTORY +The Curses package appeared in +.Bx 4.0 . diff --git a/lib/libcurses/curses_pad.3 b/lib/libcurses/curses_pad.3 new file mode 100644 index 000000000..00488b0a0 --- /dev/null +++ b/lib/libcurses/curses_pad.3 @@ -0,0 +1,142 @@ +.\" $NetBSD: curses_pad.3,v 1.4 2008/04/30 13:10:51 martin Exp $ +.\" Copyright (c) 2002 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Julian Coleman. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd December 4, 2002 +.Dt CURSES_PAD 3 +.Os +.Sh NAME +.Nm curses_pad , +.Nm newpad , +.Nm subpad , +.Nm prefresh , +.Nm pnoutrefresh +.Nd curses pad routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft WINDOW * +.Fn newpad "int lines" "int cols" +.Ft WINDOW * +.Fn subpad "WINDOW *pad" "int lines" "int cols" "int begin_y" "int begin_x" +.Ft int +.Fn prefresh "WINDOW *pad" "int pbeg_y" "int pbeg_x" "int sbeg_y" "int sbeg_x" "int smax_y" "int smax_x" +.Ft int +.Fn pnoutrefresh "WINDOW *pad" "int pbeg_y" "int pbeg_x" "int sbeg_y" "int sbeg_x" "int smax_y" "int smax_x" +.Sh DESCRIPTION +These functions create and display pads on the current screen. +.Pp +The +.Fn newpad +function creates a new pad of size +.Fa lines , +.Fa cols . +.Pp +.Fn subpad +is similar to +.Fn newpad +excepting that the size of the subpad is bounded by the parent +pad +.Fa pad . +The subpad shares internal data structures with the parent pad +and will be refreshed when the parent pad is refreshed. +The starting column and row +.Fa begin_y , +.Fa begin_x +are relative to the parent pad origin. +.Pp +The +.Fn pnoutrefresh +function performs the internal processing required by curses to determine +what changes need to be made to synchronise the internal screen buffer +and the terminal but does not modify the terminal display. +A rectangular area of the pad starting at column and row +.Fa pbeg_y , +.Fa pbeg_x +is copied to the corresponding rectangular area of the screen buffer starting +at column and row +.Fa sbeg_y , +.Fa sbeg_x +and extending to +.Fa smax_y , +.Fa smax_x . +.Pp +The +.Fn prefresh +function causes curses to propagate changes made to the pad specified by +.Fa pad +to the terminal display. +A rectangular area of the pad starting at column and row +.Fa pbeg_y , +.Fa pbeg_x +is copied to the corresponding rectangular area of the terminal starting +at column and row +.Fa sbeg_y , +.Fa sbeg_x +and extending to +.Fa smax_y , +.Fa smax_x . +.Pp +The +.Fn pnoutrefresh +and +.Fn doupdate +functions can be used together to speed up terminal redraws by +deferring the actual terminal updates until after a batch of updates +to multiple pads has been done. +.Sh RETURN VALUES +Functions returning pointers will return +.Dv NULL +if an error is detected. +The functions that return an int will return one of the following +values: +.Pp +.Bl -tag -width ERR -compact +.It Er OK +The function completed successfully. +.It Er ERR +An error occurred in the function. +.El +.Sh SEE ALSO +.Xr curses_refresh 3 , +.Xr curses_window 3 +.Sh NOTES +The +.Fn subpad +function is similar to the +.Xr derwin 3 +function, and not the +.Xr subwin 3 +function. +.Sh STANDARDS +The +.Nx +Curses library complies with the X/Open Curses specification, part of the +Single Unix Specification. +.Sh HISTORY +The Curses package appeared in +.Bx 4.0 . diff --git a/lib/libcurses/curses_print.3 b/lib/libcurses/curses_print.3 new file mode 100644 index 000000000..cc5172d05 --- /dev/null +++ b/lib/libcurses/curses_print.3 @@ -0,0 +1,124 @@ +.\" $NetBSD: curses_print.3,v 1.6 2003/04/16 13:35:01 wiz Exp $ +.\" +.\" Copyright (c) 2002 +.\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au) +.\" +.\" This code is donated to the NetBSD Foundation by the Author. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. The name of the Author may not be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" +.Dd August 12, 2002 +.Dt CURSES_PRINT 3 +.Os +.Sh NAME +.Nm curses_print , +.Nm printw , +.Nm wprintw , +.Nm mvprintw , +.Nm mvwprintw , +.Nm unctrl +.Nd curses print formatted strings on windows routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft int +.Fn printw "const char *fmt" "..." +.Ft int +.Fn wprintw "WINDOW *win" "const char *fmt" "..." +.Ft int +.Fn mvprintw "int y" "int x" "const char *fmt" "..." +.Ft int +.Fn mvwprintw "WINDOW *win" "int y" "int x" "const char *fmt" "..." +.Ft char * +.Fn unctrl "chtype ch" +.Sh DESCRIPTION +These functions print formatted strings on +.Dv stdscr +or on the specified window. +.Pp +The +.Fn printw +function formats and prints its arguments on +.Dv stdscr . +The behaviour is the same as that of +.Fn printf . +.Pp +The +.Fn wprintw +function is the same as the +.Fn printw +function, excepting that the resulting output is printed on the window +specified by +.Fa win . +.Pp +The +.Fn mvprintw +and +.Fn mvwprintw +functions are the same as the +.Fn printw +and +.Fn wprintw +functions, respectively, excepting that +.Fn wmove +is called to move the cursor to the position specified by +.Fa y , +.Fa x +before the output is printed on the window. +.Pp +The +.Fn unctrl +function returns a printable string representation of the character +.Fa ch . +If +.Fa ch +is a control character then it will be converted to the form ^Y. +.Sh RETURN VALUES +Functions returning pointers will return +.Dv NULL +if an error is detected. +The functions that return an int will return one of the following +values: +.Pp +.Bl -tag -width ERR -compact +.It Er OK +The function completed successfully. +.It Er ERR +An error occurred in the function. +.El +.Sh SEE ALSO +.Xr curses_cursor 3 , +.Xr curses_scanw 3 , +.Xr printf 3 +.Sh STANDARDS +The +.Nx +Curses library complies with the X/Open Curses specification, part of the +Single Unix Specification. +.Sh HISTORY +The Curses package appeared in +.Bx 4.0 . diff --git a/lib/libcurses/curses_private.h b/lib/libcurses/curses_private.h new file mode 100644 index 000000000..fcd19d46c --- /dev/null +++ b/lib/libcurses/curses_private.h @@ -0,0 +1,360 @@ +/* $NetBSD: curses_private.h,v 1.46 2010/12/16 17:42:28 wiz Exp $ */ + +/*- + * Copyright (c) 1998-2000 Brett Lymn + * (blymn@baea.com.au, brett_lymn@yahoo.com.au) + * All rights reserved. + * + * This code has been donated to The NetBSD Foundation by the Author. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + */ + +/* Modified by Ruibiao Qiu + * to add support for wide characters + * Changes: + * - Add a compiler variable HAVE_WCHAR for wide character only code + * - Add a pointer to liked list of non-spacing characters in __ldata + * and the macro to access the width field in the attribute field + * - Add a circular input character buffer in __screen to handle + * wide-character input (used in get_wch()) + */ + +#include +#include + +/* Private structure definitions for curses. */ + +/* Termcap capabilities. */ +#ifdef HAVE_WCHAR +/* + * Add a list of non-spacing characters to each spacing + * character in a singly linked list + */ +typedef struct nschar_t { + wchar_t ch; /* Non-spacing character */ + struct nschar_t *next; /* Next non-spacing character */ +} nschar_t; +#endif /* HAVE_WCHAR */ + +/* + * A window is an array of __LINE structures pointed to by the 'lines' pointer. + * A line is an array of __LDATA structures pointed to by the 'line' pointer. + * + * IMPORTANT: the __LDATA structure must NOT induce any padding, so if new + * fields are added -- padding fields with *constant values* should ensure + * that the compiler will not generate any padding when storing an array of + * __LDATA structures. This is to enable consistent use of memcmp, and memcpy + * for comparing and copying arrays. + */ + +struct __ldata { + wchar_t ch; /* Character */ + attr_t attr; /* Attributes */ +#ifdef HAVE_WCHAR + nschar_t *nsp; /* Foreground non-spacing character pointer */ +#endif /* HAVE_WCHAR */ +}; + +#ifdef HAVE_WCHAR +/* macros to extract the width of a wide character */ +#define __WCWIDTH 0xfc000000 +#define WCW_SHIFT 26 +#define WCOL(wc) ((((unsigned) (wc).attr) >> WCW_SHIFT ) > MB_LEN_MAX ? ((int)(((unsigned) (wc).attr ) >> WCW_SHIFT )) - 64 : ((int)(((unsigned) (wc).attr ) >> WCW_SHIFT))) +#define SET_WCOL(c, w) do { \ + ((c).attr) = ((((c).attr) & WA_ATTRIBUTES ) | ((w) << WCW_SHIFT )); \ +} while(/*CONSTCOND*/0) +#define BGWCOL(wc) ((((wc).battr) >> WCW_SHIFT ) > MB_LEN_MAX ? (((wc).battr ) >> WCW_SHIFT ) - 64 : (((wc).battr ) >> WCW_SHIFT )) +#define SET_BGWCOL(c, w) do { \ + ((c).battr) = ((((c).battr) & WA_ATTRIBUTES ) | ((w) << WCW_SHIFT )); \ +} while(/*CONSTCOND*/0) +#endif /* HAVE_WCHAR */ + +#define __LDATASIZE (sizeof(__LDATA)) + +struct __line { +#ifdef DEBUG +#define SENTINEL_VALUE 0xaac0ffee + + unsigned int sentinel; /* try to catch line overflows */ +#endif +#define __ISDIRTY 0x01 /* Line is dirty. */ +#define __ISPASTEOL 0x02 /* Cursor is past end of line */ + unsigned int flags; + unsigned int hash; /* Hash value for the line. */ + int *firstchp, *lastchp; /* First and last chngd columns ptrs */ + int firstch, lastch; /* First and last changed columns. */ + __LDATA *line; /* Pointer to the line text. */ +}; + +struct __window { /* Window structure. */ + struct __window *nextp, *orig; /* Subwindows list and parent. */ + int begy, begx; /* Window home. */ + int cury, curx; /* Current x, y coordinates. */ + int maxy, maxx; /* Maximum values for curx, cury. */ + int reqy, reqx; /* Size requested when created */ + int ch_off; /* x offset for firstch/lastch. */ + __LINE **alines; /* Array of pointers to the lines */ + __LINE *lspace; /* line space (for cleanup) */ + __LDATA *wspace; /* window space (for cleanup) */ + +#define __ENDLINE 0x00000001 /* End of screen. */ +#define __FLUSH 0x00000002 /* Fflush(stdout) after refresh. */ +#define __FULLWIN 0x00000004 /* Window is a screen. */ +#define __IDLINE 0x00000008 /* Insert/delete sequences. */ +#define __SCROLLWIN 0x00000010 /* Last char will scroll window. */ +#define __SCROLLOK 0x00000020 /* Scrolling ok. */ +#define __CLEAROK 0x00000040 /* Clear on next refresh. */ +#define __LEAVEOK 0x00000100 /* If cursor left */ +#define __KEYPAD 0x00010000 /* If interpreting keypad codes */ +#define __NOTIMEOUT 0x00020000 /* Wait indefinitely for func keys */ +#define __IDCHAR 0x00040000 /* insert/delete char sequences */ +#define __ISPAD 0x00080000 /* "window" is a pad */ + unsigned int flags; + int delay; /* delay for getch() */ + attr_t wattr; /* Character attributes */ + wchar_t bch; /* Background character */ + attr_t battr; /* Background attributes */ + int scr_t, scr_b; /* Scrolling region top, bottom */ + SCREEN *screen; /* Screen for this window */ + int pbegy, pbegx, + sbegy, sbegx, + smaxy, smaxx; /* Saved prefresh() values */ +#ifdef HAVE_WCHAR + nschar_t *bnsp; /* Background non-spacing char list */ +#endif /* HAVE_WCHAR */ +}; + +/* Set of attributes unset by 'me' - 'mb', 'md', 'mh', 'mk', 'mp' and 'mr'. */ +#ifndef HAVE_WCHAR +#define __TERMATTR \ + (__REVERSE | __BLINK | __DIM | __BOLD | __BLANK | __PROTECT) +#else +#define __TERMATTR \ + (__REVERSE | __BLINK | __DIM | __BOLD | __BLANK | __PROTECT \ + | WA_TOP | WA_LOW | WA_LEFT | WA_RIGHT | WA_HORIZONTAL | WA_VERTICAL) +#endif /* HAVE_WCHAR */ + +struct __winlist { + struct __window *winp; /* The window. */ + struct __winlist *nextp; /* Next window. */ +}; + +struct __color { + short num; + short red; + short green; + short blue; + int flags; +}; + +/* List of colour pairs */ +struct __pair { + short fore; + short back; + int flags; +}; + +/* Maximum colours */ +#define MAX_COLORS 64 +/* Maximum colour pairs - determined by number of colour bits in attr_t */ +#define MAX_PAIRS PAIR_NUMBER(__COLOR) + +typedef struct keymap keymap_t; + +/* this is the encapsulation of the terminal definition, one for + * each terminal that curses talks to. + */ +struct __screen { + FILE *infd, *outfd; /* input and output file descriptors */ + WINDOW *curscr; /* Current screen. */ + WINDOW *stdscr; /* Standard screen. */ + WINDOW *__virtscr; /* Virtual screen (for doupdate()). */ + int curwin; /* current window for refresh */ + int lx, ly; /* loop parameters for refresh */ + int COLS; /* Columns on the screen. */ + int LINES; /* Lines on the screen. */ + int COLORS; /* Maximum colors on the screen */ + int COLOR_PAIRS; /* Maximum color pairs on the screen */ + int My_term; /* Use Def_term regardless. */ + char GT; /* Gtty indicates tabs. */ + char NONL; /* Term can't hack LF doing a CR. */ + char UPPERCASE; /* Terminal is uppercase only. */ + + chtype acs_char[NUM_ACS]; +#ifdef HAVE_WCHAR + cchar_t wacs_char[ NUM_ACS ]; +#endif /* HAVE_WCHAR */ + struct __color colours[MAX_COLORS]; + struct __pair colour_pairs[MAX_PAIRS]; + attr_t nca; + +/* Style of colour manipulation */ +#define COLOR_NONE 0 +#define COLOR_ANSI 1 /* ANSI/DEC-style colour manipulation */ +#define COLOR_HP 2 /* HP-style colour manipulation */ +#define COLOR_TEK 3 /* Tektronix-style colour manipulation */ +#define COLOR_OTHER 4 /* None of the others but can set fore/back */ + int color_type; + + attr_t mask_op; + attr_t mask_me; + attr_t mask_ue; + attr_t mask_se; + TERMINAL *term; + int old_mode; /* old cursor visibility state for terminal */ + keymap_t *base_keymap; + int echoit; + int pfast; + int rawmode; + int nl; + int noqch; + int clearok; + int useraw; + struct __winlist *winlistp; + struct termios cbreakt, rawt, *curt, save_termios; + struct termios orig_termios, baset, savedtty; + int ovmin; + int ovtime; + char *stdbuf; + unsigned int len; + int meta_state; + char padchar; + char ttytype[128]; + int endwin; + int notty; + int half_delay; + int resized; + wchar_t *unget_list; + int unget_len, unget_pos; +#ifdef HAVE_WCHAR +#define MB_LEN_MAX 8 +#define MAX_CBUF_SIZE MB_LEN_MAX + int cbuf_head; /* header to cbuf */ + int cbuf_tail; /* tail to cbuf */ + int cbuf_cur; /* the current char in cbuf */ + mbstate_t sp; /* wide char processing state */ + char cbuf[ MAX_CBUF_SIZE ]; /* input character buffer */ +#endif /* HAVE_WCHAR */ +}; + + +extern char __GT; /* Gtty indicates tabs. */ +extern char __NONL; /* Term can't hack LF doing a CR. */ +extern char __UPPERCASE; /* Terminal is uppercase only. */ +extern int My_term; /* Use Def_term regardless. */ +extern const char *Def_term; /* Default terminal type. */ +extern SCREEN *_cursesi_screen; /* The current screen in use */ + +/* Debugging options/functions. */ +#ifdef DEBUG +#define __CTRACE_TSTAMP 0x00000001 +#define __CTRACE_MISC 0x00000002 +#define __CTRACE_INIT 0x00000004 +#define __CTRACE_SCREEN 0x00000008 +#define __CTRACE_WINDOW 0x00000010 +#define __CTRACE_REFRESH 0x00000020 +#define __CTRACE_COLOR 0x00000040 +#define __CTRACE_INPUT 0x00000080 +#define __CTRACE_OUTPUT 0x00000100 +#define __CTRACE_LINE 0x00000200 +#define __CTRACE_ATTR 0x00000400 +#define __CTRACE_ERASE 0x00000800 +#define __CTRACE_FILEIO 0x00001000 +#define __CTRACE_ALL 0x7fffffff +void __CTRACE_init(void); +void __CTRACE(int, const char *, ...) __attribute__((__format__(__printf__, 2, 3))); +#endif + +/* Private functions. */ +int __cputchar_args(int, void *); +void _cursesi_free_keymap(keymap_t *); +int _cursesi_gettmode(SCREEN *); +void _cursesi_reset_acs(SCREEN *); +int _cursesi_addbyte(WINDOW *, __LINE **, int *, int *, int , attr_t); +int _cursesi_addwchar(WINDOW *, __LINE **, int *, int *, const cchar_t *); +#ifdef HAVE_WCHAR +void _cursesi_reset_wacs(SCREEN *); +#endif /* HAVE_WCHAR */ +void _cursesi_resetterm(SCREEN *); +int _cursesi_setterm(char *, SCREEN *); +int __delay(void); +u_int __hash_more(const void *, size_t, u_int); +#define __hash(s, len) __hash_more((s), (len), 0u) +void __id_subwins(WINDOW *); +void __init_getch(SCREEN *); +void __init_acs(SCREEN *); +#ifdef HAVE_WCHAR +void __init_get_wch(SCREEN *); +void __init_wacs(SCREEN *); +int __cputwchar_args( wchar_t, void * ); +int _cursesi_copy_nsp(nschar_t *, struct __ldata *); +void __cursesi_free_nsp(nschar_t *); +void __cursesi_win_free_nsp(WINDOW *); +void __cursesi_putnsp(nschar_t *, const int, const int); +void __cursesi_chtype_to_cchar(chtype, cchar_t *); +#endif /* HAVE_WCHAR */ +int __unget(wint_t); +char *__longname(char *, char *); /* Original BSD version */ +int __mvcur(int, int, int, int, int); +WINDOW *__newwin(SCREEN *, int, int, int, int, int); +int __nodelay(void); +int __notimeout(void); +void __restartwin(void); +void __restore_colors(void); +void __restore_cursor_vis(void); +void __restore_meta_state(void); +void __restore_termios(void); +void __restore_stophandler(void); +void __restore_winchhandler(void); +void __save_termios(void); +void __set_color(WINDOW *win, attr_t attr); +void __set_stophandler(void); +void __set_winchhandler(void); +void __set_subwin(WINDOW *, WINDOW *); +void __startwin(SCREEN *); +void __stop_signal_handler(int); +int __stopwin(void); +void __swflags(WINDOW *); +int __timeout(int); +int __touchline(WINDOW *, int, int, int); +int __touchwin(WINDOW *); +void __unsetattr(int); +void __unset_color(WINDOW *win); +int __waddch(WINDOW *, __LDATA *); +int __wgetnstr(WINDOW *, char *, int); +void __winch_signal_handler(int); + +/* Private #defines. */ +#define min(a,b) ((a) < (b) ? (a) : (b)) +#define max(a,b) ((a) > (b) ? (a ): (b)) + +/* Private externs. */ +extern int __echoit; +extern int __endwin; +extern int __pfast; +extern int __rawmode; +extern int __noqch; +extern attr_t __mask_op, __mask_me, __mask_ue, __mask_se; +extern WINDOW *__virtscr; +extern int __using_color; +extern attr_t __default_color; diff --git a/lib/libcurses/curses_refresh.3 b/lib/libcurses/curses_refresh.3 new file mode 100644 index 000000000..9800b1aab --- /dev/null +++ b/lib/libcurses/curses_refresh.3 @@ -0,0 +1,157 @@ +.\" $NetBSD: curses_refresh.3,v 1.10 2003/04/16 13:35:01 wiz Exp $ +.\" +.\" Copyright (c) 2002 +.\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au) +.\" +.\" This code is donated to the NetBSD Foundation by the Author. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. The name of the Author may not be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" +.Dd March 26, 2003 +.Dt CURSES_REFRESH 3 +.Os +.Sh NAME +.Nm curses_refresh , +.Nm refresh , +.Nm wrefresh , +.Nm wnoutrefresh , +.Nm doupdate , +.Nm leaveok , +.Nm flushok +.Nd curses terminal update routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft int +.Fn refresh "void" +.Ft int +.Fn wrefresh "WINDOW *win" +.Ft int +.Fn wnoutrefresh "WINDOW *win" +.Ft int +.Fn doupdate "void" +.Ft int +.Fn leaveok "WINDOW *win" "boolf flag" +.Ft int +.Fn flushok "WINDOW *win" "boolf flag" +.Sh DESCRIPTION +These functions update the terminal with the contents of +.Dv stdscr +or of the specified window(s). +.Pp +The +.Fn refresh +function causes curses to propagate changes made to +.Dv stdscr +to the terminal display. +Any changes made to subwindows of +.Dv stdscr +are also propagated. +.Pp +The +.Fn wrefresh +function is the same as the +.Fn refresh +function, excepting that changes are propagated to the terminal from the +window specified by +.Fa win . +.Pp +The +.Fn wnoutrefresh +function performs the internal processing required by curses to determine +what changes need to be made to synchronise the internal screen buffer +and the terminal but does not modify the terminal display. +.Pp +The +.Fn doupdate +function updates the terminal display to match the internal curses +representation of the display. +.Pp +The +.Fn wnoutrefresh +and +.Fn doupdate +functions can be used together to speed up terminal redraws by +deferring the actual terminal updates until after a batch of updates +to multiple windows has been done. +.Pp +The +.Fn refresh +function is equivalent to +.Fn wnoutrefresh stdscr +followed by +.Fn doupdate . +.Pp +The +.Fn leaveok +function determines whether refresh operations may leave the screen cursor +in an arbitrary position on the screen. +Setting +.Fa flag +to +.Dv FALSE +ensures that the screen cursor is positioned at the current cursor +position after a refresh operation has taken place. +.Pp +The +.Fn flushok +function is used to determine whether or not the screen's output file +descriptor will be flushed on refresh. +Setting +.Fa flag +to +.Dv TRUE +will cause the output to be flushed. +.Sh RETURN VALUES +Functions returning pointers will return +.Dv NULL +if an error is detected. +The functions that return an int will return one of the following +values: +.Pp +.Bl -tag -width ERR -compact +.It Er OK +The function completed successfully. +.It Er ERR +An error occurred in the function. +.El +.Sh SEE ALSO +.Xr curses_pad 3 , +.Xr curses_touch 3 , +.Xr getch 3 +.Sh NOTES +Calling +.Fn wrefresh +on a new, unchanged window has no effect. +.Sh STANDARDS +The +.Nx +Curses library complies with the X/Open Curses specification, part of the +Single Unix Specification. +.Sh HISTORY +The Curses package appeared in +.Bx 4.0 . diff --git a/lib/libcurses/curses_scanw.3 b/lib/libcurses/curses_scanw.3 new file mode 100644 index 000000000..b6c1ab7f9 --- /dev/null +++ b/lib/libcurses/curses_scanw.3 @@ -0,0 +1,114 @@ +.\" $NetBSD: curses_scanw.3,v 1.5 2003/04/16 13:35:01 wiz Exp $ +.\" +.\" Copyright (c) 2002 +.\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au) +.\" +.\" This code is donated to the NetBSD Foundation by the Author. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. The name of the Author may not be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" +.Dd August 12, 2002 +.Dt CURSES_SCANW 3 +.Os +.Sh NAME +.Nm curses_scanw , +.Nm scanw , +.Nm wscanw , +.Nm mvscanw , +.Nm mvwscanw +.Nd curses read formatted data from screen routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft int +.Fn scanw "const char *fmt" "..." +.Ft int +.Fn wscanw "WINDOW *win" "const char *fmt" "..." +.Ft int +.Fn mvscanw "int y" "int x" "const char *fmt" "..." +.Ft int +.Fn mvwscanw "WINDOW *win" "int y" "int x" "const char *fmt" "..." +.Sh DESCRIPTION +These functions read formatted data from +.Dv stdscr +or from the specified window. +.Pp +The +.Fn scanw +function is the same as the +.Fn scanf +function, excepting that the input data stream is read from the current +cursor position on +.Dv stdscr , +.Pp +The +.Fn wscanw +function is the same +as the +.Fn scanw +function, excepting that the data stream is read from the window specified by +.Fa win . +.Pp +The +.Fn mvscanw +and +.Fn mvwscanw +functions are the same as the +.Fn scanw +and +.Fn mvscanw +functions, respectively, excepting that +.Fn wmove +is called to move the cursor to the position specified by +.Fa y , +.Fa x +before the data is read from the window. +.Sh RETURN VALUES +Functions returning pointers will return +.Dv NULL +if an error is detected. +The functions that return an int will return one of the following +values: +.Pp +.Bl -tag -width ERR -compact +.It Er OK +The function completed successfully. +.It Er ERR +An error occurred in the function. +.El +.Sh SEE ALSO +.Xr curses_cursor 3 , +.Xr curses_print 3 , +.Xr scanf 3 +.Sh STANDARDS +The +.Nx +Curses library complies with the X/Open Curses specification, part of the +Single Unix Specification. +.Sh HISTORY +The Curses package appeared in +.Bx 4.0 . diff --git a/lib/libcurses/curses_screen.3 b/lib/libcurses/curses_screen.3 new file mode 100644 index 000000000..50bb806b9 --- /dev/null +++ b/lib/libcurses/curses_screen.3 @@ -0,0 +1,204 @@ +.\" $NetBSD: curses_screen.3,v 1.14 2007/10/25 20:42:07 jdc Exp $ +.\" +.\" Copyright (c) 2002 +.\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au) +.\" +.\" This code is donated to the NetBSD Foundation by the Author. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. The name of the Author may not be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" +.Dd October 24, 2007 +.Dt CURSES_SCREEN 3 +.Os +.Sh NAME +.Nm curses_screen , +.Nm newterm , +.Nm set_term , +.Nm delscreen , +.Nm endwin , +.Nm initscr , +.Nm isendwin , +.Nm resizeterm , +.Nm setterm +.Nd curses terminal and screen routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft SCREEN * +.Fn newterm "char *type" "FILE *outfd" "FILE *infd" +.Ft SCREEN * +.Fn set_term "SCREEN *screen" +.Ft void +.Fn delscreen "SCREEN *screen" +.Ft int +.Fn endwin "void" +.Ft WINDOW * +.Fn initscr "void" +.Ft bool +.Fn isendwin "void" +.Ft int +.Fn resizeterm "int lines" "int cols" +.Ft int +.Fn setterm "char *name" +.Pp +.Va extern int LINES ; +.Pp +.Va extern int COLS ; +.Sh DESCRIPTION +These functions initialize terminals and screens. +.Pp +The +.Fn newterm +function initialises the curses data structures and pointers ready for +use by curses. +The +.Fa type +argument points to a +.Xr termcap 5 +capability name, or it may be +.Dv NULL +in which case the TERM environment variable is used. +The +.Fa outfd +and +.Fa infd +are the output and input file descriptors for the terminal. +The +.Fn newterm +function must only be called once per terminal. +.Pp +The +.Fn set_term +function can be used to switch between the screens defined by calling +.Fn newterm , +a pointer to the previous screen structure that was in use will be +returned on success. +.Pp +Calling +.Fn delscreen +will destroy the given screen and free all allocated resources. +.Pp +Calling +.Fn endwin +will end the curses session and restore the saved terminal settings. +.Pp +The curses session must be initialised by calling +.Fn initscr +which saves the current terminal state and sets up the terminal and +internal data structures to support the curses application. +This +function call must be, with few exceptions, the first Curses library +call made. +The exception to this rule is the +.Fn newterm +call which may be called prior to +.Fn initscr . +The size of the curses screen is determined by checking the +.Xr tty 4 +size and then the +.Xr termcap 5 +entries for the terminal type. +If the environment variables +.Va LINES +or +.Va COLS +are set, then these will be used instead. +.Pp +When either +.Fn newterm +or +.Fn initscr +are called, the Curses library sets up signal handlers for +.Dv SIGTSTP +and +.Dv SIGWINCH . +If a signal handler is already installed for +.Dv SIGWINCH , +this will also be called when the Curses library handler is called. +.Pp +The +.Fn isendwin +function can be used to determine whether or not a refresh of the +screen has occurred since the last call to +.Fn endwin . +.Pp +The size of the screen may be changed by calling +.Fn resizeterm +with the updated number of lines and columns. +This will resize the curses internal data structures to accommodate the +changed terminal geometry. +The +.Dv curscr +and +.Dv stdscr +windows and any of their subwindows will be resized to fit the new +screen size. +The application must redraw the screen after a call to +.Fn resizeterm . +.Pp +The +.Fn setterm +function sets the terminal type for the current screen to the one +passed, initialising all the curses internal data structures with +information related to the named terminal. +The +.Fa name +argument must be a valid name or alias in the +.Xr termcap 5 +database for this function to succeed. +.Sh RETURN VALUES +Functions returning pointers will return +.Dv NULL +if an error is detected. +The functions that return an int will return one of the following +values: +.Pp +.Bl -tag -width ERR -compact +.It Er OK +The function completed successfully. +.It Er ERR +An error occurred in the function. +.El +.Sh SEE ALSO +.Xr curses_window 3 , +.Xr tty 4 , +.Xr termcap 5 , +.Xr signal 7 +.Sh STANDARDS +The +.Nx +Curses library complies with the X/Open Curses specification, part of the +Single Unix Specification. +.Sh HISTORY +The Curses package appeared in +.Bx 4.0 . +The +.Fn resizeterm +function is a +.Em ncurses +extension to the Curses library and was added in +.Nx 1.6 . diff --git a/lib/libcurses/curses_scroll.3 b/lib/libcurses/curses_scroll.3 new file mode 100644 index 000000000..459de9af4 --- /dev/null +++ b/lib/libcurses/curses_scroll.3 @@ -0,0 +1,169 @@ +.\" $NetBSD: curses_scroll.3,v 1.4 2003/04/16 13:35:01 wiz Exp $ +.\" +.\" Copyright (c) 2002 +.\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au) +.\" +.\" This code is donated to the NetBSD Foundation by the Author. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. The name of the Author may not be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" +.Dd August 12, 2002 +.Dt CURSES_SCROLL 3 +.Os +.Sh NAME +.Nm curses_scroll , +.Nm scrl , +.Nm wscrl +.Nm scroll , +.Nm scrollok , +.Nm setscrreg , +.Nm wsetscrreg +.Nd curses window scrolling routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft int +.Fn scrl "int n" +.Ft int +.Fn wscrl "WINDOW *win" "int n" +.Ft int +.Fn scroll "WINDOW *win" +.Ft int +.Fn scrollok "WINDOW *win" "boolf flag" +.Ft int +.Fn setscrreg "int top" "int bottom" +.Ft int +.Fn wsetscrreg "WINDOW *win" "int top" "int bottom" +.Sh DESCRIPTION +These functions scroll areas on +.Dv stdscr +or on the specified window. +.Pp +The +.Fn scrl +function scrolls +.Dv stdscr +by +.Fa n +lines. +If +.Fa n +is positive then then +.Dv stdscr +is scrolled up. +.Fa n +lines are lost from the top of +.Dv stdscr +and +.Fa n +blank lines are inserted at the bottom. +If +.Fa n +is negative then +.Dv stdscr +is scrolled down. +.Fa n +blank lines are inserted at the top of +.Dv stdscr +and +.Fa n +lines are lost from the bottom. +.Pp +The +.Fn wscrl +function is the same as the +.Fn scrl +function, excepting that it scrolls the window specified by +.Fa win . +.Pp +The +.Fn scroll +function scrolls the window +.Fa win +up by one line. +.Pp +The scrolling behaviour of a window can be controlled by using the +.Fn scrollok +function. +If the +.Fa flag +argument is +.Dv TRUE +then a line wrap at the bottom of the window will cause the window to +be scrolled up one line, if +.Fa flag +is +.Dv FALSE +then lines that would force a scroll will be truncated. +.Pp +The +.Fn setscrreg +function sets up a software scrolling region on +.Dv stdscr +which will define a region of the screen that will be scrolled. +The scrolling of this region is also controlled by the +.Fn scrollok +function. +.Pp +The +.Fn wsetscrreg +function does the same as the +.Fn setscrreg +function, except that the scrolling region is set on the window specified by +.Fa win . +.Pp +If a scrolling region has been set with the +.Fn setscrreg +or +.Fn wsetscrreg +functions and the current cursor position is inside the scrolling region, +then only the area inside the scrolling region is scrolled. +.Sh RETURN VALUES +Functions returning pointers will return +.Dv NULL +if an error is detected. +The functions that return an int will return one of the following +values: +.Pp +.Bl -tag -width ERR -compact +.It Er OK +The function completed successfully. +.It Er ERR +An error occurred in the function. +.El +.Sh SEE ALSO +.Xr curses_deleteln 3 , +.Xr curses_insdelln 3 , +.Xr curses_insertln 3 +.Sh STANDARDS +The +.Nx +Curses library complies with the X/Open Curses specification, part of the +Single Unix Specification. +.Sh HISTORY +The Curses package appeared in +.Bx 4.0 . diff --git a/lib/libcurses/curses_standout.3 b/lib/libcurses/curses_standout.3 new file mode 100644 index 000000000..269b9d409 --- /dev/null +++ b/lib/libcurses/curses_standout.3 @@ -0,0 +1,104 @@ +.\" $NetBSD: curses_standout.3,v 1.4 2008/04/30 13:10:51 martin Exp $ +.\" Copyright (c) 2002 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Julian Coleman. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd October 13, 2002 +.Dt CURSES_STANDOUT 3 +.Os +.Sh NAME +.Nm curses_standout , +.Nm standout , +.Nm standend , +.Nm wstandout , +.Nm wstandend +.Nd curses standout attribute manipulation routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft int +.Fn standout void +.Ft int +.Fn standend void +.Ft int +.Fn wstandout void +.Ft int +.Fn wstandend void +.Sh DESCRIPTION +These functions manipulate the standout attribute on +.Dv stdscr +or on the specified window. +.Pp +The +.Fn standout +function turns on the standout attribute +on +.Dv stdscr . +The +.Fn standend +function turns off the standout attribute +on +.Dv stdscr . +.Pp +The +.Fn wstandout +and +.Fn wstandend +functions are equivalent to +.Fn standout +and +.Fn standend , +respectively, excepting that the attribute is manipulated on the +window specified by +.Fa win . +.Pp +The +.Fn standout +and +.Fn standend +functions are equivalent to +.Fn attron A_STANDOUT +and +.Fn attroff A_STANDOUT , +respectively. +.Sh RETURN VALUES +These functions always return 1. +.Sh SEE ALSO +.Xr curses_attributes 3 , +.Xr curses_underscore 3 +.Sh STANDARDS +The +.Nx +Curses library complies with the X/Open Curses specification, part of the +Single Unix Specification. +.Sh HISTORY +The Curses package appeared in +.Bx 4.0 . +.Sh BUGS +On modern terminals that support other attributes, there is no difference +between characters displayed with the standout attribute set and those +displayed with one of the other attributes set (usually bold). +It is best to avoid using standout if the terminal supports other attributes. diff --git a/lib/libcurses/curses_termcap.3 b/lib/libcurses/curses_termcap.3 new file mode 100644 index 000000000..a32f7e88a --- /dev/null +++ b/lib/libcurses/curses_termcap.3 @@ -0,0 +1,103 @@ +.\" $NetBSD: curses_termcap.3,v 1.4 2003/04/16 13:35:01 wiz Exp $ +.\" +.\" Copyright (c) 2002 +.\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au) +.\" +.\" This code is donated to the NetBSD Foundation by the Author. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. The name of the Author may not be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" +.Dd August 12, 2002 +.Dt CURSES_TERMCAP 3 +.Os +.Sh NAME +.Nm curses_termcap , +.Nm fullname , +.Nm getcap , +.Nm longname +.Nd curses termcap querying routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft char * +.Fn fullname "char *termbuf" "char *name" +.Ft char * +.Fn getcap "char *name" +.Ft char * +.Fn longname "void" +.Sh DESCRIPTION +The +.Fn fullname +function takes the termcap entry in +.Fa termbuf +and copies the full name of the terminal from the entry into the +target variable +.Fa name . +The full name of the terminal is assumed to be the last alias in the +termcap entry name. +It is assumed that the +.Fa name +variable has sufficient storage to hold the full name of the terminal. +.Pp +A termcap entry can be retrieved by calling the +.Fn getcap +function with the name of the capability in +.Fa name . +The matching capability string for the terminal is returned. +.Pp +The +.Fn longname +function returns a verbose description of the terminal which is taken +from the last name alias in the termcap description for the terminal. +This string will be at most 128 characters long and will only be +defined after a call to +.Fn initscr +or +.Fn newterm . +.Sh RETURN VALUES +Functions returning pointers will return +.Dv NULL +if an error is detected. +The functions that return an int will return one of the following +values: +.Pp +.Bl -tag -width ERR -compact +.It Er OK +The function completed successfully. +.It Er ERR +An error occurred in the function. +.El +.Sh SEE ALSO +.Xr termcap 5 +.Sh STANDARDS +The +.Lb libcurses +library complies with the X/Open Curses specification, part of the +Single Unix Specification. +.Sh HISTORY +The Curses package appeared in +.Bx 4.0 . diff --git a/lib/libcurses/curses_touch.3 b/lib/libcurses/curses_touch.3 new file mode 100644 index 000000000..c5d32a036 --- /dev/null +++ b/lib/libcurses/curses_touch.3 @@ -0,0 +1,199 @@ +.\" $NetBSD: curses_touch.3,v 1.8 2010/02/24 13:02:13 drochner Exp $ +.\" +.\" Copyright (c) 2002 +.\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au) +.\" +.\" This code is donated to the NetBSD Foundation by the Author. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. The name of the Author may not be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" +.Dd February 23, 2010 +.Dt CURSES_TOUCH 3 +.Os +.Sh NAME +.Nm curses_touch , +.Nm touchline , +.Nm touchoverlap , +.Nm touchwin , +.Nm untouchwin , +.Nm wtouchln , +.Nm is_linetouched , +.Nm is_wintouched , +.Nm redrawwin , +.Nm wredrawln , +.Nm wsyncup , +.Nm wsyncdown +.Nd curses window modification routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft int +.Fn touchline "WINDOW *win" "int start" "int count" +.Ft int +.Fn touchoverlap "WINDOW *win1" "WINDOW *win2" +.Ft int +.Fn touchwin "WINDOW *win" +.Ft int +.Fn untouchwin "WINDOW *win" +.Ft int +.Fn wtouchln "WINDOW *win" "int line" "int n" "boolf changed" +.Ft bool +.Fn is_linetouched "WINDOW *win" "int line" +.Ft bool +.Fn is_wintouched "WINDOW *win" +.Ft int +.Fn redrawwin "WINDOW *win" +.Ft int +.Fn wredrawln "WINDOW *win" "int line" "int n" +.Ft void +.Fn wsyncup "WINDOW *win" +.Ft void +.Fn wsyncdown "WINDOW *win" +.Sh DESCRIPTION +These functions mark lines and windows as modified and check the modification +status of lines and windows. +.Pp +The +.Fn touchline +function marks +.Fa count +lines starting from +.Fa start +in window +.Fa win +as having been modified. +These characters will be synced to the terminal on the next call to +.Fn wrefresh . +.Pp +The +.Fn touchoverlap +function marks the portion of +.Fa win2 +that overlaps +.Fa win1 +as being modified. +.Pp +The +.Fn touchwin +function marks the entire window +.Fa win +as having been modified. +Conversely, +the +.Fn untouchwin +function marks the window +.Fa win +as being unmodified, so that any changes made to that window will +not be synced to the terminal during a +.Fn wrefresh . +.Pp +The +.Fn wtouchln +function performs one of two operations on +.Fa n +lines starting at +.Fa line +in the given window. +If +.Fa changed +is 1 then the given line range is marked as being modified, if +.Fa changed +is 0 then the given line range is set to being unmodified. +.Pp +The +.Fn is_linetouched +function returns +.Dv TRUE +if +.Fa line +in window +.Fa win +has been modified since the last refresh was done, otherwise +.Dv FALSE +is returned. +.Pp +.Fn is_wintouched +returns +.Dv TRUE +if the window +.Fa win +has been modified since the last refresh, otherwise +.Dv FALSE +is returned. +.Pp +The +.Fn redrawwin +function marks the entire window +.Fa win +as having been corrupted. +Is is equivalent to the +.Fn touchwin +function. +.Pp +The +.Fn wredrawln +function marks +.Fa n +lines starting at +.Fa line +in the given window as corrupted. +It is equivalent to +.Fn wtouchln win line n 1 . +.Pp +The +.Fn wsyncup +function touches all ancestors of +.Fa win . +.Pp +The +.Fn wsyncdown +function touches +.Fa win +if any of its ancestors is touched. +.Sh RETURN VALUES +Functions returning pointers will return +.Dv NULL +if an error is detected. +The functions that return an int will return one of the following +values: +.Pp +.Bl -tag -width ERR -compact +.It Er OK +The function completed successfully. +.It Er ERR +An error occurred in the function. +.El +.Sh SEE ALSO +.Xr curses_refresh 3 +.Sh STANDARDS +The +.Nx +Curses library complies with the X/Open Curses specification, part of the +Single Unix Specification. +.Sh HISTORY +The Curses package appeared in +.Bx 4.0 . diff --git a/lib/libcurses/curses_tty.3 b/lib/libcurses/curses_tty.3 new file mode 100644 index 000000000..5c2969dc5 --- /dev/null +++ b/lib/libcurses/curses_tty.3 @@ -0,0 +1,360 @@ +.\" $NetBSD: curses_tty.3,v 1.8 2004/03/16 19:27:35 snj Exp $ +.\" +.\" Copyright (c) 2002 +.\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au) +.\" +.\" This code is donated to the NetBSD Foundation by the Author. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. The name of the Author may not be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" +.Dd June 13, 2003 +.Dt CURSES_TTY 3 +.Os +.Sh NAME +.Nm curses_tty , +.Nm beep , +.Nm flash , +.Nm curs_set , +.Nm def_prog_mode , +.Nm reset_prog_mode , +.Nm def_shell_mode , +.Nm reset_shell_mode , +.Nm echo , +.Nm noecho , +.Nm delay_output , +.Nm erasechar , +.Nm flushinp , +.Nm gettmode , +.Nm halfdelay , +.Nm has_ic , +.Nm has_il , +.Nm idcok , +.Nm idlok , +.Nm intrflush , +.Nm noqiflush , +.Nm qiflush , +.Nm killchar , +.Nm meta , +.Nm napms , +.Nm nl , +.Nm nonl , +.Nm cbreak , +.Nm nocbreak , +.Nm raw , +.Nm noraw , +.Nm savetty , +.Nm resetty +.Nd curses terminal manipulation routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft int +.Fn beep "void" +.Ft int +.Fn flash "void" +.Ft int +.Fn curs_set "int visibility" +.Ft int +.Fn def_prog_mode "void" +.Ft int +.Fn reset_prog_mode "void" +.Ft int +.Fn def_shell_mode "void" +.Ft int +.Fn reset_shell_mode "void" +.Ft int +.Fn echo "void" +.Ft int +.Fn noecho "void" +.Ft int +.Fn delay_output "int ms" +.Ft char +.Fn erasechar "void" +.Ft int +.Fn flushinp "void" +.Ft int +.Fn gettmode "void" +.Ft int +.Fn has_ic "void" +.Ft int +.Fn has_il "void" +.Ft int +.Fn idcok "WINDOW *win" "boolf flag" +.Ft int +.Fn idlok "WINDOW *win" "boolf flag" +.Ft int +.Fn intrflush "WINDOW *win" "boolf flag" +.Ft void +.Fn noqiflush "void" +.Ft void +.Fn qiflush "void" +.Ft char +.Fn killchar "void" +.Ft int +.Fn meta "WINDOW *win" "boolf flag" +.Ft int +.Fn napms "int ms" +.Ft int +.Fn nl "void" +.Ft int +.Fn nonl "void" +.Ft int +.Fn cbreak "void" +.Ft int +.Fn nocbreak "void" +.Ft int +.Fn halfdelay "int" +.Ft int +.Fn raw "void" +.Ft int +.Fn noraw "void" +.Ft int +.Fn savetty "void" +.Ft int +.Fn resetty "void" +.Sh DESCRIPTION +These functions manipulate curses terminal settings. +.Pp +The +.Fn beep +function rings the terminal bell, if this is possible. +Failing that, the terminal screen will be flashed. +If neither of these are possible, then no action will be taken. +.Fn flash +will flash the terminal screen if possible. +Failing that, the terminal bell will be rung. +If neither of these are possible then no action will be taken. +.Pp +The cursor +visibility can be set by calling +.Fn curs_set . +The following visibility settings are valid for +.Fn curs_set : +.Pp +.Bl -tag -width visibility -compact -offset indent +.It Visibility +Effect +.It 0 +cursor is invisible. +.It 1 +cursor is normal visibility +.It 2 +cursor is high visibility +.El +.Pp +A successful call to +.Fn curs_set +will return the previous visibility setting for the cursor. +.Pp +The +.Fn delay_output +function pauses the output to the terminal by sending the appropriate +number of terminal pad characters such that the transmission time of +the pad characters will take +.Fa ms +milliseconds. +.Pp +Calling +.Fn def_prog_mode +will cause the current terminal curses setting to be saved. +A subsequent call to +.Fn reset_prog_mode , +will restore the saved settings. +This is useful when calls to external programs are made that may +reset the terminal characteristics. +.Pp +The +.Fn def_shell_mode +function saves the current terminal line settings. +These settings are the ones that will be restored when the curses +application exits. +Conversely, +.Fn reset_shell_mode +will save the current terminal curses settings for later restoration and +restores the previously saved terminal line settings. +.Pp +The +.Fn echo +function turns on curses echo mode, characters entered will be echoed +to the terminal by curses. +The +.Fn noecho +function disables this feature. +.Pp +The current erase character for the terminal can be determined by +calling the +.Fn erasechar +function. +.Pp +The +.Fn flushinp +function discards any pending input for the current screen. +.Pp +The modes +for the current terminal can be reset by calling +.Fn gettmode , +this will perform the initialisation on the terminal that is normally +done by curses at start up. +.Pp +The +.Fn has_ic +function returns either +.Dv TRUE +or +.Dv FALSE +depending on whether or not the terminal has a insert character +capability or not. +Similarly the +.Fn has_il +function does the same test but for a insert line capability. +.Pp +The use of the insert character capability in curses operations can be +enabled or disabled by calling +.Fn idcok +on the desired window. +Similarly, the use of the insert line capability can be controlled using the +.Fn idlok +function. +.Pp +The +.Fn intrflush +function controls whether or not a flush of the input buffer is +performed when an interrupt key (kill, suspend or quit) is pressed. +The +.Fa win +parameter is ignored. +The +.Fn noqiflush +function is equivalent to +.Fn intrflush stdscr FALSE . +The +.Fn qiflush +function is equivalent to +.Fn intrflush stdscr TRUE . +.Pp +The character that performs the line kill function can be determined +by calling the +.Fn killchar +function. +.Pp +The +.Fn meta +function turns on and off the generation of 8 bit characters by the +terminal, if +.Fa flag +is +.Dv FALSE +then only 7 bit characters will be returned, if +.Fa flag +is +.Dv TRUE +then 8 bit characters will be returned by the terminal. +.Pp +The +.Fn napms +causes the application to sleep for the number of milliseconds +specified by +.Fa ms . +.Pp +Calling +.Fn nl +will cause curses to map all carriage returns to newlines on input, +this functionality is enabled by default. +The +.Fn nonl +function disables this behaviour. +.Pp +The +.Fn cbreak +function will put the terminal into cbreak mode, which means that +characters will be returned one at a time instead of waiting for a +newline character, line discipline processing will be performed. +The +.Fn nocbreak +function disables this mode. +.Pp +Calling +.Fn halfdelay +puts the terminal into the same mode as +.Fn cbreak +with the exception that if no character is received within the specified +number of tenths of a second then the input routine will return +.Er ERR . +This mode can be cancelled by calling +.Fn nocbreak . +The valid range for the timeout is from 1 to 255 tenths of a second. +.Pp +The +.Fn noraw +function sets the input mode for the current terminal into Cooked mode, +that is input character translation and signal character processing is +performed. +The +.Fn raw +function puts the terminal into Raw mode, no input character +translation is done nor is signal character processing. +.Pp +The terminal +tty flags can be saved by calling +.Fn savetty +and may be restored by calling +.Fn resetty , +the use of these functions is discouraged as they may cause the +terminal to be put into a state that is incompatible with curses +operation. +.Sh RETURN VALUES +Functions returning pointers will return +.Dv NULL +if an error is detected. +The functions that return an int will return one of the following +values: +.Pp +.Bl -tag -width ERR -compact +.It Er OK +The function completed successfully. +.It Er ERR +An error occurred in the function. +.El +.Sh SEE ALSO +.Xr getch 3 , +.Xr termios 4 +.Sh NOTES +The +.Fn idcok +and +.Fn idlok +currently have no effect on the curses code at all, currently curses +will always use the terminal insert character and insert line +capabilities if available. +.Sh STANDARDS +The +.Nx +Curses library complies with the X/Open Curses specification, part of the +Single Unix Specification. +.Sh HISTORY +The Curses package appeared in +.Bx 4.0 . diff --git a/lib/libcurses/curses_underscore.3 b/lib/libcurses/curses_underscore.3 new file mode 100644 index 000000000..b0b149822 --- /dev/null +++ b/lib/libcurses/curses_underscore.3 @@ -0,0 +1,100 @@ +.\" $NetBSD: curses_underscore.3,v 1.5 2008/04/30 13:10:51 martin Exp $ +.\" Copyright (c) 2002 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Julian Coleman. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd October 13, 2002 +.Dt CURSES_UNDERSCORE 3 +.Os +.Sh NAME +.Nm curses_underscore , +.Nm underscore , +.Nm underend , +.Nm wunderscore , +.Nm wunderend +.Nd curses underscore attribute manipulation routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft int +.Fn underscore void +.Ft int +.Fn underend void +.Ft int +.Fn wunderscore void +.Ft int +.Fn wunderend void +.Sh DESCRIPTION +These functions manipulate the underscore attribute on +.Dv stdscr +or on the specified window. +.Pp +The +.Fn underscore +function turns on the underscore attribute +on +.Dv stdscr . +The +.Fn underend +function turns off the underscore attribute on +.Dv stdscr . +.Pp +The +.Fn wunderscore +and +.Fn wunderend +functions +are equivalent to +.Fn underscore +and +.Fn underend , +respectively, excepting that the attribute is manipulated on the +window specified by +.Fa win . +.Pp +The +.Fn underscore +and +.Fn underend +functions +are equivalent to +.Fn wattron A_UNDERLINE +and +.Fn wattroff A_UNDERLINE , +respectively. +.Sh RETURN VALUES +These functions always return 1. +.Sh SEE ALSO +.Xr curses_attributes 3 , +.Xr curses_standout 3 +.Sh STANDARDS +The +.Nx +Curses library complies with the X/Open Curses specification, part of the +Single Unix Specification. +.Sh HISTORY +These functions first appeared in +.Nx 1.5 . diff --git a/lib/libcurses/curses_window.3 b/lib/libcurses/curses_window.3 new file mode 100644 index 000000000..cb1a30137 --- /dev/null +++ b/lib/libcurses/curses_window.3 @@ -0,0 +1,259 @@ +.\" $NetBSD: curses_window.3,v 1.13 2009/05/18 09:30:31 wiz Exp $ +.\" +.\" Copyright (c) 2002 +.\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au) +.\" +.\" This code is donated to the NetBSD Foundation by the Author. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. The name of the Author may not be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" +.Dd March 31, 2008 +.Dt CURSES_WINDOW 3 +.Os +.Sh NAME +.Nm curses_window , +.Nm copywin , +.Nm dupwin , +.Nm delwin , +.Nm derwin , +.Nm mvwin , +.Nm mvderwin , +.Nm newwin , +.Nm overlay , +.Nm overwrite , +.Nm subwin , +.Nm wresize +.Nd curses window routines +.Sh LIBRARY +.Lb libcurses +.Sh SYNOPSIS +.In curses.h +.Ft int +.Fo copywin +.Fa "WINDOW *source" +.Fa "WINDOW *dest" +.Fa "int sminrow" +.Fa "int smincol" +.Fa "int dminrow" +.Fa "int dmincol" +.Fa "int dmaxrow" +.Fa "int dmaxcol" +.Fa "int overlay" +.Fc +.Ft WINDOW * +.Fn dupwin "WINDOW *win" +.Ft WINDOW * +.Fn derwin "WINDOW *win" "int lines" "int cols" "int y" "int x" +.Ft int +.Fn delwin "WINDOW *win" +.Ft int +.Fn mvwin "WINDOW *win" "int y" "int x" +.Ft int +.Fn mvderwin "WINDOW *win" "int y" "int x" +.Ft WINDOW * +.Fn newwin "int lines" "int cols" "int begin_y" "int begin_x" +.Ft WINDOW * +.Fn subwin "WINDOW *win" "int lines" "int cols" "int begin_y" "int begin_x" +.Ft int +.Fn overlay "WINDOW *source" "WINDOW *dest" +.Ft int +.Fn overwrite "WINDOW *source" "WINDOW *dest" +.Ft int +.Fn wresize "WINDOW *win" "int lines" "int cols" +.Sh DESCRIPTION +These functions create, modify and delete windows on the current screen. +.Pp +The contents of a window may be copied to another window by using the +.Fn copywin +function, a section of the destination window +.Fa dest +bounded by +.Fa (dminrow , +.Fa dmincol ) +and +.Fa (dmaxrow , +.Fa dmaxcol ) +will be overwritten with the contents of the window +.Fa source +starting at the coordinates +.Fa (sminrow , +.Fa smincol ) . +If the +.Fa overlay +flag is +.Dv TRUE +then only non-blank characters from +.Fa source +will be copied to +.Fa dest , +if +.Fa overlay +is +.Dv FALSE +then all characters from +.Fa source +will be copied to +.Fa dest . +If the bounding rectangles of either the source or the destination +windows lay outside the maximum size of the respective windows then +the size of the window copied will be adjusted to be within the bounds +of both the source and destination windows. +.Pp +The +.Fn dupwin +function creates an exact duplicate of +.Fa win +and returns a pointer to it. +.Pp +Calling +.Fn derwin +will create a subwindow of +.Fa win +in the same manner as +.Fn subwin +excepting that the starting column and row +.Fa y , +.Fa x +are relative to the parent window origin. +.Pp +A window may deleted and all resources freed by calling the +.Fn delwin +function with the pointer to the window to be deleted in +.Fa win . +.Pp +A window can be moved to a new position by calling the +.Fn mvwin +function. +The +.Fa y +and +.Fa x +positions are the new origin of the window on the screen. +If the new position would cause the any part of the window to lie outside +the screen, it is an error and the window is not moved. +.Pp +A subwindow can be moved relative to the parent window by calling the +.Fn mvderwin +function, the +.Fa y +and +.Fa x +positions are relative to the origin of the parent window. +If the given window in +.Fa win +is not a subwindow then an error will be returned. +If the new position would cause the any part of the window to lie outside +the parent window, it is an error and the window is not moved. +.Pp +The +.Fn newwin +function creates a new window of size +.Fa lines , +.Fa cols +with an origin at +.Fa begin_y , +.Fa begin_x . +If +.Fa lines +is less than or equal to zero then the number of rows +for the window is set to +.Dv LINES - +.Fa begin_x ++ +.Fa lines . +Similarly if +.Fa cols +is less than or equal to zero then the number of columns +for the window is set to +.Dv COLS - +.Fa begin_y ++ +.Fa cols . +.Pp +.Fn subwin +is similar to +.Fn newwin +excepting that the size of the subwindow is bounded by the parent +window +.Fa win . +The subwindow shares internal data structures with the parent window +and will be refreshed when the parent window is refreshed. +The subwindow inherits the background character and attributes of the +parent window. +.Pp +The +.Fn overlay +function copies the contents of the source window +.Fa source +to the destination window +.Fa dest , +only the characters that are not the background character in the +source window are copied to the destination. +The windows need not be the same size, only the overlapping portion of both +windows will be copied. +The +.Fn overwrite +function performs the same functions as +.Fn overlay +excepting that characters from the source window are copied to the +destination without exception. +.Pp +.Fn wresize +resizes the specified window to the new number of lines and columns +given, all internal curses structures are resized. +Any subwindows of the specified window will also be resized if any part +of them falls outside the new parent window size. +The application must redraw the window after it has been resized. +Note that +.Dv curscr +and +.Dv stdscr +can not be resized to be larger than the size of the screen. +.Sh RETURN VALUES +Functions returning pointers will return +.Dv NULL +if an error is detected. +The functions that return an int will return one of the following +values: +.Pp +.Bl -tag -width ERR -compact +.It Er OK +The function completed successfully. +.It Er ERR +An error occurred in the function. +.El +.Sh SEE ALSO +.Xr curses_fileio 3 , +.Xr curses_pad 3 , +.Xr curses_screen 3 +.Sh STANDARDS +The +.Nx +Curses library complies with the X/Open Curses specification, part of the +Single Unix Specification. +.Sh HISTORY +The Curses package appeared in +.Bx 4.0 . diff --git a/lib/libcurses/cursesio.c b/lib/libcurses/cursesio.c deleted file mode 100644 index faf720879..000000000 --- a/lib/libcurses/cursesio.c +++ /dev/null @@ -1,223 +0,0 @@ -#include -#include -#include -#include -#include -#include "curspriv.h" - -struct termios _orig_tty, _tty; -cursv _cursvar; - -WINDOW *stdscr, *curscr; -int LINES, COLS; -bool NONL; - -char termcap[1024]; /* termcap buffer */ -char tc[200]; /* area to hold string capabilities */ -char *ttytype; /* terminal type from env */ -static char *arp; /* pointer for use in tgetstr */ -char *cp; /* character pointer */ - -char *cl; /* clear screen capability */ -char *cm; /* cursor motion capability */ -char *so; /* start standout capability */ -char *se; /* end standout capability */ -char *mr; /* start of reverse */ -char *me; /* revert to normal */ -char *mb; /* start of blink */ -char *md; /* start of bold */ -char *us; /* start of underscore */ -char *ue; /* end of underscore */ -char *vi; /* cursor invisible */ -char *ve; /* cursor normal */ -char *vs; /* cursor good visible */ -char *as; /* alternative charset start */ -char *ae; /* alternative charset end */ -char *bl; /* ring the bell */ -char *vb; /* visual bell */ - -/* fatal - report error and die. Never returns */ -void fatal(s) -char *s; -{ - (void) fprintf(stderr, "curses: %s\n", s); - exit(1); -} - -/* Outc - call putchar, necessary because putchar is a macro. */ -void outc(c) -int c; -{ - (void) putchar(c); -} - -/* Move cursor to r,c */ -void poscur(r, c) -int r, c; -{ - tputs(tgoto(cm, c, r), 1, outc); -} - -/* Clear the screen */ -void clrscr() -{ - tputs(cl, 1, outc); -} - -/* This are terminal independent characters which can be used in curses */ - -unsigned int ACS_ULCORNER; -unsigned int ACS_LLCORNER; -unsigned int ACS_URCORNER; -unsigned int ACS_LRCORNER; -unsigned int ACS_RTEE; -unsigned int ACS_LTEE; -unsigned int ACS_BTEE; -unsigned int ACS_TTEE; -unsigned int ACS_HLINE; -unsigned int ACS_VLINE; -unsigned int ACS_PLUS; -unsigned int ACS_S1; -unsigned int ACS_S9; -unsigned int ACS_DIAMOND; -unsigned int ACS_CKBOARD; -unsigned int ACS_DEGREE; -unsigned int ACS_PLMINUS; -unsigned int ACS_BULLET; -unsigned int ACS_LARROW; -unsigned int ACS_RARROW; -unsigned int ACS_DARROW; -unsigned int ACS_UARROW; -unsigned int ACS_BOARD; -unsigned int ACS_LANTERN; -unsigned int ACS_BLOCK; - -/* These defines describe the full set of grafic block characters which - * can be defined via termcap. - */ - -#define RIGHTARROW 0 -#define LEFTARROW 1 -#define DOWNARROW 2 -#define UPARROW 3 -#define FULLSQUARE 4 -#define GREYSQUARE 5 -#define EMPTYSQUARE 6 -#define LATERN 7 -#define DIAMOND 8 -#define DEGREE 9 -#define PLUSMINUS 10 -#define DOWNRIGHT 11 -#define UPRIGHT 12 -#define UPLEFT 13 -#define DOWNLEFT 14 -#define CROSS 15 -#define UPLINE 16 -#define UPMIDLINE 17 -#define MIDLINE 18 -#define DOMIDLINE 19 -#define DOWNLINE 20 -#define TEELEFT 21 -#define TEERIGHT 22 -#define TEEHEAD 23 -#define TEENORMAL 24 -#define VERTLINE 25 -#define PARAGRAPH 26 - -unsigned int _cursgraftable[27] = -{ - '>', '<', 'v', '^', '#', ':', ' ', '#', '+', '\'', '#', '+', '+', - '+', '+', '+', '-', ' ', '-', ' ', '_', '+', '+', '+', '+', '|' -}; -char _cursident[28] = "+,.-0ahI`fgjklmnopqrstuvwx~"; - -int setterm(type) -char *type; -{ - unsigned char *ac; - int i; -#ifdef TIOCGWINSZ - struct winsize wsize; -#endif - - if (tgetent(termcap, type) != 1) return ERR; - -#ifdef TIOCGWINSZ - if (ioctl(0, TIOCGWINSZ, &wsize) == 0) { - LINES = wsize.ws_row != 0 ? wsize.ws_row : tgetnum("li"); - COLS = wsize.ws_col != 0 ? wsize.ws_col : tgetnum("co"); - } else { -#endif - LINES = tgetnum("li"); - COLS = tgetnum("co"); -#ifdef TIOCGWINSZ - } -#endif - arp = tc; - cl = tgetstr("cl", &arp); - so = tgetstr("so", &arp); - se = tgetstr("se", &arp); - cm = tgetstr("cm", &arp); - mr = tgetstr("mr", &arp); - me = tgetstr("me", &arp); - mb = tgetstr("mb", &arp); - md = tgetstr("md", &arp); - us = tgetstr("us", &arp); - ue = tgetstr("ue", &arp); - vi = tgetstr("vi", &arp); - ve = tgetstr("ve", &arp); - vs = tgetstr("vs", &arp); - as = tgetstr("as", &arp); - ae = tgetstr("ae", &arp); - ac = (unsigned char *) tgetstr("ac", &arp); - bl = tgetstr("bl", &arp); - vb = tgetstr("vb", &arp); - - if (ac) { - while (*ac) { - i = 0; - while (*ac != _cursident[i]) i++; - _cursgraftable[i] = *++ac | A_ALTCHARSET; - ac++; - } - } - - ACS_ULCORNER = _cursgraftable[UPLEFT]; - ACS_LLCORNER = _cursgraftable[DOWNLEFT]; - ACS_URCORNER = _cursgraftable[UPRIGHT]; - ACS_LRCORNER = _cursgraftable[DOWNRIGHT]; - ACS_RTEE = _cursgraftable[TEERIGHT]; - ACS_LTEE = _cursgraftable[TEELEFT]; - ACS_BTEE = _cursgraftable[TEEHEAD]; - ACS_TTEE = _cursgraftable[TEENORMAL]; - ACS_HLINE = _cursgraftable[MIDLINE]; - ACS_VLINE = _cursgraftable[VERTLINE]; - ACS_PLUS = _cursgraftable[CROSS]; - ACS_S1 = _cursgraftable[UPLINE]; - ACS_S9 = _cursgraftable[DOWNLINE]; - ACS_DIAMOND = _cursgraftable[DIAMOND]; - ACS_CKBOARD = _cursgraftable[GREYSQUARE]; - ACS_DEGREE = _cursgraftable[DEGREE]; - ACS_PLMINUS = _cursgraftable[PLUSMINUS]; - ACS_BULLET = 'o'; /* where the hell is a bullet defined in - * termcap ??? */ - ACS_LARROW = _cursgraftable[LEFTARROW]; - ACS_RARROW = _cursgraftable[RIGHTARROW]; - ACS_DARROW = _cursgraftable[DOWNARROW]; - ACS_UARROW = _cursgraftable[UPARROW]; - ACS_BOARD = _cursgraftable[EMPTYSQUARE]; - ACS_LANTERN = _cursgraftable[LATERN]; - ACS_BLOCK = _cursgraftable[FULLSQUARE]; - /* Wow, I got it! */ - return OK; -} - -void gettmode() -{ - tcgetattr(0, &_orig_tty); - tcgetattr(0, &_tty); - _cursvar.echoit = (_tty.c_lflag & ECHO) != 0; - _cursvar.rawmode = (_tty.c_lflag & (ICANON|ISIG)) == 0; - _cursvar.cbrkmode = (_tty.c_lflag & (ICANON|ISIG)) == ISIG; - NONL = (_tty.c_iflag & ICRNL) != 0; -} diff --git a/lib/libcurses/curspriv.h b/lib/libcurses/curspriv.h deleted file mode 100644 index 9fd616b0f..000000000 --- a/lib/libcurses/curspriv.h +++ /dev/null @@ -1,36 +0,0 @@ -/* Constants */ -#define _SUBWIN 1 /* window is a subwindow */ -#define _ENDLINE 2 /* last winline is last screen line */ -#define _FULLWIN 4 /* window fills screen */ -#define _SCROLLWIN 8 /* window lwr rgt is screen lwr rgt */ - -#define _NO_CHANGE (-1) /* flags line edge unchanged */ -#define _BREAKCHAR 0x03 /* ^C character */ -#define _DCCHAR 0x08 /* Delete Char char (BS) */ -#define _DLCHAR 0x1b /* Delete Line char (ESC) */ -#define _GOCHAR 0x11 /* ^Q character */ -#define _PRINTCHAR 0x10 /* ^P character */ -#define _STOPCHAR 0x13 /* ^S character */ -#define NUNGETCH 10 /* max # chars to ungetch() */ - -#define max(a,b) (((a) > (b)) ? (a) : (b)) -#define min(a,b) (((a) < (b)) ? (a) : (b)) - -/* Character mask definitions. */ -#define CHR_MSK ((int) 0x00ff) /* ASCIIZ character mask */ -#define ATR_MSK ((int) 0xff00) /* attribute mask */ -#define ATR_NRM ((int) 0x0000) /* no special attributes */ - -/* Type declarations. */ - -typedef struct { - WINDOW *tmpwin; /* window used for updates */ - int cursrow; /* position of physical cursor */ - int curscol; - bool rawmode; - bool cbrkmode; - bool echoit; -} cursv; - -/* External variables */ -extern cursv _cursvar; /* curses variables */ diff --git a/lib/libcurses/delch.c b/lib/libcurses/delch.c new file mode 100644 index 000000000..c41d1bd61 --- /dev/null +++ b/lib/libcurses/delch.c @@ -0,0 +1,147 @@ +/* $NetBSD: delch.c,v 1.22 2009/07/22 16:57:14 roy Exp $ */ + +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)delch.c 8.2 (Berkeley) 5/4/94"; +#else +__RCSID("$NetBSD: delch.c,v 1.22 2009/07/22 16:57:14 roy Exp $"); +#endif +#endif /* not lint */ + +#include +#include + +#include "curses.h" +#include "curses_private.h" + +#ifndef _CURSES_USE_MACROS +/* + * delch -- + * Do a delete-char on the line, leaving (cury, curx) unchanged. + */ +int +delch(void) +{ + return wdelch(stdscr); +} + +/* + * mvdelch -- + * Do a delete-char on the line at (y, x) on stdscr. + */ +int +mvdelch(int y, int x) +{ + return mvwdelch(stdscr, y, x); +} + +/* + * mvwdelch -- + * Do a delete-char on the line at (y, x) of the given window. + */ +int +mvwdelch(WINDOW *win, int y, int x) +{ + if (wmove(win, y, x) == ERR) + return ERR; + + return wdelch(win); +} + +#endif + +/* + * wdelch -- + * Do a delete-char on the line, leaving (cury, curx) unchanged. + */ +int +wdelch(WINDOW *win) +{ + __LDATA *end, *temp1, *temp2; + +#ifndef HAVE_WCHAR + end = &win->alines[win->cury]->line[win->maxx - 1]; + temp1 = &win->alines[win->cury]->line[win->curx]; + temp2 = temp1 + 1; + while (temp1 < end) { + (void) memcpy(temp1, temp2, sizeof(__LDATA)); + temp1++, temp2++; + } + temp1->ch = win->bch; + if (__using_color && win != curscr) + temp1->attr = win->battr & __COLOR; + else + temp1->attr = 0; + __touchline(win, (int) win->cury, (int) win->curx, (int) win->maxx - 1); + return (OK); +#else + int cw, sx; + nschar_t *np, *tnp; + + end = &win->alines[win->cury]->line[win->maxx - 1]; + sx = win->curx; + temp1 = &win->alines[win->cury]->line[win->curx]; + cw = WCOL( *temp1 ); + if ( cw < 0 ) { + temp1 += cw; + sx += cw; + cw = WCOL( *temp1 ); + } + np = temp1->nsp; + if (np) { + while ( np ) { + tnp = np->next; + free( np ); + np = tnp; + } + temp1->nsp = NULL; + } + if ( sx + cw < win->maxx ) { + temp2 = temp1 + cw; + while ( temp1 < end - ( cw - 1 )) { + ( void )memcpy( temp1, temp2, sizeof( __LDATA )); + temp1++, temp2++; + } + } + while ( temp1 <= end ) { + temp1->ch = ( wchar_t )btowc(( int ) win->bch ); + temp1->attr = 0; + if (_cursesi_copy_nsp(win->bnsp, temp1) == ERR) + return ERR; + SET_WCOL(*temp1, 1); + temp1++; + } + __touchline(win, (int) win->cury, sx, (int) win->maxx - 1); + return (OK); +#endif /* HAVE_WCHAR */ +} diff --git a/lib/libcurses/deleteln.c b/lib/libcurses/deleteln.c new file mode 100644 index 000000000..355d5f839 --- /dev/null +++ b/lib/libcurses/deleteln.c @@ -0,0 +1,65 @@ +/* $NetBSD: deleteln.c,v 1.14 2003/08/07 16:44:21 agc Exp $ */ + +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)deleteln.c 8.2 (Berkeley) 5/4/94"; +#else +__RCSID("$NetBSD: deleteln.c,v 1.14 2003/08/07 16:44:21 agc Exp $"); +#endif +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +#ifndef _CURSES_USE_MACROS +/* + * deleteln -- + * Delete a line from stdscr. It leaves (cury, curx) unchanged. + */ +int +deleteln(void) +{ + return(winsdelln(stdscr, -1)); +} + +#endif + +/* + * wdeleteln -- + * Delete a line from the screen. It leaves (cury, curx) unchanged. + */ +int +wdeleteln(WINDOW *win) +{ + return(winsdelln(win, -1)); +} diff --git a/lib/libcurses/delwin.c b/lib/libcurses/delwin.c new file mode 100644 index 000000000..fbe77c42d --- /dev/null +++ b/lib/libcurses/delwin.c @@ -0,0 +1,113 @@ +/* $NetBSD: delwin.c,v 1.17 2009/07/22 16:57:14 roy Exp $ */ + +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)delwin.c 8.2 (Berkeley) 5/4/94"; +#else +__RCSID("$NetBSD: delwin.c,v 1.17 2009/07/22 16:57:14 roy Exp $"); +#endif +#endif /* not lint */ + +#include + +#include "curses.h" +#include "curses_private.h" + +/* + * delwin -- + * Delete a window and release it back to the system. + */ +int +delwin(WINDOW *win) +{ + WINDOW *wp, *np; + struct __winlist *wl, *pwl; + SCREEN *screen; + +#ifdef DEBUG + __CTRACE(__CTRACE_WINDOW, "delwin(%p)\n", win); +#endif + /* + * Free any storage used by non-spacing characters in the window. + */ +#ifdef HAVE_WCHAR + __cursesi_win_free_nsp(win); +#endif + + if (win->orig == NULL) { + /* + * If we are the original window, delete the space for all + * the subwindows and the window space. + */ + free(win->wspace); + wp = win->nextp; + while (wp != win) { + np = wp->nextp; + delwin(wp); + wp = np; + } + /* Remove ourselves from the list of windows on the screen. */ + pwl = NULL; + screen = win->screen; + for (wl = screen->winlistp; wl; pwl = wl, wl = wl->nextp) { + if (wl->winp != win) + continue; + if (pwl != NULL) + pwl->nextp = wl->nextp; + else + screen->winlistp = wl->nextp; + free(wl); + break; + } + } else { + /* + * If we are a subwindow, take ourselves out of the list. + * NOTE: if we are a subwindow, the minimum list is orig + * followed by this subwindow, so there are always at least + * two windows in the list. + */ + for (wp = win->nextp; wp->nextp != win; wp = wp->nextp) + continue; + wp->nextp = win->nextp; + } + free(win->lspace); + free(win->alines); + if (win == _cursesi_screen->curscr) + _cursesi_screen->curscr = NULL; + if (win == _cursesi_screen->stdscr) + _cursesi_screen->stdscr = NULL; + if (win == _cursesi_screen->__virtscr) + _cursesi_screen->__virtscr = NULL; + free(win); + return (OK); +} diff --git a/lib/libcurses/echo_wchar.c b/lib/libcurses/echo_wchar.c new file mode 100644 index 000000000..a7a9e7cd6 --- /dev/null +++ b/lib/libcurses/echo_wchar.c @@ -0,0 +1,97 @@ +/* $NetBSD: echo_wchar.c,v 1.2 2007/05/28 15:01:55 blymn Exp $ */ + +/* + * Copyright (c) 2005 The NetBSD Foundation Inc. + * All rights reserved. + * + * This code is derived from code donated to the NetBSD Foundation + * by Ruibiao Qiu . + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND + * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: echo_wchar.c,v 1.2 2007/05/28 15:01:55 blymn Exp $"); +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +/* + * echo_wchar -- + * Echo wide character and attributes on stdscr and refresh stdscr. + */ +int +echo_wchar(const cchar_t *wch) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return wecho_wchar(stdscr, wch); +#endif /* HAVE_WCHAR */ +} + +/* + * echo_wchar -- + * Echo wide character and attributes on "win" and refresh "win". + */ +int +wecho_wchar(WINDOW *win, const cchar_t *wch) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + int retval; + + retval = wadd_wch(win, wch); + if (retval == OK) + retval = wrefresh(win); + return retval; +#endif /* HAVE_WCHAR */ +} + +/* + * pecho_wchar -- + * Echo character and attributes on "pad" and refresh "pad" at + * its previous position on the screen. + */ +int +pecho_wchar(WINDOW *pad, const cchar_t *wch) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + int retval; + + retval = wadd_wch(pad, wch); + if (retval == OK) + retval = prefresh(pad, pad->pbegy, pad->pbegx, + pad->sbegy, pad->sbegx, pad->smaxy, pad->smaxx); + return retval; +#endif /* HAVE_WCHAR */ +} diff --git a/lib/libcurses/echochar.c b/lib/libcurses/echochar.c new file mode 100644 index 000000000..a615fc719 --- /dev/null +++ b/lib/libcurses/echochar.c @@ -0,0 +1,83 @@ +/* $NetBSD: echochar.c,v 1.2 2008/04/29 06:53:01 martin Exp $ */ + +/*- + * Copyright (c) 2004 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Julian Coleman. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: echochar.c,v 1.2 2008/04/29 06:53:01 martin Exp $"); +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +#ifndef _CURSES_USE_MACROS +/* + * echochar -- + * Echo character and attributes on stdscr and refresh stdscr. + */ +int +echochar(const chtype ch) +{ + + return wechochar(stdscr, ch); +} +#endif /* _CURSES_USE_MACROS */ + +/* + * echochar -- + * Echo character and attributes on "win" and refresh "win". + */ +int +wechochar(WINDOW *win, const chtype ch) +{ + int retval; + + retval = waddch(win, ch); + if (retval == OK) + retval = wrefresh(win); + return retval; +} + +/* + * pechochar -- + * Echo character and attributes on "pad" and refresh "pad" at + * its previous position on the screen. + */ +int +pechochar(WINDOW *pad, const chtype ch) +{ + int retval; + + retval = waddch(pad, ch); + if (retval == OK) + retval = prefresh(pad, pad->pbegy, pad->pbegx, + pad->sbegy, pad->sbegx, pad->smaxy, pad->smaxx); + return retval; +} diff --git a/lib/libcurses/endwin.c b/lib/libcurses/endwin.c deleted file mode 100644 index 269cbfa55..000000000 --- a/lib/libcurses/endwin.c +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include "curspriv.h" -#include - -int endwin() -{ - extern char *me; - - curs_set(1); - poscur(LINES - 1, 0); - refresh(); - tputs(me, 1, outc); - delwin(stdscr); - delwin(curscr); - delwin(_cursvar.tmpwin); - resetty(); - return(OK); -} diff --git a/lib/libcurses/erase.c b/lib/libcurses/erase.c new file mode 100644 index 000000000..9b6983a86 --- /dev/null +++ b/lib/libcurses/erase.c @@ -0,0 +1,107 @@ +/* $NetBSD: erase.c,v 1.24 2009/07/22 16:57:14 roy Exp $ */ + +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)erase.c 8.2 (Berkeley) 5/4/94"; +#else +__RCSID("$NetBSD: erase.c,v 1.24 2009/07/22 16:57:14 roy Exp $"); +#endif +#endif /* not lint */ + +#include + +#include "curses.h" +#include "curses_private.h" + +#ifndef _CURSES_USE_MACROS + +/* + * erase -- + * Erases everything on stdscr. + */ +int +erase(void) +{ + return werase(stdscr); +} + +#endif + +/* + * werase -- + * Erases everything on the window. + */ +int +werase(WINDOW *win) +{ + + int y; + __LDATA *sp, *end, *start; + attr_t attr; + +#ifdef DEBUG + __CTRACE(__CTRACE_ERASE, "werase: (%p)\n", win); +#endif + if (__using_color && win != curscr) + attr = win->battr & __COLOR; + else + attr = 0; + for (y = 0; y < win->maxy; y++) { + start = win->alines[y]->line; + end = &start[win->maxx]; + for (sp = start; sp < end; sp++) +#ifndef HAVE_WCHAR + if (sp->ch != win->bch || sp->attr != 0) { +#else + if (sp->ch != ( wchar_t )btowc(( int ) win->bch ) || + (sp->attr & WA_ATTRIBUTES) != 0 || sp->nsp) { +#endif /* HAVE_WCHAR */ + sp->attr = attr; +#ifdef HAVE_WCHAR + sp->ch = ( wchar_t )btowc(( int ) win->bch); + if (_cursesi_copy_nsp(win->bnsp, sp) == ERR) + return ERR; + SET_WCOL( *sp, 1 ); +#else + sp->ch = win->bch; +#endif /* HAVE_WCHAR */ + } + } + /* + * Mark the whole window as changed in case we have overlapping + * windows - this will result in the (intended) clearing of the + * screen over the area covered by the window. */ + __touchwin(win); + wmove(win, 0, 0); + return (OK); +} diff --git a/lib/libcurses/fileio.c b/lib/libcurses/fileio.c new file mode 100644 index 000000000..4065fc115 --- /dev/null +++ b/lib/libcurses/fileio.c @@ -0,0 +1,249 @@ +/* $NetBSD: fileio.c,v 1.4 2009/07/22 16:57:14 roy Exp $ */ + +/*- + * Copyright (c) 2008 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Julian Coleman. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: fileio.c,v 1.4 2009/07/22 16:57:14 roy Exp $"); +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" +#include "fileio.h" +#include +#include + +#ifdef HAVE_WCHAR +static int __putnsp(nschar_t *, FILE *); +static int __getnsp(nschar_t *, FILE *); +#endif /* HAVE_WCHAR */ + +#ifdef HAVE_WCHAR +/* + * __putnsp -- + * Write non-spacing character chain to file, consisting of: + * ((int) 1, (wchar_t) ch) pairs followed by (int) 0. + */ +static int +__putnsp(nschar_t *nsp, FILE *fp) +{ + int n; + + n = 1; + while (nsp != NULL) { + if (fwrite(&n, sizeof(int), 1, fp) != 1) + return ERR; + if (fwrite(&nsp->ch, sizeof(wchar_t), 1, fp) != 1) + return ERR; + } + n = 0; + if (fwrite(&n, sizeof(int), 1, fp) != 1) + return ERR; + + return OK; +} +#endif /* HAVE_WCHAR */ + +/* + * putwin -- + * Write window data to file + */ +int +putwin(WINDOW *win, FILE *fp) +{ + int major = CURSES_LIB_MAJOR; + int minor = CURSES_LIB_MINOR; + int y, x; + __LDATA *sp; + +#ifdef DEBUG + __CTRACE(__CTRACE_FILEIO, "putwin: win %p\n", win); +#endif + + if (win == NULL) + return ERR; + + /* win can't be a subwin */ + if (win->orig != NULL) + return ERR; + + /* Library version */ + if (fwrite(&major, sizeof(int), 1, fp) != 1) + return ERR; + if (fwrite(&minor, sizeof(int), 1, fp) != 1) + return ERR; + + /* Window parameters */ + if (fwrite(win, sizeof(WINDOW), 1, fp) != 1) + return ERR; +#ifdef HAVE_WCHAR + /* Background non-spacing character */ + if (__putnsp(win->bnsp, fp) == ERR) + return ERR; +#endif /* HAVE_WCHAR */ + + /* Lines and line data */ + for (y = 0; y < win->maxy; y++) + for (sp = win->alines[y]->line, x = 0; x < win->maxx; + x++, sp++) { + if (fwrite(&sp->ch, sizeof(wchar_t), 1, fp) != 1) + return ERR; + if (fwrite(&sp->attr, sizeof(attr_t), 1, fp) != 1) + return ERR; +#ifdef HAVE_WCHAR + if (sp->nsp != NULL) { + if (__putnsp(win->bnsp, fp) == ERR) + return ERR; + } +#endif /* HAVE_WCHAR */ + } + + return OK; +} + +#ifdef HAVE_WCHAR +/* + * __getnsp -- + * Read non-spacing character chain from file + */ +static int +__getnsp(nschar_t *nsp, FILE *fp) +{ + int n; + nschar_t *onsp, *tnsp; + + if (fread(&n, sizeof(int), 1, fp) != 1) + return ERR; + onsp = nsp; + while (n != 0) { + tnsp = (nschar_t *)malloc(sizeof(nschar_t)); + if (tnsp == NULL) { + __cursesi_free_nsp(nsp); + return OK; + } + if (fread(&tnsp->ch, sizeof(wchar_t), 1, fp) != 1) { + __cursesi_free_nsp(nsp); + return OK; + } + tnsp->next = NULL; + onsp->next = tnsp; + onsp = onsp->next; + if (fread(&n, sizeof(int), 1, fp) != 1) { + __cursesi_free_nsp(nsp); + return ERR; + } + } + return OK; +} +#endif /* HAVE_WCHAR */ + +/* + * getwin -- + * Read window data from file + */ +WINDOW * +getwin(FILE *fp) +{ + int major, minor; + WINDOW *wtmp, *win; + int y, x; + __LDATA *sp; + +#ifdef DEBUG + __CTRACE(__CTRACE_FILEIO, "getwin\n"); +#endif + + /* Check library version */ + if (fread(&major, sizeof(int), 1, fp) != 1) + return NULL; + if (fread(&minor, sizeof(int), 1, fp) != 1) + return NULL; + if(major != CURSES_LIB_MAJOR || minor != CURSES_LIB_MINOR) + return NULL; + + /* Window parameters */ + wtmp = (WINDOW *)malloc(sizeof(WINDOW)); + if (wtmp == NULL) + return NULL; + if (fread(wtmp, sizeof(WINDOW), 1, fp) != 1) + goto error0; + win = __newwin(_cursesi_screen, wtmp->maxy, wtmp->maxx, + wtmp->begy, wtmp->begx, FALSE); + if (win == NULL) + goto error0; + win->cury = wtmp->cury; + win->curx = wtmp->curx; + win->reqy = wtmp->reqy; + win->reqx = wtmp->reqx; + win->flags = wtmp->flags; + win->delay = wtmp->delay; + win->wattr = wtmp->wattr; + win->bch = wtmp->bch; + win->battr = wtmp->battr; + win->scr_t = wtmp->scr_t; + win->scr_b = wtmp->scr_b; + free(wtmp); + wtmp = NULL; + __swflags(win); + +#ifdef HAVE_WCHAR + if (__getnsp(win->bnsp, fp) == ERR) + goto error1; +#endif /* HAVE_WCHAR */ + + /* Lines and line data */ + for (y = 0; y < win->maxy; y++) { + for (sp = win->alines[y]->line, x = 0; x < win->maxx; + x++, sp++) { + if (fread(&sp->ch, sizeof(wchar_t), 1, fp) != 1) + goto error1; + if (fread(&sp->attr, sizeof(attr_t), 1, fp) != 1) + goto error1; +#ifdef HAVE_WCHAR + if (sp->nsp != NULL) { + if (__getnsp(win->bnsp, fp) == ERR) + goto error1; + } +#endif /* HAVE_WCHAR */ + } + __touchline(win, y, 0, (int) win->maxx - 1); + } +#ifdef DEBUG + __CTRACE(__CTRACE_FILEIO, "getwin: win = 0x%p\n", win); +#endif + return win; + +error1: + delwin(win); +error0: + if (wtmp) + free(wtmp); + return NULL; +} diff --git a/lib/libcurses/fileio.h b/lib/libcurses/fileio.h new file mode 100644 index 000000000..ef38907b3 --- /dev/null +++ b/lib/libcurses/fileio.h @@ -0,0 +1,8 @@ +/* + * Do not edit! Automatically generated file: + * from: NetBSD: shlib_version,v 1.40 2009/01/11 03:07:47 christos Exp + * by : NetBSD: genfileioh.awk,v 1.2 2008/05/02 11:13:02 martin Exp + */ + +#define CURSES_LIB_MAJOR 7 +#define CURSES_LIB_MINOR 0 diff --git a/lib/libcurses/flash.c b/lib/libcurses/flash.c deleted file mode 100644 index 2de45606c..000000000 --- a/lib/libcurses/flash.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include "curspriv.h" -#include - -extern char *bl, *vb; - -/* Flash() flashes the terminal screen. */ -void flash() -{ - if (vb) - tputs(vb, 1, outc); - else if (bl) - tputs(bl, 1, outc); -} diff --git a/lib/libcurses/flushok.c b/lib/libcurses/flushok.c new file mode 100644 index 000000000..25f86745d --- /dev/null +++ b/lib/libcurses/flushok.c @@ -0,0 +1,52 @@ +/* $NetBSD: flushok.c,v 1.5 2008/04/28 20:23:01 martin Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Julian Coleman. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: flushok.c,v 1.5 2008/04/28 20:23:01 martin Exp $"); +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +/* + * flushok -- + * Turn on and off Fflush(stdout) after refresh for the given window. + */ +int +flushok(WINDOW *win, bool bf) +{ + if (bf) + win->flags |= __FLUSH; + else + win->flags &= ~__FLUSH; + return (OK); +} diff --git a/lib/libcurses/fullname.c b/lib/libcurses/fullname.c new file mode 100644 index 000000000..026c5c78c --- /dev/null +++ b/lib/libcurses/fullname.c @@ -0,0 +1,64 @@ +/* $NetBSD: fullname.c,v 1.11 2003/08/07 16:44:21 agc Exp $ */ + +/* + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)fullname.c 8.1 (Berkeley) 6/4/93"; +#else +__RCSID("$NetBSD: fullname.c,v 1.11 2003/08/07 16:44:21 agc Exp $"); +#endif +#endif /* not lint */ + +#include "curses.h" + +/* + * fullname -- + * This routine fills in "def" with the full name of the terminal. + * This is assumed to be the last name in the list of aliases. + */ +char * +fullname(const char *bp, char *def) +{ + char *cp; + + *def = '\0'; /* In case no name. */ + + while (*bp && *bp != ':') { + cp = def; /* Start of answer. */ + while (*bp && *bp != ':' && *bp != '|') + *cp++ = *bp++; /* Copy name over. */ + *cp = '\0'; /* Zero end of name. */ + if (*bp == '|') + bp++; /* Skip over '|' if that is case. */ + } + return (def); +} diff --git a/lib/libcurses/genfileioh.awk b/lib/libcurses/genfileioh.awk new file mode 100644 index 000000000..3106d4d56 --- /dev/null +++ b/lib/libcurses/genfileioh.awk @@ -0,0 +1,66 @@ +#!/usr/bin/awk -F +# +# $NetBSD: genfileioh.awk,v 1.2 2008/05/02 11:13:02 martin Exp $ +# +# Copyright (c) 2008 The NetBSD Foundation, Inc. +# All rights reserved. +# +# This code is derived from software contributed to The NetBSD Foundation +# by Julian Coleman. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +function mangle_vers(vers) { + sub("^.*\\$NetBSD", "NetBSD", vers); + sub("\\$[^$]*$", "", vers); + return vers; +} + +BEGIN { + MYVER="$NetBSD: genfileioh.awk,v 1.2 2008/05/02 11:13:02 martin Exp $"; + MYVER=mangle_vers(MYVER); +} + +{ + if ($0 ~/\$NetBSD:/) { + SHVER=mangle_vers($0); + } + if ($1 ~ /^major=/) { + MAJ=$1; + sub("^major=", "", MAJ); + } + if ($1 ~ /^minor=/) { + MIN=$1; + sub("^minor=", "", MIN); + } +} + +END { + printf("/*\n"); + printf(" * Do not edit! Automatically generated file:\n"); + printf(" * from: %s\n", SHVER); + printf(" * by : %s\n", MYVER); + printf(" */\n"); + printf("\n"); + printf("#define CURSES_LIB_MAJOR %s\n", MAJ); + printf("#define CURSES_LIB_MINOR %s\n", MIN); +} diff --git a/lib/libcurses/get_wch.c b/lib/libcurses/get_wch.c new file mode 100644 index 000000000..4430467d0 --- /dev/null +++ b/lib/libcurses/get_wch.c @@ -0,0 +1,658 @@ +/* $NetBSD: get_wch.c,v 1.9 2010/12/16 17:42:28 wiz Exp $ */ + +/* + * Copyright (c) 2005 The NetBSD Foundation Inc. + * All rights reserved. + * + * This code is derived from code donated to the NetBSD Foundation + * by Ruibiao Qiu . + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND + * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: get_wch.c,v 1.9 2010/12/16 17:42:28 wiz Exp $"); +#endif /* not lint */ + +#include +#include +#include +#include +#include "curses.h" +#include "curses_private.h" +#include "keymap.h" + +#ifdef HAVE_WCHAR +static short wstate; /* state of the wcinkey function */ +#endif /* HAVE_WCHAR */ +extern short state; /* storage declared in getch.c */ + +/* prototypes for private functions */ +#ifdef HAVE_WCHAR +static int inkey(wchar_t *wc, int to, int delay); +#endif /* HAVE_WCHAR */ + +#ifdef HAVE_WCHAR +/* + * __init_get_wch - initialise all the pointers & structures needed to make + * get_wch work in keypad mode. + * + */ +void +__init_get_wch(SCREEN *screen) +{ + wstate = INKEY_NORM; + memset( &screen->cbuf, 0, MAX_CBUF_SIZE * sizeof( int )); + screen->cbuf_head = screen->cbuf_tail = screen->cbuf_cur = 0; +} +#endif /* HAVE_WCHAR */ + + +#ifdef HAVE_WCHAR +/* + * inkey - do the work to process keyboard input, check for multi-key + * sequences and return the appropriate symbol if we get a match. + * + */ +static int +inkey(wchar_t *wc, int to, int delay) +{ + wchar_t k = 0; + int c, mapping, ret = 0; + size_t mlen = 0; + keymap_t *current = _cursesi_screen->base_keymap; + FILE *infd = _cursesi_screen->infd; + int *start = &_cursesi_screen->cbuf_head, + *working = &_cursesi_screen->cbuf_cur, + *end = &_cursesi_screen->cbuf_tail; + char *inbuf = &_cursesi_screen->cbuf[ 0 ]; + +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, "inkey (%p, %d, %d)\n", wc, to, delay); +#endif + for (;;) { /* loop until we get a complete key sequence */ + if (wstate == INKEY_NORM) { + if (delay && __timeout(delay) == ERR) + return ERR; + c = fgetc(infd); + if (c == WEOF) { + clearerr(infd); + return ERR; + } + + if (delay && (__notimeout() == ERR)) + return ERR; + + k = (wchar_t) c; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "inkey (wstate normal) got '%s'\n", unctrl(k)); +#endif + + inbuf[ *end ] = k; + *end = ( *end + 1 ) % MAX_CBUF_SIZE; + *working = *start; + wstate = INKEY_ASSEMBLING; /* go to assembling state */ +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "inkey: NORM=>ASSEMBLING: start(%d), " + "current(%d), end(%d)\n", *start, *working, *end); +#endif /* DEBUG */ + } else if (wstate == INKEY_BACKOUT) { + k = inbuf[*working]; + *working = ( *working + 1 ) % MAX_CBUF_SIZE; + if (*working == *end) { /* see if run out of keys */ + /* if so, switch to assembling */ + wstate = INKEY_ASSEMBLING; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "inkey: BACKOUT=>ASSEMBLING, start(%d), " + "current(%d), end(%d)\n", + *start, *working, *end); +#endif /* DEBUG */ + } + } else if (wstate == INKEY_ASSEMBLING) { + /* assembling a key sequence */ + if (delay) { + if (__timeout(to ? (ESCDELAY / 100) : delay) + == ERR) + return ERR; + } else { + if (to && (__timeout(ESCDELAY / 100) == ERR)) + return ERR; + } + + c = fgetc(infd); + if (ferror(infd)) { + clearerr(infd); + return ERR; + } + + if ((to || delay) && (__notimeout() == ERR)) + return ERR; + + k = (wchar_t) c; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "inkey (wstate assembling) got '%s'\n", unctrl(k)); +#endif /* DEBUG */ + if (feof(infd)) { /* inter-char T/O, start backout */ + clearerr(infd); + if (*start == *end) + /* no chars in the buffer, restart */ + continue; + + k = inbuf[*start]; + wstate = INKEY_TIMEOUT; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "inkey: ASSEMBLING=>TIMEOUT, start(%d), " + "current(%d), end(%d)\n", + *start, *working, *end); +#endif /* DEBUG */ + } else { + inbuf[ *end ] = k; + *working = *end; + *end = ( *end + 1 ) % MAX_CBUF_SIZE; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "inkey: ASSEMBLING: start(%d), " + "current(%d), end(%d)", + *start, *working, *end); +#endif /* DEBUG */ + } + } else if (wstate == INKEY_WCASSEMBLING) { + /* assembling a wide-char sequence */ + if (delay) { + if (__timeout(to ? (ESCDELAY / 100) : delay) + == ERR) + return ERR; + } else { + if (to && (__timeout(ESCDELAY / 100) == ERR)) + return ERR; + } + + c = fgetc(infd); + if (ferror(infd)) { + clearerr(infd); + return ERR; + } + + if ((to || delay) && (__notimeout() == ERR)) + return ERR; + + k = (wchar_t) c; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "inkey (wstate wcassembling) got '%s'\n", + unctrl(k)); +#endif + if (feof(infd)) { /* inter-char T/O, start backout */ + clearerr(infd); + if (*start == *end) + /* no chars in the buffer, restart */ + continue; + + *wc = inbuf[*start]; + *working = *start + = ( *start + 1 ) % MAX_CBUF_SIZE; + if (*start == *end) { + state = wstate = INKEY_NORM; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "inkey: WCASSEMBLING=>NORM, " + "start(%d), current(%d), end(%d)", + *start, *working, *end); +#endif /* DEBUG */ + } else { + state = wstate = INKEY_BACKOUT; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "inkey: WCASSEMBLING=>BACKOUT, " + "start(%d), current(%d), end(%d)", + *start, *working, *end); +#endif /* DEBUG */ + } + return OK; + } else { + /* assembling wide characters */ + inbuf[ *end ] = k; + *working = *end; + *end = ( *end + 1 ) % MAX_CBUF_SIZE; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "inkey: WCASSEMBLING[head(%d), " + "urrent(%d), tail(%d)]\n", + *start, *working, *end); +#endif /* DEBUG */ + ret = (int) mbrtowc( wc, inbuf + (*working), 1, + &_cursesi_screen->sp ); +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "inkey: mbrtowc returns %d, wc(%x)\n", + ret, *wc ); +#endif /* DEBUG */ + if ( ret == -2 ) { + *working = (*working + 1) + % MAX_CBUF_SIZE; + continue; + } + if ( ret == 0 ) + ret = 1; + if ( ret == -1 ) { + /* return the 1st character we know */ + *wc = inbuf[ *start ]; + *working = *start = ( *start + 1 ) % MAX_CBUF_SIZE; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "inkey: Invalid wide char(%x) " + "[head(%d), current(%d), " + "tail(%d)]\n", + *wc, *start, *working, *end); +#endif /* DEBUG */ + } else { /* > 0 */ + /* return the wide character */ + *start = *working + = (*working + ret)%MAX_CBUF_SIZE; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "inkey: Wide char found(%x) " + "[head(%d), current(%d), " + "tail(%d)]\n", + *wc, *start, *working, *end); +#endif /* DEBUG */ + } + + if (*start == *end) { /* only one char processed */ + state = wstate = INKEY_NORM; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "inkey: WCASSEMBLING=>NORM, " + "start(%d), current(%d), end(%d)", + *start, *working, *end); +#endif /* DEBUG */ + } else { + /* otherwise we must have more than one char to backout */ + state = wstate = INKEY_BACKOUT; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "inkey: WCASSEMBLING=>BACKOUT, " + "start(%d), current(%d), end(%d)", + *start, *working, *end); +#endif /* DEBUG */ + } + return OK; + } + } else { + fprintf(stderr, "Inkey wstate screwed - exiting!!!"); + exit(2); + } + + /* + * Check key has no special meaning and we have not + * timed out and the key has not been disabled + */ + mapping = current->mapping[k]; + if (((wstate == INKEY_TIMEOUT) || (mapping < 0)) + || ((current->key[mapping]->type + == KEYMAP_LEAF) + && (current->key[mapping]->enable == FALSE))) { + /* wide-character specific code */ +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "inkey: Checking for wide char\n"); +#endif /* DEBUG */ + mbrtowc( NULL, NULL, 1, &_cursesi_screen->sp ); + *working = *start; + mlen = *end > *working ? + *end - *working : MAX_CBUF_SIZE - *working; + if ( !mlen ) + return ERR; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "inkey: Check wide char[head(%d), " + "current(%d), tail(%d), mlen(%ld)]\n", + *start, *working, *end, (long) mlen); +#endif /* DEBUG */ + ret = (int) mbrtowc( wc, inbuf + (*working), mlen, + &_cursesi_screen->sp ); +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "inkey: mbrtowc returns %d, wc(%x)\n", ret, *wc); +#endif /* DEBUG */ + if ( ret == -2 && *end < *working ) { + /* second half of a wide character */ + *working = 0; + mlen = *end; + if ( mlen ) + ret = (int) mbrtowc( wc, inbuf, mlen, + &_cursesi_screen->sp ); + } + if ( ret == -2 && wstate != INKEY_TIMEOUT ) { + *working = (*working + (int) mlen) + % MAX_CBUF_SIZE; + wstate = INKEY_WCASSEMBLING; + continue; + } + if ( ret == 0 ) + ret = 1; + if ( ret == -1 ) { + /* return the first key we know about */ + *wc = inbuf[ *start ]; + *working = *start + = ( *start + 1 ) % MAX_CBUF_SIZE; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "inkey: Invalid wide char(%x)[head(%d), " + "current(%d), tail(%d)]\n", + *wc, *start, *working, *end); +#endif /* DEBUG */ + } else { /* > 0 */ + /* return the wide character */ + *start = *working + = ( *working + ret ) % MAX_CBUF_SIZE; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "inkey: Wide char found(%x)[head(%d), " + "current(%d), tail(%d)]\n", + *wc, *start, *working, *end); +#endif /* DEBUG */ + } + + if (*start == *end) { /* only one char processed */ + state = wstate = INKEY_NORM; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "inkey: Empty cbuf=>NORM, " + "start(%d), current(%d), end(%d)\n", + *start, *working, *end); +#endif /* DEBUG */ + } else { + /* otherwise we must have more than one char to backout */ + state = wstate = INKEY_BACKOUT; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "inkey: Non-empty cbuf=>BACKOUT, " + "start(%d), current(%d), end(%d)\n", + *start, *working, *end); +#endif /* DEBUG */ + } + return OK; + } else { /* must be part of a multikey sequence */ + /* check for completed key sequence */ + if (current->key[current->mapping[k]]->type + == KEYMAP_LEAF) { + /* eat the key sequence in cbuf */ + *start = *working = ( *working + 1 ) % MAX_CBUF_SIZE; + + /* check if inbuf empty now */ +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "inkey: Key found(%s)\n", + key_name(current->key[mapping]->value.symbol)); +#endif /* DEBUG */ + if (*start == *end) { + /* if it is go back to normal */ + state = wstate = INKEY_NORM; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "[inkey]=>NORM, start(%d), " + "current(%d), end(%d)", + *start, *working, *end); +#endif /* DEBUG */ + } else { + /* otherwise go to backout state */ + state = wstate = INKEY_BACKOUT; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "[inkey]=>BACKOUT, start(%d), " + "current(%d), end(%d)", + *start, *working, *end ); +#endif /* DEBUG */ + } + + /* return the symbol */ + *wc = current->key[mapping]->value.symbol; + return KEY_CODE_YES; + } else { + /* Step to next part of multi-key sequence */ + current = current->key[current->mapping[k]]->value.next; + } + } + } +} +#endif /* HAVE_WCHAR */ + +/* + * get_wch -- + * Read in a wide character from stdscr. + */ +int +get_wch(wint_t *ch) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return wget_wch(stdscr, ch); +#endif /* HAVE_WCHAR */ +} + +/* + * mvget_wch -- + * Read in a character from stdscr at the given location. + */ +int +mvget_wch(int y, int x, wint_t *ch) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return mvwget_wch(stdscr, y, x, ch); +#endif /* HAVE_WCHAR */ +} + +/* + * mvwget_wch -- + * Read in a character from stdscr at the given location in the + * given window. + */ +int +mvwget_wch(WINDOW *win, int y, int x, wint_t *ch) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + if (wmove(win, y, x) == ERR) + return ERR; + + return wget_wch(win, ch); +#endif /* HAVE_WCHAR */ +} + +/* + * wget_wch -- + * Read in a wide character from the window. + */ +int +wget_wch(WINDOW *win, wint_t *ch) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + int ret, weset; + int c; + FILE *infd = _cursesi_screen->infd; + cchar_t wc; + wchar_t inp, ws[ 2 ]; + + if (!(win->flags & __SCROLLOK) && (win->flags & __FULLWIN) + && win->curx == win->maxx - 1 + && win->cury == win->maxy - 1 + && __echoit) + return (ERR); + + if (is_wintouched(win)) + wrefresh(win); +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, "wget_wch: __echoit = %d, " + "__rawmode = %d, __nl = %d, flags = %#.4x\n", + __echoit, __rawmode, _cursesi_screen->nl, win->flags); +#endif + if (_cursesi_screen->resized) { + _cursesi_screen->resized = 0; + *ch = KEY_RESIZE; + return KEY_CODE_YES; + } + if (_cursesi_screen->unget_pos) { +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, "wget_wch returning char at %d\n", + _cursesi_screen->unget_pos); +#endif + _cursesi_screen->unget_pos--; + *ch = _cursesi_screen->unget_list[_cursesi_screen->unget_pos]; + if (__echoit) { + ws[0] = *ch, ws[1] = L'\0'; + setcchar(&wc, ws, win->wattr, 0, NULL); + wadd_wch(win, &wc); + } + return KEY_CODE_YES; + } + if (__echoit && !__rawmode) { + cbreak(); + weset = 1; + } else + weset = 0; + + __save_termios(); + + if (win->flags & __KEYPAD) { + switch (win->delay) { + case -1: + ret = inkey(&inp, + win->flags & __NOTIMEOUT ? 0 : 1, 0); + break; + case 0: + if (__nodelay() == ERR) + return ERR; + ret = inkey(&inp, 0, 0); + break; + default: + ret = inkey(&inp, + win->flags & __NOTIMEOUT ? 0 : 1, + win->delay); + break; + } + if ( ret == ERR ) + return ERR; + } else { + switch (win->delay) { + case -1: + break; + case 0: + if (__nodelay() == ERR) + return ERR; + break; + default: + if (__timeout(win->delay) == ERR) + return ERR; + break; + } + + c = getwchar(); + if (feof(infd)) { + clearerr(infd); + __restore_termios(); + return ERR; /* we have timed out */ + } + + if (ferror(infd)) { + clearerr(infd); + return ERR; + } else { + ret = c; + inp = c; + } + } +#ifdef DEBUG + if (inp > 255) + /* we have a key symbol - treat it differently */ + /* XXXX perhaps __unctrl should be expanded to include + * XXXX the keysyms in the table.... + */ + __CTRACE(__CTRACE_INPUT, "wget_wch assembled keysym 0x%x\n", + inp); + else + __CTRACE(__CTRACE_INPUT, "wget_wch got '%s'\n", unctrl(inp)); +#endif + if (win->delay > -1) { + if (__delay() == ERR) + return ERR; + } + + __restore_termios(); + + if (__echoit) { + if ( ret == KEY_CODE_YES ) { + /* handle [DEL], [BS], and [LEFT] */ + if ( win->curx && + ( inp == KEY_DC || + inp == KEY_BACKSPACE || + inp == KEY_LEFT )) { + wmove( win, win->cury, win->curx - 1 ); + wdelch( win ); + } + } else { + ws[ 0 ] = inp, ws[ 1 ] = L'\0'; + setcchar( &wc, ws, win->wattr, 0, NULL ); + wadd_wch( win, &wc ); + } + } + + if (weset) + nocbreak(); + + if (_cursesi_screen->nl && inp == 13) + inp = 10; + + *ch = inp; + + if ( ret == KEY_CODE_YES ) + return KEY_CODE_YES; + return ( inp < 0 ? ERR : OK ); +#endif /* HAVE_WCHAR */ +} + +/* + * unget_wch -- + * Put the wide character back into the input queue. + */ +int +unget_wch(const wchar_t c) +{ + return __unget((wint_t) c); +} diff --git a/lib/libcurses/get_wstr.c b/lib/libcurses/get_wstr.c new file mode 100644 index 000000000..b95c8276e --- /dev/null +++ b/lib/libcurses/get_wstr.c @@ -0,0 +1,291 @@ +/* $NetBSD: get_wstr.c,v 1.3 2008/04/14 20:33:59 jdc Exp $ */ + +/* + * Copyright (c) 2005 The NetBSD Foundation Inc. + * All rights reserved. + * + * This code is derived from code donated to the NetBSD Foundation + * by Ruibiao Qiu . + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND + * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: get_wstr.c,v 1.3 2008/04/14 20:33:59 jdc Exp $"); +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +/* prototypes for private functions */ +#ifdef HAVE_WCHAR +static int __wgetn_wstr(WINDOW *, wchar_t *, int); +#endif /* HAVE_WCHAR */ + +/* + * getn_wstr -- + * Get a string (of maximum n) characters from stdscr starting at + * (cury, curx). + */ +int +getn_wstr(wchar_t *wstr, int n) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return wgetn_wstr(stdscr, wstr, n); +#endif /* HAVE_WCHAR */ +} + +/* + * get_wstr -- + * Get a string from stdscr starting at (cury, curx). + */ +__warn_references(get_wstr, + "warning: this program uses get_wstr(), which is unsafe.") +int +get_wstr(wchar_t *wstr) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return wget_wstr(stdscr, wstr); +#endif /* HAVE_WCHAR */ +} + +/* + * mvgetn_wstr -- + * Get a string (of maximum n) characters from stdscr starting at (y, x). + */ +int +mvgetn_wstr(int y, int x, wchar_t *wstr, int n) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return mvwgetn_wstr(stdscr, y, x, wstr, n); +#endif /* HAVE_WCHAR */ +} + +/* + * mvget_wstr -- + * Get a string from stdscr starting at (y, x). + */ +__warn_references(mvget_wstr, + "warning: this program uses mvget_wstr(), which is unsafe.") +int +mvget_wstr(int y, int x, wchar_t *wstr) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return mvwget_wstr(stdscr, y, x, wstr); +#endif /* HAVE_WCHAR */ +} + +/* + * mvwgetn_wstr -- + * Get a string (of maximum n) characters from the given window starting + * at (y, x). + */ +int +mvwgetn_wstr(WINDOW *win, int y, int x, wchar_t *wstr, int n) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + if (wmove(win, y, x) == ERR) + return ERR; + + return wgetn_wstr(win, wstr, n); +#endif /* HAVE_WCHAR */ +} + +/* + * mvwget_wstr -- + * Get a string from the given window starting at (y, x). + */ +__warn_references(mvget_wstr, + "warning: this program uses mvget_wstr(), which is unsafe.") +int +mvwget_wstr(WINDOW *win, int y, int x, wchar_t *wstr) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + if (wmove(win, y, x) == ERR) + return ERR; + + return wget_wstr(win, wstr); +#endif /* HAVE_WCHAR */ +} + +/* + * wget_wstr -- + * Get a string starting at (cury, curx). + */ +__warn_references(wget_wstr, + "warning: this program uses wget_wstr(), which is unsafe.") +int +wget_wstr(WINDOW *win, wchar_t *wstr) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return __wgetn_wstr(win, wstr, -1); +#endif /* HAVE_WCHAR */ +} + +/* + * wgetn_wstr -- + * Get a string starting at (cury, curx). + * Note that n < 2 means that we return ERR (SUSv2 specification). + */ +int +wgetn_wstr(WINDOW *win, wchar_t *wstr, int n) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + if (n < 1) + return (ERR); + if (n == 1) { + wstr[0] = L'\0'; + return (ERR); + } + return __wgetn_wstr(win, wstr, n); +#endif /* HAVE_WCHAR */ +} + +#ifdef HAVE_WCHAR +/* + * __wgetn_wstr -- + * The actual implementation. + * Note that we include a trailing L'\0' for safety, so str will contain + * at most n - 1 other characters. + */ +int +__wgetn_wstr(WINDOW *win, wchar_t *wstr, int n) +{ + wchar_t *ostr, ec, kc, sc[ 2 ]; + int oldx, remain; + wint_t wc; + cchar_t cc; + + ostr = wstr; + if ( erasewchar( &ec ) == ERR ) + return ERR; + if ( killwchar( &kc ) == ERR ) + return ERR; + sc[ 0 ] = ( wchar_t )btowc( ' ' ); + sc[ 1 ] = L'\0'; + setcchar( &cc, sc, win->wattr, 0, NULL ); + oldx = win->curx; + remain = n - 1; + + while (wget_wch(win, &wc) != ERR + && wc != L'\n' && wc != L'\r') { +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "__wgetn_wstr: win %p, char 0x%x, remain %d\n", + win, wc, remain); +#endif + *wstr = wc; + touchline(win, win->cury, 1); + if (wc == ec || wc == KEY_BACKSPACE || wc == KEY_LEFT) { + *wstr = L'\0'; + if (wstr != ostr) { + if ((wchar_t)wc == ec) { + mvwadd_wch(win, win->cury, + win->curx, &cc); + wmove(win, win->cury, win->curx - 1); + } + if (wc == KEY_BACKSPACE || wc == KEY_LEFT) { + /* getch() displays the key sequence */ + mvwadd_wch(win, win->cury, + win->curx - 1, &cc); + mvwadd_wch(win, win->cury, + win->curx - 2, &cc); + wmove(win, win->cury, win->curx - 1); + } + wstr--; + if (n != -1) { + /* We're counting chars */ + remain++; + } + } else { /* str == ostr */ + if (wc == KEY_BACKSPACE || wc == KEY_LEFT) + /* getch() displays the other keys */ + mvwadd_wch(win, win->cury, + win->curx - 1, &cc); + wmove(win, win->cury, oldx); + } + } else if (wc == kc) { + *wstr = L'\0'; + if (wstr != ostr) { + /* getch() displays the kill character */ + mvwadd_wch(win, win->cury, win->curx - 1, &cc); + /* Clear the characters from screen and str */ + while (wstr != ostr) { + mvwadd_wch(win, win->cury, + win->curx - 1, &cc); + wmove(win, win->cury, win->curx - 1); + wstr--; + if (n != -1) + /* We're counting chars */ + remain++; + } + mvwadd_wch(win, win->cury, win->curx - 1, &cc); + wmove(win, win->cury, win->curx - 1); + } else + /* getch() displays the kill character */ + mvwadd_wch( win, win->cury, oldx, &cc ); + wmove(win, win->cury, oldx); + } else if (wc >= KEY_MIN && wc <= KEY_MAX) { + /* get_wch() displays these characters */ + mvwadd_wch( win, win->cury, win->curx - 1, &cc ); + wmove(win, win->cury, win->curx - 1); + } else { + if (remain) { + wstr++; + remain--; + } else { + mvwadd_wch(win, win->cury, win->curx - 1, &cc); + wmove(win, win->cury, win->curx - 1); + } + } + } + + if (wc == ERR) { + *wstr = L'\0'; + return ERR; + } + *wstr = L'\0'; + return OK; +} +#endif /* HAVE_WCHAR */ diff --git a/lib/libcurses/getch.c b/lib/libcurses/getch.c new file mode 100644 index 000000000..4c1163f89 --- /dev/null +++ b/lib/libcurses/getch.c @@ -0,0 +1,967 @@ +/* $NetBSD: getch.c,v 1.57 2010/12/07 22:02:52 joerg Exp $ */ + +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)getch.c 8.2 (Berkeley) 5/4/94"; +#else +__RCSID("$NetBSD: getch.c,v 1.57 2010/12/07 22:02:52 joerg Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#include +#include +#include "curses.h" +#include "curses_private.h" +#include "keymap.h" + +short state; /* state of the inkey function */ + +static const struct tcdata tc[] = { + {TICODE_kSAV, KEY_SSAVE}, + {TICODE_kSPD, KEY_SSUSPEND}, + {TICODE_kUND, KEY_SUNDO}, + {TICODE_kHLP, KEY_SHELP}, + {TICODE_kHOM, KEY_SHOME}, + {TICODE_kIC, KEY_SIC}, + {TICODE_kLFT, KEY_SLEFT}, + {TICODE_krdo, KEY_REDO}, + {TICODE_khlp, KEY_HELP}, + {TICODE_kmrk, KEY_MARK}, + {TICODE_kmsg, KEY_MESSAGE}, + {TICODE_kmov, KEY_MOVE}, + {TICODE_knxt, KEY_NEXT}, + {TICODE_kopn, KEY_OPEN}, + {TICODE_kopt, KEY_OPTIONS}, + {TICODE_kprv, KEY_PREVIOUS}, + {TICODE_kprt, KEY_PRINT}, + {TICODE_kMSG, KEY_SMESSAGE}, + {TICODE_kMOV, KEY_SMOVE}, + {TICODE_kNXT, KEY_SNEXT}, + {TICODE_kOPT, KEY_SOPTIONS}, + {TICODE_kPRV, KEY_SPREVIOUS}, + {TICODE_kPRT, KEY_SPRINT}, + {TICODE_kRDO, KEY_SREDO}, + {TICODE_kRPL, KEY_SREPLACE}, + {TICODE_kRIT, KEY_SRIGHT}, + {TICODE_kRES, KEY_SRSUME}, + {TICODE_kCAN, KEY_SCANCEL}, + {TICODE_kref, KEY_REFERENCE}, + {TICODE_krfr, KEY_REFRESH}, + {TICODE_krpl, KEY_REPLACE}, + {TICODE_krst, KEY_RESTART}, + {TICODE_kres, KEY_RESUME}, + {TICODE_ksav, KEY_SAVE}, + {TICODE_kspd, KEY_SUSPEND}, + {TICODE_kund, KEY_UNDO}, + {TICODE_kBEG, KEY_SBEG}, + {TICODE_kFND, KEY_SFIND}, + {TICODE_kCMD, KEY_SCOMMAND}, + {TICODE_kCPY, KEY_SCOPY}, + {TICODE_kCRT, KEY_SCREATE}, + {TICODE_kDC, KEY_SDC}, + {TICODE_kDL, KEY_SDL}, + {TICODE_kslt, KEY_SELECT}, + {TICODE_kEND, KEY_SEND}, + {TICODE_kEOL, KEY_SEOL}, + {TICODE_kEXT, KEY_SEXIT}, + {TICODE_kfnd, KEY_FIND}, + {TICODE_kbeg, KEY_BEG}, + {TICODE_kcan, KEY_CANCEL}, + {TICODE_kclo, KEY_CLOSE}, + {TICODE_kcmd, KEY_COMMAND}, + {TICODE_kcpy, KEY_COPY}, + {TICODE_kcrt, KEY_CREATE}, + {TICODE_kend, KEY_END}, + {TICODE_kent, KEY_ENTER}, + {TICODE_kext, KEY_EXIT}, + {TICODE_kf11, KEY_F(11)}, + {TICODE_kf12, KEY_F(12)}, + {TICODE_kf13, KEY_F(13)}, + {TICODE_kf14, KEY_F(14)}, + {TICODE_kf15, KEY_F(15)}, + {TICODE_kf16, KEY_F(16)}, + {TICODE_kf17, KEY_F(17)}, + {TICODE_kf18, KEY_F(18)}, + {TICODE_kf19, KEY_F(19)}, + {TICODE_kf20, KEY_F(20)}, + {TICODE_kf21, KEY_F(21)}, + {TICODE_kf22, KEY_F(22)}, + {TICODE_kf23, KEY_F(23)}, + {TICODE_kf24, KEY_F(24)}, + {TICODE_kf25, KEY_F(25)}, + {TICODE_kf26, KEY_F(26)}, + {TICODE_kf27, KEY_F(27)}, + {TICODE_kf28, KEY_F(28)}, + {TICODE_kf29, KEY_F(29)}, + {TICODE_kf30, KEY_F(30)}, + {TICODE_kf31, KEY_F(31)}, + {TICODE_kf32, KEY_F(32)}, + {TICODE_kf33, KEY_F(33)}, + {TICODE_kf34, KEY_F(34)}, + {TICODE_kf35, KEY_F(35)}, + {TICODE_kf36, KEY_F(36)}, + {TICODE_kf37, KEY_F(37)}, + {TICODE_kf38, KEY_F(38)}, + {TICODE_kf39, KEY_F(39)}, + {TICODE_kf40, KEY_F(40)}, + {TICODE_kf41, KEY_F(41)}, + {TICODE_kf42, KEY_F(42)}, + {TICODE_kf43, KEY_F(43)}, + {TICODE_kf44, KEY_F(44)}, + {TICODE_kf45, KEY_F(45)}, + {TICODE_kf46, KEY_F(46)}, + {TICODE_kf47, KEY_F(47)}, + {TICODE_kf48, KEY_F(48)}, + {TICODE_kf49, KEY_F(49)}, + {TICODE_kf50, KEY_F(50)}, + {TICODE_kf51, KEY_F(51)}, + {TICODE_kf52, KEY_F(52)}, + {TICODE_kf53, KEY_F(53)}, + {TICODE_kf54, KEY_F(54)}, + {TICODE_kf55, KEY_F(55)}, + {TICODE_kf56, KEY_F(56)}, + {TICODE_kf57, KEY_F(57)}, + {TICODE_kf58, KEY_F(58)}, + {TICODE_kf59, KEY_F(59)}, + {TICODE_kf60, KEY_F(60)}, + {TICODE_kf61, KEY_F(61)}, + {TICODE_kf62, KEY_F(62)}, + {TICODE_kf63, KEY_F(63)}, + {TICODE_ka1, KEY_A1}, + {TICODE_kb2, KEY_B2}, + {TICODE_ka3, KEY_A3}, + {TICODE_kc1, KEY_C1}, + {TICODE_kc3, KEY_C3}, + {TICODE_kmous, KEY_MOUSE}, + {TICODE_kf0, KEY_F0}, + {TICODE_kf1, KEY_F(1)}, + {TICODE_kf2, KEY_F(2)}, + {TICODE_kf3, KEY_F(3)}, + {TICODE_kf4, KEY_F(4)}, + {TICODE_kf5, KEY_F(5)}, + {TICODE_kf6, KEY_F(6)}, + {TICODE_kf7, KEY_F(7)}, + {TICODE_kf8, KEY_F(8)}, + {TICODE_kf9, KEY_F(9)}, + {TICODE_kf10, KEY_F(10)}, + {TICODE_kil1, KEY_IL}, + {TICODE_ktbc, KEY_CATAB}, + {TICODE_kcbt, KEY_BTAB}, + {TICODE_kbs, KEY_BACKSPACE}, + {TICODE_kclr, KEY_CLEAR}, + {TICODE_kdch1, KEY_DC}, + {TICODE_kcud1, KEY_DOWN}, + {TICODE_kel, KEY_EOL}, + {TICODE_kind, KEY_SF}, + {TICODE_kll, KEY_LL}, + {TICODE_khome, KEY_HOME}, + {TICODE_kich1, KEY_IC}, + {TICODE_kdl1, KEY_DL}, + {TICODE_kcub1, KEY_LEFT}, + {TICODE_krmir, KEY_EIC}, + {TICODE_knp, KEY_NPAGE}, + {TICODE_kpp, KEY_PPAGE}, + {TICODE_kri, KEY_SR}, + {TICODE_kcuf1, KEY_RIGHT}, + {TICODE_ked, KEY_EOS}, + {TICODE_khts, KEY_STAB}, + {TICODE_kctab, KEY_CTAB}, + {TICODE_kcuu1, KEY_UP} +}; +/* Number of TC entries .... */ +static const int num_tcs = (sizeof(tc) / sizeof(struct tcdata)); + +int ESCDELAY = 300; /* Delay in ms between keys for esc seq's */ + +/* Key buffer */ +#define INBUF_SZ 16 /* size of key buffer - must be larger than + * longest multi-key sequence */ +static wchar_t inbuf[INBUF_SZ]; +static int start, end, working; /* pointers for manipulating inbuf data */ + +/* prototypes for private functions */ +static void add_key_sequence(SCREEN *screen, char *sequence, int key_type); +static key_entry_t *add_new_key(keymap_t *current, char ch, int key_type, + int symbol); +static void delete_key_sequence(keymap_t *current, int key_type); +static void do_keyok(keymap_t *current, int key_type, bool flag, int *retval); +static keymap_t *new_keymap(void); /* create a new keymap */ +static key_entry_t *new_key(void); /* create a new key entry */ +static wchar_t inkey(int to, int delay); + +/* + * Free the storage associated with the given keymap + */ +void +_cursesi_free_keymap(keymap_t *map) +{ + int i; + + /* check for, and free, child keymaps */ + for (i = 0; i < MAX_CHAR; i++) { + if (map->mapping[i] >= 0) { + if (map->key[map->mapping[i]]->type == KEYMAP_MULTI) + _cursesi_free_keymap( + map->key[map->mapping[i]]->value.next); + } + } + + /* now free any allocated keymap structs */ + for (i = 0; i < map->count; i += KEYMAP_ALLOC_CHUNK) { + free(map->key[i]); + } + + free(map->key); + free(map); +} + + +/* + * Add a new key entry to the keymap pointed to by current. Entry + * contains the character to add to the keymap, type is the type of + * entry to add (either multikey or leaf) and symbol is the symbolic + * value for a leaf type entry. The function returns a pointer to the + * new keymap entry. + */ +static key_entry_t * +add_new_key(keymap_t *current, char chr, int key_type, int symbol) +{ + key_entry_t *the_key; + int i, ki; + +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, + "Adding character %s of type %d, symbol 0x%x\n", + unctrl(chr), key_type, symbol); +#endif + if (current->mapping[(unsigned char) chr] < 0) { + if (current->mapping[(unsigned char) chr] == MAPPING_UNUSED) { + /* first time for this char */ + current->mapping[(unsigned char) chr] = + current->count; /* map new entry */ + ki = current->count; + + /* make sure we have room in the key array first */ + if ((current->count & (KEYMAP_ALLOC_CHUNK - 1)) == 0) + { + if ((current->key = + realloc(current->key, + ki * sizeof(key_entry_t *) + + KEYMAP_ALLOC_CHUNK * sizeof(key_entry_t *))) == NULL) { + fprintf(stderr, + "Could not malloc for key entry\n"); + exit(1); + } + + the_key = new_key(); + for (i = 0; i < KEYMAP_ALLOC_CHUNK; i++) { + current->key[ki + i] = &the_key[i]; + } + } + } else { + /* the mapping was used but freed, reuse it */ + ki = - current->mapping[(unsigned char) chr]; + current->mapping[(unsigned char) chr] = ki; + } + + current->count++; + + /* point at the current key array element to use */ + the_key = current->key[ki]; + + the_key->type = key_type; + + switch (key_type) { + case KEYMAP_MULTI: + /* need for next key */ +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "Creating new keymap\n"); +#endif + the_key->value.next = new_keymap(); + the_key->enable = TRUE; + break; + + case KEYMAP_LEAF: + /* the associated symbol for the key */ +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "Adding leaf key\n"); +#endif + the_key->value.symbol = symbol; + the_key->enable = TRUE; + break; + + default: + fprintf(stderr, "add_new_key: bad type passed\n"); + exit(1); + } + } else { + /* the key is already known - just return the address. */ +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "Keymap already known\n"); +#endif + the_key = current->key[current->mapping[(unsigned char) chr]]; + } + + return the_key; +} + +/* + * Delete the given key symbol from the key mappings for the screen. + * + */ +void +delete_key_sequence(keymap_t *current, int key_type) +{ + key_entry_t *key; + int i; + + /* + * we need to iterate over all the keys as there may be + * multiple instances of the leaf symbol. + */ + for (i = 0; i < MAX_CHAR; i++) { + if (current->mapping[i] < 0) + continue; /* no mapping for the key, next! */ + + key = current->key[current->mapping[i]]; + + if (key->type == KEYMAP_MULTI) { + /* have not found the leaf, recurse down */ + delete_key_sequence(key->value.next, key_type); + /* if we deleted the last key in the map, free */ + if (key->value.next->count == 0) + _cursesi_free_keymap(key->value.next); + } else if ((key->type == KEYMAP_LEAF) + && (key->value.symbol == key_type)) { + /* + * delete the mapping by negating the current + * index - this "holds" the position in the + * allocation just in case we later re-add + * the key for that mapping. + */ + current->mapping[i] = - current->mapping[i]; + current->count--; + } + } +} + +/* + * Add the sequence of characters given in sequence as the key mapping + * for the given key symbol. + */ +void +add_key_sequence(SCREEN *screen, char *sequence, int key_type) +{ + key_entry_t *tmp_key; + keymap_t *current; + int length, j, key_ent; + +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "add_key_sequence: add key sequence: %s(%s)\n", + sequence, keyname(key_type)); +#endif /* DEBUG */ + current = screen->base_keymap; /* always start with + * base keymap. */ + length = (int) strlen(sequence); + + /* + * OK - we really should never get a zero length string here, either + * the termcap entry is there and it has a value or we are not called + * at all. Unfortunately, if someone assigns a termcap string to the + * ^@ value we get passed a null string which messes up our length. + * So, if we get a null string then just insert a leaf value in + * the 0th char position of the root keymap. Note that we are + * totally screwed if someone terminates a multichar sequence + * with ^@... oh well. + */ + if (length == 0) + length = 1; + + for (j = 0; j < length - 1; j++) { + /* add the entry to the struct */ + tmp_key = add_new_key(current, sequence[j], KEYMAP_MULTI, 0); + + /* index into the key array - it's + clearer if we stash this */ + key_ent = current->mapping[(unsigned char) sequence[j]]; + + current->key[key_ent] = tmp_key; + + /* next key uses this map... */ + current = current->key[key_ent]->value.next; + } + + /* + * This is the last key in the sequence (it may have been the + * only one but that does not matter) this means it is a leaf + * key and should have a symbol associated with it. + */ + tmp_key = add_new_key(current, sequence[length - 1], KEYMAP_LEAF, + key_type); + current->key[current->mapping[(int)sequence[length - 1]]] = tmp_key; +} + +/* + * Init_getch - initialise all the pointers & structures needed to make + * getch work in keypad mode. + * + */ +void +__init_getch(SCREEN *screen) +{ + char entry[1024], *p; + const char *s; + int i; + size_t limit, l; +#ifdef DEBUG + int k, length; +#endif + + /* init the inkey state variable */ + state = INKEY_NORM; + + /* init the base keymap */ + screen->base_keymap = new_keymap(); + + /* key input buffer pointers */ + start = end = working = 0; + + /* now do the terminfo snarfing ... */ + + for (i = 0; i < num_tcs; i++) { + p = entry; + limit = 1023; + s = screen->term->strs[tc[i].code]; + if (s == NULL) + continue; + l = strlen(s) + 1; + if (limit < l) + continue; + strlcpy(p, s, limit); + p += l; + limit -= l; +#ifdef DEBUG + __CTRACE(__CTRACE_INIT, + "Processing termcap entry %d, sequence ", + tc[i].code); + length = (int) strlen(entry); + for (k = 0; k <= length -1; k++) + __CTRACE(__CTRACE_INIT, "%s", unctrl(entry[k])); + __CTRACE(__CTRACE_INIT, "\n"); +#endif + add_key_sequence(screen, entry, tc[i].symbol); + } +} + + +/* + * new_keymap - allocates & initialises a new keymap structure. This + * function returns a pointer to the new keymap. + * + */ +static keymap_t * +new_keymap(void) +{ + int i; + keymap_t *new_map; + + if ((new_map = malloc(sizeof(keymap_t))) == NULL) { + perror("Inkey: Cannot allocate new keymap"); + exit(2); + } + + /* Initialise the new map */ + new_map->count = 0; + for (i = 0; i < MAX_CHAR; i++) { + new_map->mapping[i] = MAPPING_UNUSED; /* no mapping for char */ + } + + /* key array will be allocated when first key is added */ + new_map->key = NULL; + + return new_map; +} + +/* + * new_key - allocates & initialises a new key entry. This function returns + * a pointer to the newly allocated key entry. + * + */ +static key_entry_t * +new_key(void) +{ + key_entry_t *new_one; + int i; + + if ((new_one = malloc(KEYMAP_ALLOC_CHUNK * sizeof(key_entry_t))) + == NULL) { + perror("inkey: Cannot allocate new key entry chunk"); + exit(2); + } + + for (i = 0; i < KEYMAP_ALLOC_CHUNK; i++) { + new_one[i].type = 0; + new_one[i].value.next = NULL; + } + + return new_one; +} + +/* + * inkey - do the work to process keyboard input, check for multi-key + * sequences and return the appropriate symbol if we get a match. + * + */ + +wchar_t +inkey(int to, int delay) +{ + wchar_t k; + int c, mapping; + keymap_t *current = _cursesi_screen->base_keymap; + FILE *infd = _cursesi_screen->infd; + + k = 0; /* XXX gcc -Wuninitialized */ + +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, "inkey (%d, %d)\n", to, delay); +#endif + for (;;) { /* loop until we get a complete key sequence */ +reread: + if (state == INKEY_NORM) { + if (delay && __timeout(delay) == ERR) + return ERR; + c = fgetc(infd); + if (c == EOF) { + clearerr(infd); + return ERR; + } + + if (delay && (__notimeout() == ERR)) + return ERR; + + k = (wchar_t) c; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "inkey (state normal) got '%s'\n", unctrl(k)); +#endif + + working = start; + inbuf[working] = k; + INC_POINTER(working); + end = working; + state = INKEY_ASSEMBLING; /* go to the assembling + * state now */ + } else if (state == INKEY_BACKOUT) { + k = inbuf[working]; + INC_POINTER(working); + if (working == end) { /* see if we have run + * out of keys in the + * backlog */ + + /* if we have then switch to assembling */ + state = INKEY_ASSEMBLING; + } + } else if (state == INKEY_ASSEMBLING) { + /* assembling a key sequence */ + if (delay) { + if (__timeout(to ? (ESCDELAY / 100) : delay) + == ERR) + return ERR; + } else { + if (to && (__timeout(ESCDELAY / 100) == ERR)) + return ERR; + } + + c = fgetc(infd); + if (ferror(infd)) { + clearerr(infd); + return ERR; + } + + if ((to || delay) && (__notimeout() == ERR)) + return ERR; + +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "inkey (state assembling) got '%s'\n", unctrl(k)); +#endif + if (feof(infd) || c == -1) { /* inter-char timeout, + * start backing out */ + clearerr(infd); + if (start == end) + /* no chars in the buffer, restart */ + goto reread; + + k = inbuf[start]; + state = INKEY_TIMEOUT; + } else { + k = (wchar_t) c; + inbuf[working] = k; + INC_POINTER(working); + end = working; + } + } else { + fprintf(stderr, "Inkey state screwed - exiting!!!"); + exit(2); + } + + /* + * Check key has no special meaning and we have not + * timed out and the key has not been disabled + */ + mapping = current->mapping[k]; + if (((state == INKEY_TIMEOUT) || (mapping < 0)) + || ((current->key[mapping]->type == KEYMAP_LEAF) + && (current->key[mapping]->enable == FALSE))) { + /* return the first key we know about */ + k = inbuf[start]; + + INC_POINTER(start); + working = start; + + if (start == end) { /* only one char processed */ + state = INKEY_NORM; + } else {/* otherwise we must have more than one char + * to backout */ + state = INKEY_BACKOUT; + } + return k; + } else { /* must be part of a multikey sequence */ + /* check for completed key sequence */ + if (current->key[current->mapping[k]]->type == KEYMAP_LEAF) { + start = working; /* eat the key sequence + * in inbuf */ + + /* check if inbuf empty now */ + if (start == end) { + /* if it is go back to normal */ + state = INKEY_NORM; + } else { + /* otherwise go to backout state */ + state = INKEY_BACKOUT; + } + + /* return the symbol */ + return current->key[current->mapping[k]]->value.symbol; + + } else { + /* + * Step on to next part of the multi-key + * sequence. + */ + current = current->key[current->mapping[k]]->value.next; + } + } + } +} + +#ifndef _CURSES_USE_MACROS +/* + * getch -- + * Read in a character from stdscr. + */ +int +getch(void) +{ + return wgetch(stdscr); +} + +/* + * mvgetch -- + * Read in a character from stdscr at the given location. + */ +int +mvgetch(int y, int x) +{ + return mvwgetch(stdscr, y, x); +} + +/* + * mvwgetch -- + * Read in a character from stdscr at the given location in the + * given window. + */ +int +mvwgetch(WINDOW *win, int y, int x) +{ + if (wmove(win, y, x) == ERR) + return ERR; + + return wgetch(win); +} + +#endif + +/* + * keyok -- + * Set the enable flag for a keysym, if the flag is false then + * getch will not return this keysym even if the matching key sequence + * is seen. + */ +int +keyok(int key_type, bool flag) +{ + int result = ERR; + + do_keyok(_cursesi_screen->base_keymap, key_type, flag, &result); + return result; +} + +/* + * do_keyok -- + * Does the actual work for keyok, we need to recurse through the + * keymaps finding the passed key symbol. + */ +void +do_keyok(keymap_t *current, int key_type, bool flag, int *retval) +{ + key_entry_t *key; + int i; + + /* + * we need to iterate over all the keys as there may be + * multiple instances of the leaf symbol. + */ + for (i = 0; i < MAX_CHAR; i++) { + if (current->mapping[i] < 0) + continue; /* no mapping for the key, next! */ + + key = current->key[current->mapping[i]]; + + if (key->type == KEYMAP_MULTI) + do_keyok(key->value.next, key_type, flag, retval); + else if ((key->type == KEYMAP_LEAF) + && (key->value.symbol == key_type)) { + key->enable = flag; + *retval = OK; /* we found at least one instance, ok */ + } + } +} + +/* + * define_key -- + * Add a custom mapping of a key sequence to key symbol. + * + */ +int +define_key(char *sequence, int symbol) +{ + + if (symbol <= 0) + return ERR; + + if (sequence == NULL) + delete_key_sequence(_cursesi_screen->base_keymap, symbol); + else + add_key_sequence(_cursesi_screen, sequence, symbol); + + return OK; +} + +/* + * wgetch -- + * Read in a character from the window. + */ +int +wgetch(WINDOW *win) +{ + int inp, weset; + int c; + FILE *infd = _cursesi_screen->infd; + +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, "wgetch: win(%p)\n", win); +#endif + if (!(win->flags & __SCROLLOK) && (win->flags & __FULLWIN) + && win->curx == win->maxx - 1 && win->cury == win->maxy - 1 + && __echoit) + return (ERR); + + if (is_wintouched(win)) + wrefresh(win); +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, "wgetch: __echoit = %d, " + "__rawmode = %d, __nl = %d, flags = %#.4x, delay = %d\n", + __echoit, __rawmode, _cursesi_screen->nl, win->flags, win->delay); +#endif + if (_cursesi_screen->resized) { + _cursesi_screen->resized = 0; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, "wgetch returning KEY_RESIZE\n"); +#endif + return KEY_RESIZE; + } + if (_cursesi_screen->unget_pos) { +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, "wgetch returning char at %d\n", + _cursesi_screen->unget_pos); +#endif + _cursesi_screen->unget_pos--; + c = _cursesi_screen->unget_list[_cursesi_screen->unget_pos]; + if (__echoit) + waddch(win, (chtype) c); + return c; + } + if (__echoit && !__rawmode) { + cbreak(); + weset = 1; + } else + weset = 0; + + __save_termios(); + + if (win->flags & __KEYPAD) { + switch (win->delay) + { + case -1: + inp = inkey (win->flags & __NOTIMEOUT ? 0 : 1, 0); + break; + case 0: + if (__nodelay() == ERR) + return ERR; + inp = inkey(0, 0); + break; + default: + inp = inkey(win->flags & __NOTIMEOUT ? 0 : 1, win->delay); + break; + } + } else { + switch (win->delay) + { + case -1: + if (__delay() == ERR) + return ERR; + break; + case 0: + if (__nodelay() == ERR) + return ERR; + break; + default: + if (__timeout(win->delay) == ERR) + return ERR; + break; + } + + c = fgetc(infd); + if (feof(infd)) { + clearerr(infd); + __restore_termios(); + return ERR; /* we have timed out */ + } + + if (ferror(infd)) { + clearerr(infd); + inp = ERR; + } else { + inp = c; + } + } +#ifdef DEBUG + if (inp > 255) + /* we have a key symbol - treat it differently */ + /* XXXX perhaps __unctrl should be expanded to include + * XXXX the keysyms in the table.... + */ + __CTRACE(__CTRACE_INPUT, "wgetch assembled keysym 0x%x\n", inp); + else + __CTRACE(__CTRACE_INPUT, "wgetch got '%s'\n", unctrl(inp)); +#endif + if (win->delay > -1) { + if (__delay() == ERR) + return ERR; + } + + __restore_termios(); + + if ((__echoit) && (inp < KEY_MIN)) + waddch(win, (chtype) inp); + + if (weset) + nocbreak(); + + if (_cursesi_screen->nl && inp == 13) + inp = 10; + + return ((inp < 0) || (inp == ERR) ? ERR : inp); +} + +/* + * ungetch -- + * Put the character back into the input queue. + */ +int +ungetch(int c) +{ + return __unget((wint_t) c); +} + +/* + * __unget -- + * Do the work for ungetch() and unget_wch(); + */ +int +__unget(wint_t c) +{ + wchar_t *p; + int len; + +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, "__unget(%x)\n", c); +#endif + if (_cursesi_screen->unget_pos >= _cursesi_screen->unget_len) { + len = _cursesi_screen->unget_len + 32; + if ((p = realloc(_cursesi_screen->unget_list, + sizeof(wchar_t) * len)) == NULL) { + /* Can't realloc(), so just lose the oldest entry */ + memmove(_cursesi_screen->unget_list, + _cursesi_screen->unget_list + sizeof(wchar_t), + _cursesi_screen->unget_len - 1); + _cursesi_screen->unget_list[_cursesi_screen->unget_len + - 1] = c; + _cursesi_screen->unget_pos = + _cursesi_screen->unget_len; + return OK; + } else { + _cursesi_screen->unget_pos = + _cursesi_screen->unget_len; + _cursesi_screen->unget_len = len; + _cursesi_screen->unget_list = p; + } + } + _cursesi_screen->unget_list[_cursesi_screen->unget_pos] = c; + _cursesi_screen->unget_pos++; + return OK; +} diff --git a/lib/libcurses/getstr.c b/lib/libcurses/getstr.c new file mode 100644 index 000000000..291238e20 --- /dev/null +++ b/lib/libcurses/getstr.c @@ -0,0 +1,251 @@ +/* $NetBSD: getstr.c,v 1.20 2007/05/28 15:01:55 blymn Exp $ */ + +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)getstr.c 8.2 (Berkeley) 5/4/94"; +#else +__RCSID("$NetBSD: getstr.c,v 1.20 2007/05/28 15:01:55 blymn Exp $"); +#endif +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +#ifndef _CURSES_USE_MACROS + +/* + * getnstr -- + * Get a string (of maximum n) characters from stdscr starting at + * (cury, curx). + */ +int +getnstr(char *str, int n) +{ + return wgetnstr(stdscr, str, n); +} + +/* + * getstr -- + * Get a string from stdscr starting at (cury, curx). + */ +__warn_references(getstr, + "warning: this program uses getstr(), which is unsafe.") +int +getstr(char *str) +{ + return wgetstr(stdscr, str); +} + +/* + * mvgetnstr -- + * Get a string (of maximum n) characters from stdscr starting at (y, x). + */ +int +mvgetnstr(int y, int x, char *str, int n) +{ + return mvwgetnstr(stdscr, y, x, str, n); +} + +/* + * mvgetstr -- + * Get a string from stdscr starting at (y, x). + */ +__warn_references(mvgetstr, + "warning: this program uses mvgetstr(), which is unsafe.") +int +mvgetstr(int y, int x, char *str) +{ + return mvwgetstr(stdscr, y, x, str); +} + +/* + * mvwgetnstr -- + * Get a string (of maximum n) characters from the given window starting + * at (y, x). + */ +int +mvwgetnstr(WINDOW *win, int y, int x, char *str, int n) +{ + if (wmove(win, y, x) == ERR) + return ERR; + + return wgetnstr(win, str, n); +} + +/* + * mvwgetstr -- + * Get a string from the given window starting at (y, x). + */ +__warn_references(mvgetstr, + "warning: this program uses mvgetstr(), which is unsafe.") +int +mvwgetstr(WINDOW *win, int y, int x, char *str) +{ + if (wmove(win, y, x) == ERR) + return ERR; + + return wgetstr(win, str); +} + +#endif + +/* + * wgetstr -- + * Get a string starting at (cury, curx). + */ +__warn_references(wgetstr, + "warning: this program uses wgetstr(), which is unsafe.") +int +wgetstr(WINDOW *win, char *str) +{ + return __wgetnstr(win, str, -1); +} + +/* + * wgetnstr -- + * Get a string starting at (cury, curx). + * Note that n < 2 means that we return ERR (SUSv2 specification). + */ +int +wgetnstr(WINDOW *win, char *str, int n) +{ + if (n < 1) + return (ERR); + if (n == 1) { + str[0] = '\0'; + return (ERR); + } + return __wgetnstr(win, str, n); +} + +/* + * __wgetnstr -- + * The actual implementation. + * Note that we include a trailing '\0' for safety, so str will contain + * at most n - 1 other characters. + * XXX: character deletion from screen is based on how the characters + * are displayed by wgetch(). + */ +int +__wgetnstr(WINDOW *win, char *str, int n) +{ + char *ostr, ec, kc; + int c, oldx, remain; + + ostr = str; + ec = erasechar(); + kc = killchar(); + oldx = win->curx; + _DIAGASSERT(n == -1 || n > 1); + remain = n - 1; + + while ((c = wgetch(win)) != ERR && c != '\n' && c != '\r') { +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "__wgetnstr: win %p, char 0x%x, remain %d\n", + win, c, remain); +#endif + *str = c; + touchline(win, win->cury, 1); + if (c == ec || c == KEY_BACKSPACE || c == KEY_LEFT) { + *str = '\0'; + if (str != ostr) { + if ((char) c == ec) { + mvwaddch(win, win->cury, win->curx, + ' '); + wmove(win, win->cury, win->curx - 1); + } + if (c == KEY_BACKSPACE || c == KEY_LEFT) { + /* getch() displays the key sequence */ + mvwaddch(win, win->cury, win->curx - 1, + ' '); + mvwaddch(win, win->cury, win->curx - 2, + ' '); + wmove(win, win->cury, win->curx - 1); + } + str--; + if (n != -1) { + /* We're counting chars */ + remain++; + } + } else { /* str == ostr */ + if (c == KEY_BACKSPACE || c == KEY_LEFT) + /* getch() displays the other keys */ + mvwaddch(win, win->cury, win->curx - 1, + ' '); + wmove(win, win->cury, oldx); + } + } else if (c == kc) { + *str = '\0'; + if (str != ostr) { + /* getch() displays the kill character */ + mvwaddch(win, win->cury, win->curx - 1, ' '); + /* Clear the characters from screen and str */ + while (str != ostr) { + mvwaddch(win, win->cury, win->curx - 1, + ' '); + wmove(win, win->cury, win->curx - 1); + str--; + if (n != -1) + /* We're counting chars */ + remain++; + } + mvwaddch(win, win->cury, win->curx - 1, ' '); + wmove(win, win->cury, win->curx - 1); + } else + /* getch() displays the kill character */ + mvwaddch(win, win->cury, oldx, ' '); + wmove(win, win->cury, oldx); + } else if (c >= KEY_MIN && c <= KEY_MAX) { + /* getch() displays these characters */ + mvwaddch(win, win->cury, win->curx - 1, ' '); + wmove(win, win->cury, win->curx - 1); + } else { + if (remain) { + str++; + remain--; + } else { + mvwaddch(win, win->cury, win->curx - 1, ' '); + wmove(win, win->cury, win->curx - 1); + } + } + } + + if (c == ERR) { + *str = '\0'; + return (ERR); + } + *str = '\0'; + return (OK); +} diff --git a/lib/libcurses/getyx.c b/lib/libcurses/getyx.c new file mode 100644 index 000000000..671f08e3e --- /dev/null +++ b/lib/libcurses/getyx.c @@ -0,0 +1,134 @@ +/* $NetBSD: getyx.c,v 1.5 2008/04/28 20:23:01 martin Exp $ */ + +/* + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Julian Coleman. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: getyx.c,v 1.5 2008/04/28 20:23:01 martin Exp $"); +#endif /* not lint */ + +#include + +#include "curses.h" +#include "curses_private.h" + +/* + * getpary -- + * Get the y postion of the window relative to the parent window + * return -1 if not a subwindow. + */ +int +getpary(WINDOW *win) +{ + if (win == NULL) + return -1; + + if (win->orig == NULL) + return -1; + + return (win->begy - win->orig->begy); +} + +/* + * getparx -- + * Get the x postion of the window relative to the parent window + * return -1 if not a subwindow. + */ +int +getparx(WINDOW *win) +{ + if (win == NULL) + return -1; + + if (win->orig == NULL) + return -1; + + return (win->begx - win->orig->begx); +} + +/* + * getcury -- + * Get current y position on window. + */ +int +getcury(WINDOW *win) +{ + return(win->cury); +} + +/* + * getcurx -- + * Get current x position on window. + */ +int +getcurx(WINDOW *win) +{ + return(win->curx); +} + +/* + * getbegy -- + * Get begin y position on window. + */ +int +getbegy(WINDOW *win) +{ + return(win->begy); +} + +/* + * getbegx -- + * Get begin x position on window. + */ +int +getbegx(WINDOW *win) +{ + return(win->begx); +} + +/* + * getmaxy -- + * Get maximum y position on window. + */ +int +getmaxy(WINDOW *win) +{ + return(win->maxy); +} + +/* + * getmaxx -- + * Get maximum x position on window. + */ +int +getmaxx(WINDOW *win) +{ + return(win->maxx); +} diff --git a/lib/libcurses/id_subwins.c b/lib/libcurses/id_subwins.c new file mode 100644 index 000000000..c91a50080 --- /dev/null +++ b/lib/libcurses/id_subwins.c @@ -0,0 +1,60 @@ +/* $NetBSD: id_subwins.c,v 1.14 2009/07/22 16:57:14 roy Exp $ */ + +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)id_subwins.c 8.2 (Berkeley) 5/4/94"; +#else +__RCSID("$NetBSD: id_subwins.c,v 1.14 2009/07/22 16:57:14 roy Exp $"); +#endif +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +/* + * __id_subwins -- + * Re-sync the pointers to lines for all the subwindows. + */ +void +__id_subwins(WINDOW *orig) +{ + WINDOW *win; + int oy, y; + + for (win = orig->nextp; win != orig; win = win->nextp) { + oy = win->begy - orig->begy; + for (y = 0; y < win->maxy; y++) + win->alines[y]->line = + &orig->alines[oy + y]->line[win->ch_off]; + } +} diff --git a/lib/libcurses/idcok.c b/lib/libcurses/idcok.c new file mode 100644 index 000000000..0af687b2e --- /dev/null +++ b/lib/libcurses/idcok.c @@ -0,0 +1,58 @@ +/* $NetBSD: idcok.c,v 1.1 2002/07/19 13:22:41 blymn Exp $ */ + +/*- + * Copyright (c) 1998-1999 Brett Lymn (blymn@baea.com.au, brett_lymn@yahoo.com) + * All rights reserved. + * + * This software has been donated to the NetBSD Foundation by the + * Author. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)idcok.c blymn 2002/06/06"; +#else +__RCSID("$NetBSD: idcok.c,v 1.1 2002/07/19 13:22:41 blymn Exp $"); +#endif +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +/* + * idcok -- + * Turn on and off using insert/delete char sequences for the + * given window. Note, currently, the ic/dc capabilities are not + * used, this function is only provided for compatibility. + */ +int +idcok(WINDOW *win, bool bf) +{ + if (bf) + win->flags |= __IDCHAR; + else + win->flags &= ~__IDCHAR; + return (OK); +} diff --git a/lib/libcurses/idlok.c b/lib/libcurses/idlok.c new file mode 100644 index 000000000..27a1ae6ce --- /dev/null +++ b/lib/libcurses/idlok.c @@ -0,0 +1,57 @@ +/* $NetBSD: idlok.c,v 1.11 2003/08/07 16:44:22 agc Exp $ */ + +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)idlok.c 8.2 (Berkeley) 5/4/94"; +#else +__RCSID("$NetBSD: idlok.c,v 1.11 2003/08/07 16:44:22 agc Exp $"); +#endif +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +/* + * idlok -- + * Turn on and off using insert/deleteln sequences for the + * given window. + */ +int +idlok(WINDOW *win, bool bf) +{ + if (bf) + win->flags |= __IDLINE; + else + win->flags &= ~__IDLINE; + return (OK); +} diff --git a/lib/libcurses/in_wch.c b/lib/libcurses/in_wch.c new file mode 100644 index 000000000..46b01383e --- /dev/null +++ b/lib/libcurses/in_wch.c @@ -0,0 +1,119 @@ +/* $NetBSD: in_wch.c,v 1.3 2009/07/22 16:57:14 roy Exp $ */ + +/* + * Copyright (c) 2005 The NetBSD Foundation Inc. + * All rights reserved. + * + * This code is derived from code donated to the NetBSD Foundation + * by Ruibiao Qiu . + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND + * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: in_wch.c,v 1.3 2009/07/22 16:57:14 roy Exp $"); +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +/* + * in_wch -- + * Return wide character at cursor position from stdscr. + */ +int +in_wch(cchar_t *wcval) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return win_wch(stdscr, wcval); +#endif /* HAVE_WCHAR */ +} + +/* + * mvin_wch -- + * Return wide character at position (y, x) from stdscr. + */ +int +mvin_wch(int y, int x, cchar_t *wcval) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return mvwin_wch(stdscr, y, x, wcval); +#endif /* HAVE_WCHAR */ +} + +/* + * mvwin_wch -- + * Return wide character at position (y, x) from the given window. + */ +int +mvwin_wch(WINDOW *win, int y, int x, cchar_t *wcval) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + if (wmove(win, y, x) == ERR) + return ERR; + + return win_wch(win, wcval); +#endif /* HAVE_WCHAR */ +} + +/* + * win_wch -- + * Return wide character at cursor position. + */ +int +win_wch(WINDOW *win, cchar_t *wcval) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + nschar_t *np; + __LDATA *lp = &win->alines[ win->cury ]->line[ win->curx ]; + int cw = WCOL( *lp ); + + if ( cw < 0 ) + lp += cw; + wcval->vals[ 0 ] = lp->ch; + wcval->attributes = lp->attr; + wcval->elements = 1; + np = lp->nsp; + if (np) { + do { + wcval->vals[ wcval->elements++ ] = np->ch; + np = np-> next; + } while ( np ); + } + + return OK; +#endif /* HAVE_WCHAR */ +} diff --git a/lib/libcurses/in_wchstr.c b/lib/libcurses/in_wchstr.c new file mode 100644 index 000000000..b6d3d75da --- /dev/null +++ b/lib/libcurses/in_wchstr.c @@ -0,0 +1,197 @@ +/* $NetBSD: in_wchstr.c,v 1.3 2009/07/22 16:57:14 roy Exp $ */ + +/* + * Copyright (c) 2005 The NetBSD Foundation Inc. + * All rights reserved. + * + * This code is derived from code donated to the NetBSD Foundation + * by Ruibiao Qiu . + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND + * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: in_wchstr.c,v 1.3 2009/07/22 16:57:14 roy Exp $"); +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +/* + * in_wchstr, in_wchnstr -- + * Return an array of wide characters at cursor position from stdscr. + */ +__warn_references(in_wchstr, + "warning: this program uses in_wchstr(), which is unsafe.") +int +in_wchstr(cchar_t *wchstr) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return win_wchstr(stdscr, wchstr); +#endif /* HAVE_WCHAR */ +} + +int +in_wchnstr(cchar_t *wchstr, int n) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return win_wchnstr(stdscr, wchstr, n); +#endif /* HAVE_WCHAR */ +} + +/* + * mvin_wchstr, mv_winchnstr -- + * Return an array of wide characters at position (y, x) from stdscr. + */ +__warn_references(mvin_wchstr, + "warning: this program uses mvin_wchstr(), which is unsafe.") +int +mvin_wchstr(int y, int x, cchar_t *wchstr) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return mvwin_wchstr(stdscr, y, x, wchstr); +#endif /* HAVE_WCHAR */ +} + +int +mvin_wchnstr(int y, int x, cchar_t *wchstr, int n) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return mvwin_wchnstr(stdscr, y, x, wchstr, n); +#endif /* HAVE_WCHAR */ +} + +/* + * mvwin_wchstr, mvwin_wchnstr -- + * Return an array wide characters at position (y, x) from the given window. + */ +__warn_references(mvwin_wchstr, + "warning: this program uses mvwin_wchstr(), which is unsafe.") +int +mvwin_wchstr(WINDOW *win, int y, int x, cchar_t *wchstr) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + if (wmove(win, y, x) == ERR) + return ERR; + + return win_wchstr(win, wchstr); +#endif /* HAVE_WCHAR */ +} + +int +mvwin_wchnstr(WINDOW *win, int y, int x, cchar_t *wchstr, int n) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + if (wmove(win, y, x) == ERR) + return ERR; + + return win_wchnstr(win, wchstr, n); +#endif /* HAVE_WCHAR */ +} + +/* + * win_wchstr, win_wchnstr -- + * Return an array of characters at cursor position. + */ +__warn_references(win_wchstr, + "warning: this program uses win_wchstr(), which is unsafe.") +int +win_wchstr(WINDOW *win, cchar_t *wchstr) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + + return win_wchnstr(win, wchstr, -1); +#endif /* HAVE_WCHAR */ +} + +/* + * - SUSv2/xcurses doesn't document whether the trailing 0 is included + * in the length count or not. For safety's sake it _is_ included. + */ +int +win_wchnstr(WINDOW *win, cchar_t *wchstr, int n) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + __LDATA *start; + int x = 0, cw = 0, cnt = 0; + cchar_t *wcp; + nschar_t *np; + + if (wchstr == NULL) + return ERR; + + start = &win->alines[win->cury]->line[win->curx]; + x = win->curx; + cw = WCOL(*start); + if (cw < 0) { + start += cw; + x += cw; + } + wcp = wchstr; + /* (n - 1) to leave room for the trailing 0 element */ + while ((x < win->maxx) && ((n < 0) || ((n > 1) && (cnt < n - 1)))) { + cw = WCOL( *start ); + wcp->vals[ 0 ] = start->ch; + wcp->attributes = start->attr; + wcp->elements = 1; + np = start->nsp; + if (np) { + do { + wcp->vals[ wcp->elements++ ] = np->ch; + np = np->next; + } while ( np ); + } + wcp++; + cnt++; + x += cw; + if ( x < win->maxx ) + start += cw; + } + wcp->vals[ 0 ] = L'\0'; + wcp->elements = 1; + wcp->attributes = win->wattr; + + return OK; +#endif /* HAVE_WCHAR */ +} diff --git a/lib/libcurses/inch.c b/lib/libcurses/inch.c new file mode 100644 index 000000000..908eef5d9 --- /dev/null +++ b/lib/libcurses/inch.c @@ -0,0 +1,94 @@ +/* $NetBSD: inch.c,v 1.10 2009/10/06 20:03:27 jdc Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Julian Coleman. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: inch.c,v 1.10 2009/10/06 20:03:27 jdc Exp $"); +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +#ifndef _CURSES_USE_MACROS + +/* + * inch -- + * Return character at cursor position from stdscr. + */ +chtype +inch(void) +{ + return winch(stdscr); +} + +/* + * mvinch -- + * Return character at position (y, x) from stdscr. + */ +chtype +mvinch(int y, int x) +{ + return mvwinch(stdscr, y, x); +} + +/* + * mvwinch -- + * Return character at position (y, x) from the given window. + */ +chtype +mvwinch(WINDOW *win, int y, int x) +{ + if (wmove(win, y, x) == ERR) + return ERR; + + return winch(win); +} + +#endif + +/* + * winch -- + * Return character at cursor position. + */ +chtype +winch(WINDOW *win) +{ + chtype ch; + attr_t attr; + + ch = (chtype) ((win)->alines[(win)->cury]->line[(win)->curx].ch & + __CHARTEXT); + attr = (attr_t) ((win)->alines[(win)->cury]->line[(win)->curx].attr & + __ATTRIBUTES); + if (__using_color && ((attr & __COLOR) == __default_color)) + attr &= ~__default_color; + return (ch | attr); +} diff --git a/lib/libcurses/inchstr.c b/lib/libcurses/inchstr.c new file mode 100644 index 000000000..00318e509 --- /dev/null +++ b/lib/libcurses/inchstr.c @@ -0,0 +1,154 @@ +/* $NetBSD: inchstr.c,v 1.3 2009/07/22 16:57:14 roy Exp $ */ + +/* + * Copyright 2001 Wasabi Systems, Inc. + * All rights reserved. + * + * Written by Simon Burge for Wasabi Systems, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed for the NetBSD Project by + * Wasabi Systems, Inc. + * 4. The name of Wasabi Systems, Inc. may not be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC. BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: inchstr.c,v 1.3 2009/07/22 16:57:14 roy Exp $"); +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +#ifndef _CURSES_USE_MACROS + +/* + * inchstr, inchnstr -- + * Return an array of characters at cursor position from stdscr. + */ +__warn_references(inchstr, + "warning: this program uses inchstr(), which is unsafe.") +int +inchstr(chtype *chstr) +{ + return winchstr(stdscr, chstr); +} + +int +inchnstr(chtype *chstr, int n) +{ + return winchnstr(stdscr, chstr, n); +} + +/* + * mvinchstr, mvinchnstr -- + * Return an array of characters at position (y, x) from stdscr. + */ +__warn_references(mvinchstr, + "warning: this program uses mvinchstr(), which is unsafe.") +int +mvinchstr(int y, int x, chtype *chstr) +{ + return mvwinchstr(stdscr, y, x, chstr); +} + +int +mvinchnstr(int y, int x, chtype *chstr, int n) +{ + return mvwinchnstr(stdscr, y, x, chstr, n); +} + +/* + * mvwinchstr, mvwinchnstr -- + * Return an array characters at position (y, x) from the given window. + */ +__warn_references(mvwinchstr, + "warning: this program uses mvwinchstr(), which is unsafe.") +int +mvwinchstr(WINDOW *win, int y, int x, chtype *chstr) +{ + if (wmove(win, y, x) == ERR) + return ERR; + + return winchstr(win, chstr); +} + +int +mvwinchnstr(WINDOW *win, int y, int x, chtype *chstr, int n) +{ + if (wmove(win, y, x) == ERR) + return ERR; + + return winchnstr(win, chstr, n); +} + +#endif /* _CURSES_USE_MACROS */ + +/* + * winchstr, winchnstr -- + * Return an array of characters at cursor position. + */ +__warn_references(winchstr, + "warning: this program uses winchstr(), which is unsafe.") +int +winchstr(WINDOW *win, chtype *chstr) +{ + + return winchnstr(win, chstr, -1); +} + +/* + * XXX: This should go in a manpage! + * - SUSv2/xcurses doesn't document whether the trailing 0 is included + * in the length count or not. For safety's sake it _is_ included. + */ +int +winchnstr(WINDOW *win, chtype *chstr, int n) +{ + __LDATA *end, *start; + int epos; + + if (chstr == NULL) + return ERR; + + start = &win->alines[win->cury]->line[win->curx]; + /* (n - 1) to leave room for the trailing 0 element */ + if (n < 0 || (n - 1) > win->maxx - win->curx - 1) + epos = win->maxx - 1; + else + /* extra -1 for trailing NUL */ + epos = win->curx + n -1 - 1; + end = &win->alines[win->cury]->line[epos]; + + while (start <= end) { + *chstr = start->ch; + chstr++; + start++; + } + *chstr = 0; + + return OK; +} diff --git a/lib/libcurses/initscr.c b/lib/libcurses/initscr.c index 7ed2f9d11..b82c68ce4 100644 --- a/lib/libcurses/initscr.c +++ b/lib/libcurses/initscr.c @@ -1,19 +1,87 @@ -/* initscr.c - initialize the curses library */ +/* $NetBSD: initscr.c,v 1.29 2007/01/22 21:14:53 jdc Exp $ */ + +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)initscr.c 8.2 (Berkeley) 5/4/94"; +#else +__RCSID("$NetBSD: initscr.c,v 1.29 2007/01/22 21:14:53 jdc Exp $"); +#endif +#endif /* not lint */ #include -#include -#include "curspriv.h" -WINDOW *initscr() +#include "curses.h" +#include "curses_private.h" + + +/* + * initscr -- + * Initialize the current and standard screen. + */ +WINDOW * +initscr(void) { - char *term; - - if ((term = getenv("TERM")) == NULL) return NULL; - setterm(term); - gettmode(); - if ((_cursvar.tmpwin = newwin(LINES, COLS, 0, 0)) == NULL) return NULL; - if ((curscr = newwin(LINES, COLS, 0, 0)) == NULL) return NULL; - if ((stdscr = newwin(LINES, COLS, 0, 0)) == NULL) return NULL; - clearok(curscr, TRUE); - return(stdscr); + const char *sp; + +#ifdef DEBUG + __CTRACE(__CTRACE_INIT, "initscr\n"); +#endif + + /* + * If My_term is set, or can't find a terminal in the environment, + * use Def_term. + */ + if (My_term || (sp = getenv("TERM")) == NULL) + sp = Def_term; + + /* LINTED const castaway; newterm does not modify sp! */ + if ((_cursesi_screen = newterm((char *) sp, stdout, stdin)) == NULL) + return NULL; + + __echoit = _cursesi_screen->echoit; + __pfast = _cursesi_screen->pfast; + __rawmode = _cursesi_screen->rawmode; + __noqch = _cursesi_screen->noqch; + COLS = _cursesi_screen->COLS; + LINES = _cursesi_screen->LINES; + COLORS = _cursesi_screen->COLORS; + COLOR_PAIRS = _cursesi_screen->COLOR_PAIRS; + __GT = _cursesi_screen->GT; + __NONL = _cursesi_screen->NONL; + __UPPERCASE = _cursesi_screen->UPPERCASE; + + set_term(_cursesi_screen); + wrefresh(curscr); + + return (stdscr); } diff --git a/lib/libcurses/ins_wch.c b/lib/libcurses/ins_wch.c new file mode 100644 index 000000000..1481280d9 --- /dev/null +++ b/lib/libcurses/ins_wch.c @@ -0,0 +1,253 @@ +/* $NetBSD: ins_wch.c,v 1.5 2010/02/23 19:48:26 drochner Exp $ */ + +/* + * Copyright (c) 2005 The NetBSD Foundation Inc. + * All rights reserved. + * + * This code is derived from code donated to the NetBSD Foundation + * by Ruibiao Qiu . + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND + * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: ins_wch.c,v 1.5 2010/02/23 19:48:26 drochner Exp $"); +#endif /* not lint */ + +#include +#include + +#include "curses.h" +#include "curses_private.h" + +/* + * ins_wch -- + * Do an insert-char on the line, leaving (cury, curx) unchanged. + */ +int +ins_wch(const cchar_t *wch) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return wins_wch(stdscr, wch); +#endif /* HAVE_WCHAR */ +} + +/* + * mvins_wch -- + * Do an insert-char on the line at (y, x). + */ +int +mvins_wch(int y, int x, const cchar_t *wch) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return mvwins_wch(stdscr, y, x, wch); +#endif /* HAVE_WCHAR */ +} + +/* + * mvwins_wch -- + * Do an insert-char on the line at (y, x) in the given window. + */ +int +mvwins_wch(WINDOW *win, int y, int x, const cchar_t *wch) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + if (wmove(win, y, x) == ERR) + return ERR; + + return wins_wch(stdscr, wch); +#endif /* HAVE_WCHAR */ +} + +/* + * wins_wch -- + * Do an insert-char on the line, leaving (cury, curx) unchanged. + */ +int +wins_wch(WINDOW *win, const cchar_t *wch) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + __LDATA *start, *temp1, *temp2; + __LINE *lnp; + int cw, pcw, x, y, sx, ex, newx, i; + nschar_t *np, *tnp; + wchar_t ws[] = L" "; + + /* check for non-spacing characters */ + if ( !wch ) + return OK; + cw = wcwidth(wch->vals[0]); + if (cw < 0) + cw = 1; + if (!cw) + return wadd_wch( win, wch ); + +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, "--before--\n"); + for ( x = 0; x < win->maxx; x++ ) + __CTRACE(__CTRACE_INPUT, "wins_wch: (0,%d)=(%x,%x,%p)\n", x, + win->alines[0]->line[x].ch, + win->alines[0]->line[x].attr, + win->alines[0]->line[x].nsp); +#endif /* DEBUG */ + x = win->curx; + y = win->cury; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, "wins_wch: (%d,%d)\n", y, x); +#endif /* DEBUG */ + switch ( wch->vals[ 0 ]) { + case L'\b': + if ( --x < 0 ) + x = 0; + win->curx = x; + return OK; + case L'\r': + win->curx = 0; + return OK; + case L'\n': + wclrtoeol( win ); + if (y == win->scr_b) { + if (!(win->flags & __SCROLLOK)) + return ERR; + scroll(win); + } + return OK; + case L'\t': + if (wins_nwstr(win, ws, min(win->maxx - x, 8-(x % 8))) + == ERR) + return ERR; + return OK; + } + + /* locate current cell */ + x = win->curx; + y = win->cury; + lnp = win->alines[ y ]; + start = &win->alines[ y ]->line[ x ]; + sx = x; + pcw = WCOL( *start ); + if (pcw < 0) { + start += pcw; + sx += pcw; + } + if ( cw > win->maxx - sx ) + return ERR; + lnp->flags |= __ISDIRTY; + newx = sx + win->ch_off; + if ( newx < *lnp->firstchp ) + *lnp->firstchp = newx; + + /* shift all complete characters */ +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, "wins_wch: shift all characters\n"); +#endif /* DEBUG */ + temp1 = &win->alines[ y ]->line[ win->maxx - 1 ]; + temp2 = temp1 - cw; + pcw = WCOL(*(temp2 + 1)); + if (pcw < 0) { +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, "wins_wch: clear EOL\n"); +#endif /* DEBUG */ + temp2 += pcw; + while ( temp1 > temp2 + cw ) { + np = temp1->nsp; + if (np) { + while ( np ) { + tnp = np->next; + free( np ); + np = tnp; + } + temp1->nsp = NULL; + } + temp1->ch = ( wchar_t )btowc(( int ) win->bch ); + if (_cursesi_copy_nsp(win->bnsp, temp1) == ERR) + return ERR; + temp1->attr = win->battr; + SET_WCOL( *temp1, 1 ); + temp1--; + } + } + while ( temp2 >= start ) { + ( void )memcpy( temp1, temp2, sizeof( __LDATA )); + temp1--, temp2--; + } + + /* update character under cursor */ + start->nsp = NULL; + start->ch = wch->vals[ 0 ]; + start->attr = wch->attributes & WA_ATTRIBUTES; + SET_WCOL( *start, cw ); + if ( wch->elements > 1 ) { + for ( i = 1; i < wch->elements; i++ ) { + np = (nschar_t *)malloc(sizeof(nschar_t)); + if (!np) + return ERR; + np->ch = wch->vals[ i ]; + np->next = start->nsp; + start->nsp = np; + } + } +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, "wins_wch: insert (%x,%x,%p)\n", + start->ch, start->attr, start->nsp); +#endif /* DEBUG */ + temp1 = start + 1; + ex = x + 1; + while ( ex - x < cw ) { + temp1->ch = wch->vals[ 0 ]; + SET_WCOL( *temp1, x - ex ); + temp1->nsp = NULL; + ex++, temp1++; + } +#ifdef DEBUG + { + __CTRACE(__CTRACE_INPUT, "--after---\n"); + for ( x = 0; x < win->maxx; x++ ) + __CTRACE(__CTRACE_INPUT, + "wins_wch: (0,%d)=(%x,%x,%p)\n", x, + win->alines[0]->line[x].ch, + win->alines[0]->line[x].attr, + win->alines[0]->line[x].nsp); + } +#endif /* DEBUG */ + newx = win->maxx - 1 + win->ch_off; + if ( newx > *lnp->lastchp ) + *lnp->lastchp = newx; + __touchline(win, y, sx, (int) win->maxx - 1); + + return OK; +#endif /* HAVE_WCHAR */ +} diff --git a/lib/libcurses/ins_wstr.c b/lib/libcurses/ins_wstr.c new file mode 100644 index 000000000..05b3ac064 --- /dev/null +++ b/lib/libcurses/ins_wstr.c @@ -0,0 +1,333 @@ +/* $NetBSD: ins_wstr.c,v 1.6 2010/12/16 17:42:28 wiz Exp $ */ + +/* + * Copyright (c) 2005 The NetBSD Foundation Inc. + * All rights reserved. + * + * This code is derived from code donated to the NetBSD Foundation + * by Ruibiao Qiu . + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND + * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: ins_wstr.c,v 1.6 2010/12/16 17:42:28 wiz Exp $"); +#endif /* not lint */ + +#include +#include + +#include "curses.h" +#include "curses_private.h" + +/* + * ins_wstr -- + * insert a multi-character wide-character string into the current window + */ +int +ins_wstr(const wchar_t *wstr) +{ + return wins_wstr(stdscr, wstr); +} + +/* + * ins_nwstr -- + * insert a multi-character wide-character string into the current window + * with at most n characters + */ +int +ins_nwstr(const wchar_t *wstr, int n) +{ + return wins_nwstr(stdscr, wstr, n); +} + +/* + * mvins_wstr -- + * Do an insert-string on the line at (y, x). + */ +int +mvins_wstr(int y, int x, const wchar_t *wstr) +{ + return mvwins_wstr(stdscr, y, x, wstr); +} + +/* + * mvins_nwstr -- + * Do an insert-n-string on the line at (y, x). + */ +int +mvins_nwstr(int y, int x, const wchar_t *wstr, int n) +{ + return mvwins_nwstr(stdscr, y, x, wstr, n); +} + +/* + * mvwins_wstr -- + * Do an insert-string on the line at (y, x) in the given window. + */ +int +mvwins_wstr(WINDOW *win, int y, int x, const wchar_t *wstr) +{ + if (wmove(win, y, x) == ERR) + return ERR; + + return wins_wstr(stdscr, wstr); +} + +/* + * mvwins_nwstr -- + * Do an insert-n-string on the line at (y, x) in the given window. + */ +int +mvwins_nwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n) +{ + if (wmove(win, y, x) == ERR) + return ERR; + + return wins_nwstr(stdscr, wstr, n); +} + + +/* + * wins_wstr -- + * Do an insert-string on the line, leaving (cury, curx) unchanged. + */ +int +wins_wstr(WINDOW *win, const wchar_t *wstr) +{ + return wins_nwstr(win, wstr, -1); +} + +/* + * wins_nwstr -- + * Do an insert-n-string on the line, leaving (cury, curx) unchanged. + */ +int +wins_nwstr(WINDOW *win, const wchar_t *wstr, int n) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + __LDATA *start, *temp1, *temp2; + __LINE *lnp; + const wchar_t *scp; + int width, len, sx, x, y, cw, pcw, newx; + nschar_t *np; + wchar_t ws[] = L" "; + + /* check for leading non-spacing character */ + if (!wstr) + return OK; + cw = wcwidth(*wstr); + if (cw < 0) + cw = 1; + if (!cw) + return ERR; + + scp = wstr + 1; + width = cw; + len = 1; + n--; + while (*scp) { + int w; + if (!n) + break; + w = wcwidth(*scp); + if (w < 0) + w = 1; + n--, len++, width += w; + scp++; + } +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, "wins_nwstr: width=%d,len=%d\n", width, len); +#endif /* DEBUG */ + + if (cw > win->maxx - win->curx + 1) + return ERR; + start = &win->alines[win->cury]->line[win->curx]; + sx = win->curx; + lnp = win->alines[win->cury]; + pcw = WCOL(*start); + if (pcw < 0) { + sx += pcw; + start += pcw; + } +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, "wins_nwstr: start@(%d)\n", sx); +#endif /* DEBUG */ + pcw = WCOL(*start); + lnp->flags |= __ISDIRTY; + newx = sx + win->ch_off; + if (newx < *lnp->firstchp) + *lnp->firstchp = newx; +#ifdef DEBUG + { + __CTRACE(__CTRACE_INPUT, "========before=======\n"); + for (x = 0; x < win->maxx; x++) + __CTRACE(__CTRACE_INPUT, + "wins_nwstr: (%d,%d)=(%x,%x,%p)\n", + (int) win->cury, x, + win->alines[win->cury]->line[x].ch, + win->alines[win->cury]->line[x].attr, + win->alines[win->cury]->line[x].nsp); + } +#endif /* DEBUG */ + + /* shift all complete characters */ + if (sx + width + pcw <= win->maxx) { +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, "wins_nwstr: shift all characters\n"); +#endif /* DEBUG */ + temp1 = &win->alines[win->cury]->line[win->maxx - 1]; + temp2 = temp1 - width; + pcw = WCOL(*(temp2 + 1)); + if (pcw < 0) { +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "wins_nwstr: clear from %d to EOL(%d)\n", + win->maxx + pcw, win->maxx - 1); +#endif /* DEBUG */ + temp2 += pcw; + while (temp1 > temp2 + width) { + temp1->ch = (wchar_t)btowc((int) win->bch); + if (_cursesi_copy_nsp(win->bnsp, temp1) == ERR) + return ERR; + temp1->attr = win->battr; + SET_WCOL(*temp1, 1); +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "wins_nwstr: empty cell(%p)\n", temp1); +#endif /* DEBUG */ + temp1--; + } + } + while (temp2 >= start) { + (void)memcpy(temp1, temp2, sizeof(__LDATA)); + temp1--, temp2--; + } +#ifdef DEBUG + { + __CTRACE(__CTRACE_INPUT, "=====after shift====\n"); + for (x = 0; x < win->maxx; x++) + __CTRACE(__CTRACE_INPUT, + "wins_nwstr: (%d,%d)=(%x,%x,%p)\n", + (int) win->cury, x, + win->alines[win->cury]->line[x].ch, + win->alines[win->cury]->line[x].attr, + win->alines[win->cury]->line[x].nsp); + } +#endif /* DEBUG */ + } + + /* update string columns */ + x = win->curx; + y = win->cury; + for (scp = wstr, temp1 = start; len; len--, scp++) { + switch (*scp) { + case L'\b': + if (--x < 0) + x = 0; + win->curx = x; + continue;; + case L'\r': + win->curx = 0; + continue; + case L'\n': + wclrtoeol(win); + if (y == win->scr_b) { + if (!(win->flags & __SCROLLOK)) + return ERR; + scroll(win); + } + continue; + case L'\t': + if (wins_nwstr(win, ws, + min(win->maxx - x, 8-(x % 8))) + == ERR) + return ERR; + continue; + } + cw = wcwidth(*scp); + if (cw < 0) + cw = 1; + if (cw) { + /* 1st column */ + temp1->ch = (wchar_t)*scp; + temp1->attr = win->wattr; + SET_WCOL(*temp1, cw); + temp1->nsp = NULL; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "wins_nwstr: add spacing char(%x)\n", temp1->ch); +#endif /* DEBUG */ + temp2 = temp1++; + if (cw > 1) { + x = -1; + while (temp1 < temp2 + cw) { + /* the rest columns */ + temp1->ch = (wchar_t)*scp; + temp1->attr = win->wattr; + temp1->nsp = NULL; + SET_WCOL(*temp1, x); + temp1++, x--; + } + temp1--; + } + } else { + /* non-spacing character */ + np = (nschar_t *)malloc(sizeof(nschar_t)); + if (!np) + return ERR; + np->ch = *scp; + np->next = temp1->nsp; + temp1->nsp = np; +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, + "wins_nstr: add non-spacing char(%x)\n", np->ch); +#endif /* DEBUG */ + } + } +#ifdef DEBUG + { + __CTRACE(__CTRACE_INPUT, "========after=======\n"); + for (x = 0; x < win->maxx; x++) + __CTRACE(__CTRACE_INPUT, + "wins_nwstr: (%d,%d)=(%x,%x,%p)\n", + (int) win->cury, x, + win->alines[win->cury]->line[x].ch, + win->alines[win->cury]->line[x].attr, + win->alines[win->cury]->line[x].nsp); + } +#endif /* DEBUG */ + newx = win->maxx - 1 + win->ch_off; + if (newx > *lnp->lastchp) + *lnp->lastchp = newx; + __touchline(win, (int) win->cury, sx, (int) win->maxx - 1); + return OK; +#endif /* HAVE_WCHAR */ +} diff --git a/lib/libcurses/insch.c b/lib/libcurses/insch.c new file mode 100644 index 000000000..317dfb070 --- /dev/null +++ b/lib/libcurses/insch.c @@ -0,0 +1,131 @@ +/* $NetBSD: insch.c,v 1.22 2009/07/22 16:57:15 roy Exp $ */ + +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)insch.c 8.2 (Berkeley) 5/4/94"; +#else +__RCSID("$NetBSD: insch.c,v 1.22 2009/07/22 16:57:15 roy Exp $"); +#endif +#endif /* not lint */ + +#include +#include + +#include "curses.h" +#include "curses_private.h" + +#ifndef _CURSES_USE_MACROS + +/* + * insch -- + * Do an insert-char on the line, leaving (cury, curx) unchanged. + */ +int +insch(chtype ch) +{ + return winsch(stdscr, ch); +} + +/* + * mvinsch -- + * Do an insert-char on the line at (y, x). + */ +int +mvinsch(int y, int x, chtype ch) +{ + return mvwinsch(stdscr, y, x, ch); +} + +/* + * mvwinsch -- + * Do an insert-char on the line at (y, x) in the given window. + */ +int +mvwinsch(WINDOW *win, int y, int x, chtype ch) +{ + if (wmove(win, y, x) == ERR) + return ERR; + + return winsch(stdscr, ch); +} + +#endif + +/* + * winsch -- + * Do an insert-char on the line, leaving (cury, curx) unchanged. + */ +int +winsch(WINDOW *win, chtype ch) +{ + + __LDATA *end, *temp1, *temp2; + attr_t attr; + + if (__using_color) + attr = win->battr & __COLOR; + else + attr = 0; + end = &win->alines[win->cury]->line[win->curx]; + temp1 = &win->alines[win->cury]->line[win->maxx - 1]; + temp2 = temp1 - 1; + while (temp1 > end) { + (void) memcpy(temp1, temp2, sizeof(__LDATA)); + temp1--, temp2--; + } + temp1->ch = (wchar_t) ch & __CHARTEXT; + if (temp1->ch == ' ') + temp1->ch = win->bch; + temp1->attr = (attr_t) ch & __ATTRIBUTES; + if (temp1->attr & __COLOR) + temp1->attr |= (win->battr & ~__COLOR); + else + temp1->attr |= win->battr; +#ifdef HAVE_WCHAR + if (_cursesi_copy_nsp(win->bnsp, temp1) == ERR) + return ERR; + SET_WCOL(*temp1, 1); +#endif /* HAVE_WCHAR */ + __touchline(win, (int) win->cury, (int) win->curx, (int) win->maxx - 1); + if (win->cury == LINES - 1 && + (win->alines[LINES - 1]->line[COLS - 1].ch != ' ' || + win->alines[LINES - 1]->line[COLS - 1].attr != attr)) { + if (win->flags & __SCROLLOK) { + wrefresh(win); + scroll(win); + win->cury--; + } else + return (ERR); + } + return (OK); +} diff --git a/lib/libcurses/insdelln.c b/lib/libcurses/insdelln.c new file mode 100644 index 000000000..2a150b5ec --- /dev/null +++ b/lib/libcurses/insdelln.c @@ -0,0 +1,181 @@ +/* $NetBSD: insdelln.c,v 1.16 2009/07/22 16:57:15 roy Exp $ */ + +/* + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Julian Coleman. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: insdelln.c,v 1.16 2009/07/22 16:57:15 roy Exp $"); +#endif /* not lint */ + +/* + * Based on deleteln.c and insertln.c - + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + */ + +#include +#include + +#include "curses.h" +#include "curses_private.h" + +#ifndef _CURSES_USE_MACROS + +/* + * insdelln -- + * Insert or delete lines on stdscr, leaving (cury, curx) unchanged. + */ +int +insdelln(int nlines) +{ + return winsdelln(stdscr, nlines); +} + +#endif + +/* + * winsdelln -- + * Insert or delete lines on the window, leaving (cury, curx) unchanged. + */ +int +winsdelln(WINDOW *win, int nlines) +{ + int y, i, last; + __LINE *temp; +#ifdef HAVE_WCHAR + __LDATA *lp; +#endif /* HAVE_WCHAR */ + attr_t attr; + +#ifdef DEBUG + __CTRACE(__CTRACE_LINE, + "winsdelln: (%p) cury=%d lines=%d\n", win, win->cury, nlines); +#endif + + if (!nlines) + return(OK); + + if (__using_color && win != curscr) + attr = win->battr & __COLOR; + else + attr = 0; + + if (nlines > 0) { + /* Insert lines */ + if (win->cury < win->scr_t || win->cury > win->scr_b) { + /* Outside scrolling region */ + if (nlines > win->maxy - win->cury) + nlines = win->maxy - win->cury; + last = win->maxy - 1; + } else { + /* Inside scrolling region */ + if (nlines > win->scr_b + 1 - win->cury) + nlines = win->scr_b + 1 - win->cury; + last = win->scr_b; + } + for (y = last - nlines; y >= win->cury; --y) { + win->alines[y]->flags &= ~__ISPASTEOL; + win->alines[y + nlines]->flags &= ~__ISPASTEOL; + if (win->orig == NULL) { + temp = win->alines[y + nlines]; + win->alines[y + nlines] = win->alines[y]; + win->alines[y] = temp; + } else { + (void) memcpy(win->alines[y + nlines]->line, + win->alines[y]->line, + (size_t) win->maxx * __LDATASIZE); + } + } + for (y = win->cury - 1 + nlines; y >= win->cury; --y) + for (i = 0; i < win->maxx; i++) { + win->alines[y]->line[i].ch = win->bch; + win->alines[y]->line[i].attr = attr; +#ifndef HAVE_WCHAR + win->alines[y]->line[i].ch = win->bch; +#else + win->alines[y]->line[i].ch + = ( wchar_t )btowc(( int ) win->bch ); + lp = &win->alines[y]->line[i]; + if (_cursesi_copy_nsp(win->bnsp, lp) == ERR) + return ERR; + SET_WCOL( *lp, 1 ); +#endif /* HAVE_WCHAR */ + } + for (y = last; y >= win->cury; --y) + __touchline(win, y, 0, (int) win->maxx - 1); + } else { + /* Delete nlines */ + nlines = 0 - nlines; + if (win->cury < win->scr_t || win->cury > win->scr_b) { + /* Outside scrolling region */ + if (nlines > win->maxy - win->cury) + nlines = win->maxy - win->cury; + last = win->maxy; + } else { + /* Inside scrolling region */ + if (nlines > win->scr_b + 1 - win->cury) + nlines = win->scr_b + 1 - win->cury; + last = win->scr_b + 1; + } + for (y = win->cury; y < last - nlines; y++) { + win->alines[y]->flags &= ~__ISPASTEOL; + win->alines[y + nlines]->flags &= ~__ISPASTEOL; + if (win->orig == NULL) { + temp = win->alines[y]; + win->alines[y] = win->alines[y + nlines]; + win->alines[y + nlines] = temp; + } else { + (void) memcpy(win->alines[y]->line, + win->alines[y + nlines]->line, + (size_t) win->maxx * __LDATASIZE); + } + } + for (y = last - nlines; y < last; y++) + for (i = 0; i < win->maxx; i++) { + win->alines[y]->line[i].ch = win->bch; + win->alines[y]->line[i].attr = attr; +#ifndef HAVE_WCHAR + win->alines[y]->line[i].ch = win->bch; +#else + win->alines[y]->line[i].ch + = (wchar_t)btowc((int) win->bch); + lp = &win->alines[y]->line[i]; + SET_WCOL( *lp, 1 ); + if (_cursesi_copy_nsp(win->bnsp, lp) == ERR) + return ERR; +#endif /* HAVE_WCHAR */ + } + for (y = win->cury; y < last; y++) + __touchline(win, y, 0, (int) win->maxx - 1); + } + if (win->orig != NULL) + __id_subwins(win->orig); + return (OK); +} diff --git a/lib/libcurses/insertln.c b/lib/libcurses/insertln.c new file mode 100644 index 000000000..0515c077a --- /dev/null +++ b/lib/libcurses/insertln.c @@ -0,0 +1,66 @@ +/* $NetBSD: insertln.c,v 1.13 2003/08/07 16:44:22 agc Exp $ */ + +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)insertln.c 8.2 (Berkeley) 5/4/94"; +#else +__RCSID("$NetBSD: insertln.c,v 1.13 2003/08/07 16:44:22 agc Exp $"); +#endif +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +#ifndef _CURSES_USE_MACROS + +/* + * insertln -- + * Do an insert-line on stdscr, leaving (cury, curx) unchanged. + */ +int +insertln(void) +{ + return(winsdelln(stdscr, 1)); +} + +#endif + +/* + * winsertln -- + * Do an insert-line on the window, leaving (cury, curx) unchanged. + */ +int +winsertln(WINDOW *win) +{ + return(winsdelln(win, 1)); +} diff --git a/lib/libcurses/insstr.c b/lib/libcurses/insstr.c new file mode 100644 index 000000000..56c8169f5 --- /dev/null +++ b/lib/libcurses/insstr.c @@ -0,0 +1,209 @@ +/* $NetBSD: insstr.c,v 1.3 2009/07/22 16:57:15 roy Exp $ */ + +/* + * Copyright (c) 2005 The NetBSD Foundation Inc. + * All rights reserved. + * + * This code is derived from code donated to the NetBSD Foundation + * by Ruibiao Qiu . + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND + * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: insstr.c,v 1.3 2009/07/22 16:57:15 roy Exp $"); +#endif /* not lint */ + +#include +#include + +#include "curses.h" +#include "curses_private.h" + +#ifndef _CURSES_USE_MACROS + +/* + * insstr -- + * insert a multi-byte character string into the current window + */ +int +insstr(const char *str) +{ + return winsstr(stdscr, str); +} + +/* + * insnstr -- + * insert a multi-byte character string into the current window + * with at most n characters + */ +int +insnstr(const char *str, int n) +{ + return winsnstr(stdscr, str, n); +} + +/* + * mvinsstr -- + * Do an insert-string on the line at (y, x). + */ +int +mvinsstr(int y, int x, const char *str) +{ + return mvwinsstr(stdscr, y, x, str); +} + +/* + * mvinsnstr -- + * Do an insert-n-string on the line at (y, x). + */ +int +mvinsnstr(int y, int x, const char *str, int n) +{ + return mvwinsnstr(stdscr, y, x, str, n); +} + +/* + * mvwinsstr -- + * Do an insert-string on the line at (y, x) in the given window. + */ +int +mvwinsstr(WINDOW *win, int y, int x, const char *str) +{ + if (wmove(win, y, x) == ERR) + return ERR; + + return winsstr(stdscr, str); +} + +/* + * mvwinsnstr -- + * Do an insert-n-string on the line at (y, x) in the given window. + */ +int +mvwinsnstr(WINDOW *win, int y, int x, const char *str, int n) +{ + if (wmove(win, y, x) == ERR) + return ERR; + + return winsnstr(stdscr, str, n); +} + +#endif + +/* + * winsstr -- + * Do an insert-string on the line, leaving (cury, curx) unchanged. + * No wrapping. + */ +int +winsstr(WINDOW *win, const char *str) +{ + return winsnstr( win, str, -1 ); +} + +/* + * winsnstr -- + * Do an insert-n-string on the line, leaving (cury, curx) unchanged. + * Performs wrapping. + */ +int +winsnstr(WINDOW *win, const char *str, int n) +{ + __LDATA *end, *temp1, *temp2; + const char *scp; + int len, x; + __LINE *lnp; +#ifdef HAVE_WCHAR + nschar_t *np, *tnp; +#endif /* HAVE_WCHAR */ + + /* find string length */ + if ( n > 0 ) + for ( scp = str, len = 0; n-- && *scp++; ++len ); + else + for ( scp = str, len = 0; *scp++; ++len ); +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, "winsnstr: len = %d\n", len); +#endif /* DEBUG */ + + /* move string */ + end = &win->alines[win->cury]->line[win->curx]; + if ( len < win->maxx - win->curx ) { +#ifdef DEBUG + __CTRACE(__CTRACE_INPUT, "winsnstr: shift %d cells\n", len); +#endif /* DEBUG */ + temp1 = &win->alines[win->cury]->line[win->maxx - 1]; + temp2 = temp1 - len; + while (temp2 >= end) { +#ifdef HAVE_WCHAR + np = temp1->nsp; + if (np){ + while ( np ) { + tnp = np->next; + free( np ); + np = tnp; + } + temp1->nsp = NULL; + } +#endif /* HAVE_WCHAR */ + (void) memcpy(temp1, temp2, sizeof(__LDATA)); + temp1--, temp2--; + } + } + + for ( scp = str, temp1 = end, x = win->curx; + *scp && x < len + win->curx && x < win->maxx; + scp++, temp1++, x++ ) { + temp1->ch = (wchar_t)*scp & __CHARTEXT; + temp1->attr = win->wattr; +#ifdef HAVE_WCHAR + SET_WCOL( *temp1, 1 ); +#endif /* HAVE_WCHAR */ + } +#ifdef DEBUG + { + int i; + + for ( i = win->curx; i < win->curx + len; i++ ) { + __CTRACE(__CTRACE_INPUT, + "winsnstr: (%d,%d)=('%c',%x)\n", win->cury, i, + win->alines[win->cury]->line[i].ch, + win->alines[win->cury]->line[i].attr); + } + } +#endif /* DEBUG */ + lnp = win->alines[ win->cury ]; + lnp->flags |= __ISDIRTY; + if ( win->ch_off < *lnp->firstchp ) + *lnp->firstchp = win->ch_off; + if ( win->ch_off + win->maxx - 1 > *lnp->lastchp ) + *lnp->lastchp = win->ch_off + win->maxx - 1; + __touchline(win, (int)win->cury, (int)win->curx, (int)win->maxx - 1); + return OK; +} diff --git a/lib/libcurses/instr.c b/lib/libcurses/instr.c new file mode 100644 index 000000000..c470f5a42 --- /dev/null +++ b/lib/libcurses/instr.c @@ -0,0 +1,168 @@ +/* $NetBSD: instr.c,v 1.3 2009/07/22 16:57:15 roy Exp $ */ + +/* + * Copyright 2001 Wasabi Systems, Inc. + * All rights reserved. + * + * Written by Simon Burge for Wasabi Systems, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed for the NetBSD Project by + * Wasabi Systems, Inc. + * 4. The name of Wasabi Systems, Inc. may not be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC. BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: instr.c,v 1.3 2009/07/22 16:57:15 roy Exp $"); +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +#ifndef _CURSES_USE_MACROS + +/* + * instr, innstr -- + * Return a string of characters at cursor position from stdscr. + */ +__warn_references(instr, + "warning: this program uses instr(), which is unsafe.") +int +instr(char *str) +{ + return winstr(stdscr, str); +} + +int +innstr(char *str, int n) +{ + return winnstr(stdscr, str, n); +} + +/* + * mvinstr, mvinnstr -- + * Return a string of characters at position (y, x) from stdscr. + * XXX: should be multi-byte characters for SUSv2. + */ +__warn_references(mvinstr, + "warning: this program uses mvinstr(), which is unsafe.") +int +mvinstr(int y, int x, char *str) +{ + return mvwinstr(stdscr, y, x, str); +} + +int +mvinnstr(int y, int x, char *str, int n) +{ + return mvwinnstr(stdscr, y, x, str, n); +} + +/* + * mvwinstr, mvwinnstr -- + * Return an array characters at position (y, x) from the given window. + * XXX: should be multi-byte characters for SUSv2. + */ +__warn_references(mvwinstr, + "warning: this program uses mvwinstr(), which is unsafe.") +int +mvwinstr(WINDOW *win, int y, int x, char *str) +{ + if (wmove(win, y, x) == ERR) + return ERR; + + return winstr(win, str); +} + +int +mvwinnstr(WINDOW *win, int y, int x, char *str, int n) +{ + if (wmove(win, y, x) == ERR) + return ERR; + + return winnstr(win, str, n); +} + +#endif /* _CURSES_USE_MACROS */ + +/* + * winstr, winnstr -- + * Return a string of characters at cursor position. + * XXX: should be multi-byte characters for SUSv2. + */ +__warn_references(winstr, + "warning: this program uses winstr(), which is unsafe.") +int +winstr(WINDOW *win, char *str) +{ + + return winnstr(win, str, -1); +} + +/* + * XXX: This should go in a manpage! + * - winnstr() returns the number of characters copied only of if it is + * called with n >= 0 (ie, as inchnstr(), mvinchnstr(), mvwinchnstr() + * or winchnstr()). If N < 0, it returns `OK'. + * - SUSv2/xcurses doesn't document whether the trailing NUL is included + * in the length count or not. For safety's sake it _is_ included. + * - This implementation does not (yet) support multi-byte characters + * strings. + */ +int +winnstr(WINDOW *win, char *str, int n) +{ + __LDATA *end, *start; + int epos; + + if (str == NULL) + return ERR; + + start = &win->alines[win->cury]->line[win->curx]; + /* (n - 1) to leave room for the trailing NUL */ + if (n < 0 || (n - 1) > win->maxx - win->curx - 1) { + epos = win->maxx - 1; + n = win->maxx - win->curx; + } else { + /* extra -1 for trailing NUL */ + epos = win->curx + n - 1 - 1; + n--; + } + end = &win->alines[win->cury]->line[epos]; + + while (start <= end) { + *str = start->ch & __CHARTEXT; + str++; + start++; + } + *str = '\0'; + + if (n < 0) + return OK; + else + return n; +} diff --git a/lib/libcurses/inwstr.c b/lib/libcurses/inwstr.c new file mode 100644 index 000000000..3af1d5c8b --- /dev/null +++ b/lib/libcurses/inwstr.c @@ -0,0 +1,194 @@ +/* $NetBSD: inwstr.c,v 1.3 2009/07/22 16:57:15 roy Exp $ */ + +/* + * Copyright (c) 2005 The NetBSD Foundation Inc. + * All rights reserved. + * + * This code is derived from code donated to the NetBSD Foundation + * by Ruibiao Qiu . + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND + * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: inwstr.c,v 1.3 2009/07/22 16:57:15 roy Exp $"); +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +/* + * inwstr, innwstr -- + * Return a string of wide characters at cursor position from stdscr. + */ +__warn_references(inwstr, + "warning: this program uses inwstr(), which is unsafe.") +int +inwstr(wchar_t *wstr) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return winwstr(stdscr, wstr); +#endif /* HAVE_WCHAR */ +} + +int +innwstr(wchar_t *wstr, int n) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return winnwstr(stdscr, wstr, n); +#endif /* HAVE_WCHAR */ +} + +/* + * mvinwstr, mvinnwstr -- + * Return a string of wide characters at position (y, x) from stdscr. + */ +__warn_references(mvinwstr, + "warning: this program uses mvinwstr(), which is unsafe.") +int +mvinwstr(int y, int x, wchar_t *wstr) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return mvwinwstr(stdscr, y, x, wstr); +#endif /* HAVE_WCHAR */ +} + +int +mvinnwstr(int y, int x, wchar_t *wstr, int n) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return mvwinnwstr(stdscr, y, x, wstr, n); +#endif /* HAVE_WCHAR */ +} + +/* + * mvwinwstr, mvwinnwstr -- + * Return an array wide characters at position (y, x) from the given window. + */ +__warn_references(mvwinwstr, + "warning: this program uses mvwinwstr(), which is unsafe.") +int +mvwinwstr(WINDOW *win, int y, int x, wchar_t *wstr) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + if (wmove(win, y, x) == ERR) + return ERR; + + return winwstr(win, wstr); +#endif /* HAVE_WCHAR */ +} + +int +mvwinnwstr(WINDOW *win, int y, int x, wchar_t *wstr, int n) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + if (wmove(win, y, x) == ERR) + return ERR; + + return winnwstr(win, wstr, n); +#endif /* HAVE_WCHAR */ +} + +/* + * winwstr, winnwstr -- + * Return a string of wide characters at cursor position. + */ +__warn_references(winwstr, + "warning: this program uses winwstr(), which is unsafe.") +int +winwstr(WINDOW *win, wchar_t *wstr) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + + return winnwstr(win, wstr, -1); +#endif /* HAVE_WCHAR */ +} + +/* + * - winnwstr() returns the number of characters copied only of if it is + * called with n >= 0 (ie, as in_wchnstr(), mvin_wchnstr(), mvwin_wchnstr() + * or win_wchnstr()). If N < 0, it returns `OK'. + * - SUSv2/xcurses doesn't document whether the trailing NUL is included + * in the length count or not. For safety's sake it _is_ included. + * - This implementation does not (yet) support multi-byte characters + * strings. + */ +int +winnwstr(WINDOW *win, wchar_t *wstr, int n) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + __LDATA *start; + int x, cw, cnt; + wchar_t *wcp; + + if (wstr == NULL) + return ERR; + + start = &win->alines[win->cury]->line[win->curx]; + x = win->curx; + cw = WCOL( *start ); + if (cw < 0) { + start += cw; + x += cw; + } + cnt = 0; + wcp = wstr; + /* (n - 1) to leave room for the trailing 0 element */ + while ((x < win->maxx) && ((n < 0) || ((n > 1) && (cnt < n - 1)))) { + cw = WCOL( *start ); + *wcp = start->ch; + wcp++; + cnt++; + x += cw; + if ( x < win->maxx ) + start += cw; + } + *wcp = L'\0'; + + if (n < 0) + return OK; + else + return cnt; +#endif /* HAVE_WCHAR */ +} diff --git a/lib/libcurses/keymap.h b/lib/libcurses/keymap.h new file mode 100644 index 000000000..2940b49c4 --- /dev/null +++ b/lib/libcurses/keymap.h @@ -0,0 +1,116 @@ +/* $NetBSD: keymap.h,v 1.3 2010/02/03 15:34:40 roy Exp $ */ + +/* + * Copyright (c) 2005 The NetBSD Foundation Inc. + * All rights reserved. + * + * This code is derived from code donated to the NetBSD Foundation + * by Ruibiao Qiu . + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND + * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _KEYMAP_H_ +#define _KEYMAP_H_ + +#include +#ifndef lint +__RCSID("$NetBSD: keymap.h,v 1.3 2010/02/03 15:34:40 roy Exp $"); +#endif /* not lint */ + +/* keymap related stuff */ +/* + * moved here by Ruibiao Qiu + * because it is needed by both getch() and get_wch() + * + * Keyboard input handler. Do this by snarfing + * all the info we can out of the termcap entry for TERM and putting it + * into a set of keymaps. A keymap is an array the size of all the possible + * single characters we can get, the contents of the array is a structure + * that contains the type of entry this character is (i.e. part/end of a + * multi-char sequence or a plain char) and either a pointer which will point + * to another keymap (in the case of a multi-char sequence) OR the data value + * that this key should return. + * + */ + +/* private data structures for holding the key definitions */ +typedef struct key_entry key_entry_t; + +struct key_entry { + short type; /* type of key this is */ + bool enable; /* true if the key is active */ + union { + keymap_t *next; /* next keymap is key is multi-key sequence */ + wchar_t symbol; /* key symbol if key is a leaf entry */ + } value; +}; +/* Types of key structures we can have */ +#define KEYMAP_MULTI 1 /* part of a multi char sequence */ +#define KEYMAP_LEAF 2 /* key has a symbol associated with it, either + * it is the end of a multi-char sequence or a + * single char key that generates a symbol */ + +/* allocate this many key_entry structs at once to speed start up must + * be a power of 2. + */ +#define KEYMAP_ALLOC_CHUNK 4 + +/* The max number of different chars we can receive */ +#define MAX_CHAR 256 + +/* + * Unused mapping flag. + */ +#define MAPPING_UNUSED (0 - MAX_CHAR) /* never been used */ + +struct keymap { + int count; /* count of number of key structs allocated */ + short mapping[MAX_CHAR]; /* mapping of key to allocated structs */ + key_entry_t **key; /* dynamic array of keys */ +}; + +#define INC_POINTER(ptr) do { \ + (ptr)++; \ + (ptr) %= INBUF_SZ; \ +} while(/*CONSTCOND*/0) + +#define INKEY_NORM 0 /* no key backlog to process */ +#define INKEY_ASSEMBLING 1 /* assembling a multi-key sequence */ +#define INKEY_BACKOUT 2 /* recovering from an unrecognised key */ +#define INKEY_TIMEOUT 3 /* multi-key sequence timeout */ +#ifdef HAVE_WCHAR +#define INKEY_WCASSEMBLING 4 /* assembling a wide char sequence */ +#endif /* HAVE_WCHAR */ + +/* The termcap data we are interested in and the symbols they map to */ +struct tcdata { + int code; /* code of the terminfo entry */ + wchar_t symbol; /* the symbol associated with it */ +}; + +#endif /* _KEYMAP_H_ */ diff --git a/lib/libcurses/keyname.c b/lib/libcurses/keyname.c new file mode 100644 index 000000000..2adef1d01 --- /dev/null +++ b/lib/libcurses/keyname.c @@ -0,0 +1,508 @@ +/* $NetBSD: keyname.c,v 1.6 2008/04/28 20:23:01 martin Exp $ */ + +/*- + * Copyright (c) 2003 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Julian Coleman. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: keyname.c,v 1.6 2008/04/28 20:23:01 martin Exp $"); +#endif /* not lint */ + +#include +#include + +#include "curses.h" +#include "curses_private.h" + +#define KEYNAMEMAX (size_t) 14 /* "KEY_BACKSPACE\0" */ +static char name[KEYNAMEMAX + 1]; + +/* + * keyname -- + * Return name of key or NULL; + */ +char * +keyname(int key) +{ +/* We don't bother with the large keyname table if SMALL is defined. */ +#ifdef SMALL + strcpy(name, "-1\0"); + return name; +#else + if (key < 0) { + strcpy(name, "-1\0"); + return name; + } + + /* No name. */ + if (key == 0x100) { + strcpy(name, "-1\0"); + return name; + } + + /* Control codes */ + if (key < 0x20) { + name[0] = '^'; + name[1] = (char) (key + 64); /* Offset of '@' */ + name[2] = '\0'; + return name; + } + + /* "Normal" keys */ + if (key < 0x7F) { + name[0] = (char) key; + name[1] = '\0'; + return name; + } + + /* Delete key */ + if (key == 0x7F) { + strcpy(name, "^?\0"); + return name; + } + + /* Meta + control codes */ + if (key < 0x9F) { + strcpy(name, "M-^"); + name[3] = (char) (key - 64); /* Offset of '@' */ + name[4] = '\0'; + return name; + } + + /* Meta + "normal" keys */ + if (key < 0xFF) { + strcpy (name, "M-"); + name[2] = (char) (key - 128); + name[3] = '\0'; + return name; + } + + /* Meta + delete key */ + if (key == 0xFF) { + strcpy(name, "M-^?\0"); + return name; + } + + /* Key names. Synchronise this with curses.h. */ + if (key == 0x101) { + strncpy(name, "KEY_BREAK\0", KEYNAMEMAX); + return name; + } + if (key == 0x102) { + strncpy(name, "KEY_DOWN\0", KEYNAMEMAX); + return name; + } + if (key == 0x103) { + strncpy(name, "KEY_UP\0", KEYNAMEMAX); + return name; + } + if (key == 0x104) { + strncpy(name, "KEY_LEFT\0", KEYNAMEMAX); + return name; + } + if (key == 0x105) { + strncpy(name, "KEY_RIGHT\0", KEYNAMEMAX); + return name; + } + if (key == 0x106) { + strncpy(name, "KEY_HOME\0", KEYNAMEMAX); + return name; + } + if (key == 0x107) { + strncpy(name, "KEY_BACKSPACE\0", KEYNAMEMAX); + return name; + } + /* Function key block (64 keys). */ + if (key < 0x148) { + int i; + + strcpy(name, "KEY_F("); + i = snprintf(&name[6], (size_t) 3, "%d", key - 0x108); + name[6 + i] = ')'; + name[7 + i] = '\0'; + return name; + } + if (key == 0x148) { + strncpy(name, "KEY_DL\0", KEYNAMEMAX); + return name; + } + if (key == 0x149) { + strncpy(name, "KEY_IL\0", KEYNAMEMAX); + return name; + } + if (key == 0x14A) { + strncpy(name, "KEY_DC\0", KEYNAMEMAX); + return name; + } + if (key == 0x14B) { + strncpy(name, "KEY_IC\0", KEYNAMEMAX); + return name; + } + if (key == 0x14C) { + strncpy(name, "KEY_EIC\0", KEYNAMEMAX); + return name; + } + if (key == 0x14D) { + strncpy(name, "KEY_CLEAR\0", KEYNAMEMAX); + return name; + } + if (key == 0x14E) { + strncpy(name, "KEY_EOS\0", KEYNAMEMAX); + return name; + } + if (key == 0x14F) { + strncpy(name, "KEY_EOL\0", KEYNAMEMAX); + return name; + } + if (key == 0x150) { + strncpy(name, "KEY_SF\0", KEYNAMEMAX); + return name; + } + if (key == 0x151) { + strncpy(name, "KEY_SR\0", KEYNAMEMAX); + return name; + } + if (key == 0x152) { + strncpy(name, "KEY_NPAGE\0", KEYNAMEMAX); + return name; + } + if (key == 0x153) { + strncpy(name, "KEY_PPAGE\0", KEYNAMEMAX); + return name; + } + if (key == 0x154) { + strncpy(name, "KEY_STAB\0", KEYNAMEMAX); + return name; + } + if (key == 0x155) { + strncpy(name, "KEY_CTAB\0", KEYNAMEMAX); + return name; + } + if (key == 0x156) { + strncpy(name, "KEY_CATAB\0", KEYNAMEMAX); + return name; + } + if (key == 0x157) { + strncpy(name, "KEY_ENTER\0", KEYNAMEMAX); + return name; + } + if (key == 0x158) { + strncpy(name, "KEY_SRESET\0", KEYNAMEMAX); + return name; + } + if (key == 0x159) { + strncpy(name, "KEY_RESET\0", KEYNAMEMAX); + return name; + } + if (key == 0x15A) { + strncpy(name, "KEY_PRINT\0", KEYNAMEMAX); + return name; + } + if (key == 0x15B) { + strncpy(name, "KEY_LL\0", KEYNAMEMAX); + return name; + } + if (key == 0x15C) { + strncpy(name, "KEY_A1\0", KEYNAMEMAX); + return name; + } + if (key == 0x15D) { + strncpy(name, "KEY_A3\0", KEYNAMEMAX); + return name; + } + if (key == 0x15E) { + strncpy(name, "KEY_B2\0", KEYNAMEMAX); + return name; + } + if (key == 0x15F) { + strncpy(name, "KEY_C1\0", KEYNAMEMAX); + return name; + } + if (key == 0x160) { + strncpy(name, "KEY_C3\0", KEYNAMEMAX); + return name; + } + if (key == 0x161) { + strncpy(name, "KEY_BTAB\0", KEYNAMEMAX); + return name; + } + if (key == 0x162) { + strncpy(name, "KEY_BEG\0", KEYNAMEMAX); + return name; + } + if (key == 0x163) { + strncpy(name, "KEY_CANCEL\0", KEYNAMEMAX); + return name; + } + if (key == 0x164) { + strncpy(name, "KEY_CLOSE\0", KEYNAMEMAX); + return name; + } + if (key == 0x165) { + strncpy(name, "KEY_COMMAND\0", KEYNAMEMAX); + return name; + } + if (key == 0x166) { + strncpy(name, "KEY_COPY\0", KEYNAMEMAX); + return name; + } + if (key == 0x167) { + strncpy(name, "KEY_CREATE\0", KEYNAMEMAX); + return name; + } + if (key == 0x168) { + strncpy(name, "KEY_END\0", KEYNAMEMAX); + return name; + } + if (key == 0x169) { + strncpy(name, "KEY_EXIT\0", KEYNAMEMAX); + return name; + } + if (key == 0x16A) { + strncpy(name, "KEY_FIND\0", KEYNAMEMAX); + return name; + } + if (key == 0x16B) { + strncpy(name, "KEY_HELP\0", KEYNAMEMAX); + return name; + } + if (key == 0x16C) { + strncpy(name, "KEY_MARK\0", KEYNAMEMAX); + return name; + } + if (key == 0x16D) { + strncpy(name, "KEY_MESSAGE\0", KEYNAMEMAX); + return name; + } + if (key == 0x16E) { + strncpy(name, "KEY_MOVE\0", KEYNAMEMAX); + return name; + } + if (key == 0x16F) { + strncpy(name, "KEY_NEXT\0", KEYNAMEMAX); + return name; + } + if (key == 0x170) { + strncpy(name, "KEY_OPEN\0", KEYNAMEMAX); + return name; + } + if (key == 0x171) { + strncpy(name, "KEY_OPTIONS\0", KEYNAMEMAX); + return name; + } + if (key == 0x172) { + strncpy(name, "KEY_PREVIOUS\0", KEYNAMEMAX); + return name; + } + if (key == 0x173) { + strncpy(name, "KEY_REDO\0", KEYNAMEMAX); + return name; + } + if (key == 0x174) { + strncpy(name, "KEY_REFERENCE\0", KEYNAMEMAX); + return name; + } + if (key == 0x175) { + strncpy(name, "KEY_REFRESH\0", KEYNAMEMAX); + return name; + } + if (key == 0x176) { + strncpy(name, "KEY_REPLACE\0", KEYNAMEMAX); + return name; + } + if (key == 0x177) { + strncpy(name, "KEY_RESTART\0", KEYNAMEMAX); + return name; + } + if (key == 0x178) { + strncpy(name, "KEY_RESUME\0", KEYNAMEMAX); + return name; + } + if (key == 0x179) { + strncpy(name, "KEY_SAVE\0", KEYNAMEMAX); + return name; + } + if (key == 0x17A) { + strncpy(name, "KEY_SBEG\0", KEYNAMEMAX); + return name; + } + if (key == 0x17B) { + strncpy(name, "KEY_SCANCEL\0", KEYNAMEMAX); + return name; + } + if (key == 0x17C) { + strncpy(name, "KEY_SCOMMAND\0", KEYNAMEMAX); + return name; + } + if (key == 0x17D) { + strncpy(name, "KEY_SCOPY\0", KEYNAMEMAX); + return name; + } + if (key == 0x17E) { + strncpy(name, "KEY_SCREATE\0", KEYNAMEMAX); + return name; + } + if (key == 0x17F) { + strncpy(name, "KEY_SDC\0", KEYNAMEMAX); + return name; + } + if (key == 0x180) { + strncpy(name, "KEY_SDL\0", KEYNAMEMAX); + return name; + } + if (key == 0x181) { + strncpy(name, "KEY_SELECT\0", KEYNAMEMAX); + return name; + } + if (key == 0x182) { + strncpy(name, "KEY_SEND\0", KEYNAMEMAX); + return name; + } + if (key == 0x183) { + strncpy(name, "KEY_SEOL\0", KEYNAMEMAX); + return name; + } + if (key == 0x184) { + strncpy(name, "KEY_SEXIT\0", KEYNAMEMAX); + return name; + } + if (key == 0x185) { + strncpy(name, "KEY_SFIND\0", KEYNAMEMAX); + return name; + } + if (key == 0x186) { + strncpy(name, "KEY_SHELP\0", KEYNAMEMAX); + return name; + } + if (key == 0x187) { + strncpy(name, "KEY_SHOME\0", KEYNAMEMAX); + return name; + } + if (key == 0x188) { + strncpy(name, "KEY_SIC\0", KEYNAMEMAX); + return name; + } + if (key == 0x189) { + strncpy(name, "KEY_SLEFT\0", KEYNAMEMAX); + return name; + } + if (key == 0x18A) { + strncpy(name, "KEY_SMESSAGE\0", KEYNAMEMAX); + return name; + } + if (key == 0x18B) { + strncpy(name, "KEY_SMOVE\0", KEYNAMEMAX); + return name; + } + if (key == 0x18C) { + strncpy(name, "KEY_SNEXT\0", KEYNAMEMAX); + return name; + } + if (key == 0x18D) { + strncpy(name, "KEY_SOPTIONS\0", KEYNAMEMAX); + return name; + } + if (key == 0x18E) { + strncpy(name, "KEY_SPREVIOUS\0", KEYNAMEMAX); + return name; + } + if (key == 0x18F) { + strncpy(name, "KEY_SPRINT\0", KEYNAMEMAX); + return name; + } + if (key == 0x190) { + strncpy(name, "KEY_SREDO\0", KEYNAMEMAX); + return name; + } + if (key == 0x191) { + strncpy(name, "KEY_SREPLACE\0", KEYNAMEMAX); + return name; + } + if (key == 0x192) { + strncpy(name, "KEY_SRIGHT\0", KEYNAMEMAX); + return name; + } + if (key == 0x193) { + strncpy(name, "KEY_SRSUME\0", KEYNAMEMAX); + return name; + } + if (key == 0x194) { + strncpy(name, "KEY_SSAVE\0", KEYNAMEMAX); + return name; + } + if (key == 0x195) { + strncpy(name, "KEY_SSUSPEND\0", KEYNAMEMAX); + return name; + } + if (key == 0x196) { + strncpy(name, "KEY_SUNDO\0", KEYNAMEMAX); + return name; + } + if (key == 0x197) { + strncpy(name, "KEY_SUSPEND\0", KEYNAMEMAX); + return name; + } + if (key == 0x198) { + strncpy(name, "KEY_UNDO\0", KEYNAMEMAX); + return name; + } + if (key == 0x199) { + strncpy(name, "KEY_MOUSE\0", KEYNAMEMAX); + return name; + } + if (key == 0x200) { + strncpy(name, "KEY_RESIZE\0", KEYNAMEMAX); + return name; + } + /* No more names. */ + strncpy(name, "UNKOWN KEY\0", KEYNAMEMAX); + return name; +#endif +} +/* + * key_name -- + * Return name of key or NULL; + */ +char * +key_name(wchar_t key) +{ +#ifndef HAVE_WCHAR + return NULL; +#else + (void) keyname((int) key); + + if (!strncmp(name, "M-", 2)) { + /* Remove the "M-" */ + name[0] = name[2]; + name[1] = '\0'; + } + return name; +#endif /* HAVE_WCHAR */ +} + diff --git a/lib/libcurses/keypad.c b/lib/libcurses/keypad.c new file mode 100644 index 000000000..94640a22f --- /dev/null +++ b/lib/libcurses/keypad.c @@ -0,0 +1,59 @@ +/* $NetBSD: keypad.c,v 1.12 2010/02/03 15:34:40 roy Exp $ */ + +/*- + * Copyright (c) 1998-1999 Brett Lymn (blymn@baea.com.au, brett_lymn@yahoo.com) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + */ + +#include +#ifndef lint +__RCSID("$NetBSD: keypad.c,v 1.12 2010/02/03 15:34:40 roy Exp $"); +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +/* + * keypad -- + * Turn on and off interpretation of function/keypad keys in the + * given window. + */ +int +keypad(WINDOW *win, bool bf) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, + "keypad: win %p, %s\n", win, bf ? "TRUE" : "FALSE"); +#endif + if (bf) { + win->flags |= __KEYPAD; + if (!(curscr->flags & __KEYPAD)) { + tputs (keypad_xmit, 0, __cputchar); + curscr->flags |= __KEYPAD; + } + } else + win->flags &= ~__KEYPAD; + + return OK; +} diff --git a/lib/libcurses/leaveok.c b/lib/libcurses/leaveok.c new file mode 100644 index 000000000..e997763aa --- /dev/null +++ b/lib/libcurses/leaveok.c @@ -0,0 +1,52 @@ +/* $NetBSD: leaveok.c,v 1.5 2008/04/28 20:23:01 martin Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Julian Coleman. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: leaveok.c,v 1.5 2008/04/28 20:23:01 martin Exp $"); +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +/* + * leaveok -- + * Turn on and off leave cursor after refresh for the given window. + */ +int +leaveok(WINDOW *win, bool bf) +{ + if (bf) + win->flags |= __LEAVEOK; + else + win->flags &= ~__LEAVEOK; + return (OK); +} diff --git a/lib/libcurses/line.c b/lib/libcurses/line.c new file mode 100644 index 000000000..50c93034b --- /dev/null +++ b/lib/libcurses/line.c @@ -0,0 +1,305 @@ +/* $NetBSD: line.c,v 1.6 2010/02/23 19:48:26 drochner Exp $ */ + +/*- + * Copyright (c) 1998-1999 Brett Lymn + * (blymn@baea.com.au, brett_lymn@yahoo.com.au) + * All rights reserved. + * + * This code has been donated to The NetBSD Foundation by the Author. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + */ + +#include +#ifndef lint +__RCSID("$NetBSD: line.c,v 1.6 2010/02/23 19:48:26 drochner Exp $"); +#endif /* not lint */ + +#include + +#include "curses.h" +#include "curses_private.h" + +/* + * hline -- + * Draw a horizontal line of character c on stdscr. + */ +int +hline(chtype ch, int count) +{ + return whline(stdscr, ch, count); +} + +/* + * mvhline -- + * Move to location (y, x) and draw a horizontal line of character c + * on stdscr. + */ +int +mvhline(int y, int x, chtype ch, int count) +{ + return mvwhline(stdscr, y, x, ch, count); +} + +/* + * mvwhline -- + * Move to location (y, x) and draw a horizontal line of character c + * in the given window. + */ +int +mvwhline(WINDOW *win, int y, int x, chtype ch, int count) +{ + if (wmove(win, y, x) == ERR) + return ERR; + + return whline(win, ch, count); +} + +/* + * whline -- + * Draw a horizontal line of character c in the given window moving + * towards the rightmost column. At most count characters are drawn + * or until the edge of the screen, whichever comes first. + */ +int +whline(WINDOW *win, chtype ch, int count) +{ +#ifndef HAVE_WCHAR + int ocurx, n, i; + + n = min(count, win->maxx - win->curx); + ocurx = win->curx; + + if (!(ch & __CHARTEXT)) + ch |= ACS_HLINE; + for (i = 0; i < n; i++) + mvwaddch(win, win->cury, ocurx + i, ch); + + wmove(win, win->cury, ocurx); + return OK; +#else + cchar_t cch, *cchp; + + if (ch & __CHARTEXT) { + __cursesi_chtype_to_cchar(ch, &cch); + cchp = & cch; + } else + cchp = WACS_HLINE; + + return whline_set(win, cchp, count); +#endif +} + +/* + * vline -- + * Draw a vertical line of character ch on stdscr. + */ +int +vline(chtype ch, int count) +{ + return wvline(stdscr, ch, count); +} + +/* + * mvvline -- + * Move to the given location an draw a vertical line of character ch. + */ +int +mvvline(int y, int x, chtype ch, int count) +{ + return mvwvline(stdscr, y, x, ch, count); +} + +/* + * mvwvline -- + * Move to the given location and draw a vertical line of character ch + * on the given window. + */ +int +mvwvline(WINDOW *win, int y, int x, chtype ch, int count) +{ + if (wmove(win, y, x) == ERR) + return ERR; + + return wvline(win, ch, count); +} + +/* + * wvline -- + * Draw a vertical line of character ch in the given window moving + * towards the bottom of the screen. At most count characters are drawn + * or until the edge of the screen, whichever comes first. + */ +int +wvline(WINDOW *win, chtype ch, int count) +{ +#ifndef HAVE_WCHAR + int ocury, ocurx, n, i; + + n = min(count, win->maxy - win->cury); + ocury = win->cury; + ocurx = win->curx; + + if (!(ch & __CHARTEXT)) + ch |= ACS_VLINE; + for (i = 0; i < n; i++) + mvwaddch(win, ocury + i, ocurx, ch); + + wmove(win, ocury, ocurx); + return OK; +#else + cchar_t cch, *cchp; + + if (ch & __CHARTEXT) { + __cursesi_chtype_to_cchar(ch, &cch); + cchp = & cch; + } else + cchp = WACS_VLINE; + + return wvline_set(win, cchp, count); +#endif +} + +int hline_set(const cchar_t *wch, int n) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return whline_set( stdscr, wch, n ); +#endif /* HAVE_WCHAR */ +} + +int mvhline_set(int y, int x, const cchar_t *wch, int n) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return mvwhline_set( stdscr, y, x, wch, n ); +#endif /* HAVE_WCHAR */ +} + +int mvwhline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + if ( wmove( win, y , x ) == ERR ) + return ERR; + + return whline_set( win, wch, n ); +#endif /* HAVE_WCHAR */ +} + +int whline_set(WINDOW *win, const cchar_t *wch, int n) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + int ocurx, wcn, i, cw; + cchar_t cc; + + cw = wcwidth( wch->vals[ 0 ]); + if (cw < 0) + cw = 1; + if ( ( win->maxx - win->curx ) < cw ) + return ERR; + wcn = min( n, ( win->maxx - win->curx ) / cw ); +#ifdef DEBUG + __CTRACE(__CTRACE_LINE, "whline_set: line of %d\n", wcn); +#endif /* DEBUG */ + ocurx = win->curx; + + memcpy( &cc, wch, sizeof( cchar_t )); + if (!(wch->vals[ 0 ])) + cc.vals[ 0 ] |= WACS_HLINE->vals[0]; + for (i = 0; i < wcn; i++ ) { +#ifdef DEBUG + __CTRACE(__CTRACE_LINE, "whline_set: (%d,%d)\n", + win->cury, ocurx + i * cw); +#endif /* DEBUG */ + mvwadd_wch(win, win->cury, ocurx + i * cw, &cc); + } + + wmove(win, win->cury, ocurx); + return OK; +#endif /* HAVE_WCHAR */ +} + +int vline_set(const cchar_t *wch, int n) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return wvline_set( stdscr, wch, n ); +#endif /* HAVE_WCHAR */ +} + +int mvvline_set(int y, int x, const cchar_t *wch, int n) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + return mvwvline_set( stdscr, y, x, wch, n ); +#endif /* HAVE_WCHAR */ +} + +int mvwvline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + if ( wmove( win, y, x ) == ERR ) + return ERR; + + return wvline_set( win, wch, n ); +#endif /* HAVE_WCHAR */ +} + +int wvline_set(WINDOW *win, const cchar_t *wch, int n) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + int ocury, ocurx, wcn, i; + cchar_t cc; + + wcn = min( n, win->maxy - win->cury); +#ifdef DEBUG + __CTRACE(__CTRACE_LINE, "wvline_set: line of %d\n", wcn); +#endif /* DEBUG */ + ocury = win->cury; + ocurx = win->curx; + + memcpy( &cc, wch, sizeof( cchar_t )); + if (!(wch->vals[ 0 ])) + cc.vals[ 0 ] |= WACS_VLINE->vals[0]; + for (i = 0; i < wcn; i++) { + mvwadd_wch(win, ocury + i, ocurx, &cc); +#ifdef DEBUG + __CTRACE(__CTRACE_LINE, "wvline_set: (%d,%d)\n", + ocury + i, ocurx); +#endif /* DEBUG */ + } + wmove(win, ocury, ocurx); + return OK; +#endif /* HAVE_WCHAR */ +} diff --git a/lib/libcurses/longname.c b/lib/libcurses/longname.c index ca9ac523d..64adbd81f 100644 --- a/lib/libcurses/longname.c +++ b/lib/libcurses/longname.c @@ -1,12 +1,88 @@ -#include -#include "curspriv.h" +/* $NetBSD: longname.c,v 1.16 2004/01/20 08:29:29 wiz Exp $ */ -/****************************************************************/ -/* Longname() returns a pointer to a string describing the */ -/* User terminal. */ -/****************************************************************/ +/* + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ -char *longname() +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)longname.c 8.1 (Berkeley) 6/4/93"; +#else +__RCSID("$NetBSD: longname.c,v 1.16 2004/01/20 08:29:29 wiz Exp $"); +#endif +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +/* + * __longname -- + * Fill in "def" with the long name of the terminal. + * This is the original BSD version of longname(), modified to return + * at most 128 characters. + */ +char * +__longname(char *bp, char *def) +{ + char *cp, *last_bp; + int i = 0; + + last_bp = NULL; + do { + while (*bp && *bp != ':' && *bp != '|') + bp++; + if (*bp == '|') { + last_bp = bp; + bp++; + } + } while (*bp && *bp != ':'); + + if (last_bp != NULL) + bp = last_bp; + + if (*bp == '|') { + for (cp = def, ++bp; *bp && *bp != ':' && *bp != '|' && + i < 127;) + *cp++ = *bp++; + i++; + *cp = '\0'; + } + return (def); +} + +/* + * longname -- + * Return pointer to the long name of the terminal. + * This is the SUS version of longname() + */ +char * +longname(void) { - return("not implemented"); + return (_cursesi_screen->ttytype); } diff --git a/lib/libcurses/meta.c b/lib/libcurses/meta.c new file mode 100644 index 000000000..917c549b6 --- /dev/null +++ b/lib/libcurses/meta.c @@ -0,0 +1,77 @@ +/* $NetBSD: meta.c,v 1.7 2010/02/03 15:34:40 roy Exp $ */ + +/*- + * Copyright (c) 1998-2000 Brett Lymn + * (blymn@baea.com.au, brett_lymn@yahoo.com.au) + * All rights reserved. + * + * This code has been donated to The NetBSD Foundation by the Author. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + */ + +#include +#ifndef lint +__RCSID("$NetBSD: meta.c,v 1.7 2010/02/03 15:34:40 roy Exp $"); +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +/* + * meta -- + * Turn on or off the terminal meta mode. + */ +int +meta(/*ARGSUSED*/ WINDOW *win, bool bf) +{ + if (bf == TRUE) { + if (meta_on != NULL) { +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "meta: TRUE\n"); +#endif + tputs(meta_on, 0, __cputchar); + _cursesi_screen->meta_state = TRUE; + } + } else { + if (meta_off != NULL) { +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "meta: FALSE\n"); +#endif + tputs(meta_off, 0, __cputchar); + _cursesi_screen->meta_state = FALSE; + } + } + + return OK; +} + +/* + * __restore_meta_state -- + * Restore old meta state. + */ +void +__restore_meta_state(void) +{ + meta(NULL, _cursesi_screen->meta_state); +} + diff --git a/lib/libcurses/move.c b/lib/libcurses/move.c index e5059c959..b964105ef 100644 --- a/lib/libcurses/move.c +++ b/lib/libcurses/move.c @@ -1,18 +1,88 @@ -#include -#include "curspriv.h" +/* $NetBSD: move.c,v 1.17 2010/02/23 19:48:26 drochner Exp $ */ -/****************************************************************/ -/* Wmove() moves the cursor in window 'win' to position (x,y). */ -/****************************************************************/ +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ -int wmove(win, y, x) -WINDOW *win; -int y; -int x; +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)move.c 8.2 (Berkeley) 5/4/94"; +#else +__RCSID("$NetBSD: move.c,v 1.17 2010/02/23 19:48:26 drochner Exp $"); +#endif +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +#ifndef _CURSES_USE_MACROS +/* + * move -- + * Moves the cursor to the given point on stdscr. + */ +int +move(int y, int x) +{ + return wmove(stdscr, y, x); +} + +#endif + +/* + * wmove -- + * Moves the cursor to the given point. + */ +int +wmove(WINDOW *win, int y, int x) { - if ((x<0) || (x>win->_maxx) || (y_regtop) || (y>win->_regbottom)) - return(ERR); - win->_curx = x; - win->_cury = y; - return(OK); + +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "wmove: (%d, %d)\n", y, x); +#endif + if (x < 0 || y < 0) + return (ERR); + if (x >= win->maxx || y >= win->maxy) + return (ERR); + win->curx = x; + win->alines[win->cury]->flags &= ~__ISPASTEOL; + win->cury = y; + win->alines[y]->flags &= ~__ISPASTEOL; + return (OK); +} + +void +wcursyncup(WINDOW *win) +{ + + while (win->orig) { + wmove(win->orig, win->cury + win->begy - win->orig->begy, + win->curx + win->begx - win->orig->begx); + win = win->orig; + } } diff --git a/lib/libcurses/mvcursor.c b/lib/libcurses/mvcursor.c deleted file mode 100644 index e16615439..000000000 --- a/lib/libcurses/mvcursor.c +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include "curspriv.h" - -/****************************************************************/ -/* Mvcur(oldy,oldx,newy,newx) the display cursor to */ -/****************************************************************/ - -int mvcur(oldy, oldx, newy, newx) -int oldy; -int oldx; -int newy; -int newx; -{ - if ((newy >= LINES) || (newx >= COLS) || (newy < 0) || (newx < 0)) - return(ERR); - poscur(newy, newx); - _cursvar.cursrow = newy; - _cursvar.curscol = newx; - return(OK); -} diff --git a/lib/libcurses/mvwin.c b/lib/libcurses/mvwin.c new file mode 100644 index 000000000..ddc9ff089 --- /dev/null +++ b/lib/libcurses/mvwin.c @@ -0,0 +1,103 @@ +/* $NetBSD: mvwin.c,v 1.15 2003/08/07 16:44:22 agc Exp $ */ + +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)mvwin.c 8.2 (Berkeley) 5/4/94"; +#else +__RCSID("$NetBSD: mvwin.c,v 1.15 2003/08/07 16:44:22 agc Exp $"); +#endif +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +/* + * mvderwin -- + * Move a derived window. + * + */ +int +mvderwin(WINDOW *win, int dy, int dx) +{ + WINDOW *parent; + int x, y; + + if (win == NULL) + return ERR; + + parent = win->orig; + + if (parent == NULL) + return ERR; + + x = parent->begx + dx; + y = parent->begy + dy; + return mvwin(win, y, x); +} + +/* + * mvwin -- + * Relocate the starting position of a window. + */ +int +mvwin(WINDOW *win, int by, int bx) +{ + WINDOW *orig; + int dy, dx; + + if (by < 0 || by + win->maxy > LINES || bx < 0 || bx + win->maxx > COLS) + return (ERR); + dy = by - win->begy; + dx = bx - win->begx; + orig = win->orig; + if (orig == NULL) { + orig = win; + do { + win->begy += dy; + win->begx += dx; + __swflags(win); + win = win->nextp; + } while (win != orig); + } else { + if (by < orig->begy || win->maxy + dy > orig->maxy) + return (ERR); + if (bx < orig->begx || win->maxx + dx > orig->maxx) + return (ERR); + win->begy = by; + win->begx = bx; + __swflags(win); + __set_subwin(orig, win); + } + __touchwin(win); + return (OK); +} diff --git a/lib/libcurses/newwin.c b/lib/libcurses/newwin.c index 23f2471a6..4084b66e9 100644 --- a/lib/libcurses/newwin.c +++ b/lib/libcurses/newwin.c @@ -1,144 +1,416 @@ +/* $NetBSD: newwin.c,v 1.47 2009/07/22 16:57:15 roy Exp $ */ + +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)newwin.c 8.3 (Berkeley) 7/27/94"; +#else +__RCSID("$NetBSD: newwin.c,v 1.47 2009/07/22 16:57:15 roy Exp $"); +#endif +#endif /* not lint */ + #include -#include -#include "curspriv.h" -/****************************************************************/ -/* Makenew() allocates all data for a new window except the */ -/* Actual lines themselves. */ -/****************************************************************/ +#include "curses.h" +#include "curses_private.h" + + +static WINDOW *__makenew(SCREEN *screen, int nlines, int ncols, int by, + int bx, int sub, int ispad); +static WINDOW *__subwin(WINDOW *orig, int nlines, int ncols, int by, int bx, + int ispad); + +/* + * derwin -- + * Create a new window in the same manner as subwin but (by, bx) + * are relative to the origin of window orig instead of absolute. + */ +WINDOW * +derwin(WINDOW *orig, int nlines, int ncols, int by, int bx) +{ -_PROTOTYPE(static WINDOW *makenew, (int nlines, int ncols, int begy,int begx)); + return __subwin(orig, nlines, ncols, orig->begy + by, orig->begx + bx, + FALSE); +} -static WINDOW *makenew(num_lines, num_columns, begy, begx) -int num_lines, num_columns, begy, begx; +/* + * subpad -- + * Create a new pad in the same manner as subwin but (by, bx) + * are relative to the origin of window orig instead of absolute. + */ +WINDOW * +subpad(WINDOW *orig, int nlines, int ncols, int by, int bx) { - int i; - WINDOW *win; - - /* Allocate the window structure itself */ - if ((win = (WINDOW *) malloc(sizeof(WINDOW))) == NULL) - return((WINDOW *) ERR); - - /* Allocate the line pointer array */ - if ((win->_line = (int **) calloc(num_lines, sizeof(int *))) == NULL) { - free(win); - return((WINDOW *) ERR); - } - - /* Allocate the minchng and maxchng arrays */ - if ((win->_minchng = (int *) calloc(num_lines, sizeof(int))) == NULL) { - free(win->_line); - free(win); - return((WINDOW *) ERR); - } - if ((win->_maxchng = (int *) calloc(num_lines, sizeof(int))) == NULL) { - free(win->_line); - free(win->_minchng); - free(win); - return((WINDOW *) ERR); - } - - /* Initialize window variables */ - win->_curx = 0; - win->_cury = 0; - win->_maxy = num_lines - 1; - win->_maxx = num_columns - 1; - win->_begy = begy; - win->_begx = begx; - win->_flags = 0; - win->_attrs = ATR_NRM; - win->_tabsize = 8; - win->_clear = FALSE; - win->_leave = FALSE; - win->_scroll = FALSE; - win->_nodelay = FALSE; - win->_keypad = FALSE; - win->_regtop = 0; - win->_regbottom = num_lines - 1; - - /* Init to say window unchanged */ - for (i = 0; i < num_lines; i++) { - win->_minchng[i] = 0; - win->_maxchng[i] = num_columns - 1; - } - - /* Set flags for window properties */ - if ((begy + num_lines) == LINES) { - win->_flags |= _ENDLINE; - if ((begx == 0) && (num_columns == COLS) && (begy == 0)) - win->_flags |= _FULLWIN; - } /* if */ - if (((begy + num_lines) == LINES) && ((begx + num_columns) == COLS)) - win->_flags |= _SCROLLWIN; - return(win); + + return __subwin(orig, nlines, ncols, orig->begy + by, orig->begx + bx, + TRUE); } +/* + * dupwin -- + * Create a copy of the given window. + */ +WINDOW * +dupwin(WINDOW *win) +{ + WINDOW *new_one; + + if ((new_one = __newwin(_cursesi_screen, win->maxy, win->maxx, + win->begy, win->begx, FALSE)) == NULL) + return NULL; -/****************************************************************/ -/* Newwin() creates a new window with size num_lines * num_co- */ -/* Lumns, and origin begx,begy relative to the SCREEN. Special */ -/* Case: if num_lines and/or num_columns is 0, the remainder of */ -/* The screen is used. */ -/****************************************************************/ -WINDOW *newwin(num_lines, num_columns, begy, begx) -int num_lines, num_columns, begy, begx; + overwrite(win, new_one); + return new_one; +} + +/* + * newwin -- + * Allocate space for and set up defaults for a new window. + */ +WINDOW * +newwin(int nlines, int ncols, int by, int bx) { - WINDOW *win; - int *ptr; - int i, j; - - if (num_lines == 0) num_lines = LINES - begy; - if (num_columns == 0) num_columns = COLS - begx; - if ((win = makenew(num_lines, num_columns, begy, begx)) == (WINDOW *) ERR) - return((WINDOW *) ERR); - for (i = 0; i < num_lines; i++) { /* make and clear the lines */ - if ((win->_line[i] = (int *)calloc(num_columns, sizeof(int))) == NULL){ - for (j = 0; j < i; j++) /* if error, free all the data */ - free(win->_line[j]); - free(win->_minchng); - free(win->_maxchng); - free(win->_line); - free(win); - return((WINDOW *) ERR); - } else { - for (ptr = win->_line[i]; ptr < win->_line[i] + num_columns;) - *ptr++ = ' ' | ATR_NRM; + return __newwin(_cursesi_screen, nlines, ncols, by, bx, FALSE); +} + +/* + * newpad -- + * Allocate space for and set up defaults for a new pad. + */ +WINDOW * +newpad(int nlines, int ncols) +{ + if (nlines < 1 || ncols < 1) + return NULL; + return __newwin(_cursesi_screen, nlines, ncols, 0, 0, TRUE); +} + +WINDOW * +__newwin(SCREEN *screen, int nlines, int ncols, int by, int bx, int ispad) +{ + WINDOW *win; + __LINE *lp; + int i, j; + int maxy, maxx; + __LDATA *sp; + + if (by < 0 || bx < 0) + return (NULL); + + maxy = nlines > 0 ? nlines : LINES - by + nlines; + maxx = ncols > 0 ? ncols : COLS - bx + ncols; + + if ((win = __makenew(screen, maxy, maxx, by, bx, 0, ispad)) == NULL) + return (NULL); + + win->bch = ' '; + if (__using_color) + win->battr = __default_color; + else + win->battr = 0; + win->nextp = win; + win->ch_off = 0; + win->orig = NULL; + win->reqy = nlines; + win->reqx = ncols; + +#ifdef DEBUG + __CTRACE(__CTRACE_WINDOW, "newwin: win->ch_off = %d\n", win->ch_off); +#endif + + for (i = 0; i < maxy; i++) { + lp = win->alines[i]; + if (ispad) + lp->flags = __ISDIRTY; + else + lp->flags = 0; + for (sp = lp->line, j = 0; j < maxx; j++, sp++) { + sp->attr = 0; +#ifndef HAVE_WCHAR + sp->ch = win->bch; +#else + sp->ch = ( wchar_t )btowc(( int ) win->bch ); + sp->nsp = NULL; + SET_WCOL( *sp, 1 ); +#endif /* HAVE_WCHAR */ + } + lp->hash = __hash((char *)(void *)lp->line, + (size_t) (ncols * __LDATASIZE)); } - } - return(win); + return (win); } +WINDOW * +subwin(WINDOW *orig, int nlines, int ncols, int by, int bx) +{ -/****************************************************************/ -/* Subwin() creates a sub-window in the 'orig' window, with */ -/* Size num_lines * num_columns, and with origin begx, begy */ -/* Relative to the SCREEN. Special case: if num_lines and/or */ -/* Num_columns is 0, the remainder of the original window is */ -/* Used. The subwindow uses the original window's line buffers */ -/* To store it's own lines. */ -/****************************************************************/ -WINDOW *subwin(orig, num_lines, num_columns, begy, begx) -WINDOW *orig; -int num_lines, num_columns, begy, begx; + return __subwin(orig, nlines, ncols, by, bx, FALSE); +} + +static WINDOW * +__subwin(WINDOW *orig, int nlines, int ncols, int by, int bx, int ispad) +{ + int i; + __LINE *lp; + WINDOW *win; + int maxy, maxx; + +#ifdef DEBUG + __CTRACE(__CTRACE_WINDOW, "subwin: (%p, %d, %d, %d, %d, %d)\n", + orig, nlines, ncols, by, bx, ispad); +#endif + if (orig == NULL || orig->orig != NULL) + return NULL; + + /* Make sure window fits inside the original one. */ + maxy = nlines > 0 ? nlines : orig->maxy + orig->begy - by + nlines; + maxx = ncols > 0 ? ncols : orig->maxx + orig->begx - bx + ncols; + if (by < orig->begy || bx < orig->begx + || by + maxy > orig->maxy + orig->begy + || bx + maxx > orig->maxx + orig->begx) + return (NULL); + if ((win = __makenew(_cursesi_screen, maxy, maxx, + by, bx, 1, ispad)) == NULL) + return (NULL); + win->bch = orig->bch; + win->battr = orig->battr; + win->reqy = nlines; + win->reqx = ncols; + win->nextp = orig->nextp; + orig->nextp = win; + win->orig = orig; + + /* Initialize flags here so that refresh can also use __set_subwin. */ + for (lp = win->lspace, i = 0; i < win->maxy; i++, lp++) + lp->flags = 0; + __set_subwin(orig, win); + return (win); +} +/* + * This code is shared with mvwin(). + */ +void +__set_subwin(WINDOW *orig, WINDOW *win) +{ + int i; + __LINE *lp, *olp; +#ifdef HAVE_WCHAR + __LDATA *cp; + int j; + nschar_t *np; +#endif /* HAVE_WCHAR */ + + win->ch_off = win->begx - orig->begx; + /* Point line pointers to line space. */ + for (lp = win->lspace, i = 0; i < win->maxy; i++, lp++) { + win->alines[i] = lp; + olp = orig->alines[i + win->begy - orig->begy]; +#ifdef DEBUG + lp->sentinel = SENTINEL_VALUE; +#endif + lp->line = &olp->line[win->ch_off]; + lp->firstchp = &olp->firstch; + lp->lastchp = &olp->lastch; +#ifndef HAVE_WCHAR + lp->hash = __hash((char *)(void *)lp->line, + (size_t) (win->maxx * __LDATASIZE)); +#else + for ( cp = lp->line, j = 0; j < win->maxx; j++, cp++ ) { + lp->hash = __hash_more( &cp->ch, + sizeof( wchar_t ), lp->hash ); + lp->hash = __hash_more( &cp->attr, + sizeof( wchar_t ), lp->hash ); + if ( cp->nsp ) { + np = cp->nsp; + while ( np ) { + lp->hash = __hash_more( &np->ch, + sizeof( wchar_t ), lp->hash ); + np = np->next; + } + } + } +#endif /* HAVE_WCHAR */ + } + +#ifdef DEBUG + __CTRACE(__CTRACE_WINDOW, "__set_subwin: win->ch_off = %d\n", + win->ch_off); +#endif +} +/* + * __makenew -- + * Set up a window buffer and returns a pointer to it. + */ +static WINDOW * +__makenew(SCREEN *screen, int nlines, int ncols, int by, int bx, int sub, + int ispad) +{ + WINDOW *win; + __LINE *lp; + struct __winlist *wlp, *wlp2; + int i; + + +#ifdef DEBUG + __CTRACE(__CTRACE_WINDOW, "makenew: (%d, %d, %d, %d)\n", + nlines, ncols, by, bx); +#endif + if (nlines <= 0 || ncols <= 0) + return NULL; + + if ((win = malloc(sizeof(WINDOW))) == NULL) + return (NULL); +#ifdef DEBUG + __CTRACE(__CTRACE_WINDOW, "makenew: win = %p\n", win); +#endif + + /* Set up line pointer array and line space. */ + if ((win->alines = malloc(nlines * sizeof(__LINE *))) == NULL) { + free(win); + return NULL; + } + if ((win->lspace = malloc(nlines * sizeof(__LINE))) == NULL) { + free(win->alines); + free(win); + return NULL; + } + /* Don't allocate window and line space if it's a subwindow */ + if (sub) + win->wspace = NULL; + else { + /* + * Allocate window space in one chunk. + */ + if ((win->wspace = + malloc(ncols * nlines * sizeof(__LDATA))) == NULL) { + free(win->lspace); + free(win->alines); + free(win); + return NULL; + } + /* + * Append window to window list. + */ + if ((wlp = malloc(sizeof(struct __winlist))) == NULL) { + free(win->wspace); + free(win->lspace); + free(win->alines); + free(win); + return NULL; + } + wlp->winp = win; + wlp->nextp = NULL; + if (screen->winlistp == NULL) + screen->winlistp = wlp; + else { + wlp2 = screen->winlistp; + while (wlp2->nextp != NULL) + wlp2 = wlp2->nextp; + wlp2->nextp = wlp; + } + /* + * Point line pointers to line space, and lines themselves into + * window space. + */ + for (lp = win->lspace, i = 0; i < nlines; i++, lp++) { + win->alines[i] = lp; + lp->line = &win->wspace[i * ncols]; +#ifdef DEBUG + lp->sentinel = SENTINEL_VALUE; +#endif + lp->firstchp = &lp->firstch; + lp->lastchp = &lp->lastch; + if (ispad) { + lp->firstch = 0; + lp->lastch = ncols; + } else { + lp->firstch = ncols; + lp->lastch = 0; + } + } + } +#ifdef DEBUG + __CTRACE(__CTRACE_WINDOW, "makenew: ncols = %d\n", ncols); +#endif + win->screen = screen; + win->cury = win->curx = 0; + win->maxy = nlines; + win->maxx = ncols; + win->reqy = nlines; + win->reqx = ncols; + + win->begy = by; + win->begx = bx; + win->flags = (__IDLINE | __IDCHAR); + win->delay = -1; + win->wattr = 0; +#ifdef HAVE_WCHAR + win->bnsp = NULL; + SET_BGWCOL( *win, 1 ); +#endif /* HAVE_WCHAR */ + win->scr_t = 0; + win->scr_b = win->maxy - 1; + if (ispad) { + win->flags |= __ISPAD; + win->pbegy = 0; + win->pbegx = 0; + win->sbegy = 0; + win->sbegx = 0; + win->smaxy = 0; + win->smaxx = 0; + } else + __swflags(win); +#ifdef DEBUG + __CTRACE(__CTRACE_WINDOW, "makenew: win->wattr = %08x\n", win->wattr); + __CTRACE(__CTRACE_WINDOW, "makenew: win->flags = %#.4x\n", win->flags); + __CTRACE(__CTRACE_WINDOW, "makenew: win->maxy = %d\n", win->maxy); + __CTRACE(__CTRACE_WINDOW, "makenew: win->maxx = %d\n", win->maxx); + __CTRACE(__CTRACE_WINDOW, "makenew: win->begy = %d\n", win->begy); + __CTRACE(__CTRACE_WINDOW, "makenew: win->begx = %d\n", win->begx); + __CTRACE(__CTRACE_WINDOW, "makenew: win->scr_t = %d\n", win->scr_t); + __CTRACE(__CTRACE_WINDOW, "makenew: win->scr_b = %d\n", win->scr_b); +#endif + return (win); +} + +void +__swflags(WINDOW *win) { - WINDOW *win; - int i, j, k; - - /* Make sure window fits inside the original one */ - if (begy < orig->_begy || begx < orig->_begx || - (begy + num_lines) > (orig->_begy + orig->_maxy) || - (begx + num_columns) > (orig->_begx + orig->_maxx) ) - return((WINDOW *) ERR); - - if (num_lines == 0) num_lines = orig->_maxy - (begy - orig->_begy); - if (num_columns == 0) num_columns = orig->_maxx - (begx - orig->_begx); - if ((win = makenew(num_lines, num_columns, begy, begx)) == (WINDOW *) ERR) - return((WINDOW *) ERR); - - /* Set line pointers the same as in the original window */ - j = begy - orig->_begy; - k = begx - orig->_begx; - for (i = 0; i < num_lines; i++) win->_line[i] = (orig->_line[j++]) + k; - win->_flags |= _SUBWIN; - return(win); + win->flags &= ~(__ENDLINE | __FULLWIN | __SCROLLWIN | __LEAVEOK); + if (win->begx + win->maxx == COLS && !(win->flags & __ISPAD)) { + win->flags |= __ENDLINE; + if (win->begx == 0 && win->maxy == LINES && win->begy == 0) + win->flags |= __FULLWIN; + if (win->begy + win->maxy == LINES) + win->flags |= __SCROLLWIN; + } } diff --git a/lib/libcurses/nodelay.c b/lib/libcurses/nodelay.c new file mode 100644 index 000000000..12748a505 --- /dev/null +++ b/lib/libcurses/nodelay.c @@ -0,0 +1,50 @@ +/* $NetBSD: nodelay.c,v 1.6 2003/12/04 21:24:36 jdc Exp $ */ + +/*- + * Copyright (c) 1998-1999 Brett Lymn (blymn@baea.com.au, brett_lymn@yahoo.com) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + */ + +#include +#ifndef lint +__RCSID("$NetBSD: nodelay.c,v 1.6 2003/12/04 21:24:36 jdc Exp $"); +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +/* + * nodelay -- + * Turn on and off blocking reads in getch for a + * given window. + */ +int +nodelay(WINDOW *win, bool bf) +{ + if (bf) + win->delay = 0; + else + win->delay = -1; + return(OK); +} diff --git a/lib/libcurses/notimeout.c b/lib/libcurses/notimeout.c new file mode 100644 index 000000000..9e20f5706 --- /dev/null +++ b/lib/libcurses/notimeout.c @@ -0,0 +1,51 @@ +/* $NetBSD: notimeout.c,v 1.5 2001/06/13 10:45:58 wiz Exp $ */ + +/*- + * Copyright (c) 1998-1999 Brett Lymn (blymn@baea.com.au, brett_lymn@yahoo.com) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + */ + +#include +#ifndef lint +__RCSID("$NetBSD: notimeout.c,v 1.5 2001/06/13 10:45:58 wiz Exp $"); +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +/* + * notimeout -- + * Turn on and off inter-key timeout when assembling function keys for a + * given window. + */ +int +notimeout(WINDOW *win, bool bf) +{ + if (bf) + win->flags &= ~__NOTIMEOUT; + else + win->flags |= __NOTIMEOUT; + + return OK; +} diff --git a/lib/libcurses/options.c b/lib/libcurses/options.c deleted file mode 100644 index 2ab0ac3c4..000000000 --- a/lib/libcurses/options.c +++ /dev/null @@ -1,84 +0,0 @@ -#include -#include "curspriv.h" - -/****************************************************************/ -/* Idlok() is used to set flag for using the terminal insert/ */ -/* Delete line capabilities. This is not relevant for the PC */ -/* Version of curses, and thus nothing is done. */ -/****************************************************************/ -void idlok(win, flag) -WINDOW *win; -bool flag; -{ -} - -/****************************************************************/ -/* Clearok() marks window 'win' to cause screen clearing and */ -/* Redraw the next time a refresh is done. */ -/****************************************************************/ -void clearok(win, flag) -WINDOW *win; -bool flag; -{ - if (win == curscr) - _cursvar.tmpwin->_clear = flag; - else - win->_clear = flag; -} - -/****************************************************************/ -/* Leaveok() marks window 'win' to allow the update routines */ -/* To leave the hardware cursor where it happens to be at the */ -/* End of update. Usually used in combination with cursoff(). */ -/****************************************************************/ - -void leaveok(win, flag) -WINDOW *win; -bool flag; -{ - win->_leave = flag; -} - -/****************************************************************/ -/* Scrollok() marks window 'win' to allow the scrolling region */ -/* Of it to actually scroll. */ -/****************************************************************/ -void scrollok(win, flag) -WINDOW *win; -bool flag; -{ - win->_scroll = flag; -} - -/****************************************************************/ -/* Nodelay() marks the window to make character input non- */ -/* Waiting, i.e. if there is no character to get, -1 will be */ -/* Returned. */ -/****************************************************************/ -void nodelay(win, flag) -WINDOW *win; -bool flag; -{ - win->_nodelay = flag; -} - -/****************************************************************/ -/* Keypad() marks window 'win' to use the special keypad mode. */ -/****************************************************************/ -void keypad(win, flag) -WINDOW *win; -bool flag; -{ - win->_keypad = flag; -} - -/****************************************************************/ -/* Meta() allows use of any alternate character set allowed by */ -/* The terminal. We always allow this on the PC, so this one */ -/* Does nothing. */ -/****************************************************************/ -void meta(win, flag) -WINDOW *win; -bool flag; -{ -} diff --git a/lib/libcurses/overlay.c b/lib/libcurses/overlay.c index c62b5ad97..75f5cb39b 100644 --- a/lib/libcurses/overlay.c +++ b/lib/libcurses/overlay.c @@ -1,124 +1,60 @@ -/****************************************************************/ -/* Overlay() and overwrite() functions of the PCcurses package */ -/* */ -/****************************************************************/ -/* This version of curses is based on ncurses, a curses version */ -/* Originally written by Pavel Curtis at Cornell University. */ -/* I have made substantial changes to make it run on IBM PC's, */ -/* And therefore consider myself free to make it public domain. */ -/* Bjorn Larsson (...mcvax!enea!infovax!bl) */ -/****************************************************************/ -/* 1.0: Release: 870515 */ -/****************************************************************/ -/* Modified to run under the MINIX operating system by Don Cope */ -/* These changes are also released into the public domain. */ -/* 900906 */ -/****************************************************************/ - -#include -#include "curspriv.h" - -/****************************************************************/ -/* Overlay() overwrites 'win1' upon 'win2', with origins alig- */ -/* Ned. Overlay is transparent; blanks from 'win1' are not */ -/* Copied to 'win2'. */ -/****************************************************************/ -void overlay(win1, win2) -WINDOW *win1, *win2; -{ - int *minchng; - int *maxchng; - int *w1ptr; - int *w2ptr; - int attrs; - int col; - int line; - int last_line; - int last_col; - - last_col = min(win1->_maxx, win2->_maxx); - last_line = min(win1->_maxy, win2->_maxy); - attrs = win2->_attrs & ATR_MSK; - minchng = win2->_minchng; - maxchng = win2->_maxchng; - - for (line = 0; line <= last_line; line++) { - register short fc, lc = 0; - w1ptr = win1->_line[line]; - w2ptr = win2->_line[line]; - fc = _NO_CHANGE; - for (col = 0; col <= last_col; col++) { - if ((*w1ptr & CHR_MSK) != ' ') { - *w2ptr = (*w1ptr & CHR_MSK) | attrs; - if (fc == _NO_CHANGE) fc = col; - lc = col; - } - 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++; - } /* for */ -} /* overlay */ - -/****************************************************************/ -/* Overwrite() overwrites 'win1' upon 'win2', with origins */ -/* Aligned. Overwrite is non-transparent; blanks from 'win1' */ -/* Are copied to 'win2'. */ -/****************************************************************/ -void overwrite(win1, win2) -WINDOW *win1, *win2; +/* $NetBSD: overlay.c,v 1.17 2007/01/21 13:25:36 jdc Exp $ */ + +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)overlay.c 8.2 (Berkeley) 5/4/94"; +#else +__RCSID("$NetBSD: overlay.c,v 1.17 2007/01/21 13:25:36 jdc Exp $"); +#endif +#endif /* not lint */ + +#include + +#include "curses.h" +#include "curses_private.h" + +/* + * overlay -- + * Writes win1 on win2 non-destructively. + */ +int +overlay(const WINDOW *win1, WINDOW *win2) { - int *minchng; - int *maxchng; - int *w1ptr; - int *w2ptr; - int attrs; - int col; - int line; - int last_line; - int last_col; - - last_col = min(win1->_maxx, win2->_maxx); - last_line = min(win1->_maxy, win2->_maxy); - attrs = win2->_attrs & ATR_MSK; - minchng = win2->_minchng; - maxchng = win2->_maxchng; - - for (line = 0; line <= last_line; line++) { - register short fc, lc = 0; - - w1ptr = win1->_line[line]; - w2ptr = win2->_line[line]; - fc = _NO_CHANGE; - - for (col = 0; col <= last_col; col++) { - if ((*w1ptr & CHR_MSK) != (*w2ptr & CHR_MSK)) { - *w2ptr = (*w1ptr & CHR_MSK) | attrs; - - if (fc == _NO_CHANGE) fc = col; - lc = col; - } - w1ptr++; - w2ptr++; - } /* for */ - 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++; - } +#ifdef DEBUG + __CTRACE(__CTRACE_WINDOW, "overlay: (%p, %p);\n", win1, win2); +#endif + return copywin(win1, win2, + win2->begy - win1->begy, win2->begx - win1->begx, + 0, 0, win2->maxy - 1, win2->maxx - 1, TRUE); } diff --git a/lib/libcurses/overwrite.c b/lib/libcurses/overwrite.c new file mode 100644 index 000000000..5900b808b --- /dev/null +++ b/lib/libcurses/overwrite.c @@ -0,0 +1,60 @@ +/* $NetBSD: overwrite.c,v 1.18 2007/01/21 13:25:36 jdc Exp $ */ + +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)overwrite.c 8.2 (Berkeley) 5/4/94"; +#else +__RCSID("$NetBSD: overwrite.c,v 1.18 2007/01/21 13:25:36 jdc Exp $"); +#endif +#endif /* not lint */ + +#include +#include + +#include "curses.h" +#include "curses_private.h" + +/* + * overwrite -- + * Writes win1 on win2 destructively. + */ +int +overwrite(const WINDOW *win1, WINDOW *win2) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_WINDOW, "overwrite: (%p, %p);\n", win1, win2); +#endif + return copywin(win1, win2, + win2->begy - win1->begy, win2->begx - win1->begx, + 0, 0, win2->maxy - 1, win2->maxx - 1, FALSE); +} diff --git a/lib/libcurses/pause.c b/lib/libcurses/pause.c new file mode 100644 index 000000000..ab2cee6b0 --- /dev/null +++ b/lib/libcurses/pause.c @@ -0,0 +1,82 @@ +/* $NetBSD: pause.c,v 1.9 2009/07/22 16:57:15 roy Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Julian Coleman. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: pause.c,v 1.9 2009/07/22 16:57:15 roy Exp $"); +#endif /* not lint */ + +#include +#include +#include + +#include "curses.h" +#include "curses_private.h" + +/* + * napms -- + * Sleep for ms milliseconds. + */ +int +napms(int ms) +{ + struct timespec ts; + +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "napms: %d\n", ms); +#endif + ts.tv_sec = ms / 1000; + ts.tv_nsec = (ms % 1000) * 1000000; + (void) nanosleep(&ts, NULL); + return(OK); +} + +/* + * delay_output -- + * Pause output using terminal pad character. + */ +int +delay_output(int ms) +{ + char *delstr; + +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "delay_output: %d\n", ms); +#endif + if (!_cursesi_screen->padchar) + return(napms(ms)); + + if (asprintf(&delstr, "%d", ms) == -1) + return (ERR); + tputs (delstr, 0, __cputchar); + free(delstr); + return (OK); +} diff --git a/lib/libcurses/printw.c b/lib/libcurses/printw.c new file mode 100644 index 000000000..625a7a4f3 --- /dev/null +++ b/lib/libcurses/printw.c @@ -0,0 +1,152 @@ +/* $NetBSD: printw.c,v 1.21 2009/07/07 10:16:52 joerg Exp $ */ + +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)printw.c 8.3 (Berkeley) 5/4/94"; +#else +__RCSID("$NetBSD: printw.c,v 1.21 2009/07/07 10:16:52 joerg Exp $"); +#endif +#endif /* not lint */ + +#include + +#include "curses.h" +#include "curses_private.h" + +/* + * printw and friends. + */ + +static int __winwrite __P((void *, const char *, int)); + +/* + * printw -- + * Printf on the standard screen. + */ +int +printw(const char *fmt,...) +{ + va_list ap; + int ret; + + va_start(ap, fmt); + ret = vw_printw(stdscr, fmt, ap); + va_end(ap); + return (ret); +} +/* + * wprintw -- + * Printf on the given window. + */ +int +wprintw(WINDOW *win, const char *fmt,...) +{ + va_list ap; + int ret; + + va_start(ap, fmt); + ret = vw_printw(win, fmt, ap); + va_end(ap); + return (ret); +} +/* + * mvprintw, mvwprintw -- + * Implement the mvprintw commands. Due to the variable number of + * arguments, they cannot be macros. Sigh.... + */ +int +mvprintw(int y, int x, const char *fmt,...) +{ + va_list ap; + int ret; + + if (move(y, x) != OK) + return (ERR); + va_start(ap, fmt); + ret = vw_printw(stdscr, fmt, ap); + va_end(ap); + return (ret); +} + +int +mvwprintw(WINDOW * win, int y, int x, const char *fmt,...) +{ + va_list ap; + int ret; + + if (wmove(win, y, x) != OK) + return (ERR); + + va_start(ap, fmt); + ret = vw_printw(win, fmt, ap); + va_end(ap); + return (ret); +} +/* + * Internal write-buffer-to-window function. + */ +static int +__winwrite(cookie, buf, n) + void *cookie; + const char *buf; + int n; +{ + WINDOW *win; + int c; + + for (c = n, win = cookie; --c >= 0;) + { +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "__winwrite: %c\n", *buf); +#endif + if (waddch(win, (chtype) (*buf++ & __CHARTEXT)) == ERR) + return (-1); + } + return (n); +} +/* + * vw_printw -- + * This routine actually executes the printf and adds it to the window. + */ +int +vw_printw(WINDOW *win, const char *fmt, _BSD_VA_LIST_ ap) +{ + FILE *f; + + if ((f = funopen(win, NULL, __winwrite, NULL, NULL)) == NULL) + return (ERR); + (void) vfprintf(f, fmt, ap); + return (fclose(f) ? ERR : OK); +} + +__strong_alias(vwprintw, vw_printw) diff --git a/lib/libcurses/prntscan.c b/lib/libcurses/prntscan.c deleted file mode 100644 index 80257f1b8..000000000 --- a/lib/libcurses/prntscan.c +++ /dev/null @@ -1,129 +0,0 @@ -#include -#include -#include "curspriv.h" - -static char printscanbuf[513]; /* buffer used during I/O */ - -/****************************************************************/ -/* Wprintw(win,fmt,args) does a printf() in window 'win'. */ -/****************************************************************/ -int wprintw(WINDOW *win, const char *fmt, ...) -{ - va_list args; - - va_start(args, fmt); - vsprintf(printscanbuf, fmt, args); - if (waddstr(win, printscanbuf) == ERR) return(ERR); - return(strlen(printscanbuf)); -} - -/****************************************************************/ -/* Printw(fmt,args) does a printf() in stdscr. */ -/****************************************************************/ -int printw(const char *fmt, ...) -{ - va_list args; - - va_start(args, fmt); - vsprintf(printscanbuf, fmt, args); - if (waddstr(stdscr, printscanbuf) == ERR) return(ERR); - return(strlen(printscanbuf)); -} /* printw */ - -/****************************************************************/ -/* Mvprintw(fmt,args) moves the stdscr cursor to a new posi- */ -/* tion, then does a printf() in stdscr. */ -/****************************************************************/ -int mvprintw(int y, int x, const char *fmt, ...) -{ - va_list args; - - va_start(args, fmt); - if (wmove(stdscr, y, x) == ERR) return(ERR); - vsprintf(printscanbuf, fmt, args); - if (waddstr(stdscr, printscanbuf) == ERR) return(ERR); - return(strlen(printscanbuf)); -} - -/****************************************************************/ -/* Mvwprintw(win,fmt,args) moves the window 'win's cursor to */ -/* A new position, then does a printf() in window 'win'. */ -/****************************************************************/ -int mvwprintw(WINDOW *win, int y, int x, const char *fmt, ...) -{ - va_list args; - - va_start(args, fmt); - if (wmove(win, y, x) == ERR) return(ERR); - vsprintf(printscanbuf, fmt, args); - if (waddstr(win, printscanbuf) == ERR) return(ERR); - return(strlen(printscanbuf)); -} /* mvwprintw */ - -/****************************************************************/ -/* Wscanw(win,fmt,args) gets a string via window 'win', then */ -/* Scans the string using format 'fmt' to extract the values */ -/* And put them in the variables pointed to the arguments. */ -/****************************************************************/ -int wscanw(WINDOW *win, const char *fmt, ...) -{ - va_list args; - - va_start(args, fmt); - wrefresh(win); /* set cursor */ - if (wgetstr(win, printscanbuf) == ERR) /* get string */ - return(ERR); - return(vsscanf(printscanbuf, fmt, args)); -} /* wscanw */ - -/****************************************************************/ -/* Scanw(fmt,args) gets a string via stdscr, then scans the */ -/* String using format 'fmt' to extract the values and put them */ -/* In the variables pointed to the arguments. */ -/****************************************************************/ -int scanw(const char *fmt, ...) -{ - va_list args; - - va_start(args, fmt); - wrefresh(stdscr); /* set cursor */ - if (wgetstr(stdscr, printscanbuf) == ERR) /* get string */ - return(ERR); - return(vsscanf(printscanbuf, fmt, args)); -} /* scanw */ - -/****************************************************************/ -/* Mvscanw(y,x,fmt,args) moves stdscr's cursor to a new posi- */ -/* Tion, then gets a string via stdscr and scans the string */ -/* Using format 'fmt' to extract the values and put them in the */ -/* Variables pointed to the arguments. */ -/****************************************************************/ -int mvscanw(int y, int x, const char *fmt, ...) -{ - va_list args; - - va_start(args, fmt); - if (wmove(stdscr, y, x) == ERR) return(ERR); - wrefresh(stdscr); /* set cursor */ - if (wgetstr(stdscr, printscanbuf) == ERR) /* get string */ - return(ERR); - return(vsscanf(printscanbuf, fmt, args)); -} /* mvscanw */ - -/****************************************************************/ -/* Mvwscanw(win,y,x,fmt,args) moves window 'win's cursor to a */ -/* New position, then gets a string via 'win' and scans the */ -/* String using format 'fmt' to extract the values and put them */ -/* In the variables pointed to the arguments. */ -/****************************************************************/ -int mvwscanw(WINDOW *win, int y, int x, const char *fmt, ...) -{ - va_list args; - - va_start(args, fmt); - if (wmove(win, y, x) == ERR) return(ERR); - wrefresh(win); /* set cursor */ - if (wgetstr(win, printscanbuf) == ERR) /* get string */ - return(ERR); - return(vsscanf(printscanbuf, fmt, args)); -} /* mvwscanw */ diff --git a/lib/libcurses/putchar.c b/lib/libcurses/putchar.c new file mode 100644 index 000000000..f3c8243b1 --- /dev/null +++ b/lib/libcurses/putchar.c @@ -0,0 +1,97 @@ +/* $NetBSD: putchar.c,v 1.21 2010/02/03 15:34:40 roy Exp $ */ + +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)putchar.c 8.2 (Berkeley) 5/4/94"; +#else +__RCSID("$NetBSD: putchar.c,v 1.21 2010/02/03 15:34:40 roy Exp $"); +#endif +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +int +__cputchar(int ch) +{ + +#ifdef DEBUG + __CTRACE(__CTRACE_OUTPUT, "__cputchar: %s\n", unctrl(ch)); +#endif + return (putc(ch, _cursesi_screen->outfd)); +} + +/* + * This is the same as __cputchar but the extra argument holds the file + * descriptor to write the output to. This function can only be used with + * the "new" libterm interface. + */ +int +__cputchar_args(int ch, void *args) +{ + FILE *outfd = (FILE *) args; + +#ifdef DEBUG + __CTRACE(__CTRACE_OUTPUT, "__cputchar_args: %s on fd %d\n", + unctrl(ch), outfd->_file); +#endif + return putc(ch, outfd); +} + +#ifdef HAVE_WCHAR +int +__cputwchar(wchar_t wch) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_OUTPUT, "__cputwchar: 0x%x\n", wch); +#endif + return (putwc(wch, _cursesi_screen->outfd)); +} + +/* + * This is the same as __cputchar but the extra argument holds the file + * descriptor to write the output to. This function can only be used with + * the "new" libterm interface. + */ +int +__cputwchar_args(wchar_t wch, void *args) +{ + FILE *outfd = (FILE *) args; + +#ifdef DEBUG + __CTRACE(__CTRACE_OUTPUT, "__cputwchar_args: 0x%x on fd %d\n", + wch, outfd->_file); +#endif + return putwc(wch, outfd); +} +#endif /* HAVE_WCHAR */ diff --git a/lib/libcurses/refresh.c b/lib/libcurses/refresh.c index a16a1b93d..5264bd3bd 100644 --- a/lib/libcurses/refresh.c +++ b/lib/libcurses/refresh.c @@ -1,72 +1,1825 @@ -/* refresh.c */ +/* $NetBSD: refresh.c,v 1.73 2010/02/08 20:45:22 roy Exp $ */ -#include -#include "curspriv.h" +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ -/* Wrefresh() updates window win's area of the physical screen. */ -void wrefresh(win) -WINDOW *win; +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)refresh.c 8.7 (Berkeley) 8/13/94"; +#else +__RCSID("$NetBSD: refresh.c,v 1.73 2010/02/08 20:45:22 roy Exp $"); +#endif +#endif /* not lint */ + +#include +#include + +#include "curses.h" +#include "curses_private.h" + +static void domvcur(int, int, int, int); +static int makech(int); +static void quickch(void); +static void scrolln(int, int, int, int, int); + +static int _cursesi_wnoutrefresh(SCREEN *, WINDOW *, + int, int, int, int, int, int); + +#ifdef HAVE_WCHAR +int cellcmp( __LDATA *, __LDATA * ); +int linecmp( __LDATA *, __LDATA *, size_t ); +#endif /* HAVE_WCHAR */ + +#ifndef _CURSES_USE_MACROS + +/* + * refresh -- + * Make the current screen look like "stdscr" over the area covered by + * stdscr. + */ +int +refresh(void) { - if (win == curscr) - curscr->_clear = TRUE; - else - wnoutrefresh(win); - doupdate(); + return wrefresh(stdscr); } -/****************************************************************/ -/* Wnoutrefresh() updates the image of the desired screen, */ -/* Without doing physical update (copies window win's image to */ -/* The _cursvar.tmpwin window, which is hidden from the user). */ -/****************************************************************/ +#endif + +/* + * wnoutrefresh -- + * Add the contents of "win" to the virtual window. + */ +int +wnoutrefresh(WINDOW *win) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, "wnoutrefresh: win %p\n", win); +#endif + + return _cursesi_wnoutrefresh(_cursesi_screen, win, 0, 0, win->begy, + win->begx, win->maxy, win->maxx); +} -void wnoutrefresh(win) -register WINDOW *win; +/* + * pnoutrefresh -- + * Add the contents of "pad" to the virtual window. + */ +int +pnoutrefresh(WINDOW *pad, int pbegy, int pbegx, int sbegy, int sbegx, + int smaxy, int smaxx) { - register int *dst; /* start destination in temp window */ - register int *end; /* end destination in temp window */ - register int *src; /* source in user window */ - register int first; /* first changed char on line */ - register int last; /* last changed char on line */ - WINDOW *nscr; - int begy; /* window's place on screen */ - int begx; - int i; - int j; - - nscr = _cursvar.tmpwin; - begy = win->_begy; - begx = win->_begx; - - for (i = 0, j = begy; i <= win->_maxy; i++, j++) { - if (win->_minchng[i] != _NO_CHANGE) { - first = win->_minchng[i]; - last = win->_maxchng[i]; - dst = &(nscr->_line[j][begx + first]); - end = &(nscr->_line[j][begx + last]); - src = &(win->_line[i][first]); - - while (dst <= end) /* copy user line to temp window */ - *dst++ = *src++; - - first += begx; /* nscr's min/max change positions */ - last += begx; - - if ((nscr->_minchng[j] == _NO_CHANGE) || (nscr->_minchng[j] > first)) - nscr->_minchng[j] = first; - if (last > nscr->_maxchng[j]) nscr->_maxchng[j] = last; - - win->_minchng[i] = _NO_CHANGE; /* updated now */ - } /* if */ - win->_maxchng[i] = _NO_CHANGE; /* updated now */ - } /* for */ - - if (win->_clear) { - win->_clear = FALSE; - nscr->_clear = TRUE; - } /* if */ - if (!win->_leave) { - nscr->_cury = win->_cury + begy; - nscr->_curx = win->_curx + begx; - } /* if */ -} /* wnoutrefresh */ + int pmaxy, pmaxx; + +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, "pnoutrefresh: pad %p, flags 0x%08x\n", + pad, pad->flags); + __CTRACE(__CTRACE_REFRESH, + "pnoutrefresh: (%d, %d), (%d, %d), (%d, %d)\n", + pbegy, pbegx, sbegy, sbegx, smaxy, smaxx); +#endif + + /* SUS says if these are negative, they should be treated as zero */ + if (pbegy < 0) + pbegy = 0; + if (pbegx < 0) + pbegx = 0; + if (sbegy < 0) + sbegy = 0; + if (sbegx < 0) + sbegx = 0; + + /* Calculate rectangle on pad - used by _cursesi_wnoutrefresh */ + pmaxy = pbegy + smaxy - sbegy + 1; + pmaxx = pbegx + smaxx - sbegx + 1; + + /* Check rectangle fits in pad */ + if (pmaxy > pad->maxy - pad->begy) + pmaxy = pad->maxy - pad->begy; + if (pmaxx > pad->maxx - pad->begx) + pmaxx = pad->maxx - pad->begx; + + if (smaxy - sbegy < 0 || smaxx - sbegx < 0 ) + return ERR; + + return _cursesi_wnoutrefresh(_cursesi_screen, pad, + pad->begy + pbegy, pad->begx + pbegx, pad->begy + sbegy, + pad->begx + sbegx, pmaxy, pmaxx); +} + +/* + * _cursesi_wnoutrefresh -- + * Does the grunt work for wnoutrefresh to the given screen. + * Copies the part of the window given by the rectangle + * (begy, begx) to (maxy, maxx) at screen position (wbegy, wbegx). + */ +int +_cursesi_wnoutrefresh(SCREEN *screen, WINDOW *win, int begy, int begx, + int wbegy, int wbegx, int maxy, int maxx) +{ + + short sy, wy, wx, y_off, x_off, mx; + __LINE *wlp, *vlp; + WINDOW *sub_win, *orig; + +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, "_wnoutrefresh: win %p, flags 0x%08x\n", + win, win->flags); + __CTRACE(__CTRACE_REFRESH, + "_wnoutrefresh: (%d, %d), (%d, %d), (%d, %d)\n", + begy, begx, wbegy, wbegx, maxy, maxx); +#endif + + if (screen->curwin) + return OK; + + /* + * Recurse through any sub-windows, mark as dirty lines on the parent + * window that are dirty on the sub-window and clear the dirty flag on + * the sub-window. + */ + if (win->orig == 0) { + orig = win; + for (sub_win = win->nextp; sub_win != win; + sub_win = sub_win->nextp) { +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, + "wnout_refresh: win %p, sub_win %p\n", + orig, sub_win); +#endif + for (sy = 0; sy < sub_win->maxy; sy++) { + if (sub_win->alines[sy]->flags == __ISDIRTY) { + orig->alines[sy + sub_win->begy - orig->begy]->flags + |= __ISDIRTY; + sub_win->alines[sy]->flags + &= ~__ISDIRTY; + } + } + } + } + + /* Check that cursor position on "win" is valid for "__virtscr" */ + if (win->cury + wbegy - begy < screen->__virtscr->maxy && + win->cury + wbegy - begy >= 0 && win->cury < maxy - begy) + screen->__virtscr->cury = win->cury + wbegy - begy; + if (win->curx + wbegx - begx < screen->__virtscr->maxx && + win->curx + wbegx - begx >= 0 && win->curx < maxx - begx) + screen->__virtscr->curx = win->curx + wbegx - begx; + + /* Copy the window flags from "win" to "__virtscr" */ + if (win->flags & __CLEAROK) { + if (win->flags & __FULLWIN) + screen->__virtscr->flags |= __CLEAROK; + win->flags &= ~__CLEAROK; + } + screen->__virtscr->flags &= ~__LEAVEOK; + screen->__virtscr->flags |= win->flags; + + for (wy = begy, y_off = wbegy; wy < maxy && + y_off < screen->__virtscr->maxy; wy++, y_off++) { + wlp = win->alines[wy]; +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, + "_wnoutrefresh: wy %d\tf %d\tl %d\tflags %x\n", + wy, *wlp->firstchp, *wlp->lastchp, wlp->flags); +#endif + if ((wlp->flags & __ISDIRTY) == 0) + continue; + vlp = screen->__virtscr->alines[y_off]; + + if (*wlp->firstchp < maxx + win->ch_off && + *wlp->lastchp >= win->ch_off) { + /* Set start column */ + wx = begx; + x_off = wbegx; + if (*wlp->firstchp - win->ch_off > 0) { + wx += *wlp->firstchp - win->ch_off; + x_off += *wlp->firstchp - win->ch_off; + } + /* Set finish column */ + mx = maxx; + if (mx > *wlp->lastchp - win->ch_off + 1) + mx = *wlp->lastchp - win->ch_off + 1; + if (x_off + (mx - wx) > __virtscr->maxx) + mx -= (x_off + maxx) - __virtscr->maxx; + /* Copy line from "win" to "__virtscr". */ + while (wx < mx) { +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, + "_wnoutrefresh: copy from %d, " + "%d to %d, %d\n", + wy, wx, y_off, x_off); +#endif + /* Copy character */ + vlp->line[x_off].ch = wlp->line[wx].ch; + /* Copy attributes */ + vlp->line[x_off].attr = wlp->line[wx].attr; + /* Check for nca conflict with colour */ + if ((vlp->line[x_off].attr & __COLOR) && + (vlp->line[x_off].attr & + _cursesi_screen->nca)) + vlp->line[x_off].attr &= ~__COLOR; +#ifdef HAVE_WCHAR + if (wlp->line[wx].ch + == (wchar_t)btowc((int) win->bch)) { + vlp->line[x_off].ch = win->bch; + SET_WCOL( vlp->line[x_off], 1 ); + if (_cursesi_copy_nsp(win->bnsp, + &vlp->line[x_off]) + == ERR) + return ERR; + } +#endif /* HAVE_WCHAR */ + wx++; + x_off++; + } + + /* Set flags on "__virtscr" and unset on "win". */ + if (wlp->flags & __ISPASTEOL) + vlp->flags |= __ISPASTEOL; + else + vlp->flags &= ~__ISPASTEOL; + if (wlp->flags & __ISDIRTY) + vlp->flags |= __ISDIRTY; + +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, + "win: firstch = %d, lastch = %d\n", + *wlp->firstchp, *wlp->lastchp); +#endif + /* Set change pointers on "__virtscr". */ + if (*vlp->firstchp > + *wlp->firstchp + wbegx - win->ch_off) + *vlp->firstchp = + *wlp->firstchp + wbegx - win->ch_off; + if (*vlp->lastchp < + *wlp->lastchp + wbegx - win->ch_off) + *vlp->lastchp = + *wlp->lastchp + wbegx - win->ch_off; +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, + "__virtscr: firstch = %d, lastch = %d\n", + *vlp->firstchp, *vlp->lastchp); +#endif + /* + * Unset change pointers only if a window, as a pad + * can be displayed again without any of the contents + * changing. + */ + if (!(win->flags & __ISPAD)) { + /* Set change pointers on "win". */ + if (*wlp->firstchp >= win->ch_off) + *wlp->firstchp = maxx + win->ch_off; + if (*wlp->lastchp < maxx + win->ch_off) + *wlp->lastchp = win->ch_off; + if ((*wlp->lastchp < *wlp->firstchp) || + (*wlp->firstchp >= maxx + win->ch_off) || + (*wlp->lastchp <= win->ch_off)) { +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, + "_wnoutrefresh: " + "line %d notdirty\n", wy); +#endif + wlp->flags &= ~__ISDIRTY; + } + } + } + } + return OK; +} + +/* + * wrefresh -- + * Make the current screen look like "win" over the area covered by + * win. + */ +int +wrefresh(WINDOW *win) +{ + int retval; + +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, "wrefresh: win %p\n", win); +#endif + + _cursesi_screen->curwin = (win == _cursesi_screen->curscr); + if (!_cursesi_screen->curwin) + retval = _cursesi_wnoutrefresh(_cursesi_screen, win, 0, 0, + win->begy, win->begx, win->maxy, win->maxx); + else + retval = OK; + if (retval == OK) { + retval = doupdate(); + if (!(win->flags & __LEAVEOK)) { + win->cury = max(0, curscr->cury - win->begy); + win->curx = max(0, curscr->curx - win->begx); + } + } + _cursesi_screen->curwin = 0; + return(retval); +} + + /* + * prefresh -- + * Make the current screen look like "pad" over the area coverd by + * the specified area of pad. + */ +int +prefresh(WINDOW *pad, int pbegy, int pbegx, int sbegy, int sbegx, + int smaxy, int smaxx) +{ + int retval; + +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, "prefresh: pad %p, flags 0x%08x\n", + pad, pad->flags); +#endif + /* Retain values in case pechochar() is called. */ + pad->pbegy = pbegy; + pad->pbegx = pbegx; + pad->sbegy = sbegy; + pad->sbegx = sbegx; + pad->smaxy = smaxy; + pad->smaxx = smaxx; + + /* Use pnoutrefresh() to avoid duplicating code here */ + retval = pnoutrefresh(pad, pbegy, pbegx, sbegy, sbegx, smaxy, smaxx); + if (retval == OK) { + retval = doupdate(); + if (!(pad->flags & __LEAVEOK)) { + pad->cury = max(0, curscr->cury - pad->begy); + pad->curx = max(0, curscr->curx - pad->begx); + } + } + return(retval); +} + +/* + * doupdate -- + * Make the current screen look like the virtual window "__virtscr". + */ +int +doupdate(void) +{ + WINDOW *win; + __LINE *wlp; + short wy; + int dnum; +#ifdef HAVE_WCHAR + __LDATA *lp; + nschar_t *np; + int x; +#endif /* HAVE_WCHAR */ + + /* Check if we need to restart ... */ + if (_cursesi_screen->endwin) + __restartwin(); + + if (_cursesi_screen->curwin) + win = curscr; + else + win = _cursesi_screen->__virtscr; + + /* Initialize loop parameters. */ + _cursesi_screen->ly = curscr->cury; + _cursesi_screen->lx = curscr->curx; + wy = 0; + + if (!_cursesi_screen->curwin) { + for (wy = 0; wy < win->maxy; wy++) { + wlp = win->alines[wy]; + if (wlp->flags & __ISDIRTY) { +#ifndef HAVE_WCHAR + wlp->hash = __hash(wlp->line, + (size_t)(win->maxx * __LDATASIZE)); +#else + wlp->hash = 0; + for ( x = 0; x < win->maxx; x++ ) { + lp = &wlp->line[ x ]; + wlp->hash = __hash_more( &lp->ch, + sizeof( wchar_t ), wlp->hash ); + wlp->hash = __hash_more( &lp->attr, + sizeof( attr_t ), wlp->hash ); + np = lp->nsp; + if (np) { + while ( np ) { + wlp->hash + = __hash_more( + &np->ch, + sizeof(wchar_t), + wlp->hash ); + np = np->next; + } + } + } +#endif /* HAVE_WCHAR */ + } + } + } + + if ((win->flags & __CLEAROK) || (curscr->flags & __CLEAROK) || + _cursesi_screen->curwin) { + if (curscr->wattr & __COLOR) + __unsetattr(0); + tputs(clear_screen, 0, __cputchar); + _cursesi_screen->ly = 0; + _cursesi_screen->lx = 0; + if (!_cursesi_screen->curwin) { + curscr->flags &= ~__CLEAROK; + curscr->cury = 0; + curscr->curx = 0; + werase(curscr); + } + __touchwin(win); + win->flags &= ~__CLEAROK; + } + if (!cursor_address) { + if (win->curx != 0) + __cputchar('\n'); + if (!_cursesi_screen->curwin) + werase(curscr); + } +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, "doupdate: (%p): curwin = %d\n", win, + _cursesi_screen->curwin); + __CTRACE(__CTRACE_REFRESH, "doupdate: \tfirstch\tlastch\n"); +#endif + + if (!_cursesi_screen->curwin) { + /* + * Invoke quickch() only if more than a quarter of the lines + * in the window are dirty. + */ + for (wy = 0, dnum = 0; wy < win->maxy; wy++) + if (win->alines[wy]->flags & __ISDIRTY) + dnum++; + if (!__noqch && dnum > (int) win->maxy / 4) + quickch(); + } + +#ifdef DEBUG + { + int i, j; + + __CTRACE(__CTRACE_REFRESH, + "#####################################\n"); + __CTRACE(__CTRACE_REFRESH, + "stdscr(%p)-curscr(%p)-__virtscr(%p)\n", + stdscr, curscr, _cursesi_screen->__virtscr); + for (i = 0; i < curscr->maxy; i++) { + __CTRACE(__CTRACE_REFRESH, "C: %d:", i); + __CTRACE(__CTRACE_REFRESH, " 0x%x \n", + curscr->alines[i]->hash); + for (j = 0; j < curscr->maxx; j++) + __CTRACE(__CTRACE_REFRESH, "%c", + curscr->alines[i]->line[j].ch); + __CTRACE(__CTRACE_REFRESH, "\n"); + __CTRACE(__CTRACE_REFRESH, " attr:"); + for (j = 0; j < curscr->maxx; j++) + __CTRACE(__CTRACE_REFRESH, " %x", + curscr->alines[i]->line[j].attr); + __CTRACE(__CTRACE_REFRESH, "\n"); + __CTRACE(__CTRACE_REFRESH, "W: %d:", i); + __CTRACE(__CTRACE_REFRESH, " 0x%x \n", + win->alines[i]->hash); + __CTRACE(__CTRACE_REFRESH, " 0x%x ", + win->alines[i]->flags); + for (j = 0; j < win->maxx; j++) + __CTRACE(__CTRACE_REFRESH, "%c", + win->alines[i]->line[j].ch); + __CTRACE(__CTRACE_REFRESH, "\n"); + __CTRACE(__CTRACE_REFRESH, " attr:"); + for (j = 0; j < win->maxx; j++) + __CTRACE(__CTRACE_REFRESH, " %x", + win->alines[i]->line[j].attr); + __CTRACE(__CTRACE_REFRESH, "\n"); +#ifdef HAVE_WCHAR + __CTRACE(__CTRACE_REFRESH, " nsp:"); + for (j = 0; j < curscr->maxx; j++) + __CTRACE(__CTRACE_REFRESH, " %p", + win->alines[i]->line[j].nsp); + __CTRACE(__CTRACE_REFRESH, "\n"); + __CTRACE(__CTRACE_REFRESH, " bnsp:"); + for (j = 0; j < curscr->maxx; j++) + __CTRACE(__CTRACE_REFRESH, " %p", + win->bnsp); + __CTRACE(__CTRACE_REFRESH, "\n"); +#endif /* HAVE_WCHAR */ + } + } +#endif /* DEBUG */ + + for (wy = 0; wy < win->maxy; wy++) { + wlp = win->alines[wy]; +/* XXX: remove this debug */ +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, + "doupdate: wy %d\tf: %d\tl:%d\tflags %x\n", + wy, *wlp->firstchp, *wlp->lastchp, wlp->flags); +#endif /* DEBUG */ + if (!_cursesi_screen->curwin) + curscr->alines[wy]->hash = wlp->hash; + if (wlp->flags & __ISDIRTY) { +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, + "doupdate: [ISDIRTY]wy:%d\tf:%d\tl:%d\n", wy, + *wlp->firstchp, *wlp->lastchp); +#endif /* DEBUG */ + if (makech(wy) == ERR) + return (ERR); + else { + if (*wlp->firstchp >= 0) + *wlp->firstchp = win->maxx; + if (*wlp->lastchp < win->maxx) + *wlp->lastchp = 0; + if (*wlp->lastchp < *wlp->firstchp) { +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, + "doupdate: line %d notdirty\n", wy); +#endif /* DEBUG */ + wlp->flags &= ~__ISDIRTY; + } + } + + } +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, "\t%d\t%d\n", + *wlp->firstchp, *wlp->lastchp); +#endif /* DEBUG */ + } + +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, "doupdate: ly=%d, lx=%d\n", + _cursesi_screen->ly, _cursesi_screen->lx); +#endif /* DEBUG */ + + if (_cursesi_screen->curwin) + domvcur(_cursesi_screen->ly, _cursesi_screen->lx, + win->cury, win->curx); + else { + if (win->flags & __LEAVEOK) { + curscr->cury = _cursesi_screen->ly; + curscr->curx = _cursesi_screen->lx; + } else { + domvcur(_cursesi_screen->ly, _cursesi_screen->lx, + win->cury, win->curx); + curscr->cury = win->cury; + curscr->curx = win->curx; + } + } + + /* Don't leave the screen with attributes set. */ + __unsetattr(0); +#ifdef DEBUG +#ifdef HAVE_WCHAR + { + int i, j; + + __CTRACE(__CTRACE_REFRESH, + "***********after*****************\n"); + __CTRACE(__CTRACE_REFRESH, + "stdscr(%p)-curscr(%p)-__virtscr(%p)\n", + stdscr, curscr, _cursesi_screen->__virtscr); + for (i = 0; i < curscr->maxy; i++) { + for (j = 0; j < curscr->maxx; j++) + __CTRACE(__CTRACE_REFRESH, + "[%d,%d](%x,%x,%p)-(%x,%x,%p)\n", + i, j, + curscr->alines[i]->line[j].ch, + curscr->alines[i]->line[j].attr, + curscr->alines[i]->line[j].nsp, + _cursesi_screen->__virtscr->alines[i]->line[j].ch, + _cursesi_screen->__virtscr->alines[i]->line[j].attr, + _cursesi_screen->__virtscr->alines[i]->line[j].nsp); + } + } +#endif /* HAVE_WCHAR */ +#endif /* DEBUG */ + return fflush(_cursesi_screen->outfd) == EOF ? ERR : OK; +} + +/* + * makech -- + * Make a change on the screen. + */ +static int +makech(int wy) +{ + WINDOW *win; + static __LDATA blank; + __LDATA *nsp, *csp, *cp, *cep; + size_t clsp, nlsp; /* Last space in lines. */ + int lch, wx; + const char *ce; + attr_t lspc; /* Last space colour */ + attr_t off, on; + +#ifdef __GNUC__ + nlsp = lspc = 0; /* XXX gcc -Wuninitialized */ +#endif + if (_cursesi_screen->curwin) + win = curscr; + else + win = __virtscr; +#ifdef HAVE_WCHAR + blank.ch = ( wchar_t )btowc(( int ) win->bch ); + blank.attr = 0; + if (_cursesi_copy_nsp(win->bnsp, &blank) == ERR) + return ERR; + SET_WCOL( blank, 1 ); +#endif /* HAVE_WCHAR */ +#ifdef DEBUG +#if HAVE_WCHAR + { + int x; + __LDATA *lp, *vlp; + + __CTRACE(__CTRACE_REFRESH, + "[makech-before]wy=%d,curscr(%p)-__virtscr(%p)\n", + wy, curscr, __virtscr); + for (x = 0; x < curscr->maxx; x++) { + lp = &curscr->alines[wy]->line[x]; + vlp = &__virtscr->alines[wy]->line[x]; + __CTRACE(__CTRACE_REFRESH, + "[%d,%d](%x,%x,%x,%x,%p)-" + "(%x,%x,%x,%x,%p)\n", + wy, x, lp->ch, lp->attr, + win->bch, win->battr, lp->nsp, + vlp->ch, vlp->attr, + win->bch, win->battr, vlp->nsp); + } + } +#endif /* HAVE_WCHAR */ +#endif /* DEBUG */ + /* Is the cursor still on the end of the last line? */ + if (wy > 0 && curscr->alines[wy - 1]->flags & __ISPASTEOL) { + domvcur(_cursesi_screen->ly, _cursesi_screen->lx, + _cursesi_screen->ly + 1, 0); + _cursesi_screen->ly++; + _cursesi_screen->lx = 0; + } + wx = *win->alines[wy]->firstchp; + if (wx < 0) + wx = 0; + else + if (wx >= win->maxx) + return (OK); + lch = *win->alines[wy]->lastchp; + if (lch < 0) + return (OK); + else + if (lch >= (int) win->maxx) + lch = win->maxx - 1; + + if (_cursesi_screen->curwin) { + csp = ␣ +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, "makech: csp is blank\n"); +#endif /* DEBUG */ + } else { + csp = &curscr->alines[wy]->line[wx]; +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, + "makech: csp is on curscr:(%d,%d)\n", wy, wx); +#endif /* DEBUG */ + } + + nsp = &win->alines[wy]->line[wx]; +#ifdef DEBUG + if ( _cursesi_screen->curwin ) + __CTRACE(__CTRACE_REFRESH, + "makech: nsp is at curscr:(%d,%d)\n", wy, wx); + else + __CTRACE(__CTRACE_REFRESH, + "makech: nsp is at __virtscr:(%d,%d)\n", wy, wx); +#endif /* DEBUG */ + if (clr_eol && !_cursesi_screen->curwin) { + cp = &win->alines[wy]->line[win->maxx - 1]; + lspc = cp->attr & __COLOR; +#ifndef HAVE_WCHAR + while (cp->ch == ' ' && cp->attr == lspc) /* XXX */ + if (cp-- <= win->alines[wy]->line) + break; +#else + while (cp->ch == ( wchar_t )btowc(( int )' ' ) + && ( cp->attr & WA_ATTRIBUTES ) == lspc) + if (cp-- <= win->alines[wy]->line) + break; +#endif /* HAVE_WCHAR */ + if (win->alines[wy]->line > cp) + nlsp = 0; + else + nlsp = cp - win->alines[wy]->line; + } + if (!_cursesi_screen->curwin) + ce = clr_eol; + else + ce = NULL; + + while (wx <= lch) { +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, "makech: wx=%d,lch=%d\n", wx, lch); +#endif /* DEBUG */ +#ifndef HAVE_WCHAR + if (memcmp(nsp, csp, sizeof(__LDATA)) == 0) { + if (wx <= lch) { + while (wx <= lch && + memcmp(nsp, csp, sizeof(__LDATA)) == 0) { + nsp++; + if (!_cursesi_screen->curwin) + ++csp; + ++wx; + } + continue; + } + break; + } +#else +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, "makech: nsp=(%x,%x,%x,%x,%p)\n", + nsp->ch, nsp->attr, win->bch, win->battr, nsp->nsp); + __CTRACE(__CTRACE_REFRESH, "makech: csp=(%x,%x,%x,%x,%p)\n", + csp->ch, csp->attr, win->bch, win->battr, csp->nsp); +#endif /* DEBUG */ + if (((nsp->attr & __WCWIDTH) != __WCWIDTH) && + cellcmp(nsp, csp)) { + if (wx <= lch) { + while (wx <= lch && cellcmp( csp, nsp )) { + nsp++; + if (!_cursesi_screen->curwin) + ++csp; + ++wx; + } + continue; + } + break; + } +#endif /* HAVE_WCHAR */ + domvcur(_cursesi_screen->ly, _cursesi_screen->lx, wy, wx); + +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, "makech: 1: wx = %d, ly= %d, " + "lx = %d, newy = %d, newx = %d\n", + wx, _cursesi_screen->ly, _cursesi_screen->lx, wy, wx); +#endif + _cursesi_screen->ly = wy; + _cursesi_screen->lx = wx; +#ifndef HAVE_WCHAR + while (wx <= lch && memcmp(nsp, csp, sizeof(__LDATA)) != 0) { + if (ce != NULL && + wx >= nlsp && nsp->ch == ' ' && nsp->attr == lspc) { +#else + while (!cellcmp(nsp, csp) && wx <= lch) { + if (ce != NULL && wx >= nlsp + && nsp->ch == (wchar_t)btowc((int)' ') /* XXX */ + && (nsp->attr & WA_ATTRIBUTES) == lspc) { + +#endif + /* Check for clear to end-of-line. */ + cep = &curscr->alines[wy]->line[win->maxx - 1]; +#ifndef HAVE_WCHAR + while (cep->ch == ' ' && cep->attr == lspc) /* XXX */ +#else + while (cep->ch == (wchar_t)btowc((int)' ') + && (cep->attr & WA_ATTRIBUTES) == lspc) +#endif /* HAVE_WCHAR */ + if (cep-- <= csp) + break; + clsp = cep - curscr->alines[wy]->line - + win->begx * __LDATASIZE; +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, + "makech: clsp = %zu, nlsp = %zu\n", + clsp, nlsp); +#endif + if (((clsp - nlsp >= strlen(clr_eol) && + clsp < win->maxx * __LDATASIZE) || + wy == win->maxy - 1) && + (!(lspc & __COLOR) || + ((lspc & __COLOR) && back_color_erase))) { + __unsetattr(0); + if (__using_color && + ((lspc & __COLOR) != + (curscr->wattr & __COLOR))) + __set_color(curscr, lspc & + __COLOR); + tputs(clr_eol, 0, __cputchar); + _cursesi_screen->lx = wx + win->begx; + while (wx++ <= clsp) { + csp->attr = lspc; +#ifndef HAVE_WCHAR + csp->ch = ' '; /* XXX */ +#else + csp->ch = (wchar_t)btowc((int)' '); + SET_WCOL( *csp, 1 ); +#endif /* HAVE_WCHAR */ + csp++; + } + return (OK); + } + ce = NULL; + } + +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, + "makech: have attr %08x, need attr %08x\n", + curscr->wattr & WA_ATTRIBUTES, + nsp->attr & WA_ATTRIBUTES); +#endif + + off = (~nsp->attr & curscr->wattr) +#ifndef HAVE_WCHAR + & __ATTRIBUTES +#else + & WA_ATTRIBUTES +#endif + ; + + /* + * Unset attributes as appropriate. Unset first + * so that the relevant attributes can be reset + * (because 'me' unsets 'mb', 'md', 'mh', 'mk', + * 'mp' and 'mr'). Check to see if we also turn off + * standout, attributes and colour. + */ + if (off & __TERMATTR && exit_attribute_mode != NULL) { + tputs(exit_attribute_mode, 0, __cputchar); + curscr->wattr &= __mask_me; + off &= __mask_me; + } + + /* + * Exit underscore mode if appropriate. + * Check to see if we also turn off standout, + * attributes and colour. + */ + if (off & __UNDERSCORE && exit_underline_mode != NULL) { + tputs(exit_underline_mode, 0, __cputchar); + curscr->wattr &= __mask_ue; + off &= __mask_ue; + } + + /* + * Exit standout mode as appropriate. + * Check to see if we also turn off underscore, + * attributes and colour. + * XXX + * Should use uc if so/se not available. + */ + if (off & __STANDOUT && exit_standout_mode != NULL) { + tputs(exit_standout_mode, 0, __cputchar); + curscr->wattr &= __mask_se; + off &= __mask_se; + } + + if (off & __ALTCHARSET && exit_alt_charset_mode != NULL) { + tputs(exit_alt_charset_mode, 0, __cputchar); + curscr->wattr &= ~__ALTCHARSET; + } + + /* Set/change colour as appropriate. */ + if (__using_color) + __set_color(curscr, nsp->attr & __COLOR); + + on = (nsp->attr & ~curscr->wattr) +#ifndef HAVE_WCHAR + & __ATTRIBUTES +#else + & WA_ATTRIBUTES +#endif + ; + + /* + * Enter standout mode if appropriate. + */ + if (on & __STANDOUT && + enter_standout_mode != NULL && + exit_standout_mode != NULL) + { + tputs(enter_standout_mode, 0, __cputchar); + curscr->wattr |= __STANDOUT; + } + + /* + * Enter underscore mode if appropriate. + * XXX + * Should use uc if us/ue not available. + */ + if (on & __UNDERSCORE && + enter_underline_mode != NULL && + exit_underline_mode != NULL) + { + tputs(enter_underline_mode, 0, __cputchar); + curscr->wattr |= __UNDERSCORE; + } + + /* + * Set other attributes as appropriate. + */ + if (exit_attribute_mode != NULL) { + if (on & __BLINK && + enter_blink_mode != NULL) + { + tputs(enter_blink_mode, 0, __cputchar); + curscr->wattr |= __BLINK; + } + if (on & __BOLD && + enter_bold_mode != NULL) + { + tputs(enter_bold_mode, 0, __cputchar); + curscr->wattr |= __BOLD; + } + if (on & __DIM && + enter_dim_mode != NULL) + { + tputs(enter_dim_mode, 0, __cputchar); + curscr->wattr |= __DIM; + } + if (on & __BLANK && + enter_secure_mode != NULL) + { + tputs(enter_secure_mode, 0, __cputchar); + curscr->wattr |= __BLANK; + } + if (on & __PROTECT && + enter_protected_mode != NULL) + { + tputs(enter_protected_mode, 0, __cputchar); + curscr->wattr |= __PROTECT; + } + if (on & __REVERSE && + enter_reverse_mode != NULL) + { + tputs(enter_reverse_mode, 0, __cputchar); + curscr->wattr |= __REVERSE; + } +#ifdef HAVE_WCHAR + if (on & WA_TOP && + enter_top_hl_mode != NULL) + { + tputs(enter_top_hl_mode, 0, __cputchar); + curscr->wattr |= WA_TOP; + } + if (on & WA_LOW && + enter_low_hl_mode != NULL) + { + tputs(enter_low_hl_mode, 0, __cputchar); + curscr->wattr |= WA_LOW; + } + if (on & WA_LEFT && + enter_left_hl_mode != NULL) + { + tputs(enter_left_hl_mode, 0, __cputchar); + curscr->wattr |= WA_LEFT; + } + if (on & WA_RIGHT && + enter_right_hl_mode != NULL) + { + tputs(enter_right_hl_mode, 0, __cputchar); + curscr->wattr |= WA_RIGHT; + } + if (on & WA_HORIZONTAL && + enter_horizontal_hl_mode != NULL) + { + tputs(enter_horizontal_hl_mode, 0, __cputchar); + curscr->wattr |= WA_HORIZONTAL; + } + if (on & WA_VERTICAL && + enter_vertical_hl_mode != NULL) + { + tputs(enter_vertical_hl_mode, 0, __cputchar); + curscr->wattr |= WA_VERTICAL; + } +#endif /* HAVE_WCHAR */ + } + + /* Enter/exit altcharset mode as appropriate. */ + if (on & __ALTCHARSET && enter_alt_charset_mode != NULL && + exit_alt_charset_mode != NULL) { + tputs(enter_alt_charset_mode, 0, __cputchar); + curscr->wattr |= __ALTCHARSET; + } + + wx++; + if (wx >= win->maxx && + wy == win->maxy - 1 && !_cursesi_screen->curwin) { + if (win->flags & __SCROLLOK) { + if (win->flags & __ENDLINE) + __unsetattr(1); + if (!(win->flags & __SCROLLWIN)) { + if (!_cursesi_screen->curwin) { + csp->attr = nsp->attr; + csp->ch = nsp->ch; +#ifdef HAVE_WCHAR + if (_cursesi_copy_nsp(nsp->nsp, csp) == ERR) + return ERR; +#endif /* HAVE_WCHAR */ + } +#ifndef HAVE_WCHAR + __cputchar((int) nsp->ch); +#else + if ( WCOL( *nsp ) > 0 ) { + __cputwchar((int)nsp->ch); +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, + "makech: (%d,%d)putwchar(0x%x)\n", + wy, wx - 1, + nsp->ch ); +#endif /* DEBUG */ + /* + * Output non-spacing + * characters for the + * cell. + */ + __cursesi_putnsp(nsp->nsp, + wy, wx); + + } +#endif /* HAVE_WCHAR */ + } + if (wx < curscr->maxx) { + domvcur(_cursesi_screen->ly, wx, + (int) (win->maxy - 1), + (int) (win->maxx - 1)); + } + _cursesi_screen->ly = win->maxy - 1; + _cursesi_screen->lx = win->maxx - 1; + return (OK); + } + } + if (wx < win->maxx || wy < win->maxy - 1 || + !(win->flags & __SCROLLWIN)) { + if (!_cursesi_screen->curwin) { + csp->attr = nsp->attr; + csp->ch = nsp->ch; +#ifdef HAVE_WCHAR + if (_cursesi_copy_nsp(nsp->nsp, + csp) == ERR) + return ERR; +#endif /* HAVE_WCHAR */ + csp++; + } +#ifndef HAVE_WCHAR + __cputchar((int) nsp->ch); +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, + "makech: putchar(%c)\n", nsp->ch & 0177); +#endif +#else + if (WCOL(*nsp) > 0) { + __cputwchar((int) nsp->ch); +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, + "makech:(%d,%d) putwchar(%x)\n", + wy, wx - 1, nsp->ch); + __cursesi_putnsp(nsp->nsp, wy, wx); +#endif /* DEBUG */ + } +#endif /* HAVE_WCHAR */ + } + if (underline_char && ((nsp->attr & __STANDOUT) || + (nsp->attr & __UNDERSCORE))) { + __cputchar('\b'); + tputs(underline_char, 0, __cputchar); + } + nsp++; +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, + "makech: 2: wx = %d, lx = %d\n", + wx, _cursesi_screen->lx); +#endif + } + if (_cursesi_screen->lx == wx) /* If no change. */ + break; + _cursesi_screen->lx = wx; + if (_cursesi_screen->lx >= COLS && auto_right_margin) + _cursesi_screen->lx = COLS - 1; + else + if (wx >= win->maxx) { + domvcur(_cursesi_screen->ly, + _cursesi_screen->lx, + _cursesi_screen->ly, + (int) (win->maxx - 1)); + _cursesi_screen->lx = win->maxx - 1; + } +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, "makech: 3: wx = %d, lx = %d\n", + wx, _cursesi_screen->lx); +#endif + } +#ifdef DEBUG +#if HAVE_WCHAR + { + int x; + __LDATA *lp, *vlp; + + __CTRACE(__CTRACE_REFRESH, + "makech-after: curscr(%p)-__virtscr(%p)\n", + curscr, __virtscr ); + for (x = 0; x < curscr->maxx; x++) { + lp = &curscr->alines[wy]->line[x]; + vlp = &__virtscr->alines[wy]->line[x]; + __CTRACE(__CTRACE_REFRESH, + "[%d,%d](%x,%x,%x,%x,%p)-" + "(%x,%x,%x,%x,%p)\n", + wy, x, lp->ch, lp->attr, + win->bch, win->battr, lp->nsp, + vlp->ch, vlp->attr, + win->bch, win->battr, vlp->nsp); + } + } +#endif /* HAVE_WCHAR */ +#endif /* DEBUG */ + + return (OK); +} + +/* + * domvcur -- + * Do a mvcur, leaving attributes if necessary. + */ +static void +domvcur(oy, ox, ny, nx) + int oy, ox, ny, nx; +{ +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, "domvcur: (%x,%d)=>(%d,%d)\n", + oy, ox, ny, nx ); +#endif /* DEBUG */ + __unsetattr(1); + if ( oy == ny && ox == nx ) + return; + __mvcur(oy, ox, ny, nx, 1); +} + +/* + * Quickch() attempts to detect a pattern in the change of the window + * in order to optimize the change, e.g., scroll n lines as opposed to + * repainting the screen line by line. + */ + +static __LDATA buf[128]; +static u_int last_hash; +static size_t last_hash_len; +#define BLANKSIZE (sizeof(buf) / sizeof(buf[0])) + +static void +quickch(void) +{ +#define THRESH (int) __virtscr->maxy / 4 + + __LINE *clp, *tmp1, *tmp2; + int bsize, curs, curw, starts, startw, i, j; + int n, target, cur_period, bot, top, sc_region; + u_int blank_hash; + attr_t bcolor; + +#ifdef __GNUC__ + curs = curw = starts = startw = 0; /* XXX gcc -Wuninitialized */ +#endif + /* + * Find how many lines from the top of the screen are unchanged. + */ + for (top = 0; top < __virtscr->maxy; top++) +#ifndef HAVE_WCHAR + if (__virtscr->alines[top]->flags & __ISDIRTY && + (__virtscr->alines[top]->hash != curscr->alines[top]->hash || + memcmp(__virtscr->alines[top]->line, + curscr->alines[top]->line, + (size_t) __virtscr->maxx * __LDATASIZE) + != 0)) + break; +#else + if (__virtscr->alines[top]->flags & __ISDIRTY && + (__virtscr->alines[top]->hash != curscr->alines[top]->hash || + !linecmp(__virtscr->alines[top]->line, + curscr->alines[top]->line, + (size_t) __virtscr->maxx ))) + break; +#endif /* HAVE_WCHAR */ + else + __virtscr->alines[top]->flags &= ~__ISDIRTY; + /* + * Find how many lines from bottom of screen are unchanged. + */ + for (bot = __virtscr->maxy - 1; bot >= 0; bot--) +#ifndef HAVE_WCHAR + if (__virtscr->alines[bot]->flags & __ISDIRTY && + (__virtscr->alines[bot]->hash != curscr->alines[bot]->hash || + memcmp(__virtscr->alines[bot]->line, + curscr->alines[bot]->line, + (size_t) __virtscr->maxx * __LDATASIZE) + != 0)) + break; +#else + if (__virtscr->alines[bot]->flags & __ISDIRTY && + (__virtscr->alines[bot]->hash != curscr->alines[bot]->hash || + !linecmp(__virtscr->alines[bot]->line, + curscr->alines[bot]->line, + (size_t) __virtscr->maxx ))) + break; +#endif /* HAVE_WCHAR */ + else + __virtscr->alines[bot]->flags &= ~__ISDIRTY; + + /* + * Work round an xterm bug where inserting lines causes all the + * inserted lines to be covered with the background colour we + * set on the first line (even if we unset it for subsequent + * lines). + */ + bcolor = __virtscr->alines[min(top, + __virtscr->maxy - 1)]->line[0].attr & __COLOR; + for (i = top + 1, j = 0; i < bot; i++) { + if ((__virtscr->alines[i]->line[0].attr & __COLOR) != bcolor) { + bcolor = __virtscr->alines[i]->line[__virtscr->maxx]. + attr & __COLOR; + j = i - top; + } else + break; + } + top += j; + +#ifdef NO_JERKINESS + /* + * If we have a bottom unchanged region return. Scrolling the + * bottom region up and then back down causes a screen jitter. + * This will increase the number of characters sent to the screen + * but it looks better. + */ + if (bot < __virtscr->maxy - 1) + return; +#endif /* NO_JERKINESS */ + + /* + * Search for the largest block of text not changed. + * Invariants of the loop: + * - Startw is the index of the beginning of the examined block in + * __virtscr. + * - Starts is the index of the beginning of the examined block in + * curscr. + * - Curw is the index of one past the end of the exmined block in + * __virtscr. + * - Curs is the index of one past the end of the exmined block in + * curscr. + * - bsize is the current size of the examined block. + */ + + for (bsize = bot - top; bsize >= THRESH; bsize--) { + for (startw = top; startw <= bot - bsize; startw++) + for (starts = top; starts <= bot - bsize; + starts++) { + for (curw = startw, curs = starts; + curs < starts + bsize; curw++, curs++) + if (__virtscr->alines[curw]->hash != + curscr->alines[curs]->hash) + break; + if (curs != starts + bsize) + continue; + for (curw = startw, curs = starts; + curs < starts + bsize; curw++, curs++) +#ifndef HAVE_WCHAR + if (memcmp(__virtscr->alines[curw]->line, + curscr->alines[curs]->line, + (size_t) __virtscr->maxx * + __LDATASIZE) != 0) + break; +#else + if (!linecmp(__virtscr->alines[curw]->line, + curscr->alines[curs]->line, + (size_t) __virtscr->maxx)) + break; +#endif /* HAVE_WCHAR */ + if (curs == starts + bsize) + goto done; + } + } +done: + + /* Did not find anything */ + if (bsize < THRESH) + return; + +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, "quickch:bsize=%d, starts=%d, startw=%d, " + "curw=%d, curs=%d, top=%d, bot=%d\n", + bsize, starts, startw, curw, curs, top, bot); +#endif + + /* + * Make sure that there is no overlap between the bottom and top + * regions and the middle scrolled block. + */ + if (bot < curs) + bot = curs - 1; + if (top > starts) + top = starts; + + n = startw - starts; + +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, "#####################################\n"); + for (i = 0; i < curscr->maxy; i++) { + __CTRACE(__CTRACE_REFRESH, "C: %d:", i); + __CTRACE(__CTRACE_REFRESH, " 0x%x \n", curscr->alines[i]->hash); + for (j = 0; j < curscr->maxx; j++) + __CTRACE(__CTRACE_REFRESH, "%c", + curscr->alines[i]->line[j].ch); + __CTRACE(__CTRACE_REFRESH, "\n"); + __CTRACE(__CTRACE_REFRESH, " attr:"); + for (j = 0; j < curscr->maxx; j++) + __CTRACE(__CTRACE_REFRESH, " %x", + curscr->alines[i]->line[j].attr); + __CTRACE(__CTRACE_REFRESH, "\n"); + __CTRACE(__CTRACE_REFRESH, "W: %d:", i); + __CTRACE(__CTRACE_REFRESH, " 0x%x \n", + __virtscr->alines[i]->hash); + __CTRACE(__CTRACE_REFRESH, " 0x%x ", + __virtscr->alines[i]->flags); + for (j = 0; j < __virtscr->maxx; j++) + __CTRACE(__CTRACE_REFRESH, "%c", + __virtscr->alines[i]->line[j].ch); + __CTRACE(__CTRACE_REFRESH, "\n"); + __CTRACE(__CTRACE_REFRESH, " attr:"); + for (j = 0; j < __virtscr->maxx; j++) + __CTRACE(__CTRACE_REFRESH, " %x", + __virtscr->alines[i]->line[j].attr); + __CTRACE(__CTRACE_REFRESH, "\n"); + } +#endif + +#ifndef HAVE_WCHAR + if (buf[0].ch != ' ') { + for (i = 0; i < BLANKSIZE; i++) { + buf[i].ch = ' '; + buf[i].attr = 0; + } + } +#else + if (buf[0].ch != ( wchar_t )btowc(( int ) curscr->bch )) { + for (i = 0; i < BLANKSIZE; i++) { + buf[i].ch = ( wchar_t )btowc(( int ) curscr->bch ); + if (_cursesi_copy_nsp(curscr->bnsp, &buf[i]) == ERR) + return; + buf[i].attr = 0; + SET_WCOL( buf[ i ], 1 ); + } + } +#endif /* HAVE_WCHAR */ + + if (__virtscr->maxx != last_hash_len) { + blank_hash = 0; + for (i = __virtscr->maxx; i > BLANKSIZE; i -= BLANKSIZE) { + blank_hash = __hash_more(buf, sizeof(buf), blank_hash); + } + blank_hash = __hash_more((char *)(void *)buf, + i * sizeof(buf[0]), blank_hash); + /* cache result in static data - screen width doesn't change often */ + last_hash_len = __virtscr->maxx; + last_hash = blank_hash; + } else + blank_hash = last_hash; + + /* + * Perform the rotation to maintain the consistency of curscr. + * This is hairy since we are doing an *in place* rotation. + * Invariants of the loop: + * - I is the index of the current line. + * - Target is the index of the target of line i. + * - Tmp1 points to current line (i). + * - Tmp2 and points to target line (target); + * - Cur_period is the index of the end of the current period. + * (see below). + * + * There are 2 major issues here that make this rotation non-trivial: + * 1. Scrolling in a scrolling region bounded by the top + * and bottom regions determined (whose size is sc_region). + * 2. As a result of the use of the mod function, there may be a + * period introduced, i.e., 2 maps to 4, 4 to 6, n-2 to 0, and + * 0 to 2, which then causes all odd lines not to be rotated. + * To remedy this, an index of the end ( = beginning) of the + * current 'period' is kept, cur_period, and when it is reached, + * the next period is started from cur_period + 1 which is + * guaranteed not to have been reached since that would mean that + * all records would have been reached. (think about it...). + * + * Lines in the rotation can have 3 attributes which are marked on the + * line so that curscr is consistent with the visual screen. + * 1. Not dirty -- lines inside the scrolled block, top region or + * bottom region. + * 2. Blank lines -- lines in the differential of the scrolling + * region adjacent to top and bot regions + * depending on scrolling direction. + * 3. Dirty line -- all other lines are marked dirty. + */ + sc_region = bot - top + 1; + i = top; + tmp1 = curscr->alines[top]; + cur_period = top; + for (j = top; j <= bot; j++) { + target = (i - top + n + sc_region) % sc_region + top; + tmp2 = curscr->alines[target]; + curscr->alines[target] = tmp1; + /* Mark block as clean and blank out scrolled lines. */ + clp = curscr->alines[target]; +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, + "quickch: n=%d startw=%d curw=%d i = %d target=%d ", + n, startw, curw, i, target); +#endif + if ((target >= startw && target < curw) || target < top + || target > bot) { +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, " notdirty\n"); +#endif + __virtscr->alines[target]->flags &= ~__ISDIRTY; + } else + if ((n > 0 && target >= top && target < top + n) || + (n < 0 && target <= bot && target > bot + n)) { +#ifndef HAVE_WCHAR + if (clp->hash != blank_hash || + memcmp(clp->line, clp->line + 1, + (__virtscr->maxx - 1) + * __LDATASIZE) || + memcmp(clp->line, buf, __LDATASIZE)) { +#else + if (clp->hash != blank_hash + || linecmp(clp->line, clp->line + 1, + (unsigned int) (__virtscr->maxx - 1)) + || cellcmp(clp->line, buf)) { +#endif /* HAVE_WCHAR */ + for (i = __virtscr->maxx; + i > BLANKSIZE; + i -= BLANKSIZE) { + (void) memcpy(clp->line + i - + BLANKSIZE, buf, sizeof(buf)); + } + (void) memcpy(clp->line , buf, i * + sizeof(buf[0])); +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, + " blanked out: dirty\n"); +#endif + clp->hash = blank_hash; + __touchline(__virtscr, target, 0, (int) __virtscr->maxx - 1); + } else { +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, + " -- blank line already: dirty\n"); +#endif + __touchline(__virtscr, target, 0, (int) __virtscr->maxx - 1); + } + } else { +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, " -- dirty\n"); +#endif + __touchline(__virtscr, target, 0, (int) __virtscr->maxx - 1); + } + if (target == cur_period) { + i = target + 1; + tmp1 = curscr->alines[i]; + cur_period = i; + } else { + tmp1 = tmp2; + i = target; + } + } +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n"); + for (i = 0; i < curscr->maxy; i++) { + __CTRACE(__CTRACE_REFRESH, "C: %d:", i); + for (j = 0; j < curscr->maxx; j++) + __CTRACE(__CTRACE_REFRESH, "%c", + curscr->alines[i]->line[j].ch); + __CTRACE(__CTRACE_REFRESH, "\n"); + __CTRACE(__CTRACE_REFRESH, "W: %d:", i); + for (j = 0; j < __virtscr->maxx; j++) + __CTRACE(__CTRACE_REFRESH, "%c", + __virtscr->alines[i]->line[j].ch); + __CTRACE(__CTRACE_REFRESH, "\n"); + } +#endif + if (n != 0) + scrolln(starts, startw, curs, bot, top); +} + +/* + * scrolln -- + * Scroll n lines, where n is starts - startw. + */ +static void /* ARGSUSED */ +scrolln(starts, startw, curs, bot, top) + int starts, startw, curs, bot, top; +{ + int i, oy, ox, n; + + oy = curscr->cury; + ox = curscr->curx; + n = starts - startw; + + /* + * XXX + * The initial tests that set __noqch don't let us reach here unless + * we have either cs + ho + SF/sf/SR/sr, or AL + DL. SF/sf and SR/sr + * scrolling can only shift the entire scrolling region, not just a + * part of it, which means that the quickch() routine is going to be + * sadly disappointed in us if we don't have cs as well. + * + * If cs, ho and SF/sf are set, can use the scrolling region. Because + * the cursor position after cs is undefined, we need ho which gives us + * the ability to move to somewhere without knowledge of the current + * location of the cursor. Still call __mvcur() anyway, to update its + * idea of where the cursor is. + * + * When the scrolling region has been set, the cursor has to be at the + * last line of the region to make the scroll happen. + * + * Doing SF/SR or AL/DL appears faster on the screen than either sf/sr + * or AL/DL, and, some terminals have AL/DL, sf/sr, and cs, but not + * SF/SR. So, if we're scrolling almost all of the screen, try and use + * AL/DL, otherwise use the scrolling region. The "almost all" is a + * shameless hack for vi. + */ + if (n > 0) { + if (change_scroll_region != NULL && cursor_home != NULL && + (parm_index != NULL || + ((parm_insert_line == NULL || parm_delete_line == NULL || + top > 3 || bot + 3 < __virtscr->maxy) && + scroll_forward != NULL))) + { + tputs(vtparm(change_scroll_region, top, bot), + 0, __cputchar); + __mvcur(oy, ox, 0, 0, 1); + tputs(cursor_home, 0, __cputchar); + __mvcur(0, 0, bot, 0, 1); + if (parm_index != NULL) + tputs(vtparm(parm_index, n), + 0, __cputchar); + else + for (i = 0; i < n; i++) + tputs(scroll_forward, 0, __cputchar); + tputs(vtparm(change_scroll_region, + 0, (int) __virtscr->maxy - 1), 0, __cputchar); + __mvcur(bot, 0, 0, 0, 1); + tputs(cursor_home, 0, __cputchar); + __mvcur(0, 0, oy, ox, 1); + return; + } + + /* Scroll up the block. */ + if (parm_index != NULL && top == 0) { + __mvcur(oy, ox, bot, 0, 1); + tputs(vtparm(parm_index, n), 0, __cputchar); + } else + if (parm_delete_line != NULL) { + __mvcur(oy, ox, top, 0, 1); + tputs(vtparm(parm_delete_line, n), + 0, __cputchar); + } else + if (delete_line != NULL) { + __mvcur(oy, ox, top, 0, 1); + for (i = 0; i < n; i++) + tputs(delete_line, + 0, __cputchar); + } else + if (scroll_forward != NULL && top == 0) { + __mvcur(oy, ox, bot, 0, 1); + for (i = 0; i < n; i++) + tputs(scroll_forward, 0, + __cputchar); + } else + abort(); + + /* Push down the bottom region. */ + __mvcur(top, 0, bot - n + 1, 0, 1); + if (parm_insert_line != NULL) + tputs(vtparm(parm_insert_line, n), 0, __cputchar); + else + if (insert_line != NULL) + for (i = 0; i < n; i++) + tputs(insert_line, 0, __cputchar); + else + abort(); + __mvcur(bot - n + 1, 0, oy, ox, 1); + } else { + /* + * !!! + * n < 0 + * + * If cs, ho and SR/sr are set, can use the scrolling region. + * See the above comments for details. + */ + if (change_scroll_region != NULL && cursor_home != NULL && + (parm_rindex != NULL || + ((parm_insert_line == NULL || parm_delete_line == NULL || + top > 3 || + bot + 3 < __virtscr->maxy) && scroll_reverse != NULL))) + { + tputs(vtparm(change_scroll_region, top, bot), + 0, __cputchar); + __mvcur(oy, ox, 0, 0, 1); + tputs(cursor_home, 0, __cputchar); + __mvcur(0, 0, top, 0, 1); + + if (parm_rindex != NULL) + tputs(vtparm(parm_rindex, -n), + 0, __cputchar); + else + for (i = n; i < 0; i++) + tputs(scroll_reverse, 0, __cputchar); + tputs(vtparm(change_scroll_region, + 0, (int) __virtscr->maxy - 1), 0, __cputchar); + __mvcur(top, 0, 0, 0, 1); + tputs(cursor_home, 0, __cputchar); + __mvcur(0, 0, oy, ox, 1); + return; + } + + /* Preserve the bottom lines. */ + __mvcur(oy, ox, bot + n + 1, 0, 1); + if (parm_rindex != NULL && bot == __virtscr->maxy) + tputs(vtparm(parm_rindex, -n), 0, __cputchar); + else + if (parm_delete_line != NULL) + tputs(vtparm(parm_delete_line, -n), + 0, __cputchar); + else + if (delete_line != NULL) + for (i = n; i < 0; i++) + tputs(delete_line, + 0, __cputchar); + else + if (scroll_reverse != NULL && + bot == __virtscr->maxy) + for (i = n; i < 0; i++) + tputs(scroll_reverse, 0, + __cputchar); + else + abort(); + + /* Scroll the block down. */ + __mvcur(bot + n + 1, 0, top, 0, 1); + if (parm_insert_line != NULL) + tputs(vtparm(parm_insert_line, -n), 0, __cputchar); + else + if (insert_line != NULL) + for (i = n; i < 0; i++) + tputs(insert_line, 0, __cputchar); + else + abort(); + __mvcur(top, 0, oy, ox, 1); + } +} + +/* + * __unsetattr -- + * Unset attributes on curscr. Leave standout, attribute and colour + * modes if necessary (!ms). Always leave altcharset (xterm at least + * ignores a cursor move if we don't). + */ +void /* ARGSUSED */ +__unsetattr(int checkms) +{ + int isms; + + if (checkms) + if (!move_standout_mode) { + isms = 1; + } else { + isms = 0; + } + else + isms = 1; +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, + "__unsetattr: checkms = %d, ms = %s, wattr = %08x\n", + checkms, move_standout_mode ? "TRUE" : "FALSE", curscr->wattr); +#endif + + /* + * Don't leave the screen in standout mode (check against ms). Check + * to see if we also turn off underscore, attributes and colour. + */ + if (curscr->wattr & __STANDOUT && isms) { + tputs(exit_standout_mode, 0, __cputchar); + curscr->wattr &= __mask_se; + } + /* + * Don't leave the screen in underscore mode (check against ms). + * Check to see if we also turn off attributes. Assume that we + * also turn off colour. + */ + if (curscr->wattr & __UNDERSCORE && isms) { + tputs(exit_underline_mode, 0, __cputchar); + curscr->wattr &= __mask_ue; + } + /* + * Don't leave the screen with attributes set (check against ms). + * Assume that also turn off colour. + */ + if (curscr->wattr & __TERMATTR && isms) { + tputs(exit_attribute_mode, 0, __cputchar); + curscr->wattr &= __mask_me; + } + /* Don't leave the screen with altcharset set (don't check ms). */ + if (curscr->wattr & __ALTCHARSET) { + tputs(exit_alt_charset_mode, 0, __cputchar); + curscr->wattr &= ~__ALTCHARSET; + } + /* Don't leave the screen with colour set (check against ms). */ + if (__using_color && isms) + __unset_color(curscr); +} + +#ifdef HAVE_WCHAR +/* compare two cells on screen, must have the same forground/background, + * and the same sequence of non-spacing characters */ +int +cellcmp( __LDATA *x, __LDATA *y ) +{ + nschar_t *xnp = x->nsp, *ynp = y->nsp; + int ret = ( x->ch == y->ch ) & ( x->attr == y->attr ); + + if ( !ret ) + return 0; + if ( !xnp && !ynp ) + return 1; + if (( xnp && !ynp ) || ( !xnp && ynp )) + return 0; + + while ( xnp && ynp ) { + if ( xnp->ch != ynp->ch ) + return 0; + xnp = xnp->next; + ynp = ynp->next; + } + return ( !xnp && !ynp ); +} + +/* compare two line segments */ +int +linecmp( __LDATA *xl, __LDATA *yl, size_t len ) +{ + int i = 0; + __LDATA *xp = xl, *yp = yl; + + for ( i = 0; i < len; i++, xp++, yp++ ) { + if ( !cellcmp( xp, yp )) + return 0; + } + return 1; +} + +/* + * Output the non-spacing characters associated with the given character + * cell to the screen. + */ + +void +__cursesi_putnsp(nschar_t *nsp, const int wy, const int wx) +{ + nschar_t *p; + + /* this shuts up gcc warnings about wx and wy not being used */ + if (wx > wy) { + } + + p = nsp; + while (p != NULL) { + __cputwchar((int) p->ch); +#ifdef DEBUG + __CTRACE(__CTRACE_REFRESH, + "_cursesi_putnsp: (%d,%d) non-spacing putwchar(0x%x)\n", + wy, wx - 1, p->ch); +#endif + p = p->next; + } +} + +#endif /* HAVE_WCHAR */ diff --git a/lib/libcurses/resize.c b/lib/libcurses/resize.c new file mode 100644 index 000000000..1f1f4a2ae --- /dev/null +++ b/lib/libcurses/resize.c @@ -0,0 +1,361 @@ +/* $NetBSD: resize.c,v 1.20 2009/07/22 16:57:15 roy Exp $ */ + +/* + * Copyright (c) 2001 + * Brett Lymn. + * + * This code has been donated to The NetBSD Foundation by the Author. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)resize.c blymn 2001/08/26"; +#else +__RCSID("$NetBSD: resize.c,v 1.20 2009/07/22 16:57:15 roy Exp $"); +#endif +#endif /* not lint */ + +#include + +#include "curses.h" +#include "curses_private.h" + +static int __resizeterm(WINDOW *win, int nlines, int ncols); +static int __resizewin(WINDOW *win, int nlines, int ncols); + +/* + * wresize -- + * Resize the given window to the new size. + */ +int +wresize(WINDOW *win, int req_nlines, int req_ncols) +{ + int nlines = req_nlines; + int ncols = req_ncols; + + if (win == NULL) + return ERR; + +#ifdef DEBUG + __CTRACE(__CTRACE_WINDOW, "wresize: (%p, %d, %d)\n", + win, nlines, ncols); +#endif + if (win->orig == NULL) { + /* bound "our" windows by the screen size */ + if (win == curscr || win == __virtscr || win == stdscr) { + if (nlines > LINES) + nlines = LINES; + if (nlines < 1) + nlines = 1; + if (ncols > COLS) + ncols = COLS; + if (ncols < 1) + ncols = 1; + } else { + if (win->begy > LINES) + win->begy = 0; + if (win->begy + nlines > LINES) + nlines = 0; + if (nlines <= 0) + nlines += LINES - win->begy; + if (nlines < 1) + nlines = 1; + if (win->begx > COLS) + win->begx = 0; + if (win->begx + ncols > COLS) + ncols = 0; + if (ncols <= 0) + ncols += COLS - win->begx; + if (ncols < 1) + ncols = 1; + } + } else { + /* subwins must fit inside the parent - check this */ + if (win->begy > win->orig->begy + win->orig->maxy) + win->begy = win->orig->begy + win->orig->maxy - 1; + if (win->begy + nlines > win->orig->begy + win->orig->maxy) + nlines = 0; + if (nlines <= 0) + nlines += win->orig->begy + win->orig->maxy - win->begy; + if (nlines < 1) + nlines = 1; + if (win->begx > win->orig->begx + win->orig->maxx) + win->begx = win->orig->begx + win->orig->maxx - 1; + if (win->begx + ncols > win->orig->begx + win->orig->maxx) + ncols = 0; + if (ncols <= 0) + ncols += win->orig->begx + win->orig->maxx - win->begx; + if (ncols < 1) + ncols = 1; + } + + if ((__resizewin(win, nlines, ncols)) == ERR) + return ERR; + + win->reqy = req_nlines; + win->reqx = req_ncols; + + /* If someone resizes curscr, we must also resize __virtscr */ + if (win == curscr) { + if ((__resizewin(__virtscr, nlines, ncols)) == ERR) + return ERR; + __virtscr->reqy = req_nlines; + __virtscr->reqx = req_ncols; + } + + return OK; +} + +/* + * resizeterm -- + * Resize the terminal window, resizing the dependent windows. + */ +int +resizeterm(int nlines, int ncols) +{ + WINDOW *win; + struct __winlist *list; + +#ifdef DEBUG + __CTRACE(__CTRACE_WINDOW, "resizeterm: (%d, %d)\n", nlines, ncols); +#endif + + if (__resizeterm(curscr, nlines, ncols) == ERR) + return ERR; + if (__resizeterm(__virtscr, nlines, ncols) == ERR) + return ERR; + if (__resizeterm(stdscr, nlines, ncols) == ERR) + return ERR; + + LINES = nlines; + COLS = ncols; + + /* tweak the flags now that we have updated the LINES and COLS */ + for (list = _cursesi_screen->winlistp; list != NULL; list = list->nextp) { + win = list->winp; + + if (!(win->flags & __ISPAD)) + __swflags(win); + } + + wrefresh(curscr); + return OK; +} + +/* + * __resizeterm + * Setup window for resizing. + */ +static int +__resizeterm(WINDOW *win, int nlines, int ncols) +{ + int newlines, newcols; + + newlines = win->reqy; + if (win->begy + newlines >= nlines) + newlines = 0; + if (newlines == 0) + newlines = nlines - win->begy; + + newcols = win->reqx; + if (win->begx + newcols >= ncols) + newcols = 0; + if (newcols == 0) + newcols = ncols - win->begx; + + return __resizewin(win, newlines, newcols); +} + +/* + * __resizewin -- + * Resize the given window. + */ +static int +__resizewin(WINDOW *win, int nlines, int ncols) +{ + __LINE *lp, *olp, **newlines, *newlspace; + __LDATA *sp; + __LDATA *newwspace; + int i, j; + int y, x; + WINDOW *swin; + +#ifdef DEBUG + __CTRACE(__CTRACE_WINDOW, "resize: (%p, %d, %d)\n", win, nlines, ncols); + __CTRACE(__CTRACE_WINDOW, "resize: win->wattr = %08x\n", win->wattr); + __CTRACE(__CTRACE_WINDOW, "resize: win->flags = %#.4x\n", win->flags); + __CTRACE(__CTRACE_WINDOW, "resize: win->maxy = %d\n", win->maxy); + __CTRACE(__CTRACE_WINDOW, "resize: win->maxx = %d\n", win->maxx); + __CTRACE(__CTRACE_WINDOW, "resize: win->begy = %d\n", win->begy); + __CTRACE(__CTRACE_WINDOW, "resize: win->begx = %d\n", win->begx); + __CTRACE(__CTRACE_WINDOW, "resize: win->scr_t = %d\n", win->scr_t); + __CTRACE(__CTRACE_WINDOW, "resize: win->scr_b = %d\n", win->scr_b); +#endif + + /* + * free up any non-spacing storage before we lose the + * pointers... + */ +#ifdef HAVE_WCHAR + __cursesi_win_free_nsp(win); +#endif + + if (nlines <= 0 || ncols <= 0) + nlines = ncols = 0; + else { + /* Reallocate line pointer array and line space. */ + newlines = realloc(win->alines, nlines * sizeof(__LINE *)); + if (newlines == NULL) + return ERR; + win->alines = newlines; + + newlspace = realloc(win->lspace, nlines * sizeof(__LINE)); + if (newlspace == NULL) + return ERR; + win->lspace = newlspace; + } + + /* Don't allocate window and line space if it's a subwindow */ + if (win->orig == NULL) { + /* + * Allocate window space in one chunk. + */ + if (ncols != 0) { + newwspace = realloc(win->wspace, + ncols * nlines * sizeof(__LDATA)); + if (newwspace == NULL) + return ERR; + win->wspace = newwspace; + } + + /* + * Point line pointers to line space, and lines themselves into + * window space. + */ + for (lp = win->lspace, i = 0; i < nlines; i++, lp++) { + win->alines[i] = lp; + lp->line = &win->wspace[i * ncols]; +#ifdef DEBUG + lp->sentinel = SENTINEL_VALUE; +#endif + lp->firstchp = &lp->firstch; + lp->lastchp = &lp->lastch; + lp->firstch = 0; + lp->lastch = ncols - 1; + lp->flags = __ISDIRTY; + } + } else { + + win->ch_off = win->begx - win->orig->begx; + /* Point line pointers to line space. */ + for (lp = win->lspace, i = 0; i < nlines; i++, lp++) { + win->alines[i] = lp; + olp = win->orig->alines[i + win->begy - win->orig->begy]; + lp->line = &olp->line[win->ch_off]; +#ifdef DEBUG + lp->sentinel = SENTINEL_VALUE; +#endif + lp->firstchp = &olp->firstch; + lp->lastchp = &olp->lastch; + lp->flags = __ISDIRTY; + } + } + + + win->cury = win->curx = 0; + win->maxy = nlines; + win->maxx = ncols; + win->scr_b = win->maxy - 1; + __swflags(win); + + /* + * we must zot the window contents otherwise lines may pick + * up attributes from the previous line when the window is + * made smaller. The client will redraw the window anyway + * so this is no big deal. + */ + for (i = 0; i < win->maxy; i++) { + lp = win->alines[i]; + for (sp = lp->line, j = 0; j < win->maxx; j++, sp++) { + sp->attr = 0; +#ifndef HAVE_WCHAR + sp->ch = win->bch; +#else + sp->ch = ( wchar_t )btowc(( int ) win->bch ); + sp->nsp = NULL; + if (_cursesi_copy_nsp(win->bnsp, sp) == ERR) + return ERR; + SET_WCOL( *sp, 1 ); +#endif /* HAVE_WCHAR */ + } + lp->hash = __hash((char *)(void *)lp->line, + (size_t) (ncols * __LDATASIZE)); + } + +#ifdef DEBUG + __CTRACE(__CTRACE_WINDOW, "resize: win->wattr = %08x\n", win->wattr); + __CTRACE(__CTRACE_WINDOW, "resize: win->flags = %#.4x\n", win->flags); + __CTRACE(__CTRACE_WINDOW, "resize: win->maxy = %d\n", win->maxy); + __CTRACE(__CTRACE_WINDOW, "resize: win->maxx = %d\n", win->maxx); + __CTRACE(__CTRACE_WINDOW, "resize: win->begy = %d\n", win->begy); + __CTRACE(__CTRACE_WINDOW, "resize: win->begx = %d\n", win->begx); + __CTRACE(__CTRACE_WINDOW, "resize: win->scr_t = %d\n", win->scr_t); + __CTRACE(__CTRACE_WINDOW, "resize: win->scr_b = %d\n", win->scr_b); +#endif + + if (win->orig == NULL) { + /* bound subwindows to new size and fixup their pointers */ + for (swin = win->nextp; swin != win; swin = swin->nextp) { + y = swin->reqy; + if (swin->begy > win->begy + win->maxy) + swin->begy = win->begy + win->maxy - 1; + if (swin->begy + y > win->begy + win->maxy) + y = 0; + if (y <= 0) + y += win->begy + win->maxy - swin->begy; + if (y < 1) + y = 1; + x = swin->reqx; + if (swin->begx > win->begx + win->maxx) + swin->begx = win->begx + win->maxx - 1; + if (swin->begx + x > win->begx + win->maxx) + x = 0; + if (x <= 0) + x += win->begy + win->maxx - swin->begx; + if (x < 1) + x = 1; + __resizewin(swin, y, x); + } + } + + return OK; +} diff --git a/lib/libcurses/scanw.c b/lib/libcurses/scanw.c new file mode 100644 index 000000000..deeb47365 --- /dev/null +++ b/lib/libcurses/scanw.c @@ -0,0 +1,125 @@ +/* $NetBSD: scanw.c,v 1.20 2009/07/07 10:16:52 joerg Exp $ */ + +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)scanw.c 8.3 (Berkeley) 5/4/94"; +#else +__RCSID("$NetBSD: scanw.c,v 1.20 2009/07/07 10:16:52 joerg Exp $"); +#endif +#endif /* not lint */ + +/* + * scanw and friends. + */ + +#include + +#include "curses.h" + +/* + * scanw -- + * Implement a scanf on the standard screen. + */ +int +scanw(const char *fmt,...) +{ + va_list ap; + int ret; + + va_start(ap, fmt); + ret = vw_scanw(stdscr, fmt, ap); + va_end(ap); + return (ret); +} +/* + * wscanw -- + * Implements a scanf on the given window. + */ +int +wscanw(WINDOW *win, const char *fmt,...) +{ + va_list ap; + int ret; + + va_start(ap, fmt); + ret = vw_scanw(win, fmt, ap); + va_end(ap); + return (ret); +} +/* + * mvscanw, mvwscanw -- + * Implement the mvscanw commands. Due to the variable number of + * arguments, they cannot be macros. Another sigh.... + */ +int +mvscanw(int y, int x, const char *fmt,...) +{ + va_list ap; + int ret; + + if (move(y, x) != OK) + return (ERR); + va_start(ap, fmt); + ret = vw_scanw(stdscr, fmt, ap); + va_end(ap); + return (ret); +} + +int +mvwscanw(WINDOW * win, int y, int x, const char *fmt,...) +{ + va_list ap; + int ret; + + if (move(y, x) != OK) + return (ERR); + va_start(ap, fmt); + ret = vw_scanw(win, fmt, ap); + va_end(ap); + return (ret); +} +/* + * vwscanw -- + * This routine actually executes the scanf from the window. + */ +int +vw_scanw(WINDOW *win, const char *fmt, _BSD_VA_LIST_ ap) +{ + + char buf[1024]; + + return (wgetnstr(win, buf, (int) sizeof(buf)) == OK ? + vsscanf(buf, fmt, ap) : ERR); +} + +__strong_alias(vwscanw, vw_scanw) diff --git a/lib/libcurses/screen.c b/lib/libcurses/screen.c new file mode 100644 index 000000000..439dcff41 --- /dev/null +++ b/lib/libcurses/screen.c @@ -0,0 +1,246 @@ +/* $NetBSD: screen.c,v 1.23 2010/06/10 05:24:55 dholland Exp $ */ + +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)screen.c 8.2 (blymn) 11/27/2001"; +#else +__RCSID("$NetBSD: screen.c,v 1.23 2010/06/10 05:24:55 dholland Exp $"); +#endif +#endif /* not lint */ + +#include + +#include "curses.h" +#include "curses_private.h" + +/* + * set_term -- + * Change the term to the given screen. + * + */ +SCREEN * +set_term(SCREEN *new) +{ + SCREEN *old_screen = _cursesi_screen; + + if (_cursesi_screen != NULL) { + /* save changes made to the current screen... */ + old_screen->echoit = __echoit; + old_screen->pfast = __pfast; + old_screen->rawmode = __rawmode; + old_screen->noqch = __noqch; + old_screen->COLS = COLS; + old_screen->LINES = LINES; + old_screen->COLORS = COLORS; + old_screen->COLOR_PAIRS = COLOR_PAIRS; + old_screen->GT = __GT; + old_screen->NONL = __NONL; + old_screen->UPPERCASE = __UPPERCASE; + } + + _cursesi_screen = new; + + __echoit = new->echoit; + __pfast = new->pfast; + __rawmode = new->rawmode; + __noqch = new->noqch; + COLS = new->COLS; + LINES = new->LINES; + COLORS = new->COLORS; + COLOR_PAIRS = new->COLOR_PAIRS; + __GT = new->GT; + __NONL = new->NONL; + __UPPERCASE = new->UPPERCASE; + + _cursesi_resetterm(new); + + curscr = new->curscr; + clearok(curscr, new->clearok); + stdscr = new->stdscr; + __virtscr = new->__virtscr; + + _cursesi_reset_acs(new); +#ifdef HAVE_WCHAR + _cursesi_reset_wacs(new); +#endif /* HAVE_WCHAR */ + +#ifdef DEBUG + __CTRACE(__CTRACE_SCREEN, "set_term: LINES = %d, COLS = %d\n", + LINES, COLS); +#endif + + return old_screen; +} + +/* + * newterm -- + * Set up a new screen. + * + */ +SCREEN * +newterm(char *type, FILE *outfd, FILE *infd) +{ + SCREEN *new_screen; + char *sp; + + sp = type; + if ((type == NULL) && (sp = getenv("TERM")) == NULL) + return NULL; + + if ((new_screen = calloc(1, sizeof(SCREEN))) == NULL) + return NULL; + +#ifdef DEBUG + __CTRACE(__CTRACE_INIT, "newterm\n"); +#endif + + new_screen->infd = infd; + new_screen->outfd = outfd; + new_screen->echoit = new_screen->nl = 1; + new_screen->pfast = new_screen->rawmode = new_screen->noqch = 0; + new_screen->nca = A_NORMAL; + new_screen->color_type = COLOR_NONE; + new_screen->COLOR_PAIRS = 0; + new_screen->old_mode = 2; + new_screen->stdbuf = NULL; + new_screen->stdscr = NULL; + new_screen->curscr = NULL; + new_screen->__virtscr = NULL; + new_screen->curwin = 0; + new_screen->notty = FALSE; + new_screen->half_delay = FALSE; + new_screen->resized = 0; + new_screen->unget_len = 32; + + if ((new_screen->unget_list = + malloc(sizeof(wchar_t) * new_screen->unget_len)) == NULL) { + goto error_exit; + } + new_screen->unget_pos = 0; + + if (_cursesi_gettmode(new_screen) == ERR) + goto error_exit; + + if (_cursesi_setterm((char *)sp, new_screen) == ERR) + goto error_exit; + + /* Need either homing or cursor motion for refreshes */ + if (!t_cursor_home(new_screen->term) && + !t_cursor_address(new_screen->term)) + goto error_exit; + + new_screen->winlistp = NULL; + + if ((new_screen->curscr = __newwin(new_screen, 0, + 0, 0, 0, FALSE)) == NULL) + goto error_exit; + + if ((new_screen->stdscr = __newwin(new_screen, 0, + 0, 0, 0, FALSE)) == NULL) { + delwin(new_screen->curscr); + goto error_exit; + } + + clearok(new_screen->stdscr, 1); + + if ((new_screen->__virtscr = __newwin(new_screen, 0, + 0, 0, 0, FALSE)) == NULL) { + delwin(new_screen->curscr); + delwin(new_screen->stdscr); + goto error_exit; + } + + __init_getch(new_screen); + __init_acs(new_screen); +#ifdef HAVE_WCHAR + __init_get_wch( new_screen ); + __init_wacs(new_screen); +#endif /* HAVE_WCHAR */ + + __set_stophandler(); + __set_winchhandler(); + + /* + * bleh - it seems that apps expect the first newterm to set + * up the curses screen.... emulate this. + */ + if (_cursesi_screen == NULL || _cursesi_screen->endwin) { + set_term(new_screen); + } + +#ifdef DEBUG + __CTRACE(__CTRACE_SCREEN, "newterm: LINES = %d, COLS = %d\n", + LINES, COLS); +#endif + __startwin(new_screen); + + return new_screen; + + error_exit: + free(new_screen); + return NULL; +} + +/* + * delscreen -- + * Free resources used by the given screen and destroy it. + * + */ +void +delscreen(SCREEN *screen) +{ + struct __winlist *list; + +#ifdef DEBUG + __CTRACE(__CTRACE_SCREEN, "delscreen(%p)\n", screen); +#endif + /* free up the terminfo stuff */ + del_curterm(screen->term); + + /* walk the window list and kill all the parent windows */ + while ((list = screen->winlistp) != NULL) { + delwin(list->winp); + if (list == screen->winlistp) + /* sanity - abort if window didn't remove itself */ + break; + } + + /* free the storage of the keymaps */ + _cursesi_free_keymap(screen->base_keymap); + + free(screen->stdbuf); + screen->stdbuf = NULL; + if (_cursesi_screen == screen) + _cursesi_screen = NULL; + free(screen); +} diff --git a/lib/libcurses/scroll.c b/lib/libcurses/scroll.c new file mode 100644 index 000000000..b64db040c --- /dev/null +++ b/lib/libcurses/scroll.c @@ -0,0 +1,158 @@ +/* $NetBSD: scroll.c,v 1.22 2010/02/03 15:34:40 roy Exp $ */ + +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)scroll.c 8.3 (Berkeley) 5/4/94"; +#else +__RCSID("$NetBSD: scroll.c,v 1.22 2010/02/03 15:34:40 roy Exp $"); +#endif +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +/* + * scroll -- + * Scroll the window up a line. + */ +int +scroll(WINDOW *win) +{ + return(wscrl(win, 1)); +} + +#ifndef _CURSES_USE_MACROS + +/* + * scrl -- + * Scroll stdscr n lines - up if n is positive, down if n is negative. + */ +int +scrl(int nlines) +{ + return wscrl(stdscr, nlines); +} + +/* + * setscrreg -- + * Set the top and bottom of the scrolling region for stdscr. + */ +int +setscrreg(int top, int bottom) +{ + return wsetscrreg(stdscr, top, bottom); +} + +#endif + +/* + * wscrl -- + * Scroll a window n lines - up if n is positive, down if n is negative. + */ +int +wscrl(WINDOW *win, int nlines) +{ + int oy, ox; + +#ifdef DEBUG + __CTRACE(__CTRACE_WINDOW, "wscrl: (%p) lines=%d\n", win, nlines); +#endif + + if (!(win->flags & __SCROLLOK)) + return (ERR); + if (!nlines) + return (OK); + + getyx(win, oy, ox); +#ifdef DEBUG + __CTRACE(__CTRACE_WINDOW, "wscrl: y=%d\n", oy); +#endif + if (oy < win->scr_t || oy > win->scr_b) + /* Outside scrolling region */ + wmove(win, 0, 0); + else + /* Inside scrolling region */ + wmove(win, win->scr_t, 0); + winsdelln(win, 0 - nlines); + wmove(win, oy, ox); + + if (win == curscr) { + __cputchar('\n'); + if (!__NONL) + win->curx = 0; +#ifdef DEBUG + __CTRACE(__CTRACE_WINDOW, "scroll: win == curscr\n"); +#endif + } + return (OK); +} + +/* + * wsetscrreg -- + * Set the top and bottom of the scrolling region for win. + */ +int +wsetscrreg(WINDOW *win, int top, int bottom) +{ + if (top < 0 || bottom >= win->maxy || bottom - top < 1) + return (ERR); + win->scr_t = top; + win->scr_b = bottom; + return (OK); +} + +/* + * has_ic -- + * Does the terminal have insert- and delete-character? + */ +bool +has_ic(void) +{ + if (insert_character != NULL && delete_character != NULL) + return (TRUE); + else + return (FALSE); +} + +/* + * has_ic -- + * Does the terminal have insert- and delete-line? + */ +bool +has_il(void) +{ + if (insert_line !=NULL && delete_line != NULL) + return (TRUE); + else + return (FALSE); +} diff --git a/lib/libcurses/scrollok.c b/lib/libcurses/scrollok.c new file mode 100644 index 000000000..59ecb207c --- /dev/null +++ b/lib/libcurses/scrollok.c @@ -0,0 +1,52 @@ +/* $NetBSD: scrollok.c,v 1.5 2008/04/28 20:23:01 martin Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Julian Coleman. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: scrollok.c,v 1.5 2008/04/28 20:23:01 martin Exp $"); +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +/* + * scrollok -- + * Turn on and off scrolling for the given window. + */ +int +scrollok(WINDOW *win, bool bf) +{ + if (bf) + win->flags |= __SCROLLOK; + else + win->flags &= ~__SCROLLOK; + return (OK); +} diff --git a/lib/libcurses/scrreg.c b/lib/libcurses/scrreg.c deleted file mode 100644 index 0b3c944dc..000000000 --- a/lib/libcurses/scrreg.c +++ /dev/null @@ -1,58 +0,0 @@ -/****************************************************************/ -/* Wsetscrreg() routine of the PCcurses package */ -/* */ -/****************************************************************/ -/* This version of curses is based on ncurses, a curses version */ -/* Originally written by Pavel Curtis at Cornell University. */ -/* I have made substantial changes to make it run on IBM PC's, */ -/* And therefore consider myself free to make it public domain. */ -/* Bjorn Larsson (...mcvax!enea!infovax!bl) */ -/****************************************************************/ -/* 1.0: Release: 870515 */ -/****************************************************************/ -/* Modified to run under the MINIX operating system by Don Cope */ -/* These changes are also released into the public domain. */ -/* 900906 */ -/****************************************************************/ - -#include -#include "curspriv.h" - -/****************************************************************/ -/* Wsetscrreg() set the scrolling region of window 'win' to in- */ -/* Clude all lines between 'top' and 'bottom'. */ -/****************************************************************/ - -int wsetscrreg(win, top, bottom) -WINDOW *win; -int top; -int bottom; -{ - if ((0 <= top) && - (top <= win->_cury) - && - (win->_cury <= bottom) - && - (bottom <= win->_maxy) - ) { - win->_regtop = top; - win->_regbottom = bottom; - return(OK); - } - - /* If */ - else - return(ERR); -} /* wsetscrreg */ - -/****************************************************************/ -/* Setscrreg() set the scrolling region of stdscr to include */ -/* All lines between 'top' and 'bottom'. */ -/****************************************************************/ - -int setscrreg(top, bottom) -int top; -int bottom; -{ - return(wsetscrreg(stdscr, top, bottom)); -} /* setscrreg */ diff --git a/lib/libcurses/setterm.c b/lib/libcurses/setterm.c index ac3c30925..832fe6749 100644 --- a/lib/libcurses/setterm.c +++ b/lib/libcurses/setterm.c @@ -1,76 +1,360 @@ -#include -#include "curspriv.h" +/* $NetBSD: setterm.c,v 1.47 2010/02/11 11:45:47 roy Exp $ */ -_PROTOTYPE( static void ttysetflags, (void) ); +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ -static void ttysetflags() -{ - _tty.c_iflag |= ICRNL | IXON; - _tty.c_oflag |= OPOST | ONLCR; - _tty.c_lflag |= ECHO | ICANON | IEXTEN | ISIG; - - if (_cursvar.rawmode) { - _tty.c_iflag &= ~(ICRNL | IXON); - _tty.c_oflag &= ~(OPOST); - _tty.c_lflag &= ~(ICANON | IEXTEN | ISIG); - } - if (_cursvar.cbrkmode) { - _tty.c_lflag &= ~(ICANON); - } - if (!_cursvar.echoit) { - _tty.c_lflag &= ~(ECHO | ECHONL); - } - if (NONL) { - _tty.c_iflag &= ~(ICRNL); - _tty.c_oflag &= ~(ONLCR); - } - tcsetattr(0, TCSANOW, &_tty); -} /* ttysetflags */ - -void raw() -{ - _cursvar.rawmode = TRUE; - ttysetflags(); -} /* raw */ +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)setterm.c 8.8 (Berkeley) 10/25/94"; +#else +__RCSID("$NetBSD: setterm.c,v 1.47 2010/02/11 11:45:47 roy Exp $"); +#endif +#endif /* not lint */ -void noraw() -{ - _cursvar.rawmode = FALSE; - ttysetflags(); -} /* noraw */ +#include /* TIOCGWINSZ on old systems. */ + +#include +#include +#include +#include + +#include "curses.h" +#include "curses_private.h" + +static int does_esc_m(const char *cap); +static int does_ctrl_o(const char *cap); + +attr_t __mask_op, __mask_me, __mask_ue, __mask_se; -void echo() +int +setterm(char *type) { - _cursvar.echoit = TRUE; - ttysetflags(); + return _cursesi_setterm(type, _cursesi_screen); } -void noecho() +int +_cursesi_setterm(char *type, SCREEN *screen) { - _cursvar.echoit = FALSE; - ttysetflags(); + int unknown, r; + struct winsize win; + char *p; + + if (type[0] == '\0') + type = "xx"; + unknown = 0; + (void)ti_setupterm(&screen->term, type, fileno(screen->outfd), &r); + if (screen->term == NULL) { + unknown++; + (void)ti_setupterm(&screen->term, "dumb", + fileno(screen->outfd), &r); + /* No dumb term? We can't continue */ + if (screen->term == NULL) + return ERR; + } +#ifdef DEBUG + __CTRACE(__CTRACE_INIT, "setterm: tty = %s\n", type); +#endif + + /* Try TIOCGWINSZ, and, if it fails, the termcap entry. */ + if (ioctl(fileno(screen->outfd), TIOCGWINSZ, &win) != -1 && + win.ws_row != 0 && win.ws_col != 0) { + screen->LINES = win.ws_row; + screen->COLS = win.ws_col; + } else { + if (unknown) { + screen->LINES = -1; + screen->COLS = -1; + } else { + screen->LINES = t_lines(screen->term); + screen->COLS = t_columns(screen->term); + } + + } + + /* POSIX 1003.2 requires that the environment override. */ + if ((p = getenv("LINES")) != NULL) + screen->LINES = (int) strtol(p, NULL, 0); + if ((p = getenv("COLUMNS")) != NULL) + screen->COLS = (int) strtol(p, NULL, 0); + if ((p = getenv("ESCDELAY")) != NULL) + ESCDELAY = (int) strtol(p, NULL, 0); + + /* + * Want cols > 4, otherwise things will fail. + */ + if (screen->COLS <= 4) + return (ERR); + + LINES = screen->LINES; + COLS = screen->COLS; + +#ifdef DEBUG + __CTRACE(__CTRACE_INIT, "setterm: LINES = %d, COLS = %d\n", + LINES, COLS); +#endif + + /* + * set the pad char, only take the first char of the pc capability + * as this is all we can use. + */ + screen->padchar = t_pad_char(screen->term) ? + t_pad_char(screen->term)[0] : 0; + + /* Get full name of terminal */ + if (unknown) { + strcpy(screen->ttytype, "dumb"); + return ERR; + } + if (screen->term->desc == NULL) + screen->ttytype[0] = '\0'; + else + strlcpy(screen->ttytype, screen->term->desc, + sizeof(screen->ttytype)); + + /* If no scrolling commands, no quick change. */ + screen->noqch = + (t_change_scroll_region(screen->term) == NULL || + t_cursor_home(screen->term) == NULL || + (t_parm_index(screen->term) == NULL && + t_scroll_forward(screen->term) == NULL) || + (t_parm_rindex(screen->term) == NULL && + t_scroll_reverse(screen->term) == NULL)) && + ((t_parm_insert_line(screen->term) == NULL && + t_insert_line(screen->term) == NULL) || + (t_parm_delete_line(screen->term) == NULL && + t_delete_line(screen->term) == NULL)); + + /* + * Precalculate conflict info for color/attribute end commands. + */ +#ifndef HAVE_WCHAR + screen->mask_op = __ATTRIBUTES & ~__COLOR; +#else + screen->mask_op = WA_ATTRIBUTES & ~__COLOR; +#endif /* HAVE_WCHAR */ + if (t_orig_pair(screen->term) != NULL) { + if (does_esc_m(t_orig_pair(screen->term))) + screen->mask_op &= + ~(__STANDOUT | __UNDERSCORE | __TERMATTR); + else { + if (t_exit_standout_mode(screen->term) != NULL && + !strcmp(t_orig_pair(screen->term), + t_exit_standout_mode(screen->term))) + screen->mask_op &= ~__STANDOUT; + if (t_exit_underline_mode(screen->term) != NULL && + !strcmp(t_orig_pair(screen->term), + t_exit_underline_mode(screen->term))) + screen->mask_op &= ~__UNDERSCORE; + if (t_exit_attribute_mode(screen->term) != NULL && + !strcmp(t_orig_pair(screen->term), + t_exit_attribute_mode(screen->term))) + screen->mask_op &= ~__TERMATTR; + } + } + /* + * Assume that "me" turns off all attributes apart from ACS. + * It might turn off ACS, so check for that. + */ + if (t_exit_attribute_mode(screen->term) != NULL && + does_ctrl_o(t_exit_attribute_mode(screen->term))) + screen->mask_me = 0; + else + screen->mask_me = __ALTCHARSET; + + /* Check what turning off the attributes also turns off */ +#ifndef HAVE_WCHAR + screen->mask_ue = __ATTRIBUTES & ~__UNDERSCORE; +#else + screen->mask_ue = WA_ATTRIBUTES & ~__UNDERSCORE; +#endif /* HAVE_WCHAR */ + if (t_exit_underline_mode(screen->term) != NULL) { + if (does_esc_m(t_exit_underline_mode(screen->term))) + screen->mask_ue &= + ~(__STANDOUT | __TERMATTR | __COLOR); + else { + if (t_exit_standout_mode(screen->term) != NULL && + !strcmp(t_exit_underline_mode(screen->term), + t_exit_standout_mode(screen->term))) + screen->mask_ue &= ~__STANDOUT; + if (t_exit_attribute_mode(screen->term) != NULL && + !strcmp(t_exit_underline_mode(screen->term), + t_exit_attribute_mode(screen->term))) + screen->mask_ue &= ~__TERMATTR; + if (t_orig_pair(screen->term) != NULL && + !strcmp(t_exit_underline_mode(screen->term), + t_orig_pair(screen->term))) + screen->mask_ue &= ~__COLOR; + } + } +#ifndef HAVE_WCHAR + screen->mask_se = __ATTRIBUTES & ~__STANDOUT; +#else + screen->mask_se = WA_ATTRIBUTES & ~__STANDOUT; +#endif /* HAVE_WCHAR */ + if (t_exit_standout_mode(screen->term) != NULL) { + if (does_esc_m(t_exit_standout_mode(screen->term))) + screen->mask_se &= + ~(__UNDERSCORE | __TERMATTR | __COLOR); + else { + if (t_exit_underline_mode(screen->term) != NULL && + !strcmp(t_exit_standout_mode(screen->term), + t_exit_underline_mode(screen->term))) + screen->mask_se &= ~__UNDERSCORE; + if (t_exit_attribute_mode(screen->term) != NULL && + !strcmp(t_exit_standout_mode(screen->term), + t_exit_attribute_mode(screen->term))) + screen->mask_se &= ~__TERMATTR; + if (t_orig_pair(screen->term) != NULL && + !strcmp(t_exit_standout_mode(screen->term), + t_orig_pair(screen->term))) + screen->mask_se &= ~__COLOR; + } + } + + return (unknown ? ERR : OK); } -void nl() +/* + * _cursesi_resetterm -- + * Copy the terminal instance data for the given screen to the global + * variables. + */ +void +_cursesi_resetterm(SCREEN *screen) { - NONL = FALSE; - ttysetflags(); -} /* nl */ -void nonl() -{ - NONL = TRUE; - ttysetflags(); -} /* nonl */ + LINES = screen->LINES; + COLS = screen->COLS; + __GT = screen->GT; + + __noqch = screen->noqch; + __mask_op = screen->mask_op; + __mask_me = screen->mask_me; + __mask_ue = screen->mask_ue; + __mask_se = screen->mask_se; -void cbreak() + set_curterm(screen->term); +} + +/* + * does_esc_m -- + * A hack for xterm-like terminals where "\E[m" or "\E[0m" will turn off + * other attributes, so we check for this in the capability passed to us. + * Note that we can't just do simple string comparison, as the capability + * may contain multiple, ';' separated sequence parts. + */ +static int +does_esc_m(const char *cap) { - _cursvar.cbrkmode = TRUE; - ttysetflags(); -} /* cbreak */ +#define WAITING 0 +#define PARSING 1 +#define NUMBER 2 +#define FOUND 4 + const char *capptr; + int seq; -void nocbreak() +#ifdef DEBUG + __CTRACE(__CTRACE_INIT, "does_esc_m: Checking %s\n", cap); +#endif + /* Is it just "\E[m" or "\E[0m"? */ + if (!strcmp(cap, "\x1b[m") || !strcmp(cap, "\x1b[0m")) + return 1; + + /* Does it contain a "\E[...m" sequence? */ + if (strlen(cap) < 4) + return 0; + capptr = cap; + seq = WAITING; + while (*capptr != 0) { + switch (seq) { + /* Start of sequence */ + case WAITING: + if (!strncmp(capptr, "\x1b[", 2)) { + capptr+=2; + if (*capptr == 'm') + return 1; + else { + seq=PARSING; + continue; + } + } + break; + /* Looking for '0' */ + case PARSING: + if (*capptr == '0') + seq=FOUND; + else if (*capptr > '0' && *capptr <= '9') + seq=NUMBER; + else if (*capptr != ';') + seq=WAITING; + break; + /* Some other number */ + case NUMBER: + if (*capptr == ';') + seq=PARSING; + else if (!(*capptr >= '0' && *capptr <= '9')) + seq=WAITING; + break; + /* Found a '0' */ + case FOUND: + if (*capptr == 'm') + return 1; + else if (!((*capptr >= '0' && *capptr <= '9') || + *capptr == ';')) + seq=WAITING; + break; + default: + break; + } + capptr++; + } + return 0; +} + +/* + * does_ctrl_o -- + * A hack for vt100/xterm-like terminals where the "me" capability also + * unsets acs (i.e. it contains the character '\017'). + */ +static int +does_ctrl_o(const char *cap) { - _cursvar.cbrkmode = FALSE; - ttysetflags(); -} /* nocbreak */ + const char *capptr = cap; + +#ifdef DEBUG + __CTRACE(__CTRACE_INIT, "does_ctrl_o: Looping on %s\n", capptr); +#endif + while (*capptr != 0) { + if (*capptr == '\x0f') + return 1; + capptr++; + } + return 0; +} diff --git a/lib/libcurses/shlib_version b/lib/libcurses/shlib_version new file mode 100644 index 000000000..1c7107b66 --- /dev/null +++ b/lib/libcurses/shlib_version @@ -0,0 +1,8 @@ +# $NetBSD: shlib_version,v 1.40 2009/01/11 03:07:47 christos Exp $ +# Remember to update distrib/sets/lists/base/shl.* when changing +# Remember to run `make fileio.h` when changing +# Remember to increment the major numbers of both libform and libmenu +# when the libcurses major number increments. +# +major=7 +minor=0 diff --git a/lib/libcurses/standout.c b/lib/libcurses/standout.c new file mode 100644 index 000000000..fb9531bc8 --- /dev/null +++ b/lib/libcurses/standout.c @@ -0,0 +1,94 @@ +/* $NetBSD: standout.c,v 1.16 2010/02/03 15:34:40 roy Exp $ */ + +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)standout.c 8.3 (Berkeley) 8/10/94"; +#else +__RCSID("$NetBSD: standout.c,v 1.16 2010/02/03 15:34:40 roy Exp $"); +#endif +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +#ifndef _CURSES_USE_MACROS + +/* + * standout -- + * Enter standout mode on stdscr. + */ +int +standout(void) +{ + return wstandout(stdscr); +} + +/* + * standend -- + * Exit standout mode on stdscr. + */ +int +standend(void) +{ + return wstandend(stdscr); +} + +#endif + +/* + * wstandout -- + * Enter standout mode in window win. + */ +int +wstandout(WINDOW *win) +{ + /* + * If standout/standend strings, or can underline, set the + * screen standout bit. + */ + if ((enter_standout_mode != NULL && exit_standout_mode != NULL) || + underline_char != NULL) + win->wattr |= __STANDOUT; + return (1); +} + +/* + * wstandend -- + * Exit standout mode in window win. + */ +int +wstandend(WINDOW *win) +{ + win->wattr &= ~__STANDOUT; + return (1); +} diff --git a/lib/libcurses/tabsize.c b/lib/libcurses/tabsize.c deleted file mode 100644 index 9fd6230d9..000000000 --- a/lib/libcurses/tabsize.c +++ /dev/null @@ -1,50 +0,0 @@ -/****************************************************************/ -/* Tabsize() routines of the PCcurses package */ -/* */ -/****************************************************************/ -/* This version of curses is based on ncurses, a curses version */ -/* Originally written by Pavel Curtis at Cornell University. */ -/* I have made substantial changes to make it run on IBM PC's, */ -/* And therefore consider myself free to make it public domain. */ -/* Bjorn Larsson (...mcvax!enea!infovax!bl) */ -/****************************************************************/ -/* 1.0: Release: 870515 */ -/****************************************************************/ -/* Modified to run under the MINIX operating system by Don Cope */ -/* These changes are also released into the public domain. */ -/* 900906 */ -/****************************************************************/ - -#include -#include "curspriv.h" - -/****************************************************************/ -/* Wtabsize(win,ts) sets the tabsize of window 'win' to 'ts', */ -/* And returns the original value. */ -/****************************************************************/ - -int wtabsize(win, ts) -WINDOW *win; -int ts; -{ - int origval; - - origval = win->_tabsize; - win->_tabsize = ts; - return(origval); -} /* wtabsize */ - -/****************************************************************/ -/* Tabsize(ts) sets the tabsize of stdscr to 'ts', and returns */ -/* The original value. */ -/****************************************************************/ - -int tabsize(ts) -int ts; -{ - int origval; - - origval = stdscr->_tabsize; - stdscr->_tabsize = ts; - return(origval); -} /* tabsize */ diff --git a/lib/libcurses/termmisc.c b/lib/libcurses/termmisc.c deleted file mode 100644 index 267ee4c98..000000000 --- a/lib/libcurses/termmisc.c +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include "curspriv.h" - -/* Static variables or saving terminal modes */ - -int fixterm() -{ - return(OK); -} /* fixterm */ - -int resetterm() -{ - return(OK); -} - -int saveoldterm() -{ - return(OK); -} /* saveoldterm */ - -int saveterm() -{ - return(OK); -} /* saveterm */ - -int baudrate() -{ - return(19200); -} /* baudrate */ - -/****************************************************************/ -/* Erasechar(), killchar() returns std MSDOS erase chars. */ -/****************************************************************/ - -int erasechar() -{ - return(_DCCHAR); /* character delete char */ -} /* erasechar */ - -int killchar() -{ - return(_DLCHAR); /* line delete char */ -} /* killchar */ - -/****************************************************************/ -/* Savetty() and resetty() saves and restores the terminal I/O */ -/* Settings. */ -/****************************************************************/ - -int savetty() -{ - return(OK); -} /* savetty */ - -/****************************************************************/ -/* Setupterm() sets up the terminal. On a PC, it is always suc- */ -/* Cessful, and returns 1. */ -/****************************************************************/ - -int setupterm() -{ - return(1); -} /* setupterm */ diff --git a/lib/libcurses/timeout.c b/lib/libcurses/timeout.c new file mode 100644 index 000000000..ab9ef9e32 --- /dev/null +++ b/lib/libcurses/timeout.c @@ -0,0 +1,76 @@ +/* $NetBSD: timeout.c,v 1.8 2009/11/04 21:24:57 dsl Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Julian Coleman. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: timeout.c,v 1.8 2009/11/04 21:24:57 dsl Exp $"); +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +#ifndef _CURSES_USE_MACROS + +/* + * timeout -- + * Set the getch() delay for stdscr. + */ +void +timeout(int delay) +{ + wtimeout(stdscr, delay); +} + +#endif + +/* + * wtimeout -- + * Set the getch() delay for a window. + */ +void +wtimeout(WINDOW *win, int delay) +{ + + if (delay < 0) + win->delay = -1; + else if (!delay) + win->delay = delay; + else { + /* + * 1. VTIME is a char + * 2. timeout granularity is ms but VTIME is 0.1s + */ + if (delay > 25500) + win->delay = 255; + else + win->delay = (delay - 1)/ 100 + 1; + } +} diff --git a/lib/libcurses/toucholap.c b/lib/libcurses/toucholap.c new file mode 100644 index 000000000..97b46dd25 --- /dev/null +++ b/lib/libcurses/toucholap.c @@ -0,0 +1,79 @@ +/* $NetBSD: toucholap.c,v 1.15 2007/01/21 13:25:36 jdc Exp $ */ + +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)toucholap.c 8.2 (Berkeley) 5/4/94"; +#else +__RCSID("$NetBSD: toucholap.c,v 1.15 2007/01/21 13:25:36 jdc Exp $"); +#endif +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +/* + * touchoverlap -- + * Touch, on win2, the part that overlaps with win1. + */ +int +touchoverlap(WINDOW *win1, WINDOW *win2) +{ + int y, endy, endx, starty, startx; + +#ifdef DEBUG + __CTRACE(__CTRACE_WINDOW, "touchoverlap: (%p, %p);\n", win1, win2); +#endif + starty = max(win1->begy, win2->begy); + startx = max(win1->begx, win2->begx); + endy = min(win1->maxy + win1->begy, win2->maxy + win2->begx); + endx = min(win1->maxx + win1->begx, win2->maxx + win2->begx); +#ifdef DEBUG + __CTRACE(__CTRACE_WINDOW, "touchoverlap: from (%d,%d) to (%d,%d)\n", + starty, startx, endy, endx); + __CTRACE(__CTRACE_WINDOW, "touchoverlap: win1 (%d,%d) to (%d,%d)\n", + win1->begy, win1->begx, win1->begy + win1->maxy, + win1->begx + win1->maxx); + __CTRACE(__CTRACE_WINDOW, "touchoverlap: win2 (%d,%d) to (%d,%d)\n", + win2->begy, win2->begx, win2->begy + win2->maxy, + win2->begx + win2->maxx); +#endif + if (starty >= endy || startx >= endx) + return (OK); + starty -= win2->begy; + startx -= win2->begx; + endy -= win2->begy; + endx -= win2->begx; + for (--endx, y = starty; y < endy; y++) + __touchline(win2, y, startx, endx); + return (OK); +} diff --git a/lib/libcurses/touchwin.c b/lib/libcurses/touchwin.c new file mode 100644 index 000000000..f01d524e3 --- /dev/null +++ b/lib/libcurses/touchwin.c @@ -0,0 +1,237 @@ +/* $NetBSD: touchwin.c,v 1.26 2010/02/23 19:48:26 drochner Exp $ */ + +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)touchwin.c 8.2 (Berkeley) 5/4/94"; +#else +__RCSID("$NetBSD: touchwin.c,v 1.26 2010/02/23 19:48:26 drochner Exp $"); +#endif +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +/* + * is_linetouched -- + * Indicate if line has been touched or not. + */ +bool +is_linetouched(WINDOW *win, int line) +{ + if (line > win->maxy) + return FALSE; + + return ((win->alines[line]->flags & __ISDIRTY) != 0); +} + +/* + * touchline -- + * Touch count lines starting at start. This is the SUS v2 compliant + * version. + */ +int +touchline(WINDOW *win, int start, int count) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_LINE, "touchline: (%p, %d, %d)\n", win, start, count); +#endif + return wtouchln(win, start, count, 1); +} + +/* + * wredrawln -- + * Mark count lines starting at start as corrupted. Implemented using + * wtouchln(). + */ +int wredrawln(WINDOW *win, int start, int count) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_LINE, "wredrawln: (%p, %d, %d)\n", win, start, count); +#endif + return wtouchln(win, start, count, 1); +} + +/* + * is_wintouched -- + * Check if the window has been touched. + */ +bool +is_wintouched(WINDOW *win) +{ + int y, maxy; + + maxy = win->maxy; + for (y = 0; y < maxy; y++) { + if (is_linetouched(win, y) == TRUE) + return TRUE; + } + + return FALSE; +} + +/* + * touchwin -- + * Make it look like the whole window has been changed. + */ +int +touchwin(WINDOW *win) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_LINE, "touchwin: (%p)\n", win); +#endif + return wtouchln(win, 0, win->maxy, 1); +} + +/* + * redrawwin -- + * Mark entire window as corrupted. Implemented using wtouchln(). + */ +int +redrawwin(WINDOW *win) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_LINE, "redrawwin: (%p)\n", win); +#endif + return wtouchln(win, 0, win->maxy, 1); +} + +/* + * untouchwin -- + * Make it look like the window has not been changed. + */ +int +untouchwin(WINDOW *win) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_LINE, "untouchwin: (%p)\n", win); +#endif + return wtouchln(win, 0, win->maxy, 0); +} + +/* + * wtouchln -- + * If changed is 1 then touch n lines starting at line. If changed + * is 0 then mark the lines as unchanged. + */ +int +wtouchln(WINDOW *win, int line, int n, int changed) +{ + int y; + __LINE *wlp; + +#ifdef DEBUG + __CTRACE(__CTRACE_LINE, "wtouchln: (%p) %d, %d, %d\n", + win, line, n, changed); +#endif + if (line + n > win->maxy) + line = win->maxy - n; + for (y = line; y < line + n; y++) { + if (changed == 1) + __touchline(win, y, 0, (int) win->maxx - 1); + else { + wlp = win->alines[y]; + if (*wlp->firstchp >= win->ch_off && + *wlp->firstchp < win->maxx + win->ch_off) + *wlp->firstchp = win->maxx + win->ch_off; + if (*wlp->lastchp >= win->ch_off && + *wlp->lastchp < win->maxx + win->ch_off) + *wlp->lastchp = win->ch_off; + wlp->flags &= ~__ISDIRTY; + } + } + + return OK; +} + +int +__touchwin(WINDOW *win) +{ + int y, maxy; + +#ifdef DEBUG + __CTRACE(__CTRACE_LINE, "__touchwin: (%p)\n", win); +#endif + maxy = win->maxy; + for (y = 0; y < maxy; y++) + __touchline(win, y, 0, (int) win->maxx - 1); + return (OK); +} + +int +__touchline(WINDOW *win, int y, int sx, int ex) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_LINE, "__touchline: (%p, %d, %d, %d)\n", + win, y, sx, ex); + __CTRACE(__CTRACE_LINE, "__touchline: first = %d, last = %d\n", + *win->alines[y]->firstchp, *win->alines[y]->lastchp); +#endif + sx += win->ch_off; + ex += win->ch_off; + if (!(win->alines[y]->flags & __ISDIRTY)) + win->alines[y]->flags |= __ISDIRTY; + /* firstchp/lastchp are shared between parent window and sub-window. */ + if (*win->alines[y]->firstchp > sx) + *win->alines[y]->firstchp = sx; + if (*win->alines[y]->lastchp < ex) + *win->alines[y]->lastchp = ex; +#ifdef DEBUG + __CTRACE(__CTRACE_LINE, "__touchline: first = %d, last = %d\n", + *win->alines[y]->firstchp, *win->alines[y]->lastchp); +#endif + return (OK); +} + +void +wsyncup(WINDOW *win) +{ + + do { + touchwin(win); + win = win->orig; + } while (win); +} + +void +wsyncdown(WINDOW *win) +{ + WINDOW *w = win->orig; + + while (w) { + if (is_wintouched(w)) { + touchwin(win); + break; + } + w = w->orig; + } +} diff --git a/lib/libcurses/tscroll.c b/lib/libcurses/tscroll.c new file mode 100644 index 000000000..fdba8b132 --- /dev/null +++ b/lib/libcurses/tscroll.c @@ -0,0 +1,253 @@ +/* $NetBSD: tscroll.c,v 1.13 2007/01/21 13:25:36 jdc Exp $ */ + +/*- + * Copyright (c) 1992, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)tscroll.c 8.4 (Berkeley) 7/27/94"; +#else +__RCSID("$NetBSD: tscroll.c,v 1.13 2007/01/21 13:25:36 jdc Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#include "curses.h" +#include "curses_private.h" + +#define MAXRETURNSIZE 64 + +char * +__tscroll(const char *cap, int n1, int n2) +{ + return (__parse_cap(cap, n1, n2)); +} + +/* + * Routines to parse capabilities. Derived from tgoto.c in termcap(3) + * library. Cap is a string containing printf type escapes to allow + * scrolling. The following escapes are defined for substituting n: + * + * %d as in printf + * %2 like %2d + * %3 like %3d + * %. gives %c hacking special case characters + * %+x like %c but adding x first + * + * The codes below affect the state but don't use up a value. + * + * %>xy if value > x add y + * %i increments n + * %% gives % + * %B BCD (2 decimal digits encoded in one byte) + * %D Delta Data (backwards bcd) + * + * all other characters are ``self-inserting''. + * + * XXX: + * %r reverse order of two parameters + * is also defined but we don't support it (yet). + */ +char * +__parse_cap (char const *cap, ...) +{ + va_list ap; + static char result[MAXRETURNSIZE]; + int c, n; + char *dp; + int have_input; + + va_start (ap, cap); + n = 0; /* XXX gcc -Wuninitialized */ + + if (cap == NULL) + goto err; +#ifdef DEBUG + { + int i; + + __CTRACE(__CTRACE_MISC, "__parse_cap: cap = "); + for (i = 0; i < strlen(cap); i++) + __CTRACE(__CTRACE_MISC, "%s", unctrl(cap[i])); + __CTRACE(__CTRACE_MISC, "\n"); + } +#endif + have_input = 0; + for (dp = result; (c = *cap++) != '\0';) { + if (c != '%') { + *dp++ = c; + continue; + } + switch (c = *cap++) { + case 'n': + if (!have_input) { + n = va_arg (ap, int); + have_input = 1; +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, + "__parse_cap: %%n, val = %d\n", n); +#endif + } + n ^= 0140; + continue; + case 'd': + if (!have_input) { + n = va_arg (ap, int); + have_input = 1; +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, + "__parse_cap: %%d, val = %d\n", n); +#endif + } + if (n < 10) + goto one; + if (n < 100) + goto two; + /* FALLTHROUGH */ + case '3': + if (!have_input) { + n = va_arg (ap, int); + have_input = 1; +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, + "__parse_cap: %%3, val = %d\n", n); +#endif + } + *dp++ = (n / 100) | '0'; + n %= 100; + /* FALLTHROUGH */ + case '2': + if (!have_input) { + n = va_arg (ap, int); + have_input = 1; +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, + "__parse_cap: %%2, val = %d\n", n); +#endif + } + two: *dp++ = n / 10 | '0'; + one: *dp++ = n % 10 | '0'; + have_input = 0; + continue; + case '>': + if (!have_input) { + n = va_arg (ap, int); + have_input = 1; +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, + "__parse_cap: %%>, val = %d\n", n); +#endif + } + if (n > *cap++) + n += *cap++; + else + cap++; + continue; + case '+': + if (!have_input) { + n = va_arg (ap, int); + have_input = 1; +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, + "__parse_cap: %%+, val = %d\n", n); +#endif + } + n += *cap++; + /* FALLTHROUGH */ + case '.': + if (!have_input) { + n = va_arg (ap, int); + have_input = 1; +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, + "__parse_cap: %%., val = %d\n", n); +#endif + } + *dp++ = n; + have_input = 0; + continue; + case 'i': + if (!have_input) { + n = va_arg (ap, int); + have_input = 1; +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, + "__parse_cap: %%i, val = %d\n", n); +#endif + } + n++; + continue; + case '%': + *dp++ = c; + continue; + case 'B': + if (!have_input) { + n = va_arg (ap, int); + have_input = 1; +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, + "__parse_cap: %%B, val = %d\n", n); +#endif + } + n = (n / 10 << 4) + n % 10; + continue; + case 'D': + if (!have_input) { + n = va_arg (ap, int); + have_input = 1; +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, + "__parse_cap: %%D, val = %d\n", n); +#endif + } + n = n - 2 * (n % 16); + continue; + /* + * XXX + * System V terminfo files have lots of extra gunk. + * The only other one we've seen in capability strings + * is %pN, and it seems to work okay if we ignore it. + */ + case 'p': + ++cap; + continue; + default: + goto err; + } + } + *dp = '\0'; + va_end (ap); + return (result); + +err: va_end (ap); + return ((char *) "\0"); +} diff --git a/lib/libcurses/tstp.c b/lib/libcurses/tstp.c new file mode 100644 index 000000000..51d03225f --- /dev/null +++ b/lib/libcurses/tstp.c @@ -0,0 +1,356 @@ +/* $NetBSD: tstp.c,v 1.38 2010/02/03 15:34:40 roy Exp $ */ + +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)tstp.c 8.3 (Berkeley) 5/4/94"; +#else +__RCSID("$NetBSD: tstp.c,v 1.38 2010/02/03 15:34:40 roy Exp $"); +#endif +#endif /* not lint */ + +#ifndef TCSASOFT +#define TCSASOFT 0 +#endif + +#include + +#include +#include +#include +#include + +#include "curses.h" +#include "curses_private.h" + +static int tstp_set = 0; +static int winch_set = 0; + +static void (*otstpfn) +__P((int)) = SIG_DFL; + +static struct sigaction owsa; + +/* + * stop_signal_handler -- + * Handle stop signals. + */ +void +__stop_signal_handler(/*ARGSUSED*/int signo) +{ + sigset_t oset, set; + + /* + * Block window change and timer signals. The latter is because + * applications use timers to decide when to repaint the screen. + */ + (void) sigemptyset(&set); + (void) sigaddset(&set, SIGALRM); + (void) sigaddset(&set, SIGWINCH); + (void) sigprocmask(SIG_BLOCK, &set, &oset); + + /* + * End the window, which also resets the terminal state to the + * original modes. + */ + __stopwin(); + + /* Unblock SIGTSTP. */ + (void) sigemptyset(&set); + (void) sigaddset(&set, SIGTSTP); + (void) sigprocmask(SIG_UNBLOCK, &set, NULL); + + /* Stop ourselves. */ + (void) kill(0, SIGTSTP); + + /* Time passes ... */ + + /* restart things */ + __restartwin(); + + /* Reset the signals. */ + (void) sigprocmask(SIG_SETMASK, &oset, NULL); +} + +/* + * Set the TSTP handler. + */ +void +__set_stophandler(void) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "__set_stophandler: %d\n", tstp_set); +#endif + if (!tstp_set) { + otstpfn = signal(SIGTSTP, __stop_signal_handler); + tstp_set = 1; + } +} + +/* + * Restore the TSTP handler. + */ +void +__restore_stophandler(void) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "__restore_stophandler: %d\n", tstp_set); +#endif + if (tstp_set) { + (void) signal(SIGTSTP, otstpfn); + tstp_set = 0; + } +} + +/* + * winch_signal_handler -- + * Handle winch signals by pushing KEY_RESIZE into the input stream. + */ +void +__winch_signal_handler(/*ARGSUSED*/int signo) +{ + struct winsize win; + + if (ioctl(fileno(_cursesi_screen->outfd), TIOCGWINSZ, &win) != -1 && + win.ws_row != 0 && win.ws_col != 0) { + LINES = win.ws_row; + COLS = win.ws_col; + } + /* + * If there was a previous handler, call that, + * otherwise tell getch() to send KEY_RESIZE. + */ + if (owsa.sa_handler != NULL) + owsa.sa_handler(signo); + else + _cursesi_screen->resized = 1; +} + +/* + * Set the WINCH handler. + */ +void +__set_winchhandler(void) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "__set_winchhandler: %d\n", winch_set); +#endif + if (!winch_set) { + struct sigaction sa; + + sa.sa_handler = __winch_signal_handler; + sa.sa_flags = 0; + sigemptyset(&sa.sa_mask); + sigaction(SIGWINCH, &sa, &owsa); + winch_set = 1; +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, + "__set_winchhandler: owsa.sa_handler=%p\n", + owsa.sa_handler); +#endif + } +} + +/* + * Restore the WINCH handler. + */ +void +__restore_winchhandler(void) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "__restore_winchhandler: %d\n", winch_set); +#endif + if (winch_set > 0) { + struct sigaction cwsa; + + sigaction(SIGWINCH, NULL, &cwsa); + if (cwsa.sa_handler == owsa.sa_handler) { + sigaction(SIGWINCH, &owsa, NULL); + winch_set = 0; + } else { + /* + * We're now using the programs WINCH handler, + * so don't restore the previous one. + */ + winch_set = -1; +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "cwsa.sa_handler = %p\n", + cwsa.sa_handler); +#endif + } + } +} + +/* To allow both SIGTSTP and endwin() to come back nicely, we provide + the following routines. */ + +int +__stopwin(void) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "__stopwin\n"); +#endif + if (_cursesi_screen->endwin) + return OK; + + /* Get the current terminal state (which the user may have changed). */ + (void) tcgetattr(fileno(_cursesi_screen->infd), + &_cursesi_screen->save_termios); + + __restore_stophandler(); + __restore_winchhandler(); + + if (curscr != NULL) { + __unsetattr(0); + __mvcur((int) curscr->cury, (int) curscr->curx, + (int) curscr->maxy - 1, 0, 0); + } + + if (meta_off != NULL) + (void) tputs(meta_off, 0, __cputchar); + + if ((curscr != NULL) && (curscr->flags & __KEYPAD)) + (void) tputs(keypad_local, 0, __cputchar); + (void) tputs(cursor_normal, 0, __cputchar); + (void) tputs(exit_ca_mode, 0, __cputchar); + (void) fflush(_cursesi_screen->outfd); + (void) setvbuf(_cursesi_screen->outfd, NULL, _IOLBF, (size_t) 0); + + _cursesi_screen->endwin = 1; + + return (tcsetattr(fileno(_cursesi_screen->infd), + __tcaction ? TCSASOFT | TCSADRAIN : TCSADRAIN, + &_cursesi_screen->orig_termios) ? ERR : OK); +} + + +void +__restartwin(void) +{ + struct winsize win; + int nlines, ncols; + +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "__restartwin\n"); +#endif + if (!_cursesi_screen->endwin) + return; + + /* Reset the curses SIGTSTP and SIGWINCH signal handlers. */ + __set_stophandler(); + __set_winchhandler(); + + /* + * Check to see if the window size has changed. + * If the application didn't update LINES and COLS, + * set the * resized flag to tell getch() to push KEY_RESIZE. + * Update curscr (which also updates __virtscr) and stdscr + * to match the new size. + */ + if (ioctl(fileno(_cursesi_screen->outfd), TIOCGWINSZ, &win) != -1 && + win.ws_row != 0 && win.ws_col != 0) { + if (win.ws_row != LINES) { + LINES = win.ws_row; + _cursesi_screen->resized = 1; + } + if (win.ws_col != COLS) { + COLS = win.ws_col; + _cursesi_screen->resized = 1; + } + } + /* + * We need to make local copies of LINES and COLS, otherwise we + * could lose if they are changed between wresize() calls. + */ + nlines = LINES; + ncols = COLS; + if (curscr->maxy != nlines || curscr->maxx != ncols) + wresize(curscr, nlines, ncols); + if (stdscr->maxy != nlines || stdscr->maxx != ncols) + wresize(stdscr, nlines, ncols); + + /* save the new "default" terminal state */ + (void) tcgetattr(fileno(_cursesi_screen->infd), + &_cursesi_screen->orig_termios); + + /* Reset the terminal state to the mode just before we stopped. */ + (void) tcsetattr(fileno(_cursesi_screen->infd), + __tcaction ? TCSASOFT | TCSADRAIN : TCSADRAIN, + &_cursesi_screen->save_termios); + + /* Restore colours */ + __restore_colors(); + + /* Reset meta */ + __restore_meta_state(); + + /* Restart the screen. */ + __startwin(_cursesi_screen); + + /* Reset cursor visibility */ + __restore_cursor_vis(); + + /* Repaint the screen. */ + wrefresh(curscr); +} + +int +def_prog_mode(void) +{ + if (_cursesi_screen->endwin) + return ERR; + + return (tcgetattr(fileno(_cursesi_screen->infd), + &_cursesi_screen->save_termios) ? ERR : OK); +} + +int +reset_prog_mode(void) +{ + + return tcsetattr(fileno(_cursesi_screen->infd), + __tcaction ? TCSASOFT | TCSADRAIN : TCSADRAIN, + &_cursesi_screen->save_termios) ? ERR : OK; +} + +int +def_shell_mode(void) +{ + return (tcgetattr(fileno(_cursesi_screen->infd), + &_cursesi_screen->orig_termios) ? ERR : OK); +} + +int +reset_shell_mode(void) +{ + return (__stopwin()); +} diff --git a/lib/libcurses/tty.c b/lib/libcurses/tty.c new file mode 100644 index 000000000..3f98b984f --- /dev/null +++ b/lib/libcurses/tty.c @@ -0,0 +1,682 @@ +/* $NetBSD: tty.c,v 1.42 2010/02/03 15:34:40 roy Exp $ */ + +/*- + * Copyright (c) 1992, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)tty.c 8.6 (Berkeley) 1/10/95"; +#else +__RCSID("$NetBSD: tty.c,v 1.42 2010/02/03 15:34:40 roy Exp $"); +#endif +#endif /* not lint */ + +#include + +#include +#include +#include +#include +#include + +#include "curses.h" +#include "curses_private.h" + +/* + * In general, curses should leave tty hardware settings alone (speed, parity, + * word size). This is most easily done in BSD by using TCSASOFT on all + * tcsetattr calls. On other systems, it would be better to get and restore + * those attributes at each change, or at least when stopped and restarted. + * See also the comments in getterm(). + */ +#ifdef TCSASOFT +int __tcaction = 1; /* Ignore hardware settings. */ +#else +#define TCSASOFT 0 +int __tcaction = 0; +#endif + +#ifndef OXTABS +#ifdef XTABS /* SMI uses XTABS. */ +#define OXTABS XTABS +#else +#define OXTABS 0 +#endif +#endif + +/* + * baudrate -- + * Return the current baudrate + */ +int +baudrate(void) +{ + if (_cursesi_screen->notty == TRUE) + return 0; + + return cfgetospeed(&_cursesi_screen->baset); +} + +/* + * gettmode -- + * Do terminal type initialization. + */ +int +gettmode(void) +{ + if (_cursesi_gettmode(_cursesi_screen) == ERR) + return ERR; + + __GT = _cursesi_screen->GT; + __NONL = _cursesi_screen->NONL; + return OK; +} + +/* + * _cursesi_gettmode -- + * Do the terminal type initialisation for the tty attached to the + * given screen. + */ +int +_cursesi_gettmode(SCREEN *screen) +{ + screen->useraw = 0; + + if (tcgetattr(fileno(screen->infd), &screen->orig_termios)) { + /* if the input fd is not a tty try the output */ + if (tcgetattr(fileno(screen->infd), &screen->orig_termios)) { + /* not a tty ... we will disable tty related stuff */ + screen->notty = TRUE; + __GT = 0; + __NONL = 0; + return (OK); + } + } + + screen->baset = screen->orig_termios; + screen->baset.c_oflag &= ~OXTABS; + + screen->GT = 0; /* historical. was used before we wired OXTABS off */ + screen->NONL = (screen->baset.c_oflag & ONLCR) == 0; + + /* + * XXX + * System V and SMI systems overload VMIN and VTIME, such that + * VMIN is the same as the VEOF element, and VTIME is the same + * as the VEOL element. This means that, if VEOF was ^D, the + * default VMIN is 4. Majorly stupid. + */ + screen->cbreakt = screen->baset; + screen->cbreakt.c_lflag &= ~(ECHO | ECHONL | ICANON); + screen->cbreakt.c_cc[VMIN] = 1; + screen->cbreakt.c_cc[VTIME] = 0; + + screen->rawt = screen->cbreakt; + screen->rawt.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | INLCR | IGNCR | + ICRNL | IXON); + screen->rawt.c_oflag &= ~OPOST; + screen->rawt.c_lflag &= ~(ISIG | IEXTEN); + + /* + * In general, curses should leave hardware-related settings alone. + * This includes parity and word size. Older versions set the tty + * to 8 bits, no parity in raw(), but this is considered to be an + * artifact of the old tty interface. If it's desired to change + * parity and word size, the TCSASOFT bit has to be removed from the + * calls that switch to/from "raw" mode. + */ + if (!__tcaction) { + screen->rawt.c_iflag &= ~ISTRIP; + screen->rawt.c_cflag &= ~(CSIZE | PARENB); + screen->rawt.c_cflag |= CS8; + } + + screen->curt = &screen->baset; + return (tcsetattr(fileno(screen->infd), __tcaction ? + TCSASOFT | TCSADRAIN : TCSADRAIN, screen->curt) ? ERR : OK); +} + +/* + * raw -- + * Put the terminal into raw mode + */ +int +raw(void) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "raw()\n"); +#endif + /* Check if we need to restart ... */ + if (_cursesi_screen->endwin) + __restartwin(); + + _cursesi_screen->useraw = __pfast = __rawmode = 1; + _cursesi_screen->curt = &_cursesi_screen->rawt; + if (_cursesi_screen->notty == TRUE) + return OK; + return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ? + TCSASOFT | TCSADRAIN : TCSADRAIN, + _cursesi_screen->curt) ? ERR : OK); +} + +/* + * noraw -- + * Put the terminal into cooked mode + */ +int +noraw(void) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "noraw()\n"); +#endif + /* Check if we need to restart ... */ + if (_cursesi_screen->endwin) + __restartwin(); + + _cursesi_screen->useraw = __pfast = __rawmode = 0; + if (_cursesi_screen->notty == TRUE) + return OK; + _cursesi_screen->curt = &_cursesi_screen->baset; + return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ? + TCSASOFT | TCSADRAIN : TCSADRAIN, + _cursesi_screen->curt) ? ERR : OK); +} + +/* + * cbreak -- + * Enable cbreak mode + */ +int +cbreak(void) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "cbreak()\n"); +#endif + /* Check if we need to restart ... */ + if (_cursesi_screen->endwin) + __restartwin(); + + __rawmode = 1; + if (_cursesi_screen->notty == TRUE) + return OK; + _cursesi_screen->curt = _cursesi_screen->useraw ? + &_cursesi_screen->rawt : &_cursesi_screen->cbreakt; + return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ? + TCSASOFT | TCSADRAIN : TCSADRAIN, + _cursesi_screen->curt) ? ERR : OK); +} + +/* + * nocbreak -- + * Disable cbreak mode + */ +int +nocbreak(void) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "nocbreak()\n"); +#endif + /* Check if we need to restart ... */ + if (_cursesi_screen->endwin) + __restartwin(); + + __rawmode = 0; + if (_cursesi_screen->notty == TRUE) + return OK; + /* if we were in halfdelay mode then nuke the timeout */ + if ((_cursesi_screen->half_delay == TRUE) && + (__notimeout() == ERR)) + return ERR; + + _cursesi_screen->half_delay = FALSE; + _cursesi_screen->curt = _cursesi_screen->useraw ? + &_cursesi_screen->rawt : &_cursesi_screen->baset; + return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ? + TCSASOFT | TCSADRAIN : TCSADRAIN, + _cursesi_screen->curt) ? ERR : OK); +} + +/* + * halfdelay -- + * Put the terminal into cbreak mode with the specified timeout. + * + */ +int +halfdelay(int duration) +{ + if ((duration < 1) || (duration > 255)) + return ERR; + + if (cbreak() == ERR) + return ERR; + + if (__timeout(duration) == ERR) + return ERR; + + _cursesi_screen->half_delay = TRUE; + return OK; +} + +int +__delay(void) + { +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "__delay()\n"); +#endif + /* Check if we need to restart ... */ + if (_cursesi_screen->endwin) + __restartwin(); + + if (_cursesi_screen->notty == TRUE) + return OK; + _cursesi_screen->rawt.c_cc[VMIN] = 1; + _cursesi_screen->rawt.c_cc[VTIME] = 0; + _cursesi_screen->cbreakt.c_cc[VMIN] = 1; + _cursesi_screen->cbreakt.c_cc[VTIME] = 0; + _cursesi_screen->baset.c_cc[VMIN] = 1; + _cursesi_screen->baset.c_cc[VTIME] = 0; + + if (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ? + TCSASOFT : TCSANOW, _cursesi_screen->curt)) { + __restore_termios(); + return ERR; + } + + return OK; +} + +int +__nodelay(void) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "__nodelay()\n"); +#endif + /* Check if we need to restart ... */ + if (_cursesi_screen->endwin) + __restartwin(); + + if (_cursesi_screen->notty == TRUE) + return OK; + _cursesi_screen->rawt.c_cc[VMIN] = 0; + _cursesi_screen->rawt.c_cc[VTIME] = 0; + _cursesi_screen->cbreakt.c_cc[VMIN] = 0; + _cursesi_screen->cbreakt.c_cc[VTIME] = 0; + _cursesi_screen->baset.c_cc[VMIN] = 0; + _cursesi_screen->baset.c_cc[VTIME] = 0; + + if (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ? + TCSASOFT : TCSANOW, _cursesi_screen->curt)) { + __restore_termios(); + return ERR; + } + + return OK; +} + +void +__save_termios(void) +{ + /* Check if we need to restart ... */ + if (_cursesi_screen->endwin) + __restartwin(); + + if (_cursesi_screen->notty == TRUE) + return; + _cursesi_screen->ovmin = _cursesi_screen->cbreakt.c_cc[VMIN]; + _cursesi_screen->ovtime = _cursesi_screen->cbreakt.c_cc[VTIME]; +} + +void +__restore_termios(void) +{ + /* Check if we need to restart ... */ + if (_cursesi_screen->endwin) + __restartwin(); + + if (_cursesi_screen->notty == TRUE) + return; + _cursesi_screen->rawt.c_cc[VMIN] = _cursesi_screen->ovmin; + _cursesi_screen->rawt.c_cc[VTIME] = _cursesi_screen->ovtime; + _cursesi_screen->cbreakt.c_cc[VMIN] = _cursesi_screen->ovmin; + _cursesi_screen->cbreakt.c_cc[VTIME] = _cursesi_screen->ovtime; + _cursesi_screen->baset.c_cc[VMIN] = _cursesi_screen->ovmin; + _cursesi_screen->baset.c_cc[VTIME] = _cursesi_screen->ovtime; +} + +int +__timeout(int delay) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "__timeout()\n"); +#endif + /* Check if we need to restart ... */ + if (_cursesi_screen->endwin) + __restartwin(); + + if (_cursesi_screen->notty == TRUE) + return OK; + _cursesi_screen->ovmin = _cursesi_screen->cbreakt.c_cc[VMIN]; + _cursesi_screen->ovtime = _cursesi_screen->cbreakt.c_cc[VTIME]; + _cursesi_screen->rawt.c_cc[VMIN] = 0; + _cursesi_screen->rawt.c_cc[VTIME] = delay; + _cursesi_screen->cbreakt.c_cc[VMIN] = 0; + _cursesi_screen->cbreakt.c_cc[VTIME] = delay; + _cursesi_screen->baset.c_cc[VMIN] = 0; + _cursesi_screen->baset.c_cc[VTIME] = delay; + + if (tcsetattr(fileno(_cursesi_screen->infd), + __tcaction ? TCSASOFT | TCSANOW : TCSANOW, + _cursesi_screen->curt)) { + __restore_termios(); + return ERR; + } + + return OK; +} + +int +__notimeout(void) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "__notimeout()\n"); +#endif + /* Check if we need to restart ... */ + if (_cursesi_screen->endwin) + __restartwin(); + + if (_cursesi_screen->notty == TRUE) + return OK; + _cursesi_screen->rawt.c_cc[VMIN] = 1; + _cursesi_screen->rawt.c_cc[VTIME] = 0; + _cursesi_screen->cbreakt.c_cc[VMIN] = 1; + _cursesi_screen->cbreakt.c_cc[VTIME] = 0; + _cursesi_screen->baset.c_cc[VMIN] = 1; + _cursesi_screen->baset.c_cc[VTIME] = 0; + + return (tcsetattr(fileno(_cursesi_screen->infd), + __tcaction ? TCSASOFT | TCSANOW : TCSANOW, + _cursesi_screen->curt) ? ERR : OK); +} + +int +echo(void) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "echo()\n"); +#endif + /* Check if we need to restart ... */ + if (_cursesi_screen->endwin) + __restartwin(); + + __echoit = 1; + return (OK); +} + +int +noecho(void) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "noecho()\n"); +#endif + /* Check if we need to restart ... */ + if (_cursesi_screen->endwin) + __restartwin(); + + __echoit = 0; + return (OK); +} + +int +nl(void) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "nl()\n"); +#endif + /* Check if we need to restart ... */ + if (_cursesi_screen->endwin) + __restartwin(); + + if (_cursesi_screen->notty == TRUE) + return OK; + _cursesi_screen->rawt.c_iflag |= ICRNL; + _cursesi_screen->rawt.c_oflag |= ONLCR; + _cursesi_screen->cbreakt.c_iflag |= ICRNL; + _cursesi_screen->cbreakt.c_oflag |= ONLCR; + _cursesi_screen->baset.c_iflag |= ICRNL; + _cursesi_screen->baset.c_oflag |= ONLCR; + + _cursesi_screen->nl = 1; + _cursesi_screen->pfast = _cursesi_screen->rawmode; + return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ? + TCSASOFT | TCSADRAIN : TCSADRAIN, + _cursesi_screen->curt) ? ERR : OK); +} + +int +nonl(void) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "nonl()\n"); +#endif + /* Check if we need to restart ... */ + if (_cursesi_screen->endwin) + __restartwin(); + + if (_cursesi_screen->notty == TRUE) + return OK; + _cursesi_screen->rawt.c_iflag &= ~ICRNL; + _cursesi_screen->rawt.c_oflag &= ~ONLCR; + _cursesi_screen->cbreakt.c_iflag &= ~ICRNL; + _cursesi_screen->cbreakt.c_oflag &= ~ONLCR; + _cursesi_screen->baset.c_iflag &= ~ICRNL; + _cursesi_screen->baset.c_oflag &= ~ONLCR; + + _cursesi_screen->nl = 0; + __pfast = 1; + return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ? + TCSASOFT | TCSADRAIN : TCSADRAIN, + _cursesi_screen->curt) ? ERR : OK); +} + +#ifndef _CURSES_USE_MACROS +void +noqiflush(void) +{ + (void) intrflush(stdscr, FALSE); +} + +void +qiflush(void) +{ + (void) intrflush(stdscr, TRUE); +} +#endif /* _CURSES_USE_MACROS */ + +int +intrflush(WINDOW *win, bool bf) /*ARGSUSED*/ +{ + /* Check if we need to restart ... */ + if (_cursesi_screen->endwin) + __restartwin(); + + if (_cursesi_screen->notty == TRUE) + return OK; + if (bf) { + _cursesi_screen->rawt.c_lflag &= ~NOFLSH; + _cursesi_screen->cbreakt.c_lflag &= ~NOFLSH; + _cursesi_screen->baset.c_lflag &= ~NOFLSH; + } else { + _cursesi_screen->rawt.c_lflag |= NOFLSH; + _cursesi_screen->cbreakt.c_lflag |= NOFLSH; + _cursesi_screen->baset.c_lflag |= NOFLSH; + } + + __pfast = 1; + return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ? + TCSASOFT | TCSADRAIN : TCSADRAIN, + _cursesi_screen->curt) ? ERR : OK); +} + +void +__startwin(SCREEN *screen) +{ + + (void) fflush(screen->infd); + + /* + * Some C libraries default to a 1K buffer when talking to a tty. + * With a larger screen, especially across a network, we'd like + * to get it to all flush in a single write. Make it twice as big + * as just the characters (so that we have room for cursor motions + * and attribute information) but no more than 8K. + */ + if (screen->stdbuf == NULL) { + screen->len = LINES * COLS * 2; + if (screen->len > 8192) + screen->len = 8192; + if ((screen->stdbuf = malloc(screen->len)) == NULL) + screen->len = 0; + } + (void) setvbuf(screen->outfd, screen->stdbuf, _IOFBF, screen->len); + + ti_puts(screen->term, t_enter_ca_mode(screen->term), 0, + __cputchar_args, (void *) screen->outfd); + ti_puts(screen->term, t_cursor_normal(screen->term), 0, + __cputchar_args, (void *) screen->outfd); + if (screen->curscr->flags & __KEYPAD) + ti_puts(screen->term, t_keypad_xmit(screen->term), 0, + __cputchar_args, (void *) screen->outfd); + screen->endwin = 0; +} + +int +endwin(void) +{ +#ifdef DEBUG + __CTRACE(__CTRACE_MISC, "endwin\n"); +#endif + return __stopwin(); +} + +bool +isendwin(void) +{ + return (_cursesi_screen->endwin ? TRUE : FALSE); +} + +int +flushinp(void) +{ + (void) fpurge(_cursesi_screen->infd); + return (OK); +} + +/* + * The following routines, savetty and resetty are completely useless and + * are left in only as stubs. If people actually use them they will almost + * certainly screw up the state of the world. + */ +/*static struct termios savedtty;*/ +int +savetty(void) +{ + if (_cursesi_screen->notty == TRUE) + return OK; + return (tcgetattr(fileno(_cursesi_screen->infd), + &_cursesi_screen->savedtty) ? ERR : OK); +} + +int +resetty(void) +{ + if (_cursesi_screen->notty == TRUE) + return OK; + return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ? + TCSASOFT | TCSADRAIN : TCSADRAIN, + &_cursesi_screen->savedtty) ? ERR : OK); +} + +/* + * erasechar -- + * Return the character of the erase key. + */ +char +erasechar(void) +{ + if (_cursesi_screen->notty == TRUE) + return 0; + return _cursesi_screen->baset.c_cc[VERASE]; +} + +/* + * killchar -- + * Return the character of the kill key. + */ +char +killchar(void) +{ + if (_cursesi_screen->notty == TRUE) + return 0; + return _cursesi_screen->baset.c_cc[VKILL]; +} + +/* + * erasewchar -- + * Return the wide character of the erase key. + */ +int +erasewchar( wchar_t *ch ) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + if (_cursesi_screen->notty == TRUE) + return ERR; + *ch = _cursesi_screen->baset.c_cc[VERASE]; + return OK; +#endif /* HAVE_WCHAR */ +} + +/* + * killwchar -- + * Return the wide character of the kill key. + */ +int +killwchar( wchar_t *ch ) +{ +#ifndef HAVE_WCHAR + return ERR; +#else + if (_cursesi_screen->notty == TRUE) + return 0; + *ch = _cursesi_screen->baset.c_cc[VKILL]; + return OK; +#endif /* HAVE_WCHAR */ +} diff --git a/lib/libcurses/unctrl.c b/lib/libcurses/unctrl.c index 93c740657..ffb6aeb4d 100644 --- a/lib/libcurses/unctrl.c +++ b/lib/libcurses/unctrl.c @@ -1,45 +1,150 @@ -/****************************************************************/ -/* Unctrl() routines of the PCcurses package */ -/* */ -/****************************************************************/ -/* This version of curses is based on ncurses, a curses version */ -/* Originally written by Pavel Curtis at Cornell University. */ -/* I have made substantial changes to make it run on IBM PC's, */ -/* And therefore consider myself free to make it public domain. */ -/* Bjorn Larsson (...mcvax!enea!infovax!bl) */ -/****************************************************************/ -/* 1.0: Release: 870515 */ -/****************************************************************/ -/* Modified to run under the MINIX operating system by Don Cope */ -/* These changes are also released into the public domain. */ -/* 900906 */ -/****************************************************************/ - -#include -#include "curspriv.h" - -static char strbuf[3] = {0, 0, 0}; - -/****************************************************************/ -/* Unctrl() returns a char pointer to a string corresponding to */ -/* Argument character 'c'. */ -/****************************************************************/ - -char *unctrl(c) -char c; -{ - int ic = c; - ic &= 0xff; - - if ((ic >= ' ') && (ic != 0x7f)) { /* normal characters */ - strbuf[0] = ic; - strbuf[1] = '\0'; - return(strbuf); - } /* if */ - strbuf[0] = '^'; /* '^' prefix */ - if (c == 0x7f) /* DEL */ - strbuf[1] = '?'; - else /* other control */ - strbuf[1] = ic + '@'; - return(strbuf); -} /* unctrl */ +/* $NetBSD: unctrl.c,v 1.11 2007/05/28 15:01:58 blymn Exp $ */ + +/* + * Copyright (c) 1981, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)unctrl.c 8.1 (Berkeley) 6/4/93"; +#else +__RCSID("$NetBSD: unctrl.c,v 1.11 2007/05/28 15:01:58 blymn Exp $"); +#endif +#endif /* not lint */ + +#include + +const char * const __unctrl[256] = { + "^@", "^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", "^[", "^\\", "^]", "^~", "^_", + " ", "!", "\"", "#", "$", "%", "&", "'", + "(", ")", "*", "+", ",", "-", ".", "/", + "0", "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", "[", "\\", "]", "^", "_", + "`", "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", "{", "|", "}", "~", "^?", + + "0x80", "0x81", "0x82", "0x83", "0x84", "0x85", "0x86", "0x87", + "0x88", "0x89", "0x8a", "0x8b", "0x8c", "0x8d", "0x8e", "0x8f", + "0x90", "0x91", "0x92", "0x93", "0x94", "0x95", "0x96", "0x97", + "0x98", "0x99", "0x9a", "0x9b", "0x9c", "0x9d", "0x9e", "0x9f", + "0xa0", "0xa1", "0xa2", "0xa3", "0xa4", "0xa5", "0xa6", "0xa7", + "0xa8", "0xa9", "0xaa", "0xab", "0xac", "0xad", "0xae", "0xaf", + "0xb0", "0xb1", "0xb2", "0xb3", "0xb4", "0xb5", "0xb6", "0xb7", + "0xb8", "0xb9", "0xba", "0xbb", "0xbc", "0xbd", "0xbe", "0xbf", + "0xc0", "0xc1", "0xc2", "0xc3", "0xc4", "0xc5", "0xc6", "0xc7", + "0xc8", "0xc9", "0xca", "0xcb", "0xcc", "0xcd", "0xce", "0xcf", + "0xd0", "0xd1", "0xd2", "0xd3", "0xd4", "0xd5", "0xd6", "0xd7", + "0xd8", "0xd9", "0xda", "0xdb", "0xdc", "0xdd", "0xde", "0xdf", + "0xe0", "0xe1", "0xe2", "0xe3", "0xe4", "0xe5", "0xe6", "0xe7", + "0xe8", "0xe9", "0xea", "0xeb", "0xec", "0xed", "0xee", "0xef", + "0xf0", "0xf1", "0xf2", "0xf3", "0xf4", "0xf5", "0xf6", "0xf7", + "0xf8", "0xf9", "0xfa", "0xfb", "0xfc", "0xfd", "0xfe", "0xff", +}; + +const unsigned char __unctrllen[256] = { + 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 2, + 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, +}; + +#ifdef HAVE_WCHAR +const wchar_t * const __wunctrl[256] = { + L"^@", L"^A", L"^B", L"^C", L"^D", L"^E", L"^F", L"^G", + L"^H", L"^I", L"^J", L"^K", L"^L", L"^M", L"^N", L"^O", + L"^P", L"^Q", L"^R", L"^S", L"^T", L"^U", L"^V", L"^W", + L"^X", L"^Y", L"^Z", L"^[", L"^\\", L"^]", L"^~", L"^_", + L" ", L"!", L"\"", L"#", L"$", L"%", L"&", L"'", + L"(", L")", L"*", L"+", L",", L"-", L".", L"/", + L"0", L"1", L"2", L"3", L"4", L"5", L"6", L"7", + L"8", L"9", L":", L";", L"<", L"=", L">", L"?", + L"@", L"A", L"B", L"C", L"D", L"E", L"F", L"G", + L"H", L"I", L"J", L"K", L"L", L"M", L"N", L"O", + L"P", L"Q", L"R", L"S", L"T", L"U", L"V", L"W", + L"X", L"Y", L"Z", L"[", L"\\", L"]", L"^", L"_", + L"`", L"a", L"b", L"c", L"d", L"e", L"f", L"g", + L"h", L"i", L"j", L"k", L"l", L"m", L"n", L"o", + L"p", L"q", L"r", L"s", L"t", L"u", L"v", L"w", + L"x", L"y", L"z", L"{", L"|", L"}", L"~", L"^?", + + L"0x80", L"0x81", L"0x82", L"0x83", L"0x84", L"0x85", L"0x86", L"0x87", + L"0x88", L"0x89", L"0x8a", L"0x8b", L"0x8c", L"0x8d", L"0x8e", L"0x8f", + L"0x90", L"0x91", L"0x92", L"0x93", L"0x94", L"0x95", L"0x96", L"0x97", + L"0x98", L"0x99", L"0x9a", L"0x9b", L"0x9c", L"0x9d", L"0x9e", L"0x9f", + L"0xa0", L"0xa1", L"0xa2", L"0xa3", L"0xa4", L"0xa5", L"0xa6", L"0xa7", + L"0xa8", L"0xa9", L"0xaa", L"0xab", L"0xac", L"0xad", L"0xae", L"0xaf", + L"0xb0", L"0xb1", L"0xb2", L"0xb3", L"0xb4", L"0xb5", L"0xb6", L"0xb7", + L"0xb8", L"0xb9", L"0xba", L"0xbb", L"0xbc", L"0xbd", L"0xbe", L"0xbf", + L"0xc0", L"0xc1", L"0xc2", L"0xc3", L"0xc4", L"0xc5", L"0xc6", L"0xc7", + L"0xc8", L"0xc9", L"0xca", L"0xcb", L"0xcc", L"0xcd", L"0xce", L"0xcf", + L"0xd0", L"0xd1", L"0xd2", L"0xd3", L"0xd4", L"0xd5", L"0xd6", L"0xd7", + L"0xd8", L"0xd9", L"0xda", L"0xdb", L"0xdc", L"0xdd", L"0xde", L"0xdf", + L"0xe0", L"0xe1", L"0xe2", L"0xe3", L"0xe4", L"0xe5", L"0xe6", L"0xe7", + L"0xe8", L"0xe9", L"0xea", L"0xeb", L"0xec", L"0xed", L"0xee", L"0xef", + L"0xf0", L"0xf1", L"0xf2", L"0xf3", L"0xf4", L"0xf5", L"0xf6", L"0xf7", + L"0xf8", L"0xf9", L"0xfa", L"0xfb", L"0xfc", L"0xfd", L"0xfe", L"0xff", +}; +#endif /* HAVE_WCHAR */ diff --git a/lib/libcurses/unctrl.h b/lib/libcurses/unctrl.h new file mode 100644 index 000000000..f8a04cf80 --- /dev/null +++ b/lib/libcurses/unctrl.h @@ -0,0 +1,58 @@ +/* $NetBSD: unctrl.h,v 1.4 2007/05/28 15:01:58 blymn Exp $ */ + +/* + * Copyright (c) 1982, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)unctrl.h 8.1 (Berkeley) 5/31/93 + */ + +#ifndef _UNCTRL_H_ +#define _UNCTRL_H_ + +#include +#ifdef HAVE_WCHAR +#include +#include +#endif /* HAVE_WCHAR */ + +__BEGIN_DECLS +extern const char * const __unctrl[]; /* Control strings. */ +extern const unsigned char __unctrllen[]; /* Control strings length. */ +#ifdef HAVE_WCHAR +extern const wchar_t * const __wunctrl[]; /* Wide char control strings. */ +#endif /* HAVE_WCHAR */ +__END_DECLS + +/* 8-bit ASCII characters. */ +#define unctrl(c) __unctrl[((unsigned char)c) & 0xff] +#define unctrllen(c) __unctrllen[((unsigned char)c) & 0xff] + +#ifdef HAVE_WCHAR +#define wunctrl(wc) __wunctrl[( int )(wc->vals[ 0 ]) & 0xff] +#endif /* HAVE_WCHAR */ +#endif /* _UNCTRL_H_ */ diff --git a/lib/libcurses/underscore.c b/lib/libcurses/underscore.c new file mode 100644 index 000000000..c790c2183 --- /dev/null +++ b/lib/libcurses/underscore.c @@ -0,0 +1,98 @@ +/* $NetBSD: underscore.c,v 1.11 2010/02/03 15:34:40 roy Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Julian Coleman. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: underscore.c,v 1.11 2010/02/03 15:34:40 roy Exp $"); +#endif /* not lint */ + +#include "curses.h" +#include "curses_private.h" + +#ifndef _CURSES_USE_MACROS + +/* + * underscore -- + * Enter underscore mode on stdscr. + */ +int +underscore(void) +{ + return wunderscore(stdscr); +} + + +/* + * underend -- + * Exit underscore mode on stdscr. + */ +int +underend(void) +{ + return wunderend(stdscr); +} + +#endif + +/* + * wunderscore -- + * Enter underscore mode. + */ +int +wunderscore(WINDOW *win) +{ + /* If can underscore, set the screen underscore bit. */ + if ((enter_underline_mode != NULL && exit_underline_mode != NULL) || + underline_char != NULL) + { +#ifdef DEBUG + __CTRACE(__CTRACE_ATTR, "wunderscore\n"); +#endif + win->wattr |= __UNDERSCORE; + } + return (1); +} + +/* + * wunderend -- + * Exit underscore mode. + */ +int +wunderend(WINDOW *win) +{ + if (exit_underline_mode != NULL) { +#ifdef DEBUG + __CTRACE(__CTRACE_ATTR, "wunderend\n"); +#endif + win->wattr &= ~__UNDERSCORE; + } + return 1; +} diff --git a/lib/libcurses/update.c b/lib/libcurses/update.c deleted file mode 100644 index 7c027d399..000000000 --- a/lib/libcurses/update.c +++ /dev/null @@ -1,170 +0,0 @@ -#include -#include "curspriv.h" -#include - -static WINDOW *twin; /* used by many routines */ - -/****************************************************************/ -/* Gotoxy() moves the physical cursor to the desired address on */ -/* The screen. We don't optimize here - on a PC, it takes more */ -/* Time to optimize than to do things directly. */ -/****************************************************************/ - -_PROTOTYPE(static void gotoxy, (int row, int col )); -_PROTOTYPE(static void newattr, (int ch )); -_PROTOTYPE(static void Putchar, (int ch )); -_PROTOTYPE(static void clrupdate, (WINDOW *scr )); -_PROTOTYPE(static void transformline, (int lineno )); - -static void gotoxy(row, col) -int row, col; -{ - poscur(row, col); - _cursvar.cursrow = row; - _cursvar.curscol = col; -} - -/* Update attributes */ -static void newattr(ch) -int ch; -{ - extern char *me, *as, *ae, *mb, *md, *mr, *so, *us; - static int lastattr = 0; - - if (lastattr != (ch &= ATR_MSK)) { - lastattr = ch; - - tputs(me, 1, outc); - if (ae) tputs(ae, 1, outc); - - if (ch & A_ALTCHARSET) - if (as) tputs(as, 1, outc); - if (ch & A_BLINK) tputs(mb, 1, outc); - if (ch & A_BOLD) tputs(md, 1, outc); - if (ch & A_REVERSE) tputs(mr, 1, outc); - if (ch & A_STANDOUT) tputs(so, 1, outc); - if (ch & A_UNDERLINE) tputs(us, 1, outc); - } -} - -/* Putchar() writes a character, with attributes, to the physical - screen, but avoids writing to the lower right screen position. - Should it care about am? -*/ - -/* Output char with attribute */ -static void Putchar(ch) -int ch; -{ - if ((_cursvar.cursrow < LINES) || (_cursvar.curscol < COLS)) { - newattr(ch); - (void) putchar(ch); - } -} - -/****************************************************************/ -/* Clrupdate(scr) updates the screen by clearing it and then */ -/* Redraw it in it's entirety. */ -/****************************************************************/ - -static void clrupdate(scr) -WINDOW *scr; -{ - register int *src; - register int *dst; - register int i; - register int j; - WINDOW *w; - - w = curscr; - - if (scr != w) { /* copy scr to curscr */ - for (i = 0; i < LINES; i++) { - src = scr->_line[i]; - dst = w->_line[i]; - for (j = 0; j < COLS; j++) *dst++ = *src++; - } /* for */ - } /* if */ - newattr(scr->_attrs); - clrscr(); - scr->_clear = FALSE; - for (i = 0; i < LINES; i++) { /* update physical screen */ - src = w->_line[i]; - j = 0; - while (j < COLS) { - if (*src != (' ' | ATR_NRM)) { - gotoxy(i, j); - while (j < COLS && (*src != (' ' | ATR_NRM))) { - Putchar(*src++); - j++; - } - } else { - src++; - j++; - } - } /* for */ - } /* for */ - fflush(stdout); -} /* clrupdate */ - -/****************************************************************/ -/* Transformline() updates the given physical line to look */ -/* Like the corresponding line in _cursvar.tmpwin. */ -/****************************************************************/ - -static void transformline(register int lineno) -{ - register int *dstp; - register int *srcp; - int x; - int endx; - - x = twin->_minchng[lineno]; - endx = twin->_maxchng[lineno]; - dstp = curscr->_line[lineno] + x; - srcp = twin->_line[lineno] + x; - - while (x <= endx) { - if (*dstp != *srcp) { - gotoxy(lineno, x); - while (x <= endx && (*dstp != *srcp)) { - Putchar(*srcp); - *dstp++ = *srcp++; - x++; - } - } else { - *dstp++ = *srcp++; - x++; - } - } /* for */ - twin->_minchng[lineno] = _NO_CHANGE; - twin->_maxchng[lineno] = _NO_CHANGE; -} /* transformline */ - -/****************************************************************/ -/* Doupdate() updates the physical screen to look like _curs- */ -/* Var.tmpwin if curscr is not 'Clear-marked'. Otherwise it */ -/* Updates the screen to look like curscr. */ -/****************************************************************/ - -void doupdate() -{ - int i; - - twin = _cursvar.tmpwin; - if (curscr->_clear) - clrupdate(curscr); - else { - if (twin->_clear) - clrupdate(twin); - else { - for (i = 0; i < LINES; i++) - if (twin->_minchng[i] != _NO_CHANGE) - transformline(i); - } - } - curscr->_curx = twin->_curx; - curscr->_cury = twin->_cury; - gotoxy(curscr->_cury, curscr->_curx); - fflush(stdout); -} /* doupdate */ diff --git a/lib/libcurses/waddch.c b/lib/libcurses/waddch.c deleted file mode 100644 index 780b26b21..000000000 --- a/lib/libcurses/waddch.c +++ /dev/null @@ -1,95 +0,0 @@ -#include -#include "curspriv.h" - -/****************************************************************/ -/* Newline() does line advance and returns the new cursor line. */ -/* If error, return -1. */ -/****************************************************************/ - -_PROTOTYPE( static short newline, (WINDOW *win, int lin)); - -static short newline(win, lin) -WINDOW *win; -int lin; -{ - if (++lin > win->_regbottom) { - lin--; - if (win->_scroll) - scroll(win); - else - return(-1); - } /* if */ - return(lin); -} /* newline */ - -/****************************************************************/ -/* Waddch() inserts character 'c' at the current cursor posi- */ -/* Tion in window 'win', and takes any actions as dictated by */ -/* The character. */ -/****************************************************************/ - -int waddch(win, c) -WINDOW *win; -int c; -{ - int x = win->_curx; - int y = win->_cury; - int newx; - int ch = c; - int ts = win->_tabsize; - - ch &= (A_ALTCHARSET | 0xff); - if (y > win->_maxy || x > win->_maxx || y < 0 || x < 0) return(ERR); - switch (ch) { - case '\t': - for (newx = ((x / ts) + 1) * ts; x < newx; x++) { - if (waddch(win, ' ') == ERR) return(ERR); - if (win->_curx == 0) /* if tab to next line */ - return(OK); /* exit the loop */ - } - return(OK); - - case '\n': - if (NONL) x = 0; - if ((y = newline(win, y)) < 0) return (ERR); - break; - - case '\r': x = 0; break; - - case '\b': - if (--x < 0) /* no back over left margin */ - x = 0; - break; - - case 0x7f: - { - if (waddch(win, '^') == ERR) return(ERR); - return(waddch(win, '?')); - } - - default: - if (ch < ' ') { /* handle control chars */ - if (waddch(win, '^') == ERR) return(ERR); - return(waddch(win, c + '@')); - } - ch |= (win->_attrs & ATR_MSK); - if (win->_line[y][x] != ch) { /* only if data change */ - if (win->_minchng[y] == _NO_CHANGE) - win->_minchng[y] = win->_maxchng[y] = x; - else if (x < win->_minchng[y]) - win->_minchng[y] = x; - else if (x > win->_maxchng[y]) - win->_maxchng[y] = x; - } /* if */ - win->_line[y][x++] = ch; - if (x > win->_maxx) { /* wrap around test */ - x = 0; - if ((y = newline(win, y)) < 0) return(ERR); - } - break; - - } /* switch */ - win->_curx = x; - win->_cury = y; - return(OK); -} diff --git a/lib/libcurses/waddstr.c b/lib/libcurses/waddstr.c deleted file mode 100644 index b32bbb331..000000000 --- a/lib/libcurses/waddstr.c +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include "curspriv.h" - -/****************************************************************/ -/* Waddstr() inserts string 'str' at the current cursor posi- */ -/* Tion in window 'win', and takes any actions as dictated by */ -/* The characters. */ -/****************************************************************/ - -int waddstr(win, str) -WINDOW *win; -char *str; -{ - while (*str) { - if (waddch(win, *str++) == ERR) return(ERR); - } - return(OK); -} diff --git a/lib/libcurses/wbox.c b/lib/libcurses/wbox.c deleted file mode 100644 index 1ae4fe85e..000000000 --- a/lib/libcurses/wbox.c +++ /dev/null @@ -1,65 +0,0 @@ -#include -#include "curspriv.h" - -/****************************************************************/ -/* Wbox(win,ymin,xmin,ymax,xmax,v,h) draws a box in window */ -/* 'win', enclosing the area xmin-xmax and ymin-xmax. If */ -/* Xmax and/or ymax is 0, the window max value is used. 'v' and */ -/* 'h' are the vertical and horizontal characters to use. If */ -/* 'v' and 'h' are 0, wbox will use the alternate character set */ -/* In a pretty way. */ -/****************************************************************/ - -int wbox(win, ymin, xmin, ymax, xmax, v, h) -WINDOW *win; -int ymin, xmin, ymax, xmax; -unsigned int v; -unsigned int h; -{ - unsigned int vc, hc, ulc, urc, llc, lrc; /* corner chars */ - int i; - - if (ymax == 0) ymax = win->_maxy; - if (xmax == 0) xmax = win->_maxx; - - if (ymin >= win->_maxy || ymax > win->_maxy || - xmin >= win->_maxx || xmax > win->_maxx || - ymin >= ymax || xmin >= xmax) - return(ERR); - - vc = v; - hc = h; - ulc = urc = llc = lrc = vc; /* default same as vertical */ - - if (v == 0 && h == 0) { - ulc = ACS_ULCORNER; - urc = ACS_URCORNER; - llc = ACS_LLCORNER; - lrc = ACS_LRCORNER; - hc = ACS_HLINE; - vc = ACS_VLINE; - } - for (i = xmin + 1; i <= xmax - 1; i++) { - win->_line[ymin][i] = hc | win->_attrs; - win->_line[ymax][i] = hc | win->_attrs; - } - for (i = ymin + 1; i <= ymax - 1; i++) { - win->_line[i][xmin] = vc | win->_attrs; - win->_line[i][xmax] = vc | win->_attrs; - } - win->_line[ymin][xmin] = ulc | win->_attrs; - win->_line[ymin][xmax] = urc | win->_attrs; - win->_line[ymax][xmin] = llc | win->_attrs; - win->_line[ymax][xmax] = lrc | win->_attrs; - - for (i = ymin; i <= ymax; i++) { - if (win->_minchng[i] == _NO_CHANGE) { - win->_minchng[i] = xmin; - win->_maxchng[i] = xmax; - } else { - win->_minchng[i] = min(win->_minchng[i], xmin); - win->_maxchng[i] = max(win->_maxchng[i], xmax); - } - } - return(OK); -} diff --git a/lib/libcurses/wclear.c b/lib/libcurses/wclear.c deleted file mode 100644 index ba4f08fb9..000000000 --- a/lib/libcurses/wclear.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include "curspriv.h" - -/****************************************************************/ -/* Wclear() fills all lines of window 'win' with blanks, and */ -/* Marks the window to be cleared at next refresh operation. */ -/****************************************************************/ - -void wclear(win) -WINDOW *win; -{ - werase(win); - win->_clear = TRUE; -} /* wclear */ diff --git a/lib/libcurses/wclrtobot.c b/lib/libcurses/wclrtobot.c deleted file mode 100644 index 379ace470..000000000 --- a/lib/libcurses/wclrtobot.c +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include "curspriv.h" - -/****************************************************************/ -/* Wclrtobot() fills the right half of the cursor line of */ -/* Window 'win', and all lines below it with blanks. */ -/****************************************************************/ - -int wclrtobot(win) -WINDOW *win; -{ - int y, minx, startx, *ptr, *end, *maxx, blank; - - blank = ' ' | (win->_attrs & ATR_MSK); - startx = win->_curx; - for (y = win->_cury; y <= win->_regbottom; y++) { - minx = _NO_CHANGE; - end = &win->_line[y][win->_maxx]; - for (ptr = &win->_line[y][startx]; ptr <= end; ptr++) { - if (*ptr != blank) { - maxx = ptr; - if (minx == _NO_CHANGE) minx = ptr - win->_line[y]; - *ptr = blank; - } /* if */ - } /* for */ - if (minx != _NO_CHANGE) { - if ((win->_minchng[y] > minx) || (win->_minchng[y] == _NO_CHANGE)) - win->_minchng[y] = minx; - if (win->_maxchng[y] < maxx - win->_line[y]) - win->_maxchng[y] = maxx - win->_line[y]; - } /* if */ - startx = 0; - } - return(OK); -} diff --git a/lib/libcurses/wclrtoeol.c b/lib/libcurses/wclrtoeol.c deleted file mode 100644 index ea72976a8..000000000 --- a/lib/libcurses/wclrtoeol.c +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include "curspriv.h" - -/****************************************************************/ -/* Wclrtoeol() fills the half of the cursor line to the right */ -/* Of the cursor in window 'win' with blanks. */ -/****************************************************************/ - -int wclrtoeol(win) -WINDOW *win; -{ - int *maxx, *ptr, *end, y, x, minx, blank; - - y = win->_cury; - x = win->_curx; - blank = ' ' | (win->_attrs & ATR_MSK); - - end = &win->_line[y][win->_maxx]; - minx = _NO_CHANGE; - maxx = &win->_line[y][x]; - for (ptr = maxx; ptr <= end; ptr++) { - if (*ptr != blank) { - maxx = ptr; - if (minx == _NO_CHANGE) minx = ptr - win->_line[y]; - *ptr = blank; - } /* if */ - } /* for */ - - if (minx != _NO_CHANGE) { - if (win->_minchng[y] > minx || win->_minchng[y] == _NO_CHANGE) - win->_minchng[y] = minx; - if (win->_maxchng[y] < maxx - win->_line[y]) - win->_maxchng[y] = maxx - win->_line[y]; - } - return(OK); -} diff --git a/lib/libcurses/wdelch.c b/lib/libcurses/wdelch.c deleted file mode 100644 index 0fe8c2cfe..000000000 --- a/lib/libcurses/wdelch.c +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include "curspriv.h" - -/* Wdelch() deletes the character at the window cursor, and the - characters to the right of it are shifted left, inserting a - space at the last position of the line. -*/ - -int wdelch(win) -WINDOW *win; -{ - int *temp1; - int *temp2; - int *end; - int y = win->_cury; - int x = win->_curx; - int maxx = win->_maxx; - - end = &win->_line[y][maxx]; - temp1 = &win->_line[y][x]; - temp2 = temp1 + 1; - while (temp1 < end) *temp1++ = *temp2++; - *temp1 = ' ' | (win->_attrs & ATR_MSK); - win->_maxchng[y] = maxx; - if (win->_minchng[y] == _NO_CHANGE || win->_minchng[y] > x) - win->_minchng[y] = x; - return(OK); -} diff --git a/lib/libcurses/wdeleteln.c b/lib/libcurses/wdeleteln.c deleted file mode 100644 index 50faa4461..000000000 --- a/lib/libcurses/wdeleteln.c +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include "curspriv.h" - -/****************************************************************/ -/* Wdeleteln() deletes the line at the window cursor, and the */ -/* Lines below it are shifted up, inserting a blank line at */ -/* The bottom of the window. */ -/****************************************************************/ - -int wdeleteln(win) -WINDOW *win; -{ - int *end, *temp, y, blank; - - blank = ' ' | (win->_attrs & ATR_MSK); - - temp = win->_line[win->_cury]; - for (y = win->_cury; y < win->_regbottom; y++) { - win->_line[y] = win->_line[y + 1]; - win->_minchng[y] = 0; - win->_maxchng[y] = win->_maxx; - } - win->_minchng[y] = 0; - win->_maxchng[y] = win->_maxx; - win->_line[win->_regbottom] = temp; - for (end = &(temp[win->_maxx]); temp <= end;) *temp++ = blank; - return(OK); -} diff --git a/lib/libcurses/werase.c b/lib/libcurses/werase.c deleted file mode 100644 index 46872b8ce..000000000 --- a/lib/libcurses/werase.c +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include "curspriv.h" - -/****************************************************************/ -/* Werase() fills all lines of window 'win' with blanks and po- */ -/* Sitions the cursor at home in the scroll region. */ -/****************************************************************/ - -void werase(win) -WINDOW *win; -{ - int *end, *start, y, blank; - - blank = ' ' | (win->_attrs & ATR_MSK); - - for (y = win->_regtop; y <= win->_regbottom; y++) { /* clear all lines */ - start = win->_line[y]; - end = &start[win->_maxx]; - while (start <= end) /* clear all line */ - *start++ = blank; - win->_minchng[y] = 0; - win->_maxchng[y] = win->_maxx; - } - win->_cury = win->_regtop; /* cursor home */ - win->_curx = 0; -} diff --git a/lib/libcurses/wgetch.c b/lib/libcurses/wgetch.c deleted file mode 100644 index 88768558a..000000000 --- a/lib/libcurses/wgetch.c +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include -#include "curspriv.h" - -int wgetch(win) -WINDOW *win; -{ - bool weset = FALSE; - char inp; - - if (!win->_scroll && (win->_flags & _FULLWIN) - && win->_curx == win->_maxx - 1 && win->_cury == win->_maxy - 1) - return ERR; - if (_cursvar.echoit && !_cursvar.rawmode) { - cbreak(); - weset++; - } - inp = getchar(); - if (_cursvar.echoit) { - (void) mvwaddch(curscr, win->_cury + win->_begy, - win->_curx + win->_begx, inp); - waddch(win, inp); - } - if (weset) nocbreak(); - return inp; -} diff --git a/lib/libcurses/wgetstr.c b/lib/libcurses/wgetstr.c deleted file mode 100644 index 2458e4b89..000000000 --- a/lib/libcurses/wgetstr.c +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include "curspriv.h" - -/****************************************************************/ -/* Wgetstr(win,str) reads in a string (terminated by \n or \r) */ -/* To the buffer pointed to by 'str', and displays the input */ -/* In window 'win'. The user's erase and kill characters are */ -/* Active. */ -/****************************************************************/ - -int wgetstr(win, str) -WINDOW *win; -char *str; -{ - while ((*str = wgetch(win)) != ERR && *str != '\n') str++; - if (*str == ERR) { - *str = '\0'; - return ERR; - } - *str = '\0'; - return OK; -} diff --git a/lib/libcurses/windel.c b/lib/libcurses/windel.c deleted file mode 100644 index ad67bd872..000000000 --- a/lib/libcurses/windel.c +++ /dev/null @@ -1,41 +0,0 @@ -/****************************************************************/ -/* Delwin() routine of the PCcurses package. */ -/* */ -/****************************************************************/ -/* This version of curses is based on ncurses, a curses version */ -/* Originally written by Pavel Curtis at Cornell University. */ -/* I have made substantial changes to make it run on IBM PC's, */ -/* And therefore consider myself free to make it public domain. */ -/* Bjorn Larsson (...mcvax!enea!infovax!bl) */ -/****************************************************************/ -/* 1.0: Release: 870515 */ -/****************************************************************/ -/* Modified to run under the MINIX operating system by Don Cope */ -/* These changes are also released into the public domain. */ -/* 900906 */ -/****************************************************************/ - -#include -#include -#include "curspriv.h" - -/****************************************************************/ -/* Delwin() deallocates all data allocated by 'win'. If 'win' */ -/* Is a subwindow, it uses the original window's lines for sto- */ -/* Rage, and thus the line arrays are not deallocated. */ -/****************************************************************/ - -void delwin(win) -WINDOW *win; -{ - int i; - - if (!(win->_flags & _SUBWIN)) { /* subwindow uses 'parent's' lines */ - for (i = 0; i <= win->_maxy && win->_line[i]; i++) - free(win->_line[i]); - } - free(win->_minchng); - free(win->_maxchng); - free(win->_line); - free(win); -} /* delwin */ diff --git a/lib/libcurses/winmove.c b/lib/libcurses/winmove.c deleted file mode 100644 index ac8c13308..000000000 --- a/lib/libcurses/winmove.c +++ /dev/null @@ -1,36 +0,0 @@ -/****************************************************************/ -/* Mvwin() routine of the PCcurses package */ -/* */ -/****************************************************************/ -/* This version of curses is based on ncurses, a curses version */ -/* Originally written by Pavel Curtis at Cornell University. */ -/* I have made substantial changes to make it run on IBM PC's, */ -/* And therefore consider myself free to make it public domain. */ -/* Bjorn Larsson (...mcvax!enea!infovax!bl) */ -/****************************************************************/ -/* 1.0: Release: 870515 */ -/****************************************************************/ -/* Modified to run under the MINIX operating system by Don Cope */ -/* These changes are also released into the public domain. */ -/* 900906 */ -/****************************************************************/ - -#include -#include "curspriv.h" - -/****************************************************************/ -/* Mvwin() moves window 'win' to position (begx, begy) on the */ -/* Screen. */ -/****************************************************************/ - -int mvwin(win, begy, begx) -WINDOW *win; -int begy, begx; -{ - if ((begy + win->_maxy) > (LINES - 1) || (begx + win->_maxx) > (COLS - 1)) - return(ERR); - win->_begy = begy; - win->_begx = begx; - touchwin(win); - return(OK); -} /* mvwin */ diff --git a/lib/libcurses/winsch.c b/lib/libcurses/winsch.c deleted file mode 100644 index b7c943089..000000000 --- a/lib/libcurses/winsch.c +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include "curspriv.h" - -/* Winsch() inserts character 'c' at the cursor position in - window 'win'. The cursor is advanced. -*/ - -int winsch(win, c) -WINDOW *win; -char c; -{ - int *temp1; - int *temp2; - int *end; - int x = win->_curx; - int y = win->_cury; - int maxx = win->_maxx; - - if ((c < ' ') && (c == '\n' || c == '\r' || c == '\t' || c == '\b')) - return(waddch(win, c)); - end = &win->_line[y][x]; - temp1 = &win->_line[y][maxx]; - temp2 = temp1 - 1; - if (c < ' ') /* if CTRL-char make space for 2 */ - temp2--; - while (temp1 > end) *temp1-- = *temp2--; - win->_maxchng[y] = maxx; - if ((win->_minchng[y] == _NO_CHANGE) || (win->_minchng[y] > x)) - win->_minchng[y] = x; - return(waddch(win, c)); /* fixes CTRL-chars too */ -} /* winsch */ diff --git a/lib/libcurses/winscrol.c b/lib/libcurses/winscrol.c deleted file mode 100644 index 7fd9dd3d3..000000000 --- a/lib/libcurses/winscrol.c +++ /dev/null @@ -1,55 +0,0 @@ -/****************************************************************/ -/* Scroll() routine of the PCcurses package */ -/* */ -/****************************************************************/ -/* This version of curses is based on ncurses, a curses version */ -/* Originally written by Pavel Curtis at Cornell University. */ -/* I have made substantial changes to make it run on IBM PC's, */ -/* And therefore consider myself free to make it public domain. */ -/* Bjorn Larsson (...mcvax!enea!infovax!bl) */ -/****************************************************************/ -/* 1.0: Release: 870515 */ -/****************************************************************/ -/* Modified to run under the MINIX operating system by Don Cope */ -/* These changes are also released into the public domain. */ -/* 900906 */ -/****************************************************************/ - -#include -#include "curspriv.h" - -/****************************************************************/ -/* Scroll() scrolls the scrolling region of 'win', but only if */ -/* Scrolling is allowed and if the cursor is inside the scrol- */ -/* Ling region. */ -/****************************************************************/ - -void scroll(win) -WINDOW *win; -{ - int i; - int *ptr; - int *temp; - static int blank; - - blank = ' ' | (win->_attrs & ATR_MSK); - if ((!win->_scroll) /* check if window scrolls */ - ||(win->_cury < win->_regtop) /* and cursor in region */ - ||(win->_cury > win->_regbottom) - ) - return; - - temp = win->_line[win->_regtop]; - for (i = win->_regtop; i < win->_regbottom; i++) { - win->_line[i] = win->_line[i + 1]; /* re-arrange line pointers */ - win->_minchng[i] = 0; - win->_maxchng[i] = win->_maxx; - } - for (ptr = temp; ptr - temp <= win->_maxx; ptr++) - *ptr = blank; /* make a blank line */ - win->_line[win->_regbottom] = temp; - if (win->_cury > win->_regtop)/* if not on top line */ - win->_cury--; /* cursor scrolls too */ - win->_minchng[win->_regbottom] = 0; - win->_maxchng[win->_regbottom] = win->_maxx; -} /* scroll */ diff --git a/lib/libcurses/winsertln.c b/lib/libcurses/winsertln.c deleted file mode 100644 index fa6b83f27..000000000 --- a/lib/libcurses/winsertln.c +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include "curspriv.h" - -/****************************************************************/ -/* Winsertln() inserts a blank line instead of the cursor line */ -/* In window 'win' and pushes other lines down. */ -/****************************************************************/ - -int winsertln(win) -WINDOW *win; -{ - int *temp, *end, y, blank; - - blank = ' ' | (win->_attrs & ATR_MSK); - temp = win->_line[win->_regbottom]; - for (y = win->_regbottom; y > win->_cury; y--) { - win->_line[y] = win->_line[y - 1]; - win->_minchng[y] = 0; - win->_maxchng[y] = win->_maxx; - } - win->_line[win->_cury] = temp; - for (end = &temp[win->_maxx]; temp <= end; temp++) *temp = blank; - win->_minchng[win->_cury] = 0; - win->_maxchng[win->_cury] = win->_maxx; - return(OK); -} diff --git a/lib/libcurses/wintouch.c b/lib/libcurses/wintouch.c deleted file mode 100644 index 05f5d78d6..000000000 --- a/lib/libcurses/wintouch.c +++ /dev/null @@ -1,40 +0,0 @@ -/****************************************************************/ -/* Touchwin() routine of the PCcurses package */ -/* */ -/****************************************************************/ -/* This version of curses is based on ncurses, a curses version */ -/* Originally written by Pavel Curtis at Cornell University. */ -/* I have made substantial changes to make it run on IBM PC's, */ -/* And therefore consider myself free to make it public domain. */ -/* Bjorn Larsson (...mcvax!enea!infovax!bl) */ -/****************************************************************/ -/* 1.0: Release: 870515 */ -/****************************************************************/ -/* Modified to run under the MINIX operating system by Don Cope */ -/* These changes are also released into the public domain. */ -/* 900906 */ -/****************************************************************/ - -#include -#include "curspriv.h" - -/****************************************************************/ -/* Touchwin() marks all lines of window 'win' as changed, from */ -/* The first to the last character on the line. */ -/****************************************************************/ - -void touchwin(win) -WINDOW *win; -{ - int y; - int maxy; - int maxx; - - maxy = win->_maxy; - maxx = win->_maxx; - - for (y = 0; y <= maxy; y++) { - win->_minchng[y] = 0; - win->_maxchng[y] = maxx; - } /* for */ -} /* touchwin */ diff --git a/man/man1/Makefile b/man/man1/Makefile index a054b52fb..be965cd4f 100644 --- a/man/man1/Makefile +++ b/man/man1/Makefile @@ -20,7 +20,7 @@ MAN= acd.1 anm.1 ar.1 ash.1 asize.1 at.1 banner.1 basename.1 \ shar.1 acksize.1 sleep.1 sort.1 soundoff.1 soundon.1 spell.1 \ split.1 strip.1 stty.1 su.1 sum.1 svc.1 \ synctree.1 sysenv.1 sz.1 tail.1 tee.1 telnet.1 template.1 \ - term.1 termcap.1 tget.1 time.1 top.1 tr.1 true.1 \ + term.1 termcap.1 tget.1 time.1 tr.1 true.1 \ truncate.1 tsort.1 tty.1 umount.1 uname.1 unexpand.1 \ uud.1 uue.1 vol.1 wc.1 whereis.1 which.1 \ who.1 write.1 xargs.1 yap.1 yes.1 linkfarm.1 pkg_view.1 diff --git a/man/man1/top.1 b/man/man1/top.1 deleted file mode 100644 index 750de7b32..000000000 --- a/man/man1/top.1 +++ /dev/null @@ -1,72 +0,0 @@ -.TH TOP 1 -.SH NAME -top \- show processes sorted by CPU usage -.SH SYNOPSIS -\fBtop\fP [\fB\-s\fIdelay\fP] [\fB\-B\fP] -.SH DESCRIPTION -Top displays a list of all running processes, once every update interval -(currently 5 seconds). It is sorted by the CPU usage of the processes in -the last interval. The first display is the CPU usage of processes since -the boot time. - -.SH OPTIONS -.PP - \fB\-s\fP\fIdelay\fP The number of seconds between screen updates. - - \fB\-B\fP Blocked-verbose mode. - For every process that is blocked, - display the chain of block-dependencies up until the process - that is either not blocked or blocked on ANY. - -At the top of the screen, top shows the current system load averages in -the last 1-minute, 5-minute and 15-minute intervals. Then, over the -last top interval it displays: the number of alive, active, and sleeping -processes; memory free; and CPU usage. CPU usage is split into -user, kernel, system and idle time. Kernel time is time spent in -the kernel. System time are system user processes, such as drivers and -servers. User time is all other CPU time. - -Then it displays all the alive processes sorted by CPU usage in the last -interval, with a number of fields for every process. Currently the -following fields are displayed: -.PP - PID - The process id of the process. Some processes (so-called kernel - tasks) don't have a real process id, as they are not processes - that are managed by the process manager, and aren't visible to - other user processes by pid. They are shown by having their process - slot number in square brackets. - USERNAME - The username of the effective uid at which the process runs, - or a number if the username could not be looked up. - PRI - The system scheduling priority the process is currently running as. - A lower priority number gives a higher scheduling priority. The - lowest is 0. The scale is internal to the kernel. - NICE - The base scheduling priority the process has been given at startup. - 0 is normal for a regular user process; the range is -20 to 20 - (PRIO_MIN and PRIO_MAX in . Most system processes - are given higher base priorities. - SIZE - Text + data size in kilobytes. - STATE - RUN if the process is runnable, empty if blocking. - TIME - Total number of CPU time spent in the process itself. So-called - system time (CPU time spent on behalf of this process by another - process, generally a system process) is not seen here. - CPU - Percentage of time that the process was running in the last interval. - COMMAND - Name of the command that belongs to this process. - -.SH "SEE ALSO" -.BR ps (1) -.SH BUGS -This is a from-scratch reimplementation of top for MINIX 3. -Many features (such as interactive commands) are not implemented. -Sorting is only done by CPU usage currently. Displayed state is -only RUN or empty. -.SH AUTHOR -Ben Gras (beng@few.vu.nl) diff --git a/man/man3/Makefile b/man/man3/Makefile index e13ef92db..f72e864f2 100644 --- a/man/man3/Makefile +++ b/man/man3/Makefile @@ -1,5 +1,5 @@ MAN= abort.3 abs.3 assert.3 atof.3 bstring.3 configfile.3 \ - crypt.3 ctime.3 ctype.3 curses.3 directory.3 dirname.3 \ + crypt.3 ctime.3 ctype.3 directory.3 dirname.3 \ editline.3 end.3 execl.3 exit.3 fabs.3 fclose.3 \ feholdexcept.3 ferror.3 fesetround.3 fnmatch.3 fopen.3 \ fpclassify.3 fread.3 fseek.3 getaddrinfo.3 getc.3 getcontext.3 \ diff --git a/man/man3/curses.3 b/man/man3/curses.3 deleted file mode 100644 index e9eaa3e94..000000000 --- a/man/man3/curses.3 +++ /dev/null @@ -1,248 +0,0 @@ -.TH CURSES 3 -.SH NAME -curses \- screen/window management library -.SH SYNOPSIS -cc demo.c -lcurses -.SH DESCRIPTION -Curses is a library of screen and window management routines. It is modeled -after the UNIX curses and ncurses libraries. Normally, programs written for -curses should be easily ported to UNIX, and vice versa. -.PP -To use the routines, the function initscr() must first be called. -This creates two 'windows' for the user: stdscr and curscr. Stdscr is the -default -window for the user to make changes on, and curscr reflects the current -contents of the physical display screen. The user writes or edits the stdscr -window to his liking, then calls the refresh() function to make curscr -and the physical screen look like stdscr. When the user program terminates, -it should call the endwin() function to restore things to normal. -.PP -There are all sorts of window manipulation routines available to the -programmer: auxiliary windows may be created, edited, moved and deleted. The -terminal may be set in many different modes, output text may be attributed -with blink, blank, bold and reverse attributes. Screen colors may also be -set, foreground and background. There are window-specific -printf- and scanf-like routines, routines for scrolling, box-drawing, -window overlaying, clearing routines etc. -.PP -For more and detailed information, see the library source codes. All curses -functions are preceded by a complete description. -.SH FUNCTIONS -Below is a list over the available functions, together with a brief -description of what they do. In general, functions whose names start with 'w' -differ from the one without 'w' (like wmove vs. move) signify that -a specific window is used. Without a 'w', sdtscr is implied. The functions -that start with 'mv' before the 'genereic' function name signify that a -cursor motion should be made before the actual work. 'mv' and 'w' combine -as expected. -.PP -Most routines that return an int will return the manifest constant ERR if -there is a failure during execution. Routines that return a char actually -return an int, so that ERR does not conflict with the character code 0xff. -All characters from 0 to 0xff are allowed for usage with curses. -.PP -Some routines, like {mv}{w} printw() and {mv}{w}scanw() return a meaningful -positive value if the operation is successful. -.PP -The curses package uses some predefined types, variables and manifest -constants that are also available to the programmer. There are also a few -globally accessible variables that should not be touched by the application -program. Those untouchable variables have names starting with an -underscore (_) to avoid conflicts. The user-accessible types, variables -and constants are (there are a number of other constants defining character -attribute names and function key names - consult for details): -.sp -.nf -.ta 3i -(manifest constants) -.RS -TRUE boolean true -FALSE boolean false -ERR unsuccessfull operation -OK successfull operation -.RE -.sp -(types) -.RS -WINDOW a window structure type -bool boolean flag type -.RE -.sp -(variables) -.RS -WINDOW curscr physical display image -WINDOW stdscr default user drawing board -int LINES terminal height -int COLS terminal width -int NONL \\n causes CR and LF when TRUE -.RE -.sp -.fi -The following is an alphabetical list of the curses functions, together -with their types, parameters and a short comment for each (win is a window, -ch, vc, hc are characters, buf is a character buffer, attrs is an -attribute bit map, bf is a boolean flag. Note that `characters' in this -context usually can have 16 bits): -.nf -.sp -int waddch(win,ch) put char in stdscr -int addch(ch) -int mvaddch(y,x,ch) -int mvwaddch(win,y,x,ch) - -int waddstr(win,str) put string in stdscr -int addstr(str) -int mvaddstr(y,x,str) -int mvwaddstr(win,y,x,str) - -void wattroff(win,attrs) clear attribute(s) in window -void attroff(attrs) - -void wattron(win,attrs) add attribute(s) in window -void attron(attrs) - -void wattrset(win,attrs) set window char attributes -void attrset(attrs) - -int baudrate() dummy for compatibility - -void beep() ring the bell or visible bell if no bell available - -void flash() flash terminal screen or rings bell if no visible bell available - -void wbox(win,miny,minx,maxy,maxx,vc,hc) box in a window, with given characters -void box(win,vc,hc) - -void cbreak() set terminal cbreak mode - -void wclear(win) clear stdscr -void clear() - -void clearok(win,bf) marks window for screen clear - -int wclrtobot(win) clear from cursor to end of line and all lines down this line -int clrtobot() -int mvclrtoeol(y,x) -int mvwclrtobot(win,y,x) - -int wclrtoeol(win) clear from cursor to end of line -int clrtoeol() -int mvclrtoeol(y,x) -int mvwclrtoeol(win,y,x) - -int wdelch(win) delete a char in a window -int delch() -int mvdelch(y,x) -int mvwdelch(win,y,x) - -int wdeleteln(win) delete a line in a window -int deleteln() -int mvdeleteln(y,x) -int mvwdeleteln(win,y,x) - -void delwin(win) delete a window or a subwindow -void doupdate() update physical screen -void echo() set terminal echo mode -int endwin() cleanup and curses finitialization - -void werase(win) erase a window -void erase() - -int erasechar() return char delete character -int fixterm() dummy for compatibility -void flushinp() kill pending keyboard input - -int wgetch(win) get char via a window -int getch() -int mvgetch(y,x) -int mvwgetch(win,y,x) - -int wgetstr(win,str) get string via window to a buffer -int getstr(str) -int mvgetstr(y,x,str) -int mvwgetstr(win,y,x,str) - -void getyx(win,y,x) get a window's cursor position - -int gettmode() dummy for compatibility -void idlok(win,bf) dummy for compatibility -WINDOW *initscr() curses initialization (ret stdscr or NULL) - -int winch(win) get char at window cursor -int inch() -int mvinch(y,x) -int mvwinch(win,y,x) - -int winsch(win,ch) insert character in a window -int insch(ch) -int mvinsch(y,x,ch) -int mvwinsch(win,y,x,ch) - -int winsertln(win) insert new line in a window -int insertln() -int mvinsertln(y,x) -int mvwinsertln(win,y,x) - -void keypad(win,bf) marks a window for keypad usage -int killchar() return line delete character -char *longname() returns terminal description string -void leaveok(win,bf) marks window for cursor 'update leave' -void meta(win,bf) marks window for meta -int move(y,x) move cursor in stdscr -int mvcur(oldy,oldx,y,x) move terminal cursor to - -int mvprintw(y,x,fmt,args) move & print string in stdscr - -int mvscanw(y,x,fmt,args) move & get values via stdscr -int mvwin(win,y,x) move window on physical screen -int mvwprintw(win,x,y,fmt,args) move & print string in a window -int mvwscanw(win,y,x,fmt,args) move & get values via a window -WINDOW *newwin(lines,cols,begy,begx) create a new window -void nl() set terminal cr-crlf mapping mode -void nocbreak() unset terminal cbreak mod -void nodelay(win,bf) marks window for no input wait -void noecho() unset terminal echo mode -void nonl() unset terminal cr-crlf mapping mode -void noraw() unset raw terminal mode -void overlay(win1,win2) overlay one window on another -void overwrite(win1,win2) overwrite one window on another -int printw(fmt,args) print string in stdscr -void raw() set raw terminal mode -void refrbrk(bf) set screen update break mode -void refresh() refresh stdscr -int resetterm() dummy for compatibility -int resetty() restore terminal I/O modes -int saveoldterm() dummy for compatibility -int saveterm() dummy for compatibility -int savetty() save terminal I/O modes -int scanw(fmt,args) get values via stdscr -void scroll(win) scroll scrolling region of a window -void scrollok(win,bf) marks a window to allow scroll -void setcolors(A_COLOR(for,back)) sets the forground and background - colors of stdscr -void set_curs(visibility) 0 for invisible, 1 for visible, 2 for good - visible -int setsrcreg(miny,maxy) define stdscr's scroll region -int setterm() dummy for compatibility -int setupterm(term,fd,errret) set up terminal -void standend() start normal chars in stdscr -void standout() start standout chars in stdscr -WINDOW *subwin(win,lines,cols,begy,begx) - create a sub-window in window win -int tabsize(ts) set/get tabsize of stdscr -void touchwin(win) mark a window as totally modified -char *unctrl(ch) char-to-string converter -int wmove(win,y,x) move cursor in a window -void wnoutrefresh(win) create internal screen image -int wprintw(win,fmt,args) print string in a window -void wrefresh(win) refresh window -int wscanw(win,fmt,args) get values via a window -void wsetcolors(win,A_COLOR(for,back)) sets the forground and - background colors of the specified window -int wsetsrcreg(win,miny,maxy) define a window's scrolling region -void wstandend(win) start normal chars in window -void wstandout(win) start standout chars in window -int wtabsize(win,ts) set/get tabsize of a window -.SH BUGS -Function keys are not available under the MINIX version. -.\" $PchId: curses.3,v 1.3 1996/02/22 21:26:28 philip Exp $ diff --git a/share/mk/Makefile b/share/mk/Makefile index f2bcc1cb0..a670a3845 100644 --- a/share/mk/Makefile +++ b/share/mk/Makefile @@ -7,7 +7,7 @@ FILES= bsd.dep.mk bsd.files.mk \ bsd.inc.mk \ bsd.init.mk bsd.kinc.mk bsd.klinks.mk bsd.lib.mk \ bsd.links.mk bsd.man.mk bsd.obj.mk bsd.own.mk \ - bsd.prog.mk bsd.subdir.mk bsd.sys.mk \ + bsd.prog.mk bsd.subdir.mk bsd.sys.mk bsd.doc.mk \ sys.mk # MINIX-specific files diff --git a/share/mk/bsd.doc.mk b/share/mk/bsd.doc.mk new file mode 100644 index 000000000..d6fd9def9 --- /dev/null +++ b/share/mk/bsd.doc.mk @@ -0,0 +1,73 @@ +# $NetBSD: bsd.doc.mk,v 1.64 2006/03/16 18:43:34 jwise Exp $ +# @(#)bsd.doc.mk 8.1 (Berkeley) 8/14/93 + +.include + +##### Basic targets +clean: cleandoc +realinstall: docinstall + +##### Build rules +.if !target(paper.ps) +paper.ps: ${SRCS} + ${_MKTARGET_FORMAT} + ${TOOL_ROFF_PS} ${MACROS} ${PAGES} ${.ALLSRC} > ${.TARGET} +.endif + +.if ${MKSHARE} != "no" +realall: paper.ps +.endif + +##### Install rules +docinstall:: # ensure existence +.PHONY: docinstall + +.if ${MKDOC} != "no" + +__docinstall: .USE + ${_MKTARGET_INSTALL} + ${INSTALL_FILE} -o ${DOCOWN} -g ${DOCGRP} -m ${DOCMODE} \ + ${.ALLSRC} ${.TARGET} + +FILES?= ${SRCS} + +.for F in Makefile ${FILES:O:u} ${EXTRA} +_F:= ${DESTDIR}${DOCDIR}/${DIR}/${F} # installed path + +.if ${MKUPDATE} == "no" +${_F}! ${F} __docinstall # install rule +.if !defined(BUILD) && !make(all) && !make(${F}) +${_F}! .MADE # no build at install +.endif +.else +${_F}: ${F} __docinstall # install rule +.if !defined(BUILD) && !make(all) && !make(${F}) +${_F}: .MADE # no build at install +.endif +.endif + +docinstall:: ${_F} +.PRECIOUS: ${_F} # keep if install fails +.endfor + +.undef _F +.endif # ${MKDOC} != "no" + +##### Clean rules +cleandoc: .PHONY + rm -f paper.* [eE]rrs mklog ${CLEANFILES} + +##### Custom rules +.if !target(print) +print: .PHONY paper.ps + lpr -P${PRINTER} ${.ALLSRC} +.endif + +spell: .PHONY ${SRCS} + spell ${.ALLSRC} | sort | comm -23 - spell.ok > paper.spell + +##### Pull in related .mk logic +.include +.include + +${TARGETS}: # ensure existence diff --git a/tools/nbsd_ports b/tools/nbsd_ports index c7b04ba79..e89461449 100644 --- a/tools/nbsd_ports +++ b/tools/nbsd_ports @@ -3,6 +3,7 @@ lib/nbsd_libc src/lib/libc lib/nbsd_libm src/lib/libm lib/libcrypt src/lib/libcrypt lib/libterminfo src/lib/libterminfo +lib/libcurses src/lib/libcurses nbsd_include src/include usr.bin/m4 src/usr.bin/m4 usr.bin/indent src/usr.bin/indent diff --git a/usr.bin/Makefile b/usr.bin/Makefile index d64f61319..79e5a6b96 100644 --- a/usr.bin/Makefile +++ b/usr.bin/Makefile @@ -8,4 +8,7 @@ SUBDIR= indent m4 stat tic sed mkdep uniq # Non-NetBSD imports SUBDIR+= ministat mkimage +# Minix commands +SUBDIR+= top + .include diff --git a/usr.bin/Makefile.inc b/usr.bin/Makefile.inc index fb17b6ac9..7c252331e 100644 --- a/usr.bin/Makefile.inc +++ b/usr.bin/Makefile.inc @@ -2,7 +2,7 @@ CC:=${CC:C/^cc/clang/} COMPILER_TYPE:= gnu -CPPFLAGS+= -D_NETBSD_SOURCE +CPPFLAGS+= -D_NETBSD_SOURCE -D__NBSD_LIBC=1 BINDIR?=/usr/bin diff --git a/usr.bin/top/Makefile b/usr.bin/top/Makefile new file mode 100644 index 000000000..52efde9e2 --- /dev/null +++ b/usr.bin/top/Makefile @@ -0,0 +1,7 @@ +PROG= top +MAN= + +DPADD+= ${LIBCURSES} ${LIBTERMINFO} +LDADD+= -lcurses -lterminfo + +.include diff --git a/commands/top/top.c b/usr.bin/top/top.c similarity index 98% rename from commands/top/top.c rename to usr.bin/top/top.c index 1669f7412..950b245a2 100644 --- a/commands/top/top.c +++ b/usr.bin/top/top.c @@ -6,10 +6,10 @@ #define _POSIX_SOURCE 1 #include +#include #include #include #include -#include #include #include #include @@ -234,8 +234,8 @@ int print_memory(void) fclose(fp); - printf("main memory: %uK total, %uK free, %uK contig free, " - "%uK cached\n", + printf("main memory: %ldK total, %ldK free, %ldK contig free, " + "%ldK cached\n", (pagesize * total)/1024, (pagesize * free)/1024, (pagesize * largest)/1024, (pagesize * cached)/1024); @@ -364,7 +364,7 @@ void print_proc(struct tp *tp, u32_t tcyc) printf("%6ldK", (pr->p_memory + 512) / 1024); printf("%6s", (pr->p_flags & BLOCKED) ? "" : "RUN"); ticks = pr->p_user_time; - printf(" %3ld:%02ld ", (ticks/system_hz/60), (ticks/system_hz)%60); + printf(" %3u:%02u ", (ticks/system_hz/60), (ticks/system_hz)%60); pcyc = div64u(tp->ticks, SCALE); @@ -598,12 +598,6 @@ void init(int *rows) if((v = tgetstr ("li", &s)) != NULL) sscanf(v, "%d", rows); if(*rows < 1) *rows = 24; - if(!initscr()) { - fprintf(stderr, "initscr() failed\n"); - exit(1); - } - cbreak(); - nl(); } void sigwinch(int sig) { } @@ -677,6 +671,7 @@ int main(int argc, char *argv[]) FD_ZERO(&fds); FD_SET(STDIN_FILENO, &fds); + if((ns=select(STDIN_FILENO+1, &fds, NULL, NULL, &tv)) < 0 && errno != EINTR) { perror("select"); -- 2.44.0