diff options
Diffstat (limited to 'lib/libcurses')
242 files changed, 21343 insertions, 10109 deletions
diff --git a/lib/libcurses/Caps b/lib/libcurses/Caps index 4e415b489e8..b24520ba66c 100644 --- a/lib/libcurses/Caps +++ b/lib/libcurses/Caps @@ -1,5 +1,7 @@ +# $OpenBSD: Caps,v 1.6 2010/01/12 23:21:58 nicm Exp $ + ############################################################################## -# Copyright (c) 1998 Free Software Foundation, Inc. # +# Copyright (c) 1998-2002,2006 Free Software Foundation, Inc. # # # # Permission is hereby granted, free of charge, to any person obtaining a # # copy of this software and associated documentation files (the "Software"), # @@ -29,8 +31,7 @@ # Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 # and: Eric S. Raymond <esr@snark.thyrsus.com> # -# $OpenBSD: Caps,v 1.5 2000/10/22 18:27:18 millert Exp $ -# $From: Caps,v 1.30 2000/10/14 17:36:14 tom Exp $ +# $Id: Caps,v 1.6 2010/01/12 23:21:58 nicm Exp $ # # This is the master termcap/terminfo capability table. # @@ -50,11 +51,13 @@ # Column 2: terminfo capability name # Column 3: capability type (boolean, numeric, or string) # Column 4: termcap capability name -# Column 5: Lead with `Y' if capability should be emitted in termcap +# Column 5: KEY_xxx name, if any, `-' otherwise +# Column 6: value for KEY_xxx name, if any, `-' otherwise +# Column 7: Lead with `Y' if capability should be emitted in termcap # translations, `-' otherwise -# Column 6: capability description +# Column 8: capability description # -# The codes following [Y-] in column 5 describe the versions of termcap which +# The codes following [Y-] in column 7 describe the versions of termcap which # use the given capability. This information is not used by the curses library # proper; rather, it's there to help the terminfo maintainer avoid emitting # termcap entry translations that are more than 1023 bytes long (and tank a @@ -68,7 +71,7 @@ # translation if possible. The problem is that preserving all such caps may # lead to some termcap translations being too long. The termcap maintainer # has a bit of a juggling act to do...potential problem cases are marked with -# a * or **. +# an asterisk (*). # # The aliases section has the following format: # @@ -208,43 +211,43 @@ #%lw25 lw6 lw2 lw20. #%\fBVariable Cap- TCap Description\fR #%\fBBooleans name Code\fR -auto_left_margin bw bool bw YB-G- cub1 wraps from column 0 to last column -auto_right_margin am bool am YBCGE terminal has automatic margins -no_esc_ctlc xsb bool xb YBCG- beehive (f1=escape, f2=ctrl C) -ceol_standout_glitch xhp bool xs YBCGE standout not erased by overwriting (hp) -eat_newline_glitch xenl bool xn YBCGE newline ignored after 80 cols (concept) -erase_overstrike eo bool eo YBCG- can erase overstrikes with a blank -generic_type gn bool gn YB-G- generic line type -hard_copy hc bool hc YBCG- hardcopy terminal -has_meta_key km bool km YB-GE Has a meta key (i.e., sets 8th-bit) -has_status_line hs bool hs YB-G- has extra status line -insert_null_glitch in bool in YBCGE insert mode distinguishes nulls -memory_above da bool da YBCG- display may be retained above the screen -memory_below db bool db YB-GE display may be retained below the screen -move_insert_mode mir bool mi YBCGE safe to move while in insert mode -move_standout_mode msgr bool ms YBCGE safe to move while in standout mode -over_strike os bool os YBCG- terminal can overstrike -status_line_esc_ok eslok bool es YB-G- escape can be used on the status line -dest_tabs_magic_smso xt bool xt YBCGE tabs destructive, magic so char (t1061) -tilde_glitch hz bool hz YB-GE can't print ~'s (hazeltine) -transparent_underline ul bool ul YBCGE underline character overstrikes -xon_xoff xon bool xo YB--- terminal uses xon/xoff handshaking -needs_xon_xoff nxon bool nx ----- padding won't work, xon/xoff required -prtr_silent mc5i bool 5i ----- printer won't echo on screen -hard_cursor chts bool HC ----- cursor is hard to see -non_rev_rmcup nrrmc bool NR ----- smcup does not reverse rmcup -no_pad_char npc bool NP ----- pad character does not exist -non_dest_scroll_region ndscr bool ND ----- scrolling region is non-destructive -can_change ccc bool cc ----- terminal can re-define existing colors -back_color_erase bce bool ut ----- screen erased with background color -hue_lightness_saturation hls bool hl ----- terminal uses only HLS color notation (Tektronix) -col_addr_glitch xhpa bool YA ----- only positive motion for hpa/mhpa caps -cr_cancels_micro_mode crxm bool YB ----- using cr turns off micro mode -has_print_wheel daisy bool YC ----- printer needs operator to change character set -row_addr_glitch xvpa bool YD ----- only positive motion for vpa/mvpa caps -semi_auto_right_margin sam bool YE ----- printing in last column causes cr -cpi_changes_res cpix bool YF ----- changing character pitch changes resolution -lpi_changes_res lpix bool YG ----- changing line pitch changes resolution +auto_left_margin bw bool bw - - YB-G- cub1 wraps from column 0 to last column +auto_right_margin am bool am - - YBCGE terminal has automatic margins +no_esc_ctlc xsb bool xb - - YBCG- beehive (f1=escape, f2=ctrl C) +ceol_standout_glitch xhp bool xs - - YBCGE standout not erased by overwriting (hp) +eat_newline_glitch xenl bool xn - - YBCGE newline ignored after 80 cols (concept) +erase_overstrike eo bool eo - - YBCG- can erase overstrikes with a blank +generic_type gn bool gn - - YB-G- generic line type +hard_copy hc bool hc - - YBCG- hardcopy terminal +has_meta_key km bool km - - YB-GE Has a meta key (i.e., sets 8th-bit) +has_status_line hs bool hs - - YB-G- has extra status line +insert_null_glitch in bool in - - YBCGE insert mode distinguishes nulls +memory_above da bool da - - YBCG- display may be retained above the screen +memory_below db bool db - - YB-GE display may be retained below the screen +move_insert_mode mir bool mi - - YBCGE safe to move while in insert mode +move_standout_mode msgr bool ms - - YBCGE safe to move while in standout mode +over_strike os bool os - - YBCG- terminal can overstrike +status_line_esc_ok eslok bool es - - YB-G- escape can be used on the status line +dest_tabs_magic_smso xt bool xt - - YBCGE tabs destructive, magic so char (t1061) +tilde_glitch hz bool hz - - YB-GE cannot print ~'s (hazeltine) +transparent_underline ul bool ul - - YBCGE underline character overstrikes +xon_xoff xon bool xo - - YB--- terminal uses xon/xoff handshaking +needs_xon_xoff nxon bool nx - - ----- padding will not work, xon/xoff required +prtr_silent mc5i bool 5i - - ----- printer will not echo on screen +hard_cursor chts bool HC - - ----- cursor is hard to see +non_rev_rmcup nrrmc bool NR - - ----- smcup does not reverse rmcup +no_pad_char npc bool NP - - ----- pad character does not exist +non_dest_scroll_region ndscr bool ND - - ----- scrolling region is non-destructive +can_change ccc bool cc - - ----- terminal can re-define existing colors +back_color_erase bce bool ut - - ----- screen erased with background color +hue_lightness_saturation hls bool hl - - ----- terminal uses only HLS color notation (Tektronix) +col_addr_glitch xhpa bool YA - - ----- only positive motion for hpa/mhpa caps +cr_cancels_micro_mode crxm bool YB - - ----- using cr turns off micro mode +has_print_wheel daisy bool YC - - ----- printer needs operator to change character set +row_addr_glitch xvpa bool YD - - ----- only positive motion for vpa/mvpa caps +semi_auto_right_margin sam bool YE - - ----- printing in last column causes cr +cpi_changes_res cpix bool YF - - ----- changing character pitch changes resolution +lpi_changes_res lpix bool YG - - ----- changing line pitch changes resolution #%.TE #%.ad #% @@ -258,23 +261,23 @@ lpi_changes_res lpix bool YG ----- changing line pitch changes resolution #%lw25 lw6 lw2 lw20. #%\fBVariable Cap- TCap Description\fR #%\fBNumeric name Code\fR -columns cols num co YBCGE number of columns in a line -init_tabs it num it YB-G- tabs initially every # spaces -lines lines num li YBCGE number of lines on screen or page -lines_of_memory lm num lm YB-G- lines of memory if > line. 0 means varies -magic_cookie_glitch xmc num sg YBCGE number of blank characters left by smso or rmso -padding_baud_rate pb num pb YB-GE lowest baud rate where padding needed -virtual_terminal vt num vt YB--- virtual terminal number (CB/unix) -width_status_line wsl num ws YB-G- number of columns in status line -num_labels nlab num Nl ----- number of labels on screen -label_height lh num lh ----- rows in each label -label_width lw num lw ----- columns in each label -max_attributes ma num ma YBC-- maximum combined attributes terminal can handle -maximum_windows wnum num MW ----- maximum number of defineable windows +columns cols num co - - YBCGE number of columns in a line +init_tabs it num it - - YB-G- tabs initially every # spaces +lines lines num li - - YBCGE number of lines on screen or page +lines_of_memory lm num lm - - YB-G- lines of memory if > line. 0 means varies +magic_cookie_glitch xmc num sg - - YBCGE number of blank characters left by smso or rmso +padding_baud_rate pb num pb - - YB-GE lowest baud rate where padding needed +virtual_terminal vt num vt - - YB--- virtual terminal number (CB/unix) +width_status_line wsl num ws - - YB-G- number of columns in status line +num_labels nlab num Nl - - ----- number of labels on screen +label_height lh num lh - - ----- rows in each label +label_width lw num lw - - ----- columns in each label +max_attributes ma num ma - - YBC-- maximum combined attributes terminal can handle +maximum_windows wnum num MW - - ----- maximum number of defineable windows # These came in with SVr4's color support -max_colors colors num Co ----- maximum number of colors on screen -max_pairs pairs num pa ----- maximum number of color-pairs on the screen -no_color_video ncv num NC ----- video attributes that can't be used with colors +max_colors colors num Co - - ----- maximum number of colors on screen +max_pairs pairs num pa - - ----- maximum number of color-pairs on the screen +no_color_video ncv num NC - - ----- video attributes that cannot be used with colors #%.TE #%.ad #% @@ -290,23 +293,23 @@ no_color_video ncv num NC ----- video attributes that can't be used with color #%lw25 lw6 lw2 lw20. #%\fBVariable Cap- TCap Description\fR #%\fBNumeric name Code\fR -buffer_capacity bufsz num Ya ----- numbers of bytes buffered before printing -dot_vert_spacing spinv num Yb ----- spacing of pins vertically in pins per inch -dot_horz_spacing spinh num Yc ----- spacing of dots horizontally in dots per inch -max_micro_address maddr num Yd ----- maximum value in micro_..._address -max_micro_jump mjump num Ye ----- maximum value in parm_..._micro -micro_col_size mcs num Yf ----- character step size when in micro mode -micro_line_size mls num Yg ----- line step size when in micro mode -number_of_pins npins num Yh ----- numbers of pins in print-head -output_res_char orc num Yi ----- horizontal resolution in units per line -output_res_line orl num Yj ----- vertical resolution in units per line -output_res_horz_inch orhi num Yk ----- horizontal resolution in units per inch -output_res_vert_inch orvi num Yl ----- vertical resolution in units per inch -print_rate cps num Ym ----- print rate in characters per second -wide_char_size widcs num Yn ----- character step size when in double wide mode -buttons btns num BT ----- number of buttons on mouse -bit_image_entwining bitwin num Yo ----- number of passes for each bit-image row -bit_image_type bitype num Yp ----- type of bit-image device +buffer_capacity bufsz num Ya - - ----- numbers of bytes buffered before printing +dot_vert_spacing spinv num Yb - - ----- spacing of pins vertically in pins per inch +dot_horz_spacing spinh num Yc - - ----- spacing of dots horizontally in dots per inch +max_micro_address maddr num Yd - - ----- maximum value in micro_..._address +max_micro_jump mjump num Ye - - ----- maximum value in parm_..._micro +micro_col_size mcs num Yf - - ----- character step size when in micro mode +micro_line_size mls num Yg - - ----- line step size when in micro mode +number_of_pins npins num Yh - - ----- numbers of pins in print-head +output_res_char orc num Yi - - ----- horizontal resolution in units per line +output_res_line orl num Yj - - ----- vertical resolution in units per line +output_res_horz_inch orhi num Yk - - ----- horizontal resolution in units per inch +output_res_vert_inch orvi num Yl - - ----- vertical resolution in units per inch +print_rate cps num Ym - - ----- print rate in characters per second +wide_char_size widcs num Yn - - ----- character step size when in double wide mode +buttons btns num BT - - ----- number of buttons on mouse +bit_image_entwining bitwin num Yo - - ----- number of passes for each bit-image row +bit_image_type bitype num Yp - - ----- type of bit-image device #%.TE #%.ad #% @@ -320,370 +323,370 @@ bit_image_type bitype num Yp ----- type of bit-image device #%lw25 lw6 lw2 lw20. #%\fBVariable Cap- TCap Description\fR #%\fBString name Code\fR -back_tab cbt str bt YBCGE back tab (P) -bell bel str bl YB-GE audible signal (bell) (P) -carriage_return cr str cr YBCGE carriage return (P*) (P*) -change_scroll_region csr str cs YBCGE change region to line #1 to line #2 (P) -clear_all_tabs tbc str ct YB-G- clear all tab stops (P) -clear_screen clear str cl YBCGE clear screen and home cursor (P*) -clr_eol el str ce YBCGE clear to end of line (P) -clr_eos ed str cd YBCGE clear to end of screen (P*) -column_address hpa str ch -B-GE** horizontal position #1, absolute (P) -command_character cmdch str CC YB-G- terminal settable cmd character in prototype !? -cursor_address cup str cm YBCGE move to row #1 columns #2 -cursor_down cud1 str do YBCGE down one line -cursor_home home str ho YBCGE home cursor (if no cup) -cursor_invisible civis str vi YB-G- make cursor invisible -cursor_left cub1 str le YBCGE move left one space -cursor_mem_address mrcup str CM YB-G- memory relative cursor addressing, move to row #1 columns #2 -cursor_normal cnorm str ve YBCGE make cursor appear normal (undo civis/cvvis) -cursor_right cuf1 str nd YBCGE non-destructive space (move right one space) -cursor_to_ll ll str ll YBCGE last line, first column (if no cup) -cursor_up cuu1 str up YBCGE up one line -cursor_visible cvvis str vs YBCGE make cursor very visible -delete_character dch1 str dc YBCGE delete character (P*) -delete_line dl1 str dl YBCGE delete line (P*) -dis_status_line dsl str ds YB-G- disable status line -down_half_line hd str hd YB-G- half a line down -enter_alt_charset_mode smacs str as YB-G- start alternate character set (P) -enter_blink_mode blink str mb YB-G- turn on blinking -enter_bold_mode bold str md YB-G- turn on bold (extra bright) mode -enter_ca_mode smcup str ti YBCGE string to start programs using cup -enter_delete_mode smdc str dm YBCGE enter delete mode -enter_dim_mode dim str mh YB-G- turn on half-bright mode -enter_insert_mode smir str im YBCGE enter insert mode -enter_secure_mode invis str mk -B-G-* turn on blank mode (characters invisible) -enter_protected_mode prot str mp -B-G-* turn on protected mode -enter_reverse_mode rev str mr YB-G- turn on reverse video mode -enter_standout_mode smso str so YBCGE begin standout mode -enter_underline_mode smul str us YBCGE begin underline mode -erase_chars ech str ec YB-G- erase #1 characters (P) -exit_alt_charset_mode rmacs str ae YB-G- end alternate character set (P) -exit_attribute_mode sgr0 str me YB-GE turn off all attributes -exit_ca_mode rmcup str te YBCGE strings to end programs using cup -exit_delete_mode rmdc str ed YBCGE end delete mode -exit_insert_mode rmir str ei YBCGE exit insert mode -exit_standout_mode rmso str se YBCGE exit standout mode -exit_underline_mode rmul str ue YBCGE exit underline mode -flash_screen flash str vb YBCGE visible bell (may not move cursor) -form_feed ff str ff YB-G- hardcopy terminal page eject (P*) -from_status_line fsl str fs YB-G- return from status line -init_1string is1 str i1 YB-G- initialization string -init_2string is2 str is YB-G- initialization string -init_3string is3 str i3 YB-G- initialization string -init_file if str if YB-G- name of initialization file -insert_character ich1 str ic YBCGE insert character (P) -insert_line il1 str al YBCGE insert line (P*) -insert_padding ip str ip YBCGE insert padding after inserted character -key_backspace kbs str kb YB-G- backspace key -key_catab ktbc str ka -B-G-* clear-all-tabs key -key_clear kclr str kC -B-G-* clear-screen or erase key -key_ctab kctab str kt -B-G-* clear-tab key -key_dc kdch1 str kD YB-G- delete-character key -key_dl kdl1 str kL -B-G-* delete-line key -key_down kcud1 str kd YBCGE down-arrow key -key_eic krmir str kM -B-G-* sent by rmir or smir in insert mode -key_eol kel str kE -B-G-* clear-to-end-of-line key -key_eos ked str kS -B-G-* clear-to-end-of-screen key -key_f0 kf0 str k0 YBCGE F0 function key -key_f1 kf1 str k1 YBCGE F1 function key -key_f10 kf10 str k; ----E F10 function key -key_f2 kf2 str k2 YBCGE F2 function key -key_f3 kf3 str k3 YBCGE F3 function key -key_f4 kf4 str k4 YBCGE F4 function key -key_f5 kf5 str k5 YBCGE F5 function key -key_f6 kf6 str k6 YBCGE F6 function key -key_f7 kf7 str k7 YBCGE F7 function key -key_f8 kf8 str k8 YBCGE F8 function key -key_f9 kf9 str k9 YBCGE F9 function key -key_home khome str kh YBCGE home key -key_ic kich1 str kI YB-GE insert-character key -key_il kil1 str kA -B-G-* insert-line key -key_left kcub1 str kl YBCGE left-arrow key -key_ll kll str kH YB-G- lower-left key (home down) -key_npage knp str kN YB-GE next-page key -key_ppage kpp str kP YB-GE previous-page key -key_right kcuf1 str kr YBCGE right-arrow key -key_sf kind str kF -B-G-* scroll-forward key -key_sr kri str kR -B-G-* scroll-backward key -key_stab khts str kT -B-G-* set-tab key -key_up kcuu1 str ku YBCGE up-arrow key -keypad_local rmkx str ke YBCGE leave 'keyboard_transmit' mode -keypad_xmit smkx str ks YBCGE enter 'keyboard_transmit' mode -lab_f0 lf0 str l0 -B-G-* label on function key f0 if not f0 -lab_f1 lf1 str l1 -B-G-* label on function key f1 if not f1 -lab_f10 lf10 str la ----- label on function key f10 if not f10 -lab_f2 lf2 str l2 -B-G-* label on function key f2 if not f2 -lab_f3 lf3 str l3 -B-G-* label on function key f3 if not f3 -lab_f4 lf4 str l4 -B-G-* label on function key f4 if not f4 -lab_f5 lf5 str l5 -B-G-* label on function key f5 if not f5 -lab_f6 lf6 str l6 -B-G-* label on function key f6 if not f6 -lab_f7 lf7 str l7 -B-G-* label on function key f7 if not f7 -lab_f8 lf8 str l8 -B-G-* label on function key f8 if not f8 -lab_f9 lf9 str l9 -B-G-* label on function key f9 if not f9 -meta_off rmm str mo YB-G-* turn off meta mode -meta_on smm str mm YB-G-* turn on meta mode (8th-bit on) -newline nel str nw YB-G-* newline (behave like cr followed by lf) -pad_char pad str pc YBCGE padding char (instead of null) -parm_dch dch str DC YB-GE delete #1 characters (P*) -parm_delete_line dl str DL YBCGE delete #1 lines (P*) -parm_down_cursor cud str DO YBCGE down #1 lines (P*) -parm_ich ich str IC YB-GE insert #1 characters (P*) -parm_index indn str SF YBCG- scroll forward #1 lines (P) -parm_insert_line il str AL YBCGE insert #1 lines (P*) -parm_left_cursor cub str LE YBCGE move #1 characters to the left (P) -parm_right_cursor cuf str RI YBCGE move #1 characters to the right (P*) -parm_rindex rin str SR YBCG- scroll back #1 lines (P) -parm_up_cursor cuu str UP YBCGE up #1 lines (P*) -pkey_key pfkey str pk -B--- program function key #1 to type string #2 -pkey_local pfloc str pl -B--- program function key #1 to execute string #2 -pkey_xmit pfx str px -B--- program function key #1 to transmit string #2 -print_screen mc0 str ps -B-G-* print contents of screen -prtr_off mc4 str pf -B-G-* turn off printer -prtr_on mc5 str po -B-G-* turn on printer -repeat_char rep str rp YB-GE repeat char #1 #2 times (P*) -reset_1string rs1 str r1 -B--- reset string -reset_2string rs2 str r2 -B--- reset string -reset_3string rs3 str r3 -B--- reset string -reset_file rf str rf -B--- name of reset file -restore_cursor rc str rc YBCG- restore cursor to position of last save_cursor -row_address vpa str cv -B-GE** vertical position #1 absolute (P) -save_cursor sc str sc YBCG- save current cursor position (P) -scroll_forward ind str sf YBCGE scroll text up (P) -scroll_reverse ri str sr YBCGE scroll text down (P) -set_attributes sgr str sa YB-G- define video attributes #1-#9 (PG9) -set_tab hts str st YB-G- set a tab in every row, current columns -set_window wind str wi -B-GE current window is lines #1-#2 cols #3-#4 -tab ht str ta YBCGE tab to next 8-space hardware tab stop -to_status_line tsl str ts YB-G- move to status line, column #1 -underline_char uc str uc YBCG- underline char and move past it -up_half_line hu str hu YB-G- half a line up -init_prog iprog str iP -B--- path name of program for initialization -key_a1 ka1 str K1 YB-GE upper left of keypad -key_a3 ka3 str K3 YB-GE upper right of keypad -key_b2 kb2 str K2 YB-GE center of keypad -key_c1 kc1 str K4 YB-GE lower left of keypad -key_c3 kc3 str K5 YB-GE lower right of keypad -prtr_non mc5p str pO -B-G-* turn on printer for #1 bytes +back_tab cbt str bt - - YBCGE back tab (P) +bell bel str bl - - YB-GE audible signal (bell) (P) +carriage_return cr str cr - - YBCGE carriage return (P*) (P*) +change_scroll_region csr str cs - - YBCGE change region to line #1 to line #2 (P) +clear_all_tabs tbc str ct - - YB-G- clear all tab stops (P) +clear_screen clear str cl - - YBCGE clear screen and home cursor (P*) +clr_eol el str ce - - YBCGE clear to end of line (P) +clr_eos ed str cd - - YBCGE clear to end of screen (P*) +column_address hpa str ch - - -B-GE* horizontal position #1, absolute (P) +command_character cmdch str CC - - YB-G- terminal settable cmd character in prototype !? +cursor_address cup str cm - - YBCGE move to row #1 columns #2 +cursor_down cud1 str do - - YBCGE down one line +cursor_home home str ho - - YBCGE home cursor (if no cup) +cursor_invisible civis str vi - - YB-G- make cursor invisible +cursor_left cub1 str le - - YBCGE move left one space +cursor_mem_address mrcup str CM - - YB-G- memory relative cursor addressing, move to row #1 columns #2 +cursor_normal cnorm str ve - - YBCGE make cursor appear normal (undo civis/cvvis) +cursor_right cuf1 str nd - - YBCGE non-destructive space (move right one space) +cursor_to_ll ll str ll - - YBCGE last line, first column (if no cup) +cursor_up cuu1 str up - - YBCGE up one line +cursor_visible cvvis str vs - - YBCGE make cursor very visible +delete_character dch1 str dc - - YBCGE delete character (P*) +delete_line dl1 str dl - - YBCGE delete line (P*) +dis_status_line dsl str ds - - YB-G- disable status line +down_half_line hd str hd - - YB-G- half a line down +enter_alt_charset_mode smacs str as - - YB-G- start alternate character set (P) +enter_blink_mode blink str mb - - YB-G- turn on blinking +enter_bold_mode bold str md - - YB-G- turn on bold (extra bright) mode +enter_ca_mode smcup str ti - - YBCGE string to start programs using cup +enter_delete_mode smdc str dm - - YBCGE enter delete mode +enter_dim_mode dim str mh - - YB-G- turn on half-bright mode +enter_insert_mode smir str im - - YBCGE enter insert mode +enter_secure_mode invis str mk - - -B-G-* turn on blank mode (characters invisible) +enter_protected_mode prot str mp - - -B-G-* turn on protected mode +enter_reverse_mode rev str mr - - YB-G- turn on reverse video mode +enter_standout_mode smso str so - - YBCGE begin standout mode +enter_underline_mode smul str us - - YBCGE begin underline mode +erase_chars ech str ec - - YB-G- erase #1 characters (P) +exit_alt_charset_mode rmacs str ae - - YB-G- end alternate character set (P) +exit_attribute_mode sgr0 str me - - YB-GE turn off all attributes +exit_ca_mode rmcup str te - - YBCGE strings to end programs using cup +exit_delete_mode rmdc str ed - - YBCGE end delete mode +exit_insert_mode rmir str ei - - YBCGE exit insert mode +exit_standout_mode rmso str se - - YBCGE exit standout mode +exit_underline_mode rmul str ue - - YBCGE exit underline mode +flash_screen flash str vb - - YBCGE visible bell (may not move cursor) +form_feed ff str ff - - YB-G- hardcopy terminal page eject (P*) +from_status_line fsl str fs - - YB-G- return from status line +init_1string is1 str i1 - - YB-G- initialization string +init_2string is2 str is - - YB-G- initialization string +init_3string is3 str i3 - - YB-G- initialization string +init_file if str if - - YB-G- name of initialization file +insert_character ich1 str ic - - YBCGE insert character (P) +insert_line il1 str al - - YBCGE insert line (P*) +insert_padding ip str ip - - YBCGE insert padding after inserted character +key_backspace kbs str kb KEY_BACKSPACE 0407 YB-G- backspace key +key_catab ktbc str ka KEY_CATAB 0526 -B-G-* clear-all-tabs key +key_clear kclr str kC KEY_CLEAR 0515 -B-G-* clear-screen or erase key +key_ctab kctab str kt KEY_CTAB 0525 -B-G-* clear-tab key +key_dc kdch1 str kD KEY_DC 0512 YB-G- delete-character key +key_dl kdl1 str kL KEY_DL 0510 -B-G-* delete-line key +key_down kcud1 str kd KEY_DOWN 0402 YBCGE down-arrow key +key_eic krmir str kM KEY_EIC 0514 -B-G-* sent by rmir or smir in insert mode +key_eol kel str kE KEY_EOL 0517 -B-G-* clear-to-end-of-line key +key_eos ked str kS KEY_EOS 0516 -B-G-* clear-to-end-of-screen key +key_f0 kf0 str k0 KEY_F(0) 0410 YBCGE F0 function key +key_f1 kf1 str k1 KEY_F(1) - YBCGE F1 function key +key_f10 kf10 str k; KEY_F(10) - ----E F10 function key +key_f2 kf2 str k2 KEY_F(2) - YBCGE F2 function key +key_f3 kf3 str k3 KEY_F(3) - YBCGE F3 function key +key_f4 kf4 str k4 KEY_F(4) - YBCGE F4 function key +key_f5 kf5 str k5 KEY_F(5) - YBCGE F5 function key +key_f6 kf6 str k6 KEY_F(6) - YBCGE F6 function key +key_f7 kf7 str k7 KEY_F(7) - YBCGE F7 function key +key_f8 kf8 str k8 KEY_F(8) - YBCGE F8 function key +key_f9 kf9 str k9 KEY_F(9) - YBCGE F9 function key +key_home khome str kh KEY_HOME 0406 YBCGE home key +key_ic kich1 str kI KEY_IC 0513 YB-GE insert-character key +key_il kil1 str kA KEY_IL 0511 -B-G-* insert-line key +key_left kcub1 str kl KEY_LEFT 0404 YBCGE left-arrow key +key_ll kll str kH KEY_LL 0533 YB-G- lower-left key (home down) +key_npage knp str kN KEY_NPAGE 0522 YB-GE next-page key +key_ppage kpp str kP KEY_PPAGE 0523 YB-GE previous-page key +key_right kcuf1 str kr KEY_RIGHT 0405 YBCGE right-arrow key +key_sf kind str kF KEY_SF 0520 -B-G-* scroll-forward key +key_sr kri str kR KEY_SR 0521 -B-G-* scroll-backward key +key_stab khts str kT KEY_STAB 0524 -B-G-* set-tab key +key_up kcuu1 str ku KEY_UP 0403 YBCGE up-arrow key +keypad_local rmkx str ke - - YBCGE leave 'keyboard_transmit' mode +keypad_xmit smkx str ks - - YBCGE enter 'keyboard_transmit' mode +lab_f0 lf0 str l0 - - -B-G-* label on function key f0 if not f0 +lab_f1 lf1 str l1 - - -B-G-* label on function key f1 if not f1 +lab_f10 lf10 str la - - ----- label on function key f10 if not f10 +lab_f2 lf2 str l2 - - -B-G-* label on function key f2 if not f2 +lab_f3 lf3 str l3 - - -B-G-* label on function key f3 if not f3 +lab_f4 lf4 str l4 - - -B-G-* label on function key f4 if not f4 +lab_f5 lf5 str l5 - - -B-G-* label on function key f5 if not f5 +lab_f6 lf6 str l6 - - -B-G-* label on function key f6 if not f6 +lab_f7 lf7 str l7 - - -B-G-* label on function key f7 if not f7 +lab_f8 lf8 str l8 - - -B-G-* label on function key f8 if not f8 +lab_f9 lf9 str l9 - - -B-G-* label on function key f9 if not f9 +meta_off rmm str mo - - YB-G-* turn off meta mode +meta_on smm str mm - - YB-G-* turn on meta mode (8th-bit on) +newline nel str nw - - YB-G-* newline (behave like cr followed by lf) +pad_char pad str pc - - YBCGE padding char (instead of null) +parm_dch dch str DC - - YB-GE delete #1 characters (P*) +parm_delete_line dl str DL - - YBCGE delete #1 lines (P*) +parm_down_cursor cud str DO - - YBCGE down #1 lines (P*) +parm_ich ich str IC - - YB-GE insert #1 characters (P*) +parm_index indn str SF - - YBCG- scroll forward #1 lines (P) +parm_insert_line il str AL - - YBCGE insert #1 lines (P*) +parm_left_cursor cub str LE - - YBCGE move #1 characters to the left (P) +parm_right_cursor cuf str RI - - YBCGE move #1 characters to the right (P*) +parm_rindex rin str SR - - YBCG- scroll back #1 lines (P) +parm_up_cursor cuu str UP - - YBCGE up #1 lines (P*) +pkey_key pfkey str pk - - -B--- program function key #1 to type string #2 +pkey_local pfloc str pl - - -B--- program function key #1 to execute string #2 +pkey_xmit pfx str px - - -B--- program function key #1 to transmit string #2 +print_screen mc0 str ps - - -B-G-* print contents of screen +prtr_off mc4 str pf - - -B-G-* turn off printer +prtr_on mc5 str po - - -B-G-* turn on printer +repeat_char rep str rp - - YB-GE repeat char #1 #2 times (P*) +reset_1string rs1 str r1 - - -B--- reset string +reset_2string rs2 str r2 - - -B--- reset string +reset_3string rs3 str r3 - - -B--- reset string +reset_file rf str rf - - -B--- name of reset file +restore_cursor rc str rc - - YBCG- restore cursor to position of last save_cursor +row_address vpa str cv - - -B-GE* vertical position #1 absolute (P) +save_cursor sc str sc - - YBCG- save current cursor position (P) +scroll_forward ind str sf - - YBCGE scroll text up (P) +scroll_reverse ri str sr - - YBCGE scroll text down (P) +set_attributes sgr str sa - - YB-G- define video attributes #1-#9 (PG9) +set_tab hts str st - - YB-G- set a tab in every row, current columns +set_window wind str wi - - -B-GE current window is lines #1-#2 cols #3-#4 +tab ht str ta - - YBCGE tab to next 8-space hardware tab stop +to_status_line tsl str ts - - YB-G- move to status line, column #1 +underline_char uc str uc - - YBCG- underline char and move past it +up_half_line hu str hu - - YB-G- half a line up +init_prog iprog str iP - - -B--- path name of program for initialization +key_a1 ka1 str K1 KEY_A1 0534 YB-GE upper left of keypad +key_a3 ka3 str K3 KEY_A3 0535 YB-GE upper right of keypad +key_b2 kb2 str K2 KEY_B2 0536 YB-GE center of keypad +key_c1 kc1 str K4 KEY_C1 0537 YB-GE lower left of keypad +key_c3 kc3 str K5 KEY_C3 0540 YB-GE lower right of keypad +prtr_non mc5p str pO - - -B-G-* turn on printer for #1 bytes # # SVr1 capabilities stop here. IBM's version of terminfo is the same as # SVr4 up to this point, but has a different set afterwards. # -char_padding rmp str rP ----- like ip but when in insert mode -acs_chars acsc str ac ----- graphics charset pairs, based on vt100 -plab_norm pln str pn ----- program label #1 to show string #2 -key_btab kcbt str kB ----- back-tab key -enter_xon_mode smxon str SX ----- turn on xon/xoff handshaking -exit_xon_mode rmxon str RX ----- turn off xon/xoff handshaking -enter_am_mode smam str SA ----- turn on automatic margins -exit_am_mode rmam str RA ----- turn off automatic margins -xon_character xonc str XN ----- XON character -xoff_character xoffc str XF ----- XOFF character -ena_acs enacs str eA ----- enable alternate char set -label_on smln str LO ----- turn on soft labels -label_off rmln str LF ----- turn off soft labels -key_beg kbeg str @1 ----- begin key -key_cancel kcan str @2 ----- cancel key -key_close kclo str @3 ----- close key -key_command kcmd str @4 ----- command key -key_copy kcpy str @5 ----- copy key -key_create kcrt str @6 ----- create key -key_end kend str @7 ----- end key -key_enter kent str @8 ----- enter/send key -key_exit kext str @9 ----- exit key -key_find kfnd str @0 ----- find key -key_help khlp str %1 ----- help key -key_mark kmrk str %2 ----- mark key -key_message kmsg str %3 ----- message key -key_move kmov str %4 ----- move key -key_next knxt str %5 ----- next key -key_open kopn str %6 ----- open key -key_options kopt str %7 ----- options key -key_previous kprv str %8 ----- previous key -key_print kprt str %9 ----- print key -key_redo krdo str %0 ----- redo key -key_reference kref str &1 ----- reference key -key_refresh krfr str &2 ----- refresh key -key_replace krpl str &3 ----- replace key -key_restart krst str &4 ----- restart key -key_resume kres str &5 ----- resume key -key_save ksav str &6 ----- save key -key_suspend kspd str &7 ----- suspend key -key_undo kund str &8 ----- undo key -key_sbeg kBEG str &9 ----- shifted begin key -key_scancel kCAN str &0 ----- shifted cancel key -key_scommand kCMD str *1 ----- shifted command key -key_scopy kCPY str *2 ----- shifted copy key -key_screate kCRT str *3 ----- shifted create key -key_sdc kDC str *4 ----- shifted delete-character key -key_sdl kDL str *5 ----- shifted delete-line key -key_select kslt str *6 ----- select key -key_send kEND str *7 ----- shifted end key -key_seol kEOL str *8 ----- shifted clear-to-end-of-line key -key_sexit kEXT str *9 ----- shifted exit key -key_sfind kFND str *0 ----- shifted find key -key_shelp kHLP str #1 ----- shifted help key -key_shome kHOM str #2 ----- shifted home key -key_sic kIC str #3 ----- shifted insert-character key -key_sleft kLFT str #4 ----- shifted left-arrow key -key_smessage kMSG str %a ----- shifted message key -key_smove kMOV str %b ----- shifted move key -key_snext kNXT str %c ----- shifted next key -key_soptions kOPT str %d ----- shifted options key -key_sprevious kPRV str %e ----- shifted previous key -key_sprint kPRT str %f ----- shifted print key -key_sredo kRDO str %g ----- shifted redo key -key_sreplace kRPL str %h ----- shifted replace key -key_sright kRIT str %i ----- shifted right-arrow key -key_srsume kRES str %j ----- shifted resume key -key_ssave kSAV str !1 ----- shifted save key -key_ssuspend kSPD str !2 ----- shifted suspend key -key_sundo kUND str !3 ----- shifted undo key -req_for_input rfi str RF ----- send next input char (for ptys) -key_f11 kf11 str F1 ----E F11 function key -key_f12 kf12 str F2 ----E F12 function key -key_f13 kf13 str F3 ----E F13 function key -key_f14 kf14 str F4 ----E F14 function key -key_f15 kf15 str F5 ----E F15 function key -key_f16 kf16 str F6 ----E F16 function key -key_f17 kf17 str F7 ----E F17 function key -key_f18 kf18 str F8 ----E F18 function key -key_f19 kf19 str F9 ----E F19 function key -key_f20 kf20 str FA ----E F20 function key -key_f21 kf21 str FB ----E F21 function key -key_f22 kf22 str FC ----E F22 function key -key_f23 kf23 str FD ----E F23 function key -key_f24 kf24 str FE ----E F24 function key -key_f25 kf25 str FF ----E F25 function key -key_f26 kf26 str FG ----E F26 function key -key_f27 kf27 str FH ----E F27 function key -key_f28 kf28 str FI ----E F28 function key -key_f29 kf29 str FJ ----E F29 function key -key_f30 kf30 str FK ----E F30 function key -key_f31 kf31 str FL ----E F31 function key -key_f32 kf32 str FM ----E F32 function key -key_f33 kf33 str FN ----E F33 function key -key_f34 kf34 str FO ----E F34 function key -key_f35 kf35 str FP ----E F35 function key -key_f36 kf36 str FQ ----E F36 function key -key_f37 kf37 str FR ----E F37 function key -key_f38 kf38 str FS ----E F38 function key -key_f39 kf39 str FT ----E F39 function key -key_f40 kf40 str FU ----E F40 function key -key_f41 kf41 str FV ----E F41 function key -key_f42 kf42 str FW ----E F42 function key -key_f43 kf43 str FX ----E F43 function key -key_f44 kf44 str FY ----E F44 function key -key_f45 kf45 str FZ ----E F45 function key -key_f46 kf46 str Fa ----E F46 function key -key_f47 kf47 str Fb ----E F47 function key -key_f48 kf48 str Fc ----E F48 function key -key_f49 kf49 str Fd ----E F49 function key -key_f50 kf50 str Fe ----E F50 function key -key_f51 kf51 str Ff ----E F51 function key -key_f52 kf52 str Fg ----E F52 function key -key_f53 kf53 str Fh ----E F53 function key -key_f54 kf54 str Fi ----E F54 function key -key_f55 kf55 str Fj ----E F55 function key -key_f56 kf56 str Fk ----E F56 function key -key_f57 kf57 str Fl ----E F57 function key -key_f58 kf58 str Fm ----E F58 function key -key_f59 kf59 str Fn ----E F59 function key -key_f60 kf60 str Fo ----E F60 function key -key_f61 kf61 str Fp ----E F61 function key -key_f62 kf62 str Fq ----E F62 function key -key_f63 kf63 str Fr ----E F63 function key -clr_bol el1 str cb ----- Clear to beginning of line -clear_margins mgc str MC ----- clear right and left soft margins -set_left_margin smgl str ML ----- set left soft margin at current column. See smgl. (ML is not in BSD termcap). -set_right_margin smgr str MR ----- set right soft margin at current column -label_format fln str Lf ----- label format -set_clock sclk str SC ----- set clock, #1 hrs #2 mins #3 secs -display_clock dclk str DK ----- display clock -remove_clock rmclk str RC ----- remove clock -create_window cwin str CW ----- define a window #1 from #2,#3 to #4,#5 -goto_window wingo str WG ----- go to window #1 -hangup hup str HU ----- hang-up phone -dial_phone dial str DI ----- dial number #1 -quick_dial qdial str QD ----- dial number #1 without checking -tone tone str TO ----- select touch tone dialing -pulse pulse str PU ----- select pulse dialing -flash_hook hook str fh ----- flash switch hook -fixed_pause pause str PA ----- pause for 2-3 seconds -wait_tone wait str WA ----- wait for dial-tone -user0 u0 str u0 ----- User string #0 -user1 u1 str u1 ----- User string #1 -user2 u2 str u2 ----- User string #2 -user3 u3 str u3 ----- User string #3 -user4 u4 str u4 ----- User string #4 -user5 u5 str u5 ----- User string #5 -user6 u6 str u6 ----- User string #6 -user7 u7 str u7 ----- User string #7 -user8 u8 str u8 ----- User string #8 -user9 u9 str u9 ----- User string #9 +char_padding rmp str rP - - ----- like ip but when in insert mode +acs_chars acsc str ac - - ----- graphics charset pairs, based on vt100 +plab_norm pln str pn - - ----- program label #1 to show string #2 +key_btab kcbt str kB KEY_BTAB 0541 ----- back-tab key +enter_xon_mode smxon str SX - - ----- turn on xon/xoff handshaking +exit_xon_mode rmxon str RX - - ----- turn off xon/xoff handshaking +enter_am_mode smam str SA - - ----- turn on automatic margins +exit_am_mode rmam str RA - - ----- turn off automatic margins +xon_character xonc str XN - - ----- XON character +xoff_character xoffc str XF - - ----- XOFF character +ena_acs enacs str eA - - ----- enable alternate char set +label_on smln str LO - - ----- turn on soft labels +label_off rmln str LF - - ----- turn off soft labels +key_beg kbeg str @1 KEY_BEG 0542 ----- begin key +key_cancel kcan str @2 KEY_CANCEL 0543 ----- cancel key +key_close kclo str @3 KEY_CLOSE 0544 ----- close key +key_command kcmd str @4 KEY_COMMAND 0545 ----- command key +key_copy kcpy str @5 KEY_COPY 0546 ----- copy key +key_create kcrt str @6 KEY_CREATE 0547 ----- create key +key_end kend str @7 KEY_END 0550 ----- end key +key_enter kent str @8 KEY_ENTER 0527 ----- enter/send key +key_exit kext str @9 KEY_EXIT 0551 ----- exit key +key_find kfnd str @0 KEY_FIND 0552 ----- find key +key_help khlp str %1 KEY_HELP 0553 ----- help key +key_mark kmrk str %2 KEY_MARK 0554 ----- mark key +key_message kmsg str %3 KEY_MESSAGE 0555 ----- message key +key_move kmov str %4 KEY_MOVE 0556 ----- move key +key_next knxt str %5 KEY_NEXT 0557 ----- next key +key_open kopn str %6 KEY_OPEN 0560 ----- open key +key_options kopt str %7 KEY_OPTIONS 0561 ----- options key +key_previous kprv str %8 KEY_PREVIOUS 0562 ----- previous key +key_print kprt str %9 KEY_PRINT 0532 ----- print key +key_redo krdo str %0 KEY_REDO 0563 ----- redo key +key_reference kref str &1 KEY_REFERENCE 0564 ----- reference key +key_refresh krfr str &2 KEY_REFRESH 0565 ----- refresh key +key_replace krpl str &3 KEY_REPLACE 0566 ----- replace key +key_restart krst str &4 KEY_RESTART 0567 ----- restart key +key_resume kres str &5 KEY_RESUME 0570 ----- resume key +key_save ksav str &6 KEY_SAVE 0571 ----- save key +key_suspend kspd str &7 KEY_SUSPEND 0627 ----- suspend key +key_undo kund str &8 KEY_UNDO 0630 ----- undo key +key_sbeg kBEG str &9 KEY_SBEG 0572 ----- shifted begin key +key_scancel kCAN str &0 KEY_SCANCEL 0573 ----- shifted cancel key +key_scommand kCMD str *1 KEY_SCOMMAND 0574 ----- shifted command key +key_scopy kCPY str *2 KEY_SCOPY 0575 ----- shifted copy key +key_screate kCRT str *3 KEY_SCREATE 0576 ----- shifted create key +key_sdc kDC str *4 KEY_SDC 0577 ----- shifted delete-character key +key_sdl kDL str *5 KEY_SDL 0600 ----- shifted delete-line key +key_select kslt str *6 KEY_SELECT 0601 ----- select key +key_send kEND str *7 KEY_SEND 0602 ----- shifted end key +key_seol kEOL str *8 KEY_SEOL 0603 ----- shifted clear-to-end-of-line key +key_sexit kEXT str *9 KEY_SEXIT 0604 ----- shifted exit key +key_sfind kFND str *0 KEY_SFIND 0605 ----- shifted find key +key_shelp kHLP str #1 KEY_SHELP 0606 ----- shifted help key +key_shome kHOM str #2 KEY_SHOME 0607 ----- shifted home key +key_sic kIC str #3 KEY_SIC 0610 ----- shifted insert-character key +key_sleft kLFT str #4 KEY_SLEFT 0611 ----- shifted left-arrow key +key_smessage kMSG str %a KEY_SMESSAGE 0612 ----- shifted message key +key_smove kMOV str %b KEY_SMOVE 0613 ----- shifted move key +key_snext kNXT str %c KEY_SNEXT 0614 ----- shifted next key +key_soptions kOPT str %d KEY_SOPTIONS 0615 ----- shifted options key +key_sprevious kPRV str %e KEY_SPREVIOUS 0616 ----- shifted previous key +key_sprint kPRT str %f KEY_SPRINT 0617 ----- shifted print key +key_sredo kRDO str %g KEY_SREDO 0620 ----- shifted redo key +key_sreplace kRPL str %h KEY_SREPLACE 0621 ----- shifted replace key +key_sright kRIT str %i KEY_SRIGHT 0622 ----- shifted right-arrow key +key_srsume kRES str %j KEY_SRSUME 0623 ----- shifted resume key +key_ssave kSAV str !1 KEY_SSAVE 0624 ----- shifted save key +key_ssuspend kSPD str !2 KEY_SSUSPEND 0625 ----- shifted suspend key +key_sundo kUND str !3 KEY_SUNDO 0626 ----- shifted undo key +req_for_input rfi str RF - - ----- send next input char (for ptys) +key_f11 kf11 str F1 KEY_F(11) - ----E F11 function key +key_f12 kf12 str F2 KEY_F(12) - ----E F12 function key +key_f13 kf13 str F3 KEY_F(13) - ----E F13 function key +key_f14 kf14 str F4 KEY_F(14) - ----E F14 function key +key_f15 kf15 str F5 KEY_F(15) - ----E F15 function key +key_f16 kf16 str F6 KEY_F(16) - ----E F16 function key +key_f17 kf17 str F7 KEY_F(17) - ----E F17 function key +key_f18 kf18 str F8 KEY_F(18) - ----E F18 function key +key_f19 kf19 str F9 KEY_F(19) - ----E F19 function key +key_f20 kf20 str FA KEY_F(20) - ----E F20 function key +key_f21 kf21 str FB KEY_F(21) - ----E F21 function key +key_f22 kf22 str FC KEY_F(22) - ----E F22 function key +key_f23 kf23 str FD KEY_F(23) - ----E F23 function key +key_f24 kf24 str FE KEY_F(24) - ----E F24 function key +key_f25 kf25 str FF KEY_F(25) - ----E F25 function key +key_f26 kf26 str FG KEY_F(26) - ----E F26 function key +key_f27 kf27 str FH KEY_F(27) - ----E F27 function key +key_f28 kf28 str FI KEY_F(28) - ----E F28 function key +key_f29 kf29 str FJ KEY_F(29) - ----E F29 function key +key_f30 kf30 str FK KEY_F(30) - ----E F30 function key +key_f31 kf31 str FL KEY_F(31) - ----E F31 function key +key_f32 kf32 str FM KEY_F(32) - ----E F32 function key +key_f33 kf33 str FN KEY_F(33) - ----E F33 function key +key_f34 kf34 str FO KEY_F(34) - ----E F34 function key +key_f35 kf35 str FP KEY_F(35) - ----E F35 function key +key_f36 kf36 str FQ KEY_F(36) - ----E F36 function key +key_f37 kf37 str FR KEY_F(37) - ----E F37 function key +key_f38 kf38 str FS KEY_F(38) - ----E F38 function key +key_f39 kf39 str FT KEY_F(39) - ----E F39 function key +key_f40 kf40 str FU KEY_F(40) - ----E F40 function key +key_f41 kf41 str FV KEY_F(41) - ----E F41 function key +key_f42 kf42 str FW KEY_F(42) - ----E F42 function key +key_f43 kf43 str FX KEY_F(43) - ----E F43 function key +key_f44 kf44 str FY KEY_F(44) - ----E F44 function key +key_f45 kf45 str FZ KEY_F(45) - ----E F45 function key +key_f46 kf46 str Fa KEY_F(46) - ----E F46 function key +key_f47 kf47 str Fb KEY_F(47) - ----E F47 function key +key_f48 kf48 str Fc KEY_F(48) - ----E F48 function key +key_f49 kf49 str Fd KEY_F(49) - ----E F49 function key +key_f50 kf50 str Fe KEY_F(50) - ----E F50 function key +key_f51 kf51 str Ff KEY_F(51) - ----E F51 function key +key_f52 kf52 str Fg KEY_F(52) - ----E F52 function key +key_f53 kf53 str Fh KEY_F(53) - ----E F53 function key +key_f54 kf54 str Fi KEY_F(54) - ----E F54 function key +key_f55 kf55 str Fj KEY_F(55) - ----E F55 function key +key_f56 kf56 str Fk KEY_F(56) - ----E F56 function key +key_f57 kf57 str Fl KEY_F(57) - ----E F57 function key +key_f58 kf58 str Fm KEY_F(58) - ----E F58 function key +key_f59 kf59 str Fn KEY_F(59) - ----E F59 function key +key_f60 kf60 str Fo KEY_F(60) - ----E F60 function key +key_f61 kf61 str Fp KEY_F(61) - ----E F61 function key +key_f62 kf62 str Fq KEY_F(62) - ----E F62 function key +key_f63 kf63 str Fr KEY_F(63) - ----E F63 function key +clr_bol el1 str cb - - ----- Clear to beginning of line +clear_margins mgc str MC - - ----- clear right and left soft margins +set_left_margin smgl str ML - - ----- set left soft margin at current column. See smgl. (ML is not in BSD termcap). +set_right_margin smgr str MR - - ----- set right soft margin at current column +label_format fln str Lf - - ----- label format +set_clock sclk str SC - - ----- set clock, #1 hrs #2 mins #3 secs +display_clock dclk str DK - - ----- display clock +remove_clock rmclk str RC - - ----- remove clock +create_window cwin str CW - - ----- define a window #1 from #2,#3 to #4,#5 +goto_window wingo str WG - - ----- go to window #1 +hangup hup str HU - - ----- hang-up phone +dial_phone dial str DI - - ----- dial number #1 +quick_dial qdial str QD - - ----- dial number #1 without checking +tone tone str TO - - ----- select touch tone dialing +pulse pulse str PU - - ----- select pulse dialing +flash_hook hook str fh - - ----- flash switch hook +fixed_pause pause str PA - - ----- pause for 2-3 seconds +wait_tone wait str WA - - ----- wait for dial-tone +user0 u0 str u0 - - ----- User string #0 +user1 u1 str u1 - - ----- User string #1 +user2 u2 str u2 - - ----- User string #2 +user3 u3 str u3 - - ----- User string #3 +user4 u4 str u4 - - ----- User string #4 +user5 u5 str u5 - - ----- User string #5 +user6 u6 str u6 - - ----- User string #6 +user7 u7 str u7 - - ----- User string #7 +user8 u8 str u8 - - ----- User string #8 +user9 u9 str u9 - - ----- User string #9 # # SVr4 added these capabilities to support color # -orig_pair op str op ----- Set default pair to its original value -orig_colors oc str oc ----- Set all color pairs to the original ones -initialize_color initc str Ic ----- initialize color #1 to (#2,#3,#4) -initialize_pair initp str Ip ----- Initialize color pair #1 to fg=(#2,#3,#4), bg=(#5,#6,#7) -set_color_pair scp str sp ----- Set current color pair to #1 -set_foreground setf str Sf ----- Set foreground color #1 -set_background setb str Sb ----- Set background color #1 +orig_pair op str op - - ----- Set default pair to its original value +orig_colors oc str oc - - ----- Set all color pairs to the original ones +initialize_color initc str Ic - - ----- initialize color #1 to (#2,#3,#4) +initialize_pair initp str Ip - - ----- Initialize color pair #1 to fg=(#2,#3,#4), bg=(#5,#6,#7) +set_color_pair scp str sp - - ----- Set current color pair to #1 +set_foreground setf str Sf - - ----- Set foreground color #1 +set_background setb str Sb - - ----- Set background color #1 # # SVr4 added these capabilities to support printers # -change_char_pitch cpi str ZA ----- Change number of characters per inch to #1 -change_line_pitch lpi str ZB ----- Change number of lines per inch to #1 -change_res_horz chr str ZC ----- Change horizontal resolution to #1 -change_res_vert cvr str ZD ----- Change vertical resolution to #1 -define_char defc str ZE ----- Define a character #1, #2 dots wide, descender #3 -enter_doublewide_mode swidm str ZF ----- Enter double-wide mode -enter_draft_quality sdrfq str ZG ----- Enter draft-quality mode -enter_italics_mode sitm str ZH ----- Enter italic mode -enter_leftward_mode slm str ZI ----- Start leftward carriage motion -enter_micro_mode smicm str ZJ ----- Start micro-motion mode -enter_near_letter_quality snlq str ZK ----- Enter NLQ mode -enter_normal_quality snrmq str ZL ----- Enter normal-quality mode -enter_shadow_mode sshm str ZM ----- Enter shadow-print mode -enter_subscript_mode ssubm str ZN ----- Enter subscript mode -enter_superscript_mode ssupm str ZO ----- Enter superscript mode -enter_upward_mode sum str ZP ----- Start upward carriage motion -exit_doublewide_mode rwidm str ZQ ----- End double-wide mode -exit_italics_mode ritm str ZR ----- End italic mode -exit_leftward_mode rlm str ZS ----- End left-motion mode -exit_micro_mode rmicm str ZT ----- End micro-motion mode -exit_shadow_mode rshm str ZU ----- End shadow-print mode -exit_subscript_mode rsubm str ZV ----- End subscript mode -exit_superscript_mode rsupm str ZW ----- End superscript mode -exit_upward_mode rum str ZX ----- End reverse character motion -micro_column_address mhpa str ZY ----- Like column_address in micro mode -micro_down mcud1 str ZZ ----- Like cursor_down in micro mode -micro_left mcub1 str Za ----- Like cursor_left in micro mode -micro_right mcuf1 str Zb ----- Like cursor_right in micro mode -micro_row_address mvpa str Zc ----- Like row_address #1 in micro mode -micro_up mcuu1 str Zd ----- Like cursor_up in micro mode -order_of_pins porder str Ze ----- Match software bits to print-head pins -parm_down_micro mcud str Zf ----- Like parm_down_cursor in micro mode -parm_left_micro mcub str Zg ----- Like parm_left_cursor in micro mode -parm_right_micro mcuf str Zh ----- Like parm_right_cursor in micro mode -parm_up_micro mcuu str Zi ----- Like parm_up_cursor in micro mode -select_char_set scs str Zj ----- Select character set, #1 -set_bottom_margin smgb str Zk ----- Set bottom margin at current line -set_bottom_margin_parm smgbp str Zl ----- Set bottom margin at line #1 or (if smgtp is not given) #2 lines from bottom -set_left_margin_parm smglp str Zm ----- Set left (right) margin at column #1 -set_right_margin_parm smgrp str Zn ----- Set right margin at column #1 -set_top_margin smgt str Zo ----- Set top margin at current line -set_top_margin_parm smgtp str Zp ----- Set top (bottom) margin at row #1 -start_bit_image sbim str Zq ----- Start printing bit image graphics -start_char_set_def scsd str Zr ----- Start character set definition #1, with #2 characters in the set -stop_bit_image rbim str Zs ----- Stop printing bit image graphics -stop_char_set_def rcsd str Zt ----- End definition of character set #1 -subscript_characters subcs str Zu ----- List of subscriptable characters -superscript_characters supcs str Zv ----- List of superscriptable characters -these_cause_cr docr str Zw ----- Printing any of these characters causes CR -zero_motion zerom str Zx ----- No motion for subsequent character +change_char_pitch cpi str ZA - - ----- Change number of characters per inch to #1 +change_line_pitch lpi str ZB - - ----- Change number of lines per inch to #1 +change_res_horz chr str ZC - - ----- Change horizontal resolution to #1 +change_res_vert cvr str ZD - - ----- Change vertical resolution to #1 +define_char defc str ZE - - ----- Define a character #1, #2 dots wide, descender #3 +enter_doublewide_mode swidm str ZF - - ----- Enter double-wide mode +enter_draft_quality sdrfq str ZG - - ----- Enter draft-quality mode +enter_italics_mode sitm str ZH - - ----- Enter italic mode +enter_leftward_mode slm str ZI - - ----- Start leftward carriage motion +enter_micro_mode smicm str ZJ - - ----- Start micro-motion mode +enter_near_letter_quality snlq str ZK - - ----- Enter NLQ mode +enter_normal_quality snrmq str ZL - - ----- Enter normal-quality mode +enter_shadow_mode sshm str ZM - - ----- Enter shadow-print mode +enter_subscript_mode ssubm str ZN - - ----- Enter subscript mode +enter_superscript_mode ssupm str ZO - - ----- Enter superscript mode +enter_upward_mode sum str ZP - - ----- Start upward carriage motion +exit_doublewide_mode rwidm str ZQ - - ----- End double-wide mode +exit_italics_mode ritm str ZR - - ----- End italic mode +exit_leftward_mode rlm str ZS - - ----- End left-motion mode +exit_micro_mode rmicm str ZT - - ----- End micro-motion mode +exit_shadow_mode rshm str ZU - - ----- End shadow-print mode +exit_subscript_mode rsubm str ZV - - ----- End subscript mode +exit_superscript_mode rsupm str ZW - - ----- End superscript mode +exit_upward_mode rum str ZX - - ----- End reverse character motion +micro_column_address mhpa str ZY - - ----- Like column_address in micro mode +micro_down mcud1 str ZZ - - ----- Like cursor_down in micro mode +micro_left mcub1 str Za - - ----- Like cursor_left in micro mode +micro_right mcuf1 str Zb - - ----- Like cursor_right in micro mode +micro_row_address mvpa str Zc - - ----- Like row_address #1 in micro mode +micro_up mcuu1 str Zd - - ----- Like cursor_up in micro mode +order_of_pins porder str Ze - - ----- Match software bits to print-head pins +parm_down_micro mcud str Zf - - ----- Like parm_down_cursor in micro mode +parm_left_micro mcub str Zg - - ----- Like parm_left_cursor in micro mode +parm_right_micro mcuf str Zh - - ----- Like parm_right_cursor in micro mode +parm_up_micro mcuu str Zi - - ----- Like parm_up_cursor in micro mode +select_char_set scs str Zj - - ----- Select character set, #1 +set_bottom_margin smgb str Zk - - ----- Set bottom margin at current line +set_bottom_margin_parm smgbp str Zl - - ----- Set bottom margin at line #1 or (if smgtp is not given) #2 lines from bottom +set_left_margin_parm smglp str Zm - - ----- Set left (right) margin at column #1 +set_right_margin_parm smgrp str Zn - - ----- Set right margin at column #1 +set_top_margin smgt str Zo - - ----- Set top margin at current line +set_top_margin_parm smgtp str Zp - - ----- Set top (bottom) margin at row #1 +start_bit_image sbim str Zq - - ----- Start printing bit image graphics +start_char_set_def scsd str Zr - - ----- Start character set definition #1, with #2 characters in the set +stop_bit_image rbim str Zs - - ----- Stop printing bit image graphics +stop_char_set_def rcsd str Zt - - ----- End definition of character set #1 +subscript_characters subcs str Zu - - ----- List of subscriptable characters +superscript_characters supcs str Zv - - ----- List of superscriptable characters +these_cause_cr docr str Zw - - ----- Printing any of these characters causes CR +zero_motion zerom str Zx - - ----- No motion for subsequent character #%.TE #%.ad #% @@ -698,41 +701,41 @@ zero_motion zerom str Zx ----- No motion for subsequent character #%lw25 lw6 lw2 lw18. #%\fBVariable Cap- TCap Description\fR #%\fBString name Code\fR -char_set_names csnm str Zy ----- Produce #1'th item from list of character set names -key_mouse kmous str Km ----- Mouse event has occurred -mouse_info minfo str Mi ----- Mouse status information -req_mouse_pos reqmp str RQ ----- Request mouse position -get_mouse getm str Gm ----- Curses should get button events, parameter #1 not documented. -set_a_foreground setaf str AF ----- Set foreground color to #1, using ANSI escape -set_a_background setab str AB ----- Set background color to #1, using ANSI escape -pkey_plab pfxl str xl ----- Program function key #1 to type string #2 and show string #3 -device_type devt str dv ----- Indicate language/codeset support -code_set_init csin str ci ----- Init sequence for multiple codesets -set0_des_seq s0ds str s0 ----- Shift to code set 0 (EUC set 0, ASCII) -set1_des_seq s1ds str s1 ----- Shift to code set 1 -set2_des_seq s2ds str s2 ----- Shift to code set 2 -set3_des_seq s3ds str s3 ----- Shift to code set 3 -set_lr_margin smglr str ML ----- Set both left and right margins to #1, #2. (ML is not in BSD termcap). -set_tb_margin smgtb str MT ----- Sets both top and bottom margins to #1, #2 -bit_image_repeat birep str Xy ----- Repeat bit image cell #1 #2 times -bit_image_newline binel str Zz ----- Move to next row of the bit image -bit_image_carriage_return bicr str Yv ----- Move to beginning of same row -color_names colornm str Yw ----- Give name for color #1 -define_bit_image_region defbi str Yx ----- Define rectangualar bit image region -end_bit_image_region endbi str Yy ----- End a bit-image region -set_color_band setcolor str Yz ----- Change to ribbon color #1 -set_page_length slines str YZ ----- Set page length to #1 lines +char_set_names csnm str Zy - - ----- Produce #1'th item from list of character set names +key_mouse kmous str Km KEY_MOUSE 0631 ----- Mouse event has occurred +mouse_info minfo str Mi - - ----- Mouse status information +req_mouse_pos reqmp str RQ - - ----- Request mouse position +get_mouse getm str Gm - - ----- Curses should get button events, parameter #1 not documented. +set_a_foreground setaf str AF - - ----- Set foreground color to #1, using ANSI escape +set_a_background setab str AB - - ----- Set background color to #1, using ANSI escape +pkey_plab pfxl str xl - - ----- Program function key #1 to type string #2 and show string #3 +device_type devt str dv - - ----- Indicate language/codeset support +code_set_init csin str ci - - ----- Init sequence for multiple codesets +set0_des_seq s0ds str s0 - - ----- Shift to codeset 0 (EUC set 0, ASCII) +set1_des_seq s1ds str s1 - - ----- Shift to codeset 1 +set2_des_seq s2ds str s2 - - ----- Shift to codeset 2 +set3_des_seq s3ds str s3 - - ----- Shift to codeset 3 +set_lr_margin smglr str ML - - ----- Set both left and right margins to #1, #2. (ML is not in BSD termcap). +set_tb_margin smgtb str MT - - ----- Sets both top and bottom margins to #1, #2 +bit_image_repeat birep str Xy - - ----- Repeat bit image cell #1 #2 times +bit_image_newline binel str Zz - - ----- Move to next row of the bit image +bit_image_carriage_return bicr str Yv - - ----- Move to beginning of same row +color_names colornm str Yw - - ----- Give name for color #1 +define_bit_image_region defbi str Yx - - ----- Define rectangualar bit image region +end_bit_image_region endbi str Yy - - ----- End a bit-image region +set_color_band setcolor str Yz - - ----- Change to ribbon color #1 +set_page_length slines str YZ - - ----- Set page length to #1 lines # # SVr4 added these capabilities for direct PC-clone support # -display_pc_char dispc str S1 ----- Display PC character #1 -enter_pc_charset_mode smpch str S2 ----- Enter PC character display mode -exit_pc_charset_mode rmpch str S3 ----- Exit PC character display mode -enter_scancode_mode smsc str S4 ----- Enter PC scancode mode -exit_scancode_mode rmsc str S5 ----- Exit PC scancode mode -pc_term_options pctrm str S6 ----- PC terminal options -scancode_escape scesc str S7 ----- Escape for scancode emulation -alt_scancode_esc scesa str S8 ----- Alternate escape for scancode emulation +display_pc_char dispc str S1 - - ----- Display PC character #1 +enter_pc_charset_mode smpch str S2 - - ----- Enter PC character display mode +exit_pc_charset_mode rmpch str S3 - - ----- Exit PC character display mode +enter_scancode_mode smsc str S4 - - ----- Enter PC scancode mode +exit_scancode_mode rmsc str S5 - - ----- Exit PC scancode mode +pc_term_options pctrm str S6 - - ----- PC terminal options +scancode_escape scesc str S7 - - ----- Escape for scancode emulation +alt_scancode_esc scesa str S8 - - ----- Alternate escape for scancode emulation #%.TE #%.ad #% @@ -752,14 +755,14 @@ alt_scancode_esc scesa str S8 ----- Alternate escape for scancode emulation #%lw25 lw6 lw2 lw20. #%\fBVariable Cap- TCap Description\fR #%\fBString name Code\fR -enter_horizontal_hl_mode ehhlm str Xh ----- Enter horizontal highlight mode -enter_left_hl_mode elhlm str Xl ----- Enter left highlight mode -enter_low_hl_mode elohlm str Xo ----- Enter low highlight mode -enter_right_hl_mode erhlm str Xr ----- Enter right highlight mode -enter_top_hl_mode ethlm str Xt ----- Enter top highlight mode -enter_vertical_hl_mode evhlm str Xv ----- Enter vertical highlight mode -set_a_attributes sgr1 str sA ----- Define second set of video attributes #1-#6 -set_pglen_inch slength str sL ----- YI Set page length to #1 hundredth of an inch +enter_horizontal_hl_mode ehhlm str Xh - - ----- Enter horizontal highlight mode +enter_left_hl_mode elhlm str Xl - - ----- Enter left highlight mode +enter_low_hl_mode elohlm str Xo - - ----- Enter low highlight mode +enter_right_hl_mode erhlm str Xr - - ----- Enter right highlight mode +enter_top_hl_mode ethlm str Xt - - ----- Enter top highlight mode +enter_vertical_hl_mode evhlm str Xv - - ----- Enter vertical highlight mode +set_a_attributes sgr1 str sA - - ----- Define second set of video attributes #1-#6 +set_pglen_inch slength str sL - - ----- YI Set page length to #1 hundredth of an inch #%.TE #%.ad # @@ -796,34 +799,34 @@ set_pglen_inch slength str sL ----- YI Set page length to #1 hundredth of an i # The ug capability is thrown away, but assumed to be whatever sg is if the # latter is nonzero and we're dumping in termcap format. # -termcap_init2 OTi2 str i2 YB--- secondary initialization string -termcap_reset OTrs str rs YB-G- terminal reset string -magic_cookie_glitch_ul OTug num ug YBCGE number of blanks left by ul +termcap_init2 OTi2 str i2 - - YB--- secondary initialization string +termcap_reset OTrs str rs - - YB-G- terminal reset string +magic_cookie_glitch_ul OTug num ug - - YBCGE number of blanks left by ul # # Obsolete termcap capabilities. Some are used for termcap translation. The # code uses the 'OT' prefix we put on obsolete capabilities to suppress # printing them in terminfo source dumps of compiled entries. # -backspaces_with_bs OTbs bool bs YBCGE uses ^H to move left -crt_no_scrolling OTns bool ns YBCG- crt cannot scroll -no_correctly_working_cr OTnc bool nc YBCG- no way to go to start of line -carriage_return_delay OTdC num dC YB-G- pad needed for CR -new_line_delay OTdN num dN YB-G- pad needed for LF -linefeed_if_not_lf OTnl str nl YBCGE use to move down -backspace_if_not_bs OTbc str bc YBCGE move left, if not ^H +backspaces_with_bs OTbs bool bs - - YBCGE uses ^H to move left +crt_no_scrolling OTns bool ns - - YBCG- crt cannot scroll +no_correctly_working_cr OTnc bool nc - - YBCG- no way to go to start of line +carriage_return_delay OTdC num dC - - YB-G- pad needed for CR +new_line_delay OTdN num dN - - YB-G- pad needed for LF +linefeed_if_not_lf OTnl str nl - - YBCGE use to move down +backspace_if_not_bs OTbc str bc - - YBCGE move left, if not ^H # # GNU termcap library extensions. The GNU termcap file distributed with # Emacs no longer uses these, but MT showed up in pre-9.0 versions of the # BSD termcap file. The name clash with terminfo MT is resolved by type # info; MT is converted to km. # -gnu_has_meta_key OTMT bool MT ----E has meta key -# gnu_tab_width OTtw num tw ----E tab width in spaces +gnu_has_meta_key OTMT bool MT - - ----E has meta key +# gnu_tab_width OTtw num tw - - ----E tab width in spaces # # GNU termcap *does* include the following extended capability, Only the # now-obsolete Ann Arbor terminals used it. # -# gnu_change_scroll_region OTcS str cS ---GE alternate set scrolling region +# gnu_change_scroll_region OTcS str cS - - ---GE alternate set scrolling region # # The following comments describe capnames so ancient that I believe no # software uses them any longer. Some of these have to go because they @@ -856,50 +859,50 @@ gnu_has_meta_key OTMT bool MT ----E has meta key # Applications that use terminfo are supposed to behave as though xr is # always true. # -linefeed_is_newline OTNL bool NL YB--- move down with \n -# even_parity OTEP bool EP -B--- terminal requires even parity -# odd_parity OTOP bool OP -B--- terminal requires odd parity -# half_duplex OTHD bool HD -B--- terminal is half-duplex -# lower_case_only OTLC bool LC -B--- terminal has only lower case -# upper_case_only OTUC bool UC -B--- terminal has only upper case -backspace_delay OTdB num dB YB-G- padding required for ^H -# form_feed_delay OTdF num dF -B-G- padding required for ^L -horizontal_tab_delay OTdT num dT YB-G- padding required for ^I -# vertical_tab_delay OTdV num dV -B--- padding required for ^V -number_of_function_keys OTkn num kn -B-G- count of function keys -other_non_function_keys OTko str ko -B-G- list of self-mapped keycaps -arrow_key_map OTma str ma YBC-- map arrow keys rogue(1) motion keys -# memory_lock_above OTml str ml -B--- lock visible screen memory above the current line -# memory_unlock OTmu str mu -B--- unlock visible screen memory above the current line -has_hardware_tabs OTpt bool pt YB--- has 8-char tabs invoked with ^I -return_does_clr_eol OTxr bool xr YB--- return clears the line -# tek_4025_insert_line OTxx bool xx -BC-- Tektronix 4025 insert-line glitch +linefeed_is_newline OTNL bool NL - - YB--- move down with \n +# even_parity OTEP bool EP - - -B--- terminal requires even parity +# odd_parity OTOP bool OP - - -B--- terminal requires odd parity +# half_duplex OTHD bool HD - - -B--- terminal is half-duplex +# lower_case_only OTLC bool LC - - -B--- terminal has only lower case +# upper_case_only OTUC bool UC - - -B--- terminal has only upper case +backspace_delay OTdB num dB - - YB-G- padding required for ^H +# form_feed_delay OTdF num dF - - -B-G- padding required for ^L +horizontal_tab_delay OTdT num dT - - YB-G- padding required for ^I +# vertical_tab_delay OTdV num dV - - -B--- padding required for ^V +number_of_function_keys OTkn num kn - - -B-G- count of function keys +other_non_function_keys OTko str ko - - -B-G- list of self-mapped keycaps +arrow_key_map OTma str ma - - YBC-- map arrow keys rogue(1) motion keys +# memory_lock_above OTml str ml - - -B--- lock visible screen memory above the current line +# memory_unlock OTmu str mu - - -B--- unlock visible screen memory above the current line +has_hardware_tabs OTpt bool pt - - YB--- has 8-char tabs invoked with ^I +return_does_clr_eol OTxr bool xr - - YB--- return clears the line +# tek_4025_insert_line OTxx bool xx - - -BC-- Tektronix 4025 insert-line glitch # # mytinfo described this as a termcap capability, but it's not listed in the # 4.4BSD man pages, and not found in the 4.4BSD termcap file. The ncurses # package, like System V, behaves as though it is always true. # -# rind_only_at_top OTxq bool xq ----- reverse index only works from top line +# rind_only_at_top OTxq bool xq - - ----- reverse index only works from top line # # University of Waterloo termcap extensions (as described in mytinfo). # The `xl' termcap file clashes with a terminfo name; this ambiguity cannot # be resolved by a type check. The descriptions are guesses from what was # in the mytinfo tables. # -# key_interrupt_char OTki str ki ----- string set by interrupt key (?) -# key_kill_char OTkk str kk ----- string set by kill key (?) -# key_suspend_char OTkz str kz ----- string set by suspend key (?) -# initialization_messy OTxc bool xc ----- initialization leaves garbage on the screen (?) -# ind_at_bottom_does_cr OTxl bool xl ----- index does a carriage return +# key_interrupt_char OTki str ki - - ----- string set by interrupt key (?) +# key_kill_char OTkk str kk - - ----- string set by kill key (?) +# key_suspend_char OTkz str kz - - ----- string set by suspend key (?) +# initialization_messy OTxc bool xc - - ----- initialization leaves garbage on the screen (?) +# ind_at_bottom_does_cr OTxl bool xl - - ----- index does a carriage return # # Nonstandard capabilities unique to Ross Ridge's `mytinfo' package. # SR clashes with a terminfo name; this ambiguity cannot be resolved by a type # check. # -# scroll_left OTsl1 str Sl ----- scroll screen leftward -# scroll_right OTsr1 str Sr ----- scroll screen rightward -# parm_scroll_left OTsl str SL ----- scroll screen leftward #1 characters -# parm_scroll_right OTsr str SR ----- scroll screen rightward #1 characters +# scroll_left OTsl1 str Sl - - ----- scroll screen leftward +# scroll_right OTsr1 str Sr - - ----- scroll screen rightward +# parm_scroll_left OTsl str SL - - ----- scroll screen leftward #1 characters +# parm_scroll_right OTsr str SR - - ----- scroll screen rightward #1 characters # # The mytinfo capabilities end here. # @@ -939,17 +942,17 @@ return_does_clr_eol OTxr bool xr YB--- return clears the line # that detects the acs_ prefix and uses it to suppress pad translation. # These terminfo names are invented. # -acs_ulcorner OTG2 str G2 ----- single upper left -acs_llcorner OTG3 str G3 ----- single lower left -acs_urcorner OTG1 str G1 ----- single upper right -acs_lrcorner OTG4 str G4 ----- single lower right -acs_ltee OTGR str GR ----- tee pointing right -acs_rtee OTGL str GL ----- tee pointing left -acs_btee OTGU str GU ----- tee pointing up -acs_ttee OTGD str GD ----- tee pointing down -acs_hline OTGH str GH ----- single horizontal line -acs_vline OTGV str GV ----- single vertical line -acs_plus OTGC str GC ----- single intersection +acs_ulcorner OTG2 str G2 - - ----- single upper left +acs_llcorner OTG3 str G3 - - ----- single lower left +acs_urcorner OTG1 str G1 - - ----- single upper right +acs_lrcorner OTG4 str G4 - - ----- single lower right +acs_ltee OTGR str GR - - ----- tee pointing right +acs_rtee OTGL str GL - - ----- tee pointing left +acs_btee OTGU str GU - - ----- tee pointing up +acs_ttee OTGD str GD - - ----- tee pointing down +acs_hline OTGH str GH - - ----- single horizontal line +acs_vline OTGV str GV - - ----- single vertical line +acs_plus OTGC str GC - - ----- single intersection # ############################################################################# # @@ -966,64 +969,64 @@ acs_plus OTGC str GC ----- single intersection # functionally identical to SVr4 extensions, but they make the binary format # different. Grrr.... # -memory_lock meml str ml ----K memory lock above -memory_unlock memu str mu ----K memory unlock -#plab_norm pln str pn ----- program label #1 to show string #2 -#label_on smln str LO ----- turn on soft labels -#label_off rmln str LF ----- turn off soft labels -#key_f11 kf11 str F1 ----- F11 function key -#key_f12 kf12 str F2 ----- F12 function key -#key_f13 kf13 str F3 ----- F13 function key -#key_f14 kf14 str F4 ----- F14 function key -#key_f15 kf15 str F5 ----- F15 function key -#key_f16 kf16 str F6 ----- F16 function key -#key_f17 kf17 str F7 ----- F17 function key -#key_f18 kf18 str F8 ----- F18 function key -#key_f19 kf19 str F9 ----- F19 function key -#key_f20 kf20 str FA ----- F20 function key -#key_f21 kf21 str FB ----- F21 function key -#key_f22 kf22 str FC ----- F22 function key -#key_f23 kf23 str FD ----- F23 function key -#key_f24 kf24 str FE ----- F24 function key -#key_f25 kf25 str FF ----- F25 function key -#key_f26 kf26 str FG ----- F26 function key -#key_f27 kf27 str FH ----- F27 function key -#key_f28 kf28 str FI ----- F28 function key -#key_f29 kf29 str FJ ----- F29 function key -#key_f30 kf30 str FK ----- F30 function key -#key_f31 kf31 str FL ----- F31 function key -#key_f32 kf32 str FM ----- F32 function key -#key_f33 kf33 str FN ----- F33 function key -#key_f34 kf34 str FO ----- F34 function key -#key_f35 kf35 str FP ----- F35 function key -#key_f36 kf36 str FQ ----- F36 function key -#key_f37 kf37 str FR ----- F37 function key -#key_f38 kf38 str FS ----- F38 function key -#key_f39 kf39 str FT ----- F39 function key -#key_f40 kf40 str FU ----- F40 function key -#key_f41 kf41 str FV ----- F41 function key -#key_f42 kf42 str FW ----- F42 function key -#key_f43 kf43 str FX ----- F43 function key -#key_f44 kf44 str FY ----- F44 function key -#key_f45 kf45 str FZ ----- F45 function key -#key_f46 kf46 str Fa ----- F46 function key -#key_f47 kf47 str Fb ----- F47 function key -#key_f48 kf48 str Fc ----- F48 function key -#key_f49 kf49 str Fd ----- F49 function key -#key_f50 kf50 str Fe ----- F50 function key -#key_f51 kf51 str Ff ----- F51 function key -#key_f52 kf52 str Fg ----- F52 function key -#key_f53 kf53 str Fh ----- F53 function key -#key_f54 kf54 str Fi ----- F54 function key -#key_f55 kf55 str Fj ----- F55 function key -#key_f56 kf56 str Fk ----- F56 function key -#key_f57 kf57 str Fl ----- F57 function key -#key_f58 kf58 str Fm ----- F58 function key -#key_f59 kf59 str Fn ----- F59 function key -#key_f60 kf60 str Fo ----- F60 function key -#key_f61 kf61 str Fp ----- F61 function key -#key_f62 kf62 str Fq ----- F62 function key -#key_f63 kf63 str Fr ----- F63 function key +memory_lock meml str ml - - ----K lock memory above cursor +memory_unlock memu str mu - - ----K unlock memory +#plab_norm pln str pn - - ----- program label #1 to show string #2 +#label_on smln str LO - - ----- turn on soft labels +#label_off rmln str LF - - ----- turn off soft labels +#key_f11 kf11 str F1 - - ----- F11 function key +#key_f12 kf12 str F2 - - ----- F12 function key +#key_f13 kf13 str F3 - - ----- F13 function key +#key_f14 kf14 str F4 - - ----- F14 function key +#key_f15 kf15 str F5 - - ----- F15 function key +#key_f16 kf16 str F6 - - ----- F16 function key +#key_f17 kf17 str F7 - - ----- F17 function key +#key_f18 kf18 str F8 - - ----- F18 function key +#key_f19 kf19 str F9 - - ----- F19 function key +#key_f20 kf20 str FA - - ----- F20 function key +#key_f21 kf21 str FB - - ----- F21 function key +#key_f22 kf22 str FC - - ----- F22 function key +#key_f23 kf23 str FD - - ----- F23 function key +#key_f24 kf24 str FE - - ----- F24 function key +#key_f25 kf25 str FF - - ----- F25 function key +#key_f26 kf26 str FG - - ----- F26 function key +#key_f27 kf27 str FH - - ----- F27 function key +#key_f28 kf28 str FI - - ----- F28 function key +#key_f29 kf29 str FJ - - ----- F29 function key +#key_f30 kf30 str FK - - ----- F30 function key +#key_f31 kf31 str FL - - ----- F31 function key +#key_f32 kf32 str FM - - ----- F32 function key +#key_f33 kf33 str FN - - ----- F33 function key +#key_f34 kf34 str FO - - ----- F34 function key +#key_f35 kf35 str FP - - ----- F35 function key +#key_f36 kf36 str FQ - - ----- F36 function key +#key_f37 kf37 str FR - - ----- F37 function key +#key_f38 kf38 str FS - - ----- F38 function key +#key_f39 kf39 str FT - - ----- F39 function key +#key_f40 kf40 str FU - - ----- F40 function key +#key_f41 kf41 str FV - - ----- F41 function key +#key_f42 kf42 str FW - - ----- F42 function key +#key_f43 kf43 str FX - - ----- F43 function key +#key_f44 kf44 str FY - - ----- F44 function key +#key_f45 kf45 str FZ - - ----- F45 function key +#key_f46 kf46 str Fa - - ----- F46 function key +#key_f47 kf47 str Fb - - ----- F47 function key +#key_f48 kf48 str Fc - - ----- F48 function key +#key_f49 kf49 str Fd - - ----- F49 function key +#key_f50 kf50 str Fe - - ----- F50 function key +#key_f51 kf51 str Ff - - ----- F51 function key +#key_f52 kf52 str Fg - - ----- F52 function key +#key_f53 kf53 str Fh - - ----- F53 function key +#key_f54 kf54 str Fi - - ----- F54 function key +#key_f55 kf55 str Fj - - ----- F55 function key +#key_f56 kf56 str Fk - - ----- F56 function key +#key_f57 kf57 str Fl - - ----- F57 function key +#key_f58 kf58 str Fm - - ----- F58 function key +#key_f59 kf59 str Fn - - ----- F59 function key +#key_f60 kf60 str Fo - - ----- F60 function key +#key_f61 kf61 str Fp - - ----- F61 function key +#key_f62 kf62 str Fq - - ----- F62 function key +#key_f63 kf63 str Fr - - ----- F63 function key # # IBM extensions # @@ -1047,146 +1050,94 @@ memory_unlock memu str mu ----K memory unlock # # The box2 characters are the double-line versions of these forms graphics. # -box_chars_1 box1 str bx ----K box characters primary set -#box_chars_2 box2 str by ----K box characters secondary set -#box_attr_1 batt1 str Bx ----K attributes for box1 -#box_attr_2 batt2 str By ----K attributes for box2 -#color_bg_0 colb0 str d0 ----K background color 0 -#color_bg_1 colb1 str d1 ----K background color 1 -#color_bg_2 colb2 str d2 ----K background color 2 -#color_bg_3 colb3 str d3 ----K background color 3 -#color_bg_4 colb4 str d4 ----K background color 4 -#color_bg_5 colb5 str d5 ----K background color 5 -#color_bg_6 colb6 str d6 ----K background color 6 -#color_bg_7 colb7 str d7 ----K background color 7 -#color_fg_0 colf0 str c0 ----K foreground color 0 -#color_fg_1 colf1 str c1 ----K foreground color 1 -#color_fg_2 colf2 str c2 ----K foreground color 2 -#color_fg_3 colf3 str c3 ----K foreground color 3 -#color_fg_4 colf4 str c4 ----K foreground color 4 -#color_fg_5 colf5 str c5 ----K foreground color 5 -#color_fg_6 colf6 str c6 ----K foreground color 6 -#color_fg_7 colf7 str c7 ----K foreground color 7 -#font_0 font0 str f0 ----- select font 0 -#font_1 font1 str f1 ----- select font 1 -#font_2 font2 str f2 ----- select font 2 -#font_3 font3 str f3 ----- select font 3 -#font_4 font4 str f4 ----K select font 4 -#font_5 font5 str f5 ----K select font 5 -#font_6 font6 str f6 ----K select font 6 -#font_7 font7 str f7 ----K select font 7 -#key_back_tab kbtab str k0 ----- backtab key -#key_do kdo str ki ----K do request key -#key_command kcmd str kd ----K command-request key -#key_command_pane kcpn str kW ----K command-pane key -#key_end kend str kw ----- end key -#key_help khlp str kq ----- help key -#key_newline knl str nl ----K newline key -#key_next_pane knpn str kv ----K next-pane key -#key_prev_cmd kppn str kp ----K previous-command key -#key_prev_pane kppn str kV ----K previous-pane key -#key_quit kquit str kQ ----K quit key -#key_select ksel str kU ----- select key -#key_scroll_left kscl str kz ----K scroll left -#key_scroll_right kscr str kZ ----K scroll right -#key_tab ktab str ko ----K tab key -#key_smap_in1 kmpf1 str Kv ----K special mapped key 1 input -#key_smap_out1 kmpt1 str KV ----K special mapped key 1 output -#key_smap_in2 kmpf2 str Kw ----K special mapped key 2 input -#key_smap_out2 kmpt2 str KW ----K special mapped key 2 output -#key_smap_in3 kmpf3 str Kx ----K special mapped key 3 input -#key_smap_out3 kmpt3 str KX ----K special mapped key 3 output -#key_smap_in4 kmpf4 str Ky ----K special mapped key 4 input -#key_smap_out4 kmpt4 str KY ----K special mapped key 4 output -#key_smap_in5 kmpf5 str Kz ----K special mapped key 5 input -#key_smap_out5 kmpt5 str KZ ----K special mapped key 5 output -#appl_defined_str apstr str za ----K application-defined string +box_chars_1 box1 str bx - - ----K box characters primary set +#box_chars_2 box2 str by - - ----K box characters secondary set +#box_attr_1 batt1 str Bx - - ----K attributes for box1 +#box_attr_2 batt2 str By - - ----K attributes for box2 +#color_bg_0 colb0 str d0 - - ----K background color 0 +#color_bg_1 colb1 str d1 - - ----K background color 1 +#color_bg_2 colb2 str d2 - - ----K background color 2 +#color_bg_3 colb3 str d3 - - ----K background color 3 +#color_bg_4 colb4 str d4 - - ----K background color 4 +#color_bg_5 colb5 str d5 - - ----K background color 5 +#color_bg_6 colb6 str d6 - - ----K background color 6 +#color_bg_7 colb7 str d7 - - ----K background color 7 +#color_fg_0 colf0 str c0 - - ----K foreground color 0 +#color_fg_1 colf1 str c1 - - ----K foreground color 1 +#color_fg_2 colf2 str c2 - - ----K foreground color 2 +#color_fg_3 colf3 str c3 - - ----K foreground color 3 +#color_fg_4 colf4 str c4 - - ----K foreground color 4 +#color_fg_5 colf5 str c5 - - ----K foreground color 5 +#color_fg_6 colf6 str c6 - - ----K foreground color 6 +#color_fg_7 colf7 str c7 - - ----K foreground color 7 +#font_0 font0 str f0 - - ----- select font 0 +#font_1 font1 str f1 - - ----- select font 1 +#font_2 font2 str f2 - - ----- select font 2 +#font_3 font3 str f3 - - ----- select font 3 +#font_4 font4 str f4 - - ----K select font 4 +#font_5 font5 str f5 - - ----K select font 5 +#font_6 font6 str f6 - - ----K select font 6 +#font_7 font7 str f7 - - ----K select font 7 +#key_back_tab kbtab str k0 - - ----- backtab key +#key_do kdo str ki - - ----K do request key +#key_command kcmd str kd - - ----K command-request key +#key_command_pane kcpn str kW - - ----K command-pane key +#key_end kend str kw - - ----- end key +#key_help khlp str kq - - ----- help key +#key_newline knl str nl - - ----K newline key +#key_next_pane knpn str kv - - ----K next-pane key +#key_prev_cmd kppn str kp - - ----K previous-command key +#key_prev_pane kppn str kV - - ----K previous-pane key +#key_quit kquit str kQ - - ----K quit key +#key_select ksel str kU - - ----- select key +#key_scroll_left kscl str kz - - ----K scroll left +#key_scroll_right kscr str kZ - - ----K scroll right +#key_tab ktab str ko - - ----K tab key +#key_smap_in1 kmpf1 str Kv - - ----K special mapped key 1 input +#key_smap_out1 kmpt1 str KV - - ----K special mapped key 1 output +#key_smap_in2 kmpf2 str Kw - - ----K special mapped key 2 input +#key_smap_out2 kmpt2 str KW - - ----K special mapped key 2 output +#key_smap_in3 kmpf3 str Kx - - ----K special mapped key 3 input +#key_smap_out3 kmpt3 str KX - - ----K special mapped key 3 output +#key_smap_in4 kmpf4 str Ky - - ----K special mapped key 4 input +#key_smap_out4 kmpt4 str KY - - ----K special mapped key 4 output +#key_smap_in5 kmpf5 str Kz - - ----K special mapped key 5 input +#key_smap_out5 kmpt5 str KZ - - ----K special mapped key 5 output +#appl_defined_str apstr str za - - ----K application-defined string # The key_smap_in[6789] and key_smap_out[6789] capabilities aren't described in # the IBM manual pages, so the cap name strings are guesses. The terminfo # names are almost certainly right, the termcap ones almost certainly wrong. -#key_smap_in6 kmpf6 str k! ----K special mapped key 6 input -#key_smap_out6 kmpt6 str K@ ----K special mapped key 6 output -#key_smap_in7 kmpf7 str k# ----K special mapped key 7 input -#key_smap_out7 kmpt7 str K$ ----K special mapped key 7 output -#key_smap_in8 kmpf8 str k% ----K special mapped key 8 input -#key_smap_out8 kmpt8 str K^ ----K special mapped key 8 output -#key_smap_in9 kmpf9 str k& ----K special mapped key 9 input -#key_smap_out9 kmpt9 str K* ----K special mapped key 9 output +#key_smap_in6 kmpf6 str k! - - ----K special mapped key 6 input +#key_smap_out6 kmpt6 str K@ - - ----K special mapped key 6 output +#key_smap_in7 kmpf7 str k# - - ----K special mapped key 7 input +#key_smap_out7 kmpt7 str K$ - - ----K special mapped key 7 output +#key_smap_in8 kmpf8 str k% - - ----K special mapped key 8 input +#key_smap_out8 kmpt8 str K^ - - ----K special mapped key 8 output +#key_smap_in9 kmpf9 str k& - - ----K special mapped key 9 input +#key_smap_out9 kmpt9 str K* - - ----K special mapped key 9 output # Undocumented capabilities end here -#key_sf1 ksf1 str S1 ----K special function key 1 -#key_sf2 ksf2 str S2 ----K special function key 2 -#key_sf3 ksf3 str S3 ----K special function key 3 -#key_sf4 ksf4 str S4 ----K special function key 4 -#key_sf5 ksf5 str S5 ----K special function key 5 -#key_sf6 ksf6 str S6 ----K special function key 6 -#key_sf7 ksf7 str S7 ----K special function key 7 -#key_sf8 ksf8 str S8 ----K special function key 8 -#key_sf9 ksf9 str S9 ----K special function key 9 -#key_sf10 ksf10 str SA ----K special function key 10 -#key_f11 kf11 str k< ----- function key 11 -#key_f12 kf12 str k> ----- function key 12 -# The key_f13 through key_f64 capabilities aren't described in -# the IBM manual pages, so the cap name strings are guesses. The terminfo -# names are almost certainly right, the termcap ones certainly wrong. -#key_f13 kf13 str k+ ----- function key 13 -#key_f14 kf14 str k+ ----- function key 14 -#key_f15 kf15 str k+ ----- function key 15 -#key_f16 kf16 str k+ ----- function key 16 -#key_f17 kf17 str k+ ----- function key 17 -#key_f18 kf18 str k+ ----- function key 18 -#key_f19 kf19 str k+ ----- function key 19 -#key_f20 kf20 str k+ ----- function key 20 -#key_f21 kf21 str k+ ----- function key 21 -#key_f22 kf22 str k+ ----- function key 22 -#key_f23 kf23 str k+ ----- function key 23 -#key_f24 kf24 str k+ ----- function key 24 -#key_f25 kf25 str k+ ----- function key 25 -#key_f26 kf26 str k+ ----- function key 26 -#key_f27 kf26 str k+ ----- function key 26 -#key_f28 kf28 str k+ ----- function key 28 -#key_f29 kf29 str k+ ----- function key 29 -#key_f30 kf30 str k+ ----- function key 30 -#key_f31 kf31 str k+ ----- function key 31 -#key_f32 kf31 str k+ ----- function key 32 -#key_f33 kf33 str k+ ----- function key 33 -#key_f34 kf34 str k+ ----- function key 34 -#key_f35 kf35 str k+ ----- function key 35 -#key_f36 kf36 str k+ ----- function key 36 -#key_f37 kf37 str k+ ----- function key 37 -#key_f38 kf38 str k+ ----- function key 38 -#key_f39 kf39 str k+ ----- function key 39 -#key_f40 kf40 str k+ ----- function key 40 -#key_f41 kf41 str k+ ----- function key 41 -#key_f42 kf42 str k+ ----- function key 42 -#key_f43 kf43 str k+ ----- function key 43 -#key_f44 kf44 str k+ ----- function key 44 -#key_f45 kf45 str k+ ----- function key 45 -#key_f46 kf46 str k+ ----- function key 46 -#key_f47 kf47 str k+ ----- function key 47 -#key_f48 kf48 str k+ ----- function key 48 -#key_f49 kf49 str k+ ----- function key 49 -#key_f50 kf50 str k+ ----- function key 50 -#key_f51 kf51 str k+ ----- function key 51 -#key_f52 kf52 str k+ ----- function key 52 -#key_f53 kf53 str k+ ----- function key 53 -#key_f54 kf54 str k+ ----- function key 54 -#key_f55 kf55 str k+ ----- function key 55 -#key_f56 kf56 str k+ ----- function key 56 -#key_f57 kf57 str k+ ----- function key 57 -#key_f58 kf58 str k+ ----- function key 58 -#key_f59 kf59 str k+ ----- function key 59 -#key_f60 kf60 str k+ ----- function key 60 -#key_f61 kf61 str k+ ----- function key 61 -#key_f62 kf62 str k+ ----- function key 62 -#key_f63 kf63 str k+ ----- function key 63 +#key_sf1 ksf1 str S1 - - ----K special function key 1 +#key_sf2 ksf2 str S2 - - ----K special function key 2 +#key_sf3 ksf3 str S3 - - ----K special function key 3 +#key_sf4 ksf4 str S4 - - ----K special function key 4 +#key_sf5 ksf5 str S5 - - ----K special function key 5 +#key_sf6 ksf6 str S6 - - ----K special function key 6 +#key_sf7 ksf7 str S7 - - ----K special function key 7 +#key_sf8 ksf8 str S8 - - ----K special function key 8 +#key_sf9 ksf9 str S9 - - ----K special function key 9 +#key_sf10 ksf10 str SA - - ----K special function key 10 +# AIX version 3 documents different codes for F11, F12 and does not mention +# F13-F64. AIX version 4 uses the same naming for F0-F63 as above. +#key_f11 kf11 str k< - - ----- function key 11 +#key_f12 kf12 str k> - - ----- function key 12 # Undocumented capabilities end here. -#key_action kact str kJ ----K sent by action key +#key_action kact str kJ - - ----K sent by action key # The IBM docs say these capabilities are for table-drawing, and are # valid only for aixterm descriptions. -#enter_topline_mode topl str tp ----K start top-line mode -#enter_bottom_mode btml str bm ----K start bottom-line mode -#enter_rvert_mode rvert str rv ----K start right-vertical mode -#enter_lvert_mode lvert str lv ----K start left-vertical mode +#enter_topline_mode topl str tp - - ----K start top-line mode +#enter_bottom_mode btml str bm - - ----K start bottom-line mode +#enter_rvert_mode rvert str rv - - ----K start right-vertical mode +#enter_lvert_mode lvert str lv - - ----K start left-vertical mode # ############################################################################# # diff --git a/lib/libcurses/Makefile b/lib/libcurses/Makefile index cf63dceaaac..9414ea4e646 100644 --- a/lib/libcurses/Makefile +++ b/lib/libcurses/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.58 2009/08/13 19:54:58 jmc Exp $ +# $OpenBSD: Makefile,v 1.59 2010/01/12 23:21:58 nicm Exp $ # Uncomment this to enable tracing in libcurses #CURSESTRACE=-DTRACE @@ -17,13 +17,13 @@ WANTLINT= SRCS= codes.c comp_captab.c expanded.c fallback.c lib_gen.c lib_keyname.c \ names.c unctrl.c # base -SRCS+= define_key.c keybound.c keyok.c lib_adabind.c lib_addch.c lib_addstr.c \ - lib_beep.c lib_bkgd.c lib_box.c lib_chgat.c lib_clear.c \ - lib_clearok.c lib_clrbot.c lib_clreol.c lib_color.c \ - lib_colorset.c lib_delch.c lib_delwin.c lib_dft_fgbg.c \ - lib_echo.c lib_endwin.c lib_erase.c lib_flash.c lib_freeall.c \ - lib_getch.c lib_getstr.c lib_hline.c lib_immedok.c lib_inchstr.c \ - lib_initscr.c lib_insch.c lib_insdel.c lib_insstr.c lib_instr.c \ +SRCS+= define_key.c key_defined.c keybound.c keyok.c legacy_coding.c \ + lib_addch.c lib_addstr.c lib_beep.c lib_bkgd.c lib_box.c lib_chgat.c \ + lib_clear.c lib_clearok.c lib_clrbot.c lib_clreol.c lib_color.c \ + lib_colorset.c lib_delch.c lib_delwin.c lib_dft_fgbg.c lib_echo.c \ + lib_endwin.c lib_erase.c lib_flash.c lib_freeall.c lib_getch.c \ + lib_getstr.c lib_hline.c lib_immedok.c lib_inchstr.c lib_initscr.c \ + lib_insnstr.c lib_insch.c lib_insdel.c lib_instr.c \ lib_isendwin.c lib_leaveok.c lib_mouse.c lib_move.c lib_mvwin.c \ lib_newterm.c lib_newwin.c lib_nl.c lib_overlay.c lib_pad.c \ lib_printw.c lib_redrawln.c lib_refresh.c lib_restart.c \ @@ -34,20 +34,22 @@ SRCS+= define_key.c keybound.c keyok.c lib_adabind.c lib_addch.c lib_addstr.c \ lib_slkrefr.c lib_slkset.c lib_slktouch.c lib_touch.c \ lib_ungetch.c lib_vline.c lib_wattroff.c lib_wattron.c \ lib_winch.c lib_window.c nc_panel.c resizeterm.c safe_sprintf.c \ - sigaction.c tries.c version.c wresize.c + tries.c use_window.c version.c vsscanf.c wresize.c # tinfo SRCS+= access.c add_tries.c alloc_entry.c alloc_ttype.c captoinfo.c \ comp_error.c comp_expand.c comp_hash.c comp_parse.c comp_scan.c \ - doalloc.c free_ttype.c getenv_num.c home_terminfo.c init_keytry.c \ - lib_acs.c lib_baudrate.c lib_cur_term.c lib_data.c lib_has_cap.c \ - lib_kernel.c lib_longname.c lib_napms.c lib_options.c lib_print.c \ - lib_raw.c lib_setup.c lib_termcap.c lib_termname.c lib_tgoto.c \ - lib_ti.c lib_tparm.c lib_tputs.c lib_ttyflags.c name_match.c \ - parse_entry.c read_bsd_terminfo.c read_entry.c read_termcap.c \ - setbuf.c strings.c write_entry.c + db_iterator.c doalloc.c entries.c free_ttype.c getenv_num.c \ + hashed_db.c home_terminfo.c init_keytry.c lib_acs.c lib_baudrate.c \ + lib_cur_term.c lib_data.c lib_has_cap.c lib_kernel.c lib_longname.c \ + lib_napms.c lib_options.c lib_print.c lib_raw.c lib_setup.c \ + lib_termcap.c lib_termname.c lib_tgoto.c lib_ti.c lib_tparm.c \ + lib_tputs.c lib_ttyflags.c name_match.c parse_entry.c \ + read_bsd_terminfo.c read_entry.c read_termcap.c setbuf.c strings.c \ + trim_sgr0.c use_screen.c write_entry.c # trace SRCS+= lib_trace.c lib_traceatr.c lib_tracebits.c lib_tracechr.c \ - lib_tracedmp.c lib_tracemse.c trace_buf.c trace_tries.c trace_xnames.c + lib_tracedmp.c lib_tracemse.c trace_buf.c trace_tries.c trace_xnames.c \ + varargs.c visbuf.c # tty SRCS+= hardscroll.c hashmap.c lib_mvcur.c lib_tstp.c lib_twait.c \ lib_vidattr.c tty_update.c @@ -57,16 +59,30 @@ HOSTLDFLAGS?= ${LDFLAGS} HOSTCFLAGS+= -I. -I${.CURDIR} ${CURSESTRACE} CFLAGS+= -I. -I${.CURDIR} ${CURSESTRACE} -MAN= curs_addch.3 curs_addchstr.3 curs_addstr.3 curs_attr.3 curs_beep.3 \ - curs_bkgd.3 curs_border.3 curs_clear.3 curs_color.3 curs_delch.3 \ - curs_deleteln.3 curs_extend.3 curs_getch.3 curs_getstr.3 curs_getyx.3 \ - curs_inch.3 curs_inchstr.3 curs_initscr.3 curs_inopts.3 curs_insch.3 \ - curs_insstr.3 curs_instr.3 curs_kernel.3 curs_mouse.3 curs_move.3 \ - curs_outopts.3 curs_overlay.3 curs_pad.3 curs_print.3 curs_printw.3 \ - curs_refresh.3 curs_scanw.3 curs_scr_dump.3 curs_scroll.3 curs_slk.3 \ - curs_termattrs.3 curs_touch.3 curs_util.3 curs_window.3 \ - curses.3 define_key.3 default_colors.3 keybound.3 keyok.3 resizeterm.3 \ - wresize.3 termcap.3 terminfo.3 terminfo.5 term.5 term.7 +MAN= curs_addch.3tbl curs_addchstr.3 curs_addstr.3 curs_attr.3tbl \ + curs_beep.3 curs_bkgd.3 curs_bkgrnd.3 curs_border.3 curs_border_set.3 \ + curs_clear.3 curs_color.3 \ + curs_delch.3 curs_deleteln.3 \ + curs_extend.3 \ + curs_getch.3tbl curs_getstr.3 curs_getyx.3 \ + curs_inch.3tbl curs_inchstr.3 curs_initscr.3 curs_inopts.3 curs_insch.3 curs_insstr.3 curs_instr.3 \ + curs_kernel.3 \ + curs_legacy.3 \ + curs_mouse.3tbl curs_move.3 \ + curs_opaque.3 curs_outopts.3 curs_overlay.3 \ + curs_pad.3 curs_print.3 curs_printw.3 \ + curs_refresh.3 \ + curs_scanw.3 curs_scr_dump.3 curs_scroll.3 curs_slk.3 \ + curs_termattrs.3 curs_touch.3 \ + curs_util.3 \ + curs_window.3 \ + default_colors.3 define_key.3 \ + key_defined.3 keybound.3 keyok.3 \ + curses.3tbl \ + resizeterm.3 \ + term.5tbl term.7 termcap.3 terminfo.3 terminfo.5tbl \ + wresize.3 + MLINKS+=curses.3 ncurses.3 MLINKS+=curs_addch.3 addch.3 curs_addch.3 waddch.3 curs_addch.3 mvaddch.3 \ curs_addch.3 mvwaddch.3 curs_addch.3 echochar.3 curs_addch.3 \ @@ -186,9 +202,28 @@ MLINKS+= terminfo.3 setupterm.3 terminfo.3 setterm.3 terminfo.3 set_curterm.3 \ terminfo.3 tigetflag.3 terminfo.3 tigetnum.3 terminfo.3 tigetstr.3 MLINKS+= termcap.3 tgetent.3 termcap.3 tgetflag.3 termcap.3 tgetnum.3 \ termcap.3 tgetstr.3 termcap.3 tgoto.3 termcap.3 tputs.3 +MLINKS+= curs_bkgrnd.3 bkgrnd.3 curs_bkgrnd.3 wbkgrnd.3 \ + curs_bkgrnd.3 bkgrndset.3 curs_bkgrnd.3 wbkgrndset.3 \ + curs_bkgrnd.3 getbkgrnd.3 curs_bkgrnd.3 wgetbkgrnd.3 +MLINKS+= curs_border_set.3 border_set.3 curs_border_set.3 wborder_set.3 \ + curs_border_set.3 box_set.3 curs_border_set.3 hline_set.3 \ + curs_border_set.3 whline_set.3 curs_border_set.3 mvhline_set.3 \ + curs_border_set.3 mvhline_set.3 curs_border_set.3 mvwhline_set.3 \ + curs_border_set.3 vline_set.3 curs_border_set.3 wvline_set.3 \ + curs_border_set.3 mvvline_set.3 curs_border_set.3 mvwvline_set.3 +MLINKS+= curs_legacy.3 getbegx.3 curs_legacy.3 getbegy.3 \ + curs_legacy.3 getcurx.3 curs_legacy.3 getcury.3 \ + curs_legacy.3 getmaxx.3 curs_legacy.3 getmaxy.3 \ + curs_legacy.3 getparx.3 curs_legacy.3 getpary.3 +MLINKS+= curs_opaque.3 is_cleared.3 curs_opaque.3 is_idcok.3 \ + curs_opaque.3 is_idlok.3 curs_opaque.3 is_immedok.3 \ + curs_opaque.3 is_keypad.3 curs_opaque.3 is_leaveok.3 \ + curs_opaque.3 is_nodelay.3 curs_opaque.3 is_notimeout.3 \ + curs_opaque.3 is_scrollok.3 curs_opaque.3 is_syncok.3 \ + curs_opaque.3 wgetparent.3 curs_opaque.3 wgetscrreg.3 -GENERATED= init_keytry.h nomacros.h codes.c comp_captab.c expanded.c \ - fallback.c lib_gen.c lib_keyname.c names.c unctrl.c make_hash make_keys +GENERATED= init_keytry.h codes.c comp_captab.c expanded.c fallback.c \ + keys.list lib_gen.c lib_keyname.c names.c unctrl.c make_hash make_keys CLEANFILES+= ${GENERATED} stamp_namebuild .if make(install) @@ -208,44 +243,51 @@ includes: ${INSTALL} ${INSTALL_COPY} -m 444 -o $(BINOWN) -g $(BINGRP) $$i \ ${DESTDIR}/usr/include; done -fallback.c: ${.CURDIR}/term.h ${.CURDIR}/curses.priv.h ${.CURDIR}/tinfo/MKfallback.sh - sh ${.CURDIR}/tinfo/MKfallback.sh $(FALLBACK_LIST) > ${.TARGET} +keys.list: ${.CURDIR}/tinfo/MKkeys_list.sh + sh ${.CURDIR}/tinfo/MKkeys_list.sh ${.CURDIR}/Caps | sort > ${.TARGET} -lib_gen.c: ${.CURDIR}/curses.h ${.CURDIR}/base/MKlib_gen.sh - sh ${.CURDIR}/base/MKlib_gen.sh "${CPP} -I${.CURDIR}" "${AWK}" < ${.CURDIR}/curses.h > lib_gen.c +fallback.c: ${.CURDIR}/tinfo/MKfallback.sh + sh ${.CURDIR}/tinfo/MKfallback.sh $(FALLBACK_LIST) > ${.TARGET} -nomacros.h: ${.CURDIR}/base/MKlib_gen.sh lib_gen.c - fgrep undef lib_gen.c > ${.TARGET} +lib_gen.c: ${.CURDIR}/base/MKlib_gen.sh + sh ${.CURDIR}/base/MKlib_gen.sh "${CPP} -I${.CURDIR}" \ + "${AWK}" generated < ${.CURDIR}/curses.h > lib_gen.c -init_keytry.h: make_keys ${.CURDIR}/tinfo/keys.list - ./make_keys ${.CURDIR}/tinfo/keys.list > ${.TARGET} +init_keytry.h: make_keys keys.list + ./make_keys keys.list > ${.TARGET} -make_keys: ${.CURDIR}/tinfo/make_keys.c names.c - ${HOSTCC} ${LDSTATIC} ${HOSTCFLAGS} ${HOSTLDFLAGS} -o ${.TARGET} ${.CURDIR}/tinfo/make_keys.c ${LDADD} +make_keys: ${.CURDIR}/tinfo/make_keys.c ${.CURDIR}/curses.priv.h names.c + ${HOSTCC} ${LDSTATIC} ${HOSTCFLAGS} ${HOSTLDFLAGS} \ + -o ${.TARGET} ${.CURDIR}/tinfo/make_keys.c ${LDADD} -make_hash: ${.CURDIR}/tinfo/comp_hash.c ${.CURDIR}/hashsize.h - ${HOSTCC} ${LDSTATIC} ${HOSTCFLAGS} -DMAIN_PROGRAM ${HOSTLDFLAGS} -o ${.TARGET} ${.CURDIR}/tinfo/comp_hash.c ${LDADD} +make_hash: ${.CURDIR}/tinfo/comp_hash.c ${.CURDIR}/curses.priv.h \ + ${.CURDIR}/hashsize.h + ${HOSTCC} ${LDSTATIC} ${HOSTCFLAGS} -DMAIN_PROGRAM ${HOSTLDFLAGS} \ + -o ${.TARGET} ${.CURDIR}/tinfo/comp_hash.c ${LDADD} -expanded.c: ${.CURDIR}/term.h ${.CURDIR}/curses.priv.h ${.CURDIR}/tty/MKexpanded.sh +expanded.c: ${.CURDIR}/term.h ${.CURDIR}/curses.priv.h \ + ${.CURDIR}/ncurses_cfg.h ${.CURDIR}/tty/MKexpanded.sh sh ${.CURDIR}/tty/MKexpanded.sh "${CPP}" ${CPPFLAGS} > ${.TARGET} -comp_captab.c: make_hash ${.CURDIR}/ncurses_cfg.h ${.CURDIR}/tic.h ${.CURDIR}/term.h - sh ${.CURDIR}/tinfo/MKcaptab.awk ${AWK} ${.CURDIR}/Caps > ${.TARGET} +comp_captab.c: make_hash + sh ${.CURDIR}/tinfo/MKcaptab.sh ${AWK} 1 \ + ${.CURDIR}/tinfo/MKcaptab.awk ${.CURDIR}/Caps > ${.TARGET} -lib_keyname.c: ${.CURDIR}/ncurses_cfg.h ${.CURDIR}/curses.h ${.CURDIR}/term.h ${.CURDIR}/tinfo/keys.list ${.CURDIR}/base/MKkeyname.awk - ${AWK} -f ${.CURDIR}/base/MKkeyname.awk ${.CURDIR}/tinfo/keys.list > ${.TARGET} +lib_keyname.c: keys.list ${.CURDIR}/base/MKkeyname.awk + ${AWK} -f ${.CURDIR}/base/MKkeyname.awk bigstrings=1 \ + keys.list > ${.TARGET} names.c codes.c: stamp_namebuild -stamp_namebuild: ${.CURDIR}/tinfo/MKnames.awk - ${AWK} -f ${.CURDIR}/tinfo/MKnames.awk ${.CURDIR}/Caps - cat namehdr boolnames boolfnames numnames numfnames strnames strfnames nameftr > names.c - cat namehdr boolcodes numcodes strcodes codeftr > codes.c - -rm -f namehdr nameftr codeftr boolnames boolfnames boolcodes numnames numfnames numcodes strnames strfnames strcodes +stamp_namebuild: ${.CURDIR}/tinfo/MKnames.awk ${.CURDIR}/tinfo/MKcodes.awk + ${AWK} -f ${.CURDIR}/tinfo/MKnames.awk \ + ${.CURDIR}/Caps > names.c + ${AWK} -f ${.CURDIR}/tinfo/MKcodes.awk \ + bigstrings=1 ${.CURDIR}/Caps > codes.c touch $@ unctrl.c: ${.CURDIR}/base/MKunctrl.awk - echo | ${AWK} -f ${.CURDIR}/base/MKunctrl.awk > ${.TARGET} + echo | ${AWK} -f ${.CURDIR}/base/MKunctrl.awk bigstrings=1 > ${.TARGET} .include <bsd.own.mk> diff --git a/lib/libcurses/SigAction.h b/lib/libcurses/SigAction.h index 5faf7c43e53..3a2783284d1 100644 --- a/lib/libcurses/SigAction.h +++ b/lib/libcurses/SigAction.h @@ -1,4 +1,4 @@ -/* $OpenBSD: SigAction.h,v 1.3 2001/01/22 18:01:32 millert Exp $ */ +/* $OpenBSD: SigAction.h,v 1.4 2010/01/12 23:21:58 nicm Exp $ */ /**************************************************************************** * Copyright (c) 1998,2000 Free Software Foundation, Inc. * @@ -34,7 +34,7 @@ ****************************************************************************/ /* - * $From: SigAction.h,v 1.6 2000/12/10 02:36:10 tom Exp $ + * $Id: SigAction.h,v 1.4 2010/01/12 23:21:58 nicm Exp $ * * This file exists to handle non-POSIX systems which don't have <unistd.h>, * and usually no sigaction() nor <termios.h> @@ -61,10 +61,6 @@ typedef struct sigaction sigaction_t; #if HAVE_SIGVEC -#if HAVE_LIBC_H -#include <libc.h> -#endif - #undef SIG_BLOCK #define SIG_BLOCK 00 @@ -107,12 +103,8 @@ typedef unsigned long sigset_t; #undef sigaddset #define sigaddset _nc_sigaddset -extern NCURSES_EXPORT(int) sigaction (int sig, sigaction_t * sigact, sigaction_t * osigact); -extern NCURSES_EXPORT(int) sigprocmask (int how, sigset_t *mask, sigset_t *omask); -extern NCURSES_EXPORT(int) sigemptyset (sigset_t *mask); -extern NCURSES_EXPORT(int) sigsuspend (sigset_t *mask); -extern NCURSES_EXPORT(int) sigdelset (sigset_t *mask, int sig); -extern NCURSES_EXPORT(int) sigaddset (sigset_t *mask, int sig); +/* tty/lib_tstp.c is the only user */ +#include <base/sigaction.c> #endif /* HAVE_SIGVEC */ #endif /* HAVE_SIGACTION */ diff --git a/lib/libcurses/base/MKkeyname.awk b/lib/libcurses/base/MKkeyname.awk index 5c45e22cc6e..9f98264a0ca 100644 --- a/lib/libcurses/base/MKkeyname.awk +++ b/lib/libcurses/base/MKkeyname.awk @@ -1,7 +1,7 @@ -# $OpenBSD: MKkeyname.awk,v 1.4 2003/03/17 21:54:44 millert Exp $ -# $From: MKkeyname.awk,v 1.18 2000/12/10 02:25:23 tom Exp $ +# $OpenBSD: MKkeyname.awk,v 1.5 2010/01/12 23:22:05 nicm Exp $ +# $Id: MKkeyname.awk,v 1.5 2010/01/12 23:22:05 nicm Exp $ ############################################################################## -# Copyright (c) 1999,2000 Free Software Foundation, Inc. # +# Copyright (c) 1999-2007,2008 Free Software Foundation, Inc. # # # # Permission is hereby granted, free of charge, to any person obtaining a # # copy of this software and associated documentation files (the "Software"), # @@ -30,49 +30,136 @@ BEGIN { print "/* generated by MKkeyname.awk */" print "" - print "#include <ncurses_cfg.h>" - print "#include <stdlib.h>" - print "#include <string.h>" - print "#include <curses.h>" + print "#include <curses.priv.h>" print "#include <tic.h>" + print "#include <term_entry.h>" print "" - print "const struct kn _nc_key_names[] = {" + first = 1; } /^[^#]/ { - printf "\t{ \"%s\", %s },\n", $1, $1; + if (bigstrings) { + if (first) { + print "struct kn { short offset; int code; };" + print "static const struct kn _nc_key_names[] = {" + } + printf "\t{ %d, %s },\n", offset, $1 + offset += length($1) + 1 + names = names"\n\t\""$1"\\0\"" + } else { + if (first) { + print "struct kn { const char *name; int code; };" + print "static const struct kn _nc_key_names[] = {" + } + printf "\t{ \"%s\", %s },\n", $1, $1; + } + first = 0; } END { - printf "\t{ 0, 0 }};\n" + if (bigstrings) { + printf "\t{ -1, 0 }};\n" + print "" + print "static const char key_names[] = "names";" + } else { + printf "\t{ 0, 0 }};\n" + } + print "" + print "#define SIZEOF_TABLE 256" + print "#define MyTable _nc_globals.keyname_table" + print "" + print "NCURSES_EXPORT(NCURSES_CONST char *) _nc_keyname (SCREEN *sp, int c)" + print "{" + print " int i;" + print " char name[20];" + print " char *p;" + print " size_t psize;" + print " NCURSES_CONST char *result = 0;" + print "" + print " if (c == -1) {" + print " result = \"-1\";" + print " } else {" + if (bigstrings) { + print " for (i = 0; _nc_key_names[i].offset != -1; i++) {" + print " if (_nc_key_names[i].code == c) {" + print " result = (NCURSES_CONST char *)key_names + _nc_key_names[i].offset;" + print " break;" + print " }" + print " }" + } else { + print " for (i = 0; _nc_key_names[i].name != 0; i++) {" + print " if (_nc_key_names[i].code == c) {" + print " result = (NCURSES_CONST char *)_nc_key_names[i].name;" + print " break;" + print " }" + print " }" + } + print "" + print " if (result == 0 && (c >= 0 && c < SIZEOF_TABLE)) {" + print " if (MyTable == 0)" + print " MyTable = typeCalloc(char *, SIZEOF_TABLE);" + print " if (MyTable != 0) {" + print " if (MyTable[c] == 0) {" + print " int cc = c;" + print " p = name;" + print " psize = sizeof(name);" + print " if (cc >= 128 && (sp == 0 || sp->_use_meta)) {" + print " strlcpy(p, \"M-\", psize);" + print " p += 2;" + print " psize -= 2;" + print " cc -= 128;" + print " }" + print " if (cc < 32)" + print " snprintf(p, psize, \"^%c\", cc + '@');" + print " else if (cc == 127)" + print " strlcpy(p, \"^?\", psize);" + print " else" + print " snprintf(p, psize, \"%c\", cc);" + print " MyTable[c] = strdup(name);" + print " }" + print " result = MyTable[c];" + print " }" + print "#if NCURSES_EXT_FUNCS && NCURSES_XNAMES" + print " } else if (result == 0 && cur_term != 0) {" + print " int j, k;" + print " char * bound;" + print " TERMTYPE *tp = &(cur_term->type);" + print " int save_trace = _nc_tracing;" + print "" + print " _nc_tracing = 0; /* prevent recursion via keybound() */" + print " for (j = 0; (bound = keybound(c, j)) != 0; ++j) {" + print " for(k = STRCOUNT; k < (int) NUM_STRINGS(tp); k++) {" + print " if (tp->Strings[k] != 0 && !strcmp(bound, tp->Strings[k])) {" + print " result = ExtStrname(tp, k, strnames);" + print " break;" + print " }" + print " }" + print " free(bound);" + print " if (result != 0)" + print " break;" + print " }" + print " _nc_tracing = save_trace;" + print "#endif" + print " }" + print " }" + print " return result;" + print "}" print "" print "NCURSES_EXPORT(NCURSES_CONST char *) keyname (int c)" print "{" - print "\tint i;" - print "\tstatic char name[20];" - print "\tchar *p;" - print "\tsize_t psize;" + print "\treturn _nc_keyname(SP, c);" + print "}" print "" - print "\tfor (i = 0; _nc_key_names[i].name != 0; i++)" - print "\t\tif (_nc_key_names[i].code == c)" - print "\t\t\treturn (NCURSES_CONST char *)_nc_key_names[i].name;" - print "\tif (c >= 256) return \"UNKNOWN KEY\";" - print "\tp = name;" - print "\tpsize = sizeof(name);" - print "\tif (c >= 128) {" - print "\t\tstrlcpy(p, \"M-\", psize);" - print "\t\tp += 2;" - print "\t\tpsize -= 2;" - print "\t\tc -= 128;" - print "\t}" - print "\tif (c < 0)" - print "\t\tsnprintf(p, psize, \"%d\", c);" - print "\telse if (c < 32)" - print "\t\tsnprintf(p, psize, \"^%c\", c + '@');" - print "\telse if (c == 127)" - print "\t\tstrlcpy(p, \"^?\", psize);" - print "\telse" - print "\t\tsnprintf(p, psize, \"%c\", c);" - print "\treturn (NCURSES_CONST char *)name;" + print "#if NO_LEAKS" + print "void _nc_keyname_leaks(void)" + print "{" + print " int j;" + print " if (MyTable != 0) {" + print " for (j = 0; j < SIZEOF_TABLE; ++j) {" + print " FreeIfNeeded(MyTable[j]);" + print " }" + print " FreeAndNull(MyTable);" + print " }" print "}" + print "#endif /* NO_LEAKS */" } diff --git a/lib/libcurses/base/MKlib_gen.sh b/lib/libcurses/base/MKlib_gen.sh index ad30cb2b149..1c183621da8 100644 --- a/lib/libcurses/base/MKlib_gen.sh +++ b/lib/libcurses/base/MKlib_gen.sh @@ -2,8 +2,36 @@ # # MKlib_gen.sh -- generate sources from curses.h macro definitions # -# $OpenBSD: MKlib_gen.sh,v 1.3 2001/01/22 18:01:36 millert Exp $ -# ($From: MKlib_gen.sh,v 1.13 2000/12/10 00:30:25 tom Exp $) +# $OpenBSD: MKlib_gen.sh,v 1.4 2010/01/12 23:22:05 nicm Exp $ +# ($Id: MKlib_gen.sh,v 1.4 2010/01/12 23:22:05 nicm Exp $) +# +############################################################################## +# Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. # +# # +# Permission is hereby granted, free of charge, to any person obtaining a # +# copy of this software and associated documentation files (the "Software"), # +# to deal in the Software without restriction, including without limitation # +# the rights to use, copy, modify, merge, publish, distribute, distribute # +# with modifications, sublicense, and/or sell copies of the Software, and to # +# permit persons to whom the Software is furnished to do so, subject to the # +# following conditions: # +# # +# The above copyright notice and this permission notice shall be included in # +# all copies or substantial portions of the Software. # +# # +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # +# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # +# DEALINGS IN THE SOFTWARE. # +# # +# Except as contained in this notice, the name(s) of the above copyright # +# holders shall not be used in advertising or otherwise to promote the sale, # +# use or other dealings in this Software without prior written # +# authorization. # +############################################################################## # # The XSI Curses standard requires all curses entry points to exist as # functions, even though many definitions would normally be shadowed @@ -12,14 +40,14 @@ # # This script accepts a file of prototypes on standard input. It discards # any that don't have a `generated' comment attached. It then parses each -# prototype (relying on the fact that none of the macros take function +# prototype (relying on the fact that none of the macros take function # pointer or array arguments) and generates C source from it. # # Here is what the pipeline stages are doing: # # 1. sed: extract prototypes of generated functions # 2. sed: decorate prototypes with generated arguments a1. a2,...z -# 3. awk: generate the calls with args matching the formals +# 3. awk: generate the calls with args matching the formals # 4. sed: prefix function names in prototypes so the preprocessor won't expand # them. # 5. cpp: macro-expand the file so the macro calls turn into C calls @@ -27,32 +55,62 @@ # 7. sed: squeeze spaces, strip off gen_ prefix, create needed #undef # -preprocessor="$1 -I../include" +# keep the editing independent of locale: +if test "${LANGUAGE+set}" = set; then LANGUAGE=C; export LANGUAGE; fi +if test "${LANG+set}" = set; then LANG=C; export LANG; fi +if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi +if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi +if test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi +if test "${LC_COLLATE+set}" = set; then LC_COLLATE=C; export LC_COLLATE; fi + +preprocessor="$1 -DNCURSES_INTERNALS -I../include" AWK="$2" -ED1=sed1$$.sed -ED2=sed2$$.sed -ED3=sed3$$.sed -AW1=awk1$$.awk -TMP=gen$$.c -trap "rm -f $ED1 $ED2 $ED3 $AW1 $TMP" 0 1 2 5 15 +USE="$3" -(cat <<EOF -#include <ncurses_cfg.h> -#include <curses.h> +PID=$$ +ED1=sed1_${PID}.sed +ED2=sed2_${PID}.sed +ED3=sed3_${PID}.sed +ED4=sed4_${PID}.sed +AW1=awk1_${PID}.awk +AW2=awk2_${PID}.awk +TMP=gen__${PID}.c +trap "rm -f $ED1 $ED2 $ED3 $ED4 $AW1 $AW2 $TMP" 0 1 2 5 15 -DECLARATIONS - -EOF -cat >$ED1 <<EOF1 +ALL=$USE +if test "$USE" = implemented ; then + CALL="call_" + cat >$ED1 <<EOF1 +/^extern.*implemented/{ + h + s/^.*implemented:\([^ *]*\).*/P_POUNDCif_USE_\1_SUPPORT/p + g + s/^extern \([^;]*\);.*/\1/p + g + s/^.*implemented:\([^ *]*\).*/P_POUNDCendif/p +} /^extern.*generated/{ h - s/^.*generated:\([^ *]*\).*/P_#if_USE_\1_SUPPORT/p + s/^.*generated:\([^ *]*\).*/P_POUNDCif_USE_\1_SUPPORT/p + g + s/^extern \([^;]*\);.*/\1/p + g + s/^.*generated:\([^ *]*\).*/P_POUNDCendif/p +} +EOF1 +else + CALL="" + cat >$ED1 <<EOF1 +/^extern.*${ALL}/{ + h + s/^.*${ALL}:\([^ *]*\).*/P_POUNDCif_USE_\1_SUPPORT/p g s/^extern \([^;]*\);.*/\1/p g - s/^.*generated:\([^ *]*\).*/P_#endif/p + s/^.*${ALL}:\([^ *]*\).*/P_POUNDCendif/p } EOF1 +fi cat >$ED2 <<EOF2 /^P_/b nc @@ -75,55 +133,102 @@ cat >$ED2 <<EOF2 s/*/ * /g s/%/ , /g s/)/ z)/ + s/\.\.\. z)/...)/ :nc - /(/s// ( / + s/(/ ( / s/)/ )/ EOF2 cat >$ED3 <<EOF3 /^P_/{ - s/^P_#if_/#if / + s/^P_POUNDCif_/#if / + s/^P_POUNDCendif/#endif/ s/^P_// b done } s/ */ /g s/ */ /g s/ ,/,/g + s/( /(/g s/ )/)/g s/ gen_/ / s/^M_/#undef / - /^%%/s// / + s/^[ ]*@[ ]*@[ ]*/ / :done EOF3 +if test "$USE" = generated ; then +cat >$ED4 <<EOF + s/^\(.*\) \(.*\) (\(.*\))\$/NCURSES_EXPORT(\1) \2 (\3)/ +EOF +else +cat >$ED4 <<EOF +/^\(.*\) \(.*\) (\(.*\))\$/ { + h + s/^\(.*\) \(.*\) (\(.*\))\$/extern \1 call_\2 (\3);/ + p + g + s/^\(.*\) \(.*\) (\(.*\))\$/\1 call_\2 (\3)/ + } +EOF +fi + cat >$AW1 <<\EOF1 BEGIN { skip=0; } - /^P_#if/ { +/^P_POUNDCif/ { print "\n" print $0 skip=0; - } - /^P_#endif/ { +} +/^P_POUNDCendif/ { print $0 skip=1; - } - $0 !~ /^P_/ { +} +$0 !~ /^P_/ { if (skip) print "\n" skip=1; - if ( $1 == "chtype" ) { + first=$1 + for (i = 1; i <= NF; i++) { + if ( $i != "NCURSES_CONST" ) { + first = i; + break; + } + } + second = first + 1; + if ( $first == "chtype" ) { returnType = "Char"; + } else if ( $first == "SCREEN" ) { + returnType = "SP"; + } else if ( $first == "WINDOW" ) { + returnType = "Win"; + } else if ( $first == "attr_t" || $second == "attrset" || $second == "standout" || $second == "standend" || $second == "wattrset" || $second == "wstandout" || $second == "wstandend" ) { + returnType = "Attr"; + } else if ( $first == "bool" || $first == "NCURSES_BOOL" ) { + returnType = "Bool"; + } else if ( $second == "*" ) { + returnType = "Ptr"; } else { returnType = "Code"; } - print "M_" $2 + myfunc = second; + for (i = second; i <= NF; i++) { + if ($i != "*") { + myfunc = i; + break; + } + } + if (using == "generated") { + print "M_" $myfunc + } print $0; print "{"; argcount = 1; - if (NF == 5 && $4 == "void") + check = NF - 1; + if ($check == "void") argcount = 0; if (argcount != 0) { for (i = 1; i <= NF; i++) @@ -134,21 +239,36 @@ BEGIN { # suppress trace-code for functions that we cannot do properly here, # since they return data. dotrace = 1; - if ($2 == "innstr") + if ($myfunc ~ /innstr/) + dotrace = 0; + if ($myfunc ~ /innwstr/) dotrace = 0; - call = "%%T((T_CALLED(\"" + # workaround functions that we do not parse properly + if ($myfunc ~ /ripoffline/) { + dotrace = 0; + argcount = 2; + } + if ($myfunc ~ /wunctrl/) { + dotrace = 0; + } + + call = "@@T((T_CALLED(\"" args = "" comma = "" num = 0; pointer = 0; + va_list = 0; + varargs = 0; argtype = "" - for (i = 1; i <= NF; i++) { + for (i = myfunc; i <= NF; i++) { ch = $i; if ( ch == "*" ) pointer = 1; else if ( ch == "va_list" ) - pointer = 1; + va_list = 1; + else if ( ch == "..." ) + varargs = 1; else if ( ch == "char" ) argtype = "char"; else if ( ch == "int" ) @@ -161,7 +281,11 @@ BEGIN { argtype = "attr"; if ( ch == "," || ch == ")" ) { - if (pointer) { + if (va_list) { + call = call "%s" + } else if (varargs) { + call = call "%s" + } else if (pointer) { if ( argtype == "char" ) { call = call "%s" comma = comma "_nc_visbuf2(" num "," @@ -180,10 +304,17 @@ BEGIN { comma = comma "(long)" } } - if (ch == ",") + if (ch == ",") { args = args comma "a" ++num; - else if (argcount != 0) - args = args comma "z" + } else if ( argcount != 0 ) { + if ( va_list ) { + args = args comma "\"va_list\"" + } else if ( varargs ) { + args = args comma "\"...\"" + } else { + args = args comma "z" + } + } call = call ch if (pointer == 0 && argcount != 0 && argtype != "" ) args = args ")" @@ -208,13 +339,19 @@ BEGIN { else if (dotrace) call = sprintf("return%s( ", returnType); else - call = "%%return "; + call = "@@return "; - call = call $2 "("; - for (i = 1; i < argcount; i++) - call = call "a" i ", "; - if (argcount != 0) + call = call $myfunc "("; + for (i = 1; i < argcount; i++) { + if (i != 1) + call = call ", "; + call = call "a" i; + } + if ( argcount != 0 && $check != "..." ) { + if (argcount != 1) + call = call ", "; call = call "z"; + } if (!match($0, "^void")) call = call ") "; if (dotrace) @@ -222,43 +359,72 @@ BEGIN { print call ";" if (match($0, "^void")) - print "%%returnVoid;" + print "@@returnVoid;" print "}"; } EOF1 +cat >$AW2 <<EOF1 +BEGIN { + print "/*" + print " * DO NOT EDIT THIS FILE BY HAND!" + printf " * It is generated by $0 %s.\n", "$USE" + if ( "$USE" == "generated" ) { + print " *" + print " * This is a file of trivial functions generated from macro" + print " * definitions in curses.h to satisfy the XSI Curses requirement" + print " * that every macro also exist as a callable function." + print " *" + print " * It will never be linked unless you call one of the entry" + print " * points with its normal macro definition disabled. In that" + print " * case, if you have no shared libraries, it will indirectly" + print " * pull most of the rest of the library into your link image." + } + print " */" + print "#define NCURSES_ATTR_T int" + print "#include <curses.priv.h>" + print "" + } +/^DECLARATIONS/ {start = 1; next;} + {if (start) print \$0;} +END { + if ( "$USE" != "generated" ) { + print "int main(void) { return 0; }" + } + } +EOF1 + +cat >$TMP <<EOF +#include <ncurses_cfg.h> +#undef NCURSES_NOMACROS +#include <curses.h> + +DECLARATIONS + +EOF + sed -n -f $ED1 \ | sed -e 's/NCURSES_EXPORT(\(.*\)) \(.*\) (\(.*\))/\1 \2(\3)/' \ | sed -f $ED2 \ -| $AWK -f $AW1 ) \ +| $AWK -f $AW1 using=$USE \ | sed \ - -e '/^\([a-z_][a-z_]*\) /s//\1 gen_/' >$TMP - $preprocessor $TMP 2>/dev/null \ -| $AWK ' -BEGIN { - print "/*" - print " * DO NOT EDIT THIS FILE BY HAND!" - print " * It is generated by MKlib_gen.sh." - print " *" - print " * This is a file of trivial functions generated from macro" - print " * definitions in curses.h to satisfy the XSI Curses requirement" - print " * that every macro also exist as a callable function." - print " *" - print " * It will never be linked unless you call one of the entry" - print " * points with its normal macro definition disabled. In that" - print " * case, if you have no shared libraries, it will indirectly" - print " * pull most of the rest of the library into your link image." - print " */" - print "#include <curses.priv.h>" - print "" - } -/^DECLARATIONS/ {start = 1; next;} - {if (start) print $0;} -' \ + -e 's/ [ ]*$//g' \ + -e 's/^\([a-zA-Z_][a-zA-Z_]*[ *]*\)/\1 gen_/' \ + -e 's/gen_$//' \ + -e 's/ / /g' >>$TMP + +$preprocessor $TMP 2>/dev/null \ +| sed \ + -e 's/ / /g' \ + -e 's/^ //' \ + -e 's/_Bool/NCURSES_BOOL/g' \ +| $AWK -f $AW2 \ | sed -f $ED3 \ | sed \ -e 's/^.*T_CALLED.*returnCode( \([a-z].*) \));/ return \1;/' \ -e 's/^.*T_CALLED.*returnCode( \((wmove.*) \));/ return \1;/' \ -| sed \ - -e 's/^\(.*\) \(.*\) (\(.*\))$/NCURSES_EXPORT(\1) \2 (\3)/' - + -e 's/gen_//' \ + -e 's/^[ ]*#/#/' \ + -e '/#ident/d' \ + -e '/#line/d' \ +| sed -f $ED4 diff --git a/lib/libcurses/base/MKunctrl.awk b/lib/libcurses/base/MKunctrl.awk index ee9423558c5..506443a6512 100644 --- a/lib/libcurses/base/MKunctrl.awk +++ b/lib/libcurses/base/MKunctrl.awk @@ -1,7 +1,7 @@ -# $OpenBSD: MKunctrl.awk,v 1.3 2001/01/22 18:01:36 millert Exp $ -# $From: MKunctrl.awk,v 1.8 2000/12/10 02:25:37 tom Exp $ +# $OpenBSD: MKunctrl.awk,v 1.4 2010/01/12 23:22:05 nicm Exp $ +# $Id: MKunctrl.awk,v 1.4 2010/01/12 23:22:05 nicm Exp $ ############################################################################## -# Copyright (c) 1998,2000 Free Software Foundation, Inc. # +# Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. # # # # Permission is hereby granted, free of charge, to any person obtaining a # # copy of this software and associated documentation files (the "Software"), # @@ -28,43 +28,166 @@ # authorization. # ############################################################################## # -# Author: Thomas E. Dickey <dickey@clark.net> 1997 +# Author: Thomas E. Dickey (1997-on) # BEGIN { print "/* generated by MKunctrl.awk */" print "" print "#include <curses.priv.h>" + print "#include <ctype.h>" + print "" + print "#if USE_WIDEC_SUPPORT" + print "#if HAVE_WCTYPE_H" + print "#include <wctype.h>" + print "#endif" + print "#endif" print "" print "#undef unctrl" print "" } END { - print "NCURSES_EXPORT(NCURSES_CONST char *) unctrl (register chtype ch)" + print "NCURSES_EXPORT(NCURSES_CONST char *) _nc_unctrl (SCREEN *sp, chtype ch)" print "{" - printf "static const char* const table[] = {" + + blob="" + offset=0 + if (bigstrings) { + printf "static const short unctrl_table[] = {" + } else { + printf "static const char* const unctrl_table[] = {" + } for ( ch = 0; ch < 256; ch++ ) { gap = "," - if ((ch % 8) == 0) + part="" + if ((ch % 8) == 0) { printf "\n " + if (ch != 0) + blob = blob "\"" + blob = blob "\n \"" + } + if (bigstrings) + printf "%4d%s", offset, gap; if (ch < 32) { - printf "\"^\\%03o\"", ch + 64 + part = sprintf ("^\\%03o", ch + 64); + offset = offset + 3; } else if (ch == 127) { - printf "\"^?\"" + part = "^?"; + offset = offset + 3; } else if (ch >= 128 && ch < 160) { - printf "\"~\\%03o\"", ch - 64 + part = sprintf("~\\%03o", ch - 64); + offset = offset + 3; + } else if (ch == 255) { + part = "~?"; + offset = offset + 3; + } else if (ch >= 160) { + part = sprintf("M-\\%03o", ch - 128); + offset = offset + 4; } else { - printf "\"\\%03o\"", ch gap = gap " " + part = sprintf("\\%03o", ch); + offset = offset + 2; } if (ch == 255) gap = "\n" else if (((ch + 1) % 8) != 0) gap = gap " " - printf "%s", gap + if (bigstrings) { + blob = blob part "\\0"; + } else { + printf "\"%s\"%s", part, gap + } + } + print "};" + blob = blob "\""; + + print "" + printf "#if NCURSES_EXT_FUNCS\n"; + if (bigstrings) { + blob = blob "\n/* printable values in 128-255 range */" + printf "static const short unctrl_c1[] = {" + } else { + printf "static const char* const unctrl_c1[] = {" + } + for ( ch = 128; ch < 256; ch++ ) { + gap = "," + if ((ch % 8) == 0) { + if (ch != 128) + blob = blob "\"" + printf "\n " + blob = blob "\n \"" + } + if (bigstrings) { + printf "%4d%s", offset, gap; + part = sprintf("\\%03o\\0", ch); + blob = blob part + offset = offset + 2; + if (((ch + 1) % 8) != 0) + gap = gap " " + } else { + if (ch >= 128) { + printf "\"\\%03o\"", ch + gap = gap " " + } + if (ch == 255) + gap = "\n" + else if (((ch + 1) % 8) != 0) + gap = gap " " + printf "%s", gap + } } print "};" + print "#endif /* NCURSES_EXT_FUNCS */" + blob = blob "\"\n" + print "" - print "\treturn (NCURSES_CONST char *)table[TextOf(ch)];" - print "}" + if (bigstrings) { + print "static const char unctrl_blob[] = "blob";" + print "" + stringname = "unctrl_blob + unctrl" + } else { + stringname = "unctrl" + } + print "\tint check = ChCharOf(ch);" + print "\tconst char *result;" + print "" + print "\tif (check >= 0 && check < (int)SIZEOF(unctrl_table)) {" + print "#if NCURSES_EXT_FUNCS" + print "\t\tif ((sp != 0)" + print "\t\t && (sp->_legacy_coding > 1)" + print "\t\t && (check >= 128)" + print "\t\t && (check < 160))" + printf "\t\t\tresult = %s_c1[check - 128];\n", stringname; + print "\t\telse" + print "#if USE_WIDEC_SUPPORT" + print "\t\tif ((check >= 160)" + print "\t\t && (check < 256)" + print "\t\t && ((sp != 0)" + print "\t\t && ((sp->_legacy_coding > 0)" + print "\t\t || (sp->_legacy_coding == 0" + print "\t\t && (isprint(check) || iswprint(check))))))" + printf "\t\t\tresult = %s_c1[check - 128];\n", stringname; + print "\t\telse" + print "#else" + print "\t\tif ((check >= 160)" + print "\t\t && (check < 256)" + print "\t\t && ((sp != 0)" + print "\t\t && ((sp->_legacy_coding > 0)" + print "\t\t || (sp->_legacy_coding == 0" + print "\t\t && isprint(check)))))" + printf "\t\t\tresult = %s_c1[check - 128];\n", stringname; + print "\t\telse" + print "#endif /* USE_WIDEC_SUPPORT */" + print "#endif /* NCURSES_EXT_FUNCS */" + printf "\t\t\tresult = %s_table[check];\n", stringname; + print "\t} else {" + print "\t\tresult = 0;" + print "\t}" + print "\treturn (NCURSES_CONST char *)result;" + print "}" + print "" + print "NCURSES_EXPORT(NCURSES_CONST char *) unctrl (chtype ch)" + print "{" + print "\treturn _nc_unctrl(SP, ch);" + print "}" } diff --git a/lib/libcurses/base/define_key.c b/lib/libcurses/base/define_key.c index 5dd6dcda7ea..001287859cb 100644 --- a/lib/libcurses/base/define_key.c +++ b/lib/libcurses/base/define_key.c @@ -1,7 +1,7 @@ -/* $OpenBSD: define_key.c,v 1.4 2001/01/22 18:01:36 millert Exp $ */ +/* $OpenBSD: define_key.c,v 1.5 2010/01/12 23:22:05 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,30 +29,40 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey <dickey@clark.net> 1997 * + * Author: Thomas E. Dickey 1997-on * ****************************************************************************/ #include <curses.priv.h> -MODULE_ID("$From: define_key.c,v 1.6 2000/12/10 02:43:26 tom Exp $") +MODULE_ID("$Id: define_key.c,v 1.5 2010/01/12 23:22:05 nicm Exp $") NCURSES_EXPORT(int) -define_key -(char *str, int keycode) +define_key(const char *str, int keycode) { int code = ERR; T((T_CALLED("define_key(%s,%d)"), _nc_visbuf(str), keycode)); - if (keycode > 0) { + if (SP == 0) { + code = ERR; + } else if (keycode > 0) { + unsigned ukey = (unsigned) keycode; + if (str != 0) { define_key(str, 0); } else if (has_key(keycode)) { - while (_nc_remove_key(&(SP->_keytry), keycode)) + while (_nc_remove_key(&(SP->_keytry), ukey)) code = OK; } if (str != 0) { - (void) _nc_add_to_try(&(SP->_keytry), str, keycode); - code = OK; + if (key_defined(str) == 0) { + if (_nc_add_to_try(&(SP->_keytry), str, ukey) == OK) { + code = OK; + } else { + code = ERR; + } + } else { + code = ERR; + } } } else { while (_nc_remove_string(&(SP->_keytry), str)) diff --git a/lib/libcurses/base/sigaction.c b/lib/libcurses/base/key_defined.c index f25543c4dea..65f66486dec 100644 --- a/lib/libcurses/base/sigaction.c +++ b/lib/libcurses/base/key_defined.c @@ -1,7 +1,7 @@ -/* $OpenBSD: sigaction.c,v 1.4 2001/01/22 18:01:48 millert Exp $ */ +/* $OpenBSD: key_defined.c,v 1.1 2010/01/12 23:22:05 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 2003,2006 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,92 +29,52 @@ ****************************************************************************/ /**************************************************************************** - * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * - * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * Author: Thomas E. Dickey, 2003 * ****************************************************************************/ #include <curses.priv.h> -#include <signal.h> -#include <SigAction.h> +MODULE_ID("$Id: key_defined.c,v 1.1 2010/01/12 23:22:05 nicm Exp $") -/* This file provides sigaction() emulation using sigvec() */ -/* Use only if this is non POSIX system */ - -#if !HAVE_SIGACTION && HAVE_SIGVEC - -MODULE_ID("$From: sigaction.c,v 1.11 2000/12/10 02:43:28 tom Exp $") - -NCURSES_EXPORT(int) -sigaction -(int sig, sigaction_t * sigact, sigaction_t * osigact) -{ - return sigvec(sig, sigact, osigact); -} - -NCURSES_EXPORT(int) -sigemptyset -(sigset_t * mask) +static int +find_definition(TRIES * tree, const char *str) { - *mask = 0; - return 0; + TRIES *ptr; + int result = OK; + + if (str != 0 && *str != '\0') { + for (ptr = tree; ptr != 0; ptr = ptr->sibling) { + if (UChar(*str) == UChar(ptr->ch)) { + if (str[1] == '\0' && ptr->child != 0) { + result = ERR; + } else if ((result = find_definition(ptr->child, str + 1)) + == OK) { + result = ptr->value; + } else if (str[1] == '\0') { + result = ERR; + } + } + if (result != OK) + break; + } + } + return (result); } +/* + * Returns the keycode associated with the given string. If none is found, + * return OK. If the string is only a prefix to other strings, return ERR. + * Otherwise, return the keycode's value (neither OK/ERR). + */ NCURSES_EXPORT(int) -sigprocmask -(int mode, sigset_t * mask, sigset_t * omask) +key_defined(const char *str) { - sigset_t current = sigsetmask(0); - - if (omask) - *omask = current; + int code = ERR; - if (mode == SIG_BLOCK) - current |= *mask; - else if (mode == SIG_UNBLOCK) - current &= ~*mask; - else if (mode == SIG_SETMASK) - current = *mask; + T((T_CALLED("key_defined(%s)"), _nc_visbuf(str))); + if (SP != 0 && str != 0) { + code = find_definition(SP->_keytry, str); + } - sigsetmask(current); - return 0; + returnCode(code); } - -NCURSES_EXPORT(int) -sigsuspend(sigset_t * mask) -{ - return sigpause(*mask); -} - -NCURSES_EXPORT(int) -sigdelset -(sigset_t * mask, int sig) -{ - *mask &= ~sigmask(sig); - return 0; -} - -NCURSES_EXPORT(int) -sigaddset -(sigset_t * mask, int sig) -{ - *mask |= sigmask(sig); - return 0; -} - -NCURSES_EXPORT(int) -sigismember -(sigset_t * mask, int sig) -{ - return (*mask & sigmask(sig)) != 0; -} - -#else -extern -NCURSES_EXPORT(void) -_nc_sigaction(void); /* quiet's gcc warning */ -NCURSES_EXPORT(void) -_nc_sigaction(void) -{ -} /* nonempty for strict ANSI compilers */ -#endif diff --git a/lib/libcurses/base/keybound.c b/lib/libcurses/base/keybound.c index 7bb74aad505..e8f1c34f860 100644 --- a/lib/libcurses/base/keybound.c +++ b/lib/libcurses/base/keybound.c @@ -1,7 +1,7 @@ -/* $OpenBSD: keybound.c,v 1.4 2007/10/17 20:10:44 chl Exp $ */ +/* $OpenBSD: keybound.c,v 1.5 2010/01/12 23:22:05 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1999-2005,2006 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,25 +29,26 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey <dickey@clark.net> 1999 * + * Author: Thomas E. Dickey 1999-on * ****************************************************************************/ #include <curses.priv.h> #include <limits.h> -MODULE_ID("$From: keybound.c,v 1.3 2000/12/10 02:43:26 tom Exp $") +MODULE_ID("$Id: keybound.c,v 1.5 2010/01/12 23:22:05 nicm Exp $") /* * Returns the count'th string definition which is associated with the * given keycode. The result is malloc'd, must be freed by the caller. */ - NCURSES_EXPORT(char *) keybound(int code, int count) { - if (code < 0 || code > (int)USHRT_MAX) { - return NULL; - } else { - return _nc_expand_try(SP->_key_ok, (unsigned short)code, &count, 0); + char *result = 0; + + T((T_CALLED("keybound(%d,%d)"), code, count)); + if (SP != 0 && code >= 0) { + result = _nc_expand_try(SP->_keytry, (unsigned) code, &count, 0); } + returnPtr(result); } diff --git a/lib/libcurses/base/keyok.c b/lib/libcurses/base/keyok.c index e486969237c..0eb646984a4 100644 --- a/lib/libcurses/base/keyok.c +++ b/lib/libcurses/base/keyok.c @@ -1,7 +1,7 @@ -/* $OpenBSD: keyok.c,v 1.4 2006/05/14 09:01:06 espie Exp $ */ +/* $OpenBSD: keyok.c,v 1.5 2010/01/12 23:22:05 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2000,2006 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,13 +29,12 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey <dickey@clark.net> 1997 * + * Author: Thomas E. Dickey 1997-on * ****************************************************************************/ #include <curses.priv.h> -#include <limits.h> -MODULE_ID("$From: keyok.c,v 1.5 2000/12/10 02:43:26 tom Exp $") +MODULE_ID("$Id: keyok.c,v 1.5 2010/01/12 23:22:05 nicm Exp $") /* * Enable (or disable) ncurses' interpretation of a keycode by adding (or @@ -55,25 +54,27 @@ keyok(int c, bool flag) char *s; T((T_CALLED("keyok(%d,%d)"), c, flag)); - if (c >= 0 && c <= (int)USHRT_MAX) { - unsigned short k = (unsigned short) c; - if (flag) { - while ((s = _nc_expand_try(SP->_key_ok, k, &count, 0)) != 0 - && _nc_remove_key(&(SP->_key_ok), k)) { - _nc_add_to_try(&(SP->_keytry), s, k); - free(s); - code = OK; - count = 0; - } - } else { - while ((s = _nc_expand_try(SP->_keytry, k, &count, 0)) != 0 - && _nc_remove_key(&(SP->_keytry), k)) { - _nc_add_to_try(&(SP->_key_ok), s, k); - free(s); - code = OK; - count = 0; - } + if (c >= 0) { + unsigned ch = (unsigned) c; + if (flag) { + while ((s = _nc_expand_try(SP->_key_ok, ch, &count, 0)) != 0 + && _nc_remove_key(&(SP->_key_ok), ch)) { + code = _nc_add_to_try(&(SP->_keytry), s, ch); + free(s); + count = 0; + if (code != OK) + break; } + } else { + while ((s = _nc_expand_try(SP->_keytry, ch, &count, 0)) != 0 + && _nc_remove_key(&(SP->_keytry), ch)) { + code = _nc_add_to_try(&(SP->_key_ok), s, ch); + free(s); + count = 0; + if (code != OK) + break; + } + } } returnCode(code); } diff --git a/lib/libcurses/base/legacy_coding.c b/lib/libcurses/base/legacy_coding.c new file mode 100644 index 00000000000..f88d1b8ddc4 --- /dev/null +++ b/lib/libcurses/base/legacy_coding.c @@ -0,0 +1,50 @@ +/* $OpenBSD: legacy_coding.c,v 1.1 2010/01/12 23:22:05 nicm Exp $ */ + +/**************************************************************************** + * Copyright (c) 2005 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey * + ****************************************************************************/ + +#include <curses.priv.h> + +MODULE_ID("$Id: legacy_coding.c,v 1.1 2010/01/12 23:22:05 nicm Exp $") + +NCURSES_EXPORT(int) +use_legacy_coding(int level) +{ + int result = ERR; + + T((T_CALLED("use_legacy_coding(%d)"), level)); + if (level >= 0 && level <= 2 && SP != 0) { + result = SP->_legacy_coding; + SP->_legacy_coding = level; + } + returnCode(result); +} diff --git a/lib/libcurses/base/lib_adabind.c b/lib/libcurses/base/lib_adabind.c deleted file mode 100644 index 2fd7faa23ed..00000000000 --- a/lib/libcurses/base/lib_adabind.c +++ /dev/null @@ -1,220 +0,0 @@ -/* $OpenBSD: lib_adabind.c,v 1.1 1999/01/18 19:09:34 millert Exp $ */ - -/**************************************************************************** - * Copyright (c) 1998 Free Software Foundation, Inc. * - * * - * Permission is hereby granted, free of charge, to any person obtaining a * - * copy of this software and associated documentation files (the * - * "Software"), to deal in the Software without restriction, including * - * without limitation the rights to use, copy, modify, merge, publish, * - * distribute, distribute with modifications, sublicense, and/or sell * - * copies of the Software, and to permit persons to whom the Software is * - * furnished to do so, subject to the following conditions: * - * * - * The above copyright notice and this permission notice shall be included * - * in all copies or substantial portions of the Software. * - * * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * - * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * - * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * - * * - * Except as contained in this notice, the name(s) of the above copyright * - * holders shall not be used in advertising or otherwise to promote the * - * sale, use or other dealings in this Software without prior written * - * authorization. * - ****************************************************************************/ - -/**************************************************************************** - * Author: Juergen Pfeifer <Juergen.Pfeifer@T-Online.de> 1996,1997 * - ****************************************************************************/ - -/* -// lib_adabind.c -// -// Some small wrappers to ease the implementation of an Ada95 -// binding. Especially functionalities only available as macros -// in (n)curses are wrapped here by functions. -// See the documentation and copyright notices in the ../Ada95 -// subdirectory. -*/ -#include "curses.priv.h" - -MODULE_ID("$From: lib_adabind.c,v 1.10 1998/12/06 04:30:32 juergen Exp $") - -/* In (n)curses are a few functionalities that can't be expressed as -// functions, because for historic reasons they use as macro argument -// variable names that are "out" parameters. For those macros we provide -// small wrappers. -*/ - -/* Prototypes for the functions in this module */ -int _nc_ada_getmaxyx (const WINDOW *win, int *y, int *x); -int _nc_ada_getbegyx (const WINDOW *win, int *y, int *x); -int _nc_ada_getyx (const WINDOW *win, int *y, int *x); -int _nc_ada_getparyx (const WINDOW *win, int *y, int *x); -int _nc_ada_isscroll (const WINDOW *win); -int _nc_ada_coord_transform (const WINDOW *win, int *Y, int *X, int dir); -void _nc_ada_mouse_event (mmask_t m, int *b, int *s); -int _nc_ada_mouse_mask (int button, int state, mmask_t *mask); -void _nc_ada_unregister_mouse (void); -int _nc_ada_vcheck (int major, int minor); - -int _nc_ada_getmaxyx (const WINDOW *win, int *y, int *x) -{ - if (win && y && x) - { - getmaxyx(win,*y,*x); - return OK; - } - else - return ERR; -} - -int _nc_ada_getbegyx (const WINDOW *win, int *y, int *x) -{ - if (win && y && x) - { - getbegyx(win,*y,*x); - return OK; - } - else - return ERR; -} - -int _nc_ada_getyx (const WINDOW *win, int *y, int *x) -{ - if (win && y && x) - { - getyx(win,*y,*x); - return OK; - } - else - return ERR; -} - -int _nc_ada_getparyx (const WINDOW *win, int *y, int *x) -{ - if (win && y && x) - { - getparyx(win,*y,*x); - return OK; - } - else - return ERR; -} - -int _nc_ada_isscroll (const WINDOW *win) -{ - return win ? (win->_scroll ? TRUE : FALSE) : ERR; -} - -#define BUTTON1_EVENTS (BUTTON1_RELEASED |\ - BUTTON1_PRESSED |\ - BUTTON1_CLICKED |\ - BUTTON1_DOUBLE_CLICKED |\ - BUTTON1_TRIPLE_CLICKED |\ - BUTTON1_RESERVED_EVENT ) - -#define BUTTON2_EVENTS (BUTTON2_RELEASED |\ - BUTTON2_PRESSED |\ - BUTTON2_CLICKED |\ - BUTTON2_DOUBLE_CLICKED |\ - BUTTON2_TRIPLE_CLICKED |\ - BUTTON2_RESERVED_EVENT ) - -#define BUTTON3_EVENTS (BUTTON3_RELEASED |\ - BUTTON3_PRESSED |\ - BUTTON3_CLICKED |\ - BUTTON3_DOUBLE_CLICKED |\ - BUTTON3_TRIPLE_CLICKED |\ - BUTTON3_RESERVED_EVENT ) - -#define BUTTON4_EVENTS (BUTTON4_RELEASED |\ - BUTTON4_PRESSED |\ - BUTTON4_CLICKED |\ - BUTTON4_DOUBLE_CLICKED |\ - BUTTON4_TRIPLE_CLICKED |\ - BUTTON4_RESERVED_EVENT ) - -void _nc_ada_mouse_event( mmask_t m, int *b, int *s ) -{ - int k = 0; - - if ( m & BUTTON1_EVENTS) - { - k = 1; - } - else if ( m & BUTTON2_EVENTS) - { - k = 2; - } - else if ( m & BUTTON3_EVENTS) - { - k = 3; - } - else if ( m & BUTTON4_EVENTS) - { - k = 4; - } - - if (k) - { - *b = k-1; - if (BUTTON_RELEASE(m,k)) *s = 0; - else if (BUTTON_PRESS(m,k)) *s = 1; - else if (BUTTON_CLICK(m,k)) *s = 2; - else if (BUTTON_DOUBLE_CLICK(m,k)) *s = 3; - else if (BUTTON_TRIPLE_CLICK(m,k)) *s = 4; - else if (BUTTON_RESERVED_EVENT(m,k)) *s = 5; - else - { - *s = -1; - } - } - else - { - *s = 1; - if (m & BUTTON_CTRL) *b = 4; - else if (m & BUTTON_SHIFT) *b = 5; - else if (m & BUTTON_ALT) *b = 6; - else - { - *b = -1; - } - } -} - -int _nc_ada_mouse_mask ( int button, int state, mmask_t *mask ) -{ - mmask_t b = (button<4) ? ((1<<6*button) << state) : - (BUTTON_CTRL << (button-4)); - - if (button>=4 && state!=1) - return ERR; - - *mask |= b; - return OK; -} - -/* - * Allow Ada to check whether or not we are the correct library version - * for the binding. It calls this routine with the version it requests - * and this routine returns a 1 if it is a correct version, a 2 if the - * major version is correct but the minor version of the library differs - * and a 0 if the versions don't match. - */ -int _nc_ada_vcheck (int major, int minor) -{ - if (major==NCURSES_VERSION_MAJOR) { - if (minor==NCURSES_VERSION_MINOR) - return 1; - else - return 2; - } - else - return 0; -} diff --git a/lib/libcurses/base/lib_addch.c b/lib/libcurses/base/lib_addch.c index 4408a6cc43c..055ca39306b 100644 --- a/lib/libcurses/base/lib_addch.c +++ b/lib/libcurses/base/lib_addch.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_addch.c,v 1.4 2001/01/22 18:01:37 millert Exp $ */ +/* $OpenBSD: lib_addch.c,v 1.5 2010/01/12 23:22:05 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2006,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -28,11 +28,6 @@ * authorization. * ****************************************************************************/ -/**************************************************************************** - * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * - * and: Eric S. Raymond <esr@snark.thyrsus.com> * - ****************************************************************************/ - /* ** lib_addch.c ** @@ -43,7 +38,9 @@ #include <curses.priv.h> #include <ctype.h> -MODULE_ID("$From: lib_addch.c,v 1.47 2000/12/10 02:43:26 tom Exp $") +MODULE_ID("$Id: lib_addch.c,v 1.5 2010/01/12 23:22:05 nicm Exp $") + +static const NCURSES_CH_T blankchar = NewChar(BLANK_TEXT); /* * Ugly microtweaking alert. Everything from here to end of module is @@ -56,41 +53,56 @@ MODULE_ID("$From: lib_addch.c,v 1.47 2000/12/10 02:43:26 tom Exp $") */ /* Return bit mask for clearing color pair number if given ch has color */ -#define COLOR_MASK(ch) (~(chtype)((ch)&A_COLOR?A_COLOR:0)) +#define COLOR_MASK(ch) (~(attr_t)((ch) & A_COLOR ? A_COLOR : 0)) -static inline chtype -render_char(WINDOW *win, chtype ch) +static NCURSES_INLINE NCURSES_CH_T +render_char(WINDOW *win, NCURSES_CH_T ch) /* compute a rendition of the given char correct for the current context */ { - chtype a = win->_attrs; - - if (ch == ' ') { - /* color in attrs has precedence over bkgd */ - ch = a | (win->_bkgd & COLOR_MASK(a)); + attr_t a = WINDOW_ATTRS(win); + int pair = GetPair(ch); + + if (ISBLANK(ch) + && AttrOf(ch) == A_NORMAL + && pair == 0) { + /* color/pair in attrs has precedence over bkgrnd */ + ch = win->_nc_bkgd; + SetAttr(ch, a | AttrOf(win->_nc_bkgd)); + if ((pair = GET_WINDOW_PAIR(win)) == 0) + pair = GetPair(win->_nc_bkgd); + SetPair(ch, pair); } else { - /* color in attrs has precedence over bkgd */ - a |= (win->_bkgd & A_ATTRIBUTES) & COLOR_MASK(a); + /* color in attrs has precedence over bkgrnd */ + a |= AttrOf(win->_nc_bkgd) & COLOR_MASK(a); /* color in ch has precedence */ - ch |= (a & COLOR_MASK(ch)); + if (pair == 0) { + if ((pair = GET_WINDOW_PAIR(win)) == 0) + pair = GetPair(win->_nc_bkgd); + } +#if 0 + if (pair > 255) { + NCURSES_CH_T fixme = ch; + SetPair(fixme, pair); + } +#endif + AddAttr(ch, (a & COLOR_MASK(AttrOf(ch)))); + SetPair(ch, pair); } - TR(TRACE_VIRTPUT, ("bkg = %lx, attrs = %lx -> ch = %lx", win->_bkgd, - win->_attrs, ch)); + TR(TRACE_VIRTPUT, + ("render_char bkg %s (%d), attrs %s (%d) -> ch %s (%d)", + _tracech_t2(1, CHREF(win->_nc_bkgd)), + GetPair(win->_nc_bkgd), + _traceattr(WINDOW_ATTRS(win)), + GET_WINDOW_PAIR(win), + _tracech_t2(3, CHREF(ch)), + GetPair(ch))); return (ch); } -NCURSES_EXPORT(chtype) -_nc_background -(WINDOW *win) -/* make render_char() visible while still allowing us to inline it below */ -{ - return (win->_bkgd); -} - -NCURSES_EXPORT(chtype) -_nc_render -(WINDOW *win, chtype ch) +NCURSES_EXPORT(NCURSES_CH_T) +_nc_render(WINDOW *win, NCURSES_CH_T ch) /* make render_char() visible while still allowing us to inline it below */ { return render_char(win, ch); @@ -112,77 +124,306 @@ _nc_render #define CHECK_POSITION(win, x, y) /* nothing */ #endif -static inline int -waddch_literal(WINDOW *win, chtype ch) +static bool +newline_forces_scroll(WINDOW *win, NCURSES_SIZE_T * ypos) { - int x; - struct ldat *line; - - x = win->_curx; + bool result = FALSE; - CHECK_POSITION(win, x, win->_cury); + if (*ypos >= win->_regtop && *ypos == win->_regbottom) { + *ypos = win->_regbottom; + result = TRUE; + } else { + *ypos += 1; + } + return result; +} - /* - * If we're trying to add a character at the lower-right corner more - * than once, fail. (Moving the cursor will clear the flag). - */ -#if 0 /* Solaris 2.6 allows updating the corner more than once */ - if (win->_flags & _WRAPPED) { - if (x >= win->_maxx) +/* + * The _WRAPPED flag is useful only for telling an application that we've just + * wrapped the cursor. We don't do anything with this flag except set it when + * wrapping, and clear it whenever we move the cursor. If we try to wrap at + * the lower-right corner of a window, we cannot move the cursor (since that + * wouldn't be legal). So we return an error (which is what SVr4 does). + * Unlike SVr4, we can successfully add a character to the lower-right corner + * (Solaris 2.6 does this also, however). + */ +static int +wrap_to_next_line(WINDOW *win) +{ + win->_flags |= _WRAPPED; + if (newline_forces_scroll(win, &(win->_cury))) { + win->_curx = win->_maxx; + if (!win->_scroll) return (ERR); - win->_flags &= ~_WRAPPED; + scroll(win); + } + win->_curx = 0; + return (OK); +} + +#if USE_WIDEC_SUPPORT +static int waddch_literal(WINDOW *, NCURSES_CH_T); +/* + * Fill the given number of cells with blanks using the current background + * rendition. This saves/restores the current x-position. + */ +static void +fill_cells(WINDOW *win, int count) +{ + NCURSES_CH_T blank = blankchar; + int save_x = win->_curx; + int save_y = win->_cury; + + while (count-- > 0) { + if (waddch_literal(win, blank) == ERR) + break; } + win->_curx = save_x; + win->_cury = save_y; +} #endif +/* + * Build up the bytes for a multibyte character, returning the length when + * complete (a positive number), -1 for error and -2 for incomplete. + */ +#if USE_WIDEC_SUPPORT +NCURSES_EXPORT(int) +_nc_build_wch(WINDOW *win, ARG_CH_T ch) +{ + char *buffer = WINDOW_EXT(win, addch_work); + int len; + int x = win->_curx; + int y = win->_cury; + mbstate_t state; + wchar_t result; + + if ((WINDOW_EXT(win, addch_used) != 0) && + (WINDOW_EXT(win, addch_x) != x || + WINDOW_EXT(win, addch_y) != y)) { + /* discard the incomplete multibyte character */ + WINDOW_EXT(win, addch_used) = 0; + TR(TRACE_VIRTPUT, + ("Alert discarded multibyte on move (%d,%d) -> (%d,%d)", + WINDOW_EXT(win, addch_y), WINDOW_EXT(win, addch_x), + y, x)); + } + WINDOW_EXT(win, addch_x) = x; + WINDOW_EXT(win, addch_y) = y; + + init_mb(state); + buffer[WINDOW_EXT(win, addch_used)] = (char) CharOf(CHDEREF(ch)); + WINDOW_EXT(win, addch_used) += 1; + buffer[WINDOW_EXT(win, addch_used)] = '\0'; + if ((len = mbrtowc(&result, + buffer, + WINDOW_EXT(win, addch_used), &state)) > 0) { + attr_t attrs = AttrOf(CHDEREF(ch)); + if_EXT_COLORS(int pair = GetPair(CHDEREF(ch))); + SetChar(CHDEREF(ch), result, attrs); + if_EXT_COLORS(SetPair(CHDEREF(ch), pair)); + WINDOW_EXT(win, addch_used) = 0; + } else if (len == -1) { + /* + * An error occurred. We could either discard everything, + * or assume that the error was in the previous input. + * Try the latter. + */ + TR(TRACE_VIRTPUT, ("Alert! mbrtowc returns error")); + /* handle this with unctrl() */ + WINDOW_EXT(win, addch_used) = 0; + } + return len; +} +#endif /* USE_WIDEC_SUPPORT */ + +static +#if !USE_WIDEC_SUPPORT /* cannot be inline if it is recursive */ +NCURSES_INLINE +#endif +int +waddch_literal(WINDOW *win, NCURSES_CH_T ch) +{ + int x; + int y; + struct ldat *line; + + x = win->_curx; + y = win->_cury; + + CHECK_POSITION(win, x, y); + ch = render_char(win, ch); - TR(TRACE_VIRTPUT, ("win attr = %s", _traceattr(win->_attrs))); - line = win->_line + win->_cury; + line = win->_line + y; CHANGED_CELL(line, x); + /* + * Build up multibyte characters until we have a wide-character. + */ + if_WIDEC({ + if (WINDOW_EXT(win, addch_used) != 0 || !Charable(ch)) { + int len = _nc_build_wch(win, CHREF(ch)); + + if (len >= -1) { + /* handle EILSEQ */ + if (is8bits(CharOf(ch))) { + const char *s = unctrl((chtype) CharOf(ch)); + if (s[1] != 0) { + return waddstr(win, s); + } + } + if (len == -1) + return waddch(win, ' '); + } else { + return OK; + } + } + }); + + /* + * Non-spacing characters are added to the current cell. + * + * Spacing characters that are wider than one column require some display + * adjustments. + */ + if_WIDEC({ + int len = wcwidth(CharOf(ch)); + int i; + int j; + wchar_t *chars; + + if (len == 0) { /* non-spacing */ + if ((x > 0 && y >= 0) + || (win->_maxx >= 0 && win->_cury >= 1)) { + if (x > 0 && y >= 0) + chars = (win->_line[y].text[x - 1].chars); + else + chars = (win->_line[y - 1].text[win->_maxx].chars); + for (i = 0; i < CCHARW_MAX; ++i) { + if (chars[i] == 0) { + TR(TRACE_VIRTPUT, + ("added non-spacing %d: %x", + x, (int) CharOf(ch))); + chars[i] = CharOf(ch); + break; + } + } + } + goto testwrapping; + } else if (len > 1) { /* multi-column characters */ + /* + * Check if the character will fit on the current line. If it does + * not fit, fill in the remainder of the line with blanks. and + * move to the next line. + */ + if (len > win->_maxx + 1) { + TR(TRACE_VIRTPUT, ("character will not fit")); + return ERR; + } else if (x + len > win->_maxx + 1) { + int count = win->_maxx + 1 - x; + TR(TRACE_VIRTPUT, ("fill %d remaining cells", count)); + fill_cells(win, count); + if (wrap_to_next_line(win) == ERR) + return ERR; + x = win->_curx; + y = win->_cury; + } + /* + * Check for cells which are orphaned by adding this character, set + * those to blanks. + * + * FIXME: this actually could fill j-i cells, more complicated to + * setup though. + */ + for (i = 0; i < len; ++i) { + if (isWidecBase(win->_line[y].text[x + i])) { + break; + } else if (isWidecExt(win->_line[y].text[x + i])) { + for (j = i; x + j <= win->_maxx; ++j) { + if (!isWidecExt(win->_line[y].text[x + j])) { + TR(TRACE_VIRTPUT, ("fill %d orphan cells", j)); + fill_cells(win, j); + break; + } + } + break; + } + } + /* + * Finally, add the cells for this character. + */ + for (i = 0; i < len; ++i) { + NCURSES_CH_T value = ch; + SetWidecExt(value, i); + TR(TRACE_VIRTPUT, ("multicolumn %d:%d (%d,%d)", + i + 1, len, + win->_begy + y, win->_begx + x)); + line->text[x] = value; + CHANGED_CELL(line, x); + ++x; + } + goto testwrapping; + } + }); + + /* + * Single-column characters. + */ line->text[x++] = ch; + /* + * This label is used only for wide-characters. + */ + if_WIDEC( + testwrapping: + ); + + TR(TRACE_VIRTPUT, ("cell (%ld, %ld..%d) = %s", + (long) win->_cury, (long) win->_curx, x - 1, + _tracech_t(CHREF(ch)))); - TR(TRACE_VIRTPUT, ("(%d, %d) = %s", win->_cury, x, _tracechtype(ch))); if (x > win->_maxx) { - /* - * The _WRAPPED flag is useful only for telling an application that - * we've just wrapped the cursor. We don't do anything with this flag - * except set it when wrapping, and clear it whenever we move the - * cursor. If we try to wrap at the lower-right corner of a window, we - * cannot move the cursor (since that wouldn't be legal). So we return - * an error (which is what SVr4 does). Unlike SVr4, we can - * successfully add a character to the lower-right corner (Solaris 2.6 - * does this also, however). - */ - win->_flags |= _WRAPPED; - if (++win->_cury > win->_regbottom) { - win->_cury = win->_regbottom; - win->_curx = win->_maxx; - if (!win->_scroll) - return (ERR); - scroll(win); - } - win->_curx = 0; - return (OK); + return wrap_to_next_line(win); } win->_curx = x; return OK; } -static inline int -waddch_nosync(WINDOW *win, const chtype ch) +static NCURSES_INLINE int +waddch_nosync(WINDOW *win, const NCURSES_CH_T ch) /* the workhorse function -- add a character to the given window */ { - int x, y; - chtype t = 0; - const char *s = 0; + NCURSES_SIZE_T x, y; + chtype t = CharOf(ch); + const char *s = unctrl(t); - if ((ch & A_ALTCHARSET) - || ((t = TextOf(ch)) > 127) - || ((s = unctrl(t))[1] == 0)) + /* + * If we are using the alternate character set, forget about locale. + * Otherwise, if unctrl() returns a single-character or the locale + * claims the code is printable, treat it that way. + */ + if ((AttrOf(ch) & A_ALTCHARSET) + || ( +#if USE_WIDEC_SUPPORT + (SP != 0 && SP->_legacy_coding) && +#endif + s[1] == 0 + ) + || ( + isprint(t) +#if USE_WIDEC_SUPPORT + || ((SP == 0 || !SP->_legacy_coding) && + (WINDOW_EXT(win, addch_used) + || !_nc_is_charable(CharOf(ch)))) +#endif + )) return waddch_literal(win, ch); + /* + * Handle carriage control and other codes that are not printable, or are + * known to expand to more than one character according to unctrl(). + */ x = win->_curx; y = win->_cury; @@ -196,7 +437,8 @@ waddch_nosync(WINDOW *win, const chtype ch) */ if ((!win->_scroll && (y == win->_regbottom)) || (x <= win->_maxx)) { - chtype blank = (' ' | AttrOf(ch)); + NCURSES_CH_T blank = blankchar; + AddAttr(blank, AttrOf(ch)); while (win->_curx < x) { if (waddch_literal(win, blank) == ERR) return (ERR); @@ -205,9 +447,8 @@ waddch_nosync(WINDOW *win, const chtype ch) } else { wclrtoeol(win); win->_flags |= _WRAPPED; - if (++y > win->_regbottom) { + if (newline_forces_scroll(win, &y)) { x = win->_maxx; - y--; if (win->_scroll) { scroll(win); x = 0; @@ -219,8 +460,7 @@ waddch_nosync(WINDOW *win, const chtype ch) break; case '\n': wclrtoeol(win); - if (++y > win->_regbottom) { - y--; + if (newline_forces_scroll(win, &y)) { if (win->_scroll) scroll(win); else @@ -238,9 +478,13 @@ waddch_nosync(WINDOW *win, const chtype ch) win->_flags &= ~_WRAPPED; break; default: - while (*s) - if (waddch_literal(win, (*s++) | AttrOf(ch)) == ERR) + while (*s) { + NCURSES_CH_T sch; + SetChar(sch, *s++, AttrOf(ch)); + if_EXT_COLORS(SetPair(sch, GetPair(ch))); + if (waddch_literal(win, sch) == ERR) return ERR; + } return (OK); } @@ -251,15 +495,14 @@ waddch_nosync(WINDOW *win, const chtype ch) } NCURSES_EXPORT(int) -_nc_waddch_nosync -(WINDOW *win, const chtype c) +_nc_waddch_nosync(WINDOW *win, const NCURSES_CH_T c) /* export copy of waddch_nosync() so the string-put functions can use it */ { return (waddch_nosync(win, c)); } /* - * The versions below call _nc_synhook(). We wanted to avoid this in the + * The versions below call _nc_synchook(). We wanted to avoid this in the * version exported for string puts; they'll call _nc_synchook once at end * of run. */ @@ -267,15 +510,16 @@ _nc_waddch_nosync /* These are actual entry points */ NCURSES_EXPORT(int) -waddch -(WINDOW *win, const chtype ch) +waddch(WINDOW *win, const chtype ch) { int code = ERR; + NCURSES_CH_T wch; + SetChar2(wch, ch); TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("waddch(%p, %s)"), win, _tracechtype(ch))); - if (win && (waddch_nosync(win, ch) != ERR)) { + if (win && (waddch_nosync(win, wch) != ERR)) { _nc_synchook(win); code = OK; } @@ -285,15 +529,16 @@ waddch } NCURSES_EXPORT(int) -wechochar -(WINDOW *win, const chtype ch) +wechochar(WINDOW *win, const chtype ch) { int code = ERR; + NCURSES_CH_T wch; + SetChar2(wch, ch); TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("wechochar(%p, %s)"), win, _tracechtype(ch))); - if (win && (waddch_nosync(win, ch) != ERR)) { + if (win && (waddch_nosync(win, wch) != ERR)) { bool save_immed = win->_immed; win->_immed = TRUE; _nc_synchook(win); diff --git a/lib/libcurses/base/lib_addstr.c b/lib/libcurses/base/lib_addstr.c index 79e9f9eec87..7f038d83e4a 100644 --- a/lib/libcurses/base/lib_addstr.c +++ b/lib/libcurses/base/lib_addstr.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_addstr.c,v 1.4 2001/01/22 18:01:37 millert Exp $ */ +/* $OpenBSD: lib_addstr.c,v 1.5 2010/01/12 23:22:05 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,10 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * * + * Rewritten 2001-2004 to support wide-characters by * + * Sven Verdoolaege * + * Thomas Dickey * ****************************************************************************/ /* @@ -42,27 +46,29 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_addstr.c,v 1.19 2000/12/10 01:24:50 tom Exp $") +MODULE_ID("$Id: lib_addstr.c,v 1.5 2010/01/12 23:22:05 nicm Exp $") NCURSES_EXPORT(int) -waddnstr -(WINDOW *win, const char *const astr, int n) +waddnstr(WINDOW *win, const char *astr, int n) { - unsigned const char *str = (unsigned const char *) astr; + const char *str = astr; int code = ERR; - T((T_CALLED("waddnstr(%p,%s,%d)"), win, _nc_visbuf(astr), n)); + T((T_CALLED("waddnstr(%p,%s,%d)"), win, _nc_visbufn(astr, n), n)); if (win && (str != 0)) { - TR(TRACE_VIRTPUT | TRACE_ATTRS, ("... current %s", _traceattr(win->_attrs))); - TR(TRACE_VIRTPUT, ("str is not null")); + TR(TRACE_VIRTPUT | TRACE_ATTRS, + ("... current %s", _traceattr(WINDOW_ATTRS(win)))); code = OK; if (n < 0) n = (int) strlen(astr); + TR(TRACE_VIRTPUT, ("str is not null, length = %d", n)); while ((n-- > 0) && (*str != '\0')) { - TR(TRACE_VIRTPUT, ("*str = %#x", *str)); - if (_nc_waddch_nosync(win, (chtype) * str++) == ERR) { + NCURSES_CH_T ch; + TR(TRACE_VIRTPUT, ("*str = %#o", UChar(*str))); + SetChar(ch, UChar(*str++), A_NORMAL); + if (_nc_waddch_nosync(win, ch) == ERR) { code = ERR; break; } @@ -74,12 +80,11 @@ waddnstr } NCURSES_EXPORT(int) -waddchnstr -(WINDOW *win, const chtype * const astr, int n) +waddchnstr(WINDOW *win, const chtype *astr, int n) { - NCURSES_SIZE_T y = win->_cury; - NCURSES_SIZE_T x = win->_curx; + NCURSES_SIZE_T y, x; int code = OK; + int i; struct ldat *line; T((T_CALLED("waddchnstr(%p,%p,%d)"), win, astr, n)); @@ -87,6 +92,8 @@ waddchnstr if (!win) returnCode(ERR); + y = win->_cury; + x = win->_curx; if (n < 0) { const chtype *str; n = 0; @@ -99,9 +106,142 @@ waddchnstr returnCode(code); line = &(win->_line[y]); - memcpy(line->text + x, astr, n * sizeof(*astr)); + for (i = 0; i < n && ChCharOf(astr[i]) != '\0'; ++i) { + SetChar2(line->text[i + x], astr[i]); + } CHANGED_RANGE(line, x, x + n - 1); _nc_synchook(win); returnCode(code); } + +#if USE_WIDEC_SUPPORT + +NCURSES_EXPORT(int) +_nc_wchstrlen(const cchar_t *s) +{ + int result = 0; + while (CharOf(s[result]) != L'\0') { + result++; + } + return result; +} + +NCURSES_EXPORT(int) +wadd_wchnstr(WINDOW *win, const cchar_t *astr, int n) +{ + static const NCURSES_CH_T blank = NewChar(BLANK_TEXT); + NCURSES_SIZE_T y; + NCURSES_SIZE_T x; + int code = OK; + struct ldat *line; + int i, j, start, len, end; + + T((T_CALLED("wadd_wchnstr(%p,%s,%d)"), win, _nc_viscbuf(astr, n), n)); + + if (!win) + returnCode(ERR); + + y = win->_cury; + x = win->_curx; + if (n < 0) { + n = _nc_wchstrlen(astr); + } + if (n > win->_maxx - x + 1) + n = win->_maxx - x + 1; + if (n == 0) + returnCode(code); + + line = &(win->_line[y]); + start = x; + end = x + n - 1; + + /* + * Reset orphaned cells of multi-column characters that extend up to the + * new string's location to blanks. + */ + if (x > 0 && isWidecExt(line->text[x])) { + for (i = 0; i <= x; ++i) { + if (!isWidecExt(line->text[x - i])) { + /* must be isWidecBase() */ + start -= i; + while (i > 0) { + line->text[x - i--] = _nc_render(win, blank); + } + break; + } + } + } + + /* + * Copy the new string to the window. + */ + for (i = 0; i < n && CharOf(astr[i]) != L'\0' && x <= win->_maxx; ++i) { + if (isWidecExt(astr[i])) + continue; + + len = wcwidth(CharOf(astr[i])); + + if (x + len - 1 <= win->_maxx) { + line->text[x] = _nc_render(win, astr[i]); + if (len > 1) { + for (j = 0; j < len; ++j) { + if (j != 0) { + line->text[x + j] = line->text[x]; + } + SetWidecExt(line->text[x + j], j); + } + } + x += len; + end += len - 1; + } else { + break; + } + } + + /* + * Set orphaned cells of multi-column characters which lie after the new + * string to blanks. + */ + while (x <= win->_maxx && isWidecExt(line->text[x])) { + line->text[x] = _nc_render(win, blank); + ++end; + ++x; + } + CHANGED_RANGE(line, start, end); + + _nc_synchook(win); + returnCode(code); +} + +NCURSES_EXPORT(int) +waddnwstr(WINDOW *win, const wchar_t *str, int n) +{ + int code = ERR; + + T((T_CALLED("waddnwstr(%p,%s,%d)"), win, _nc_viswbufn(str, n), n)); + + if (win && (str != 0)) { + TR(TRACE_VIRTPUT | TRACE_ATTRS, + ("... current %s", _traceattr(WINDOW_ATTRS(win)))); + code = OK; + if (n < 0) + n = (int) wcslen(str); + + TR(TRACE_VIRTPUT, ("str is not null, length = %d", n)); + while ((n-- > 0) && (*str != L('\0'))) { + NCURSES_CH_T ch; + TR(TRACE_VIRTPUT, ("*str[0] = %#lx", (unsigned long) *str)); + SetChar(ch, *str++, A_NORMAL); + if (wadd_wch(win, &ch) == ERR) { + code = ERR; + break; + } + } + _nc_synchook(win); + } + TR(TRACE_VIRTPUT, ("waddnwstr returns %d", code)); + returnCode(code); +} + +#endif diff --git a/lib/libcurses/base/lib_beep.c b/lib/libcurses/base/lib_beep.c index fa30974bbeb..99d8dd65844 100644 --- a/lib/libcurses/base/lib_beep.c +++ b/lib/libcurses/base/lib_beep.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_beep.c,v 1.3 2001/01/22 18:01:37 millert Exp $ */ +/* $OpenBSD: lib_beep.c,v 1.4 2010/01/12 23:22:05 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2000,2005 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -43,7 +44,7 @@ #include <curses.priv.h> #include <term.h> /* beep, flash */ -MODULE_ID("$From: lib_beep.c,v 1.9 2000/12/10 02:43:26 tom Exp $") +MODULE_ID("$Id: lib_beep.c,v 1.4 2010/01/12 23:22:05 nicm Exp $") /* * beep() @@ -61,7 +62,9 @@ beep(void) T((T_CALLED("beep()"))); /* FIXME: should make sure that we are not in altchar mode */ - if (bell) { + if (cur_term == 0) { + res = ERR; + } else if (bell) { TPUTS_TRACE("bell"); res = putp(bell); _nc_flush(); diff --git a/lib/libcurses/base/lib_bkgd.c b/lib/libcurses/base/lib_bkgd.c index 88a7461eb0e..34adf40fe2c 100644 --- a/lib/libcurses/base/lib_bkgd.c +++ b/lib/libcurses/base/lib_bkgd.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_bkgd.c,v 1.2 2001/01/22 18:01:37 millert Exp $ */ +/* $OpenBSD: lib_bkgd.c,v 1.3 2010/01/12 23:22:05 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2006,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,55 +31,115 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Juergen Pfeifer 1997 * + * and: Sven Verdoolaege 2000 * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ #include <curses.priv.h> -MODULE_ID("$From: lib_bkgd.c,v 1.14 2000/12/10 02:43:26 tom Exp $") +MODULE_ID("$Id: lib_bkgd.c,v 1.3 2010/01/12 23:22:05 nicm Exp $") +/* + * Set the window's background information. + */ +#if USE_WIDEC_SUPPORT NCURSES_EXPORT(void) -wbkgdset(WINDOW *win, chtype ch) +#else +static NCURSES_INLINE void +#endif +wbkgrndset(WINDOW *win, const ARG_CH_T ch) { - T((T_CALLED("wbkgdset(%p,%s)"), win, _tracechtype(ch))); + T((T_CALLED("wbkgdset(%p,%s)"), win, _tracech_t(ch))); if (win) { - chtype off = AttrOf(win->_bkgd); - chtype on = AttrOf(ch); + attr_t off = AttrOf(win->_nc_bkgd); + attr_t on = AttrOf(CHDEREF(ch)); + + toggle_attr_off(WINDOW_ATTRS(win), off); + toggle_attr_on(WINDOW_ATTRS(win), on); - toggle_attr_off(win->_attrs, off); - toggle_attr_on(win->_attrs, on); +#if NCURSES_EXT_COLORS + { + int pair; - if (TextOf(ch) == 0) - ch |= BLANK; - win->_bkgd = ch; + if ((pair = GetPair(win->_nc_bkgd)) != 0) + SET_WINDOW_PAIR(win, 0); + if ((pair = GetPair(CHDEREF(ch))) != 0) + SET_WINDOW_PAIR(win, pair); + } +#endif + + if (CharOf(CHDEREF(ch)) == L('\0')) { + SetChar(win->_nc_bkgd, BLANK_TEXT, AttrOf(CHDEREF(ch))); + if_EXT_COLORS(SetPair(win->_nc_bkgd, GetPair(CHDEREF(ch)))); + } else { + win->_nc_bkgd = CHDEREF(ch); + } +#if USE_WIDEC_SUPPORT + /* + * If we're compiled for wide-character support, _bkgrnd is the + * preferred location for the background information since it stores + * more than _bkgd. Update _bkgd each time we modify _bkgrnd, so the + * macro getbkgd() will work. + */ + { + cchar_t wch; + int tmp; + + wgetbkgrnd(win, &wch); + tmp = _nc_to_char((wint_t) CharOf(wch)); + + win->_bkgd = (((tmp == EOF) ? ' ' : (chtype) tmp) + | (AttrOf(wch) & ALL_BUT_COLOR) + | COLOR_PAIR(GET_WINDOW_PAIR(win))); + } +#endif } returnVoid; } +NCURSES_EXPORT(void) +wbkgdset(WINDOW *win, chtype ch) +{ + NCURSES_CH_T wch; + SetChar2(wch, ch); + wbkgrndset(win, CHREF(wch)); +} + +/* + * Set the window's background information and apply it to each cell. + */ +#if USE_WIDEC_SUPPORT NCURSES_EXPORT(int) -wbkgd(WINDOW *win, const chtype ch) +#else +static NCURSES_INLINE int +#undef wbkgrnd +#endif +wbkgrnd(WINDOW *win, const ARG_CH_T ch) { int code = ERR; int x, y; - chtype new_bkgd = ch; + NCURSES_CH_T new_bkgd = CHDEREF(ch); - T((T_CALLED("wbkgd(%p,%s)"), win, _tracechtype(new_bkgd))); + T((T_CALLED("wbkgd(%p,%s)"), win, _tracech_t(ch))); if (win) { - chtype old_bkgd = getbkgd(win); + NCURSES_CH_T old_bkgrnd; + wgetbkgrnd(win, &old_bkgrnd); - wbkgdset(win, new_bkgd); - wattrset(win, AttrOf(win->_bkgd)); + wbkgrndset(win, CHREF(new_bkgd)); + wattrset(win, AttrOf(win->_nc_bkgd)); for (y = 0; y <= win->_maxy; y++) { for (x = 0; x <= win->_maxx; x++) { - if (win->_line[y].text[x] == old_bkgd) - win->_line[y].text[x] = win->_bkgd; - else - win->_line[y].text[x] = - _nc_render(win, (A_ALTCHARSET & - AttrOf(win->_line[y].text[x])) - | TextOf(win->_line[y].text[x])); + if (CharEq(win->_line[y].text[x], old_bkgrnd)) { + win->_line[y].text[x] = win->_nc_bkgd; + } else { + NCURSES_CH_T wch = win->_line[y].text[x]; + RemAttr(wch, (~(A_ALTCHARSET | A_CHARTEXT))); + win->_line[y].text[x] = _nc_render(win, wch); + } } } touchwin(win); @@ -88,3 +148,11 @@ wbkgd(WINDOW *win, const chtype ch) } returnCode(code); } + +NCURSES_EXPORT(int) +wbkgd(WINDOW *win, chtype ch) +{ + NCURSES_CH_T wch; + SetChar2(wch, ch); + return wbkgrnd(win, CHREF(wch)); +} diff --git a/lib/libcurses/base/lib_box.c b/lib/libcurses/base/lib_box.c index f97ee247c99..6676b3b58a6 100644 --- a/lib/libcurses/base/lib_box.c +++ b/lib/libcurses/base/lib_box.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_box.c,v 1.3 2001/01/22 18:01:37 millert Exp $ */ +/* $OpenBSD: lib_box.c,v 1.4 2010/01/12 23:22:05 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2002,2005 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,8 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * + * and: Sven Verdoolaege 2001 * ****************************************************************************/ /* @@ -42,16 +44,32 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_box.c,v 1.13 2000/12/10 02:43:26 tom Exp $") +MODULE_ID("$Id: lib_box.c,v 1.4 2010/01/12 23:22:05 nicm Exp $") + +#if USE_WIDEC_SUPPORT +static NCURSES_INLINE chtype +_my_render(WINDOW *win, chtype ch) +{ + NCURSES_CH_T wch; + SetChar2(wch, ch); + wch = _nc_render(win, wch); + return CharOf(wch) | AttrOf(wch); +} +#define RENDER_WITH_DEFAULT(ch,def) w ## ch = _my_render(win, (ch == 0) ? def : ch) +#else +#define RENDER_WITH_DEFAULT(ch,def) w ## ch = _nc_render(win, (ch == 0) ? def : ch) +#endif NCURSES_EXPORT(int) -wborder -(WINDOW *win, - chtype ls, chtype rs, chtype ts, chtype bs, - chtype tl, chtype tr, chtype bl, chtype br) +wborder(WINDOW *win, + chtype ls, chtype rs, + chtype ts, chtype bs, + chtype tl, chtype tr, + chtype bl, chtype br) { NCURSES_SIZE_T i; NCURSES_SIZE_T endx, endy; + chtype wls, wrs, wts, wbs, wtl, wtr, wbl, wbr; T((T_CALLED("wborder(%p,%s,%s,%s,%s,%s,%s,%s,%s)"), win, @@ -67,55 +85,45 @@ wborder if (!win) returnCode(ERR); - if (ls == 0) - ls = ACS_VLINE; - if (rs == 0) - rs = ACS_VLINE; - if (ts == 0) - ts = ACS_HLINE; - if (bs == 0) - bs = ACS_HLINE; - if (tl == 0) - tl = ACS_ULCORNER; - if (tr == 0) - tr = ACS_URCORNER; - if (bl == 0) - bl = ACS_LLCORNER; - if (br == 0) - br = ACS_LRCORNER; - - ls = _nc_render(win, ls); - rs = _nc_render(win, rs); - ts = _nc_render(win, ts); - bs = _nc_render(win, bs); - tl = _nc_render(win, tl); - tr = _nc_render(win, tr); - bl = _nc_render(win, bl); - br = _nc_render(win, br); + RENDER_WITH_DEFAULT(ls, ACS_VLINE); + RENDER_WITH_DEFAULT(rs, ACS_VLINE); + RENDER_WITH_DEFAULT(ts, ACS_HLINE); + RENDER_WITH_DEFAULT(bs, ACS_HLINE); + RENDER_WITH_DEFAULT(tl, ACS_ULCORNER); + RENDER_WITH_DEFAULT(tr, ACS_URCORNER); + RENDER_WITH_DEFAULT(bl, ACS_LLCORNER); + RENDER_WITH_DEFAULT(br, ACS_LRCORNER); - T(("using %#lx, %#lx, %#lx, %#lx, %#lx, %#lx, %#lx, %#lx", - ls, rs, ts, bs, tl, tr, bl, br)); + T(("using %s, %s, %s, %s, %s, %s, %s, %s", + _tracechtype2(1, wls), + _tracechtype2(2, wrs), + _tracechtype2(3, wts), + _tracechtype2(4, wbs), + _tracechtype2(5, wtl), + _tracechtype2(6, wtr), + _tracechtype2(7, wbl), + _tracechtype2(8, wbr))); endx = win->_maxx; endy = win->_maxy; for (i = 0; i <= endx; i++) { - win->_line[0].text[i] = ts; - win->_line[endy].text[i] = bs; + SetChar2(win->_line[0].text[i], wts); + SetChar2(win->_line[endy].text[i], wbs); } win->_line[endy].firstchar = win->_line[0].firstchar = 0; win->_line[endy].lastchar = win->_line[0].lastchar = endx; for (i = 0; i <= endy; i++) { - win->_line[i].text[0] = ls; - win->_line[i].text[endx] = rs; + SetChar2(win->_line[i].text[0], wls); + SetChar2(win->_line[i].text[endx], wrs); win->_line[i].firstchar = 0; win->_line[i].lastchar = endx; } - win->_line[0].text[0] = tl; - win->_line[0].text[endx] = tr; - win->_line[endy].text[0] = bl; - win->_line[endy].text[endx] = br; + SetChar2(win->_line[0].text[0], wtl); + SetChar2(win->_line[0].text[endx], wtr); + SetChar2(win->_line[endy].text[0], wbl); + SetChar2(win->_line[endy].text[endx], wbr); _nc_synchook(win); returnCode(OK); diff --git a/lib/libcurses/base/lib_chgat.c b/lib/libcurses/base/lib_chgat.c index d48c9aba297..5762785c207 100644 --- a/lib/libcurses/base/lib_chgat.c +++ b/lib/libcurses/base/lib_chgat.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_chgat.c,v 1.2 2001/01/22 18:01:37 millert Exp $ */ +/* $OpenBSD: lib_chgat.c,v 1.3 2010/01/12 23:22:05 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,8 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Sven Verdoolaege 2001 * + * and: Thomas E. Dickey 2005 * ****************************************************************************/ /* @@ -42,22 +44,25 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_chgat.c,v 1.4 2000/12/10 02:43:26 tom Exp $") +MODULE_ID("$Id: lib_chgat.c,v 1.3 2010/01/12 23:22:05 nicm Exp $") NCURSES_EXPORT(int) -wchgat -(WINDOW *win, int n, attr_t attr, short color, const void *opts GCC_UNUSED) +wchgat(WINDOW *win, int n, attr_t attr, short color, const void *opts GCC_UNUSED) { int i; T((T_CALLED("wchgat(%p,%d,%s,%d)"), win, n, _traceattr(attr), color)); if (win) { + struct ldat *line = &(win->_line[win->_cury]); + toggle_attr_on(attr, COLOR_PAIR(color)); - for (i = win->_curx; i <= win->_maxx && (n == -1 || (n-- > 0)); i++) - win->_line[win->_cury].text[i] - = TextOf(win->_line[win->_cury].text[i]) | attr; + for (i = win->_curx; i <= win->_maxx && (n == -1 || (n-- > 0)); i++) { + SetAttr(line->text[i], attr); + SetPair(line->text[i], color); + CHANGED_CELL(line, i); + } returnCode(OK); } else diff --git a/lib/libcurses/base/lib_clear.c b/lib/libcurses/base/lib_clear.c index 6cb0a2f7929..10dab985fbc 100644 --- a/lib/libcurses/base/lib_clear.c +++ b/lib/libcurses/base/lib_clear.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_clear.c,v 1.2 2001/01/22 18:01:38 millert Exp $ */ +/* $OpenBSD: lib_clear.c,v 1.3 2010/01/12 23:22:05 nicm Exp $ */ /**************************************************************************** * Copyright (c) 1998,2000 Free Software Foundation, Inc. * @@ -42,7 +42,7 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_clear.c,v 1.7 2000/12/10 02:43:26 tom Exp $") +MODULE_ID("$Id: lib_clear.c,v 1.3 2010/01/12 23:22:05 nicm Exp $") NCURSES_EXPORT(int) wclear(WINDOW *win) diff --git a/lib/libcurses/base/lib_clearok.c b/lib/libcurses/base/lib_clearok.c index ccf11335497..d0746956fa6 100644 --- a/lib/libcurses/base/lib_clearok.c +++ b/lib/libcurses/base/lib_clearok.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_clearok.c,v 1.2 2001/01/22 18:01:38 millert Exp $ */ +/* $OpenBSD: lib_clearok.c,v 1.3 2010/01/12 23:22:05 nicm Exp $ */ /**************************************************************************** * Copyright (c) 1998,2000 Free Software Foundation, Inc. * @@ -42,7 +42,7 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_clearok.c,v 1.4 2000/12/10 02:43:26 tom Exp $") +MODULE_ID("$Id: lib_clearok.c,v 1.3 2010/01/12 23:22:05 nicm Exp $") NCURSES_EXPORT(int) clearok(WINDOW *win, bool flag) diff --git a/lib/libcurses/base/lib_clrbot.c b/lib/libcurses/base/lib_clrbot.c index c947b668613..f0b86d921f1 100644 --- a/lib/libcurses/base/lib_clrbot.c +++ b/lib/libcurses/base/lib_clrbot.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_clrbot.c,v 1.3 2001/01/22 18:01:38 millert Exp $ */ +/* $OpenBSD: lib_clrbot.c,v 1.4 2010/01/12 23:22:05 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2001,2006 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -42,7 +42,7 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_clrbot.c,v 1.17 2000/12/10 02:43:26 tom Exp $") +MODULE_ID("$Id: lib_clrbot.c,v 1.4 2010/01/12 23:22:05 nicm Exp $") NCURSES_EXPORT(int) wclrtobot(WINDOW *win) @@ -54,15 +54,15 @@ wclrtobot(WINDOW *win) if (win) { NCURSES_SIZE_T y; NCURSES_SIZE_T startx = win->_curx; - chtype blank = _nc_background(win); + NCURSES_CH_T blank = win->_nc_bkgd; - T(("clearing from y = %d to y = %d with maxx = %d", - win->_cury, win->_maxy, win->_maxx)); + T(("clearing from y = %ld to y = %ld with maxx = %ld", + (long) win->_cury, (long) win->_maxy, (long) win->_maxx)); for (y = win->_cury; y <= win->_maxy; y++) { struct ldat *line = &(win->_line[y]); - chtype *ptr = &(line->text[startx]); - chtype *end = &(line->text[win->_maxx]); + NCURSES_CH_T *ptr = &(line->text[startx]); + NCURSES_CH_T *end = &(line->text[win->_maxx]); CHANGED_TO_EOL(line, startx, win->_maxx); diff --git a/lib/libcurses/base/lib_clreol.c b/lib/libcurses/base/lib_clreol.c index 7c00cd16d5b..2b9a48bf417 100644 --- a/lib/libcurses/base/lib_clreol.c +++ b/lib/libcurses/base/lib_clreol.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_clreol.c,v 1.3 2001/01/22 18:01:38 millert Exp $ */ +/* $OpenBSD: lib_clreol.c,v 1.4 2010/01/12 23:22:05 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -42,7 +42,7 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_clreol.c,v 1.19 2000/12/10 02:43:26 tom Exp $") +MODULE_ID("$Id: lib_clreol.c,v 1.4 2010/01/12 23:22:05 nicm Exp $") NCURSES_EXPORT(int) wclrtoeol(WINDOW *win) @@ -52,8 +52,8 @@ wclrtoeol(WINDOW *win) T((T_CALLED("wclrtoeol(%p)"), win)); if (win) { - chtype blank; - chtype *ptr, *end; + NCURSES_CH_T blank; + NCURSES_CH_T *ptr, *end; struct ldat *line; NCURSES_SIZE_T y = win->_cury; NCURSES_SIZE_T x = win->_curx; @@ -76,7 +76,7 @@ wclrtoeol(WINDOW *win) || x > win->_maxx) returnCode(ERR); - blank = _nc_background(win); + blank = win->_nc_bkgd; line = &win->_line[y]; CHANGED_TO_EOL(line, x, win->_maxx); diff --git a/lib/libcurses/base/lib_color.c b/lib/libcurses/base/lib_color.c index 06b88fe43e5..d1c4ce7f0d5 100644 --- a/lib/libcurses/base/lib_color.c +++ b/lib/libcurses/base/lib_color.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_color.c,v 1.10 2001/01/22 18:01:38 millert Exp $ */ +/* $OpenBSD: lib_color.c,v 1.11 2010/01/12 23:22:05 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* lib_color.c @@ -43,17 +44,37 @@ #include <term.h> #include <tic.h> -MODULE_ID("$From: lib_color.c,v 1.55 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_color.c,v 1.11 2010/01/12 23:22:05 nicm Exp $") /* * These should be screen structure members. They need to be globals for * historical reasons. So we assign them in start_color() and also in * set_term()'s screen-switching logic. */ -NCURSES_EXPORT_VAR(int) -COLOR_PAIRS = 0; -NCURSES_EXPORT_VAR(int) -COLORS = 0; +#if USE_REENTRANT +NCURSES_EXPORT(int) +NCURSES_PUBLIC_VAR(COLOR_PAIRS) (void) +{ + return SP ? SP->_pair_count : -1; +} +NCURSES_EXPORT(int) +NCURSES_PUBLIC_VAR(COLORS) (void) +{ + return SP ? SP->_color_count : -1; +} +#else +NCURSES_EXPORT_VAR(int) COLOR_PAIRS = 0; +NCURSES_EXPORT_VAR(int) COLORS = 0; +#endif + +#define DATA(r,g,b) {r,g,b, 0,0,0, 0} + +#define TYPE_CALLOC(type,elts) typeCalloc(type, (unsigned)(elts)) + +#define MAX_PALETTE 8 + +#define OkColorHi(n) (((n) < COLORS) && ((n) < max_colors)) +#define InPalette(n) ((n) >= 0 && (n) < MAX_PALETTE) /* * Given a RGB range of 0..1000, we'll normally set the individual values @@ -65,27 +86,27 @@ COLORS = 0; static const color_t cga_palette[] = { /* R G B */ - {RGB_OFF, RGB_OFF, RGB_OFF}, /* COLOR_BLACK */ - {RGB_ON, RGB_OFF, RGB_OFF}, /* COLOR_RED */ - {RGB_OFF, RGB_ON, RGB_OFF}, /* COLOR_GREEN */ - {RGB_ON, RGB_ON, RGB_OFF}, /* COLOR_YELLOW */ - {RGB_OFF, RGB_OFF, RGB_ON}, /* COLOR_BLUE */ - {RGB_ON, RGB_OFF, RGB_ON}, /* COLOR_MAGENTA */ - {RGB_OFF, RGB_ON, RGB_ON}, /* COLOR_CYAN */ - {RGB_ON, RGB_ON, RGB_ON}, /* COLOR_WHITE */ + DATA(RGB_OFF, RGB_OFF, RGB_OFF), /* COLOR_BLACK */ + DATA(RGB_ON, RGB_OFF, RGB_OFF), /* COLOR_RED */ + DATA(RGB_OFF, RGB_ON, RGB_OFF), /* COLOR_GREEN */ + DATA(RGB_ON, RGB_ON, RGB_OFF), /* COLOR_YELLOW */ + DATA(RGB_OFF, RGB_OFF, RGB_ON), /* COLOR_BLUE */ + DATA(RGB_ON, RGB_OFF, RGB_ON), /* COLOR_MAGENTA */ + DATA(RGB_OFF, RGB_ON, RGB_ON), /* COLOR_CYAN */ + DATA(RGB_ON, RGB_ON, RGB_ON), /* COLOR_WHITE */ }; static const color_t hls_palette[] = { - /* H L S */ - { 0, 0, 0}, /* COLOR_BLACK */ - { 120, 50, 100}, /* COLOR_RED */ - { 240, 50, 100}, /* COLOR_GREEN */ - { 180, 50, 100}, /* COLOR_YELLOW */ - { 330, 50, 100}, /* COLOR_BLUE */ - { 60, 50, 100}, /* COLOR_MAGENTA */ - { 300, 50, 100}, /* COLOR_CYAN */ - { 0, 50, 100}, /* COLOR_WHITE */ + /* H L S */ + DATA( 0, 0, 0), /* COLOR_BLACK */ + DATA( 120, 50, 100), /* COLOR_RED */ + DATA( 240, 50, 100), /* COLOR_GREEN */ + DATA( 180, 50, 100), /* COLOR_YELLOW */ + DATA( 330, 50, 100), /* COLOR_BLUE */ + DATA( 60, 50, 100), /* COLOR_MAGENTA */ + DATA( 300, 50, 100), /* COLOR_CYAN */ + DATA( 0, 50, 100), /* COLOR_WHITE */ }; /* *INDENT-ON* */ @@ -94,8 +115,8 @@ static const color_t hls_palette[] = * These are called from _nc_do_color(), which in turn is called from * vidattr - so we have to assume that SP may be null. */ - static int - default_fg(void) +static int +default_fg(void) { return (SP != 0) ? SP->_default_fg : COLOR_WHITE; } @@ -115,8 +136,8 @@ default_bg(void) * to maintain compatibility with a pre-ANSI scheme. The same scheme is * also used in the FreeBSD syscons. */ - static int - toggled_colors(int c) +static int +toggled_colors(int c) { if (c < 16) { static const int table[] = @@ -132,10 +153,10 @@ set_background_color(int bg, int (*outc) (int)) { if (set_a_background) { TPUTS_TRACE("set_a_background"); - tputs(tparm(set_a_background, bg), 1, outc); + tputs(TPARM_1(set_a_background, bg), 1, outc); } else { TPUTS_TRACE("set_background"); - tputs(tparm(set_background, toggled_colors(bg)), 1, outc); + tputs(TPARM_1(set_background, toggled_colors(bg)), 1, outc); } } @@ -144,62 +165,25 @@ set_foreground_color(int fg, int (*outc) (int)) { if (set_a_foreground) { TPUTS_TRACE("set_a_foreground"); - tputs(tparm(set_a_foreground, fg), 1, outc); + tputs(TPARM_1(set_a_foreground, fg), 1, outc); } else { TPUTS_TRACE("set_foreground"); - tputs(tparm(set_foreground, toggled_colors(fg)), 1, outc); + tputs(TPARM_1(set_foreground, toggled_colors(fg)), 1, outc); } } -static bool -set_original_colors(void) -{ - if (orig_pair != 0) { - TPUTS_TRACE("orig_pair"); - putp(orig_pair); - return TRUE; - } else if (orig_colors != NULL) { - TPUTS_TRACE("orig_colors"); - putp(orig_colors); - return TRUE; - } - return FALSE; -} - -NCURSES_EXPORT(int) -start_color(void) +static void +init_color_table(void) { - int n; const color_t *tp; + int n; - T((T_CALLED("start_color()"))); - - if (set_original_colors() != TRUE) { - set_foreground_color(default_fg(), _nc_outch); - set_background_color(default_bg(), _nc_outch); - } - - if (VALID_NUMERIC(max_pairs)) - COLOR_PAIRS = SP->_pair_count = max_pairs; - else - returnCode(ERR); - if ((SP->_color_pairs = typeCalloc(unsigned short, max_pairs)) == 0) - returnCode(ERR); - SP->_color_pairs[0] = PAIR_OF(default_fg(), default_bg()); - if (VALID_NUMERIC(max_colors)) - COLORS = SP->_color_count = max_colors; - else - returnCode(ERR); - SP->_coloron = 1; - - if ((SP->_color_table = typeMalloc(color_t, COLORS)) == 0) - returnCode(ERR); tp = (hue_lightness_saturation) ? hls_palette : cga_palette; for (n = 0; n < COLORS; n++) { - if (n < 8) { + if (InPalette(n)) { SP->_color_table[n] = tp[n]; } else { - SP->_color_table[n] = tp[n % 8]; + SP->_color_table[n] = tp[n % MAX_PALETTE]; if (hue_lightness_saturation) { SP->_color_table[n].green = 100; } else { @@ -212,10 +196,95 @@ start_color(void) } } } +} - T(("started color: COLORS = %d, COLOR_PAIRS = %d", COLORS, COLOR_PAIRS)); +/* + * Reset the color pair, e.g., to whatever color pair 0 is. + */ +static bool +reset_color_pair(void) +{ + bool result = FALSE; - returnCode(OK); + if (orig_pair != 0) { + TPUTS_TRACE("orig_pair"); + putp(orig_pair); + result = TRUE; + } + return result; +} + +/* + * Reset color pairs and definitions. Actually we do both more to accommodate + * badly-written terminal descriptions than for the relatively rare case where + * someone has changed the color definitions. + */ +bool +_nc_reset_colors(void) +{ + int result = FALSE; + + T((T_CALLED("_nc_reset_colors()"))); + if (SP->_color_defs > 0) + SP->_color_defs = -(SP->_color_defs); + + if (reset_color_pair()) + result = TRUE; + if (orig_colors != 0) { + TPUTS_TRACE("orig_colors"); + putp(orig_colors); + result = TRUE; + } + returnBool(result); +} + +NCURSES_EXPORT(int) +start_color(void) +{ + int result = ERR; + + T((T_CALLED("start_color()"))); + + if (SP == 0) { + result = ERR; + } else if (SP->_coloron) { + result = OK; + } else { + + if (reset_color_pair() != TRUE) { + set_foreground_color(default_fg(), _nc_outch); + set_background_color(default_bg(), _nc_outch); + } + + if (max_pairs > 0 && max_colors > 0) { + SP->_pair_count = max_pairs; + SP->_color_count = max_colors; +#if !USE_REENTRANT + COLOR_PAIRS = max_pairs; + COLORS = max_colors; +#endif + + if ((SP->_color_pairs = TYPE_CALLOC(colorpair_t, + max_pairs)) != 0) { + if ((SP->_color_table = TYPE_CALLOC(color_t, + max_colors)) != 0) { + SP->_color_pairs[0] = PAIR_OF(default_fg(), default_bg()); + init_color_table(); + + T(("started color: COLORS = %d, COLOR_PAIRS = %d", + COLORS, COLOR_PAIRS)); + + SP->_coloron = 1; + result = OK; + } else if (SP->_color_pairs != 0) { + FreeAndNull(SP->_color_pairs); + } + } + } else { + result = OK; + } + } + returnCode(result); } /* This function was originally written by Daniel Weaver <danw@znyx.com> */ @@ -261,30 +330,29 @@ rgb2hls(short r, short g, short b, short *h, short *l, short *s) * values. */ NCURSES_EXPORT(int) -init_pair -(short pair, short f, short b) +init_pair(short pair, short f, short b) { - unsigned result; + colorpair_t result; T((T_CALLED("init_pair(%d,%d,%d)"), pair, f, b)); - if ((pair < 0) || (pair >= COLOR_PAIRS)) + if ((pair < 0) || (pair >= COLOR_PAIRS) || SP == 0 || !SP->_coloron) returnCode(ERR); #if NCURSES_EXT_FUNCS if (SP->_default_color) { if (f < 0) - f = C_MASK; + f = COLOR_DEFAULT; if (b < 0) - b = C_MASK; - if (f >= COLORS && f != C_MASK) + b = COLOR_DEFAULT; + if (!OkColorHi(f) && !isDefaultColor(f)) returnCode(ERR); - if (b >= COLORS && b != C_MASK) + if (!OkColorHi(b) && !isDefaultColor(b)) returnCode(ERR); } else #endif { - if ((f < 0) || (f >= COLORS) - || (b < 0) || (b >= COLORS) + if ((f < 0) || !OkColorHi(f) + || (b < 0) || !OkColorHi(b) || (pair < 1)) returnCode(ERR); } @@ -298,16 +366,15 @@ init_pair if (SP->_color_pairs[pair] != 0 && SP->_color_pairs[pair] != result) { int y, x; - attr_t z = COLOR_PAIR(pair); for (y = 0; y <= curscr->_maxy; y++) { struct ldat *ptr = &(curscr->_line[y]); bool changed = FALSE; for (x = 0; x <= curscr->_maxx; x++) { - if ((ptr->text[x] & A_COLOR) == z) { + if (GetPair(ptr->text[x]) == pair) { /* Set the old cell to zero to ensure it will be updated on the next doupdate() */ - ptr->text[x] = 0; + SetChar(ptr->text[x], 0, 0); CHANGED_CELL(ptr, x); changed = TRUE; } @@ -317,59 +384,65 @@ init_pair } } SP->_color_pairs[pair] = result; - if ((int) (SP->_current_attr & A_COLOR) == COLOR_PAIR(pair)) - SP->_current_attr |= A_COLOR; /* force attribute update */ + if (GET_SCREEN_PAIR(SP) == pair) + SET_SCREEN_PAIR(SP, (chtype) (~0)); /* force attribute update */ - if (initialize_pair) { + if (initialize_pair && InPalette(f) && InPalette(b)) { const color_t *tp = hue_lightness_saturation ? hls_palette : cga_palette; - T(("initializing pair: pair = %d, fg=(%d,%d,%d), bg=(%d,%d,%d)", - pair, - tp[f].red, tp[f].green, tp[f].blue, - tp[b].red, tp[b].green, tp[b].blue)); - - if (initialize_pair) { - TPUTS_TRACE("initialize_pair"); - putp(tparm(initialize_pair, - pair, - tp[f].red, tp[f].green, tp[f].blue, - tp[b].red, tp[b].green, tp[b].blue)); - } + TR(TRACE_ATTRS, + ("initializing pair: pair = %d, fg=(%d,%d,%d), bg=(%d,%d,%d)", + pair, + tp[f].red, tp[f].green, tp[f].blue, + tp[b].red, tp[b].green, tp[b].blue)); + + TPUTS_TRACE("initialize_pair"); + putp(TPARM_7(initialize_pair, + pair, + tp[f].red, tp[f].green, tp[f].blue, + tp[b].red, tp[b].green, tp[b].blue)); } returnCode(OK); } +#define okRGB(n) ((n) >= 0 && (n) <= 1000) + NCURSES_EXPORT(int) -init_color -(short color, short r, short g, short b) +init_color(short color, short r, short g, short b) { - T((T_CALLED("init_color(%d,%d,%d,%d)"), color, r, g, b)); - - if (initialize_color == NULL) - returnCode(ERR); + int result = ERR; - if (color < 0 || color >= COLORS) - returnCode(ERR); - if (r < 0 || r > 1000 || g < 0 || g > 1000 || b < 0 || b > 1000) - returnCode(ERR); + T((T_CALLED("init_color(%d,%d,%d,%d)"), color, r, g, b)); - if (hue_lightness_saturation) - rgb2hls(r, g, b, - &SP->_color_table[color].red, - &SP->_color_table[color].green, - &SP->_color_table[color].blue); - else { - SP->_color_table[color].red = r; - SP->_color_table[color].green = g; - SP->_color_table[color].blue = b; - } + if (initialize_color != NULL + && SP != 0 + && SP->_coloron + && (color >= 0 && OkColorHi(color)) + && (okRGB(r) && okRGB(g) && okRGB(b))) { + + SP->_color_table[color].init = 1; + SP->_color_table[color].r = r; + SP->_color_table[color].g = g; + SP->_color_table[color].b = b; + + if (hue_lightness_saturation) { + rgb2hls(r, g, b, + &SP->_color_table[color].red, + &SP->_color_table[color].green, + &SP->_color_table[color].blue); + } else { + SP->_color_table[color].red = r; + SP->_color_table[color].green = g; + SP->_color_table[color].blue = b; + } - if (initialize_color) { TPUTS_TRACE("initialize_color"); - putp(tparm(initialize_color, color, r, g, b)); + putp(TPARM_4(initialize_color, color, r, g, b)); + SP->_color_defs = max(color + 1, SP->_color_defs); + result = OK; } - returnCode(OK); + returnCode(result); } NCURSES_EXPORT(bool) @@ -392,43 +465,68 @@ has_colors(void) } NCURSES_EXPORT(int) -color_content -(short color, short *r, short *g, short *b) +color_content(short color, short *r, short *g, short *b) { - T((T_CALLED("color_content(%d,%p,%p,%p)"), color, r, g, b)); - if (color < 0 || color >= COLORS) - returnCode(ERR); + int result; - if (r) - *r = SP->_color_table[color].red; - if (g) - *g = SP->_color_table[color].green; - if (b) - *b = SP->_color_table[color].blue; - returnCode(OK); + T((T_CALLED("color_content(%d,%p,%p,%p)"), color, r, g, b)); + if (color < 0 || !OkColorHi(color) || SP == 0 || !SP->_coloron) { + result = ERR; + } else { + NCURSES_COLOR_T c_r = SP->_color_table[color].red; + NCURSES_COLOR_T c_g = SP->_color_table[color].green; + NCURSES_COLOR_T c_b = SP->_color_table[color].blue; + + if (r) + *r = c_r; + if (g) + *g = c_g; + if (b) + *b = c_b; + + TR(TRACE_ATTRS, ("...color_content(%d,%d,%d,%d)", + color, c_r, c_g, c_b)); + result = OK; + } + returnCode(result); } NCURSES_EXPORT(int) -pair_content -(short pair, short *f, short *b) +pair_content(short pair, short *f, short *b) { + int result; + T((T_CALLED("pair_content(%d,%p,%p)"), pair, f, b)); - if ((pair < 0) || (pair >= COLOR_PAIRS)) - returnCode(ERR); - if (f) - *f = ((SP->_color_pairs[pair] >> C_SHIFT) & C_MASK); - if (b) - *b = (SP->_color_pairs[pair] & C_MASK); + if ((pair < 0) || (pair >= COLOR_PAIRS) || SP == 0 || !SP->_coloron) { + result = ERR; + } else { + NCURSES_COLOR_T fg = ((SP->_color_pairs[pair] >> C_SHIFT) & C_MASK); + NCURSES_COLOR_T bg = (SP->_color_pairs[pair] & C_MASK); - returnCode(OK); +#if NCURSES_EXT_FUNCS + if (fg == COLOR_DEFAULT) + fg = -1; + if (bg == COLOR_DEFAULT) + bg = -1; +#endif + + if (f) + *f = fg; + if (b) + *b = bg; + + TR(TRACE_ATTRS, ("...pair_content(%d,%d,%d)", pair, fg, bg)); + result = OK; + } + returnCode(result); } NCURSES_EXPORT(void) -_nc_do_color -(int old_pair, int pair, bool reverse, int (*outc) (int)) +_nc_do_color(short old_pair, short pair, bool reverse, int (*outc) (int)) { - NCURSES_COLOR_T fg = C_MASK, bg = C_MASK; + NCURSES_COLOR_T fg = COLOR_DEFAULT; + NCURSES_COLOR_T bg = COLOR_DEFAULT; NCURSES_COLOR_T old_fg, old_bg; if (pair < 0 || pair >= COLOR_PAIRS) { @@ -436,41 +534,46 @@ _nc_do_color } else if (pair != 0) { if (set_color_pair) { TPUTS_TRACE("set_color_pair"); - tputs(tparm(set_color_pair, pair), 1, outc); + tputs(TPARM_1(set_color_pair, pair), 1, outc); return; } else if (SP != 0) { - pair_content(pair, &fg, &bg); + pair_content((short) pair, &fg, &bg); } } - if (old_pair >= 0 && SP != 0) { - pair_content(old_pair, &old_fg, &old_bg); - if ((fg == C_MASK && old_fg != C_MASK) - || (bg == C_MASK && old_bg != C_MASK)) { + if (old_pair >= 0 + && SP != 0 + && pair_content(old_pair, &old_fg, &old_bg) != ERR) { + if ((isDefaultColor(fg) && !isDefaultColor(old_fg)) + || (isDefaultColor(bg) && !isDefaultColor(old_bg))) { #if NCURSES_EXT_FUNCS /* * A minor optimization - but extension. If "AX" is specified in * the terminal description, treat it as screen's indicator of ECMA * SGR 39 and SGR 49, and assume the two sequences are independent. */ - if (SP->_has_sgr_39_49 && old_bg == C_MASK && old_fg != C_MASK) { + if (SP->_has_sgr_39_49 + && isDefaultColor(old_bg) + && !isDefaultColor(old_fg)) { tputs("\033[39m", 1, outc); - } else if (SP->_has_sgr_39_49 && old_fg == C_MASK && old_bg != C_MASK) { + } else if (SP->_has_sgr_39_49 + && isDefaultColor(old_fg) + && !isDefaultColor(old_bg)) { tputs("\033[49m", 1, outc); } else #endif - set_original_colors(); + reset_color_pair(); } } else { - set_original_colors(); + reset_color_pair(); if (old_pair < 0) return; } #if NCURSES_EXT_FUNCS - if (fg == C_MASK) + if (isDefaultColor(fg)) fg = default_fg(); - if (bg == C_MASK) + if (isDefaultColor(bg)) bg = default_bg(); #endif @@ -483,10 +586,10 @@ _nc_do_color TR(TRACE_ATTRS, ("setting colors: pair = %d, fg = %d, bg = %d", pair, fg, bg)); - if (fg != C_MASK) { + if (!isDefaultColor(fg)) { set_foreground_color(fg, outc); } - if (bg != C_MASK) { + if (!isDefaultColor(bg)) { set_background_color(bg, outc); } } diff --git a/lib/libcurses/base/lib_colorset.c b/lib/libcurses/base/lib_colorset.c index 73cd69e609c..039587de146 100644 --- a/lib/libcurses/base/lib_colorset.c +++ b/lib/libcurses/base/lib_colorset.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_colorset.c,v 1.4 2001/01/22 18:01:38 millert Exp $ */ +/* $OpenBSD: lib_colorset.c,v 1.5 2010/01/12 23:22:05 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2003,2005 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,7 +29,8 @@ ****************************************************************************/ /**************************************************************************** - * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1998 * + * Author: Juergen Pfeifer, 1998 * + * and: Thomas E. Dickey, 2005 * ****************************************************************************/ /* @@ -42,19 +43,19 @@ #include <curses.priv.h> #include <ctype.h> -MODULE_ID("$From: lib_colorset.c,v 1.7 2000/12/10 01:24:50 tom Exp $") +MODULE_ID("$Id: lib_colorset.c,v 1.5 2010/01/12 23:22:05 nicm Exp $") NCURSES_EXPORT(int) -wcolor_set -(WINDOW *win, short color_pair_number, void *opts) +wcolor_set(WINDOW *win, short color_pair_number, void *opts) { T((T_CALLED("wcolor_set(%p,%d)"), win, color_pair_number)); if (win && !opts && (color_pair_number >= 0) && (color_pair_number < COLOR_PAIRS)) { - TR(TRACE_ATTRS, ("... current %ld", (long) PAIR_NUMBER(win->_attrs))); - toggle_attr_on(win->_attrs, COLOR_PAIR(color_pair_number)); + TR(TRACE_ATTRS, ("... current %ld", (long) GET_WINDOW_PAIR(win))); + SET_WINDOW_PAIR(win, color_pair_number); + if_EXT_COLORS(win->_color = color_pair_number); returnCode(OK); } else returnCode(ERR); diff --git a/lib/libcurses/base/lib_delch.c b/lib/libcurses/base/lib_delch.c index d07198c60a4..42efa5cabfe 100644 --- a/lib/libcurses/base/lib_delch.c +++ b/lib/libcurses/base/lib_delch.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_delch.c,v 1.2 2001/01/22 18:01:38 millert Exp $ */ +/* $OpenBSD: lib_delch.c,v 1.3 2010/01/12 23:22:05 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -42,7 +42,7 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_delch.c,v 1.10 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_delch.c,v 1.3 2010/01/12 23:22:05 nicm Exp $") NCURSES_EXPORT(int) wdelch(WINDOW *win) @@ -52,11 +52,11 @@ wdelch(WINDOW *win) T((T_CALLED("wdelch(%p)"), win)); if (win) { - chtype blank = _nc_background(win); + NCURSES_CH_T blank = win->_nc_bkgd; struct ldat *line = &(win->_line[win->_cury]); - chtype *end = &(line->text[win->_maxx]); - chtype *temp2 = &(line->text[win->_curx + 1]); - chtype *temp1 = temp2 - 1; + NCURSES_CH_T *end = &(line->text[win->_maxx]); + NCURSES_CH_T *temp2 = &(line->text[win->_curx + 1]); + NCURSES_CH_T *temp1 = temp2 - 1; CHANGED_TO_EOL(line, win->_curx, win->_maxx); while (temp1 < end) diff --git a/lib/libcurses/base/lib_delwin.c b/lib/libcurses/base/lib_delwin.c index 5358ae94f00..15a52a36953 100644 --- a/lib/libcurses/base/lib_delwin.c +++ b/lib/libcurses/base/lib_delwin.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_delwin.c,v 1.2 2001/01/22 18:01:38 millert Exp $ */ +/* $OpenBSD: lib_delwin.c,v 1.3 2010/01/12 23:22:05 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -42,7 +42,7 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_delwin.c,v 1.12 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_delwin.c,v 1.3 2010/01/12 23:22:05 nicm Exp $") static bool cannot_delete(WINDOW *win) @@ -50,11 +50,11 @@ cannot_delete(WINDOW *win) WINDOWLIST *p; bool result = TRUE; - for (p = _nc_windows; p != 0; p = p->next) { - if (p->win == win) { + for (each_window(p)) { + if (&(p->win) == win) { result = FALSE; - } else if ((p->win->_flags & _SUBWIN) != 0 - && p->win->_parent == win) { + } else if ((p->win._flags & _SUBWIN) != 0 + && p->win._parent == win) { result = TRUE; break; } @@ -65,16 +65,24 @@ cannot_delete(WINDOW *win) NCURSES_EXPORT(int) delwin(WINDOW *win) { + int result = ERR; + T((T_CALLED("delwin(%p)"), win)); - if (win == 0 - || cannot_delete(win)) - returnCode(ERR); + if (_nc_try_global(curses) == 0) { + if (win == 0 + || cannot_delete(win)) { + result = ERR; + } else { - if (win->_flags & _SUBWIN) - touchwin(win->_parent); - else if (curscr != 0) - touchwin(curscr); + if (win->_flags & _SUBWIN) + touchwin(win->_parent); + else if (curscr != 0) + touchwin(curscr); - returnCode(_nc_freewin(win)); + result = _nc_freewin(win); + } + _nc_unlock_global(curses); + } + returnCode(result); } diff --git a/lib/libcurses/base/lib_dft_fgbg.c b/lib/libcurses/base/lib_dft_fgbg.c index 45aeac0c4dd..d051dcd414d 100644 --- a/lib/libcurses/base/lib_dft_fgbg.c +++ b/lib/libcurses/base/lib_dft_fgbg.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_dft_fgbg.c,v 1.7 2001/01/22 18:01:39 millert Exp $ */ +/* $OpenBSD: lib_dft_fgbg.c,v 1.8 2010/01/12 23:22:05 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2004,2005 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,13 +29,13 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey <dickey@clark.net> 1997,1999 * + * Author: Thomas E. Dickey * ****************************************************************************/ #include <curses.priv.h> #include <term.h> -MODULE_ID("$From: lib_dft_fgbg.c,v 1.15 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_dft_fgbg.c,v 1.8 2010/01/12 23:22:05 nicm Exp $") /* * Modify the behavior of color-pair 0 so that the library doesn't assume that @@ -45,7 +45,7 @@ NCURSES_EXPORT(int) use_default_colors(void) { T((T_CALLED("use_default_colors()"))); - returnCode(assume_default_colors(C_MASK, C_MASK)); + returnCode(assume_default_colors(-1, -1)); } /* @@ -63,11 +63,15 @@ assume_default_colors(int fg, int bg) if (initialize_pair) /* don't know how to handle this */ returnCode(ERR); - SP->_default_color = (fg < 0 || fg == C_MASK) || (bg < 0 || bg == C_MASK); + SP->_default_color = isDefaultColor(fg) || isDefaultColor(bg); SP->_has_sgr_39_49 = (tigetflag("AX") == TRUE); - SP->_default_fg = (fg >= 0) ? (fg & C_MASK) : C_MASK; - SP->_default_bg = (bg >= 0) ? (bg & C_MASK) : C_MASK; - if (SP->_color_pairs != 0) - init_pair(0, fg, bg); + SP->_default_fg = isDefaultColor(fg) ? COLOR_DEFAULT : (fg & C_MASK); + SP->_default_bg = isDefaultColor(bg) ? COLOR_DEFAULT : (bg & C_MASK); + if (SP->_color_pairs != 0) { + bool save = SP->_default_color; + SP->_default_color = TRUE; + init_pair(0, (short) fg, (short) bg); + SP->_default_color = save; + } returnCode(OK); } diff --git a/lib/libcurses/base/lib_echo.c b/lib/libcurses/base/lib_echo.c index 6f101ba3399..3a73b349c9a 100644 --- a/lib/libcurses/base/lib_echo.c +++ b/lib/libcurses/base/lib_echo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_echo.c,v 1.2 2001/01/22 18:01:39 millert Exp $ */ +/* $OpenBSD: lib_echo.c,v 1.3 2010/01/12 23:22:05 nicm Exp $ */ /**************************************************************************** * Copyright (c) 1998,2000 Free Software Foundation, Inc. * @@ -44,7 +44,7 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_echo.c,v 1.5 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_echo.c,v 1.3 2010/01/12 23:22:05 nicm Exp $") NCURSES_EXPORT(int) echo(void) diff --git a/lib/libcurses/base/lib_endwin.c b/lib/libcurses/base/lib_endwin.c index 971bc9a06c8..281569ea043 100644 --- a/lib/libcurses/base/lib_endwin.c +++ b/lib/libcurses/base/lib_endwin.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_endwin.c,v 1.3 2001/01/22 18:01:39 millert Exp $ */ +/* $OpenBSD: lib_endwin.c,v 1.4 2010/01/12 23:22:05 nicm Exp $ */ /**************************************************************************** * Copyright (c) 1998,2000 Free Software Foundation, Inc. * @@ -43,7 +43,7 @@ #include <curses.priv.h> #include <term.h> -MODULE_ID("$From: lib_endwin.c,v 1.19 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_endwin.c,v 1.4 2010/01/12 23:22:05 nicm Exp $") NCURSES_EXPORT(int) endwin(void) diff --git a/lib/libcurses/base/lib_erase.c b/lib/libcurses/base/lib_erase.c index 44e51e8ce27..9bc4aadf120 100644 --- a/lib/libcurses/base/lib_erase.c +++ b/lib/libcurses/base/lib_erase.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_erase.c,v 1.2 2001/01/22 18:01:39 millert Exp $ */ +/* $OpenBSD: lib_erase.c,v 1.3 2010/01/12 23:22:05 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -42,24 +43,42 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_erase.c,v 1.13 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_erase.c,v 1.3 2010/01/12 23:22:05 nicm Exp $") NCURSES_EXPORT(int) werase(WINDOW *win) { int code = ERR; int y; - chtype blank; - chtype *sp, *end, *start; + NCURSES_CH_T blank; + NCURSES_CH_T *sp, *end, *start; T((T_CALLED("werase(%p)"), win)); if (win) { - blank = _nc_background(win); + blank = win->_nc_bkgd; for (y = 0; y <= win->_maxy; y++) { start = win->_line[y].text; end = &start[win->_maxx]; + /* + * If this is a derived window, we have to handle the case where + * a multicolumn character extends into the window that we are + * erasing. + */ + if_WIDEC({ + if (isWidecExt(start[0])) { + int x = (win->_parent != 0) ? (win->_begx) : 0; + while (x-- > 0) { + if (isWidecBase(start[-1])) { + --start; + break; + } + --start; + } + } + }); + for (sp = start; sp <= end; sp++) *sp = blank; diff --git a/lib/libcurses/base/lib_flash.c b/lib/libcurses/base/lib_flash.c index fd4c3c07658..9f66c4cebd4 100644 --- a/lib/libcurses/base/lib_flash.c +++ b/lib/libcurses/base/lib_flash.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_flash.c,v 1.3 2001/01/22 18:01:39 millert Exp $ */ +/* $OpenBSD: lib_flash.c,v 1.4 2010/01/12 23:22:05 nicm Exp $ */ /**************************************************************************** * Copyright (c) 1998,2000 Free Software Foundation, Inc. * @@ -43,7 +43,7 @@ #include <curses.priv.h> #include <term.h> /* beep, flash */ -MODULE_ID("$From: lib_flash.c,v 1.6 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_flash.c,v 1.4 2010/01/12 23:22:05 nicm Exp $") /* * flash() diff --git a/lib/libcurses/base/lib_freeall.c b/lib/libcurses/base/lib_freeall.c index 5fc67234223..dd3a9449815 100644 --- a/lib/libcurses/base/lib_freeall.c +++ b/lib/libcurses/base/lib_freeall.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_freeall.c,v 1.4 2001/01/22 18:01:39 millert Exp $ */ +/* $OpenBSD: lib_freeall.c,v 1.5 2010/01/12 23:22:05 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,11 +29,12 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey <dickey@clark.net> 1996,1997 * + * Author: Thomas E. Dickey 1996-on * ****************************************************************************/ #include <curses.priv.h> #include <term_entry.h> +#include <tic.h> #if HAVE_NC_FREEALL @@ -41,31 +42,7 @@ extern int malloc_errfd; /* FIXME */ #endif -MODULE_ID("$From: lib_freeall.c,v 1.18 2000/12/10 02:43:27 tom Exp $") - -static void -free_slk(SLK * p) -{ - if (p != 0) { - FreeIfNeeded(p->ent); - FreeIfNeeded(p->buffer); - free(p); - } -} - -static void -free_tries(struct tries *p) -{ - struct tries *q; - - while (p != 0) { - q = p->sibling; - if (p->child != 0) - free_tries(p->child); - free(p); - p = q; - } -} +MODULE_ID("$Id: lib_freeall.c,v 1.5 2010/01/12 23:22:05 nicm Exp $") /* * Free all ncurses data. This is used for testing only (there's no practical @@ -75,61 +52,92 @@ NCURSES_EXPORT(void) _nc_freeall(void) { WINDOWLIST *p, *q; + static va_list empty_va; + T((T_CALLED("_nc_freeall()"))); #if NO_LEAKS - _nc_free_tparm(); + if (SP != 0) { + if (SP->_oldnum_list != 0) { + FreeAndNull(SP->_oldnum_list); + } + if (SP->_panelHook.destroy != 0) { + SP->_panelHook.destroy(SP->_panelHook.stdscr_pseudo_panel); + } + } #endif if (SP != 0) { + _nc_lock_global(curses); + while (_nc_windows != 0) { + bool deleted = FALSE; + /* Delete only windows that're not a parent */ - for (p = _nc_windows; p != 0; p = p->next) { + for (each_window(p)) { bool found = FALSE; - for (q = _nc_windows; q != 0; q = q->next) { + for (each_window(q)) { if ((p != q) - && (q->win->_flags & _SUBWIN) - && (p->win == q->win->_parent)) { + && (q->win._flags & _SUBWIN) + && (&(p->win) == q->win._parent)) { found = TRUE; break; } } if (!found) { - delwin(p->win); + if (delwin(&(p->win)) != ERR) + deleted = TRUE; break; } } - } - free_tries(SP->_keytry); - free_tries(SP->_key_ok); - free_slk(SP->_slk); - FreeIfNeeded(SP->_color_pairs); - FreeIfNeeded(SP->_color_table); -#if !BROKEN_LINKER - FreeAndNull(SP); -#endif + /* + * Don't continue to loop if the list is trashed. + */ + if (!deleted) + break; + } + delscreen(SP); + _nc_unlock_global(curses); } + if (cur_term != 0) + del_curterm(cur_term); - if (cur_term != 0) { - _nc_free_termtype(&(cur_term->type)); - free(cur_term); - } + (void) _nc_printf_string(0, empty_va); #ifdef TRACE (void) _nc_trace_buf(-1, 0); #endif +#if USE_WIDEC_SUPPORT + FreeIfNeeded(_nc_wacs); +#endif + _nc_leaks_tinfo(); + #if HAVE_LIBDBMALLOC malloc_dump(malloc_errfd); #elif HAVE_LIBDMALLOC +#elif HAVE_LIBMPATROL + __mp_summary(); #elif HAVE_PURIFY purify_all_inuse(); #endif + returnVoid; } NCURSES_EXPORT(void) _nc_free_and_exit(int code) { + char *last_setbuf = (SP != 0) ? SP->_setbuf : 0; + _nc_freeall(); +#ifdef TRACE + trace(0); /* close trace file, freeing its setbuf */ + { + static va_list fake; + free(_nc_varargs("?", fake)); + } +#endif + fclose(stdout); + FreeIfNeeded(last_setbuf); exit(code); } @@ -138,4 +146,14 @@ NCURSES_EXPORT(void) _nc_freeall(void) { } + +NCURSES_EXPORT(void) +_nc_free_and_exit(int code) +{ + if (SP) + delscreen(SP); + if (cur_term != 0) + del_curterm(cur_term); + exit(code); +} #endif diff --git a/lib/libcurses/base/lib_getch.c b/lib/libcurses/base/lib_getch.c index 0b17a36d043..db35bc803dc 100644 --- a/lib/libcurses/base/lib_getch.c +++ b/lib/libcurses/base/lib_getch.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_getch.c,v 1.10 2001/01/22 18:01:39 millert Exp $ */ +/* $OpenBSD: lib_getch.c,v 1.11 2010/01/12 23:22:05 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -42,29 +43,96 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_getch.c,v 1.54 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_getch.c,v 1.11 2010/01/12 23:22:05 nicm Exp $") #include <fifo_defs.h> +#if USE_REENTRANT +#define GetEscdelay(sp) (sp)->_ESCDELAY +NCURSES_EXPORT(int) +NCURSES_PUBLIC_VAR(ESCDELAY) (void) +{ + return SP ? GetEscdelay(SP) : 1000; +} +#else +#define GetEscdelay(sp) ESCDELAY NCURSES_EXPORT_VAR(int) ESCDELAY = 1000; /* max interval betw. chars in funkeys, in millisecs */ +#endif + +#if NCURSES_EXT_FUNCS +NCURSES_EXPORT(int) +set_escdelay(int value) +{ + int code = OK; +#if USE_REENTRANT + if (SP) { + SP->_ESCDELAY = value; + } else { + code = ERR; + } +#else + ESCDELAY = value; +#endif + return code; +} +#endif + +static int +_nc_use_meta(WINDOW *win) +{ + SCREEN *sp = _nc_screen_of(win); + return (sp ? sp->_use_meta : 0); +} + +#ifdef NCURSES_WGETCH_EVENTS +#define TWAIT_MASK 7 +#else +#define TWAIT_MASK 3 +#endif + +/* + * Check for mouse activity, returning nonzero if we find any. + */ +static int +check_mouse_activity(SCREEN *sp, int delay EVENTLIST_2nd(_nc_eventlist * evl)) +{ + int rc; + +#if USE_SYSMOUSE + if ((sp->_mouse_type == M_SYSMOUSE) + && (sp->_sysmouse_head < sp->_sysmouse_tail)) { + return 2; + } +#endif + rc = _nc_timed_wait(sp, TWAIT_MASK, delay, (int *) 0 EVENTLIST_2nd(evl)); +#if USE_SYSMOUSE + if ((sp->_mouse_type == M_SYSMOUSE) + && (sp->_sysmouse_head < sp->_sysmouse_tail) + && (rc == 0) + && (errno == EINTR)) { + rc |= 2; + } +#endif + return rc; +} - static inline int - fifo_peek(void) +static NCURSES_INLINE int +fifo_peek(SCREEN *sp) { - int ch = SP->_fifo[peek]; + int ch = sp->_fifo[peek]; TR(TRACE_IEVENT, ("peeking at %d", peek)); p_inc(); return ch; } -static inline int -fifo_pull(void) +static NCURSES_INLINE int +fifo_pull(SCREEN *sp) { int ch; - ch = SP->_fifo[head]; - TR(TRACE_IEVENT, ("pulling %d from %d", ch, head)); + ch = sp->_fifo[head]; + TR(TRACE_IEVENT, ("pulling %s from %d", _nc_tracechar(sp, ch), head)); if (peek == head) { h_inc(); @@ -73,18 +141,22 @@ fifo_pull(void) h_inc(); #ifdef TRACE - if (_nc_tracing & TRACE_IEVENT) - _nc_fifo_dump(); + if (USE_TRACEF(TRACE_IEVENT)) { + _nc_fifo_dump(sp); + _nc_unlock_global(tracef); + } #endif return ch; } -static inline int -fifo_push(void) +static NCURSES_INLINE int +fifo_push(SCREEN *sp EVENTLIST_2nd(_nc_eventlist * evl)) { int n; - int ch; + int ch = 0; + int mask = 0; + (void) mask; if (tail == -1) return ERR; @@ -93,18 +165,51 @@ fifo_push(void) errno = 0; #endif -#if USE_GPM_SUPPORT || defined(USE_EMX_MOUSE) - if ((SP->_mouse_fd >= 0) - && (_nc_timed_wait(3, -1, (int *) 0) & 2)) { - SP->_mouse_event(SP); +#ifdef NCURSES_WGETCH_EVENTS + if (evl +#if USE_GPM_SUPPORT || USE_EMX_MOUSE || USE_SYSMOUSE + || (sp->_mouse_fd >= 0) +#endif + ) { + mask = check_mouse_activity(sp, -1 EVENTLIST_2nd(evl)); + } else + mask = 0; + + if (mask & 4) { + T(("fifo_push: ungetch KEY_EVENT")); + _nc_ungetch(sp, KEY_EVENT); + return KEY_EVENT; + } +#elif USE_GPM_SUPPORT || USE_EMX_MOUSE || USE_SYSMOUSE + if (sp->_mouse_fd >= 0) { + mask = check_mouse_activity(sp, -1 EVENTLIST_2nd(evl)); + } +#endif + +#if USE_GPM_SUPPORT || USE_EMX_MOUSE + if ((sp->_mouse_fd >= 0) && (mask & 2)) { + sp->_mouse_event(sp); + ch = KEY_MOUSE; + n = 1; + } else +#endif +#if USE_SYSMOUSE + if ((sp->_mouse_type == M_SYSMOUSE) + && (sp->_sysmouse_head < sp->_sysmouse_tail)) { + sp->_mouse_event(sp); + ch = KEY_MOUSE; + n = 1; + } else if ((sp->_mouse_type == M_SYSMOUSE) + && (mask <= 0) && errno == EINTR) { + sp->_mouse_event(sp); ch = KEY_MOUSE; n = 1; } else #endif - { + { /* Can block... */ unsigned char c2 = 0; - n = read(SP->_ifd, &c2, 1); - ch = CharOf(c2); + n = read(sp->_ifd, &c2, 1); + ch = c2; } #ifdef HIDE_EINTR @@ -122,96 +227,192 @@ fifo_push(void) #endif if ((n == -1) || (n == 0)) { - TR(TRACE_IEVENT, ("read(%d,&ch,1)=%d, errno=%d", SP->_ifd, n, errno)); + TR(TRACE_IEVENT, ("read(%d,&ch,1)=%d, errno=%d", sp->_ifd, n, errno)); ch = ERR; } TR(TRACE_IEVENT, ("read %d characters", n)); - SP->_fifo[tail] = ch; - SP->_fifohold = 0; + sp->_fifo[tail] = ch; + sp->_fifohold = 0; if (head == -1) head = peek = tail; t_inc(); - TR(TRACE_IEVENT, ("pushed %#x at %d", ch, tail)); + TR(TRACE_IEVENT, ("pushed %s at %d", _nc_tracechar(sp, ch), tail)); #ifdef TRACE - if (_nc_tracing & TRACE_IEVENT) - _nc_fifo_dump(); + if (USE_TRACEF(TRACE_IEVENT)) { + _nc_fifo_dump(sp); + _nc_unlock_global(tracef); + } #endif return ch; } -static inline void -fifo_clear(void) +static NCURSES_INLINE void +fifo_clear(SCREEN *sp) { - int i; - for (i = 0; i < FIFO_SIZE; i++) - SP->_fifo[i] = 0; + memset(sp->_fifo, 0, sizeof(sp->_fifo)); head = -1; tail = peek = 0; } -static int kgetch(WINDOW *); +static int kgetch(SCREEN *EVENTLIST_2nd(_nc_eventlist * evl)); + +static void +recur_wrefresh(WINDOW *win) +{ +#ifdef USE_PTHREADS + SCREEN *sp = _nc_screen_of(win); + if (_nc_use_pthreads && sp != SP) { + SCREEN *save_SP; + + /* temporarily switch to the window's screen to check/refresh */ + _nc_lock_global(curses); + save_SP = SP; + _nc_set_screen(sp); + recur_wrefresh(win); + _nc_set_screen(save_SP); + _nc_unlock_global(curses); + } else +#endif + if ((is_wintouched(win) || (win->_flags & _HASMOVED)) + && !(win->_flags & _ISPAD)) { + wrefresh(win); + } +} -#define wgetch_should_refresh(win) (\ - (is_wintouched(win) || (win->_flags & _HASMOVED)) \ - && !(win->_flags & _ISPAD)) +static int +recur_wgetnstr(WINDOW *win, char *buf) +{ + SCREEN *sp = _nc_screen_of(win); + int rc; + + if (sp != 0) { +#ifdef USE_PTHREADS + if (_nc_use_pthreads && sp != SP) { + SCREEN *save_SP; + + /* temporarily switch to the window's screen to get cooked input */ + _nc_lock_global(curses); + save_SP = SP; + _nc_set_screen(sp); + rc = recur_wgetnstr(win, buf); + _nc_set_screen(save_SP); + _nc_unlock_global(curses); + } else +#endif + { + sp->_called_wgetch = TRUE; + rc = wgetnstr(win, buf, MAXCOLUMNS); + sp->_called_wgetch = FALSE; + } + } else { + rc = ERR; + } + return rc; +} NCURSES_EXPORT(int) -wgetch(WINDOW *win) +_nc_wgetch(WINDOW *win, + unsigned long *result, + int use_meta + EVENTLIST_2nd(_nc_eventlist * evl)) { + SCREEN *sp; int ch; +#ifdef NCURSES_WGETCH_EVENTS + long event_delay = -1; +#endif - T((T_CALLED("wgetch(%p)"), win)); + T((T_CALLED("_nc_wgetch(%p)"), win)); - if (!win) + *result = 0; + + sp = _nc_screen_of(win); + if (win == 0 || sp == 0) { returnCode(ERR); + } if (cooked_key_in_fifo()) { - if (wgetch_should_refresh(win)) - wrefresh(win); - - ch = fifo_pull(); - T(("wgetch returning (pre-cooked): %#x = %s", ch, _trace_key(ch))); - returnCode(ch); + recur_wrefresh(win); + *result = fifo_pull(sp); + returnCode(*result >= KEY_MIN ? KEY_CODE_YES : OK); } +#ifdef NCURSES_WGETCH_EVENTS + if (evl && (evl->count == 0)) + evl = NULL; + event_delay = _nc_eventlist_timeout(evl); +#endif /* * Handle cooked mode. Grab a string from the screen, * stuff its contents in the FIFO queue, and pop off * the first character to return it. */ - if (head == -1 && !SP->_raw && !SP->_cbreak) { - char buf[MAXCOLUMNS], *sp; + if (head == -1 && + !sp->_notty && + !sp->_raw && + !sp->_cbreak && + !sp->_called_wgetch) { + char buf[MAXCOLUMNS], *bufp; + int rc; TR(TRACE_IEVENT, ("filling queue in cooked mode")); - wgetnstr(win, buf, MAXCOLUMNS); + rc = recur_wgetnstr(win, buf); /* ungetch in reverse order */ - ungetch('\n'); - for (sp = buf + strlen(buf); sp > buf; sp--) - ungetch(sp[-1]); - - returnCode(fifo_pull()); +#ifdef NCURSES_WGETCH_EVENTS + if (rc != KEY_EVENT) +#endif + _nc_ungetch(sp, '\n'); + for (bufp = buf + strlen(buf); bufp > buf; bufp--) + _nc_ungetch(sp, bufp[-1]); + +#ifdef NCURSES_WGETCH_EVENTS + /* Return it first */ + if (rc == KEY_EVENT) { + *result = rc; + } else +#endif + *result = fifo_pull(sp); + returnCode(*result >= KEY_MIN ? KEY_CODE_YES : OK); } - if (wgetch_should_refresh(win)) - wrefresh(win); + if (win->_use_keypad != sp->_keypad_on) + _nc_keypad(sp, win->_use_keypad); + + recur_wrefresh(win); + + if (win->_notimeout || (win->_delay >= 0) || (sp->_cbreak > 1)) { + if (head == -1) { /* fifo is empty */ + int delay; + int rc; - if (!win->_notimeout && (win->_delay >= 0 || SP->_cbreak > 1)) { - int delay; + TR(TRACE_IEVENT, ("timed delay in wgetch()")); + if (sp->_cbreak > 1) + delay = (sp->_cbreak - 1) * 100; + else + delay = win->_delay; + +#ifdef NCURSES_WGETCH_EVENTS + if (event_delay >= 0 && delay > event_delay) + delay = event_delay; +#endif - TR(TRACE_IEVENT, ("timed delay in wgetch()")); - if (SP->_cbreak > 1) - delay = (SP->_cbreak - 1) * 100; - else - delay = win->_delay; + TR(TRACE_IEVENT, ("delay is %d milliseconds", delay)); - TR(TRACE_IEVENT, ("delay is %d milliseconds", delay)); + rc = check_mouse_activity(sp, delay EVENTLIST_2nd(evl)); - if (head == -1) /* fifo is empty */ - if (!_nc_timed_wait(3, delay, (int *) 0)) +#ifdef NCURSES_WGETCH_EVENTS + if (rc & 4) { + *result = KEY_EVENT; + returnCode(KEY_CODE_YES); + } +#endif + if (!rc) { returnCode(ERR); + } + } /* else go on to read data available */ } @@ -228,42 +429,59 @@ wgetch(WINDOW *win) * increase the wait with mouseinterval(). */ int runcount = 0; + int rc; do { - ch = kgetch(win); + ch = kgetch(sp EVENTLIST_2nd(evl)); if (ch == KEY_MOUSE) { ++runcount; - if (SP->_mouse_inline(SP)) + if (sp->_mouse_inline(sp)) break; } + if (sp->_maxclick < 0) + break; } while (ch == KEY_MOUSE - && (_nc_timed_wait(3, SP->_maxclick, (int *) 0) - || !SP->_mouse_parse(runcount))); + && (((rc = check_mouse_activity(sp, sp->_maxclick + EVENTLIST_2nd(evl))) != 0 + && !(rc & 4)) + || !sp->_mouse_parse(sp, runcount))); +#ifdef NCURSES_WGETCH_EVENTS + if ((rc & 4) && !ch == KEY_EVENT) { + _nc_ungetch(sp, ch); + ch = KEY_EVENT; + } +#endif if (runcount > 0 && ch != KEY_MOUSE) { - /* mouse event sequence ended by keystroke, push it */ - ungetch(ch); - ch = KEY_MOUSE; +#ifdef NCURSES_WGETCH_EVENTS + /* mouse event sequence ended by an event, report event */ + if (ch == KEY_EVENT) { + _nc_ungetch(sp, KEY_MOUSE); /* FIXME This interrupts a gesture... */ + } else +#endif + { + /* mouse event sequence ended by keystroke, store keystroke */ + _nc_ungetch(sp, ch); + ch = KEY_MOUSE; + } } } else { if (head == -1) - fifo_push(); - ch = fifo_pull(); + fifo_push(sp EVENTLIST_2nd(evl)); + ch = fifo_pull(sp); } if (ch == ERR) { #if USE_SIZECHANGE - if (SP->_sig_winch) { - _nc_update_screensize(); + if (_nc_handle_sigwinch(sp)) { + _nc_update_screensize(sp); /* resizeterm can push KEY_RESIZE */ if (cooked_key_in_fifo()) { - ch = fifo_pull(); - T(("wgetch returning (pre-cooked): %#x = %s", ch, _trace_key(ch))); - returnCode(ch); + *result = fifo_pull(sp); + returnCode(*result >= KEY_MIN ? KEY_CODE_YES : OK); } } #endif - T(("wgetch returning ERR")); returnCode(ERR); } @@ -285,7 +503,7 @@ wgetch(WINDOW *win) * However, we provide the same visual result as Solaris, moving the * cursor to the left. */ - if (SP->_echo && !(win->_flags & _ISPAD)) { + if (sp->_echo && !(win->_flags & _ISPAD)) { chtype backup = (ch == KEY_BACKSPACE) ? '\b' : ch; if (backup < KEY_MIN) wechochar(win, backup); @@ -294,7 +512,7 @@ wgetch(WINDOW *win) /* * Simulate ICRNL mode */ - if ((ch == '\r') && SP->_nl) + if ((ch == '\r') && sp->_nl) ch = '\n'; /* Strip 8th-bit if so desired. We do this only for characters that @@ -302,13 +520,48 @@ wgetch(WINDOW *win) * that display only 7-bit characters. Note that 'ch' may be a * function key at this point, so we mustn't strip _those_. */ - if ((ch < KEY_MIN) && (ch & 0x80)) - if (!SP->_use_meta) + if (!use_meta) + if ((ch < KEY_MIN) && (ch & 0x80)) ch &= 0x7f; - T(("wgetch returning : %#x = %s", ch, _trace_key(ch))); + T(("wgetch returning : %s", _nc_tracechar(sp, ch))); + + *result = ch; + returnCode(ch >= KEY_MIN ? KEY_CODE_YES : OK); +} + +#ifdef NCURSES_WGETCH_EVENTS +NCURSES_EXPORT(int) +wgetch_events(WINDOW *win, _nc_eventlist * evl) +{ + int code; + unsigned long value; + + T((T_CALLED("wgetch_events(%p,%p)"), win, evl)); + code = _nc_wgetch(win, + &value, + _nc_use_meta(win) + EVENTLIST_2nd(evl)); + if (code != ERR) + code = value; + returnCode(code); +} +#endif + +NCURSES_EXPORT(int) +wgetch(WINDOW *win) +{ + int code; + unsigned long value; - returnCode(ch); + T((T_CALLED("wgetch(%p)"), win)); + code = _nc_wgetch(win, + &value, + _nc_use_meta(win) + EVENTLIST_2nd((_nc_eventlist *) 0)); + if (code != ERR) + code = value; + returnCode(code); } /* @@ -321,55 +574,66 @@ wgetch(WINDOW *win) ** sequence is received by the time the alarm goes off, pass through ** the sequence gotten so far. ** -** This function must be called when there is no cooked keys in queue. +** This function must be called when there are no cooked keys in queue. ** (that is head==-1 || peek==head) ** */ static int -kgetch(WINDOW *win GCC_UNUSED) +kgetch(SCREEN *sp EVENTLIST_2nd(_nc_eventlist * evl)) { - struct tries *ptr; + TRIES *ptr; int ch = 0; - int timeleft = ESCDELAY; + int timeleft = GetEscdelay(sp); - TR(TRACE_IEVENT, ("kgetch(%p) called", win)); + TR(TRACE_IEVENT, ("kgetch() called")); - ptr = SP->_keytry; + ptr = sp->_keytry; for (;;) { - if (!raw_key_in_fifo()) { - if (fifo_push() == ERR) { + if (cooked_key_in_fifo() && sp->_fifo[head] >= KEY_MIN) { + break; + } else if (!raw_key_in_fifo()) { + ch = fifo_push(sp EVENTLIST_2nd(evl)); + if (ch == ERR) { peek = head; /* the keys stay uninterpreted */ return ERR; } +#ifdef NCURSES_WGETCH_EVENTS + else if (ch == KEY_EVENT) { + peek = head; /* the keys stay uninterpreted */ + return fifo_pull(sp); /* Remove KEY_EVENT from the queue */ + } +#endif } - ch = fifo_peek(); + + ch = fifo_peek(sp); if (ch >= KEY_MIN) { + /* If not first in queue, somebody put this key there on purpose in + * emergency. Consider it higher priority than the unfinished + * keysequence we are parsing. + */ peek = head; /* assume the key is the last in fifo */ t_dec(); /* remove the key */ return ch; } - TR(TRACE_IEVENT, ("ch: %s", _trace_key((unsigned char) ch))); + TR(TRACE_IEVENT, ("ch: %s", _nc_tracechar(sp, (unsigned char) ch))); while ((ptr != NULL) && (ptr->ch != (unsigned char) ch)) ptr = ptr->sibling; -#ifdef TRACE + if (ptr == NULL) { TR(TRACE_IEVENT, ("ptr is null")); - } else - TR(TRACE_IEVENT, ("ptr=%p, ch=%d, value=%d", - ptr, ptr->ch, ptr->value)); -#endif /* TRACE */ - - if (ptr == NULL) break; + } + TR(TRACE_IEVENT, ("ptr=%p, ch=%d, value=%d", + ptr, ptr->ch, ptr->value)); if (ptr->value != 0) { /* sequence terminated */ TR(TRACE_IEVENT, ("end of sequence")); if (peek == tail) - fifo_clear(); + fifo_clear(sp); else head = peek; return (ptr->value); @@ -378,14 +642,25 @@ kgetch(WINDOW *win GCC_UNUSED) ptr = ptr->child; if (!raw_key_in_fifo()) { + int rc; + TR(TRACE_IEVENT, ("waiting for rest of sequence")); - if (!_nc_timed_wait(3, timeleft, &timeleft)) { + rc = check_mouse_activity(sp, timeleft EVENTLIST_2nd(evl)); +#ifdef NCURSES_WGETCH_EVENTS + if (rc & 4) { + TR(TRACE_IEVENT, ("interrupted by a user event")); + /* FIXME Should have preserved remainder timeleft for reuse... */ + peek = head; /* Restart interpreting later */ + return KEY_EVENT; + } +#endif + if (!rc) { TR(TRACE_IEVENT, ("ran out of time")); break; } } } - ch = fifo_pull(); + ch = fifo_pull(sp); peek = head; return ch; } diff --git a/lib/libcurses/base/lib_getstr.c b/lib/libcurses/base/lib_getstr.c index 0744f96f40e..b83a0523e63 100644 --- a/lib/libcurses/base/lib_getstr.c +++ b/lib/libcurses/base/lib_getstr.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_getstr.c,v 1.2 2001/01/22 18:01:39 millert Exp $ */ +/* $OpenBSD: lib_getstr.c,v 1.3 2010/01/12 23:22:05 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2006,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -43,7 +43,7 @@ #include <curses.priv.h> #include <term.h> -MODULE_ID("$From: lib_getstr.c,v 1.23 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_getstr.c,v 1.3 2010/01/12 23:22:05 nicm Exp $") /* * This wipes out the last character, no matter whether it was a tab, control @@ -72,8 +72,12 @@ WipeOut(WINDOW *win, int y, int x, char *first, char *last, bool echoed) } NCURSES_EXPORT(int) -wgetnstr(WINDOW *win, char *str, int maxlen) +wgetnstr_events(WINDOW *win, + char *str, + int maxlen, + EVENTLIST_1st(_nc_eventlist * evl)) { + SCREEN *sp = _nc_screen_of(win); TTY buf; bool oldnl, oldecho, oldraw, oldcbreak; char erasec; @@ -89,10 +93,10 @@ wgetnstr(WINDOW *win, char *str, int maxlen) _nc_get_tty_mode(&buf); - oldnl = SP->_nl; - oldecho = SP->_echo; - oldraw = SP->_raw; - oldcbreak = SP->_cbreak; + oldnl = sp->_nl; + oldecho = sp->_echo; + oldraw = sp->_raw; + oldcbreak = sp->_cbreak; nl(); noecho(); noraw(); @@ -107,7 +111,7 @@ wgetnstr(WINDOW *win, char *str, int maxlen) if (is_wintouched(win) || (win->_flags & _HASMOVED)) wrefresh(win); - while ((ch = wgetch(win)) != ERR) { + while ((ch = wgetch_events(win, evl)) != ERR) { /* * Some terminals (the Wyse-50 is the most common) generate * a \n from the down-arrow key. With this logic, it's the @@ -124,6 +128,14 @@ wgetnstr(WINDOW *win, char *str, int maxlen) wechochar(win, (chtype) '\n'); break; } +#ifdef KEY_EVENT + if (ch == KEY_EVENT) + break; +#endif +#ifdef KEY_RESIZE + if (ch == KEY_RESIZE) + break; +#endif if (ch == erasec || ch == KEY_LEFT || ch == KEY_BACKSPACE) { if (str > oldstr) { str = WipeOut(win, y, x, oldstr, str, oldecho); @@ -136,7 +148,7 @@ wgetnstr(WINDOW *win, char *str, int maxlen) || (maxlen >= 0 && str - oldstr >= maxlen)) { beep(); } else { - *str++ = ch; + *str++ = (char) ch; if (oldecho == TRUE) { int oldy = win->_cury; if (waddch(win, (chtype) ch) == ERR) { @@ -178,18 +190,38 @@ wgetnstr(WINDOW *win, char *str, int maxlen) /* Restore with a single I/O call, to fix minor asymmetry between * raw/noraw, etc. */ - SP->_nl = oldnl; - SP->_echo = oldecho; - SP->_raw = oldraw; - SP->_cbreak = oldcbreak; + sp->_nl = oldnl; + sp->_echo = oldecho; + sp->_raw = oldraw; + sp->_cbreak = oldcbreak; _nc_set_tty_mode(&buf); *str = '\0'; if (ch == ERR) - returnCode(ERR); + returnCode(ch); T(("wgetnstr returns %s", _nc_visbuf(oldstr))); +#ifdef KEY_EVENT + if (ch == KEY_EVENT) + returnCode(ch); +#endif +#ifdef KEY_RESIZE + if (ch == KEY_RESIZE) + returnCode(ch); +#endif + returnCode(OK); } + +#ifdef NCURSES_WGETCH_EVENTS +NCURSES_EXPORT(int) +wgetnstr(WINDOW *win, char *str, int maxlen) +{ + returnCode(wgetnstr_events(win, + str, + maxlen, + EVENTLIST_1st((_nc_eventlist *) 0))); +} +#endif diff --git a/lib/libcurses/base/lib_hline.c b/lib/libcurses/base/lib_hline.c index 6854c5a61a1..58d83488068 100644 --- a/lib/libcurses/base/lib_hline.c +++ b/lib/libcurses/base/lib_hline.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_hline.c,v 1.4 2001/01/22 18:01:40 millert Exp $ */ +/* $OpenBSD: lib_hline.c,v 1.5 2010/01/12 23:22:05 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2001,2006 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -42,7 +42,7 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_hline.c,v 1.8 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_hline.c,v 1.5 2010/01/12 23:22:05 nicm Exp $") NCURSES_EXPORT(int) whline(WINDOW *win, chtype ch, int n) @@ -55,6 +55,7 @@ whline(WINDOW *win, chtype ch, int n) if (win) { struct ldat *line = &(win->_line[win->_cury]); + NCURSES_CH_T wch; start = win->_curx; end = start + n - 1; @@ -64,11 +65,13 @@ whline(WINDOW *win, chtype ch, int n) CHANGED_RANGE(line, start, end); if (ch == 0) - ch = ACS_HLINE; - ch = _nc_render(win, ch); + SetChar2(wch, ACS_HLINE); + else + SetChar2(wch, ch); + wch = _nc_render(win, wch); while (end >= start) { - line->text[end] = ch; + line->text[end] = wch; end--; } diff --git a/lib/libcurses/base/lib_immedok.c b/lib/libcurses/base/lib_immedok.c index f5925446e8d..53effcbad16 100644 --- a/lib/libcurses/base/lib_immedok.c +++ b/lib/libcurses/base/lib_immedok.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_immedok.c,v 1.2 2001/01/22 18:01:40 millert Exp $ */ +/* $OpenBSD: lib_immedok.c,v 1.3 2010/01/12 23:22:05 nicm Exp $ */ /**************************************************************************** * Copyright (c) 1998,2000 Free Software Foundation, Inc. * @@ -42,7 +42,7 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_immedok.c,v 1.4 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_immedok.c,v 1.3 2010/01/12 23:22:05 nicm Exp $") NCURSES_EXPORT(void) immedok(WINDOW *win, bool flag) diff --git a/lib/libcurses/base/lib_inchstr.c b/lib/libcurses/base/lib_inchstr.c index 0965de4ffdb..87fddea809f 100644 --- a/lib/libcurses/base/lib_inchstr.c +++ b/lib/libcurses/base/lib_inchstr.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_inchstr.c,v 1.2 2001/01/22 18:01:40 millert Exp $ */ +/* $OpenBSD: lib_inchstr.c,v 1.3 2010/01/12 23:22:05 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -42,7 +42,7 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_inchstr.c,v 1.9 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_inchstr.c,v 1.3 2010/01/12 23:22:05 nicm Exp $") NCURSES_EXPORT(int) winchnstr(WINDOW *win, chtype * str, int n) @@ -56,7 +56,9 @@ winchnstr(WINDOW *win, chtype * str, int n) if (win) { for (; (n < 0 || (i < n)) && (win->_curx + i <= win->_maxx); i++) - str[i] = win->_line[win->_cury].text[win->_curx + i]; + str[i] = + CharOf(win->_line[win->_cury].text[win->_curx + i]) | + AttrOf(win->_line[win->_cury].text[win->_curx + i]); } str[i] = (chtype) 0; diff --git a/lib/libcurses/base/lib_initscr.c b/lib/libcurses/base/lib_initscr.c index c3fa8fecbdd..6f8fa785065 100644 --- a/lib/libcurses/base/lib_initscr.c +++ b/lib/libcurses/base/lib_initscr.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_initscr.c,v 1.2 2001/01/22 18:01:40 millert Exp $ */ +/* $OpenBSD: lib_initscr.c,v 1.3 2010/01/12 23:22:05 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-2003 * ****************************************************************************/ /* @@ -41,41 +42,60 @@ */ #include <curses.priv.h> -#include <tic.h> /* for MAX_ALIAS */ #if HAVE_SYS_TERMIO_H #include <sys/termio.h> /* needed for ISC */ #endif -MODULE_ID("$From: lib_initscr.c,v 1.28 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_initscr.c,v 1.3 2010/01/12 23:22:05 nicm Exp $") NCURSES_EXPORT(WINDOW *) initscr(void) { - static bool initialized = FALSE; + WINDOW *result; + NCURSES_CONST char *name; - int value; + START_TRACE(); T((T_CALLED("initscr()"))); + + _nc_init_pthreads(); + _nc_lock_global(curses); + /* Portable applications must not call initscr() more than once */ - if (!initialized) { - initialized = TRUE; + if (!_nc_globals.init_screen) { + _nc_globals.init_screen = TRUE; if ((name = getenv("TERM")) == 0 || *name == '\0') name = "unknown"; +#ifdef __CYGWIN__ + /* + * 2002/9/21 + * Work around a bug in Cygwin. Full-screen subprocesses run from + * bash, in turn spawned from another full-screen process, will dump + * core when attempting to write to stdout. Opening /dev/tty + * explicitly seems to fix the problem. + */ + if (isatty(fileno(stdout))) { + FILE *fp = fopen("/dev/tty", "w"); + if (fp != 0 && isatty(fileno(fp))) { + fclose(stdout); + dup2(fileno(fp), STDOUT_FILENO); + stdout = fdopen(STDOUT_FILENO, "w"); + } + } +#endif if (newterm(name, stdout, stdin) == 0) { fprintf(stderr, "Error opening terminal: %s.\n", name); exit(EXIT_FAILURE); } - /* allow user to set maximum escape delay from the environment */ - if ((value = _nc_getenv_num("ESCDELAY")) >= 0) { - ESCDELAY = value; - } - /* def_shell_mode - done in newterm/_nc_setupscreen */ def_prog_mode(); } - returnWin(stdscr); + result = stdscr; + _nc_unlock_global(curses); + + returnWin(result); } diff --git a/lib/libcurses/base/lib_insch.c b/lib/libcurses/base/lib_insch.c index 5d6ef421df9..d0b7404c331 100644 --- a/lib/libcurses/base/lib_insch.c +++ b/lib/libcurses/base/lib_insch.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_insch.c,v 1.2 2001/01/22 18:01:40 millert Exp $ */ +/* $OpenBSD: lib_insch.c,v 1.3 2010/01/12 23:22:05 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2005,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,8 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Sven Verdoolaege * + * and: Thomas E. Dickey * ****************************************************************************/ /* @@ -41,28 +43,115 @@ */ #include <curses.priv.h> +#include <ctype.h> -MODULE_ID("$From: lib_insch.c,v 1.12 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_insch.c,v 1.3 2010/01/12 23:22:05 nicm Exp $") + +/* + * Insert the given character, updating the current location to simplify + * inserting a string. + */ +NCURSES_EXPORT(int) +_nc_insert_ch(WINDOW *win, chtype ch) +{ + int code = OK; + NCURSES_CH_T wch; + int count; + NCURSES_CONST char *s; + + switch (ch) { + case '\t': + for (count = (TABSIZE - (win->_curx % TABSIZE)); count > 0; count--) { + if ((code = _nc_insert_ch(win, ' ')) != OK) + break; + } + break; + case '\n': + case '\r': + case '\b': + SetChar2(wch, ch); + _nc_waddch_nosync(win, wch); + break; + default: + if ( +#if USE_WIDEC_SUPPORT + WINDOW_EXT(win, addch_used) == 0 && +#endif + is8bits(ChCharOf(ch)) && + isprint(ChCharOf(ch))) { + if (win->_curx <= win->_maxx) { + struct ldat *line = &(win->_line[win->_cury]); + NCURSES_CH_T *end = &(line->text[win->_curx]); + NCURSES_CH_T *temp1 = &(line->text[win->_maxx]); + NCURSES_CH_T *temp2 = temp1 - 1; + + SetChar2(wch, ch); + + CHANGED_TO_EOL(line, win->_curx, win->_maxx); + while (temp1 > end) + *temp1-- = *temp2--; + + *temp1 = _nc_render(win, wch); + win->_curx++; + } + } else if (is8bits(ChCharOf(ch)) && iscntrl(ChCharOf(ch))) { + s = unctrl(ChCharOf(ch)); + while (*s != '\0') { + code = _nc_insert_ch(win, ChAttrOf(ch) | UChar(*s)); + if (code != OK) + break; + ++s; + } + } +#if USE_WIDEC_SUPPORT + else { + /* + * Handle multibyte characters here + */ + SetChar2(wch, ch); + wch = _nc_render(win, wch); + count = _nc_build_wch(win, &wch); + if (count > 0) { + code = wins_wch(win, &wch); + } else if (count == -1) { + /* handle EILSEQ */ + if (is8bits(ch)) { + s = unctrl(ChCharOf(ch)); + while (*s != '\0') { + code = _nc_insert_ch(win, ChAttrOf(ch) | UChar(*s)); + if (code != OK) + break; + ++s; + } + } else { + code = ERR; + } + } + } +#endif + break; + } + return code; +} NCURSES_EXPORT(int) winsch(WINDOW *win, chtype c) { + NCURSES_SIZE_T oy; + NCURSES_SIZE_T ox; int code = ERR; T((T_CALLED("winsch(%p, %s)"), win, _tracechtype(c))); - if (win) { - struct ldat *line = &(win->_line[win->_cury]); - chtype *end = &(line->text[win->_curx]); - chtype *temp1 = &(line->text[win->_maxx]); - chtype *temp2 = temp1 - 1; + if (win != 0) { + oy = win->_cury; + ox = win->_curx; - CHANGED_TO_EOL(line, win->_curx, win->_maxx); - while (temp1 > end) - *temp1-- = *temp2--; + code = _nc_insert_ch(win, c); - *temp1 = _nc_render(win, c); - code = OK; + win->_curx = ox; + win->_cury = oy; + _nc_synchook(win); } returnCode(code); } diff --git a/lib/libcurses/base/lib_insdel.c b/lib/libcurses/base/lib_insdel.c index 9c02cfda019..dc121093809 100644 --- a/lib/libcurses/base/lib_insdel.c +++ b/lib/libcurses/base/lib_insdel.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_insdel.c,v 1.2 2001/01/22 18:01:40 millert Exp $ */ +/* $OpenBSD: lib_insdel.c,v 1.3 2010/01/12 23:22:05 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2001,2003 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -44,19 +44,19 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_insdel.c,v 1.10 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_insdel.c,v 1.3 2010/01/12 23:22:05 nicm Exp $") NCURSES_EXPORT(int) winsdelln(WINDOW *win, int n) { int code = ERR; - T((T_CALLED("winsdel(%p,%d)"), win, n)); + T((T_CALLED("winsdelln(%p,%d)"), win, n)); if (win) { if (n != 0) { _nc_scroll_window(win, -n, win->_cury, win->_maxy, - _nc_background(win)); + win->_nc_bkgd); _nc_synchook(win); } code = OK; diff --git a/lib/libcurses/base/lib_insstr.c b/lib/libcurses/base/lib_insnstr.c index 20ed15f9f60..3929d148699 100644 --- a/lib/libcurses/base/lib_insstr.c +++ b/lib/libcurses/base/lib_insnstr.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_insstr.c,v 1.4 2001/01/22 18:01:40 millert Exp $ */ +/* $OpenBSD: lib_insnstr.c,v 1.1 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 2004 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,12 +29,11 @@ ****************************************************************************/ /**************************************************************************** - * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * - * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * Author: Thomas E. Dickey * ****************************************************************************/ /* -** lib_insstr.c +** lib_insnstr.c ** ** The routine winsnstr(). ** @@ -43,7 +42,7 @@ #include <curses.priv.h> #include <ctype.h> -MODULE_ID("$From: lib_insstr.c,v 1.17 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_insnstr.c,v 1.1 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(int) winsnstr(WINDOW *win, const char *s, int n) @@ -54,26 +53,14 @@ winsnstr(WINDOW *win, const char *s, int n) const unsigned char *str = (const unsigned char *) s; const unsigned char *cp; - T((T_CALLED("winsnstr(%p,%s,%d)"), win, _nc_visbuf(s), n)); + T((T_CALLED("winsnstr(%p,%s,%d)"), win, _nc_visbufn(s, n), n)); - if (win && str) { + if (win != 0 && str != 0) { oy = win->_cury; ox = win->_curx; for (cp = str; *cp && (n <= 0 || (cp - str) < n); cp++) { - if (*cp == '\n' || *cp == '\r' || *cp == '\t' || *cp == '\b') - _nc_waddch_nosync(win, (chtype) (*cp)); - else if (is7bits(*cp) && iscntrl(*cp)) { - winsch(win, ' ' + (chtype) (*cp)); - winsch(win, (chtype) '^'); - win->_curx += 2; - } else { - winsch(win, (chtype) (*cp)); - win->_curx++; - } - if (win->_curx > win->_maxx) - win->_curx = win->_maxx; + _nc_insert_ch(win, (chtype) UChar(*cp)); } - win->_curx = ox; win->_cury = oy; _nc_synchook(win); diff --git a/lib/libcurses/base/lib_instr.c b/lib/libcurses/base/lib_instr.c index 8977e40484a..bf943ad4b24 100644 --- a/lib/libcurses/base/lib_instr.c +++ b/lib/libcurses/base/lib_instr.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_instr.c,v 1.2 2001/01/22 18:01:41 millert Exp $ */ +/* $OpenBSD: lib_instr.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2005,2007 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -42,7 +43,7 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_instr.c,v 1.10 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_instr.c,v 1.3 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(int) winnstr(WINDOW *win, char *str, int n) @@ -61,14 +62,53 @@ winnstr(WINDOW *win, char *str, int n) n = win->_maxx - win->_curx + 1; for (; i < n;) { - str[i++] = TextOf(win->_line[row].text[col]); +#if USE_WIDEC_SUPPORT + cchar_t *cell = &(win->_line[row].text[col]); + wchar_t *wch; + attr_t attrs; + short pair; + int n2; + bool done = FALSE; + mbstate_t state; + size_t i3, n3; + char *tmp; + + if (!isWidecExt(*cell)) { + n2 = getcchar(cell, 0, 0, 0, 0); + if (n2 > 0 + && (wch = typeCalloc(wchar_t, (unsigned) n2 + 1)) != 0) { + if (getcchar(cell, wch, &attrs, &pair, 0) == OK) { + + init_mb(state); + n3 = wcstombs(0, wch, 0); + if (isEILSEQ(n3) || (n3 == 0)) { + ; + } else if ((int) (n3 + i) > n) { + done = TRUE; + } else if ((tmp = typeCalloc(char, n3 + 10)) == 0) { + done = TRUE; + } else { + init_mb(state); + wcstombs(tmp, wch, n3); + for (i3 = 0; i3 < n3; ++i3) + str[i++] = tmp[i3]; + free(tmp); + } + } + free(wch); + if (done) + break; + } + } +#else + str[i++] = (char) CharOf(win->_line[row].text[col]); +#endif if (++col > win->_maxx) { - col = 0; - if (++row > win->_maxy) - break; + break; } } } str[i] = '\0'; /* SVr4 does not seem to count the null */ + T(("winnstr returns %s", _nc_visbuf(str))); returnCode(i); } diff --git a/lib/libcurses/base/lib_isendwin.c b/lib/libcurses/base/lib_isendwin.c index 55495476584..2c8421e5298 100644 --- a/lib/libcurses/base/lib_isendwin.c +++ b/lib/libcurses/base/lib_isendwin.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_isendwin.c,v 1.2 2001/01/22 18:01:41 millert Exp $ */ +/* $OpenBSD: lib_isendwin.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** * Copyright (c) 1998,2000 Free Software Foundation, Inc. * @@ -42,7 +42,7 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_isendwin.c,v 1.6 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_isendwin.c,v 1.3 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(bool) isendwin(void) diff --git a/lib/libcurses/base/lib_leaveok.c b/lib/libcurses/base/lib_leaveok.c index a496d226c42..8edde4dc459 100644 --- a/lib/libcurses/base/lib_leaveok.c +++ b/lib/libcurses/base/lib_leaveok.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_leaveok.c,v 1.2 2001/01/22 18:01:41 millert Exp $ */ +/* $OpenBSD: lib_leaveok.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** * Copyright (c) 1998,2000 Free Software Foundation, Inc. * @@ -42,7 +42,7 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_leaveok.c,v 1.5 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_leaveok.c,v 1.3 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(int) leaveok(WINDOW *win, bool flag) diff --git a/lib/libcurses/base/lib_mouse.c b/lib/libcurses/base/lib_mouse.c index a6108e32517..fe5278dd0df 100644 --- a/lib/libcurses/base/lib_mouse.c +++ b/lib/libcurses/base/lib_mouse.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_mouse.c,v 1.13 2001/01/22 18:01:41 millert Exp $ */ +/* $OpenBSD: lib_mouse.c,v 1.14 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,14 +31,18 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* * This module is intended to encapsulate ncurses's interface to pointing * devices. * - * The first method used is xterm's internal mouse-tracking facility. - * The second is Alessandro Rubini's GPM server. + * The primary method used is xterm's internal mouse-tracking facility. + * Additional methods depend on the platform: + * Alessandro Rubini's GPM server (Linux) + * sysmouse (FreeBSD) + * special-purpose mouse interface for OS/2 EMX. * * Notes for implementors of new mouse-interface methods: * @@ -76,82 +80,131 @@ #endif #include <curses.priv.h> + +MODULE_ID("$Id: lib_mouse.c,v 1.14 2010/01/12 23:22:06 nicm Exp $") + #include <term.h> +#include <tic.h> #if USE_GPM_SUPPORT -#ifndef LINT /* don't need this for llib-lncurses */ -#undef buttons /* term.h defines this, and gpm uses it! */ -#include <gpm.h> #include <linux/keyboard.h> /* defines KG_* macros */ + +#ifdef HAVE_LIBDL +/* use dynamic loader to avoid linkage dependency */ +#include <dlfcn.h> + +#ifdef RTLD_NOW +#define my_RTLD RTLD_NOW +#else +#ifdef RTLD_LAZY +#define my_RTLD RTLD_LAZY +#else +make an error #endif +#endif /* RTLD_NOW */ +#endif /* HAVE_LIBDL */ + +#endif /* USE_GPM_SUPPORT */ + +#if USE_SYSMOUSE +#undef buttons /* symbol conflict in consio.h */ +#undef mouse_info /* symbol conflict in consio.h */ +#include <osreldate.h> +#if (__FreeBSD_version >= 400017) +#include <sys/consio.h> +#include <sys/fbio.h> +#else +#include <machine/console.h> #endif - -MODULE_ID("$From: lib_mouse.c,v 1.57 2000/12/10 02:43:27 tom Exp $") +#endif /* use_SYSMOUSE */ #define MY_TRACE TRACE_ICALLS|TRACE_IEVENT -#define INVALID_EVENT -1 +#define MASK_RELEASE(x) NCURSES_MOUSE_MASK(x, 001) +#define MASK_PRESS(x) NCURSES_MOUSE_MASK(x, 002) +#define MASK_CLICK(x) NCURSES_MOUSE_MASK(x, 004) +#define MASK_DOUBLE_CLICK(x) NCURSES_MOUSE_MASK(x, 010) +#define MASK_TRIPLE_CLICK(x) NCURSES_MOUSE_MASK(x, 020) +#define MASK_RESERVED_EVENT(x) NCURSES_MOUSE_MASK(x, 040) + +#if NCURSES_MOUSE_VERSION == 1 +#define BUTTON_CLICKED (BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED | BUTTON4_CLICKED) +#define BUTTON_PRESSED (BUTTON1_PRESSED | BUTTON2_PRESSED | BUTTON3_PRESSED | BUTTON4_PRESSED) +#define BUTTON_RELEASED (BUTTON1_RELEASED | BUTTON2_RELEASED | BUTTON3_RELEASED | BUTTON4_RELEASED) +#define BUTTON_DOUBLE_CLICKED (BUTTON1_DOUBLE_CLICKED | BUTTON2_DOUBLE_CLICKED | BUTTON3_DOUBLE_CLICKED | BUTTON4_DOUBLE_CLICKED) +#define BUTTON_TRIPLE_CLICKED (BUTTON1_TRIPLE_CLICKED | BUTTON2_TRIPLE_CLICKED | BUTTON3_TRIPLE_CLICKED | BUTTON4_TRIPLE_CLICKED) +#define MAX_BUTTONS 4 +#else +#define BUTTON_CLICKED (BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED | BUTTON4_CLICKED | BUTTON5_CLICKED) +#define BUTTON_PRESSED (BUTTON1_PRESSED | BUTTON2_PRESSED | BUTTON3_PRESSED | BUTTON4_PRESSED | BUTTON5_PRESSED) +#define BUTTON_RELEASED (BUTTON1_RELEASED | BUTTON2_RELEASED | BUTTON3_RELEASED | BUTTON4_RELEASED | BUTTON5_RELEASED) +#define BUTTON_DOUBLE_CLICKED (BUTTON1_DOUBLE_CLICKED | BUTTON2_DOUBLE_CLICKED | BUTTON3_DOUBLE_CLICKED | BUTTON4_DOUBLE_CLICKED | BUTTON5_DOUBLE_CLICKED) +#define BUTTON_TRIPLE_CLICKED (BUTTON1_TRIPLE_CLICKED | BUTTON2_TRIPLE_CLICKED | BUTTON3_TRIPLE_CLICKED | BUTTON4_TRIPLE_CLICKED | BUTTON5_TRIPLE_CLICKED) +#define MAX_BUTTONS 5 +#endif -static int mousetype; -#define M_XTERM -1 /* use xterm's mouse tracking? */ -#define M_NONE 0 /* no mouse device */ -#define M_GPM 1 /* use GPM */ -#define M_QNX 2 /* QNX mouse on console */ -#define M_QNX_TERM 3 /* QNX mouse on pterm/xterm (using qansi-m) */ +#define INVALID_EVENT -1 +#define NORMAL_EVENT 0 #if USE_GPM_SUPPORT -#ifndef LINT -static Gpm_Connect gpm_connect; -#endif + +#ifndef LIBGPM_SONAME +#define LIBGPM_SONAME "libgpm.so" #endif -static mmask_t eventmask; /* current event mask */ +#define GET_DLSYM(name) (my_##name = (TYPE_##name) dlsym(SP->_dlopen_gpm, #name)) -static bool _nc_mouse_parse(int); +#endif /* USE_GPM_SUPPORT */ + +static bool _nc_mouse_parse(SCREEN *, int); static void _nc_mouse_resume(SCREEN *); static void _nc_mouse_wrap(SCREEN *); /* maintain a circular list of mouse events */ -/* The definition of the circular list size (EV_MAX), is in curses.priv.h, so - * wgetch() may refer to the size and call _nc_mouse_parse() before circular - * list overflow. - */ -static MEVENT events[EV_MAX]; /* hold the last mouse event seen */ -static MEVENT *eventp = events; /* next free slot in event queue */ -#define NEXT(ep) ((ep == events + EV_MAX - 1) ? events : ep + 1) -#define PREV(ep) ((ep == events) ? events + EV_MAX - 1 : ep - 1) +#define FirstEV(sp) ((sp)->_mouse_events) +#define LastEV(sp) ((sp)->_mouse_events + EV_MAX - 1) + +#undef NEXT +#define NEXT(ep) ((ep >= LastEV(sp)) \ + ? FirstEV(sp) \ + : ep + 1) + +#undef PREV +#define PREV(ep) ((ep <= FirstEV(sp)) \ + ? LastEV(sp) \ + : ep - 1) + +#define IndexEV(sp, ep) (ep - FirstEV(sp)) + +#define RunParams(sp, eventp, runp) \ + (long) IndexEV(sp, runp), \ + (long) (IndexEV(sp, eventp) + (EV_MAX - 1)) % EV_MAX #ifdef TRACE static void -_trace_slot(const char *tag) +_trace_slot(SCREEN *sp, const char *tag) { MEVENT *ep; _tracef(tag); - for (ep = events; ep < events + EV_MAX; ep++) + for (ep = FirstEV(sp); ep <= LastEV(sp); ep++) _tracef("mouse event queue slot %ld = %s", - (long) (ep - events), - _tracemouse(ep)); + (long) IndexEV(sp, ep), + _nc_tracemouse(sp, ep)); } #endif -#ifdef USE_EMX_MOUSE +#if USE_EMX_MOUSE # define TOP_ROW 0 # define LEFT_COL 0 -static int mouse_wfd; -static int mouse_thread; -static int mouse_activated; -static char mouse_buttons[] = -{0, 1, 3, 2}; - # define M_FD(sp) sp->_mouse_fd static void -write_event(int down, int button, int x, int y) +write_event(SCREEN *sp, int down, int button, int x, int y) { char buf[6]; unsigned long ignore; @@ -160,12 +213,13 @@ write_event(int down, int button, int x, int y) buf[3] = ' ' + (button - 1) + (down ? 0 : 0x40); buf[4] = ' ' + x - LEFT_COL + 1; buf[5] = ' ' + y - TOP_ROW + 1; - DosWrite(mouse_wfd, buf, 6, &ignore); + DosWrite(sp->_emxmouse_wfd, buf, 6, &ignore); } static void -mouse_server(unsigned long ignored GCC_UNUSED) +mouse_server(unsigned long param) { + SCREEN *sp = (SCREEN *) param; unsigned short fWait = MOU_WAIT; /* NOPTRRECT mourt = { 0,0,24,79 }; */ MOUEVENTINFO mouev; @@ -189,11 +243,10 @@ mouse_server(unsigned long ignored GCC_UNUSED) /* sit and wait on the event queue */ rc = MouReadEventQue(&mouev, &fWait, hmou); if (rc) { - snprintf(err, sizeof(err), - "Error reading mouse queue, rc=%lu.\r\n", rc); + snprintf(err, sizeof(err), "Error reading mouse queue, rc=%lu.\r\n", rc); break; } - if (!mouse_activated) + if (!sp->_emxmouse_activated) goto finish; /* @@ -204,22 +257,21 @@ mouse_server(unsigned long ignored GCC_UNUSED) * 3 = middle. */ if ((mouev.fs ^ oldstate) & MOUSE_BN1_DOWN) - write_event(mouev.fs & MOUSE_BN1_DOWN, - mouse_buttons[1], mouev.col, mouev.row); + write_event(sp, mouev.fs & MOUSE_BN1_DOWN, + sp->_emxmouse_buttons[1], mouev.col, mouev.row); if ((mouev.fs ^ oldstate) & MOUSE_BN2_DOWN) - write_event(mouev.fs & MOUSE_BN2_DOWN, - mouse_buttons[3], mouev.col, mouev.row); + write_event(sp, mouev.fs & MOUSE_BN2_DOWN, + sp->_emxmouse_buttons[3], mouev.col, mouev.row); if ((mouev.fs ^ oldstate) & MOUSE_BN3_DOWN) - write_event(mouev.fs & MOUSE_BN3_DOWN, - mouse_buttons[2], mouev.col, mouev.row); + write_event(sp, mouev.fs & MOUSE_BN3_DOWN, + sp->_emxmouse_buttons[2], mouev.col, mouev.row); finish: oldstate = mouev.fs; } } else - snprintf(err, sizeof(err), - "Error setting event mask, buttons=%d, rc=%lu.\r\n", - nbuttons, rc); + snprintf(err, sizeof(err), "Error setting event mask, buttons=%d, rc=%lu.\r\n", + nbuttons, rc); DosWrite(2, err, strlen(err), &rc); MouClose(hmou); @@ -227,185 +279,508 @@ mouse_server(unsigned long ignored GCC_UNUSED) DosExit(EXIT_THREAD, 0L); } +#endif /* USE_EMX_MOUSE */ + +#if USE_SYSMOUSE static void -server_state(const int state) -{ /* It would be nice to implement pointer-off and stop looping... */ - mouse_activated = state; +sysmouse_server(SCREEN *sp) +{ + struct mouse_info the_mouse; + MEVENT *work; + + the_mouse.operation = MOUSE_GETINFO; + if (sp != 0 + && sp->_mouse_fd >= 0 + && sp->_sysmouse_tail < FIFO_SIZE + && ioctl(sp->_mouse_fd, CONS_MOUSECTL, &the_mouse) != -1) { + + if (sp->_sysmouse_head > sp->_sysmouse_tail) { + sp->_sysmouse_tail = 0; + sp->_sysmouse_head = 0; + } + work = &(sp->_sysmouse_fifo[sp->_sysmouse_tail]); + memset(work, 0, sizeof(*work)); + work->id = NORMAL_EVENT; /* there's only one mouse... */ + + sp->_sysmouse_old_buttons = sp->_sysmouse_new_buttons; + sp->_sysmouse_new_buttons = the_mouse.u.data.buttons & 0x7; + + if (sp->_sysmouse_new_buttons) { + if (sp->_sysmouse_new_buttons & 1) + work->bstate |= BUTTON1_PRESSED; + if (sp->_sysmouse_new_buttons & 2) + work->bstate |= BUTTON2_PRESSED; + if (sp->_sysmouse_new_buttons & 4) + work->bstate |= BUTTON3_PRESSED; + } else { + if (sp->_sysmouse_old_buttons & 1) + work->bstate |= BUTTON1_RELEASED; + if (sp->_sysmouse_old_buttons & 2) + work->bstate |= BUTTON2_RELEASED; + if (sp->_sysmouse_old_buttons & 4) + work->bstate |= BUTTON3_RELEASED; + } + + /* for cosmetic bug in syscons.c on FreeBSD 3.[34] */ + the_mouse.operation = MOUSE_HIDE; + ioctl(sp->_mouse_fd, CONS_MOUSECTL, &the_mouse); + the_mouse.operation = MOUSE_SHOW; + ioctl(sp->_mouse_fd, CONS_MOUSECTL, &the_mouse); + + /* + * We're only interested if the button is pressed or released. + * FIXME: implement continuous event-tracking. + */ + if (sp->_sysmouse_new_buttons != sp->_sysmouse_old_buttons) { + sp->_sysmouse_tail += 1; + } + work->x = the_mouse.u.data.x / sp->_sysmouse_char_width; + work->y = the_mouse.u.data.y / sp->_sysmouse_char_height; + } } +static void +handle_sysmouse(int sig GCC_UNUSED) +{ + sysmouse_server(SP); +} +#endif /* USE_SYSMOUSE */ + +static void +init_xterm_mouse(SCREEN *sp) +{ + sp->_mouse_type = M_XTERM; + sp->_mouse_xtermcap = tigetstr("XM"); + if (!VALID_STRING(sp->_mouse_xtermcap)) + sp->_mouse_xtermcap = "\033[?1000%?%p1%{1}%=%th%el%;"; +} + +static void +enable_xterm_mouse(SCREEN *sp, int enable) +{ +#if USE_EMX_MOUSE + sp->_emxmouse_activated = enable; +#else + putp(TPARM_1(sp->_mouse_xtermcap, enable)); #endif + sp->_mouse_active = enable; +} -static int initialized; +#if USE_GPM_SUPPORT +static bool +allow_gpm_mouse(void) +{ + bool result = FALSE; + /* GPM does printf's without checking if stdout is a terminal */ + if (isatty(fileno(stdout))) { + char *list = getenv("NCURSES_GPM_TERMS"); + char *env = getenv("TERM"); + if (list != 0) { + if (env != 0) { + result = _nc_name_match(list, env, "|:"); + } + } else { + /* GPM checks the beginning of the $TERM variable to decide if it + * should pass xterm events through. There is no real advantage in + * allowing GPM to do this. Recent versions relax that check, and + * pretend that GPM can work with any terminal having the kmous + * capability. Perhaps that works for someone. If so, they can + * set the environment variable (above). + */ + if (env != 0 && strstr(env, "linux") != 0) { + result = TRUE; + } + } + } + return result; +} + +#ifdef HAVE_LIBDL static void -initialize_mousetype(void) +unload_gpm_library(SCREEN *sp) { - static const char *xterm_kmous = "\033[M"; + if (SP->_dlopen_gpm != 0) { + T(("unload GPM library")); + sp->_mouse_gpm_loaded = FALSE; + sp->_mouse_fd = -1; + dlclose(sp->_dlopen_gpm); + sp->_dlopen_gpm = 0; + } +} + +static void +load_gpm_library(SCREEN *sp) +{ + sp->_mouse_gpm_found = FALSE; + if ((sp->_dlopen_gpm = dlopen(LIBGPM_SONAME, my_RTLD)) != 0) { + if (GET_DLSYM(gpm_fd) == 0 || + GET_DLSYM(Gpm_Open) == 0 || + GET_DLSYM(Gpm_Close) == 0 || + GET_DLSYM(Gpm_GetEvent) == 0) { + T(("GPM initialization failed: %s", dlerror())); + unload_gpm_library(sp); + } else { + sp->_mouse_gpm_found = TRUE; + sp->_mouse_gpm_loaded = TRUE; + } + } +} +#endif + +static bool +enable_gpm_mouse(SCREEN *sp, bool enable) +{ + bool result; + + T((T_CALLED("enable_gpm_mouse(%d)"), enable)); + + if (enable && !sp->_mouse_active) { +#ifdef HAVE_LIBDL + if (sp->_mouse_gpm_found && !sp->_mouse_gpm_loaded) { + load_gpm_library(sp); + } +#endif + if (sp->_mouse_gpm_loaded) { + /* GPM: initialize connection to gpm server */ + sp->_mouse_gpm_connect.eventMask = GPM_DOWN | GPM_UP; + sp->_mouse_gpm_connect.defaultMask = + (unsigned short) (~(sp->_mouse_gpm_connect.eventMask | GPM_HARD)); + sp->_mouse_gpm_connect.minMod = 0; + sp->_mouse_gpm_connect.maxMod = + (unsigned short) (~((1 << KG_SHIFT) | + (1 << KG_SHIFTL) | + (1 << KG_SHIFTR))); + /* + * Note: GPM hardcodes \E[?1001s and \E[?1000h during its open. + * The former is recognized by wscons (SunOS), and the latter by + * xterm. Those will not show up in ncurses' traces. + */ + result = (my_Gpm_Open(&sp->_mouse_gpm_connect, 0) >= 0); + } else { + result = FALSE; + } + sp->_mouse_active = result; + T(("GPM open %s", result ? "succeeded" : "failed")); + } else { + if (!enable && sp->_mouse_active) { + /* GPM: close connection to gpm server */ + my_Gpm_Close(); + sp->_mouse_active = FALSE; + T(("GPM closed")); + } + result = enable; + } +#ifdef HAVE_LIBDL + if (!result) { + unload_gpm_library(sp); + } +#endif + returnBool(result); +} +#endif /* USE_GPM_SUPPORT */ + +#define xterm_kmous "\033[M" + +static void +initialize_mousetype(SCREEN *sp) +{ + T((T_CALLED("initialize_mousetype()"))); /* Try gpm first, because gpm may be configured to run in xterm */ #if USE_GPM_SUPPORT - /* GPM: initialize connection to gpm server */ - gpm_connect.eventMask = GPM_DOWN | GPM_UP; - gpm_connect.defaultMask = ~(gpm_connect.eventMask | GPM_HARD); - gpm_connect.minMod = 0; - gpm_connect.maxMod = ~((1 << KG_SHIFT) | (1 << KG_SHIFTL) | (1 << KG_SHIFTR)); - if (Gpm_Open(&gpm_connect, 0) >= 0) { /* returns the file-descriptor */ - mousetype = M_GPM; - SP->_mouse_fd = gpm_fd; - return; - } + if (allow_gpm_mouse()) { + if (!sp->_mouse_gpm_loaded) { +#ifdef HAVE_LIBDL + load_gpm_library(sp); +#else /* !HAVE_LIBDL */ + sp->_mouse_gpm_found = TRUE; + sp->_mouse_gpm_loaded = TRUE; #endif + } + + /* + * The gpm_fd file-descriptor may be negative (xterm). So we have to + * maintain our notion of whether the mouse connection is active + * without testing the file-descriptor. + */ + if (sp->_mouse_gpm_found && enable_gpm_mouse(sp, TRUE)) { + sp->_mouse_type = M_GPM; + sp->_mouse_fd = *(my_gpm_fd); + T(("GPM mouse_fd %d", sp->_mouse_fd)); + returnVoid; + } + } +#endif /* USE_GPM_SUPPORT */ /* OS/2 VIO */ -#ifdef USE_EMX_MOUSE - if (!mouse_thread +#if USE_EMX_MOUSE + if (!sp->_emxmouse_thread && strstr(cur_term->type.term_names, "xterm") == 0 && key_mouse) { int handles[2]; if (pipe(handles) < 0) { perror("mouse pipe error"); - return; + returnVoid; } else { int rc; - if (!mouse_buttons[0]) { + if (!sp->_emxmouse_buttons[0]) { char *s = getenv("MOUSE_BUTTONS_123"); - mouse_buttons[0] = 1; + sp->_emxmouse_buttons[0] = 1; if (s && strlen(s) >= 3) { - mouse_buttons[1] = s[0] - '0'; - mouse_buttons[2] = s[1] - '0'; - mouse_buttons[3] = s[2] - '0'; + sp->_emxmouse_buttons[1] = s[0] - '0'; + sp->_emxmouse_buttons[2] = s[1] - '0'; + sp->_emxmouse_buttons[3] = s[2] - '0'; + } else { + sp->_emxmouse_buttons[1] = 1; + sp->_emxmouse_buttons[2] = 3; + sp->_emxmouse_buttons[3] = 2; } } - mouse_wfd = handles[1]; - M_FD(SP) = handles[0]; + sp->_emxmouse_wfd = handles[1]; + M_FD(sp) = handles[0]; /* Needed? */ setmode(handles[0], O_BINARY); setmode(handles[1], O_BINARY); /* Do not use CRT functions, we may single-threaded. */ - rc = DosCreateThread((unsigned long *) &mouse_thread, - mouse_server, 0, 0, 8192); + rc = DosCreateThread((unsigned long *) &sp->_emxmouse_thread, + mouse_server, (long) sp, 0, 8192); if (rc) { printf("mouse thread error %d=%#x", rc, rc); - return; } else { - mousetype = M_XTERM; - return; + sp->_mouse_type = M_XTERM; } + returnVoid; } } -#endif +#endif /* USE_EMX_MOUSE */ + +#if USE_SYSMOUSE + { + struct mouse_info the_mouse; + char *the_device = 0; + + if (isatty(sp->_ifd)) + the_device = ttyname(sp->_ifd); + if (the_device == 0) + the_device = "/dev/tty"; + + sp->_mouse_fd = open(the_device, O_RDWR); + + if (sp->_mouse_fd >= 0) { + /* + * sysmouse does not have a usable user interface for obtaining + * mouse events. The logical way to proceed (reading data on a + * stream) only works if one opens the device as root. Even in + * that mode, careful examination shows we lose events + * occasionally. The interface provided for user programs is to + * establish a signal handler. really. + * + * Take over SIGUSR2 for this purpose since SIGUSR1 is more + * likely to be used by an application. getch() will have to + * handle the misleading EINTR's. + */ + signal(SIGUSR2, SIG_IGN); + the_mouse.operation = MOUSE_MODE; + the_mouse.u.mode.mode = 0; + the_mouse.u.mode.signal = SIGUSR2; + if (ioctl(sp->_mouse_fd, CONS_MOUSECTL, &the_mouse) != -1) { + signal(SIGUSR2, handle_sysmouse); + the_mouse.operation = MOUSE_SHOW; + ioctl(sp->_mouse_fd, CONS_MOUSECTL, &the_mouse); + +#if defined(FBIO_MODEINFO) || defined(CONS_MODEINFO) /* FreeBSD > 2.x */ + { +#ifndef FBIO_GETMODE /* FreeBSD 3.x */ +#define FBIO_GETMODE CONS_GET +#define FBIO_MODEINFO CONS_MODEINFO +#endif /* FBIO_GETMODE */ + video_info_t the_video; + + if (ioctl(sp->_mouse_fd, + FBIO_GETMODE, + &the_video.vi_mode) != -1 + && ioctl(sp->_mouse_fd, + FBIO_MODEINFO, + &the_video) != -1) { + sp->_sysmouse_char_width = the_video.vi_cwidth; + sp->_sysmouse_char_height = the_video.vi_cheight; + } + } +#endif /* defined(FBIO_MODEINFO) || defined(CONS_MODEINFO) */ + + if (sp->_sysmouse_char_width <= 0) + sp->_sysmouse_char_width = 8; + if (sp->_sysmouse_char_height <= 0) + sp->_sysmouse_char_height = 16; + sp->_mouse_type = M_SYSMOUSE; + returnVoid; + } + } + } +#endif /* USE_SYSMOUSE */ /* we know how to recognize mouse events under "xterm" */ if (key_mouse != 0) { - if (!strcmp(key_mouse, xterm_kmous)) { - mousetype = M_XTERM; - return; + if (!strcmp(key_mouse, xterm_kmous) + || strstr(cur_term->type.term_names, "xterm") != 0) { + init_xterm_mouse(sp); } } else if (strstr(cur_term->type.term_names, "xterm") != 0) { - (void) _nc_add_to_try(&(SP->_keytry), xterm_kmous, KEY_MOUSE); - mousetype = M_XTERM; - return; + if (_nc_add_to_try(&(sp->_keytry), xterm_kmous, KEY_MOUSE) == OK) + init_xterm_mouse(sp); } + returnVoid; } -static void -_nc_mouse_init(void) +static bool +_nc_mouse_init(SCREEN *sp) /* initialize the mouse */ { + bool result = FALSE; int i; - if (!initialized) { - initialized = TRUE; + if (sp != 0) { + if (!sp->_mouse_initialized) { + sp->_mouse_initialized = TRUE; - TR(MY_TRACE, ("_nc_mouse_init() called")); + TR(MY_TRACE, ("_nc_mouse_init() called")); - for (i = 0; i < EV_MAX; i++) - events[i].id = INVALID_EVENT; + sp->_mouse_eventp = FirstEV(sp); + for (i = 0; i < EV_MAX; i++) + sp->_mouse_events[i].id = INVALID_EVENT; - initialize_mousetype(); + initialize_mousetype(sp); - T(("_nc_mouse_init() set mousetype to %d", mousetype)); + T(("_nc_mouse_init() set mousetype to %d", sp->_mouse_type)); + } + result = sp->_mouse_initialized; } + return result; } +/* + * Query to see if there is a pending mouse event. This is called from + * fifo_push() in lib_getch.c + */ static bool -_nc_mouse_event(SCREEN * sp GCC_UNUSED) -/* query to see if there is a pending mouse event */ +_nc_mouse_event(SCREEN *sp GCC_UNUSED) { -#if USE_GPM_SUPPORT - /* GPM: query server for event, return TRUE if we find one */ - Gpm_Event ev; + MEVENT *eventp = sp->_mouse_eventp; + bool result = FALSE; - if (gpm_fd >= 0 - && (_nc_timed_wait(3, 0, (int *) 0) & 2) != 0 - && Gpm_GetEvent(&ev) == 1) { - eventp->id = 0; /* there's only one mouse... */ + (void) eventp; - eventp->bstate = 0; - switch (ev.type & 0x0f) { - case (GPM_DOWN): - if (ev.buttons & GPM_B_LEFT) - eventp->bstate |= BUTTON1_PRESSED; - if (ev.buttons & GPM_B_MIDDLE) - eventp->bstate |= BUTTON2_PRESSED; - if (ev.buttons & GPM_B_RIGHT) - eventp->bstate |= BUTTON3_PRESSED; - break; - case (GPM_UP): - if (ev.buttons & GPM_B_LEFT) - eventp->bstate |= BUTTON1_RELEASED; - if (ev.buttons & GPM_B_MIDDLE) - eventp->bstate |= BUTTON2_RELEASED; - if (ev.buttons & GPM_B_RIGHT) - eventp->bstate |= BUTTON3_RELEASED; - break; - default: - break; + switch (sp->_mouse_type) { + case M_XTERM: + /* xterm: never have to query, mouse events are in the keyboard stream */ +#if USE_EMX_MOUSE + { + char kbuf[3]; + + int i, res = read(M_FD(sp), &kbuf, 3); /* Eat the prefix */ + if (res != 3) + printf("Got %d chars instead of 3 for prefix.\n", res); + for (i = 0; i < res; i++) { + if (kbuf[i] != key_mouse[i]) + printf("Got char %d instead of %d for prefix.\n", + (int) kbuf[i], (int) key_mouse[i]); + } + result = TRUE; } +#endif /* USE_EMX_MOUSE */ + break; + +#if USE_GPM_SUPPORT + case M_GPM: + { + /* query server for event, return TRUE if we find one */ + Gpm_Event ev; + + if (my_Gpm_GetEvent(&ev) == 1) { + /* there's only one mouse... */ + eventp->id = NORMAL_EVENT; + + eventp->bstate = 0; + switch (ev.type & 0x0f) { + case (GPM_DOWN): + if (ev.buttons & GPM_B_LEFT) + eventp->bstate |= BUTTON1_PRESSED; + if (ev.buttons & GPM_B_MIDDLE) + eventp->bstate |= BUTTON2_PRESSED; + if (ev.buttons & GPM_B_RIGHT) + eventp->bstate |= BUTTON3_PRESSED; + break; + case (GPM_UP): + if (ev.buttons & GPM_B_LEFT) + eventp->bstate |= BUTTON1_RELEASED; + if (ev.buttons & GPM_B_MIDDLE) + eventp->bstate |= BUTTON2_RELEASED; + if (ev.buttons & GPM_B_RIGHT) + eventp->bstate |= BUTTON3_RELEASED; + break; + default: + break; + } - eventp->x = ev.x - 1; - eventp->y = ev.y - 1; - eventp->z = 0; + eventp->x = ev.x - 1; + eventp->y = ev.y - 1; + eventp->z = 0; - /* bump the next-free pointer into the circular list */ - eventp = NEXT(eventp); - return (TRUE); - } + /* bump the next-free pointer into the circular list */ + sp->_mouse_eventp = eventp = NEXT(eventp); + result = TRUE; + } + } + break; #endif -#ifdef USE_EMX_MOUSE - if (SP->_mouse_fd >= 0 - && (_nc_timed_wait(3, 0, (int *) 0) & 2) != 0) { - char kbuf[3]; - - int i, res = read(M_FD(sp), &kbuf, 3); /* Eat the prefix */ - if (res != 3) - printf("Got %d chars instead of 3 for prefix.\n", res); - for (i = 0; i < res; i++) { - if (kbuf[i] != key_mouse[i]) - printf("Got char %d instead of %d for prefix.\n", - (int) kbuf[i], (int) key_mouse[i]); +#if USE_SYSMOUSE + case M_SYSMOUSE: + if (sp->_sysmouse_head < sp->_sysmouse_tail) { + *eventp = sp->_sysmouse_fifo[sp->_sysmouse_head]; + + /* + * Point the fifo-head to the next possible location. If there + * are none, reset the indices. This may be interrupted by the + * signal handler, doing essentially the same reset. + */ + sp->_sysmouse_head += 1; + if (sp->_sysmouse_head == sp->_sysmouse_tail) { + sp->_sysmouse_tail = 0; + sp->_sysmouse_head = 0; + } + + /* bump the next-free pointer into the circular list */ + sp->_mouse_eventp = eventp = NEXT(eventp); + result = TRUE; } - return TRUE; + break; +#endif /* USE_SYSMOUSE */ + + case M_NONE: + break; } -#endif /* USE_EMX_MOUSE */ - /* xterm: never have to query, mouse events are in the keyboard stream */ - return (FALSE); /* no event waiting */ + return result; /* true if we found an event */ } static bool -_nc_mouse_inline(SCREEN * sp) +_nc_mouse_inline(SCREEN *sp) /* mouse report received in the keyboard stream -- parse its info */ { + int b; + bool result = FALSE; + MEVENT *eventp = sp->_mouse_eventp; + TR(MY_TRACE, ("_nc_mouse_inline() called")); - if (mousetype == M_XTERM) { + if (sp->_mouse_type == M_XTERM) { unsigned char kbuf[4]; - MEVENT *prev; + mmask_t prev; size_t grabbed; int res; @@ -436,13 +811,15 @@ _nc_mouse_inline(SCREEN * sp) * (End quote) By the time we get here, we've eaten the * key prefix. FYI, the loop below is necessary because * mouse click info isn't guaranteed to present as a - * single clist item. It always does under Linux but often - * fails to under Solaris. + * single clist item. + * + * Wheel mice may return buttons 4 and 5 when the wheel is turned. + * We encode those as button presses. */ - for (grabbed = 0; grabbed < 3; grabbed += res) { + for (grabbed = 0; grabbed < 3; grabbed += (size_t) res) { /* For VIO mouse we add extra bit 64 to disambiguate button-up. */ -#ifdef USE_EMX_MOUSE +#if USE_EMX_MOUSE res = read(M_FD(sp) >= 0 ? M_FD(sp) : sp->_ifd, &kbuf, 3); #else res = read(sp->_ifd, kbuf + grabbed, 3 - grabbed); @@ -455,59 +832,71 @@ _nc_mouse_inline(SCREEN * sp) TR(TRACE_IEVENT, ("_nc_mouse_inline sees the following xterm data: '%s'", kbuf)); - eventp->id = 0; /* there's only one mouse... */ + /* there's only one mouse... */ + eventp->id = NORMAL_EVENT; /* processing code goes here */ eventp->bstate = 0; + prev = PREV(eventp)->bstate; + +#if USE_EMX_MOUSE +#define PRESS_POSITION(n) \ + eventp->bstate = MASK_PRESS(n); \ + if (kbuf[0] & 0x40) \ + eventp->bstate = MASK_RELEASE(n) +#else +#define PRESS_POSITION(n) \ + eventp->bstate = (mmask_t) (prev & MASK_PRESS(n) \ + ? REPORT_MOUSE_POSITION \ + : MASK_PRESS(n)) +#endif + switch (kbuf[0] & 0x3) { case 0x0: - eventp->bstate = BUTTON1_PRESSED; -#ifdef USE_EMX_MOUSE - if (kbuf[0] & 0x40) - eventp->bstate = BUTTON1_RELEASED; -#endif + if (kbuf[0] & 64) + eventp->bstate = MASK_PRESS(4); + else + PRESS_POSITION(1); break; case 0x1: - eventp->bstate = BUTTON2_PRESSED; -#ifdef USE_EMX_MOUSE - if (kbuf[0] & 0x40) - eventp->bstate = BUTTON2_RELEASED; +#if NCURSES_MOUSE_VERSION == 2 + if (kbuf[0] & 64) + eventp->bstate = MASK_PRESS(5); + else #endif + PRESS_POSITION(2); break; case 0x2: - eventp->bstate = BUTTON3_PRESSED; -#ifdef USE_EMX_MOUSE - if (kbuf[0] & 0x40) - eventp->bstate = BUTTON3_RELEASED; -#endif + PRESS_POSITION(3); break; case 0x3: /* - * Release events aren't reported for individual buttons, - * just for the button set as a whole... - */ - eventp->bstate = - (BUTTON1_RELEASED | - BUTTON2_RELEASED | - BUTTON3_RELEASED); - /* - * ...however, because there are no kinds of mouse events under - * xterm that can intervene between press and release, we can - * deduce which buttons were actually released by looking at the - * previous event. + * Release events aren't reported for individual buttons, just for + * the button set as a whole. However, because there are normally + * no mouse events under xterm that intervene between press and + * release, we can infer the button actually released by looking at + * the previous event. */ - prev = PREV(eventp); - if (!(prev->bstate & BUTTON1_PRESSED)) - eventp->bstate &= ~BUTTON1_RELEASED; - if (!(prev->bstate & BUTTON2_PRESSED)) - eventp->bstate &= ~BUTTON2_RELEASED; - if (!(prev->bstate & BUTTON3_PRESSED)) - eventp->bstate &= ~BUTTON3_RELEASED; + if (prev & (BUTTON_PRESSED | BUTTON_RELEASED)) { + eventp->bstate = BUTTON_RELEASED; + for (b = 1; b <= MAX_BUTTONS; ++b) { + if (!(prev & MASK_PRESS(b))) + eventp->bstate &= ~MASK_RELEASE(b); + } + } else { + /* + * XFree86 xterm will return a stream of release-events to + * let the application know where the mouse is going, if the + * private mode 1002 or 1003 is enabled. + */ + eventp->bstate = REPORT_MOUSE_POSITION; + } break; } + result = (eventp->bstate & REPORT_MOUSE_POSITION) ? TRUE : FALSE; if (kbuf[0] & 4) { eventp->bstate |= BUTTON_SHIFT; @@ -523,71 +912,83 @@ _nc_mouse_inline(SCREEN * sp) eventp->y = (kbuf[2] - ' ') - 1; TR(MY_TRACE, ("_nc_mouse_inline: primitive mouse-event %s has slot %ld", - _tracemouse(eventp), - (long) (eventp - events))); + _nc_tracemouse(sp, eventp), + (long) IndexEV(sp, eventp))); /* bump the next-free pointer into the circular list */ - eventp = NEXT(eventp); + sp->_mouse_eventp = NEXT(eventp); #if 0 /* this return would be needed for QNX's mods to lib_getch.c */ return (TRUE); #endif } - return (FALSE); + return (result); } static void -mouse_activate(bool on) +mouse_activate(SCREEN *sp, bool on) { - if (!on && !initialized) + if (!on && !sp->_mouse_initialized) return; - _nc_mouse_init(); + if (!_nc_mouse_init(sp)) + return; if (on) { - switch (mousetype) { + switch (sp->_mouse_type) { case M_XTERM: #if NCURSES_EXT_FUNCS keyok(KEY_MOUSE, on); #endif TPUTS_TRACE("xterm mouse initialization"); -#ifdef USE_EMX_MOUSE - server_state(1); -#else - putp("\033[?1000h"); -#endif + enable_xterm_mouse(sp, 1); break; #if USE_GPM_SUPPORT case M_GPM: - SP->_mouse_fd = gpm_fd; + if (enable_gpm_mouse(sp, TRUE)) { + sp->_mouse_fd = *(my_gpm_fd); + T(("GPM mouse_fd %d", sp->_mouse_fd)); + } break; #endif +#if USE_SYSMOUSE + case M_SYSMOUSE: + signal(SIGUSR2, handle_sysmouse); + sp->_mouse_active = TRUE; + break; +#endif + case M_NONE: + return; } /* Make runtime binding to cut down on object size of applications that * do not use the mouse (e.g., 'clear'). */ - SP->_mouse_event = _nc_mouse_event; - SP->_mouse_inline = _nc_mouse_inline; - SP->_mouse_parse = _nc_mouse_parse; - SP->_mouse_resume = _nc_mouse_resume; - SP->_mouse_wrap = _nc_mouse_wrap; - + sp->_mouse_event = _nc_mouse_event; + sp->_mouse_inline = _nc_mouse_inline; + sp->_mouse_parse = _nc_mouse_parse; + sp->_mouse_resume = _nc_mouse_resume; + sp->_mouse_wrap = _nc_mouse_wrap; } else { - switch (mousetype) { + switch (sp->_mouse_type) { case M_XTERM: TPUTS_TRACE("xterm mouse deinitialization"); -#ifdef USE_EMX_MOUSE - server_state(0); -#else - putp("\033[?1000l"); -#endif + enable_xterm_mouse(sp, 0); break; #if USE_GPM_SUPPORT case M_GPM: + enable_gpm_mouse(sp, FALSE); + break; +#endif +#if USE_SYSMOUSE + case M_SYSMOUSE: + signal(SIGUSR2, SIG_IGN); + sp->_mouse_active = FALSE; break; #endif + case M_NONE: + return; } } _nc_flush(); @@ -600,11 +1001,13 @@ mouse_activate(bool on) **************************************************************************/ static bool -_nc_mouse_parse(int runcount) +_nc_mouse_parse(SCREEN *sp, int runcount) /* parse a run of atomic mouse events into a gesture */ { + MEVENT *eventp = sp->_mouse_eventp; MEVENT *ep, *runp, *next, *prev = PREV(eventp); int n; + int b; bool merge; TR(MY_TRACE, ("_nc_mouse_parse(%d) called", runcount)); @@ -613,7 +1016,7 @@ _nc_mouse_parse(int runcount) * When we enter this routine, the event list next-free pointer * points just past a run of mouse events that we know were separated * in time by less than the critical click interval. The job of this - * routine is to collaps this run into a single higher-level event + * routine is to collapse this run into a single higher-level event * or gesture. * * We accomplish this in two passes. The first pass merges press/release @@ -633,10 +1036,10 @@ _nc_mouse_parse(int runcount) if (runcount == 1) { TR(MY_TRACE, ("_nc_mouse_parse: returning simple mouse event %s at slot %ld", - _tracemouse(prev), - (long) (prev - events))); - return (prev->id >= 0) - ? ((prev->bstate & eventmask) ? TRUE : FALSE) + _nc_tracemouse(sp, prev), + (long) IndexEV(sp, prev))); + return (prev->id >= NORMAL_EVENT) + ? ((prev->bstate & sp->_mouse_mask) ? TRUE : FALSE) : FALSE; } @@ -647,45 +1050,40 @@ _nc_mouse_parse(int runcount) } #ifdef TRACE - if (_nc_tracing & TRACE_IEVENT) { - _trace_slot("before mouse press/release merge:"); + if (USE_TRACEF(TRACE_IEVENT)) { + _trace_slot(sp, "before mouse press/release merge:"); _tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d", - (long) (runp - events), - (long) ((eventp - events) + (EV_MAX - 1)) % EV_MAX, + RunParams(sp, eventp, runp), runcount); + _nc_unlock_global(tracef); } #endif /* TRACE */ /* first pass; merge press/release pairs */ do { merge = FALSE; - for (ep = runp; next = NEXT(ep), next != eventp; ep = next) { + for (ep = runp; (next = NEXT(ep)) != eventp; ep = next) { + +#define MASK_CHANGED(x) (!(ep->bstate & MASK_PRESS(x)) \ + == !(next->bstate & MASK_RELEASE(x))) + if (ep->x == next->x && ep->y == next->y - && (ep->bstate & (BUTTON1_PRESSED | BUTTON2_PRESSED | BUTTON3_PRESSED)) - && (!(ep->bstate & BUTTON1_PRESSED) - == !(next->bstate & BUTTON1_RELEASED)) - && (!(ep->bstate & BUTTON2_PRESSED) - == !(next->bstate & BUTTON2_RELEASED)) - && (!(ep->bstate & BUTTON3_PRESSED) - == !(next->bstate & BUTTON3_RELEASED)) + && (ep->bstate & BUTTON_PRESSED) + && MASK_CHANGED(1) + && MASK_CHANGED(2) + && MASK_CHANGED(3) + && MASK_CHANGED(4) +#if NCURSES_MOUSE_VERSION == 2 + && MASK_CHANGED(5) +#endif ) { - if ((eventmask & BUTTON1_CLICKED) - && (ep->bstate & BUTTON1_PRESSED)) { - ep->bstate &= ~BUTTON1_PRESSED; - ep->bstate |= BUTTON1_CLICKED; - merge = TRUE; - } - if ((eventmask & BUTTON2_CLICKED) - && (ep->bstate & BUTTON2_PRESSED)) { - ep->bstate &= ~BUTTON2_PRESSED; - ep->bstate |= BUTTON2_CLICKED; - merge = TRUE; - } - if ((eventmask & BUTTON3_CLICKED) - && (ep->bstate & BUTTON3_PRESSED)) { - ep->bstate &= ~BUTTON3_PRESSED; - ep->bstate |= BUTTON3_CLICKED; - merge = TRUE; + for (b = 1; b <= MAX_BUTTONS; ++b) { + if ((sp->_mouse_mask & MASK_CLICK(b)) + && (ep->bstate & MASK_PRESS(b))) { + ep->bstate &= ~MASK_PRESS(b); + ep->bstate |= MASK_CLICK(b); + merge = TRUE; + } } if (merge) next->id = INVALID_EVENT; @@ -695,12 +1093,12 @@ _nc_mouse_parse(int runcount) (merge); #ifdef TRACE - if (_nc_tracing & TRACE_IEVENT) { - _trace_slot("before mouse click merge:"); + if (USE_TRACEF(TRACE_IEVENT)) { + _trace_slot(sp, "before mouse click merge:"); _tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d", - (long) (runp - events), - (long) ((eventp - events) + (EV_MAX - 1)) % EV_MAX, + RunParams(sp, eventp, runp), runcount); + _nc_unlock_global(tracef); } #endif /* TRACE */ @@ -724,7 +1122,7 @@ _nc_mouse_parse(int runcount) MEVENT *follower; merge = FALSE; - for (ep = runp; next = NEXT(ep), next != eventp; ep = next) + for (ep = runp; (next = NEXT(ep)) != eventp; ep = next) if (ep->id != INVALID_EVENT) { if (next->id != INVALID_EVENT) continue; @@ -733,56 +1131,30 @@ _nc_mouse_parse(int runcount) continue; /* merge click events forward */ - if ((ep->bstate & - (BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED)) - && (follower->bstate & - (BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED))) { - if ((eventmask & BUTTON1_DOUBLE_CLICKED) - && (follower->bstate & BUTTON1_CLICKED)) { - follower->bstate &= ~BUTTON1_CLICKED; - follower->bstate |= BUTTON1_DOUBLE_CLICKED; - merge = TRUE; - } - if ((eventmask & BUTTON2_DOUBLE_CLICKED) - && (follower->bstate & BUTTON2_CLICKED)) { - follower->bstate &= ~BUTTON2_CLICKED; - follower->bstate |= BUTTON2_DOUBLE_CLICKED; - merge = TRUE; - } - if ((eventmask & BUTTON3_DOUBLE_CLICKED) - && (follower->bstate & BUTTON3_CLICKED)) { - follower->bstate &= ~BUTTON3_CLICKED; - follower->bstate |= BUTTON3_DOUBLE_CLICKED; - merge = TRUE; + if ((ep->bstate & BUTTON_CLICKED) + && (follower->bstate & BUTTON_CLICKED)) { + for (b = 1; b <= MAX_BUTTONS; ++b) { + if ((sp->_mouse_mask & MASK_DOUBLE_CLICK(b)) + && (follower->bstate & MASK_CLICK(b))) { + follower->bstate &= ~MASK_CLICK(b); + follower->bstate |= MASK_DOUBLE_CLICK(b); + merge = TRUE; + } } if (merge) ep->id = INVALID_EVENT; } /* merge double-click events forward */ - if ((ep->bstate & - (BUTTON1_DOUBLE_CLICKED - | BUTTON2_DOUBLE_CLICKED - | BUTTON3_DOUBLE_CLICKED)) - && (follower->bstate & - (BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED))) { - if ((eventmask & BUTTON1_TRIPLE_CLICKED) - && (follower->bstate & BUTTON1_CLICKED)) { - follower->bstate &= ~BUTTON1_CLICKED; - follower->bstate |= BUTTON1_TRIPLE_CLICKED; - merge = TRUE; - } - if ((eventmask & BUTTON2_TRIPLE_CLICKED) - && (follower->bstate & BUTTON2_CLICKED)) { - follower->bstate &= ~BUTTON2_CLICKED; - follower->bstate |= BUTTON2_TRIPLE_CLICKED; - merge = TRUE; - } - if ((eventmask & BUTTON3_TRIPLE_CLICKED) - && (follower->bstate & BUTTON3_CLICKED)) { - follower->bstate &= ~BUTTON3_CLICKED; - follower->bstate |= BUTTON3_TRIPLE_CLICKED; - merge = TRUE; + if ((ep->bstate & BUTTON_DOUBLE_CLICKED) + && (follower->bstate & BUTTON_CLICKED)) { + for (b = 1; b <= MAX_BUTTONS; ++b) { + if ((sp->_mouse_mask & MASK_TRIPLE_CLICK(b)) + && (follower->bstate & MASK_CLICK(b))) { + follower->bstate &= ~MASK_CLICK(b); + follower->bstate |= MASK_TRIPLE_CLICK(b); + merge = TRUE; + } } if (merge) ep->id = INVALID_EVENT; @@ -792,12 +1164,12 @@ _nc_mouse_parse(int runcount) (merge); #ifdef TRACE - if (_nc_tracing & TRACE_IEVENT) { - _trace_slot("before mouse event queue compaction:"); + if (USE_TRACEF(TRACE_IEVENT)) { + _trace_slot(sp, "before mouse event queue compaction:"); _tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d", - (long) (runp - events), - (long) ((eventp - events) + (EV_MAX - 1)) % EV_MAX, + RunParams(sp, eventp, runp), runcount); + _nc_unlock_global(tracef); } #endif /* TRACE */ @@ -806,23 +1178,23 @@ _nc_mouse_parse(int runcount) * don't match the current event mask. */ for (; runcount; prev = PREV(eventp), runcount--) - if (prev->id == INVALID_EVENT || !(prev->bstate & eventmask)) { - eventp = prev; + if (prev->id == INVALID_EVENT || !(prev->bstate & sp->_mouse_mask)) { + sp->_mouse_eventp = eventp = prev; } #ifdef TRACE - if (_nc_tracing & TRACE_IEVENT) { - _trace_slot("after mouse event queue compaction:"); + if (USE_TRACEF(TRACE_IEVENT)) { + _trace_slot(sp, "after mouse event queue compaction:"); _tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d", - (long) (runp - events), - (long) ((eventp - events) + (EV_MAX - 1)) % EV_MAX, + RunParams(sp, eventp, runp), runcount); + _nc_unlock_global(tracef); } for (ep = runp; ep != eventp; ep = NEXT(ep)) if (ep->id != INVALID_EVENT) TR(MY_TRACE, ("_nc_mouse_parse: returning composite mouse event %s at slot %ld", - _tracemouse(ep), - (long) (ep - events))); + _nc_tracemouse(sp, ep), + (long) IndexEV(sp, ep))); #endif /* TRACE */ /* after all this, do we have a valid event? */ @@ -830,35 +1202,62 @@ _nc_mouse_parse(int runcount) } static void -_nc_mouse_wrap(SCREEN * sp GCC_UNUSED) +_nc_mouse_wrap(SCREEN *sp) /* release mouse -- called by endwin() before shellout/exit */ { TR(MY_TRACE, ("_nc_mouse_wrap() called")); - switch (mousetype) { + switch (sp->_mouse_type) { case M_XTERM: - if (eventmask) - mouse_activate(FALSE); + if (sp->_mouse_mask) + mouse_activate(sp, FALSE); break; #if USE_GPM_SUPPORT /* GPM: pass all mouse events to next client */ case M_GPM: + if (sp->_mouse_mask) + mouse_activate(sp, FALSE); + break; +#endif +#if USE_SYSMOUSE + case M_SYSMOUSE: + mouse_activate(sp, FALSE); break; #endif + case M_NONE: + break; } } static void -_nc_mouse_resume(SCREEN * sp GCC_UNUSED) +_nc_mouse_resume(SCREEN *sp) /* re-connect to mouse -- called by doupdate() after shellout */ { TR(MY_TRACE, ("_nc_mouse_resume() called")); - /* xterm: re-enable reporting */ - if (mousetype == M_XTERM && eventmask) - mouse_activate(TRUE); + switch (sp->_mouse_type) { + case M_XTERM: + /* xterm: re-enable reporting */ + if (sp->_mouse_mask) + mouse_activate(sp, TRUE); + break; - /* GPM: reclaim our event set */ +#if USE_GPM_SUPPORT + case M_GPM: + /* GPM: reclaim our event set */ + if (sp->_mouse_mask) + mouse_activate(sp, TRUE); + break; +#endif + +#if USE_SYSMOUSE + case M_SYSMOUSE: + mouse_activate(sp, TRUE); + break; +#endif + case M_NONE: + break; + } } /************************************************************************** @@ -867,13 +1266,13 @@ _nc_mouse_resume(SCREEN * sp GCC_UNUSED) * **************************************************************************/ -NCURSES_EXPORT(int) -getmouse(MEVENT * aevent) -/* grab a copy of the current mouse event */ +static int +_nc_getmouse(SCREEN *sp, MEVENT * aevent) { T((T_CALLED("getmouse(%p)"), aevent)); - if (aevent && (mousetype != M_NONE)) { + if ((aevent != 0) && (sp != 0) && (sp->_mouse_type != M_NONE)) { + MEVENT *eventp = sp->_mouse_eventp; /* compute the current-event pointer */ MEVENT *prev = PREV(eventp); @@ -881,8 +1280,8 @@ getmouse(MEVENT * aevent) *aevent = *prev; TR(TRACE_IEVENT, ("getmouse: returning event %s from slot %ld", - _tracemouse(prev), - (long) (prev - events))); + _nc_tracemouse(sp, prev), + (long) IndexEV(sp, prev))); prev->id = INVALID_EVENT; /* so the queue slot becomes free */ returnCode(OK); @@ -890,18 +1289,40 @@ getmouse(MEVENT * aevent) returnCode(ERR); } +/* grab a copy of the current mouse event */ NCURSES_EXPORT(int) -ungetmouse(MEVENT * aevent) -/* enqueue a synthesized mouse event to be seen by the next wgetch() */ +getmouse(MEVENT * aevent) { - /* stick the given event in the next-free slot */ - *eventp = *aevent; + return _nc_getmouse(SP, aevent); +} + +static int +_nc_ungetmouse(SCREEN *sp, MEVENT * aevent) +{ + int result = ERR; + + T((T_CALLED("ungetmouse(%p)"), aevent)); + + if (aevent != 0 && sp != 0) { + MEVENT *eventp = sp->_mouse_eventp; + + /* stick the given event in the next-free slot */ + *eventp = *aevent; + + /* bump the next-free pointer into the circular list */ + sp->_mouse_eventp = NEXT(eventp); - /* bump the next-free pointer into the circular list */ - eventp = NEXT(eventp); + /* push back the notification event on the keyboard queue */ + result = _nc_ungetch(sp, KEY_MOUSE); + } + returnCode(result); +} - /* push back the notification event on the keyboard queue */ - return ungetch(KEY_MOUSE); +/* enqueue a synthesized mouse event to be seen by the next wgetch() */ +NCURSES_EXPORT(int) +ungetmouse(MEVENT * aevent) +{ + return _nc_ungetmouse(SP, aevent); } NCURSES_EXPORT(mmask_t) @@ -910,45 +1331,51 @@ mousemask(mmask_t newmask, mmask_t * oldmask) { mmask_t result = 0; - T((T_CALLED("mousemask(%#lx,%p)"), newmask, oldmask)); - - if (oldmask) - *oldmask = eventmask; + T((T_CALLED("mousemask(%#lx,%p)"), (unsigned long) newmask, oldmask)); - if (!newmask && !initialized) - returnCode(0); - - _nc_mouse_init(); - if (mousetype != M_NONE) { - eventmask = newmask & - (BUTTON_ALT | BUTTON_CTRL | BUTTON_SHIFT - | BUTTON1_PRESSED | BUTTON1_RELEASED | BUTTON1_CLICKED - | BUTTON1_DOUBLE_CLICKED | BUTTON1_TRIPLE_CLICKED - | BUTTON2_PRESSED | BUTTON2_RELEASED | BUTTON2_CLICKED - | BUTTON2_DOUBLE_CLICKED | BUTTON2_TRIPLE_CLICKED - | BUTTON3_PRESSED | BUTTON3_RELEASED | BUTTON3_CLICKED - | BUTTON3_DOUBLE_CLICKED | BUTTON3_TRIPLE_CLICKED); - - mouse_activate(eventmask != 0); - - result = eventmask; + if (SP != 0) { + if (oldmask) + *oldmask = SP->_mouse_mask; + + if (newmask || SP->_mouse_initialized) { + _nc_mouse_init(SP); + if (SP->_mouse_type != M_NONE) { + result = newmask & + (REPORT_MOUSE_POSITION + | BUTTON_ALT + | BUTTON_CTRL + | BUTTON_SHIFT + | BUTTON_PRESSED + | BUTTON_RELEASED + | BUTTON_CLICKED + | BUTTON_DOUBLE_CLICKED + | BUTTON_TRIPLE_CLICKED); + + mouse_activate(SP, (bool) (result != 0)); + + SP->_mouse_mask = result; + } + } } - - returnCode(result); + returnBits(result); } NCURSES_EXPORT(bool) wenclose(const WINDOW *win, int y, int x) /* check to see if given window encloses given screen location */ { - if (win) { + bool result = FALSE; + + T((T_CALLED("wenclose(%p,%d,%d)"), win, y, x)); + + if (win != 0) { y -= win->_yoffset; - return ((win->_begy <= y && - win->_begx <= x && - (win->_begx + win->_maxx) >= x && - (win->_begy + win->_maxy) >= y) ? TRUE : FALSE); + result = ((win->_begy <= y && + win->_begx <= x && + (win->_begx + win->_maxx) >= x && + (win->_begy + win->_maxy) >= y) ? TRUE : FALSE); } - return FALSE; + returnBool(result); } NCURSES_EXPORT(int) @@ -957,6 +1384,8 @@ mouseinterval(int maxclick) { int oldval; + T((T_CALLED("mouseinterval(%d)"), maxclick)); + if (SP != 0) { oldval = SP->_maxclick; if (maxclick >= 0) @@ -965,7 +1394,7 @@ mouseinterval(int maxclick) oldval = DEFAULT_MAXCLICK; } - return (oldval); + returnCode(oldval); } /* This may be used by other routines to ask for the existence of mouse @@ -973,15 +1402,16 @@ mouseinterval(int maxclick) NCURSES_EXPORT(int) _nc_has_mouse(void) { - return (mousetype == M_NONE ? 0 : 1); + return (SP->_mouse_type == M_NONE ? 0 : 1); } NCURSES_EXPORT(bool) -wmouse_trafo -(const WINDOW *win, int *pY, int *pX, bool to_screen) +wmouse_trafo(const WINDOW *win, int *pY, int *pX, bool to_screen) { bool result = FALSE; + T((T_CALLED("wmouse_trafo(%p,%p,%p,%d)"), win, pY, pX, to_screen)); + if (win && pY && pX) { int y = *pY; int x = *pX; @@ -1003,7 +1433,5 @@ wmouse_trafo *pY = y; } } - return (result); + returnBool(result); } - -/* lib_mouse.c ends here */ diff --git a/lib/libcurses/base/lib_move.c b/lib/libcurses/base/lib_move.c index 629dacbd719..a2f2f793b72 100644 --- a/lib/libcurses/base/lib_move.c +++ b/lib/libcurses/base/lib_move.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_move.c,v 1.3 2001/01/22 18:01:41 millert Exp $ */ +/* $OpenBSD: lib_move.c,v 1.4 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2000,2004 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -42,16 +43,14 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_move.c,v 1.11 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_move.c,v 1.4 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(int) wmove(WINDOW *win, int y, int x) { T((T_CALLED("wmove(%p,%d,%d)"), win, y, x)); - if (win && - x >= 0 && x <= win->_maxx && - y >= 0 && y <= win->_maxy) { + if (LEGALYX(win, y, x)) { win->_curx = (NCURSES_SIZE_T) x; win->_cury = (NCURSES_SIZE_T) y; diff --git a/lib/libcurses/base/lib_mvwin.c b/lib/libcurses/base/lib_mvwin.c index dbd28576f1b..3a6e9d54fb3 100644 --- a/lib/libcurses/base/lib_mvwin.c +++ b/lib/libcurses/base/lib_mvwin.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_mvwin.c,v 1.2 2001/01/22 18:01:41 millert Exp $ */ +/* $OpenBSD: lib_mvwin.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2001,2006 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -42,7 +42,7 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_mvwin.c,v 1.9 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_mvwin.c,v 1.3 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(int) mvwin(WINDOW *win, int by, int bx) @@ -52,6 +52,11 @@ mvwin(WINDOW *win, int by, int bx) if (!win || (win->_flags & _ISPAD)) returnCode(ERR); + /* + * mvwin() should only modify the indices. See test/demo_menus.c and + * test/movewindow.c for examples. + */ +#if 0 /* Copying subwindows is allowed, but it is expensive... */ if (win->_flags & _SUBWIN) { int err = ERR; @@ -71,7 +76,8 @@ mvwin(WINDOW *win, int by, int bx) /* now we have the clone, so relocate win */ werase(win); /* Erase the original place */ - wbkgd(win, parent->_bkgd); /* fill with parents background */ + /* fill with parents background */ + wbkgrnd(win, CHREF(parent->_nc_bkgd)); wsyncup(win); /* Tell the parent(s) */ err = mvderwin(win, @@ -90,6 +96,7 @@ mvwin(WINDOW *win, int by, int bx) } returnCode(err); } +#endif if (by + win->_maxy > screen_lines - 1 || bx + win->_maxx > screen_columns - 1 diff --git a/lib/libcurses/base/lib_newterm.c b/lib/libcurses/base/lib_newterm.c index 0dc1f85592d..18e26bfeea4 100644 --- a/lib/libcurses/base/lib_newterm.c +++ b/lib/libcurses/base/lib_newterm.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_newterm.c,v 1.12 2001/01/22 18:01:42 millert Exp $ */ +/* $OpenBSD: lib_newterm.c,v 1.13 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -49,7 +50,7 @@ #include <term.h> /* clear_screen, cup & friends, cur_term */ #include <tic.h> -MODULE_ID("$From: lib_newterm.c,v 1.50 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_newterm.c,v 1.13 2010/01/12 23:22:06 nicm Exp $") #ifndef ONLCR /* Allows compilation under the QNX 4.2 OS */ #define ONLCR 0 @@ -63,21 +64,30 @@ MODULE_ID("$From: lib_newterm.c,v 1.50 2000/12/10 02:43:27 tom Exp $") * The newterm function also initializes terminal settings, and since initscr * is supposed to behave as if it calls newterm, we do it here. */ -static inline int +static NCURSES_INLINE int _nc_initscr(void) { + int result = ERR; + /* for extended XPG4 conformance requires cbreak() at this point */ /* (SVr4 curses does this anyway) */ - cbreak(); + if (cbreak() == OK) { + TTY buf; + buf = cur_term->Nttyb; #ifdef TERMIOS - cur_term->Nttyb.c_lflag &= ~(ECHO | ECHONL); - cur_term->Nttyb.c_iflag &= ~(ICRNL | INLCR | IGNCR); - cur_term->Nttyb.c_oflag &= ~(ONLCR); + buf.c_lflag &= ~(ECHO | ECHONL); + buf.c_iflag &= ~(ICRNL | INLCR | IGNCR); + buf.c_oflag &= ~(ONLCR); +#elif HAVE_SGTTY_H + buf.sg_flags &= ~(ECHO | CRMOD); #else - cur_term->Nttyb.sg_flags &= ~(ECHO | CRMOD); + memset(&buf, 0, sizeof(buf)); #endif - return _nc_set_tty_mode(&cur_term->Nttyb); + if ((result = _nc_set_tty_mode(&buf)) == OK) + cur_term->Nttyb = buf; + } + return result; } /* @@ -86,145 +96,142 @@ _nc_initscr(void) * aside from possibly delaying a filter() call until some terminals have been * initialized. */ -static int filter_mode = FALSE; - NCURSES_EXPORT(void) filter(void) { - filter_mode = TRUE; + START_TRACE(); + T((T_CALLED("filter"))); + _nc_prescreen.filter_mode = TRUE; + returnVoid; } +#if NCURSES_EXT_FUNCS +/* + * An extension, allowing the application to open a new screen without + * requiring it to also be filtered. + */ +NCURSES_EXPORT(void) +nofilter(void) +{ + START_TRACE(); + T((T_CALLED("nofilter"))); + _nc_prescreen.filter_mode = FALSE; + returnVoid; +} +#endif + NCURSES_EXPORT(SCREEN *) -newterm -(NCURSES_CONST char *name, FILE * ofp, FILE * ifp) +newterm(NCURSES_CONST char *name, FILE *ofp, FILE *ifp) { + int value; int errret; - int slk_format = _nc_slk_format; SCREEN *current; -#ifdef TRACE - int t = _nc_getenv_num("NCURSES_TRACE"); - - if (t >= 0) - trace(t); -#endif + SCREEN *result = 0; + TERMINAL *its_term; + START_TRACE(); T((T_CALLED("newterm(\"%s\",%p,%p)"), name, ofp, ifp)); - /* this loads the capability entry, then sets LINES and COLS */ - if (setupterm(name, fileno(ofp), &errret) == ERR) - return 0; - - /* implement filter mode */ - if (filter_mode) { - LINES = 1; - - if (VALID_NUMERIC(init_tabs)) - TABSIZE = init_tabs; - else - TABSIZE = 8; + _nc_init_pthreads(); + _nc_lock_global(curses); - T(("TABSIZE = %d", TABSIZE)); - - clear_screen = 0; - cursor_down = parm_down_cursor = 0; - cursor_address = 0; - cursor_up = parm_up_cursor = 0; - row_address = 0; - - cursor_home = carriage_return; - } - - /* If we must simulate soft labels, grab off the line to be used. - We assume that we must simulate, if it is none of the standard - formats (4-4 or 3-2-3) for which there may be some hardware - support. */ - if (num_labels <= 0 || !SLK_STDFMT(slk_format)) - if (slk_format) { - if (ERR == _nc_ripoffline(-SLK_LINES(slk_format), - _nc_slk_initialize)) - return 0; - } - /* this actually allocates the screen structure, and saves the - * original terminal settings. - */ current = SP; - _nc_set_screen(0); - if (_nc_setupscreen(LINES, COLS, ofp) == ERR) { - _nc_set_screen(current); - return 0; - } + its_term = (SP ? SP->_term : 0); - /* if the terminal type has real soft labels, set those up */ - if (slk_format && num_labels > 0 && SLK_STDFMT(slk_format)) - _nc_slk_initialize(stdscr, COLS); + /* this loads the capability entry, then sets LINES and COLS */ + if (setupterm(name, fileno(ofp), &errret) != ERR) { + int slk_format = _nc_globals.slk_format; + + /* + * This actually allocates the screen structure, and saves the original + * terminal settings. + */ + _nc_set_screen(0); + + /* allow user to set maximum escape delay from the environment */ + if ((value = _nc_getenv_num("ESCDELAY")) >= 0) { + set_escdelay(value); + } - SP->_ifd = fileno(ifp); - SP->_checkfd = fileno(ifp); - typeahead(fileno(ifp)); + if (_nc_setupscreen(LINES, + COLS, + ofp, + _nc_prescreen.filter_mode, + slk_format) == ERR) { + _nc_set_screen(current); + result = 0; + } else { + assert(SP != 0); + /* + * In setupterm() we did a set_curterm(), but it was before we set + * SP. So the "current" screen's terminal pointer was overwritten + * with a different terminal. Later, in _nc_setupscreen(), we set + * SP and the terminal pointer in the new screen. + * + * Restore the terminal-pointer for the pre-existing screen, if + * any. + */ + if (current) + current->_term = its_term; + + /* if the terminal type has real soft labels, set those up */ + if (slk_format && num_labels > 0 && SLK_STDFMT(slk_format)) + _nc_slk_initialize(stdscr, COLS); + + SP->_ifd = fileno(ifp); + typeahead(fileno(ifp)); #ifdef TERMIOS - SP->_use_meta = ((cur_term->Ottyb.c_cflag & CSIZE) == CS8 && - !(cur_term->Ottyb.c_iflag & ISTRIP)); + SP->_use_meta = ((cur_term->Ottyb.c_cflag & CSIZE) == CS8 && + !(cur_term->Ottyb.c_iflag & ISTRIP)); #else - SP->_use_meta = FALSE; + SP->_use_meta = FALSE; #endif - SP->_endwin = FALSE; - - /* Check whether we can optimize scrolling under dumb terminals in case - * we do not have any of these capabilities, scrolling optimization - * will be useless. - */ - SP->_scrolling = ((scroll_forward && scroll_reverse) || - ((parm_rindex || parm_insert_line || insert_line) && - (parm_index || parm_delete_line || delete_line))); - - baudrate(); /* sets a field in the SP structure */ - - SP->_keytry = 0; - - /* - * Check for mismatched graphic-rendition capabilities. Most SVr4 - * terminfo trees contain entries that have rmul or rmso equated to - * sgr0 (Solaris curses copes with those entries). We do this only for - * curses, since many termcap applications assume that smso/rmso and - * smul/rmul are paired, and will not function properly if we remove - * rmso or rmul. Curses applications shouldn't be looking at this - * detail. - */ + SP->_endwin = FALSE; + + /* + * Check whether we can optimize scrolling under dumb terminals in + * case we do not have any of these capabilities, scrolling + * optimization will be useless. + */ + SP->_scrolling = ((scroll_forward && scroll_reverse) || + ((parm_rindex || + parm_insert_line || + insert_line) && + (parm_index || + parm_delete_line || + delete_line))); + + baudrate(); /* sets a field in the SP structure */ + + SP->_keytry = 0; + + /* + * Check for mismatched graphic-rendition capabilities. Most SVr4 + * terminfo trees contain entries that have rmul or rmso equated to + * sgr0 (Solaris curses copes with those entries). We do this only + * for curses, since many termcap applications assume that + * smso/rmso and smul/rmul are paired, and will not function + * properly if we remove rmso or rmul. Curses applications + * shouldn't be looking at this detail. + */ #define SGR0_TEST(mode) (mode != 0) && (exit_attribute_mode == 0 || strcmp(mode, exit_attribute_mode)) - SP->_use_rmso = SGR0_TEST(exit_standout_mode); - SP->_use_rmul = SGR0_TEST(exit_underline_mode); - -#if USE_WIDEC_SUPPORT - /* - * XFree86 xterm can be configured to support UTF-8 based on environment - * variable settings. - */ - { - char *s; - s = getenv("LC_ALL"); - if (s == NULL || *s == '\0') { - s = getenv("LC_CTYPE"); - if (s == NULL || *s == '\0') { - s = getenv("LANG"); - } - } - if (s != NULL && *s != '\0' && strstr(s, "UTF-8") != NULL) { - SP->_outch = _nc_utf8_outch; - } - } -#endif + SP->_use_rmso = SGR0_TEST(exit_standout_mode); + SP->_use_rmul = SGR0_TEST(exit_underline_mode); - /* compute movement costs so we can do better move optimization */ - _nc_mvcur_init(); + /* compute movement costs so we can do better move optimization */ + _nc_mvcur_init(); - /* initialize terminal to a sane state */ - _nc_screen_init(); + /* initialize terminal to a sane state */ + _nc_screen_init(); - /* Initialize the terminal line settings. */ - _nc_initscr(); + /* Initialize the terminal line settings. */ + _nc_initscr(); - _nc_signal_handler(TRUE); + _nc_signal_handler(TRUE); - T((T_RETURN("%p"), SP)); - return (SP); + result = SP; + } + } + _nc_unlock_global(curses); + returnSP(result); } diff --git a/lib/libcurses/base/lib_newwin.c b/lib/libcurses/base/lib_newwin.c index 5e25d33f3cb..64fca59d06a 100644 --- a/lib/libcurses/base/lib_newwin.c +++ b/lib/libcurses/base/lib_newwin.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_newwin.c,v 1.5 2009/11/11 18:34:10 deraadt Exp $ */ +/* $OpenBSD: lib_newwin.c,v 1.6 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -41,8 +42,40 @@ */ #include <curses.priv.h> +#include <stddef.h> -MODULE_ID("$From: lib_newwin.c,v 1.27 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_newwin.c,v 1.6 2010/01/12 23:22:06 nicm Exp $") + +#define window_is(name) ((sp)->_##name == win) + +#if USE_REENTRANT +#define remove_window(name) \ + sp->_##name = 0 +#else +#define remove_window(name) \ + sp->_##name = 0; \ + if (win == name) \ + name = 0 +#endif + +static void +remove_window_from_screen(WINDOW *win) +{ + SCREEN *sp; + + for (each_screen(sp)) { + if (window_is(curscr)) { + remove_window(curscr); + break; + } else if (window_is(stdscr)) { + remove_window(stdscr); + break; + } else if (window_is(newscr)) { + remove_window(newscr); + break; + } + } +} NCURSES_EXPORT(int) _nc_freewin(WINDOW *win) @@ -51,44 +84,43 @@ _nc_freewin(WINDOW *win) int i; int result = ERR; + T((T_CALLED("_nc_freewin(%p)"), win)); + if (win != 0) { - for (p = _nc_windows, q = 0; p != 0; q = p, p = p->next) { - if (p->win == win) { - if (q == 0) - _nc_windows = p->next; - else - q->next = p->next; - free(p); - - if (!(win->_flags & _SUBWIN)) { - for (i = 0; i <= win->_maxy; i++) - FreeIfNeeded(win->_line[i].text); + if (_nc_try_global(curses) == 0) { + q = 0; + for (each_window(p)) { + if (&(p->win) == win) { + remove_window_from_screen(win); + if (q == 0) + _nc_windows = p->next; + else + q->next = p->next; + + if (!(win->_flags & _SUBWIN)) { + for (i = 0; i <= win->_maxy; i++) + FreeIfNeeded(win->_line[i].text); + } + free(win->_line); + free(p); + + result = OK; + T(("...deleted win=%p", win)); + break; } - free(win->_line); - free(win); - - if (win == curscr) - curscr = 0; - if (win == stdscr) - stdscr = 0; - if (win == newscr) - newscr = 0; - - result = OK; - T(("...deleted win=%p", win)); - break; + q = p; } + _nc_unlock_global(curses); } } - return result; + returnCode(result); } NCURSES_EXPORT(WINDOW *) -newwin -(int num_lines, int num_columns, int begy, int begx) +newwin(int num_lines, int num_columns, int begy, int begx) { WINDOW *win; - chtype *ptr; + NCURSES_CH_T *ptr; int i; T((T_CALLED("newwin(%d,%d,%d,%d)"), num_lines, num_columns, begy, begx)); @@ -101,31 +133,26 @@ newwin if (num_columns == 0) num_columns = screen_columns - begx; - if (num_columns + begx > SP->_columns || num_lines + begy > SP->_lines_avail) - returnWin(0); - if ((win = _nc_makenew(num_lines, num_columns, begy, begx, 0)) == 0) returnWin(0); for (i = 0; i < num_lines; i++) { - win->_line[i].text = typeCalloc(chtype, (unsigned) num_columns); + win->_line[i].text = typeCalloc(NCURSES_CH_T, (unsigned) num_columns); if (win->_line[i].text == 0) { (void) _nc_freewin(win); returnWin(0); } - for (ptr = win->_line[i].text; ptr < win->_line[i].text + - num_columns;) - *ptr++ = ' '; + for (ptr = win->_line[i].text; + ptr < win->_line[i].text + num_columns; + ptr++) + SetChar(*ptr, BLANK_TEXT, BLANK_ATTR); } - T(("newwin: returned window is %p", win)); - returnWin(win); } NCURSES_EXPORT(WINDOW *) -derwin -(WINDOW *orig, int num_lines, int num_columns, int begy, int begx) +derwin(WINDOW *orig, int num_lines, int num_columns, int begy, int begx) { WINDOW *win; int i; @@ -135,7 +162,7 @@ derwin begy, begx)); /* - ** make sure window fits inside the original one + * make sure window fits inside the original one */ if (begy < 0 || begx < 0 || orig == 0 || num_lines < 0 || num_columns < 0) returnWin(0); @@ -158,25 +185,22 @@ derwin win->_pary = begy; win->_parx = begx; - win->_attrs = orig->_attrs; - win->_bkgd = orig->_bkgd; + WINDOW_ATTRS(win) = WINDOW_ATTRS(orig); + win->_nc_bkgd = orig->_nc_bkgd; for (i = 0; i < num_lines; i++) win->_line[i].text = &orig->_line[begy++].text[begx]; win->_parent = orig; - T(("derwin: returned window is %p", win)); - returnWin(win); } NCURSES_EXPORT(WINDOW *) -subwin -(WINDOW *w, int l, int c, int y, int x) +subwin(WINDOW *w, int l, int c, int y, int x) { T((T_CALLED("subwin(%p, %d, %d, %d, %d)"), w, l, c, y, x)); - T(("parent has begy = %d, begx = %d", w->_begy, w->_begx)); + T(("parent has begy = %ld, begx = %ld", (long) w->_begy, (long) w->_begx)); returnWin(derwin(w, l, c, y - w->_begy, x - w->_begx)); } @@ -189,33 +213,33 @@ dimension_limit(int value) } NCURSES_EXPORT(WINDOW *) -_nc_makenew -(int num_lines, int num_columns, int begy, int begx, int flags) +_nc_makenew(int num_lines, int num_columns, int begy, int begx, int flags) { int i; WINDOWLIST *wp; WINDOW *win; bool is_pad = (flags & _ISPAD); - T(("_nc_makenew(%d,%d,%d,%d)", num_lines, num_columns, begy, begx)); + T((T_CALLED("_nc_makenew(%d,%d,%d,%d)"), num_lines, num_columns, begy, begx)); + + if (SP == 0) + returnWin(0); if (!dimension_limit(num_lines) || !dimension_limit(num_columns)) - return 0; + returnWin(0); if ((wp = typeCalloc(WINDOWLIST, 1)) == 0) - return 0; + returnWin(0); - if ((win = typeCalloc(WINDOW, 1)) == 0) { - free(wp); - return 0; - } + win = &(wp->win); if ((win->_line = typeCalloc(struct ldat, ((unsigned) num_lines))) == 0) { free(wp); - free(win); - return 0; + returnWin(0); } + _nc_lock_global(curses); + win->_curx = 0; win->_cury = 0; win->_maxy = num_lines - 1; @@ -225,8 +249,8 @@ _nc_makenew win->_yoffset = SP->_topstolen; win->_flags = flags; - win->_attrs = A_NORMAL; - win->_bkgd = BLANK; + WINDOW_ATTRS(win) = A_NORMAL; + SetChar(win->_nc_bkgd, BLANK_TEXT, BLANK_ATTR); win->_clear = is_pad ? FALSE : (num_lines == screen_lines && num_columns == screen_columns); @@ -289,10 +313,28 @@ _nc_makenew } wp->next = _nc_windows; - wp->win = win; + wp->screen = SP; _nc_windows = wp; T((T_CREATE("window %p"), win)); - return (win); + _nc_unlock_global(curses); + returnWin(win); +} + +/* + * wgetch() and other functions with a WINDOW* parameter may use a SCREEN* + * internally, and it is useful to allow those to be invoked without switching + * SCREEN's, e.g., for multi-threaded applications. + */ +NCURSES_EXPORT(SCREEN *) +_nc_screen_of(WINDOW *win) +{ + SCREEN *sp = 0; + + if (win != 0) { + WINDOWLIST *wp = (WINDOWLIST *) win; + sp = wp->screen; + } + return (sp); } diff --git a/lib/libcurses/base/lib_nl.c b/lib/libcurses/base/lib_nl.c index b24cb3ec14e..74ac920ed53 100644 --- a/lib/libcurses/base/lib_nl.c +++ b/lib/libcurses/base/lib_nl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_nl.c,v 1.5 2001/01/22 18:01:42 millert Exp $ */ +/* $OpenBSD: lib_nl.c,v 1.6 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * @@ -44,7 +44,7 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_nl.c,v 1.8 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_nl.c,v 1.6 2010/01/12 23:22:06 nicm Exp $") #ifdef __EMX__ #include <io.h> diff --git a/lib/libcurses/base/lib_overlay.c b/lib/libcurses/base/lib_overlay.c index 7e3c169f08c..a61ebf3f1fc 100644 --- a/lib/libcurses/base/lib_overlay.c +++ b/lib/libcurses/base/lib_overlay.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_overlay.c,v 1.2 2001/01/22 18:01:42 millert Exp $ */ +/* $OpenBSD: lib_overlay.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -42,30 +42,61 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_overlay.c,v 1.14 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_overlay.c,v 1.3 2010/01/12 23:22:06 nicm Exp $") static int -overlap(const WINDOW *const s, WINDOW *const d, int const flag) +overlap(const WINDOW *const src, WINDOW *const dst, int const flag) { - int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol; - - T(("overlap : sby %d, sbx %d, smy %d, smx %d, dby %d, dbx %d, dmy %d, dmx %d", - s->_begy, s->_begx, s->_maxy, s->_maxx, - d->_begy, d->_begx, d->_maxy, d->_maxx)); - - if (!s || !d) - returnCode(ERR); - - sminrow = max(s->_begy, d->_begy) - s->_begy; - smincol = max(s->_begx, d->_begx) - s->_begx; - dminrow = max(s->_begy, d->_begy) - d->_begy; - dmincol = max(s->_begx, d->_begx) - d->_begx; - dmaxrow = min(s->_maxy + s->_begy, d->_maxy + d->_begy) - d->_begy; - dmaxcol = min(s->_maxx + s->_begx, d->_maxx + d->_begx) - d->_begx; - - return (copywin(s, d, - sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol, - flag)); + int rc = ERR; + int sx1, sy1, sx2, sy2; + int dx1, dy1, dx2, dy2; + int sminrow, smincol; + int dminrow, dmincol; + int dmaxrow, dmaxcol; + + T((T_CALLED("overlap(%p,%p,%d)"), src, dst, flag)); + + if (src != 0 && dst != 0) { + _nc_lock_global(curses); + + T(("src : begy %ld, begx %ld, maxy %ld, maxx %ld", + (long) src->_begy, + (long) src->_begx, + (long) src->_maxy, + (long) src->_maxx)); + T(("dst : begy %ld, begx %ld, maxy %ld, maxx %ld", + (long) dst->_begy, + (long) dst->_begx, + (long) dst->_maxy, + (long) dst->_maxx)); + + sx1 = src->_begx; + sy1 = src->_begy; + sx2 = sx1 + src->_maxx; + sy2 = sy1 + src->_maxy; + + dx1 = dst->_begx; + dy1 = dst->_begy; + dx2 = dx1 + dst->_maxx; + dy2 = dy1 + dst->_maxy; + + if (dx2 >= sx1 && dx1 <= sx2 && dy2 >= sy1 && dy1 <= sy2) { + sminrow = max(sy1, dy1) - sy1; + smincol = max(sx1, dx1) - sx1; + dminrow = max(sy1, dy1) - dy1; + dmincol = max(sx1, dx1) - dx1; + dmaxrow = min(sy2, dy2) - dy1; + dmaxcol = min(sx2, dx2) - dx1; + + rc = copywin(src, dst, + sminrow, smincol, + dminrow, dmincol, + dmaxrow, dmaxcol, + flag); + } + _nc_unlock_global(curses); + } + returnCode(rc); } /* @@ -103,59 +134,75 @@ overwrite(const WINDOW *win1, WINDOW *win2) } NCURSES_EXPORT(int) -copywin -(const WINDOW *src, WINDOW *dst, - int sminrow, int smincol, - int dminrow, int dmincol, int dmaxrow, int dmaxcol, - int over) +copywin(const WINDOW *src, WINDOW *dst, + int sminrow, int smincol, + int dminrow, int dmincol, + int dmaxrow, int dmaxcol, + int over) { + int rc = ERR; int sx, sy, dx, dy; bool touched; - chtype bk = AttrOf(dst->_bkgd); - chtype mask = ~(chtype) ((bk & A_COLOR) ? A_COLOR : 0); + attr_t bk; + attr_t mask; T((T_CALLED("copywin(%p, %p, %d, %d, %d, %d, %d, %d, %d)"), src, dst, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol, over)); - if (!src || !dst) - returnCode(ERR); - - /* make sure rectangle exists in source */ - if ((sminrow + dmaxrow - dminrow) > (src->_maxy + 1) || - (smincol + dmaxcol - dmincol) > (src->_maxx + 1)) { - returnCode(ERR); - } - - T(("rectangle exists in source")); - - /* make sure rectangle fits in destination */ - if (dmaxrow > dst->_maxy || dmaxcol > dst->_maxx) { - returnCode(ERR); - } - - T(("rectangle fits in destination")); - - for (dy = dminrow, sy = sminrow; dy <= dmaxrow; sy++, dy++) { - touched = FALSE; - for (dx = dmincol, sx = smincol; dx <= dmaxcol; sx++, dx++) { - if (over) { - if ((TextOf(src->_line[sy].text[sx]) != ' ') && - (dst->_line[dy].text[dx] != src->_line[sy].text[sx])) { - dst->_line[dy].text[dx] = - (src->_line[sy].text[sx] & mask) | bk; - touched = TRUE; - } - } else { - if (dst->_line[dy].text[dx] != src->_line[sy].text[sx]) { - dst->_line[dy].text[dx] = src->_line[sy].text[sx]; - touched = TRUE; + if (src && dst) { + _nc_lock_global(curses); + + bk = AttrOf(dst->_nc_bkgd); + mask = ~(attr_t) ((bk & A_COLOR) ? A_COLOR : 0); + + /* make sure rectangle exists in source */ + if ((sminrow + dmaxrow - dminrow) <= (src->_maxy + 1) && + (smincol + dmaxcol - dmincol) <= (src->_maxx + 1)) { + + T(("rectangle exists in source")); + + /* make sure rectangle fits in destination */ + if (dmaxrow <= dst->_maxy && dmaxcol <= dst->_maxx) { + + T(("rectangle fits in destination")); + + for (dy = dminrow, sy = sminrow; + dy <= dmaxrow; + sy++, dy++) { + + touched = FALSE; + for (dx = dmincol, sx = smincol; + dx <= dmaxcol; + sx++, dx++) { + if (over) { + if ((CharOf(src->_line[sy].text[sx]) != L(' ')) && + (!CharEq(dst->_line[dy].text[dx], + src->_line[sy].text[sx]))) { + dst->_line[dy].text[dx] = + src->_line[sy].text[sx]; + SetAttr(dst->_line[dy].text[dx], + ((AttrOf(src->_line[sy].text[sx]) & + mask) | bk)); + touched = TRUE; + } + } else { + if (!CharEq(dst->_line[dy].text[dx], + src->_line[sy].text[sx])) { + dst->_line[dy].text[dx] = + src->_line[sy].text[sx]; + touched = TRUE; + } + } + } + if (touched) { + touchline(dst, dminrow, (dmaxrow - dminrow + 1)); + } } + T(("finished copywin")); + rc = OK; } } - if (touched) { - touchline(dst, 0, getmaxy(dst)); - } + _nc_unlock_global(curses); } - T(("finished copywin")); - returnCode(OK); + returnCode(rc); } diff --git a/lib/libcurses/base/lib_pad.c b/lib/libcurses/base/lib_pad.c index f53f6a0f2a6..50463e24a23 100644 --- a/lib/libcurses/base/lib_pad.c +++ b/lib/libcurses/base/lib_pad.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_pad.c,v 1.4 2001/01/22 18:01:42 millert Exp $ */ +/* $OpenBSD: lib_pad.c,v 1.5 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2004,2006 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -42,13 +42,13 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_pad.c,v 1.32 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_pad.c,v 1.5 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(WINDOW *) newpad(int l, int c) { WINDOW *win; - chtype *ptr; + NCURSES_CH_T *ptr; int i; T((T_CALLED("newpad(%d, %d)"), l, c)); @@ -61,20 +61,19 @@ newpad(int l, int c) for (i = 0; i < l; i++) { if_USE_SCROLL_HINTS(win->_line[i].oldindex = _NEWINDEX); - if ((win->_line[i].text = typeCalloc(chtype, ((size_t) c))) == 0) { + if ((win->_line[i].text = typeCalloc(NCURSES_CH_T, ((size_t) c))) == 0) { (void) _nc_freewin(win); returnWin(0); } - for (ptr = win->_line[i].text; ptr < win->_line[i].text + c;) - *ptr++ = ' '; + for (ptr = win->_line[i].text; ptr < win->_line[i].text + c; ptr++) + SetChar(*ptr, BLANK_TEXT, BLANK_ATTR); } returnWin(win); } NCURSES_EXPORT(WINDOW *) -subpad -(WINDOW *orig, int l, int c, int begy, int begx) +subpad(WINDOW *orig, int l, int c, int begy, int begx) { WINDOW *win = (WINDOW *) 0; @@ -89,9 +88,13 @@ subpad } NCURSES_EXPORT(int) -prefresh -(WINDOW *win, int pminrow, int pmincol, - int sminrow, int smincol, int smaxrow, int smaxcol) +prefresh(WINDOW *win, + int pminrow, + int pmincol, + int sminrow, + int smincol, + int smaxrow, + int smaxcol) { T((T_CALLED("prefresh()"))); if (pnoutrefresh(win, pminrow, pmincol, sminrow, smincol, smaxrow, @@ -103,9 +106,13 @@ prefresh } NCURSES_EXPORT(int) -pnoutrefresh -(WINDOW *win, int pminrow, int pmincol, - int sminrow, int smincol, int smaxrow, int smaxcol) +pnoutrefresh(WINDOW *win, + int pminrow, + int pmincol, + int sminrow, + int smincol, + int smaxrow, + int smaxcol) { NCURSES_SIZE_T i, j; NCURSES_SIZE_T m, n; @@ -140,8 +147,10 @@ pnoutrefresh pmaxrow = pminrow + smaxrow - sminrow; pmaxcol = pmincol + smaxcol - smincol; - T((" pminrow + smaxrow - sminrow %d, win->_maxy %d", pmaxrow, win->_maxy)); - T((" pmincol + smaxcol - smincol %d, win->_maxx %d", pmaxcol, win->_maxx)); + T((" pminrow + smaxrow - sminrow %ld, win->_maxy %ld", + (long) pmaxrow, (long) win->_maxy)); + T((" pmincol + smaxcol - smincol %ld, win->_maxx %ld", + (long) pmaxcol, (long) win->_maxx)); /* * Trim the caller's screen size back to the actual limits. @@ -155,8 +164,8 @@ pnoutrefresh pmaxcol = pmincol + smaxcol - smincol; } - if (smaxrow > screen_lines - || smaxcol > screen_columns + if (smaxrow >= screen_lines + || smaxcol >= screen_columns || sminrow > smaxrow || smincol > smaxcol) returnCode(ERR); @@ -195,10 +204,21 @@ pnoutrefresh i++, m++) { register struct ldat *nline = &newscr->_line[m]; register struct ldat *oline = &win->_line[i]; - for (j = pmincol, n = smincol; j <= pmaxcol; j++, n++) { - if (oline->text[j] != nline->text[n]) { - nline->text[n] = oline->text[j]; + NCURSES_CH_T ch = oline->text[j]; +#if USE_WIDEC_SUPPORT + /* + * Special case for leftmost character of the displayed area. + * Only half of a double-width character may be visible. + */ + if (j == pmincol + && j > 0 + && isWidecExt(ch)) { + SetChar(ch, L(' '), AttrOf(oline->text[j - 1])); + } +#endif + if (!CharEq(ch, nline->text[n])) { + nline->text[n] = ch; CHANGED_CELL(nline, n); } } diff --git a/lib/libcurses/base/lib_printw.c b/lib/libcurses/base/lib_printw.c index 3a567584b0e..165d6ae719c 100644 --- a/lib/libcurses/base/lib_printw.c +++ b/lib/libcurses/base/lib_printw.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_printw.c,v 1.2 2001/01/22 18:01:42 millert Exp $ */ +/* $OpenBSD: lib_printw.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2003,2005 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -41,79 +41,100 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_printw.c,v 1.9 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_printw.c,v 1.3 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(int) -printw(NCURSES_CONST char *fmt,...) +printw(const char *fmt,...) { va_list argp; int code; - T(("printw(%s,...) called", _nc_visbuf(fmt))); +#ifdef TRACE + va_start(argp, fmt); + T((T_CALLED("printw(%s%s)"), + _nc_visbuf(fmt), _nc_varargs(fmt, argp))); + va_end(argp); +#endif va_start(argp, fmt); code = vwprintw(stdscr, fmt, argp); va_end(argp); - return code; + returnCode(code); } NCURSES_EXPORT(int) -wprintw(WINDOW *win, NCURSES_CONST char *fmt,...) +wprintw(WINDOW *win, const char *fmt,...) { va_list argp; int code; - T(("wprintw(%p,%s,...) called", win, _nc_visbuf(fmt))); +#ifdef TRACE + va_start(argp, fmt); + T((T_CALLED("wprintw(%p,%s%s)"), + win, _nc_visbuf(fmt), _nc_varargs(fmt, argp))); + va_end(argp); +#endif va_start(argp, fmt); code = vwprintw(win, fmt, argp); va_end(argp); - return code; + returnCode(code); } NCURSES_EXPORT(int) -mvprintw(int y, int x, NCURSES_CONST char *fmt,...) +mvprintw(int y, int x, const char *fmt,...) { va_list argp; - int code = move(y, x); + int code; + +#ifdef TRACE + va_start(argp, fmt); + T((T_CALLED("mvprintw(%d,%d,%s%s)"), + y, x, _nc_visbuf(fmt), _nc_varargs(fmt, argp))); + va_end(argp); +#endif - if (code != ERR) { + if ((code = move(y, x)) != ERR) { va_start(argp, fmt); code = vwprintw(stdscr, fmt, argp); va_end(argp); } - return code; + returnCode(code); } NCURSES_EXPORT(int) -mvwprintw -(WINDOW *win, int y, int x, NCURSES_CONST char *fmt,...) +mvwprintw(WINDOW *win, int y, int x, const char *fmt,...) { va_list argp; - int code = wmove(win, y, x); + int code; - if (code != ERR) { +#ifdef TRACE + va_start(argp, fmt); + T((T_CALLED("mvwprintw(%d,%d,%p,%s%s)"), + y, x, win, _nc_visbuf(fmt), _nc_varargs(fmt, argp))); + va_end(argp); +#endif + + if ((code = wmove(win, y, x)) != ERR) { va_start(argp, fmt); code = vwprintw(win, fmt, argp); va_end(argp); } - return code; + returnCode(code); } NCURSES_EXPORT(int) -vwprintw -(WINDOW *win, NCURSES_CONST char *fmt, va_list argp) +vwprintw(WINDOW *win, const char *fmt, va_list argp) { - char *buf = _nc_printf_string(fmt, argp); + char *buf; int code = ERR; - if (buf != 0) { + T((T_CALLED("vwprintw(%p,%s,va_list)"), win, _nc_visbuf(fmt))); + + if ((buf = _nc_printf_string(fmt, argp)) != 0) { code = waddstr(win, buf); -#if USE_SAFE_SPRINTF - free(buf); -#endif } - return code; + returnCode(code); } diff --git a/lib/libcurses/base/lib_redrawln.c b/lib/libcurses/base/lib_redrawln.c index 82ce92b216b..d300a7c7ee0 100644 --- a/lib/libcurses/base/lib_redrawln.c +++ b/lib/libcurses/base/lib_redrawln.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_redrawln.c,v 1.2 2001/01/22 18:01:43 millert Exp $ */ +/* $OpenBSD: lib_redrawln.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -41,30 +41,45 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_redrawln.c,v 1.9 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_redrawln.c,v 1.3 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(int) wredrawln(WINDOW *win, int beg, int num) { int i; int end; - size_t len = (win->_maxx + 1) * sizeof(chtype); + size_t len; T((T_CALLED("wredrawln(%p,%d,%d)"), win, beg, num)); + if (win == 0) + returnCode(ERR); + if (beg < 0) beg = 0; if (touchline(win, beg, num) == ERR) returnCode(ERR); + if (touchline(curscr, beg + win->_begy, num) == ERR) + returnCode(ERR); + end = beg + num; + if (end > curscr->_maxy + 1) + end = curscr->_maxy + 1; if (end > win->_maxy + 1) end = win->_maxy + 1; + len = (win->_maxx + 1); + if (len > (size_t) (curscr->_maxx + 1)) + len = (size_t) (curscr->_maxx + 1); + len *= sizeof(curscr->_line[0].text[0]); + for (i = beg; i < end; i++) { - memset(curscr->_line[i + win->_begy].text + win->_begx, 0, len); - _nc_make_oldhash(i + win->_begy); + int crow = i + win->_begy; + + memset(curscr->_line[crow].text + win->_begx, 0, len); + _nc_make_oldhash(crow); } returnCode(OK); diff --git a/lib/libcurses/base/lib_refresh.c b/lib/libcurses/base/lib_refresh.c index d3d65e7434a..d0571b99212 100644 --- a/lib/libcurses/base/lib_refresh.c +++ b/lib/libcurses/base/lib_refresh.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_refresh.c,v 1.4 2001/01/22 18:01:43 millert Exp $ */ +/* $OpenBSD: lib_refresh.c,v 1.5 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -42,7 +43,7 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_refresh.c,v 1.28 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_refresh.c,v 1.5 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(int) wrefresh(WINDOW *win) @@ -51,7 +52,9 @@ wrefresh(WINDOW *win) T((T_CALLED("wrefresh(%p)"), win)); - if (win == curscr) { + if (win == 0) { + code = ERR; + } else if (win == curscr) { curscr->_clear = TRUE; code = doupdate(); } else if ((code = wnoutrefresh(win)) == OK) { @@ -73,18 +76,20 @@ NCURSES_EXPORT(int) wnoutrefresh(WINDOW *win) { NCURSES_SIZE_T limit_x; - NCURSES_SIZE_T i, j; + NCURSES_SIZE_T src_row, src_col; NCURSES_SIZE_T begx; NCURSES_SIZE_T begy; - NCURSES_SIZE_T m, n; + NCURSES_SIZE_T dst_row, dst_col; #if USE_SCROLL_HINTS bool wide; #endif T((T_CALLED("wnoutrefresh(%p)"), win)); #ifdef TRACE - if (_nc_tracing & TRACE_UPDATE) + if (USE_TRACEF(TRACE_UPDATE)) { _tracedump("...win", win); + _nc_unlock_global(tracef); + } #endif /* TRACE */ /* @@ -98,8 +103,8 @@ wnoutrefresh(WINDOW *win) begx = win->_begx; begy = win->_begy; - newscr->_bkgd = win->_bkgd; - newscr->_attrs = win->_attrs; + newscr->_nc_bkgd = win->_nc_bkgd; + WINDOW_ATTRS(newscr) = WINDOW_ATTRS(win); /* merge in change information from all subwindows of this window */ wsyncdown(win); @@ -131,28 +136,121 @@ wnoutrefresh(WINDOW *win) * so we'll force the issue. */ - /* limit(n) */ + /* limit(dst_col) */ limit_x = win->_maxx; - /* limit(j) */ - if (limit_x > win->_maxx) - limit_x = win->_maxx; + /* limit(src_col) */ + if (limit_x > newscr->_maxx - begx) + limit_x = newscr->_maxx - begx; - for (i = 0, m = begy + win->_yoffset; - i <= win->_maxy && m <= newscr->_maxy; - i++, m++) { - register struct ldat *nline = &newscr->_line[m]; - register struct ldat *oline = &win->_line[i]; + for (src_row = 0, dst_row = begy + win->_yoffset; + src_row <= win->_maxy && dst_row <= newscr->_maxy; + src_row++, dst_row++) { + register struct ldat *nline = &newscr->_line[dst_row]; + register struct ldat *oline = &win->_line[src_row]; if (oline->firstchar != _NOCHANGE) { - int last = oline->lastchar; + int last_src = oline->lastchar; + + if (last_src > limit_x) + last_src = limit_x; + + src_col = oline->firstchar; + dst_col = src_col + begx; + + if_WIDEC({ + register int j; + + /* + * Ensure that we will copy complete multi-column characters + * on the left-boundary. + */ + if (isWidecExt(oline->text[src_col])) { + j = 1 + dst_col - WidecExt(oline->text[src_col]); + if (j < 0) + j = 0; + if (dst_col > j) { + src_col -= (dst_col - j); + dst_col = j; + } + } + + /* + * Ensure that we will copy complete multi-column characters + * on the right-boundary. + */ + j = last_src; + if (WidecExt(oline->text[j])) { + ++j; + while (j <= limit_x) { + if (isWidecBase(oline->text[j])) { + break; + } else { + last_src = j; + } + ++j; + } + } + }); - if (last > limit_x) - last = limit_x; + if_WIDEC({ + static cchar_t blank = BLANK; + int last_dst = begx + ((last_src < win->_maxx) + ? last_src + : win->_maxx); + int fix_left = dst_col; + int fix_right = last_dst; + register int j; - for (j = oline->firstchar, n = j + begx; j <= last; j++, n++) { - if (oline->text[j] != nline->text[n]) { - nline->text[n] = oline->text[j]; - CHANGED_CELL(nline, n); + /* + * Check for boundary cases where we may overwrite part of a + * multi-column character. For those, wipe the remainder of + * the character to blanks. + */ + j = dst_col; + if (isWidecExt(nline->text[j])) { + /* + * On the left, we only care about multi-column characters + * that extend into the changed region. + */ + fix_left = 1 + j - WidecExt(nline->text[j]); + if (fix_left < 0) + fix_left = 0; /* only if cell is corrupt */ + } + + j = last_dst; + if (WidecExt(nline->text[j]) != 0) { + /* + * On the right, any multi-column character is a problem, + * unless it happens to be contained in the change, and + * ending at the right boundary of the change. The + * computation for 'fix_left' accounts for the left-side of + * this character. Find the end of the character. + */ + ++j; + while (j <= newscr->_maxx && isWidecExt(nline->text[j])) { + fix_right = j++; + } + } + + /* + * The analysis is simpler if we do the clearing afterwards. + * Do that now. + */ + if (fix_left < dst_col || fix_right > last_dst) { + for (j = fix_left; j <= fix_right; ++j) { + nline->text[j] = blank; + CHANGED_CELL(nline, j); + } + } + }); + + /* + * Copy the changed text. + */ + for (; src_col <= last_src; src_col++, dst_col++) { + if (!CharEq(oline->text[src_col], nline->text[dst_col])) { + nline->text[dst_col] = oline->text[src_col]; + CHANGED_CELL(nline, dst_col); } } @@ -161,13 +259,14 @@ wnoutrefresh(WINDOW *win) if (wide) { int oind = oline->oldindex; - nline->oldindex = (oind == _NEWINDEX) ? _NEWINDEX : begy + oind - + win->_yoffset; + nline->oldindex = ((oind == _NEWINDEX) + ? _NEWINDEX + : (begy + oind + win->_yoffset)); } #endif /* USE_SCROLL_HINTS */ oline->firstchar = oline->lastchar = _NOCHANGE; - if_USE_SCROLL_HINTS(oline->oldindex = i); + if_USE_SCROLL_HINTS(oline->oldindex = src_row); } if (win->_clear) { @@ -182,8 +281,10 @@ wnoutrefresh(WINDOW *win) newscr->_leaveok = win->_leaveok; #ifdef TRACE - if (_nc_tracing & TRACE_UPDATE) + if (USE_TRACEF(TRACE_UPDATE)) { _tracedump("newscr", newscr); + _nc_unlock_global(tracef); + } #endif /* TRACE */ returnCode(OK); } diff --git a/lib/libcurses/base/lib_restart.c b/lib/libcurses/base/lib_restart.c index c7a2797b7d1..b017010bc8f 100644 --- a/lib/libcurses/base/lib_restart.c +++ b/lib/libcurses/base/lib_restart.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_restart.c,v 1.4 2001/01/22 18:01:43 millert Exp $ */ +/* $OpenBSD: lib_restart.c,v 1.5 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,14 +31,13 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* * Terminfo-only terminal setup routines: * * int restartterm(const char *, int, int *) - * TERMINAL *set_curterm(TERMINAL *) - * int del_curterm(TERMINAL *) */ #include <curses.priv.h> @@ -49,46 +48,52 @@ #include <term.h> /* lines, columns, cur_term */ -MODULE_ID("$From: lib_restart.c,v 1.4 2000/12/10 01:26:52 tom Exp $") +MODULE_ID("$Id: lib_restart.c,v 1.5 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(int) -restartterm -(NCURSES_CONST char *termp, int filenum, int *errret) +restartterm(NCURSES_CONST char *termp, int filenum, int *errret) { - int saveecho = SP->_echo; - int savecbreak = SP->_cbreak; - int saveraw = SP->_raw; - int savenl = SP->_nl; + int result; T((T_CALLED("restartterm(%s,%d,%p)"), termp, filenum, errret)); - setupterm(termp, filenum, errret); + if (setupterm(termp, filenum, errret) != OK) { + result = ERR; + } else if (SP != 0) { + int saveecho = SP->_echo; + int savecbreak = SP->_cbreak; + int saveraw = SP->_raw; + int savenl = SP->_nl; - if (saveecho) - echo(); - else - noecho(); + if (saveecho) + echo(); + else + noecho(); - if (savecbreak) { - cbreak(); - noraw(); - } else if (saveraw) { - nocbreak(); - raw(); - } else { - nocbreak(); - noraw(); - } - if (savenl) - nl(); - else - nonl(); + if (savecbreak) { + cbreak(); + noraw(); + } else if (saveraw) { + nocbreak(); + raw(); + } else { + nocbreak(); + noraw(); + } + if (savenl) + nl(); + else + nonl(); - reset_prog_mode(); + reset_prog_mode(); #if USE_SIZECHANGE - _nc_update_screensize(); + _nc_update_screensize(SP); #endif - returnCode(OK); + result = OK; + } else { + result = ERR; + } + returnCode(result); } diff --git a/lib/libcurses/base/lib_scanw.c b/lib/libcurses/base/lib_scanw.c index 057f57adee0..852573c83c5 100644 --- a/lib/libcurses/base/lib_scanw.c +++ b/lib/libcurses/base/lib_scanw.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_scanw.c,v 1.2 2001/01/22 18:01:43 millert Exp $ */ +/* $OpenBSD: lib_scanw.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -42,15 +42,7 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_scanw.c,v 1.10 2000/12/10 02:43:27 tom Exp $") - -#if !HAVE_VSSCANF -#if defined(__QNX__) -extern int vsscanf(const char *str, const char *format, __va_list __arg); -#else -extern int vsscanf(const char *str, const char *format,...); -#endif -#endif +MODULE_ID("$Id: lib_scanw.c,v 1.3 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(int) vwscanw(WINDOW *win, NCURSES_CONST char *fmt, va_list argp) diff --git a/lib/libcurses/base/lib_screen.c b/lib/libcurses/base/lib_screen.c index 8f7f830a708..de9e4dc8196 100644 --- a/lib/libcurses/base/lib_screen.c +++ b/lib/libcurses/base/lib_screen.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_screen.c,v 1.3 2001/01/22 18:01:43 millert Exp $ */ +/* $OpenBSD: lib_screen.c,v 1.4 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,92 +31,111 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996 on * ****************************************************************************/ #include <curses.priv.h> -#include <sys/stat.h> -#include <time.h> -#include <term.h> /* exit_ca_mode, non_rev_rmcup */ +MODULE_ID("$Id: lib_screen.c,v 1.4 2010/01/12 23:22:06 nicm Exp $") -MODULE_ID("$From: lib_screen.c,v 1.17 2000/12/10 02:43:27 tom Exp $") - -static time_t dumptime; +#define MAX_SIZE 0x3fff /* 16k is big enough for a window or pad */ NCURSES_EXPORT(WINDOW *) -getwin(FILE * filep) +getwin(FILE *filep) { WINDOW tmp, *nwin; int n; T((T_CALLED("getwin(%p)"), filep)); + clearerr(filep); (void) fread(&tmp, sizeof(WINDOW), 1, filep); - if (ferror(filep)) + if (ferror(filep) + || tmp._maxy == 0 + || tmp._maxy > MAX_SIZE + || tmp._maxx == 0 + || tmp._maxx > MAX_SIZE) returnWin(0); - if ((nwin = newwin(tmp._maxy + 1, tmp._maxx + 1, 0, 0)) == 0) - returnWin(0); + if (tmp._flags & _ISPAD) { + nwin = newpad(tmp._maxy + 1, tmp._maxx + 1); + } else { + nwin = newwin(tmp._maxy + 1, tmp._maxx + 1, 0, 0); + } /* * We deliberately do not restore the _parx, _pary, or _parent * fields, because the window hierarchy within which they * made sense is probably gone. */ - nwin->_curx = tmp._curx; - nwin->_cury = tmp._cury; - nwin->_maxy = tmp._maxy; - nwin->_maxx = tmp._maxx; - nwin->_begy = tmp._begy; - nwin->_begx = tmp._begx; - nwin->_yoffset = tmp._yoffset; - nwin->_flags = tmp._flags & ~(_SUBWIN | _ISPAD); - - nwin->_attrs = tmp._attrs; - nwin->_bkgd = tmp._bkgd; - - nwin->_clear = tmp._clear; - nwin->_scroll = tmp._scroll; - nwin->_leaveok = tmp._leaveok; - nwin->_use_keypad = tmp._use_keypad; - nwin->_delay = tmp._delay; - nwin->_immed = tmp._immed; - nwin->_sync = tmp._sync; - - nwin->_regtop = tmp._regtop; - nwin->_regbottom = tmp._regbottom; - - for (n = 0; n < nwin->_maxy + 1; n++) { - (void) fread(nwin->_line[n].text, - sizeof(chtype), (size_t) (nwin->_maxx + 1), filep); - if (ferror(filep)) { - delwin(nwin); - returnWin(0); + if (nwin != 0) { + nwin->_curx = tmp._curx; + nwin->_cury = tmp._cury; + nwin->_maxy = tmp._maxy; + nwin->_maxx = tmp._maxx; + nwin->_begy = tmp._begy; + nwin->_begx = tmp._begx; + nwin->_yoffset = tmp._yoffset; + nwin->_flags = tmp._flags & ~(_SUBWIN); + + WINDOW_ATTRS(nwin) = WINDOW_ATTRS(&tmp); + nwin->_nc_bkgd = tmp._nc_bkgd; + + nwin->_notimeout = tmp._notimeout; + nwin->_clear = tmp._clear; + nwin->_leaveok = tmp._leaveok; + nwin->_idlok = tmp._idlok; + nwin->_idcok = tmp._idcok; + nwin->_immed = tmp._immed; + nwin->_scroll = tmp._scroll; + nwin->_sync = tmp._sync; + nwin->_use_keypad = tmp._use_keypad; + nwin->_delay = tmp._delay; + + nwin->_regtop = tmp._regtop; + nwin->_regbottom = tmp._regbottom; + + if (tmp._flags & _ISPAD) + nwin->_pad = tmp._pad; + + for (n = 0; n <= nwin->_maxy; n++) { + clearerr(filep); + (void) fread(nwin->_line[n].text, + sizeof(NCURSES_CH_T), + (size_t) (nwin->_maxx + 1), + filep); + if (ferror(filep)) { + delwin(nwin); + returnWin(0); + } } + touchwin(nwin); } - touchwin(nwin); - returnWin(nwin); } NCURSES_EXPORT(int) -putwin(WINDOW *win, FILE * filep) +putwin(WINDOW *win, FILE *filep) { int code = ERR; int n; T((T_CALLED("putwin(%p,%p)"), win, filep)); - if (win) { - (void) fwrite(win, sizeof(WINDOW), 1, filep); - if (ferror(filep)) - returnCode(code); + if (win != 0) { + size_t len = (size_t) (win->_maxx + 1); + + clearerr(filep); + if (fwrite(win, sizeof(WINDOW), 1, filep) != 1 + || ferror(filep)) + returnCode(code); - for (n = 0; n < win->_maxy + 1; n++) { - (void) fwrite(win->_line[n].text, - sizeof(chtype), (size_t) (win->_maxx + 1), filep); - if (ferror(filep)) + for (n = 0; n <= win->_maxy; n++) { + if (fwrite(win->_line[n].text, + sizeof(NCURSES_CH_T), len, filep) != len + || ferror(filep)) { returnCode(code); + } } code = OK; } @@ -131,11 +150,14 @@ scr_restore(const char *file) T((T_CALLED("scr_restore(%s)"), _nc_visbuf(file))); if (_nc_access(file, R_OK) < 0 - || (fp = fopen(file, "rb")) == 0) + || (fp = fopen(file, "rb")) == 0) { returnCode(ERR); - else { + } else { delwin(newscr); - newscr = getwin(fp); + SP->_newscr = getwin(fp); +#if !USE_REENTRANT + newscr = SP->_newscr; +#endif (void) fclose(fp); returnCode(OK); } @@ -149,12 +171,11 @@ scr_dump(const char *file) T((T_CALLED("scr_dump(%s)"), _nc_visbuf(file))); if (_nc_access(file, W_OK) < 0 - || (fp = fopen(file, "wb")) == 0) + || (fp = fopen(file, "wb")) == 0) { returnCode(ERR); - else { + } else { (void) putwin(newscr, fp); (void) fclose(fp); - dumptime = time((time_t *) 0); returnCode(OK); } } @@ -163,7 +184,6 @@ NCURSES_EXPORT(int) scr_init(const char *file) { FILE *fp = 0; - struct stat stb; T((T_CALLED("scr_init(%s)"), _nc_visbuf(file))); @@ -171,13 +191,14 @@ scr_init(const char *file) returnCode(ERR); if (_nc_access(file, R_OK) < 0 - || (fp = fopen(file, "rb")) == 0) - returnCode(ERR); - else if (fstat(STDOUT_FILENO, &stb) || stb.st_mtime > dumptime) + || (fp = fopen(file, "rb")) == 0) { returnCode(ERR); - else { + } else { delwin(curscr); - curscr = getwin(fp); + SP->_curscr = getwin(fp); +#if !USE_REENTRANT + curscr = SP->_curscr; +#endif (void) fclose(fp); returnCode(OK); } @@ -188,11 +209,14 @@ scr_set(const char *file) { T((T_CALLED("scr_set(%s)"), _nc_visbuf(file))); - if (scr_init(file) == ERR) + if (scr_init(file) == ERR) { returnCode(ERR); - else { + } else { delwin(newscr); - newscr = dupwin(curscr); + SP->_newscr = dupwin(curscr); +#if !USE_REENTRANT + newscr = SP->_newscr; +#endif returnCode(OK); } } diff --git a/lib/libcurses/base/lib_scroll.c b/lib/libcurses/base/lib_scroll.c index 8f9b3c5e17b..c3fc784958c 100644 --- a/lib/libcurses/base/lib_scroll.c +++ b/lib/libcurses/base/lib_scroll.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_scroll.c,v 1.3 2001/01/22 18:01:43 millert Exp $ */ +/* $OpenBSD: lib_scroll.c,v 1.4 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2004,2006 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,7 +29,8 @@ ****************************************************************************/ /**************************************************************************** - * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * Author: Thomas E. Dickey 1996-2003 * + * and: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * ****************************************************************************/ @@ -44,17 +45,29 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_scroll.c,v 1.20 2000/12/10 02:54:03 tom Exp $") +MODULE_ID("$Id: lib_scroll.c,v 1.4 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(void) -_nc_scroll_window -(WINDOW *win, int const n, NCURSES_SIZE_T const top, - NCURSES_SIZE_T const bottom, chtype blank) +_nc_scroll_window(WINDOW *win, + int const n, + NCURSES_SIZE_T const top, + NCURSES_SIZE_T const bottom, + NCURSES_CH_T blank) { - int line, j; - size_t to_copy = (size_t) (sizeof(chtype) * (win->_maxx + 1)); - - TR(TRACE_MOVE, ("_nc_scroll_window(%p, %d, %d, %d)", win, n, top, bottom)); + int limit; + int line; + int j; + size_t to_copy = (size_t) (sizeof(NCURSES_CH_T) * (win->_maxx + 1)); + + TR(TRACE_MOVE, ("_nc_scroll_window(%p, %d, %ld, %ld)", + win, n, (long) top, (long) bottom)); + + if (top < 0 + || bottom < top + || bottom > win->_maxy) { + TR(TRACE_MOVE, ("nothing to scroll")); + return; + } /* * This used to do a line-text pointer-shuffle instead of text copies. @@ -69,15 +82,17 @@ _nc_scroll_window /* shift n lines downwards */ if (n < 0) { - for (line = bottom; line >= top - n; line--) { + limit = top - n; + for (line = bottom; line >= limit && line >= 0; line--) { + TR(TRACE_MOVE, ("...copying %d to %d", line + n, line)); memcpy(win->_line[line].text, win->_line[line + n].text, to_copy); - if_USE_SCROLL_HINTS( - win->_line[line].oldindex = - win->_line[line + n].oldindex); + if_USE_SCROLL_HINTS(win->_line[line].oldindex = + win->_line[line + n].oldindex); } - for (line = top; line < top - n; line++) { + for (line = top; line < limit && line <= win->_maxy; line++) { + TR(TRACE_MOVE, ("...filling %d", line)); for (j = 0; j <= win->_maxx; j++) win->_line[line].text[j] = blank; if_USE_SCROLL_HINTS(win->_line[line].oldindex = _NEWINDEX); @@ -86,20 +101,37 @@ _nc_scroll_window /* shift n lines upwards */ if (n > 0) { - for (line = top; line <= bottom - n; line++) { + limit = bottom - n; + for (line = top; line <= limit && line <= win->_maxy; line++) { memcpy(win->_line[line].text, win->_line[line + n].text, to_copy); if_USE_SCROLL_HINTS(win->_line[line].oldindex = win->_line[line + n].oldindex); } - for (line = bottom; line > bottom - n; line--) { + for (line = bottom; line > limit && line >= 0; line--) { for (j = 0; j <= win->_maxx; j++) win->_line[line].text[j] = blank; if_USE_SCROLL_HINTS(win->_line[line].oldindex = _NEWINDEX); } } touchline(win, top, bottom - top + 1); + + if_WIDEC({ + if (WINDOW_EXT(win, addch_used) != 0) { + int next = WINDOW_EXT(win, addch_y) + n; + if (next < 0 || next > win->_maxy) { + TR(TRACE_VIRTPUT, + ("Alert discarded multibyte on scroll")); + WINDOW_EXT(win, addch_y) = 0; + } else { + TR(TRACE_VIRTPUT, ("scrolled working position to %d,%d", + WINDOW_EXT(win, addch_y), + WINDOW_EXT(win, addch_x))); + WINDOW_EXT(win, addch_y) = next; + } + } + }) } NCURSES_EXPORT(int) @@ -107,18 +139,14 @@ wscrl(WINDOW *win, int n) { T((T_CALLED("wscrl(%p,%d)"), win, n)); - if (!win || !win->_scroll) + if (!win || !win->_scroll) { + TR(TRACE_MOVE, ("...scrollok is false")); returnCode(ERR); + } - if (n == 0) - returnCode(OK); - - if ((n > (win->_regbottom - win->_regtop)) || - (-n > (win->_regbottom - win->_regtop))) - returnCode(ERR); - - _nc_scroll_window(win, n, win->_regtop, win->_regbottom, _nc_background(win)); - - _nc_synchook(win); + if (n != 0) { + _nc_scroll_window(win, n, win->_regtop, win->_regbottom, win->_nc_bkgd); + _nc_synchook(win); + } returnCode(OK); } diff --git a/lib/libcurses/base/lib_scrollok.c b/lib/libcurses/base/lib_scrollok.c index 3cd16dc0891..a3bfc155ddf 100644 --- a/lib/libcurses/base/lib_scrollok.c +++ b/lib/libcurses/base/lib_scrollok.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_scrollok.c,v 1.2 2001/01/22 18:01:43 millert Exp $ */ +/* $OpenBSD: lib_scrollok.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** * Copyright (c) 1998,2000 Free Software Foundation, Inc. * @@ -42,7 +42,7 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_scrollok.c,v 1.4 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_scrollok.c,v 1.3 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(int) scrollok(WINDOW *win, bool flag) diff --git a/lib/libcurses/base/lib_scrreg.c b/lib/libcurses/base/lib_scrreg.c index d7f8fa7a91a..d70a0ac88a9 100644 --- a/lib/libcurses/base/lib_scrreg.c +++ b/lib/libcurses/base/lib_scrreg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_scrreg.c,v 1.3 2001/01/22 18:01:44 millert Exp $ */ +/* $OpenBSD: lib_scrreg.c,v 1.4 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** * Copyright (c) 1998,2000 Free Software Foundation, Inc. * @@ -42,7 +42,7 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_scrreg.c,v 1.10 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_scrreg.c,v 1.4 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(int) wsetscrreg(WINDOW *win, int top, int bottom) diff --git a/lib/libcurses/base/lib_set_term.c b/lib/libcurses/base/lib_set_term.c index d9653821351..0c4af8a2673 100644 --- a/lib/libcurses/base/lib_set_term.c +++ b/lib/libcurses/base/lib_set_term.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_set_term.c,v 1.12 2001/01/22 18:01:44 millert Exp $ */ +/* $OpenBSD: lib_set_term.c,v 1.13 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -45,32 +46,50 @@ #include <term.h> /* cur_term */ #include <tic.h> -MODULE_ID("$From: lib_set_term.c,v 1.61 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_set_term.c,v 1.13 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(SCREEN *) -set_term(SCREEN * screenp) +set_term(SCREEN *screenp) { SCREEN *oldSP; + SCREEN *newSP; T((T_CALLED("set_term(%p)"), screenp)); + _nc_lock_global(curses); + oldSP = SP; _nc_set_screen(screenp); + newSP = SP; + + if (newSP != 0) { + set_curterm(newSP->_term); +#if !USE_REENTRANT + curscr = newSP->_curscr; + newscr = newSP->_newscr; + stdscr = newSP->_stdscr; + COLORS = newSP->_color_count; + COLOR_PAIRS = newSP->_pair_count; +#endif + } else { + set_curterm(0); +#if !USE_REENTRANT + curscr = 0; + newscr = 0; + stdscr = 0; + COLORS = 0; + COLOR_PAIRS = 0; +#endif + } - set_curterm(SP->_term); - curscr = SP->_curscr; - newscr = SP->_newscr; - stdscr = SP->_stdscr; - COLORS = SP->_color_count; - COLOR_PAIRS = SP->_pair_count; - memcpy(acs_map, SP->_acs_map, sizeof(chtype) * ACS_LEN); + _nc_unlock_global(curses); T((T_RETURN("%p"), oldSP)); return (oldSP); } static void -_nc_free_keytry(struct tries *kt) +_nc_free_keytry(TRIES * kt) { if (kt != 0) { _nc_free_keytry(kt->child); @@ -79,97 +98,135 @@ _nc_free_keytry(struct tries *kt) } } +static bool +delink_screen(SCREEN *sp) +{ + SCREEN *last = 0; + SCREEN *temp; + bool result = FALSE; + + for (each_screen(temp)) { + if (temp == sp) { + if (last) + last = sp->_next_screen; + else + _nc_screen_chain = sp->_next_screen; + result = TRUE; + break; + } + last = temp; + } + return result; +} + /* * Free the storage associated with the given SCREEN sp. */ NCURSES_EXPORT(void) -delscreen(SCREEN * sp) +delscreen(SCREEN *sp) { - SCREEN **scan = &_nc_screen_chain; + int i; T((T_CALLED("delscreen(%p)"), sp)); - while (*scan) { - if (*scan == sp) { - *scan = sp->_next_screen; - break; + _nc_lock_global(curses); + if (delink_screen(sp)) { + + (void) _nc_freewin(sp->_curscr); + (void) _nc_freewin(sp->_newscr); + (void) _nc_freewin(sp->_stdscr); + + if (sp->_slk != 0) { + if (sp->_slk->ent != 0) { + for (i = 0; i < sp->_slk->labcnt; ++i) { + FreeIfNeeded(sp->_slk->ent[i].ent_text); + FreeIfNeeded(sp->_slk->ent[i].form_text); + } + free(sp->_slk->ent); + } + free(sp->_slk); + sp->_slk = 0; } - scan = &(*scan)->_next_screen; - } - (void) _nc_freewin(sp->_curscr); - (void) _nc_freewin(sp->_newscr); - (void) _nc_freewin(sp->_stdscr); - _nc_free_keytry(sp->_keytry); - _nc_free_keytry(sp->_key_ok); + _nc_free_keytry(sp->_keytry); + sp->_keytry = 0; - FreeIfNeeded(sp->_color_table); - FreeIfNeeded(sp->_color_pairs); + _nc_free_keytry(sp->_key_ok); + sp->_key_ok = 0; - FreeIfNeeded(sp->oldhash); - FreeIfNeeded(sp->newhash); + FreeIfNeeded(sp->_current_attr); - del_curterm(sp->_term); + FreeIfNeeded(sp->_color_table); + FreeIfNeeded(sp->_color_pairs); - /* - * If the associated output stream has been closed, we can discard the - * set-buffer. Limit the error check to EBADF, since fflush may fail - * for other reasons than trying to operate upon a closed stream. - */ - if (sp->_ofp != 0 - && sp->_setbuf != 0 - && fflush(sp->_ofp) != 0 - && errno == EBADF) { - free(sp->_setbuf); - } + FreeIfNeeded(sp->oldhash); + FreeIfNeeded(sp->newhash); + FreeIfNeeded(sp->hashtab); - free(sp); + FreeIfNeeded(sp->_acs_map); + FreeIfNeeded(sp->_screen_acs_map); - /* - * If this was the current screen, reset everything that the - * application might try to use (except cur_term, which may have - * multiple references in different screens). - */ - if (sp == SP) { - curscr = 0; - newscr = 0; - stdscr = 0; - COLORS = 0; - COLOR_PAIRS = 0; - _nc_set_screen(0); + /* + * If the associated output stream has been closed, we can discard the + * set-buffer. Limit the error check to EBADF, since fflush may fail + * for other reasons than trying to operate upon a closed stream. + */ + if (sp->_ofp != 0 + && sp->_setbuf != 0 + && fflush(sp->_ofp) != 0 + && errno == EBADF) { + free(sp->_setbuf); + } + + del_curterm(sp->_term); + free(sp); + + /* + * If this was the current screen, reset everything that the + * application might try to use (except cur_term, which may have + * multiple references in different screens). + */ + if (sp == SP) { +#if !USE_REENTRANT + curscr = 0; + newscr = 0; + stdscr = 0; + COLORS = 0; + COLOR_PAIRS = 0; +#endif + _nc_set_screen(0); + } } + _nc_unlock_global(curses); + returnVoid; } -static ripoff_t rippedoff[5]; -static ripoff_t *rsp = rippedoff; -#define N_RIPS SIZEOF(rippedoff) - static bool -no_mouse_event(SCREEN * sp GCC_UNUSED) +no_mouse_event(SCREEN *sp GCC_UNUSED) { return FALSE; } static bool -no_mouse_inline(SCREEN * sp GCC_UNUSED) +no_mouse_inline(SCREEN *sp GCC_UNUSED) { return FALSE; } static bool -no_mouse_parse(int code GCC_UNUSED) +no_mouse_parse(SCREEN *sp GCC_UNUSED, int code GCC_UNUSED) { return TRUE; } static void -no_mouse_resume(SCREEN * sp GCC_UNUSED) +no_mouse_resume(SCREEN *sp GCC_UNUSED) { } static void -no_mouse_wrap(SCREEN * sp GCC_UNUSED) +no_mouse_wrap(SCREEN *sp GCC_UNUSED) { } @@ -183,7 +240,7 @@ extract_fgbg(char *src, int *result) if (dst == 0) { dst = src; } else if (value >= 0) { - *result = value % max_colors; + *result = value; } while (*dst != 0 && *dst != ';') dst++; @@ -193,21 +250,64 @@ extract_fgbg(char *src, int *result) } #endif -NCURSES_EXPORT(int) -_nc_setupscreen -(short slines, short const scolumns, FILE * output) /* OS-independent screen initializations */ +NCURSES_EXPORT(int) +_nc_setupscreen(int slines GCC_UNUSED, + int scolumns GCC_UNUSED, + FILE *output, + bool filtered, + int slk_format) { + char *env; int bottom_stolen = 0; - size_t i; + bool support_cookies = USE_XMC_SUPPORT; + ripoff_t *rop; + + T((T_CALLED("_nc_setupscreen(%d, %d, %p, %d, %d)"), + slines, scolumns, output, filtered, slk_format)); assert(SP == 0); /* has been reset in newterm() ! */ - if (!_nc_alloc_screen()) - return ERR; + if (!_nc_alloc_screen() + || ((SP->_acs_map = typeCalloc(chtype, ACS_LEN)) == 0) + || ((SP->_screen_acs_map = typeCalloc(bool, ACS_LEN)) == 0)) { + returnCode(ERR); + } + T(("created SP %p", SP)); SP->_next_screen = _nc_screen_chain; _nc_screen_chain = SP; + if ((SP->_current_attr = typeCalloc(NCURSES_CH_T, 1)) == 0) + returnCode(ERR); + + /* + * We should always check the screensize, just in case. + */ + _nc_get_screensize(SP, &slines, &scolumns); + SET_LINES(slines); + SET_COLS(scolumns); + T((T_CREATE("screen %s %dx%d"), termname(), LINES, COLS)); + + SP->_filtered = filtered; + + /* implement filter mode */ + if (filtered) { + slines = 1; + SET_LINES(slines); + clear_screen = 0; + cursor_down = parm_down_cursor = 0; + cursor_address = 0; + cursor_up = parm_up_cursor = 0; + row_address = 0; + + cursor_home = carriage_return; + T(("filter screensize %dx%d", LINES, COLS)); + } +#ifdef __DJGPP__ + T(("setting output mode to binary")); + fflush(output); + setmode(output, O_BINARY); +#endif _nc_set_buffer(output, TRUE); SP->_term = cur_term; SP->_lines = slines; @@ -224,11 +324,7 @@ _nc_setupscreen SP->_ofp = output; SP->_cursor = -1; /* cannot know real cursor shape */ -#if NCURSES_NO_PADDING - SP->_no_padding = getenv("NCURSES_NO_PADDING") != 0; - TR(TRACE_CHARPUT | TRACE_MOVE, ("padding will%s be used", - SP->_no_padding ? " not" : "")); -#endif + SetNoPadding(SP); #if NCURSES_EXT_FUNCS SP->_default_color = FALSE; @@ -261,6 +357,25 @@ _nc_setupscreen SP->_default_bg = C_MASK; #endif + /* + * Allow those assumed/default color assumptions to be overridden at + * runtime: + */ + if ((env = getenv("NCURSES_ASSUMED_COLORS")) != 0) { + int fg, bg; + char sep1, sep2; + int count = sscanf(env, "%d%c%d%c", &fg, &sep1, &bg, &sep2); + if (count >= 1) { + SP->_default_fg = (fg >= 0 && fg < max_colors) ? fg : C_MASK; + if (count >= 3) { + SP->_default_bg = (bg >= 0 && bg < max_colors) ? bg : C_MASK; + } + TR(TRACE_CHARPUT | TRACE_MOVE, + ("from environment assumed fg=%d, bg=%d", + SP->_default_fg, + SP->_default_bg)); + } + } #if USE_COLORFGBG /* * If rxvt's $COLORFGBG variable is set, use it to specify the assumed @@ -270,8 +385,29 @@ _nc_setupscreen */ if (getenv("COLORFGBG") != 0) { char *p = getenv("COLORFGBG"); + TR(TRACE_CHARPUT | TRACE_MOVE, ("decoding COLORFGBG %s", p)); p = extract_fgbg(p, &(SP->_default_fg)); p = extract_fgbg(p, &(SP->_default_bg)); + if (*p) /* assume rxvt was compiled with xpm support */ + p = extract_fgbg(p, &(SP->_default_bg)); + TR(TRACE_CHARPUT | TRACE_MOVE, ("decoded fg=%d, bg=%d", + SP->_default_fg, SP->_default_bg)); + if (SP->_default_fg >= max_colors) { + if (set_a_foreground != ABSENT_STRING + && !strcmp(set_a_foreground, "\033[3%p1%dm")) { + set_a_foreground = "\033[3%?%p1%{8}%>%t9%e%p1%d%;m"; + } else { + SP->_default_fg %= max_colors; + } + } + if (SP->_default_bg >= max_colors) { + if (set_a_background != ABSENT_STRING + && !strcmp(set_a_background, "\033[4%p1%dm")) { + set_a_background = "\033[4%?%p1%{8}%>%t9%e%p1%d%;m"; + } else { + SP->_default_bg %= max_colors; + } + } } #endif #endif /* NCURSES_EXT_FUNCS */ @@ -284,64 +420,133 @@ _nc_setupscreen SP->_mouse_wrap = no_mouse_wrap; SP->_mouse_fd = -1; - /* initialize the panel hooks */ - SP->_panelHook.top_panel = (struct panel *) 0; - SP->_panelHook.bottom_panel = (struct panel *) 0; - SP->_panelHook.stdscr_pseudo_panel = (struct panel *) 0; - /* - * If we've no magic cookie support, we suppress attributes that xmc - * would affect, i.e., the attributes that affect the rendition of a - * space. Note that this impacts the alternate character set mapping - * as well. + * If we've no magic cookie support, we suppress attributes that xmc would + * affect, i.e., the attributes that affect the rendition of a space. + */ + SP->_ok_attributes = termattrs(); + if (has_colors()) { + SP->_ok_attributes |= A_COLOR; + } +#if USE_XMC_SUPPORT + /* + * If we have no magic-cookie support compiled-in, or if it is suppressed + * in the environment, reset the support-flag. */ - if (magic_cookie_glitch > 0) { - - SP->_xmc_triggers = termattrs() & ( - A_ALTCHARSET | - A_BLINK | - A_BOLD | - A_REVERSE | - A_STANDOUT | - A_UNDERLINE + if (magic_cookie_glitch >= 0) { + if (getenv("NCURSES_NO_MAGIC_COOKIE") != 0) { + support_cookies = FALSE; + } + } +#endif + + if (!support_cookies && magic_cookie_glitch >= 0) { + T(("will disable attributes to work w/o magic cookies")); + } + + if (magic_cookie_glitch > 0) { /* tvi, wyse */ + + SP->_xmc_triggers = SP->_ok_attributes & ( + A_STANDOUT | + A_UNDERLINE | + A_REVERSE | + A_BLINK | + A_DIM | + A_BOLD | + A_INVIS | + A_PROTECT ); - SP->_xmc_suppress = SP->_xmc_triggers & (chtype) ~ (A_BOLD); +#if 0 + /* + * We "should" treat colors as an attribute. The wyse350 (and its + * clones) appear to be the only ones that have both colors and magic + * cookies. + */ + if (has_colors()) { + SP->_xmc_triggers |= A_COLOR; + } +#endif + SP->_xmc_suppress = SP->_xmc_triggers & (chtype) ~(A_BOLD); T(("magic cookie attributes %s", _traceattr(SP->_xmc_suppress))); + /* + * Supporting line-drawing may be possible. But make the regular + * video attributes work first. + */ + acs_chars = ABSENT_STRING; + ena_acs = ABSENT_STRING; + enter_alt_charset_mode = ABSENT_STRING; + exit_alt_charset_mode = ABSENT_STRING; #if USE_XMC_SUPPORT /* - * To keep this simple, suppress all of the optimization hooks - * except for clear_screen and the cursor addressing. + * To keep the cookie support simple, suppress all of the optimization + * hooks except for clear_screen and the cursor addressing. */ - clr_eol = 0; - clr_eos = 0; - set_attributes = 0; -#else - magic_cookie_glitch = ABSENT_NUMERIC; - acs_chars = 0; + if (support_cookies) { + clr_eol = ABSENT_STRING; + clr_eos = ABSENT_STRING; + set_attributes = ABSENT_STRING; + } #endif + } else if (magic_cookie_glitch == 0) { /* hpterm */ + } + + /* + * If magic cookies are not supported, cancel the strings that set + * video attributes. + */ + if (!support_cookies && magic_cookie_glitch >= 0) { + magic_cookie_glitch = ABSENT_NUMERIC; + set_attributes = ABSENT_STRING; + enter_blink_mode = ABSENT_STRING; + enter_bold_mode = ABSENT_STRING; + enter_dim_mode = ABSENT_STRING; + enter_reverse_mode = ABSENT_STRING; + enter_standout_mode = ABSENT_STRING; + enter_underline_mode = ABSENT_STRING; + } + + /* initialize normal acs before wide, since we use mapping in the latter */ +#if !USE_WIDEC_SUPPORT + if (_nc_unicode_locale() && _nc_locale_breaks_acs(cur_term)) { + acs_chars = NULL; + ena_acs = NULL; + enter_alt_charset_mode = NULL; + exit_alt_charset_mode = NULL; + set_attributes = NULL; } +#endif _nc_init_acs(); - memcpy(SP->_acs_map, acs_map, sizeof(chtype) * ACS_LEN); +#if USE_WIDEC_SUPPORT + _nc_init_wacs(); + + SP->_screen_acs_fix = (_nc_unicode_locale() + && _nc_locale_breaks_acs(cur_term)); +#endif + env = _nc_get_locale(); + SP->_legacy_coding = ((env == 0) + || !strcmp(env, "C") + || !strcmp(env, "POSIX")); + T(("legacy-coding %d", SP->_legacy_coding)); _nc_idcok = TRUE; _nc_idlok = FALSE; - _nc_windows = 0; /* no windows yet */ - SP->oldhash = 0; SP->newhash = 0; T(("creating newscr")); - if ((newscr = newwin(slines, scolumns, 0, 0)) == 0) - return ERR; + if ((SP->_newscr = newwin(slines, scolumns, 0, 0)) == 0) + returnCode(ERR); T(("creating curscr")); - if ((curscr = newwin(slines, scolumns, 0, 0)) == 0) - return ERR; + if ((SP->_curscr = newwin(slines, scolumns, 0, 0)) == 0) + returnCode(ERR); - SP->_newscr = newscr; - SP->_curscr = curscr; +#if !USE_REENTRANT + newscr = SP->_newscr; + curscr = SP->_curscr; +#endif #if USE_SIZECHANGE SP->_resize = resizeterm; #endif @@ -349,70 +554,92 @@ _nc_setupscreen newscr->_clear = TRUE; curscr->_clear = FALSE; - for (i = 0, rsp = rippedoff; rsp->line && (i < N_RIPS); rsp++, i++) { - if (rsp->hook) { + def_shell_mode(); + def_prog_mode(); + + for (rop = ripoff_stack; + rop != ripoff_sp && (rop - ripoff_stack) < N_RIPS; + rop++) { + + /* If we must simulate soft labels, grab off the line to be used. + We assume that we must simulate, if it is none of the standard + formats (4-4 or 3-2-3) for which there may be some hardware + support. */ + if (rop->hook == _nc_slk_initialize) + if (!(num_labels <= 0 || !SLK_STDFMT(slk_format))) + continue; + if (rop->hook) { + int count; WINDOW *w; - int count = (rsp->line < 0) ? -rsp->line : rsp->line; - - if (rsp->line < 0) { - w = newwin(count, scolumns, SP->_lines_avail - count, 0); - if (w) { - rsp->w = w; - rsp->hook(w, scolumns); - bottom_stolen += count; - } else - return ERR; + + count = (rop->line < 0) ? -rop->line : rop->line; + T(("ripping off %i lines at %s", count, + ((rop->line < 0) + ? "bottom" + : "top"))); + + w = newwin(count, scolumns, + ((rop->line < 0) + ? SP->_lines_avail - count + : 0), + 0); + if (w) { + rop->win = w; + rop->hook(w, scolumns); } else { - w = newwin(count, scolumns, 0, 0); - if (w) { - rsp->w = w; - rsp->hook(w, scolumns); - SP->_topstolen += count; - } else - return ERR; + returnCode(ERR); } + if (rop->line < 0) + bottom_stolen += count; + else + SP->_topstolen += count; SP->_lines_avail -= count; } - rsp->line = 0; } /* reset the stack */ - rsp = rippedoff; + ripoff_sp = ripoff_stack; T(("creating stdscr")); assert((SP->_lines_avail + SP->_topstolen + bottom_stolen) == slines); - if ((stdscr = newwin(LINES = SP->_lines_avail, scolumns, 0, 0)) == 0) - return ERR; - SP->_stdscr = stdscr; + if ((SP->_stdscr = newwin(SP->_lines_avail, scolumns, 0, 0)) == 0) + returnCode(ERR); - def_shell_mode(); - def_prog_mode(); + SET_LINES(SP->_lines_avail); +#if !USE_REENTRANT + stdscr = SP->_stdscr; +#endif - return OK; + returnCode(OK); } -/* The internal implementation interprets line as the number of - lines to rip off from the top or bottom. - */ +/* + * The internal implementation interprets line as the number of lines to rip + * off from the top or bottom. + */ NCURSES_EXPORT(int) _nc_ripoffline(int line, int (*init) (WINDOW *, int)) { - if (line == 0) - return (OK); + T((T_CALLED("_nc_ripoffline(%d, %p)"), line, init)); + + if (line != 0) { - if (rsp >= rippedoff + N_RIPS) - return (ERR); + if (ripoff_sp == 0) + ripoff_sp = ripoff_stack; + if (ripoff_sp >= ripoff_stack + N_RIPS) + returnCode(ERR); - rsp->line = line; - rsp->hook = init; - rsp->w = 0; - rsp++; + ripoff_sp->line = line; + ripoff_sp->hook = init; + ripoff_sp++; + } - return (OK); + returnCode(OK); } NCURSES_EXPORT(int) ripoffline(int line, int (*init) (WINDOW *, int)) { + START_TRACE(); T((T_CALLED("ripoffline(%d,%p)"), line, init)); if (line == 0) diff --git a/lib/libcurses/base/lib_slk.c b/lib/libcurses/base/lib_slk.c index 7b72ce85844..c9abb8038f0 100644 --- a/lib/libcurses/base/lib_slk.c +++ b/lib/libcurses/base/lib_slk.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_slk.c,v 1.4 2001/01/22 18:01:44 millert Exp $ */ +/* $OpenBSD: lib_slk.c,v 1.5 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2005,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,8 +29,12 @@ ****************************************************************************/ /**************************************************************************** - * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * - * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * Authors: * + * Gerhard Fuernkranz 1993 (original) * + * Zeyd M. Ben-Halim 1992,1995 (sic) * + * Eric S. Raymond * + * Juergen Pfeifer 1996-on * + * Thomas E. Dickey * ****************************************************************************/ /* @@ -43,40 +47,20 @@ #include <ctype.h> #include <term.h> /* num_labels, label_*, plab_norm */ -MODULE_ID("$From: lib_slk.c,v 1.20 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_slk.c,v 1.5 2010/01/12 23:22:06 nicm Exp $") /* - * We'd like to move these into the screen context structure, but cannot, - * because slk_init() is called before initscr()/newterm(). + * Free any memory related to soft labels, return an error. */ -NCURSES_EXPORT_VAR(int) -_nc_slk_format = 0; /* one more than format specified in slk_init() */ - -/* - * Paint the info line for the PC style SLK emulation. - * - */ - static void - slk_paint_info(WINDOW *win) +static int +slk_failed(void) { - if (win && SP->slk_format == 4) { - int i; - - mvwhline(win, 0, 0, 0, getmaxx(win)); - wmove(win, 0, 0); - - for (i = 0; i < SP->_slk->maxlab; i++) { - if (win && SP->slk_format == 4) { - mvwaddch(win, 0, SP->_slk->ent[i].x, (chtype) 'F'); - if (i < 9) - waddch(win, (chtype) '1' + i); - else { - waddch(win, (chtype) '1'); - waddch(win, (chtype) '0' + (i - 9)); - } - } - } + if (SP->_slk) { + FreeIfNeeded(SP->_slk->ent); + free(SP->_slk); + SP->_slk = (SLK *) 0; } + return ERR; } /* @@ -88,101 +72,108 @@ _nc_slk_initialize(WINDOW *stwin, int cols) { int i, x; int res = OK; - char *p; + unsigned max_length; - T(("slk_initialize()")); + T((T_CALLED("_nc_slk_initialize()"))); if (SP->_slk) { /* we did this already, so simply return */ - return (OK); + returnCode(OK); } else if ((SP->_slk = typeCalloc(SLK, 1)) == 0) - return (ERR); + returnCode(ERR); SP->_slk->ent = NULL; - SP->_slk->buffer = NULL; - SP->_slk->attr = A_STANDOUT; - SP->_slk->maxlab = (num_labels > 0) ? - num_labels : MAX_SKEY(_nc_slk_format); - SP->_slk->maxlen = (num_labels > 0) ? - label_width * label_height : MAX_SKEY_LEN(_nc_slk_format); - SP->_slk->labcnt = (SP->_slk->maxlab < MAX_SKEY(_nc_slk_format)) ? - MAX_SKEY(_nc_slk_format) : SP->_slk->maxlab; + /* + * If we use colors, vidputs() will suppress video attributes that conflict + * with colors. In that case, we're still guaranteed that "reverse" would + * work. + */ + if ((no_color_video & 1) == 0) + SetAttr(SP->_slk->attr, A_STANDOUT); + else + SetAttr(SP->_slk->attr, A_REVERSE); + + SP->_slk->maxlab = ((num_labels > 0) + ? num_labels + : MAX_SKEY(_nc_globals.slk_format)); + SP->_slk->maxlen = ((num_labels > 0) + ? label_width * label_height + : MAX_SKEY_LEN(_nc_globals.slk_format)); + SP->_slk->labcnt = ((SP->_slk->maxlab < MAX_SKEY(_nc_globals.slk_format)) + ? MAX_SKEY(_nc_globals.slk_format) + : SP->_slk->maxlab); + + if (SP->_slk->maxlen <= 0 + || SP->_slk->labcnt <= 0 + || (SP->_slk->ent = typeCalloc(slk_ent, + (unsigned) SP->_slk->labcnt)) == NULL) + returnCode(slk_failed()); + + max_length = SP->_slk->maxlen; + for (i = 0; i < SP->_slk->labcnt; i++) { + size_t used = max_length + 1; - SP->_slk->ent = typeCalloc(slk_ent, SP->_slk->labcnt); - if (SP->_slk->ent == NULL) - goto exception; + if ((SP->_slk->ent[i].ent_text = (char *) _nc_doalloc(0, used)) == 0) + returnCode(slk_failed()); + memset(SP->_slk->ent[i].ent_text, 0, used); - p = SP->_slk->buffer = (char *) calloc(2 * SP->_slk->labcnt, (1 + SP->_slk->maxlen)); - if (SP->_slk->buffer == NULL) - goto exception; + if ((SP->_slk->ent[i].form_text = (char *) _nc_doalloc(0, used)) == 0) + returnCode(slk_failed()); + memset(SP->_slk->ent[i].form_text, 0, used); - for (i = 0; i < SP->_slk->labcnt; i++) { - SP->_slk->ent[i].text = p; - p += (1 + SP->_slk->maxlen); - SP->_slk->ent[i].form_text = p; - p += (1 + SP->_slk->maxlen); - memset(SP->_slk->ent[i].form_text, ' ', (unsigned) (SP->_slk->maxlen)); - SP->_slk->ent[i].visible = (i < SP->_slk->maxlab); + memset(SP->_slk->ent[i].form_text, ' ', max_length); + SP->_slk->ent[i].visible = (char) (i < SP->_slk->maxlab); } - if (_nc_slk_format >= 3) { /* PC style */ - int gap = (cols - 3 * (3 + 4 * SP->_slk->maxlen)) / 2; + if (_nc_globals.slk_format >= 3) { /* PC style */ + int gap = (cols - 3 * (3 + 4 * max_length)) / 2; if (gap < 1) gap = 1; for (i = x = 0; i < SP->_slk->maxlab; i++) { - SP->_slk->ent[i].x = x; - x += SP->_slk->maxlen; + SP->_slk->ent[i].ent_x = x; + x += max_length; x += (i == 3 || i == 7) ? gap : 1; } - if (_nc_slk_format == 4) - slk_paint_info(stwin); } else { - if (_nc_slk_format == 2) { /* 4-4 */ - int gap = cols - (SP->_slk->maxlab * SP->_slk->maxlen) - 6; + if (_nc_globals.slk_format == 2) { /* 4-4 */ + int gap = cols - (SP->_slk->maxlab * max_length) - 6; if (gap < 1) gap = 1; for (i = x = 0; i < SP->_slk->maxlab; i++) { - SP->_slk->ent[i].x = x; - x += SP->_slk->maxlen; + SP->_slk->ent[i].ent_x = x; + x += max_length; x += (i == 3) ? gap : 1; } } else { - if (_nc_slk_format == 1) { /* 1 -> 3-2-3 */ - int gap = (cols - (SP->_slk->maxlab * SP->_slk->maxlen) - 5) + if (_nc_globals.slk_format == 1) { /* 1 -> 3-2-3 */ + int gap = (cols - (SP->_slk->maxlab * max_length) - 5) / 2; if (gap < 1) gap = 1; for (i = x = 0; i < SP->_slk->maxlab; i++) { - SP->_slk->ent[i].x = x; - x += SP->_slk->maxlen; + SP->_slk->ent[i].ent_x = x; + x += max_length; x += (i == 2 || i == 4) ? gap : 1; } } else - goto exception; + returnCode(slk_failed()); } } SP->_slk->dirty = TRUE; if ((SP->_slk->win = stwin) == NULL) { - exception: - if (SP->_slk) { - FreeIfNeeded(SP->_slk->buffer); - FreeIfNeeded(SP->_slk->ent); - free(SP->_slk); - SP->_slk = (SLK *) 0; - res = (ERR); - } + returnCode(slk_failed()); } /* We now reset the format so that the next newterm has again * per default no SLK keys and may call slk_init again to * define a new layout. (juergen 03-Mar-1999) */ - SP->slk_format = _nc_slk_format; - _nc_slk_format = 0; - return (res); + SP->slk_format = _nc_globals.slk_format; + _nc_globals.slk_format = 0; + returnCode(res); } /* @@ -197,8 +188,6 @@ slk_restore(void) return (ERR); SP->_slk->hidden = FALSE; SP->_slk->dirty = TRUE; - /* we have to repaint info line eventually */ - slk_paint_info(SP->_slk->win); returnCode(slk_refresh()); } diff --git a/lib/libcurses/base/lib_slkatr_set.c b/lib/libcurses/base/lib_slkatr_set.c index 403ec288aab..523eadfdf3e 100644 --- a/lib/libcurses/base/lib_slkatr_set.c +++ b/lib/libcurses/base/lib_slkatr_set.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_slkatr_set.c,v 1.3 2001/01/22 18:01:44 millert Exp $ */ +/* $OpenBSD: lib_slkatr_set.c,v 1.4 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2003,2005 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,28 +29,32 @@ ****************************************************************************/ /**************************************************************************** - * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1998 * + * Author: Juergen Pfeifer, 1998 * + * and: Thomas E. Dickey 2005 * ****************************************************************************/ /* * lib_slkatr_set.c * Soft key routines. - * Set the labels attributes + * Set the label's attributes */ #include <curses.priv.h> -MODULE_ID("$From: lib_slkatr_set.c,v 1.5 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_slkatr_set.c,v 1.4 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(int) -slk_attr_set -(const attr_t attr, short color_pair_number, void *opts) +slk_attr_set(const attr_t attr, short color_pair_number, void *opts) { T((T_CALLED("slk_attr_set(%s,%d)"), _traceattr(attr), color_pair_number)); if (SP != 0 && SP->_slk != 0 && !opts && color_pair_number >= 0 && color_pair_number < COLOR_PAIRS) { - SP->_slk->attr = attr; - toggle_attr_on(SP->_slk->attr, COLOR_PAIR(color_pair_number)); + TR(TRACE_ATTRS, ("... current %s", _tracech_t(CHREF(SP->_slk->attr)))); + SetAttr(SP->_slk->attr, attr); + if (color_pair_number > 0) { + SetPair(SP->_slk->attr, color_pair_number); + } + TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP->_slk->attr)))); returnCode(OK); } else returnCode(ERR); diff --git a/lib/libcurses/base/lib_slkatrof.c b/lib/libcurses/base/lib_slkatrof.c index 36e2c128e80..e760fa62001 100644 --- a/lib/libcurses/base/lib_slkatrof.c +++ b/lib/libcurses/base/lib_slkatrof.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_slkatrof.c,v 1.2 2001/01/22 18:01:44 millert Exp $ */ +/* $OpenBSD: lib_slkatrof.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2000,2005 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,8 +29,8 @@ ****************************************************************************/ /**************************************************************************** - * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * - * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * Author: Juergen Pfeifer, 1997 * + * and: Thomas E. Dickey 2005 * ****************************************************************************/ /* @@ -40,7 +40,7 @@ */ #include <curses.priv.h> -MODULE_ID("$From: lib_slkatrof.c,v 1.6 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_slkatrof.c,v 1.3 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(int) slk_attroff(const chtype attr) @@ -48,7 +48,12 @@ slk_attroff(const chtype attr) T((T_CALLED("slk_attroff(%s)"), _traceattr(attr))); if (SP != 0 && SP->_slk != 0) { - toggle_attr_off(SP->_slk->attr, attr); + TR(TRACE_ATTRS, ("... current %s", _tracech_t(CHREF(SP->_slk->attr)))); + RemAttr(SP->_slk->attr, attr); + if ((attr & A_COLOR) != 0) { + SetPair(SP->_slk->attr, 0); + } + TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP->_slk->attr)))); returnCode(OK); } else returnCode(ERR); diff --git a/lib/libcurses/base/lib_slkatron.c b/lib/libcurses/base/lib_slkatron.c index f12bd7ad20f..deef29f7326 100644 --- a/lib/libcurses/base/lib_slkatron.c +++ b/lib/libcurses/base/lib_slkatron.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_slkatron.c,v 1.2 2001/01/22 18:01:44 millert Exp $ */ +/* $OpenBSD: lib_slkatron.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2000,2005 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,8 +29,8 @@ ****************************************************************************/ /**************************************************************************** - * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * - * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * Author: Juergen Pfeifer, 1997 * + * and: Thomas E. Dickey 2005 * ****************************************************************************/ /* @@ -40,7 +40,7 @@ */ #include <curses.priv.h> -MODULE_ID("$From: lib_slkatron.c,v 1.6 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_slkatron.c,v 1.3 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(int) slk_attron(const chtype attr) @@ -48,7 +48,12 @@ slk_attron(const chtype attr) T((T_CALLED("slk_attron(%s)"), _traceattr(attr))); if (SP != 0 && SP->_slk != 0) { - toggle_attr_on(SP->_slk->attr, attr); + TR(TRACE_ATTRS, ("... current %s", _tracech_t(CHREF(SP->_slk->attr)))); + AddAttr(SP->_slk->attr, attr); + if ((attr & A_COLOR) != 0) { + SetPair(SP->_slk->attr, PAIR_NUMBER(attr)); + } + TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP->_slk->attr)))); returnCode(OK); } else returnCode(ERR); diff --git a/lib/libcurses/base/lib_slkatrset.c b/lib/libcurses/base/lib_slkatrset.c index 3d3fb73d5e1..17dc4a2097f 100644 --- a/lib/libcurses/base/lib_slkatrset.c +++ b/lib/libcurses/base/lib_slkatrset.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_slkatrset.c,v 1.2 2001/01/22 18:01:44 millert Exp $ */ +/* $OpenBSD: lib_slkatrset.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2000,2005 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,8 +29,8 @@ ****************************************************************************/ /**************************************************************************** - * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * - * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * Author: Juergen Pfeifer, 1997 * + * and: Thomas E. Dickey 2005 * ****************************************************************************/ /* @@ -40,7 +40,7 @@ */ #include <curses.priv.h> -MODULE_ID("$From: lib_slkatrset.c,v 1.6 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_slkatrset.c,v 1.3 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(int) slk_attrset(const chtype attr) @@ -48,7 +48,7 @@ slk_attrset(const chtype attr) T((T_CALLED("slk_attrset(%s)"), _traceattr(attr))); if (SP != 0 && SP->_slk != 0) { - SP->_slk->attr = attr; + SetAttr(SP->_slk->attr, attr); returnCode(OK); } else returnCode(ERR); diff --git a/lib/libcurses/base/lib_slkattr.c b/lib/libcurses/base/lib_slkattr.c index 2ddc36f926c..fadcbe0afe2 100644 --- a/lib/libcurses/base/lib_slkattr.c +++ b/lib/libcurses/base/lib_slkattr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_slkattr.c,v 1.2 2001/01/22 18:01:46 millert Exp $ */ +/* $OpenBSD: lib_slkattr.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** * Copyright (c) 1998,2000 Free Software Foundation, Inc. * @@ -29,8 +29,8 @@ ****************************************************************************/ /**************************************************************************** - * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * - * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * Author: Juergen Pfeifer, 1997 * + * and: Thomas E. Dickey 2005 * ****************************************************************************/ /* @@ -40,7 +40,7 @@ */ #include <curses.priv.h> -MODULE_ID("$From: lib_slkattr.c,v 1.5 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_slkattr.c,v 1.3 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(attr_t) slk_attr(void) @@ -48,7 +48,11 @@ slk_attr(void) T((T_CALLED("slk_attr()"))); if (SP != 0 && SP->_slk != 0) { - returnAttr(SP->_slk->attr); + attr_t result = AttrOf(SP->_slk->attr) & ALL_BUT_COLOR; + int pair = GetPair(SP->_slk->attr); + + result |= COLOR_PAIR(pair); + returnAttr(result); } else returnAttr(0); } diff --git a/lib/libcurses/base/lib_slkclear.c b/lib/libcurses/base/lib_slkclear.c index 729ece1f185..44a542ef0c4 100644 --- a/lib/libcurses/base/lib_slkclear.c +++ b/lib/libcurses/base/lib_slkclear.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_slkclear.c,v 1.3 2001/01/22 18:01:46 millert Exp $ */ +/* $OpenBSD: lib_slkclear.c,v 1.4 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,8 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Juergen Pfeifer 1996-1999 * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -40,24 +42,27 @@ */ #include <curses.priv.h> -MODULE_ID("$From: lib_slkclear.c,v 1.6 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_slkclear.c,v 1.4 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(int) slk_clear(void) { + int rc = ERR; + T((T_CALLED("slk_clear()"))); - if (SP == NULL || SP->_slk == NULL) - returnCode(ERR); - SP->_slk->hidden = TRUE; - /* For simulated SLK's it's looks much more natural to - inherit those attributes from the standard screen */ - SP->_slk->win->_bkgd = stdscr->_bkgd; - SP->_slk->win->_attrs = stdscr->_attrs; - if (SP->_slk->win == stdscr) { - returnCode(OK); - } else { - werase(SP->_slk->win); - returnCode(wrefresh(SP->_slk->win)); + if (SP != NULL && SP->_slk != NULL) { + SP->_slk->hidden = TRUE; + /* For simulated SLK's it looks much more natural to + inherit those attributes from the standard screen */ + SP->_slk->win->_nc_bkgd = stdscr->_nc_bkgd; + WINDOW_ATTRS(SP->_slk->win) = WINDOW_ATTRS(stdscr); + if (SP->_slk->win == stdscr) { + rc = OK; + } else { + werase(SP->_slk->win); + rc = wrefresh(SP->_slk->win); + } } + returnCode(rc); } diff --git a/lib/libcurses/base/lib_slkcolor.c b/lib/libcurses/base/lib_slkcolor.c index 6b06426dbbe..1fcf42647d6 100644 --- a/lib/libcurses/base/lib_slkcolor.c +++ b/lib/libcurses/base/lib_slkcolor.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_slkcolor.c,v 1.3 2001/01/22 18:01:46 millert Exp $ */ +/* $OpenBSD: lib_slkcolor.c,v 1.4 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2003,2005 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,15 +29,18 @@ ****************************************************************************/ /**************************************************************************** - * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1998 * + * Author: Juergen Pfeifer, 1998 * + * and: Thomas E. Dickey 2005 * ****************************************************************************/ /* * lib_slkcolor.c + * Soft key routines. + * Set the label's color */ #include <curses.priv.h> -MODULE_ID("$From: lib_slkcolor.c,v 1.7 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_slkcolor.c,v 1.4 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(int) slk_color(short color_pair_number) @@ -46,8 +49,9 @@ slk_color(short color_pair_number) if (SP != 0 && SP->_slk != 0 && color_pair_number >= 0 && color_pair_number < COLOR_PAIRS) { - T(("... current %ld", (long) PAIR_NUMBER(SP->_slk->attr))); - toggle_attr_on(SP->_slk->attr, COLOR_PAIR(color_pair_number)); + TR(TRACE_ATTRS, ("... current is %s", _tracech_t(CHREF(SP->_slk->attr)))); + SetPair(SP->_slk->attr, color_pair_number); + TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP->_slk->attr)))); returnCode(OK); } else returnCode(ERR); diff --git a/lib/libcurses/base/lib_slkinit.c b/lib/libcurses/base/lib_slkinit.c index 6159dc6a209..ea1ce623c60 100644 --- a/lib/libcurses/base/lib_slkinit.c +++ b/lib/libcurses/base/lib_slkinit.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_slkinit.c,v 1.2 2001/01/22 18:01:46 millert Exp $ */ +/* $OpenBSD: lib_slkinit.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -40,14 +41,17 @@ */ #include <curses.priv.h> -MODULE_ID("$From: lib_slkinit.c,v 1.5 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_slkinit.c,v 1.3 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(int) slk_init(int format) { + int code = ERR; + T((T_CALLED("slk_init(%d)"), format)); - if (format < 0 || format > 3) - returnCode(ERR); - _nc_slk_format = 1 + format; - returnCode(OK); + if (format >= 0 && format <= 3 && !_nc_globals.slk_format) { + _nc_globals.slk_format = 1 + format; + code = _nc_ripoffline(-SLK_LINES(_nc_globals.slk_format), _nc_slk_initialize); + } + returnCode(code); } diff --git a/lib/libcurses/base/lib_slklab.c b/lib/libcurses/base/lib_slklab.c index 2eb3ff6e0d0..4df19d35dcf 100644 --- a/lib/libcurses/base/lib_slklab.c +++ b/lib/libcurses/base/lib_slklab.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_slklab.c,v 1.2 2001/01/22 18:01:46 millert Exp $ */ +/* $OpenBSD: lib_slklab.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2000,2003 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -40,7 +40,7 @@ */ #include <curses.priv.h> -MODULE_ID("$From: lib_slklab.c,v 1.6 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_slklab.c,v 1.3 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(char *) slk_label(int n) @@ -49,5 +49,5 @@ slk_label(int n) if (SP == NULL || SP->_slk == NULL || n < 1 || n > SP->_slk->labcnt) returnPtr(0); - returnPtr(SP->_slk->ent[n - 1].text); + returnPtr(SP->_slk->ent[n - 1].ent_text); } diff --git a/lib/libcurses/base/lib_slkrefr.c b/lib/libcurses/base/lib_slkrefr.c index 80cdec3e66a..4c58f9dbac6 100644 --- a/lib/libcurses/base/lib_slkrefr.c +++ b/lib/libcurses/base/lib_slkrefr.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_slkrefr.c,v 1.4 2001/01/22 18:01:46 millert Exp $ */ +/* $OpenBSD: lib_slkrefr.c,v 1.5 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2006,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,8 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Juergen Pfeifer 1996-on * + * and: Thomas E. Dickey * ****************************************************************************/ /* @@ -40,7 +42,27 @@ #include <curses.priv.h> #include <term.h> /* num_labels, label_*, plab_norm */ -MODULE_ID("$From: lib_slkrefr.c,v 1.10 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_slkrefr.c,v 1.5 2010/01/12 23:22:06 nicm Exp $") + +/* + * Paint the info line for the PC style SLK emulation. + */ +static void +slk_paint_info(WINDOW *win) +{ + SCREEN *sp = _nc_screen_of(win); + + if (win && sp && (sp->slk_format == 4)) { + int i; + + mvwhline(win, 0, 0, 0, getmaxx(win)); + wmove(win, 0, 0); + + for (i = 0; i < sp->_slk->maxlab; i++) { + mvwprintw(win, 0, sp->_slk->ent[i].ent_x, "F%d", i + 1); + } + } +} /* * Write the soft labels to the soft-key window. @@ -57,18 +79,20 @@ slk_intern_refresh(SLK * slk) if (num_labels > 0 && SLK_STDFMT(fmt)) { if (i < num_labels) { TPUTS_TRACE("plab_norm"); - putp(tparm(plab_norm, i + 1, slk->ent[i].form_text)); + putp(TPARM_2(plab_norm, i + 1, slk->ent[i].form_text)); } } else { - wmove(slk->win, SLK_LINES(fmt) - 1, slk->ent[i].x); - if (SP && SP->_slk) - wattrset(slk->win, SP->_slk->attr); - waddnstr(slk->win, slk->ent[i].form_text, - MAX_SKEY_LEN(fmt)); + if (fmt == 4) + slk_paint_info(slk->win); + wmove(slk->win, SLK_LINES(fmt) - 1, slk->ent[i].ent_x); + if (SP->_slk) { + wattrset(slk->win, AttrOf(SP->_slk->attr)); + } + waddstr(slk->win, slk->ent[i].form_text); /* if we simulate SLK's, it's looking much more natural to use the current ATTRIBUTE also for the label window */ - wattrset(slk->win, stdscr->_attrs); + wattrset(slk->win, WINDOW_ATTRS(stdscr)); } } slk->ent[i].dirty = FALSE; diff --git a/lib/libcurses/base/lib_slkset.c b/lib/libcurses/base/lib_slkset.c index a8360d60f49..6958f8d2a9a 100644 --- a/lib/libcurses/base/lib_slkset.c +++ b/lib/libcurses/base/lib_slkset.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_slkset.c,v 1.3 2001/01/22 18:05:43 millert Exp $ */ +/* $OpenBSD: lib_slkset.c,v 1.4 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2005,2007 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,8 +29,8 @@ ****************************************************************************/ /**************************************************************************** - * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * - * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * Author: Juergen Pfeifer * + * and: Thomas E. Dickey * ****************************************************************************/ /* @@ -40,59 +40,112 @@ #include <curses.priv.h> #include <ctype.h> -MODULE_ID("$From: lib_slkset.c,v 1.6 2000/12/10 02:43:27 tom Exp $") +#if USE_WIDEC_SUPPORT +#if HAVE_WCTYPE_H +#include <wctype.h> +#endif +#endif + +MODULE_ID("$Id: lib_slkset.c,v 1.4 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(int) slk_set(int i, const char *astr, int format) { - SLK *slk = SP->_slk; - size_t len; + SLK *slk; + int offset; + int numchrs; + int numcols; + int limit; const char *str = astr; const char *p; T((T_CALLED("slk_set(%d, \"%s\", %d)"), i, str, format)); - if (slk == NULL || i < 1 || i > slk->labcnt || format < 0 || format > 2) + if (SP == 0 + || (slk = SP->_slk) == 0 + || i < 1 + || i > slk->labcnt + || format < 0 + || format > 2) returnCode(ERR); if (str == NULL) str = ""; + --i; /* Adjust numbering of labels */ - while (isspace(CharOf(*str))) + limit = MAX_SKEY_LEN(SP->slk_format); + while (isspace(UChar(*str))) str++; /* skip over leading spaces */ p = str; - while (isprint(CharOf(*p))) + +#if USE_WIDEC_SUPPORT + numcols = 0; + while (*p != 0) { + mbstate_t state; + wchar_t wc; + size_t need; + + init_mb(state); + need = mbrtowc(0, p, strlen(p), &state); + if (need == (size_t) -1) + break; + mbrtowc(&wc, p, need, &state); + if (!iswprint((wint_t) wc)) + break; + if (wcwidth(wc) + numcols > limit) + break; + numcols += wcwidth(wc); + p += need; + } + numchrs = (p - str); +#else + while (isprint(UChar(*p))) p++; /* The first non-print stops */ - --i; /* Adjust numbering of labels */ + numcols = (p - str); + if (numcols > limit) + numcols = limit; + numchrs = numcols; +#endif - len = (size_t) (p - str); - if (len > (unsigned) slk->maxlen) - len = slk->maxlen; - if (len == 0) - slk->ent[i].text[0] = 0; - else - (void) strlcpy(slk->ent[i].text, str, len+1); - memset(slk->ent[i].form_text, ' ', (unsigned) slk->maxlen); - /* len = strlen(slk->ent[i].text); */ + FreeIfNeeded(slk->ent[i].ent_text); + if ((slk->ent[i].ent_text = strdup(str)) == 0) + returnCode(ERR); + slk->ent[i].ent_text[numchrs] = '\0'; + + if ((slk->ent[i].form_text = (char *) _nc_doalloc(slk->ent[i].form_text, + (unsigned) (limit + + numchrs + 1)) + ) == 0) + returnCode(ERR); switch (format) { + default: case 0: /* left-justified */ - memcpy(slk->ent[i].form_text, - slk->ent[i].text, - len); + offset = 0; break; case 1: /* centered */ - memcpy(slk->ent[i].form_text + (slk->maxlen - len) / 2, - slk->ent[i].text, - len); + offset = (limit - numcols) / 2; break; case 2: /* right-justified */ - memcpy(slk->ent[i].form_text + slk->maxlen - len, - slk->ent[i].text, - len); + offset = limit - numcols; break; } - slk->ent[i].form_text[slk->maxlen] = 0; + if (offset <= 0) + offset = 0; + else + memset(slk->ent[i].form_text, ' ', (unsigned) offset); + + memcpy(slk->ent[i].form_text + offset, + slk->ent[i].ent_text, + (unsigned) numchrs); + + if (offset < limit) { + memset(slk->ent[i].form_text + offset + numchrs, + ' ', + (unsigned) (limit - (offset + numcols))); + } + + slk->ent[i].form_text[numchrs - numcols + limit] = 0; slk->ent[i].dirty = TRUE; returnCode(OK); } diff --git a/lib/libcurses/base/lib_slktouch.c b/lib/libcurses/base/lib_slktouch.c index 34f4fde8261..7137ec44b01 100644 --- a/lib/libcurses/base/lib_slktouch.c +++ b/lib/libcurses/base/lib_slktouch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_slktouch.c,v 1.2 2001/01/22 18:01:47 millert Exp $ */ +/* $OpenBSD: lib_slktouch.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** * Copyright (c) 1998,2000 Free Software Foundation, Inc. * @@ -40,7 +40,7 @@ */ #include <curses.priv.h> -MODULE_ID("$From: lib_slktouch.c,v 1.5 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_slktouch.c,v 1.3 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(int) slk_touch(void) diff --git a/lib/libcurses/base/lib_touch.c b/lib/libcurses/base/lib_touch.c index c883fc6b91f..a19fb982320 100644 --- a/lib/libcurses/base/lib_touch.c +++ b/lib/libcurses/base/lib_touch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_touch.c,v 1.2 2001/01/22 18:01:47 millert Exp $ */ +/* $OpenBSD: lib_touch.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** * Copyright (c) 1998,2000 Free Software Foundation, Inc. * @@ -45,7 +45,7 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_touch.c,v 1.9 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_touch.c,v 1.3 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(bool) is_linetouched(WINDOW *win, int line) diff --git a/lib/libcurses/base/lib_ungetch.c b/lib/libcurses/base/lib_ungetch.c index 3837f645b3a..122776d8ff4 100644 --- a/lib/libcurses/base/lib_ungetch.c +++ b/lib/libcurses/base/lib_ungetch.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_ungetch.c,v 1.2 2001/01/22 18:01:47 millert Exp $ */ +/* $OpenBSD: lib_ungetch.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -42,38 +43,50 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_ungetch.c,v 1.4 2000/12/10 02:43:27 tom Exp $") +MODULE_ID("$Id: lib_ungetch.c,v 1.3 2010/01/12 23:22:06 nicm Exp $") #include <fifo_defs.h> #ifdef TRACE NCURSES_EXPORT(void) -_nc_fifo_dump(void) +_nc_fifo_dump(SCREEN *sp) { int i; T(("head = %d, tail = %d, peek = %d", head, tail, peek)); for (i = 0; i < 10; i++) - T(("char %d = %s", i, _trace_key(SP->_fifo[i]))); + T(("char %d = %s", i, _nc_tracechar(sp, sp->_fifo[i]))); } #endif /* TRACE */ NCURSES_EXPORT(int) -ungetch(int ch) +_nc_ungetch(SCREEN *sp, int ch) { - if (tail == -1) - return ERR; - if (head == -1) { - head = 0; - t_inc() + int rc = ERR; + + if (tail != -1) { + if (head == -1) { + head = 0; + t_inc(); peek = tail; /* no raw keys */ - } else - h_dec(); + } else + h_dec(); - SP->_fifo[head] = ch; - T(("ungetch %#x ok", ch)); + sp->_fifo[head] = ch; + T(("ungetch %s ok", _nc_tracechar(sp, ch))); #ifdef TRACE - if (_nc_tracing & TRACE_IEVENT) - _nc_fifo_dump(); + if (USE_TRACEF(TRACE_IEVENT)) { + _nc_fifo_dump(sp); + _nc_unlock_global(tracef); + } #endif - return OK; + rc = OK; + } + return rc; +} + +NCURSES_EXPORT(int) +ungetch(int ch) +{ + T((T_CALLED("ungetch(%s)"), _nc_tracechar(SP, ch))); + returnCode(_nc_ungetch(SP, ch)); } diff --git a/lib/libcurses/base/lib_vline.c b/lib/libcurses/base/lib_vline.c index 03dee2977ae..03fcac6b2dc 100644 --- a/lib/libcurses/base/lib_vline.c +++ b/lib/libcurses/base/lib_vline.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_vline.c,v 1.3 2001/01/22 18:01:47 millert Exp $ */ +/* $OpenBSD: lib_vline.c,v 1.4 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2001,2006 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -42,7 +42,7 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_vline.c,v 1.7 2000/12/10 02:43:28 tom Exp $") +MODULE_ID("$Id: lib_vline.c,v 1.4 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(int) wvline(WINDOW *win, chtype ch, int n) @@ -54,6 +54,7 @@ wvline(WINDOW *win, chtype ch, int n) T((T_CALLED("wvline(%p,%s,%d)"), win, _tracechtype(ch), n)); if (win) { + NCURSES_CH_T wch; row = win->_cury; col = win->_curx; end = row + n - 1; @@ -61,12 +62,14 @@ wvline(WINDOW *win, chtype ch, int n) end = win->_maxy; if (ch == 0) - ch = ACS_VLINE; - ch = _nc_render(win, ch); + SetChar2(wch, ACS_VLINE); + else + SetChar2(wch, ch); + wch = _nc_render(win, wch); while (end >= row) { struct ldat *line = &(win->_line[end]); - line->text[col] = ch; + line->text[col] = wch; CHANGED_CELL(line, col); end--; } diff --git a/lib/libcurses/base/lib_wattroff.c b/lib/libcurses/base/lib_wattroff.c index 38d5cfb0d31..9dfdb95a929 100644 --- a/lib/libcurses/base/lib_wattroff.c +++ b/lib/libcurses/base/lib_wattroff.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_wattroff.c,v 1.2 2001/01/22 18:01:47 millert Exp $ */ +/* $OpenBSD: lib_wattroff.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -43,16 +44,22 @@ #include <curses.priv.h> #include <ctype.h> -MODULE_ID("$From: lib_wattroff.c,v 1.6 2000/12/10 02:43:28 tom Exp $") +MODULE_ID("$Id: lib_wattroff.c,v 1.3 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(int) -wattr_off -(WINDOW *win, NCURSES_CONST attr_t at, void *opts GCC_UNUSED) +wattr_off(WINDOW *win, attr_t at, void *opts GCC_UNUSED) { T((T_CALLED("wattr_off(%p,%s)"), win, _traceattr(at))); if (win) { - T(("... current %s", _traceattr(win->_attrs))); - toggle_attr_off(win->_attrs, at); + T(("... current %s (%d)", + _traceattr(WINDOW_ATTRS(win)), + GET_WINDOW_PAIR(win))); + + if_EXT_COLORS({ + if (at & A_COLOR) + win->_color = 0; + }); + toggle_attr_off(WINDOW_ATTRS(win), at); returnCode(OK); } else returnCode(ERR); diff --git a/lib/libcurses/base/lib_wattron.c b/lib/libcurses/base/lib_wattron.c index b788582bc19..cadbae69980 100644 --- a/lib/libcurses/base/lib_wattron.c +++ b/lib/libcurses/base/lib_wattron.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_wattron.c,v 1.2 2001/01/22 18:01:47 millert Exp $ */ +/* $OpenBSD: lib_wattron.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -43,16 +44,22 @@ #include <curses.priv.h> #include <ctype.h> -MODULE_ID("$From: lib_wattron.c,v 1.6 2000/12/10 02:43:28 tom Exp $") +MODULE_ID("$Id: lib_wattron.c,v 1.3 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(int) -wattr_on -(WINDOW *win, NCURSES_CONST attr_t at, void *opts GCC_UNUSED) +wattr_on(WINDOW *win, attr_t at, void *opts GCC_UNUSED) { T((T_CALLED("wattr_on(%p,%s)"), win, _traceattr(at))); - if (win) { - T(("... current %s", _traceattr(win->_attrs))); - toggle_attr_on(win->_attrs, at); + if (win != 0) { + T(("... current %s (%d)", + _traceattr(WINDOW_ATTRS(win)), + GET_WINDOW_PAIR(win))); + + if_EXT_COLORS({ + if (at & A_COLOR) + win->_color = PAIR_NUMBER(at); + }); + toggle_attr_on(WINDOW_ATTRS(win), at); returnCode(OK); } else returnCode(ERR); diff --git a/lib/libcurses/base/lib_winch.c b/lib/libcurses/base/lib_winch.c index 9dc58e732b9..870ebea83a2 100644 --- a/lib/libcurses/base/lib_winch.c +++ b/lib/libcurses/base/lib_winch.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_winch.c,v 1.3 2001/01/22 18:01:48 millert Exp $ */ +/* $OpenBSD: lib_winch.c,v 1.4 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -41,14 +41,15 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_winch.c,v 1.4 2000/12/10 02:43:28 tom Exp $") +MODULE_ID("$Id: lib_winch.c,v 1.4 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(chtype) winch(WINDOW *win) { T((T_CALLED("winch(%p)"), win)); if (win != 0) { - returnChar(win->_line[win->_cury].text[win->_curx]); + returnChar(CharOf(win->_line[win->_cury].text[win->_curx]) | + AttrOf(win->_line[win->_cury].text[win->_curx])); } else { returnChar(0); } diff --git a/lib/libcurses/base/lib_window.c b/lib/libcurses/base/lib_window.c index 6cfe4ac6fc4..1143622c938 100644 --- a/lib/libcurses/base/lib_window.c +++ b/lib/libcurses/base/lib_window.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_window.c,v 1.2 2001/01/22 18:01:48 millert Exp $ */ +/* $OpenBSD: lib_window.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -41,7 +41,7 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_window.c,v 1.15 2000/12/10 02:43:28 tom Exp $") +MODULE_ID("$Id: lib_window.c,v 1.3 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(void) _nc_synchook(WINDOW *win) @@ -100,7 +100,8 @@ wsyncup(WINDOW *win) { WINDOW *wp; - if (win && win->_parent) + T((T_CALLED("wsyncup(%p)"), win)); + if (win && win->_parent) { for (wp = win; wp->_parent; wp = wp->_parent) { int y; WINDOW *pp = wp->_parent; @@ -120,6 +121,8 @@ wsyncup(WINDOW *win) } } } + } + returnVoid; } NCURSES_EXPORT(void) @@ -127,6 +130,8 @@ wsyncdown(WINDOW *win) /* mark changed every cell in win that is changed in any of its ancestors */ /* Rewritten by J. Pfeifer, 1-Apr-96 (don't even think that...) */ { + T((T_CALLED("wsyncdown(%p)"), win)); + if (win && win->_parent) { WINDOW *pp = win->_parent; int y; @@ -146,7 +151,7 @@ wsyncdown(WINDOW *win) /* left and right character in child coordinates */ int left = pp->_line[win->_pary + y].firstchar - win->_parx; int right = pp->_line[win->_pary + y].lastchar - win->_parx; - /* The change maybe outside the childs range */ + /* The change may be outside the child's range */ if (left < 0) left = 0; if (right > win->_maxx) @@ -155,6 +160,7 @@ wsyncdown(WINDOW *win) } } } + returnVoid; } NCURSES_EXPORT(void) @@ -162,64 +168,85 @@ wcursyncup(WINDOW *win) /* sync the cursor in all derived windows to its value in the base window */ { WINDOW *wp; + + T((T_CALLED("wcursyncup(%p)"), win)); for (wp = win; wp && wp->_parent; wp = wp->_parent) { wmove(wp->_parent, wp->_pary + wp->_cury, wp->_parx + wp->_curx); } + returnVoid; } NCURSES_EXPORT(WINDOW *) dupwin(WINDOW *win) /* make an exact duplicate of the given window */ { - WINDOW *nwin; + WINDOW *nwin = 0; size_t linesize; int i; T((T_CALLED("dupwin(%p)"), win)); - if ((win == NULL) || - ((nwin = newwin(win->_maxy + 1, win->_maxx + 1, win->_begy, - win->_begx)) == NULL)) - returnWin(0); - - nwin->_curx = win->_curx; - nwin->_cury = win->_cury; - nwin->_maxy = win->_maxy; - nwin->_maxx = win->_maxx; - nwin->_begy = win->_begy; - nwin->_begx = win->_begx; - nwin->_yoffset = win->_yoffset; - - nwin->_flags = win->_flags & ~_SUBWIN; - /* Due to the use of newwin(), the clone is not a subwindow. - * The text is really copied into the clone. - */ - - nwin->_attrs = win->_attrs; - nwin->_bkgd = win->_bkgd; - - nwin->_clear = win->_clear; - nwin->_scroll = win->_scroll; - nwin->_leaveok = win->_leaveok; - nwin->_use_keypad = win->_use_keypad; - nwin->_delay = win->_delay; - nwin->_immed = win->_immed; - nwin->_sync = win->_sync; - - nwin->_parx = 0; - nwin->_pary = 0; - nwin->_parent = (WINDOW *) 0; - /* See above: the clone isn't a subwindow! */ - - nwin->_regtop = win->_regtop; - nwin->_regbottom = win->_regbottom; - - linesize = (win->_maxx + 1) * sizeof(chtype); - for (i = 0; i <= nwin->_maxy; i++) { - memcpy(nwin->_line[i].text, win->_line[i].text, linesize); - nwin->_line[i].firstchar = win->_line[i].firstchar; - nwin->_line[i].lastchar = win->_line[i].lastchar; - } + if (win != 0) { + + _nc_lock_global(curses); + if (win->_flags & _ISPAD) { + nwin = newpad(win->_maxy + 1, + win->_maxx + 1); + } else { + nwin = newwin(win->_maxy + 1, + win->_maxx + 1, + win->_begy, + win->_begx); + } + if (nwin != 0) { + + nwin->_curx = win->_curx; + nwin->_cury = win->_cury; + nwin->_maxy = win->_maxy; + nwin->_maxx = win->_maxx; + nwin->_begy = win->_begy; + nwin->_begx = win->_begx; + nwin->_yoffset = win->_yoffset; + + nwin->_flags = win->_flags & ~_SUBWIN; + /* Due to the use of newwin(), the clone is not a subwindow. + * The text is really copied into the clone. + */ + + WINDOW_ATTRS(nwin) = WINDOW_ATTRS(win); + nwin->_nc_bkgd = win->_nc_bkgd; + + nwin->_notimeout = win->_notimeout; + nwin->_clear = win->_clear; + nwin->_leaveok = win->_leaveok; + nwin->_scroll = win->_scroll; + nwin->_idlok = win->_idlok; + nwin->_idcok = win->_idcok; + nwin->_immed = win->_immed; + nwin->_sync = win->_sync; + nwin->_use_keypad = win->_use_keypad; + nwin->_delay = win->_delay; + + nwin->_parx = 0; + nwin->_pary = 0; + nwin->_parent = (WINDOW *) 0; + /* See above: the clone isn't a subwindow! */ + + nwin->_regtop = win->_regtop; + nwin->_regbottom = win->_regbottom; + + if (win->_flags & _ISPAD) + nwin->_pad = win->_pad; + + linesize = (win->_maxx + 1) * sizeof(NCURSES_CH_T); + for (i = 0; i <= nwin->_maxy; i++) { + memcpy(nwin->_line[i].text, win->_line[i].text, linesize); + nwin->_line[i].firstchar = win->_line[i].firstchar; + nwin->_line[i].lastchar = win->_line[i].lastchar; + } + } + _nc_unlock_global(curses); + } returnWin(nwin); } diff --git a/lib/libcurses/base/nc_panel.c b/lib/libcurses/base/nc_panel.c index 00bbda062f8..452153859c9 100644 --- a/lib/libcurses/base/nc_panel.c +++ b/lib/libcurses/base/nc_panel.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nc_panel.c,v 1.2 2001/01/22 18:01:48 millert Exp $ */ +/* $OpenBSD: nc_panel.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** * Copyright (c) 1998,2000 Free Software Foundation, Inc. * @@ -34,7 +34,7 @@ #include <curses.priv.h> -MODULE_ID("$From: nc_panel.c,v 1.4 2000/12/10 02:43:28 tom Exp $") +MODULE_ID("$Id: nc_panel.c,v 1.3 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(struct panelhook *) _nc_panelhook(void) diff --git a/lib/libcurses/base/resizeterm.c b/lib/libcurses/base/resizeterm.c index 829f9148820..8f8c7131b83 100644 --- a/lib/libcurses/base/resizeterm.c +++ b/lib/libcurses/base/resizeterm.c @@ -1,7 +1,7 @@ -/* $OpenBSD: resizeterm.c,v 1.2 2001/01/22 18:01:48 millert Exp $ */ +/* $OpenBSD: resizeterm.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,7 +29,7 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey <dickey@clark.net> 1996,1997 * + * Author: Thomas E. Dickey * ****************************************************************************/ /* @@ -43,69 +43,319 @@ #include <curses.priv.h> #include <term.h> -MODULE_ID("$From: resizeterm.c,v 1.9 2000/12/10 02:43:28 tom Exp $") +MODULE_ID("$Id: resizeterm.c,v 1.3 2010/01/12 23:22:06 nicm Exp $") + +#define stolen_lines (screen_lines - SP->_lines_avail) /* - * This function reallocates NCURSES window structures. It is invoked in - * response to a SIGWINCH interrupt. Other user-defined windows may also need - * to be reallocated. - * - * Because this performs memory allocation, it should not (in general) be - * invoked directly from the signal handler. + * If we're trying to be reentrant, do not want any local statics. + */ +#if USE_REENTRANT +#define EXTRA_ARGS , CurLines, CurCols +#define EXTRA_DCLS , int CurLines, int CurCols +#else +static int current_lines; +static int current_cols; +#define CurLines current_lines +#define CurCols current_cols +#define EXTRA_ARGS /* nothing */ +#define EXTRA_DCLS /* nothing */ +#endif + +#ifdef TRACE +static void +show_window_sizes(const char *name) +{ + WINDOWLIST *wp; + + _nc_lock_global(curses); + _tracef("%s resizing: %2d x %2d (%2d x %2d)", name, LINES, COLS, + screen_lines, screen_columns); + for (each_window(wp)) { + _tracef(" window %p is %2ld x %2ld at %2ld,%2ld", + &(wp->win), + (long) wp->win._maxy + 1, + (long) wp->win._maxx + 1, + (long) wp->win._begy, + (long) wp->win._begx); + } + _nc_unlock_global(curses); +} +#endif + +/* + * Return true if the given dimensions do not match the internal terminal + * structure's size. + */ +NCURSES_EXPORT(bool) +is_term_resized(int ToLines, int ToCols) +{ + T((T_CALLED("is_term_resized(%d, %d)"), ToLines, ToCols)); + returnCode(ToLines > 0 + && ToCols > 0 + && (ToLines != screen_lines + || ToCols != screen_columns)); +} + +/* + */ +static ripoff_t * +ripped_window(WINDOW *win) +{ + ripoff_t *result = 0; + ripoff_t *rop; + + if (win != 0) { + for (each_ripoff(rop)) { + if (rop->win == win && rop->line != 0) { + result = rop; + break; + } + } + } + return result; +} + +/* + * Returns the number of lines from the bottom for the beginning of a ripped + * off window. + */ +static int +ripped_bottom(WINDOW *win) +{ + int result = 0; + ripoff_t *rop; + + if (win != 0) { + for (each_ripoff(rop)) { + if (rop->line < 0) { + result -= rop->line; + if (rop->win == win) { + break; + } + } + } + } + return result; +} + +/* + * Return the number of levels of child-windows under the current window. + */ +static int +child_depth(WINDOW *cmp) +{ + int depth = 0; + + if (cmp != 0) { + WINDOWLIST *wp; + + for (each_window(wp)) { + WINDOW *tst = &(wp->win); + if (tst->_parent == cmp) { + depth = 1 + child_depth(tst); + break; + } + } + } + return depth; +} + +/* + * Return the number of levels of parent-windows above the current window. + */ +static int +parent_depth(WINDOW *cmp) +{ + int depth = 0; + + if (cmp != 0) { + WINDOW *tst; + while ((tst = cmp->_parent) != 0) { + ++depth; + cmp = tst; + } + } + return depth; +} + +/* + * FIXME: must adjust position so it's within the parent! + */ +static int +adjust_window(WINDOW *win, int ToLines, int ToCols, int stolen EXTRA_DCLS) +{ + int result; + int bottom = CurLines + SP->_topstolen - stolen; + int myLines = win->_maxy + 1; + int myCols = win->_maxx + 1; + ripoff_t *rop = ripped_window(win); + + T((T_CALLED("adjust_window(%p,%d,%d)%s depth %d/%d currently %ldx%ld at %ld,%ld"), + win, ToLines, ToCols, + (rop != 0) ? " (rip)" : "", + parent_depth(win), + child_depth(win), + (long) getmaxy(win), (long) getmaxx(win), + (long) getbegy(win) + win->_yoffset, (long) getbegx(win))); + + if (rop != 0 && rop->line < 0) { + /* + * If it is a ripped-off window at the bottom of the screen, simply + * move it to the same relative position. + */ + win->_begy = ToLines - ripped_bottom(win) - 0 - win->_yoffset; + } else if (win->_begy >= bottom) { + /* + * If it is below the bottom of the new screen, move up by the same + * amount that the screen shrank. + */ + win->_begy += (ToLines - CurLines); + } else { + if (myLines == (CurLines - stolen) + && ToLines != CurLines) { + myLines = ToLines - stolen; + } else if (myLines == CurLines + && ToLines != CurLines) { + myLines = ToLines; + } + } + + if (myLines > ToLines) { + myLines = ToLines; + } + + if (myCols > ToCols) + myCols = ToCols; + + if (myCols == CurCols + && ToCols != CurCols) + myCols = ToCols; + + result = wresize(win, myLines, myCols); + returnCode(result); +} + +/* + * If we're decreasing size, recursively search for windows that have no + * children, decrease those to fit, then decrease the containing window, etc. + */ +static int +decrease_size(int ToLines, int ToCols, int stolen EXTRA_DCLS) +{ + bool found; + int depth = 0; + WINDOWLIST *wp; + + T((T_CALLED("decrease_size(%d, %d)"), ToLines, ToCols)); + + do { + found = FALSE; + TR(TRACE_UPDATE, ("decreasing size of windows to %dx%d, depth=%d", + ToLines, ToCols, depth)); + for (each_window(wp)) { + WINDOW *win = &(wp->win); + + if (!(win->_flags & _ISPAD)) { + if (child_depth(win) == depth) { + found = TRUE; + if (adjust_window(win, ToLines, ToCols, + stolen EXTRA_ARGS) != OK) + returnCode(ERR); + } + } + } + ++depth; + } while (found); + returnCode(OK); +} + +/* + * If we're increasing size, recursively search for windows that have no + * parent, increase those to fit, then increase the contained window, etc. + */ +static int +increase_size(int ToLines, int ToCols, int stolen EXTRA_DCLS) +{ + bool found; + int depth = 0; + WINDOWLIST *wp; + + T((T_CALLED("increase_size(%d, %d)"), ToLines, ToCols)); + + do { + found = FALSE; + TR(TRACE_UPDATE, ("increasing size of windows to %dx%d, depth=%d", + ToLines, ToCols, depth)); + for (each_window(wp)) { + WINDOW *win = &(wp->win); + + if (!(win->_flags & _ISPAD)) { + if (parent_depth(win) == depth) { + found = TRUE; + if (adjust_window(win, ToLines, ToCols, + stolen EXTRA_ARGS) != OK) + returnCode(ERR); + } + } + } + ++depth; + } while (found); + returnCode(OK); +} + +/* + * This function reallocates NCURSES window structures, with no side-effects + * such as ungetch(). */ NCURSES_EXPORT(int) -resizeterm(int ToLines, int ToCols) +resize_term(int ToLines, int ToCols) { - int stolen = screen_lines - SP->_lines_avail; - int bottom = screen_lines + SP->_topstolen - stolen; + int result = OK EXTRA_ARGS; + int was_stolen; - T((T_CALLED("resizeterm(%d,%d) old(%d,%d)"), + T((T_CALLED("resize_term(%d,%d) old(%d,%d)"), ToLines, ToCols, screen_lines, screen_columns)); - SP->_sig_winch = FALSE; + if (SP == 0) { + returnCode(ERR); + } - if (ToLines != screen_lines - || ToCols != screen_columns) { - WINDOWLIST *wp; + _nc_lock_global(curses); -#if USE_SIGWINCH - ungetch(KEY_RESIZE); /* so application can know this */ - clearok(curscr, TRUE); /* screen contents are unknown */ -#endif + was_stolen = (screen_lines - SP->_lines_avail); + if (is_term_resized(ToLines, ToCols)) { + int myLines = CurLines = screen_lines; + int myCols = CurCols = screen_columns; - for (wp = _nc_windows; wp != 0; wp = wp->next) { - WINDOW *win = wp->win; - int myLines = win->_maxy + 1; - int myCols = win->_maxx + 1; - - /* pads aren't treated this way */ - if (win->_flags & _ISPAD) - continue; - - if (win->_begy >= bottom) { - win->_begy += (ToLines - screen_lines); - } else { - if (myLines == screen_lines - stolen - && ToLines != screen_lines) - myLines = ToLines - stolen; - else if (myLines == screen_lines - && ToLines != screen_lines) - myLines = ToLines; - } +#ifdef TRACE + if (USE_TRACEF(TRACE_UPDATE)) { + show_window_sizes("before"); + _nc_unlock_global(tracef); + } +#endif + if (ToLines > screen_lines) { + increase_size(myLines = ToLines, myCols, was_stolen EXTRA_ARGS); + CurLines = myLines; + CurCols = myCols; + } - if (myCols == screen_columns - && ToCols != screen_columns) - myCols = ToCols; + if (ToCols > screen_columns) { + increase_size(myLines, myCols = ToCols, was_stolen EXTRA_ARGS); + CurLines = myLines; + CurCols = myCols; + } - if (wresize(win, myLines, myCols) != OK) - returnCode(ERR); + if (ToLines < myLines || + ToCols < myCols) { + decrease_size(ToLines, ToCols, was_stolen EXTRA_ARGS); } screen_lines = lines = ToLines; screen_columns = columns = ToCols; - SP->_lines_avail = lines - stolen; + SP->_lines_avail = lines - was_stolen; if (SP->oldhash) { FreeAndNull(SP->oldhash); @@ -113,14 +363,95 @@ resizeterm(int ToLines, int ToCols) if (SP->newhash) { FreeAndNull(SP->newhash); } +#ifdef TRACE + if (USE_TRACEF(TRACE_UPDATE)) { + SET_LINES(ToLines - was_stolen); + SET_COLS(ToCols); + show_window_sizes("after"); + _nc_unlock_global(tracef); + } +#endif } /* * Always update LINES, to allow for call from lib_doupdate.c which * needs to have the count adjusted by the stolen (ripped off) lines. */ - LINES = ToLines - stolen; - COLS = ToCols; + SET_LINES(ToLines - was_stolen); + SET_COLS(ToCols); - returnCode(OK); + _nc_unlock_global(curses); + + returnCode(result); +} + +/* + * This function reallocates NCURSES window structures. It is invoked in + * response to a SIGWINCH interrupt. Other user-defined windows may also need + * to be reallocated. + * + * Because this performs memory allocation, it should not (in general) be + * invoked directly from the signal handler. + */ +NCURSES_EXPORT(int) +resizeterm(int ToLines, int ToCols) +{ + int result = ERR; + + T((T_CALLED("resizeterm(%d,%d) old(%d,%d)"), + ToLines, ToCols, + screen_lines, screen_columns)); + + if (SP != 0) { + result = OK; + SP->_sig_winch = FALSE; + + if (is_term_resized(ToLines, ToCols)) { +#if USE_SIGWINCH + ripoff_t *rop; + bool slk_visible = (SP != 0 + && SP->_slk != 0 + && !(SP->_slk->hidden)); + + if (slk_visible) { + slk_clear(); + } +#endif + result = resize_term(ToLines, ToCols); + +#if USE_SIGWINCH + _nc_ungetch(SP, KEY_RESIZE); /* so application can know this */ + clearok(curscr, TRUE); /* screen contents are unknown */ + + /* ripped-off lines are a special case: if we did not lengthen + * them, we haven't moved them either. repaint them, too. + * + * for the rest - stdscr and other windows - the client has to + * decide which to repaint, since without panels, ncurses does + * not know which are really on top. + */ + for (each_ripoff(rop)) { + if (rop->win != stdscr + && rop->win != 0 + && rop->line < 0) { + + if (rop->hook != _nc_slk_initialize) { + touchwin(rop->win); + wnoutrefresh(rop->win); + } + } + } + + /* soft-keys are a special case: we _know_ how to repaint them */ + if (slk_visible) { + slk_restore(); + slk_touch(); + + slk_refresh(); + } +#endif + } + } + + returnCode(result); } diff --git a/lib/libcurses/base/safe_sprintf.c b/lib/libcurses/base/safe_sprintf.c index 616a50127c7..4173a32ee77 100644 --- a/lib/libcurses/base/safe_sprintf.c +++ b/lib/libcurses/base/safe_sprintf.c @@ -1,7 +1,7 @@ -/* $OpenBSD: safe_sprintf.c,v 1.4 2001/01/22 18:01:48 millert Exp $ */ +/* $OpenBSD: safe_sprintf.c,v 1.5 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2003,2007 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -35,7 +35,7 @@ #include <curses.priv.h> #include <ctype.h> -MODULE_ID("$From: safe_sprintf.c,v 1.13 2000/12/10 02:43:28 tom Exp $") +MODULE_ID("$Id: safe_sprintf.c,v 1.5 2010/01/12 23:22:06 nicm Exp $") #if USE_SAFE_SPRINTF @@ -58,10 +58,13 @@ _nc_printf_length(const char *fmt, va_list ap) char *buffer; char *format; int len = 0; + size_t fmt_len; + char fmt_arg[BUFSIZ]; if (fmt == 0 || *fmt == '\0') - return -1; - if ((format = typeMalloc(char, strlen(fmt) + 1)) == 0) + return 0; + fmt_len = strlen(fmt) + 1; + if ((format = typeMalloc(char, fmt_len)) == 0) return -1; if ((buffer = typeMalloc(char, length)) == 0) { free(format); @@ -86,7 +89,7 @@ _nc_printf_length(const char *fmt, va_list ap) while (*++fmt != '\0' && len >= 0 && !done) { format[f++] = *fmt; - if (isdigit(*fmt)) { + if (isdigit(UChar(*fmt))) { int num = *fmt - '0'; if (state == Flags && num != 0) state = Width; @@ -108,9 +111,14 @@ _nc_printf_length(const char *fmt, va_list ap) } else if (state == Prec) { prec = ival; } - sprintf(&format[--f], "%d", ival); + sprintf(fmt_arg, "%d", ival); + fmt_len += strlen(fmt_arg); + if ((format = realloc(format, fmt_len)) == 0) { + return -1; + } + strcpy(&format[--f], fmt_arg); f = strlen(format); - } else if (isalpha(*fmt)) { + } else if (isalpha(UChar(*fmt))) { done = TRUE; switch (*fmt) { case 'Z': /* FALLTHRU */ @@ -201,46 +209,58 @@ _nc_printf_length(const char *fmt, va_list ap) } #endif +#define my_buffer _nc_globals.safeprint_buf +#define my_length _nc_globals.safeprint_used + /* * Wrapper for vsprintf that allocates a buffer big enough to hold the result. */ NCURSES_EXPORT(char *) -_nc_printf_string -(const char *fmt, va_list ap) +_nc_printf_string(const char *fmt, va_list ap) { + char *result = 0; + + if (fmt != 0) { #if USE_SAFE_SPRINTF - char *buf = 0; - int len = _nc_printf_length(fmt, ap); + int len = _nc_printf_length(fmt, ap); - if (len > 0) { - if ((buf = typeMalloc(char, len + 1)) == 0) - return (0); - vsprintf(buf, fmt, ap); - } + if ((int) my_length < len + 1) { + my_length = 2 * (len + 1); + my_buffer = typeRealloc(char, my_length, my_buffer); + } + if (my_buffer != 0) { + *my_buffer = '\0'; + if (len >= 0) { + vsprintf(my_buffer, fmt, ap); + } + result = my_buffer; + } #else - static int rows, cols; - static char *buf; - static size_t len; - - if (screen_lines > rows || screen_columns > cols) { - if (screen_lines > rows) - rows = screen_lines; - if (screen_columns > cols) - cols = screen_columns; - len = (rows * (cols + 1)) + 1; - buf = typeRealloc(char, len, buf); - if (buf == 0) { - return (0); +#define MyCols _nc_globals.safeprint_cols +#define MyRows _nc_globals.safeprint_rows + + if (screen_lines > MyRows || screen_columns > MyCols) { + if (screen_lines > MyRows) + MyRows = screen_lines; + if (screen_columns > MyCols) + MyCols = screen_columns; + my_length = (MyRows * (MyCols + 1)) + 1; + my_buffer = typeRealloc(char, my_length, my_buffer); } - } - if (buf != 0) { + if (my_buffer != 0) { # if HAVE_VSNPRINTF - vsnprintf(buf, len, fmt, ap); /* GNU extension */ + vsnprintf(my_buffer, my_length, fmt, ap); /* GNU extension */ # else - vsprintf(buf, fmt, ap); /* ANSI */ + vsprintf(my_buffer, fmt, ap); /* ANSI */ # endif - } + result = my_buffer; + } #endif - return buf; + } else if (my_buffer != 0) { /* see _nc_freeall() */ + free(my_buffer); + my_buffer = 0; + my_length = 0; + } + return result; } diff --git a/lib/libcurses/base/tries.c b/lib/libcurses/base/tries.c index 15d48289d49..704498044b0 100644 --- a/lib/libcurses/base/tries.c +++ b/lib/libcurses/base/tries.c @@ -1,7 +1,7 @@ -/* $OpenBSD: tries.c,v 1.4 2001/01/22 18:01:48 millert Exp $ */ +/* $OpenBSD: tries.c,v 1.5 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -41,17 +41,16 @@ #include <curses.priv.h> -MODULE_ID("$From: tries.c,v 1.14 2000/12/10 02:43:28 tom Exp $") +MODULE_ID("$Id: tries.c,v 1.5 2010/01/12 23:22:06 nicm Exp $") /* * Expand a keycode into the string that it corresponds to, returning null if * no match was found, otherwise allocating a string of the result. */ NCURSES_EXPORT(char *) -_nc_expand_try -(struct tries *tree, unsigned short code, int *count, size_t len) +_nc_expand_try(TRIES * tree, unsigned code, int *count, size_t len) { - struct tries *ptr = tree; + TRIES *ptr = tree; char *result = 0; if (code != 0) { @@ -71,11 +70,13 @@ _nc_expand_try } } if (result != 0) { - if ((result[len] = ptr->ch) == 0) + if (ptr != 0 && (result[len] = (char) ptr->ch) == 0) *((unsigned char *) (result + len)) = 128; #ifdef TRACE - if (len == 0) - _tracef("expand_key %s %s", _trace_key(code), _nc_visbuf(result)); + if (len == 0 && USE_TRACEF(TRACE_MAXIMUM)) { + _tracef("expand_key %s %s", _nc_tracechar(SP, code), _nc_visbuf(result)); + _nc_unlock_global(tracef); + } #endif } return result; @@ -86,8 +87,7 @@ _nc_expand_try * true if the code was found/removed. */ NCURSES_EXPORT(int) -_nc_remove_key -(struct tries **tree, unsigned short code) +_nc_remove_key(TRIES ** tree, unsigned code) { T((T_CALLED("_nc_remove_key(%p,%d)"), tree, code)); @@ -103,7 +103,7 @@ _nc_remove_key /* don't cut the whole sub-tree */ (*tree)->value = 0; } else { - struct tries *to_free = *tree; + TRIES *to_free = *tree; *tree = (*tree)->sibling; free(to_free); } @@ -119,7 +119,7 @@ _nc_remove_key * true if the string was found/removed. */ NCURSES_EXPORT(int) -_nc_remove_string(struct tries **tree, char *string) +_nc_remove_string(TRIES ** tree, const char *string) { T((T_CALLED("_nc_remove_string(%p,%s)"), tree, _nc_visbuf(string))); @@ -127,18 +127,17 @@ _nc_remove_string(struct tries **tree, char *string) returnCode(FALSE); while (*tree != 0) { - if ((unsigned char) (*tree)->ch == (unsigned char) *string) { + if (UChar((*tree)->ch) == UChar(*string)) { if (string[1] != 0) returnCode(_nc_remove_string(&(*tree)->child, string + 1)); - if ((*tree)->child) { - /* don't cut the whole sub-tree */ - (*tree)->value = 0; - } else { - struct tries *to_free = *tree; + if ((*tree)->child == 0) { + TRIES *to_free = *tree; *tree = (*tree)->sibling; free(to_free); + returnCode(TRUE); + } else { + returnCode(FALSE); } - returnCode(TRUE); } tree = &(*tree)->sibling; } diff --git a/lib/libcurses/base/use_window.c b/lib/libcurses/base/use_window.c new file mode 100644 index 00000000000..ead06ec1440 --- /dev/null +++ b/lib/libcurses/base/use_window.c @@ -0,0 +1,50 @@ +/* $OpenBSD: use_window.c,v 1.1 2010/01/12 23:22:06 nicm Exp $ */ + +/**************************************************************************** + * Copyright (c) 2007,2008 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey 2007 * + ****************************************************************************/ + +#include <curses.priv.h> + +MODULE_ID("$Id: use_window.c,v 1.1 2010/01/12 23:22:06 nicm Exp $") + +NCURSES_EXPORT(int) +use_window(WINDOW *win, NCURSES_WINDOW_CB func, void *data) +{ + int code = OK; + + T((T_CALLED("use_window(%p,%p,%p)"), win, func, data)); + _nc_lock_global(curses); + code = func(win, data); + _nc_unlock_global(curses); + + returnCode(code); +} diff --git a/lib/libcurses/base/version.c b/lib/libcurses/base/version.c index 99cd40934e4..7387797accf 100644 --- a/lib/libcurses/base/version.c +++ b/lib/libcurses/base/version.c @@ -1,5 +1,7 @@ +/* $OpenBSD: version.c,v 1.5 2010/01/12 23:22:06 nicm Exp $ */ + /**************************************************************************** - * Copyright (c) 1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1999-2004,2005 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -32,16 +34,11 @@ #include <curses.priv.h> -MODULE_ID("$From: version.c,v 1.4 2000/12/10 02:43:28 tom Exp $") +MODULE_ID("$Id: version.c,v 1.5 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(const char *) curses_version(void) { - static char my_version[80]; - T((T_CALLED("curses_version()"))); - snprintf(my_version, sizeof(my_version), "ncurses %s.%d", - NCURSES_VERSION, - NCURSES_VERSION_PATCH); - returnPtr(my_version); + returnCPtr("ncurses " NCURSES_VERSION_STRING); } diff --git a/lib/libcurses/base/vsscanf.c b/lib/libcurses/base/vsscanf.c new file mode 100644 index 00000000000..0a283e30c9c --- /dev/null +++ b/lib/libcurses/base/vsscanf.c @@ -0,0 +1,358 @@ +/* $OpenBSD: vsscanf.c,v 1.1 2010/01/12 23:22:06 nicm Exp $ */ + +/**************************************************************************** + * Copyright (c) 1998-2003,2004 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * State-machine fallback written by Thomas E. Dickey 2002 * + ****************************************************************************/ + +/* + * This function is needed to support vwscanw + */ + +#include <curses.priv.h> + +#if !HAVE_VSSCANF + +MODULE_ID("$Id: vsscanf.c,v 1.1 2010/01/12 23:22:06 nicm Exp $") + +#if !(HAVE_VFSCANF || HAVE__DOSCAN) + +#include <ctype.h> + +#define L_SQUARE '[' +#define R_SQUARE ']' + +typedef enum { + cUnknown + ,cError /* anything that isn't ANSI */ + ,cAssigned + ,cChar + ,cInt + ,cFloat + ,cDouble + ,cPointer + ,cLong + ,cShort + ,cRange + ,cString +} ChunkType; + +typedef enum { + oUnknown + ,oShort + ,oLong +} OtherType; + +typedef enum { + sUnknown + ,sPercent /* last was '%' beginning a format */ + ,sNormal /* ...somewhere in the middle */ + ,sLeft /* last was left square bracket beginning a range */ + ,sRange /* ...somewhere in the middle */ + ,sFinal /* last finished a format */ +} ScanState; + +static ChunkType +final_ch(int ch, OtherType other) +{ + ChunkType result = cUnknown; + + switch (ch) { + case 'c': + if (other == oUnknown) + result = cChar; + else + result = cError; + break; + case 'd': + case 'i': + case 'X': + case 'x': + switch (other) { + case oUnknown: + result = cInt; + break; + case oShort: + result = cShort; + break; + case oLong: + result = cLong; + break; + } + break; + case 'E': + case 'e': + case 'f': + case 'g': + switch (other) { + case oUnknown: + result = cFloat; + break; + case oShort: + result = cError; + break; + case oLong: + result = cDouble; + break; + } + break; + case 'n': + if (other == oUnknown) + result = cAssigned; + else + result = cError; + break; + case 'p': + if (other == oUnknown) + result = cPointer; + else + result = cError; + break; + case 's': + if (other == oUnknown) + result = cString; + else + result = cError; + break; + } + return result; +} + +static OtherType +other_ch(int ch) +{ + OtherType result = oUnknown; + switch (ch) { + case 'h': + result = oShort; + break; + case 'l': + result = oLong; + break; + } + return result; +} +#endif + +/*VARARGS2*/ +NCURSES_EXPORT(int) +vsscanf(const char *str, const char *format, va_list ap) +{ +#if HAVE_VFSCANF || HAVE__DOSCAN + /* + * This code should work on anything descended from AT&T SVr1. + */ + FILE strbuf; + + strbuf._flag = _IOREAD; + strbuf._ptr = strbuf._base = (unsigned char *) str; + strbuf._cnt = strlen(str); + strbuf._file = _NFILE; + +#if HAVE_VFSCANF + return (vfscanf(&strbuf, format, ap)); +#else + return (_doscan(&strbuf, format, ap)); +#endif +#else + static int can_convert = -1; + + int assigned = 0; + int consumed = 0; + + T((T_CALLED("vsscanf(%s,%s,...)"), + _nc_visbuf2(1, str), + _nc_visbuf2(2, format))); + + /* + * This relies on having a working "%n" format conversion. Check if it + * works. Only very old C libraries do not support it. + * + * FIXME: move this check into the configure script. + */ + if (can_convert < 0) { + int check1; + int check2; + if (sscanf("123", "%d%n", &check1, &check2) > 0 + && check1 == 123 + && check2 == 3) { + can_convert = 1; + } else { + can_convert = 0; + } + } + + if (can_convert) { + size_t len_fmt = strlen(format) + 32; + char *my_fmt = malloc(len_fmt); + ChunkType chunk, ctest; + OtherType other, otest; + ScanState state; + unsigned n; + int eaten; + void *pointer; + + if (my_fmt != 0) { + /* + * Split the original format into chunks, adding a "%n" to the end + * of each (except of course if it used %n), and use that + * information to decide where to start scanning the next chunk. + * + * FIXME: does %n count bytes or characters? If the latter, this + * will require further work for multibyte strings. + */ + while (*format != '\0') { + /* find a chunk */ + state = sUnknown; + chunk = cUnknown; + other = oUnknown; + pointer = 0; + for (n = 0; format[n] != 0 && state != sFinal; ++n) { + my_fmt[n] = format[n]; + switch (state) { + case sUnknown: + if (format[n] == '%') + state = sPercent; + break; + case sPercent: + if (format[n] == '%') { + state = sUnknown; + } else if (format[n] == L_SQUARE) { + state = sLeft; + } else { + state = sNormal; + --n; + } + break; + case sLeft: + state = sRange; + if (format[n] == '^') { + ++n; + my_fmt[n] = format[n]; + } + break; + case sRange: + if (format[n] == R_SQUARE) { + state = sFinal; + chunk = cRange; + } + break; + case sNormal: + if (format[n] == '*') { + state = sUnknown; + } else { + if ((ctest = final_ch(format[n], other)) != cUnknown) { + state = sFinal; + chunk = ctest; + } else if ((otest = other_ch(format[n])) != oUnknown) { + other = otest; + } else if (isalpha(UChar(format[n]))) { + state = sFinal; + chunk = cError; + } + } + break; + case sFinal: + break; + } + } + my_fmt[n] = '\0'; + format += n; + + if (chunk == cUnknown + || chunk == cError) { + if (assigned == 0) + assigned = EOF; + break; + } + + /* add %n, if the format was not that */ + if (chunk != cAssigned) { + strlcat(my_fmt, "%n", len_fmt); + } + + switch (chunk) { + case cAssigned: + strlcat(my_fmt, "%n", len_fmt); + pointer = &eaten; + break; + case cInt: + pointer = va_arg(ap, int *); + break; + case cShort: + pointer = va_arg(ap, short *); + break; + case cFloat: + pointer = va_arg(ap, float *); + break; + case cDouble: + pointer = va_arg(ap, double *); + break; + case cLong: + pointer = va_arg(ap, long *); + break; + case cPointer: + pointer = va_arg(ap, void *); + break; + case cChar: + case cRange: + case cString: + pointer = va_arg(ap, char *); + break; + case cError: + case cUnknown: + break; + } + /* do the conversion */ + T(("...converting chunk #%d type %d(%s,%s)", + assigned + 1, chunk, + _nc_visbuf2(1, str + consumed), + _nc_visbuf2(2, my_fmt))); + if (sscanf(str + consumed, my_fmt, pointer, &eaten) > 0) + consumed += eaten; + else + break; + ++assigned; + } + free(my_fmt); + } + } + returnCode(assigned); +#endif +} +#else +extern +NCURSES_EXPORT(void) +_nc_vsscanf(void); /* quiet's gcc warning */ +NCURSES_EXPORT(void) +_nc_vsscanf(void) +{ +} /* nonempty for strict ANSI compilers */ +#endif /* !HAVE_VSSCANF */ diff --git a/lib/libcurses/base/wresize.c b/lib/libcurses/base/wresize.c index d513f29b9d3..ef4a91e7150 100644 --- a/lib/libcurses/base/wresize.c +++ b/lib/libcurses/base/wresize.c @@ -1,7 +1,7 @@ -/* $OpenBSD: wresize.c,v 1.4 2001/01/22 18:01:49 millert Exp $ */ +/* $OpenBSD: wresize.c,v 1.5 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,40 +29,82 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey <dickey@clark.net> 1996,1997 * + * Author: Thomas E. Dickey 1996-2002 * ****************************************************************************/ #include <curses.priv.h> -MODULE_ID("$From: wresize.c,v 1.18 2000/12/10 02:43:28 tom Exp $") +MODULE_ID("$Id: wresize.c,v 1.5 2010/01/12 23:22:06 nicm Exp $") + +static int +cleanup_lines(struct ldat *data, int length) +{ + while (--length >= 0) + free(data[length].text); + free(data); + return ERR; +} + +/* + * If we have reallocated the ldat structs, we will have to repair pointers + * used in subwindows. + */ +static void +repair_subwindows(WINDOW *cmp) +{ + WINDOWLIST *wp; + struct ldat *pline = cmp->_line; + int row; + + _nc_lock_global(curses); + + for (each_window(wp)) { + WINDOW *tst = &(wp->win); + + if (tst->_parent == cmp) { + + if (tst->_pary > cmp->_maxy) + tst->_pary = cmp->_maxy; + if (tst->_parx > cmp->_maxx) + tst->_parx = cmp->_maxx; + + if (tst->_maxy + tst->_pary > cmp->_maxy) + tst->_maxy = cmp->_maxy - tst->_pary; + if (tst->_maxx + tst->_parx > cmp->_maxx) + tst->_maxx = cmp->_maxx - tst->_parx; + + for (row = 0; row <= tst->_maxy; ++row) { + tst->_line[row].text = &pline[tst->_pary + row].text[tst->_parx]; + } + repair_subwindows(tst); + } + } + _nc_unlock_global(curses); +} /* * Reallocate a curses WINDOW struct to either shrink or grow to the specified * new lines/columns. If it grows, the new character cells are filled with * blanks. The application is responsible for repainting the blank area. */ - -#define DOALLOC(p,t,n) typeRealloc(t, n, p) -#define ld_ALLOC(p,n) DOALLOC(p,struct ldat,n) -#define c_ALLOC(p,n) DOALLOC(p,chtype,n) - NCURSES_EXPORT(int) wresize(WINDOW *win, int ToLines, int ToCols) { - register int row; - int size_x, size_y; + int col, row, size_x, size_y; struct ldat *pline; - chtype blank; + struct ldat *new_lines = 0; #ifdef TRACE T((T_CALLED("wresize(%p,%d,%d)"), win, ToLines, ToCols)); if (win) { - TR(TRACE_UPDATE, ("...beg (%d, %d), max(%d,%d), reg(%d,%d)", - win->_begy, win->_begx, - win->_maxy, win->_maxx, - win->_regtop, win->_regbottom)); - if (_nc_tracing & TRACE_UPDATE) + TR(TRACE_UPDATE, ("...beg (%ld, %ld), max(%ld,%ld), reg(%ld,%ld)", + (long) win->_begy, (long) win->_begx, + (long) win->_maxy, (long) win->_maxx, + (long) win->_regtop, (long) win->_regbottom)); + if (USE_TRACEF(TRACE_UPDATE)) { _tracedump("...before", win); + _nc_unlock_global(tracef); + } } #endif @@ -92,65 +134,82 @@ wresize(WINDOW *win, int ToLines, int ToCols) } /* - * If the number of lines has changed, adjust the size of the overall - * vector: + * Allocate new memory as needed. Do the allocations without modifying + * the original window, in case an allocation fails. Always allocate + * (at least temporarily) the array pointing to the individual lines. */ - if (ToLines != size_y) { + new_lines = typeCalloc(struct ldat, (unsigned) (ToLines + 1)); + if (new_lines == 0) + returnCode(ERR); + + /* + * For each line in the target, allocate or adjust pointers for the + * corresponding text, depending on whether this is a window or a + * subwindow. + */ + for (row = 0; row <= ToLines; ++row) { + int begin = (row > size_y) ? 0 : (size_x + 1); + int end = ToCols; + NCURSES_CH_T *s; + if (!(win->_flags & _SUBWIN)) { - for (row = ToLines + 1; row <= size_y; row++) - free((char *) (win->_line[row].text)); + if (row <= size_y) { + if (ToCols != size_x) { + if ((s = typeMalloc(NCURSES_CH_T, ToCols + 1)) == 0) + returnCode(cleanup_lines(new_lines, row)); + for (col = 0; col <= ToCols; ++col) { + s[col] = (col <= size_x + ? win->_line[row].text[col] + : win->_nc_bkgd); + } + } else { + s = win->_line[row].text; + } + } else { + if ((s = typeMalloc(NCURSES_CH_T, ToCols + 1)) == 0) + returnCode(cleanup_lines(new_lines, row)); + for (col = 0; col <= ToCols; ++col) + s[col] = win->_nc_bkgd; + } + } else { + s = &pline[win->_pary + row].text[win->_parx]; } - win->_line = ld_ALLOC(win->_line, ToLines + 1); - if (win->_line == 0) - returnCode(ERR); - - for (row = size_y + 1; row <= ToLines; row++) { - win->_line[row].text = 0; - win->_line[row].firstchar = 0; - win->_line[row].lastchar = ToCols; - if ((win->_flags & _SUBWIN)) { - win->_line[row].text = - &pline[win->_pary + row].text[win->_parx]; + if_USE_SCROLL_HINTS(new_lines[row].oldindex = row); + if (row <= size_y) { + new_lines[row].firstchar = win->_line[row].firstchar; + new_lines[row].lastchar = win->_line[row].lastchar; + } + if ((ToCols != size_x) || (row > size_y)) { + if (end >= begin) { /* growing */ + if (new_lines[row].firstchar < begin) + new_lines[row].firstchar = begin; + } else { /* shrinking */ + new_lines[row].firstchar = 0; } + new_lines[row].lastchar = ToCols; } + new_lines[row].text = s; } /* - * Adjust the width of the columns: + * Dispose of unwanted memory. */ - blank = _nc_background(win); - for (row = 0; row <= ToLines; row++) { - chtype *s = win->_line[row].text; - int begin = (s == 0) ? 0 : size_x + 1; - int end = ToCols; - - if_USE_SCROLL_HINTS(win->_line[row].oldindex = row); - - if (ToCols != size_x || s == 0) { - if (!(win->_flags & _SUBWIN)) { - win->_line[row].text = s = c_ALLOC(s, ToCols + 1); - if (win->_line[row].text == 0) - returnCode(ERR); - } else if (s == 0) { - win->_line[row].text = s = - &pline[win->_pary + row].text[win->_parx]; + if (!(win->_flags & _SUBWIN)) { + if (ToCols == size_x) { + for (row = ToLines + 1; row <= size_y; row++) { + free(win->_line[row].text); } - - if (end >= begin) { /* growing */ - if (win->_line[row].firstchar < begin) - win->_line[row].firstchar = begin; - win->_line[row].lastchar = ToCols; - do { - s[end] = blank; - } while (--end >= begin); - } else { /* shrinking */ - win->_line[row].firstchar = 0; - win->_line[row].lastchar = ToCols; + } else { + for (row = 0; row <= size_y; row++) { + free(win->_line[row].text); } } } + free(win->_line); + win->_line = new_lines; + /* * Finally, adjust the parameters showing screen size and cursor * position: @@ -169,13 +228,21 @@ wresize(WINDOW *win, int ToLines, int ToCols) if (win->_cury > win->_maxy) win->_cury = win->_maxy; + /* + * Check for subwindows of this one, and readjust pointers to our text, + * if needed. + */ + repair_subwindows(win); + #ifdef TRACE - TR(TRACE_UPDATE, ("...beg (%d, %d), max(%d,%d), reg(%d,%d)", - win->_begy, win->_begx, - win->_maxy, win->_maxx, - win->_regtop, win->_regbottom)); - if (_nc_tracing & TRACE_UPDATE) + TR(TRACE_UPDATE, ("...beg (%ld, %ld), max(%ld,%ld), reg(%ld,%ld)", + (long) win->_begy, (long) win->_begx, + (long) win->_maxy, (long) win->_maxx, + (long) win->_regtop, (long) win->_regbottom)); + if (USE_TRACEF(TRACE_UPDATE)) { _tracedump("...after:", win); + _nc_unlock_global(tracef); + } #endif returnCode(OK); } diff --git a/lib/libcurses/capdefaults.c b/lib/libcurses/capdefaults.c index 4f1ec7e5e42..95c21c7d4a4 100644 --- a/lib/libcurses/capdefaults.c +++ b/lib/libcurses/capdefaults.c @@ -1,5 +1,7 @@ +/* $OpenBSD: capdefaults.c,v 1.3 2010/01/12 23:21:58 nicm Exp $ */ + /**************************************************************************** - * Copyright (c) 1998-2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2000,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,10 +31,10 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ -/* $OpenBSD: capdefaults.c,v 1.2 2000/01/02 22:06:50 millert Exp $ */ -/* $From: capdefaults.c,v 1.12 2000/01/02 02:34:56 tom Exp $ */ +/* $Id: capdefaults.c,v 1.3 2010/01/12 23:21:58 nicm Exp $ */ /* * Compute obsolete capabilities. The reason this is an include file is @@ -45,9 +47,10 @@ */ { char *sp; - int capval; + short capval; -#define EXTRACT_DELAY(str) (sp = strchr(str, '*'), sp ? atoi(sp+1) : 0) +#define EXTRACT_DELAY(str) \ + (short) (sp = strchr(str, '*'), sp ? atoi(sp+1) : 0) /* current (4.4BSD) capabilities marked obsolete */ if (VALID_STRING(carriage_return) @@ -74,8 +77,8 @@ magic_cookie_glitch_ul = magic_cookie_glitch; /* totally obsolete capabilities */ - linefeed_is_newline = VALID_STRING(newline) - && (strcmp("\n", newline) == 0); + linefeed_is_newline = (char) (VALID_STRING(newline) + && (strcmp("\n", newline) == 0)); if (VALID_STRING(cursor_left) && (capval = EXTRACT_DELAY(cursor_left))) backspace_delay = capval; diff --git a/lib/libcurses/curs_addch.3tbl b/lib/libcurses/curs_addch.3tbl index 4405acbd180..dfb44b95320 100644 --- a/lib/libcurses/curs_addch.3tbl +++ b/lib/libcurses/curs_addch.3tbl @@ -1,8 +1,8 @@ -'\" t -.\" $OpenBSD: curs_addch.3tbl,v 1.10 2003/05/12 11:06:49 jmc Exp $ -.\" +'\" t +.\" $OpenBSD: curs_addch.3tbl,v 1.11 2010/01/12 23:21:58 nicm Exp $ +.\" .\"*************************************************************************** -.\" Copyright (c) 1998,2000 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -29,7 +29,7 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_addch.3x,v 1.17 2000/07/01 19:53:01 tom Exp $ +.\" $Id: curs_addch.3tbl,v 1.11 2010/01/12 23:21:58 nicm Exp $ .TH curs_addch 3 "" .SH NAME \fBaddch\fR, \fBwaddch\fR, \fBmvaddch\fR, \fBmvwaddch\fR, @@ -37,18 +37,18 @@ \fBwechochar\fR - add a character (with attributes) to a \fBcurses\fR window, then advance the cursor .SH SYNOPSIS \fB#include <curses.h>\fR - -\fBint addch(chtype ch);\fR +.PP +\fBint addch(const chtype ch);\fR .br -\fBint waddch(WINDOW *win, chtype ch);\fR +\fBint waddch(WINDOW *win, const chtype ch);\fR .br -\fBint mvaddch(int y, int x, chtype ch);\fR +\fBint mvaddch(int y, int x, const chtype ch);\fR .br -\fBint mvwaddch(WINDOW *win, int y, int x, chtype ch);\fR +\fBint mvwaddch(WINDOW *win, int y, int x, const chtype ch);\fR .br -\fBint echochar(chtype ch);\fR +\fBint echochar(const chtype ch);\fR .br -\fBint wechochar(WINDOW *win, chtype ch);\fR +\fBint wechochar(WINDOW *win, const chtype ch);\fR .br .SH DESCRIPTION The \fBaddch\fR, \fBwaddch\fR, \fBmvaddch\fR and \fBmvwaddch\fR routines put @@ -57,25 +57,29 @@ which is then advanced. They are analogous to \fBputchar\fR in \fBstdio\fR(3). If the advance is at the right margin, the cursor automatically wraps to the beginning of the next line. At the bottom of the current scrolling region, if \fBscrollok\fR is enabled, the scrolling region is scrolled up one line. - -If \fIch\fR is a tab, newline, or backspace, the cursor is moved appropriately -within the window. Backspace moves the cursor one character left; at the left -edge of a window it does nothing. Newline does a \fBclrtoeol\fR, then moves -the cursor to the window left margin on the next line, scrolling the window if -on the last line. Tabs are considered to be at every eighth column. - +.PP +If \fIch\fR is a tab, newline, or backspace, +the cursor is moved appropriately within the window. +Backspace moves the cursor one character left; at the left +edge of a window it does nothing. +Newline does a \fBclrtoeol\fR, +then moves the cursor to the window left margin on the next line, +scrolling the window if on the last line. +Tabs are considered to be at every eighth column. +The tab interval may be altered by setting the \fBTABSIZE\fR variable. +.PP If \fIch\fR is any control character other than tab, newline, or backspace, it is drawn in \fB^\fR\fIX\fR notation. Calling \fBwinch\fR after adding a control character does not return the character itself, but instead returns the ^-representation of the control character. - +.PP Video attributes can be combined with a character argument passed to \fBaddch\fR or related functions by logical-ORing them into the character. (Thus, text, including attributes, can be copied from one place to another using \fBinch\fR and \fBaddch\fR.) See the \fBcurs_attr\fR(3) page for values of predefined video attribute constants that can be usefully OR'ed into characters. - +.PP The \fBechochar\fR and \fBwechochar\fR routines are equivalent to a call to \fBaddch\fR followed by a call to \fBrefresh\fR, or a call to \fBwaddch\fR followed by a call to \fBwrefresh\fR. The knowledge that only a single @@ -85,10 +89,10 @@ their equivalents. .SS Line Graphics The following variables may be used to add line drawing characters to the screen with routines of the \fBaddch\fR family. The default character listed -below is used if the \fBacsc\fR capability doesn't define a terminal-specific -replacement for it (but see the EXTENSIONS section below). The names are -taken from VT100 nomenclature. - +below is used if the \fBacsc\fR capability does not define a terminal-specific +replacement for it. +The names are taken from VT100 nomenclature. +.PP .TS l l l _ _ _ @@ -127,7 +131,6 @@ ACS_ULCORNER + upper left-hand corner ACS_URCORNER + upper right-hand corner ACS_VLINE | vertical line .TE - .SH RETURN VALUE All routines return the integer \fBERR\fR upon failure and \fBOK\fR on success (the SVr4 manuals specify only "an integer value other than \fBERR\fR") upon @@ -139,7 +142,7 @@ Note that \fBaddch\fR, \fBmvaddch\fR, \fBmvwaddch\fR, and .SH PORTABILITY All these functions are described in the XSI Curses standard, Issue 4. The defaults specified for forms-drawing characters apply in the POSIX locale. - +.LP Some ACS symbols (ACS_S3, ACS_S7, @@ -153,10 +156,25 @@ any publicly released System V. However, many publicly available terminfos include \fBacsc\fR strings in which their key characters (pryz{|}) are embedded, and a second-hand list of their character descriptions has come to light. The ACS-prefixed names for them were invented for \fBncurses\fR(3). +.LP +The \fBTABSIZE\fR variable is implemented in some versions of curses, +but is not part of X/Open curses. +.LP +If \fIch\fR is a carriage return, +the cursor is moved to the beginning of the current row of the window. +This is true of other implementations, but is not documented. .SH SEE ALSO -\fBcurses\fR(3), \fBcurs_attr\fR(3), \fBcurs_clear\fR(3), -\fBcurs_inch\fR(3), \fBcurs_outopts\fR(3), \fBcurs_refresh\fR(3), +\fBcurses\fR(3), +\fBcurs_attr\fR(3), +\fBcurs_clear\fR(3), +\fBcurs_inch\fR(3), +\fBcurs_outopts\fR(3), +\fBcurs_refresh\fR(3), \fBputc\fR(3). +.PP +Comparable functions in the wide-character (ncursesw) library are +described in +\fBcurs_add_wch\fR(3). .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_addchstr.3 b/lib/libcurses/curs_addchstr.3 index f58a9021406..d291af1c54d 100644 --- a/lib/libcurses/curs_addchstr.3 +++ b/lib/libcurses/curs_addchstr.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_addchstr.3,v 1.8 2004/12/10 03:54:19 jaredy Exp $ +.\" $OpenBSD: curs_addchstr.3,v 1.9 2010/01/12 23:21:58 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998,2000 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,15 +28,24 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_addchstr.3x,v 1.7 2000/07/01 19:53:33 tom Exp $ +.\" $Id: curs_addchstr.3,v 1.9 2010/01/12 23:21:58 nicm Exp $ .TH curs_addchstr 3 "" +.na +.hy 0 .SH NAME -\fBaddchstr\fR, \fBaddchnstr\fR, \fBwaddchstr\fR, -\fBwaddchnstr\fR, \fBmvaddchstr\fR, \fBmvaddchnstr\fR, \fBmvwaddchstr\fR, +\fBaddchstr\fR, +\fBaddchnstr\fR, +\fBwaddchstr\fR, +\fBwaddchnstr\fR, +\fBmvaddchstr\fR, +\fBmvaddchnstr\fR, +\fBmvwaddchstr\fR, \fBmvwaddchnstr\fR - add a string of characters (and attributes) to a \fBcurses\fR window +.ad +.hy .SH SYNOPSIS \fB#include <curses.h>\fR - +.PP \fBint addchstr(const chtype *chstr);\fR .br \fBint addchnstr(const chtype *chstr, int n);\fR @@ -58,25 +67,32 @@ the current cursor position. The four routines with \fIn\fR as the last argument copy at most \fIn\fR elements, but no more than will fit on the line. If \fBn\fR=\fB-1\fR then the whole string is copied, to the maximum number of characters that will fit on the line. - +.PP The window cursor is \fInot\fR advanced, and these routines work faster than -\fBwaddnstr\fR. On the other hand, they don't perform any kind of checking -(such as for the newline, backspace, or carriage return characters), they don't -advance the current cursor position, they don't expand other control characters +\fBwaddnstr\fR. On the other hand, they do not perform any kind of checking +(such as for the newline, backspace, or carriage return characters), they do not +advance the current cursor position, they do not expand other control characters to ^-escapes, and they truncate the string if it crosses the right margin, rather than wrapping it around to the new line. - .SH RETURN VALUES All routines return the integer \fBERR\fR upon failure and \fBOK\fR on success (the SVr4 manuals specify only "an integer value other than \fBERR\fR") upon successful completion, unless otherwise noted in the preceding routine descriptions. +.PP +X/Open does not define any error conditions. +This implementation returns an error +if the window pointer is null. .SH NOTES Note that all routines except \fBwaddchnstr\fR may be macros. .SH PORTABILITY -All these entry points are described in the XSI Curses standard, Issue 4. +These entry points are described in the XSI Curses standard, Issue 4. .SH SEE ALSO \fBcurses\fR(3). +.PP +Comparable functions in the wide-character (ncursesw) library are +described in +\fBcurs_add_wchstr\fR(3). .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_addstr.3 b/lib/libcurses/curs_addstr.3 index 33541a4de2d..d1815f117c0 100644 --- a/lib/libcurses/curs_addstr.3 +++ b/lib/libcurses/curs_addstr.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_addstr.3,v 1.6 2000/07/10 03:06:04 millert Exp $ +.\" $OpenBSD: curs_addstr.3,v 1.7 2010/01/12 23:21:58 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998,2000 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2003,2005 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,8 +28,10 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_addstr.3x,v 1.9 2000/07/01 19:54:05 tom Exp $ +.\" $Id: curs_addstr.3,v 1.7 2010/01/12 23:21:58 nicm Exp $ .TH curs_addstr 3 "" +.na +.hy 0 .SH NAME \fBaddstr\fR, \fBaddnstr\fR, @@ -39,34 +41,47 @@ \fBmvaddnstr\fR, \fBmvwaddstr\fR, \fBmvwaddnstr\fR - add a string of characters to a \fBcurses\fR window and advance cursor +.ad +.hy .SH SYNOPSIS +.nf \fB#include <curses.h>\fR - -\fBint addstr(const char *str);\fR +.PP +\fBint addstr(const char *\fR\fIstr\fR\fB);\fR .br -\fBint addnstr(const char *str, int n);\fR +\fBint addnstr(const char *\fR\fIstr\fR\fB, int \fR\fIn\fR\fB);\fR .br -\fBint waddstr(WINDOW *win, const char *str);\fR +\fBint waddstr(WINDOW *\fR\fIwin\fR\fB, const char *\fR\fIstr\fR\fB);\fR .br -\fBint waddnstr(WINDOW *win, const char *str, int n);\fR +\fBint waddnstr(WINDOW *\fR\fIwin\fR\fB, const char *\fR\fIstr\fR\fB, int \fR\fIn\fR\fB);\fR .br -\fBint mvaddstr(int y, int x, const char *str);\fR +\fBint mvaddstr(int \fR\fIy\fR\fB, int \fR\fIx\fR\fB, const char *\fR\fIstr\fR\fB);\fR .br -\fBint mvaddnstr(int y, int x, const char *str, int n);\fR +\fBint mvaddnstr(int \fR\fIy\fR\fB, int \fR\fIx\fR\fB, const char *\fR\fIstr\fR\fB, int \fR\fIn\fR\fB);\fR .br -\fBint mvwaddstr(WINDOW *win, int y, int x, const char *str);\fR +\fBint mvwaddstr(WINDOW *\fR\fIwin\fR\fB, int \fR\fIy\fR\fB, int \fR\fIx\fR\fB, const char *\fR\fIstr\fR\fB);\fR .br -\fBint mvwaddnstr(WINDOW *win, int y, int x, const char *str, int n);\fR +\fBint mvwaddnstr(WINDOW *\fR\fIwin\fR\fB, int \fR\fIy\fR\fB, int \fR\fIx\fR\fB, const char *\fR\fIstr, int \fR\fIn\fR\fB);\fR +.fi .SH DESCRIPTION These routines write the characters of the (null-terminated) character string -\fIstr\fR on the given window. It is similar to calling \fBwaddch\fR once for -each character in the string. The four routines with \fIn\fR as the last -argument write at most \fIn\fR characters. If \fIn\fR is -1, then the -entire string will be added. +\fIstr\fR on the given window. +It is similar to calling \fBwaddch\fR once for each character in the string. +The four routines with \fIn\fR as the last argument +write at most \fIn\fR characters. +If \fIn\fR is -1, then the entire string will be added, +up to the maximum number of characters that will fit on the line, +or until a terminating null is reached. .SH RETURN VALUE All routines return the integer \fBERR\fR upon failure and \fBOK\fR on success (the SVr4 manuals specify only "an integer value other than \fBERR\fR") upon successful completion. +.PP +X/Open does not define any error conditions. +This implementation returns an error +if the window pointer is null or +if the string pointer is null or +if the corresponding calls to \fBwaddch\fP return an error. .SH NOTES Note that all of these routines except \fBwaddstr\fR and \fBwaddnstr\fR may be macros. diff --git a/lib/libcurses/curs_attr.3tbl b/lib/libcurses/curs_attr.3tbl index 0882fa30732..faa8b3e6f44 100644 --- a/lib/libcurses/curs_attr.3tbl +++ b/lib/libcurses/curs_attr.3tbl @@ -1,8 +1,8 @@ -'\" t -.\" $OpenBSD: curs_attr.3tbl,v 1.9 2000/07/10 03:06:04 millert Exp $ +'\" t +.\" $OpenBSD: curs_attr.3tbl,v 1.10 2010/01/12 23:21:58 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998,2000 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -29,19 +29,38 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_attr.3x,v 1.22 2000/07/08 11:59:58 tom Exp $ +.\" $Id: curs_attr.3tbl,v 1.10 2010/01/12 23:21:58 nicm Exp $ .TH curs_attr 3 "" +.na +.hy 0 .SH NAME -\fBattroff\fR, \fBwattroff\fR, \fBattron\fR, \fBwattron\fR, -\fBattrset\fR, \fBwattrset\fR, \fBcolor_set\fR, \fBwcolor_set\fR, -\fBstandend\fR, \fBwstandend\fR, \fBstandout\fR, \fBwstandout\fR, -\fBattr_get\fR, \fBwattr_get\fR, -\fBattr_off\fR, \fBwattr_off\fR, -\fBattr_on\fR, \fBwattr_on\fR, -\fBattr_set\fR, \fBwattr_set\fR, -\fBchgat\fR, \fBwchgat\fR, -\fBmvchgat\fR, \fBmvwchgat\fR, +\fBattroff\fR, +\fBwattroff\fR, +\fBattron\fR, +\fBwattron\fR, +\fBattrset\fR, +\fBwattrset\fR, +\fBcolor_set\fR, +\fBwcolor_set\fR, +\fBstandend\fR, +\fBwstandend\fR, +\fBstandout\fR, +\fBwstandout\fR, +\fBattr_get\fR, +\fBwattr_get\fR, +\fBattr_off\fR, +\fBwattr_off\fR, +\fBattr_on\fR, +\fBwattr_on\fR, +\fBattr_set\fR, +\fBwattr_set\fR, +\fBchgat\fR, +\fBwchgat\fR, +\fBmvchgat\fR, +\fBmvwchgat\fR, \fBPAIR_NUMBER\fR - \fBcurses\fR character and window attribute control routines +.ad +.hy .SH SYNOPSIS \fB#include <curses.h>\fR .br @@ -107,7 +126,7 @@ a property of the character, and move with the character through any scrolling and insert/delete line/character operations. To the extent possible, they are displayed as appropriate modifications to the graphic rendition of characters put on the screen. - +.PP The routine \fBattrset\fR sets the current attributes of the given window to \fIattrs\fR. The routine \fBattroff\fR turns off the named attributes without turning any other attributes on or off. The routine \fBattron\fR turns on the @@ -115,19 +134,24 @@ named attributes without affecting any others. The routine \fBstandout\fR is the same as \fBattron(A_STANDOUT)\fR. The routine \fBstandend\fR is the same as \fBattrset(A_NORMAL)\fR or \fBattrset(0)\fR, that is, it turns off all attributes. - +.PP +The \fBattrset\fR and related routines do not affect the attributes used +when erasing portions of the window. +See \fBcurs_bkgd\fR(3) for functions which modify the attributes used for +erasing and clearing. +.PP The routine \fBcolor_set\fR sets the current color of the given window to the foreground/background combination described by the color_pair_number. The parameter opts is reserved for future use, applications must supply a null pointer. - +.PP The routine \fBwattr_get\fR returns the current attribute and color pair for the given window; \fBattr_get\fR returns the current attribute and color pair for \fBstdscr\fR. The remaining \fBattr_\fR* functions operate exactly like the corresponding \fBattr\fR* functions, except that they take arguments of type \fBattr_t\fR rather than \fBint\fR. - +.PP The routine \fBchgat\fR changes the attributes of a given number of characters starting at the current cursor location of \fBstdscr\fR. It does not update the cursor and does not perform wrapping. A character count of -1 or greater @@ -139,9 +163,9 @@ of \fIinit_pair\fR, see \fBcurs_color\fR(3)). The \fBopts\fR argument is not presently used, but is reserved for the future (leave it \fBNULL\fR). .SS Attributes The following video attributes, defined in \fB<curses.h>\fR, can be passed to -the routines \fBattron\fR, \fBattroff\fR, and \fBattrset\fR, or OR'ed with the +the routines \fBattron\fR, \fBattroff\fR, and \fBattrset\fR, or OR'd with the characters passed to \fBaddch\fR. - +.PP .TS center ; l l . @@ -158,39 +182,49 @@ l l . \fBA_CHARTEXT\fR Bit-mask to extract a character \fBCOLOR_PAIR(\fR\fIn\fR\fB)\fR Color-pair number \fIn\fR .TE - +.PP The following macro is the reverse of \fBCOLOR_PAIR(\fR\fIn\fR\fB)\fR: - -.DS C +.PP +.br \fBPAIR_NUMBER(\fR\fIattrs\fR) Returns the pair number associated with the \fBCOLOR_PAIR(\fR\fIn\fR\fB)\fR attribute. -.DE - +.br +.PP The return values of many of these routines are not meaningful (they are implemented as macro-expanded assignments and simply return their argument). The SVr4 manual page claims (falsely) that these routines always return \fB1\fR. - .SH NOTES Note that \fBattroff\fR, \fBwattroff\fR, \fBattron\fR, \fBwattron\fR, \fBattrset\fR, \fBwattrset\fR, \fBstandend\fR and \fBstandout\fR may be macros. +.PP +\fBCOLOR_PAIR\fP values can only be OR'd with attributes if the pair +number is less than 256. +The alternate functions such as \fBcolor_set\fP can pass a color pair +value directly. +However, ncurses ABI 4 and 5 simply OR this value within the alternate functions. +You must use ncurses ABI 6 to support more than 256 color pairs. .SH PORTABILITY -All these functions are supported in the XSI Curses standard, Issue 4. The +These functions are supported in the XSI Curses standard, Issue 4. The standard defined the dedicated type for highlights, \fBattr_t\fR, which is not defined in SVr4 curses. The functions taking \fBattr_t\fR arguments are not supported under SVr4. - +.PP The XSI Curses standard states that whether the traditional functions \fBattron\fR/\fBattroff\fR/\fBattrset\fR can manipulate attributes other than \fBA_BLINK\fR, \fBA_BOLD\fR, \fBA_DIM\fR, \fBA_REVERSE\fR, \fBA_STANDOUT\fR, or \fBA_UNDERLINE\fR is "unspecified". Under this implementation as well as SVr4 curses, these functions correctly manipulate all other highlights (specifically, \fBA_ALTCHARSET\fR, \fBA_PROTECT\fR, and \fBA_INVIS\fR). - +.PP XSI Curses added the new entry points, \fBattr_get\fR, \fBattr_on\fR, \fBattr_off\fR, \fBattr_set\fR, \fBwattr_on\fR, \fBwattr_off\fR, \fBwattr_get\fR, \fBwattr_set\fR. These are intended to work with a new series of highlight macros prefixed with \fBWA_\fR. - +.PP +Older versions of this library did not force an update of the screen +when changing the attributes. +Use \fBtouchwin\fR to force the screen to match the updated attributes. +.PP .TS center ; l l . @@ -203,17 +237,32 @@ l l . \fBWA_BOLD\fR Extra bright or bold \fBWA_ALTCHARSET\fR Alternate character set .TE - +.PP The XSI curses standard specifies that each pair of corresponding \fBA_\fR and \fBWA_\fR-using functions operates on the same current-highlight information. - +.PP The XSI standard extended conformance level adds new highlights \fBA_HORIZONTAL\fR, \fBA_LEFT\fR, \fBA_LOW\fR, \fBA_RIGHT\fR, \fBA_TOP\fR, \fBA_VERTICAL\fR (and corresponding \fBWA_\fR macros for each) which this -curses does not yet support. +implementation does not yet support. +.SH RETURN VALUE +All routines return the integer \fBOK\fR on success, or \fBERR\fP on failure. +.PP +X/Open does not define any error conditions. +.PP +This implementation returns an error +if the window pointer is null. +The \fBwcolor_set\fP function returns an error if the color pair parameter +is outside the range 0..COLOR_PAIRS-1. +This implementation also provides +\fBgetattrs\fR +for compatibility with older versions of curses. .SH SEE ALSO -\fBcurses\fR(3), \fBcurs_addch\fR(3), \fBcurs_addstr\fR(3), +\fBcurses\fR(3), +\fBcurs_addch\fR(3), +\fBcurs_addstr\fR(3), +\fBcurs_bkgd\fR(3), \fBcurs_printw\fR(3) .\"# .\"# The following sets edit modes for GNU EMACS diff --git a/lib/libcurses/curs_beep.3 b/lib/libcurses/curs_beep.3 index 720ef140c81..66849875d19 100644 --- a/lib/libcurses/curs_beep.3 +++ b/lib/libcurses/curs_beep.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_beep.3,v 1.6 2003/05/12 11:06:49 jmc Exp $ +.\" $OpenBSD: curs_beep.3,v 1.7 2010/01/12 23:21:58 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2003,2005 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,13 +28,13 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_beep.3x,v 1.7 1998/03/11 21:12:53 juergen Exp $ +.\" $Id: curs_beep.3,v 1.7 2010/01/12 23:21:58 nicm Exp $ .TH curs_beep 3 "" .SH NAME \fBbeep\fR, \fBflash\fR - \fBcurses\fR bell and screen flash routines .SH SYNOPSIS \fB#include <curses.h>\fR - +.PP \fBint beep(void);\fR .br \fBint flash(void);\fR @@ -53,8 +53,8 @@ These routines return \fBOK\fR if they succeed in beeping or flashing, SVr4's beep and flash routines always returned \fBOK\fR, so it was not possible to tell when the beep or flash failed. .SH PORTABILITY -These functions are defined in the XSI Curses standard, Issue 4. Like SVr4, it -specifies that they always return \fBOK\fR. +These functions are described in the XSI Curses standard, Issue 4. +Like SVr4, it specifies that they always return \fBOK\fR. .SH SEE ALSO \fBcurses\fR(3) .\"# diff --git a/lib/libcurses/curs_bkgd.3 b/lib/libcurses/curs_bkgd.3 index 024acb4da2c..6e1fc34fbea 100644 --- a/lib/libcurses/curs_bkgd.3 +++ b/lib/libcurses/curs_bkgd.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_bkgd.3,v 1.7 2000/07/10 03:06:05 millert Exp $ +.\" $OpenBSD: curs_bkgd.3,v 1.8 2010/01/12 23:21:58 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998,2000 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2002,2003 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,27 +28,25 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_bkgd.3x,v 1.14 2000/07/01 17:39:31 tom Exp $ +.\" $Id: curs_bkgd.3,v 1.8 2010/01/12 23:21:58 nicm Exp $ .TH curs_bkgd 3 "" .SH NAME \fBbkgdset\fR, \fBwbkgdset\fR, \fBbkgd\fR, \fBwbkgd\fR, \fBgetbkgd\fR - \fBcurses\fR window background manipulation routines -.. .SH SYNOPSIS \fB#include <curses.h>\fR - -\fBvoid bkgdset(const chtype ch);\fR +.PP +\fBvoid bkgdset(chtype ch);\fR .br -\fBvoid wbkgdset(WINDOW *win, const chtype ch);\fR +\fBvoid wbkgdset(WINDOW *win, chtype ch);\fR .br -\fBint bkgd(const chtype ch);\fR +\fBint bkgd(chtype ch);\fR .br -\fBint wbkgd(WINDOW *win, const chtype ch);\fR +\fBint wbkgd(WINDOW *win, chtype ch);\fR .br \fBchtype getbkgd(WINDOW *win);\fR .br -.. .SH DESCRIPTION The \fBbkgdset\fR and \fBwbkgdset\fR routines manipulate the background of the named window. @@ -60,42 +58,40 @@ the character and attribute parts of the background are combined with the blank characters. The background becomes a property of the character and moves with the character through any scrolling and insert/delete line/character operations. - -To the extent possible on a -particular terminal, the attribute part of the background is displayed +.PP +To the extent possible on a particular terminal, +the attribute part of the background is displayed as the graphic rendition of the character put on the screen. - +.PP The \fBbkgd\fR and \fBwbkgd\fR functions set the background property of the current or specified window and then apply this setting to every character position in that window: - +.PP .RS The rendition of every character on the screen is changed to the new background rendition. - +.PP Wherever the former background character appears, it is changed to the new background character. .RE - +.PP The \fBgetbkgd\fR function returns the given window's current background character/attribute pair. -.. .SH RETURN VALUE The routines \fBbkgd\fR and \fBwbkgd\fR return the integer \fBOK\fR. The SVr4.0 manual says "or a non-negative integer if \fBimmedok\fR is set", but this appears to be an error. -.. .SH NOTES Note that \fBbkgdset\fR and \fBbkgd\fR may be macros. -.. .SH PORTABILITY -These functions are described in the XSI Curses standard, Issue 4. The draft -does not include \fBconst\fR qualifiers on the arguments. The standard -specifies that \fBbkgd\fR and \fBwbkgd\fR return \fBERR\fR, on failure. but -gives no failure conditions. -.. +These functions are described in the XSI Curses standard, Issue 4. +It specifies that \fBbkgd\fR and \fBwbkgd\fR return \fBERR\fR on failure. +but gives no failure conditions. .SH SEE ALSO -\fBcurses\fR(3), \fBcurs_addch\fR(3), \fBcurs_outopts\fR(3) +\fBcurses\fR(3), +\fBcurs_addch\fR(3), +\fBcurs_attr\fR(3), +\fBcurs_outopts\fR(3) .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_bkgrnd.3 b/lib/libcurses/curs_bkgrnd.3 new file mode 100644 index 00000000000..89260b6ea5b --- /dev/null +++ b/lib/libcurses/curs_bkgrnd.3 @@ -0,0 +1,108 @@ +.\" $OpenBSD: curs_bkgrnd.3,v 1.1 2010/01/12 23:21:58 nicm Exp $ +.\" +.\"*************************************************************************** +.\" Copyright (c) 2002-2004,2006 Free Software Foundation, Inc. * +.\" * +.\" Permission is hereby granted, free of charge, to any person obtaining a * +.\" copy of this software and associated documentation files (the * +.\" "Software"), to deal in the Software without restriction, including * +.\" without limitation the rights to use, copy, modify, merge, publish, * +.\" distribute, distribute with modifications, sublicense, and/or sell * +.\" copies of the Software, and to permit persons to whom the Software is * +.\" furnished to do so, subject to the following conditions: * +.\" * +.\" The above copyright notice and this permission notice shall be included * +.\" in all copies or substantial portions of the Software. * +.\" * +.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * +.\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * +.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * +.\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * +.\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * +.\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * +.\" THE USE OR OTHER DEALINGS IN THE SOFTWARE. * +.\" * +.\" Except as contained in this notice, the name(s) of the above copyright * +.\" holders shall not be used in advertising or otherwise to promote the * +.\" sale, use or other dealings in this Software without prior written * +.\" authorization. * +.\"*************************************************************************** +.\" +.\" $Id: curs_bkgrnd.3,v 1.1 2010/01/12 23:21:58 nicm Exp $ +.TH curs_bkgrnd 3 "" +.SH NAME +\fBbkgrnd\fR, +\fBwbkgrnd\fR, +\fBbkgrndset\fR, +\fBwbkgrndset\fR, +\fBgetbkgrnd\fR, +\fBwgetbkgrnd\fR \- \fBcurses\fR window complex background manipulation routines +.SH SYNOPSIS +.PP +.B #include <curses.h> +.sp +\fBint bkgrnd(\fR\fB const cchar_t *\fR\fIwch\fR\fB);\fR +.br +\fBint wbkgrnd(\fR\fB WINDOW *\fR\fIwin\fR\fB, const cchar_t *\fR\fIwch\fR\fB);\fR +.br +\fBvoid bkgrndset(const cchar_t *\fR\fIwch\fR \fB);\fR +.br +\fBvoid wbkgrndset(WINDOW *\fR\fIwin\fR\fB, const cchar_t *\fR\fIwch\fR\fB);\fR +.br +\fBint getbkgrnd(cchar_t *\fR\fIwch\fR\fB);\fR +.br +\fBint wgetbkgrnd(WINDOW *\fR\fIwin\fR\fB, cchar_t *\fR\fIwch\fR\fB);\fR +.br +.SH DESCRIPTION +The \fBbkgrndset\fR and \fBwbkgrndset\fR routines manipulate the +background of the named window. +The window background is a \fBcchar_t\fR consisting of +any combination of attributes (i.e., rendition) and a complex character. +The attribute part of the background is combined (OR'ed) with all non-blank +characters that are written into the window with \fBwaddch\fR. Both +the character and attribute parts of the background are combined with +the blank characters. +The background becomes a property of the +character and moves with the character through any scrolling and +insert/delete line/character operations. +.PP +To the extent possible on a +particular terminal, the attribute part of the background is displayed +as the graphic rendition of the character put on the screen. +.PP +The \fBbkgrnd\fR and \fBwbkgrnd\fR functions +set the background property of the current or specified window +and then apply this setting to every character position in that window: +.RS +.PP +The rendition of every character on the screen is changed to +the new background rendition. +.PP +Wherever the former background character +appears, it is changed to the new background character. +.RE +.PP +The \fBgetbkgrnd\fR function returns the given window's current background +character/attribute pair via the \fBwch\fR pointer. +. +.SH NOTES +Note that +\fBbkgrnd\fR, +\fBbkgrndset\fR, and +\fBgetbkgrnd\fR +may be macros. +.SH RETURN VALUES +The \fBbkgrndset\fR and \fBwbkgrndset\fR routines do not return a value. +.PP +Upon successful completion, the other functions return \fBOK\fR. +Otherwise, they return \fBERR\fR. +A null window pointer is treated as an error. +.SH SEE ALSO +\fBcurses\fR(3), +\fBcurs_bkgd\fR(3) +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_border.3 b/lib/libcurses/curs_border.3 index 6bc6aecaed5..1ea0dc53044 100644 --- a/lib/libcurses/curs_border.3 +++ b/lib/libcurses/curs_border.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_border.3,v 1.10 2000/07/10 03:06:05 millert Exp $ +.\" $OpenBSD: curs_border.3,v 1.11 2010/01/12 23:21:58 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998,2000 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,14 +28,24 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_border.3x,v 1.14 2000/07/01 19:54:58 tom Exp $ +.\" $Id: curs_border.3,v 1.11 2010/01/12 23:21:58 nicm Exp $ .TH curs_border 3 "" +.na +.hy 0 .SH NAME -\fBborder\fR, \fBwborder\fR, \fBbox\fR, -\fBhline\fR, \fBwhline\fR, -\fBvline\fR, \fBwvline\fR, -\fBmvhline\fR, \fBmvwhline\fR, -\fBmvvline\fR, \fBmvwvline\fR - create \fBcurses\fR borders, horizontal and vertical lines +\fBborder\fR, +\fBwborder\fR, +\fBbox\fR, +\fBhline\fR, +\fBwhline\fR, +\fBvline\fR, +\fBwvline\fR, +\fBmvhline\fR, +\fBmvwhline\fR, +\fBmvvline\fR, +\fBmvwvline\fR - create \fBcurses\fR borders, horizontal and vertical lines +.ad +.hy .SH SYNOPSIS \fB#include <curses.h>\fR .br @@ -56,34 +66,67 @@ .br \fBint wvline(WINDOW *win, chtype ch, int n);\fR .br -\fBmvhline(int y, int x, chtype ch, int n);\fR +\fBint mvhline(int y, int x, chtype ch, int n);\fR .br -\fBmvwhline(WINDOW *, int y, int x, chtype ch, int n);\fR +\fBint mvwhline(WINDOW *, int y, int x, chtype ch, int n);\fR .br \fBint mvvline(int y, int x, chtype ch, int n);\fR .br \fBint mvwvline(WINDOW *, int y, int x, chtype ch, int n);\fR .br .SH DESCRIPTION -The \fBborder\fR, \fBwborder\fR and \fBbox\fR routines draw a box around the -edges of a window. The argument \fIls\fR is a character and attributes used -for the left side of the border, \fIrs\fR - right side, \fIts\fR - top side, -\fIbs\fR - bottom side, \fItl\fR - top left-hand corner, \fItr\fR - top -right-hand corner, \fIbl\fR - bottom left-hand corner, and \fIbr\fR - bottom -right-hand corner. If any of these arguments is zero, then the following -default values (defined in \fBcurses.h\fR) are used instead: \fBACS_VLINE\fR, -\fBACS_VLINE\fR, \fBACS_HLINE\fR, \fBACS_HLINE\fR, \fB\fBACS_ULCORNER\fR, -\fBACS_URCORNER\fR, \fBACS_LLCORNER\fR, \fBACS_LRCORNER\fR. - +The \fBborder\fR, \fBwborder\fR and \fBbox\fR routines +draw a box around the edges of a window. +Other than the window, each argument is a character with attributes: +.sp +.RS +\fIls\fR - left side, +.br +\fIrs\fR - right side, +.br +\fIts\fR - top side, +.br +\fIbs\fR - bottom side, +.br +\fItl\fR - top left-hand corner, +.br +\fItr\fR - top right-hand corner, +.br +\fIbl\fR - bottom left-hand corner, and +.br +\fIbr\fR - bottom right-hand corner. +.RE +.PP +If any of these arguments is zero, then the corresponding +default values (defined in \fBcurses.h\fR) are used instead: +.sp +.RS +\fBACS_VLINE\fR, +.br +\fBACS_VLINE\fR, +.br +\fBACS_HLINE\fR, +.br +\fBACS_HLINE\fR, +.br +\fBACS_ULCORNER\fR, +.br +\fBACS_URCORNER\fR, +.br +\fBACS_LLCORNER\fR, +.br +\fBACS_LRCORNER\fR. +.RE +.PP \fBbox(\fR\fIwin\fR\fB, \fR\fIverch\fR\fB, \fR\fIhorch\fR\fB)\fR is a shorthand for the following call: \fBwborder(\fR\fIwin\fR\fB,\fR \fIverch\fR\fB,\fR \fIverch\fR\fB,\fR \fIhorch\fR\fB,\fR \fIhorch\fR\fB, 0, 0, 0, 0)\fR. - +.PP The \fBhline\fR and \fBwhline\fR functions draw a horizontal (left to right) line using \fIch\fR starting at the current cursor position in the window. The current cursor position is not changed. The line is at most \fIn\fR characters long, or as many as fit into the window. - +.PP The \fBvline\fR and \fBwvline\fR functions draw a vertical (top to bottom) line using \fIch\fR starting at the current cursor position in the window. The current cursor position is not changed. The line is at most \fIn\fR characters @@ -91,17 +134,19 @@ long, or as many as fit into the window. .SH RETURN VALUE All routines return the integer \fBOK\fR. The SVr4.0 manual says "or a non-negative integer if \fBimmedok\fR is set", but this appears to be an error. +.PP +X/Open does not define any error conditions. +This implementation returns an error +if the window pointer is null. .SH NOTES The borders generated by these functions are \fIinside\fR borders (this is also true of SVr4 curses, though the fact is not documented). - +.PP Note that \fBborder\fR and \fBbox\fR may be macros. .SH PORTABILITY -These functions are described in the XSI Curses standard, Issue 4. Additional -functions \fBmvhline\fR, \fBmvvline\fR, \fBmvwhline\fR, and \fBmvwvline\fR are -described there which this implementation does not yet support. The standard -specifies that they return \fBERR\fR on failure, but specifies no error -conditions. +These functions are described in the XSI Curses standard, Issue 4. +The standard specifies that they return \fBERR\fR on failure, +but specifies no error conditions. .SH SEE ALSO \fBcurses\fR(3), \fBcurs_outopts\fR(3). .\"# diff --git a/lib/libcurses/curs_border_set.3 b/lib/libcurses/curs_border_set.3 new file mode 100644 index 00000000000..68194312be9 --- /dev/null +++ b/lib/libcurses/curs_border_set.3 @@ -0,0 +1,209 @@ +.\" $OpenBSD: curs_border_set.3,v 1.1 2010/01/12 23:21:58 nicm Exp $ +.\" +.\"*************************************************************************** +.\" Copyright (c) 2002-2004,2005 Free Software Foundation, Inc. * +.\" * +.\" Permission is hereby granted, free of charge, to any person obtaining a * +.\" copy of this software and associated documentation files (the * +.\" "Software"), to deal in the Software without restriction, including * +.\" without limitation the rights to use, copy, modify, merge, publish, * +.\" distribute, distribute with modifications, sublicense, and/or sell * +.\" copies of the Software, and to permit persons to whom the Software is * +.\" furnished to do so, subject to the following conditions: * +.\" * +.\" The above copyright notice and this permission notice shall be included * +.\" in all copies or substantial portions of the Software. * +.\" * +.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * +.\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * +.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * +.\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * +.\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * +.\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * +.\" THE USE OR OTHER DEALINGS IN THE SOFTWARE. * +.\" * +.\" Except as contained in this notice, the name(s) of the above copyright * +.\" holders shall not be used in advertising or otherwise to promote the * +.\" sale, use or other dealings in this Software without prior written * +.\" authorization. * +.\"*************************************************************************** +.\" +.\" $Id: curs_border_set.3,v 1.1 2010/01/12 23:21:58 nicm Exp $ +.TH curs_border_set 3 "" +.na +.hy 0 +.SH NAME +\fBborder_set\fR, +\fBwborder_set\fR, +\fBbox_set\fR, +\fBhline_set\fR, +\fBwhline_set\fR, +\fBmvhline_set\fR, +\fBmvwhline_set\fR, +\fBvline_set\fR, +\fBwvline_set\fR, +\fBmvvline_set\fR, +\fBmvwvline_set\fR \- create \fBcurses\fR borders or lines using complex characters and renditions +.ad +.hy +.SH SYNOPSIS +.PP +\fB#include <curses.h>\fR +.sp +\fBint border_set(\fR + \fBconst cchar_t *\fR\fIls\fR, \fBconst cchar_t *\fR\fIrs\fR, + \fBconst cchar_t *\fR\fIts\fR, \fBconst cchar_t *\fR\fIbs\fR, + \fBconst cchar_t *\fR\fItl\fR, \fBconst cchar_t *\fR\fItr\fR, + \fBconst cchar_t *\fR\fIbl\fR, \fBconst cchar_t *\fR\fIbr\fR +\fB);\fR +.br +\fBint wborder_set(\fR + \fBWINDOW *win\fR, + \fBconst cchar_t *\fR\fIls\fR, \fBconst cchar_t *\fR\fIrs\fR, + \fBconst cchar_t *\fR\fIts\fR, \fBconst cchar_t *\fR\fIbs\fR, + \fBconst cchar_t *\fR\fItl\fR, \fBconst cchar_t *\fR\fItr\fR, + \fBconst cchar_t *\fR\fIbl\fR, \fBconst cchar_t *\fR\fIbr\fR\fB);\fR +.br +\fBint box_set(\fR + \fBWINDOW *win\fR, + \fBconst cchar_t *\fR\fIverch\fR, + \fBconst cchar_t *\fR\fIhorch\fR\fB);\fR +.br +\fBint hline_set(\fR + \fBconst cchar_t *\fR\fIwch\fR, \fBint \fR\fIn\fR\fB);\fR +.br +\fBint whline_set(\fR + \fBWINDOW *\fR\fIwin\fR, + \fBconst cchar_t *\fR\fIwch\fR, \fBint \fR\fIn\fR\fB);\fR +.br +\fBint mvhline_set(\fR + \fBint \fR\fIy\fR, \fBint \fR\fIx\fR, + \fBconst cchar_t *\fR\fIwch\fR, \fBint \fR\fIn\fR\fB);\fR +.br +\fBint mvwhline_set(\fR + \fBWINDOW *\fR\fIwin\fR, + \fBint \fR\fIy\fR, \fBint \fR\fIx\fR, + \fBconst cchar_t *\fR\fIwch\fR, \fBint \fR\fIn\fR\fB);\fR +.br +\fBint vline_set(\fR + \fBconst cchar_t *\fR\fIwch\fR, \fBint \fR\fIn\fR\fB);\fR +.br +\fBint wvline_set(\fR + \fBWINDOW *\fR\fIwin\fR, + \fBconst cchar_t *\fR\fIwch\fR, \fBint \fR\fIn\fR\fB);\fR +.br +\fBint mvvline_set(\fR + \fBint \fR\fIy\fR, \fBint \fR\fIx\fR, + \fBconst cchar_t *\fR\fIwch\fR, \fBint \fR\fIn\fR\fB);\fR +.br +\fBint mvwvline_set(\fR + \fBWINDOW *\fR\fIwin\fR, + \fBint \fR\fIy\fR, \fBint \fR\fIx\fR, + \fBconst cchar_t *\fR\fIwch\fR, \fBint \fR\fIn\fR\fB);\fR +.br +.SH DESCRIPTION +.PP +The +\fBborder_set\fR +and +\fBwborder_set\fR +functions draw a border around the edges of the current or specified window. +These functions do not change the cursor position, and do not wrap. +.PP +Other than the window, each argument is a complex character with attributes: +.RS +\fIls\fR - left side, +.br +\fIrs\fR - right side, +.br +\fIts\fR - top side, +.br +\fIbs\fR - bottom side, +.br +\fItl\fR - top left-hand corner, +.br +\fItr\fR - top right-hand corner, +.br +\fIbl\fR - bottom left-hand corner, and +.br +\fIbr\fR - bottom right-hand corner. +.RE +.PP +If any of these arguments is zero, then the corresponding +default values (defined in \fBcurses.h\fR) are used instead: +.RS +\fBWACS_VLINE\fR, +.br +\fBWACS_VLINE\fR, +.br +\fBWACS_HLINE\fR, +.br +\fBWACS_HLINE\fR, +.br +\fBWACS_ULCORNER\fR, +.br +\fBWACS_URCORNER\fR, +.br +\fBWACS_LLCORNER\fR, and +.br +\fBWACS_LRCORNER\fR. +.RE +.PP +\fBbox_set(\fR\fIwin\fR, \fIverch\fR\fB, \fR\fIhorch\fR\fB);\fR +is a shorthand for the following call: +.PP +\fBwborder_set(\fR\fIwin\fR\fB, \fR\fIverch\fR\fB, \fR\fIverch\fR\fB,\fR + \fIhorch\fR\fB, \fR\fIhorch\fR\fB, NULL, NULL, NULL, NULL);\fR +.PP +The +\fB*line_set\fR +functions use +\fIwch\fR +to draw a line starting at the current cursor position in the window. +The line is at most \fIn\fR characters long or as many as fit into the window. +The current cursor position is not changed. +.PP +The +\fBhline_set\fR, +\fBmvhline_set\fR, +\fBmvwhline_set\fR, and +\fBwhline_set\fR +functions draw a line proceeding toward the last column of the same line. +.PP +The +\fBvline_set\fR, +\fBmvvline_set\fR, +\fBmvwvline_set\fR, and +\fBwvline_set\fR +functions draw a line proceeding toward the last line of the window. +.br +.SH NOTES +.PP +Note that +\fBborder_set\fR, +\fBhline_set\fR, +\fBmvhline_set\fR, +\fBmvvline_set\fR, +\fBmvwhline_set\fR, +\fBmvwvline_set\fR, and +\fBvline_set\fR +may be macros. +.br +.SH RETURN VALUES +.PP +Upon successful completion, these functions return +\fBOK\fR. +Otherwise, they return +\fBERR\fR. +.PP +Functions using a window parameter return an error if it is null. +.SH SEE ALSO +\fBncurses\fR(3), +\fBcurs_border\fR(3), +\fBcurs_outopts\fR(3) +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_clear.3 b/lib/libcurses/curs_clear.3 index 063e709e717..cdf6af8dd70 100644 --- a/lib/libcurses/curs_clear.3 +++ b/lib/libcurses/curs_clear.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_clear.3,v 1.6 1998/09/13 19:16:17 millert Exp $ +.\" $OpenBSD: curs_clear.3,v 1.7 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2005,2007 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,15 +28,24 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_clear.3x,v 1.7 1998/03/11 21:12:53 juergen Exp $ +.\" $Id: curs_clear.3,v 1.7 2010/01/12 23:21:59 nicm Exp $ .TH curs_clear 3 "" +.na +.hy 0 .SH NAME -\fBerase\fR, \fBwerase\fR, \fBclear\fR, -\fBwclear\fR, \fBclrtobot\fR, \fBwclrtobot\fR, \fBclrtoeol\fR, +\fBerase\fR, +\fBwerase\fR, +\fBclear\fR, +\fBwclear\fR, +\fBclrtobot\fR, +\fBwclrtobot\fR, +\fBclrtoeol\fR, \fBwclrtoeol\fR - clear all or part of a \fBcurses\fR window +.ad +.hy .SH SYNOPSIS \fB# include <curses.h>\fR - +.sp \fBint erase(void);\fR .br \fBint werase(WINDOW *win);\fR @@ -56,24 +65,29 @@ .SH DESCRIPTION The \fBerase\fR and \fBwerase\fR routines copy blanks to every position in the window, clearing the screen. - +.PP The \fBclear\fR and \fBwclear\fR routines are like \fBerase\fR and \fBwerase\fR, but they also call \fBclearok\fR, so that the screen is cleared completely on the next call to \fBwrefresh\fR for that window and repainted from scratch. - +.PP The \fBclrtobot\fR and \fBwclrtobot\fR routines erase from the cursor to the end of screen. That is, they erase all lines below the cursor in the window. Also, the current line to the right of the cursor, inclusive, is erased. - +.PP The \fBclrtoeol\fR and \fBwclrtoeol\fR routines erase the current line to the right of the cursor, inclusive, to the end of the current line. - +.PP Blanks created by erasure have the current background rendition (as set by \fBwbkgdset\fR) merged into them. .SH RETURN VALUE -All routines return the integer \fBOK\fR. The SVr4.0 manual says "or a +All routines return the integer \fBOK\fR on success and \fBERR\fP on failure. +The SVr4.0 manual says "or a non-negative integer if \fBimmedok\fR is set", but this appears to be an error. +.PP +X/Open defines no error conditions. +In this implementation, +functions using a window pointer parameter return an error if it is null. .SH NOTES Note that \fBerase\fR, \fBwerase\fR, \fBclear\fR, \fBwclear\fR, \fBclrtobot\fR, and \fBclrtoeol\fR may be macros. @@ -81,11 +95,24 @@ Note that \fBerase\fR, \fBwerase\fR, \fBclear\fR, \fBwclear\fR, These functions are described in the XSI Curses standard, Issue 4. The standard specifies that they return \fBERR\fR on failure, but specifies no error conditions. - +.PP Some historic curses implementations had, as an undocumented feature, the ability to do the equivalent of \fBclearok(..., 1)\fR by saying \fBtouchwin(stdscr)\fR or \fBclear(stdscr)\fR. This will not work under ncurses. +.PP +This implementation, and others such as Solaris, +sets the current position to 0,0 after erasing +via \fBwerase()\fP and \fBwclear()\fP. +That fact is not documented in other implementations, +and may not be true of implementations +which were not derived from SVr4 source. +.PP +Not obvious from the description, +most implementations clear the screen after \fBwclear\fP +even for a subwindow or derived window. +If you do not want to clear the screen during the next \fBwrefresh\fP, +use \fBwerase\fP instead. .SH SEE ALSO \fBcurses\fR(3), \fBcurs_outopts\fR(3), \fBcurs_refresh\fR(3) .\"# diff --git a/lib/libcurses/curs_color.3 b/lib/libcurses/curs_color.3 index db447938918..7aa05201098 100644 --- a/lib/libcurses/curs_color.3 +++ b/lib/libcurses/curs_color.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_color.3,v 1.9 2000/07/24 04:06:09 millert Exp $ +.\" $OpenBSD: curs_color.3,v 1.10 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998,2000 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2004,2005 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,8 +28,10 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_color.3x,v 1.16 2000/07/15 22:57:03 tom Exp $ +.\" $Id: curs_color.3,v 1.10 2010/01/12 23:21:59 nicm Exp $ .TH curs_color 3 "" +.na +.hy 0 .SH NAME \fBstart_color\fR, \fBinit_pair\fR, @@ -39,6 +41,8 @@ \fBcolor_content\fR, \fBpair_content\fR, \fBCOLOR_PAIR\fR - \fBcurses\fR color manipulation routines +.ad +.hy .SH SYNOPSIS \fB# include <curses.h>\fR .br @@ -66,7 +70,7 @@ color (for the blank field on which the characters are displayed). A programmer initializes a color-pair with the routine \fBinit_pair\fR. After it has been initialized, \fBCOLOR_PAIR\fR(\fIn\fR), a macro defined in \fB<curses.h>\fR, can be used as a new video attribute. - +.PP If a terminal is capable of redefining colors, the programmer can use the routine \fBinit_color\fR to change the definition of a color. The routines \fBhas_colors\fR and \fBcan_change_color\fR return \fBTRUE\fR or \fBFALSE\fR, @@ -86,7 +90,7 @@ and white), and two global variables, \fBCOLORS\fR and and color-pairs the terminal can support). It also restores the colors on the terminal to the values they had when the terminal was just turned on. - +.PP The \fBinit_pair\fR routine changes the definition of a color-pair. It takes three arguments: the number of the color-pair to be changed, the foreground color number, and the background color number. @@ -98,18 +102,20 @@ must be between \fB1\fR and \fBCOLOR_PAIRS-1\fR. .TP 5 - The value of the second and -third arguments must be between 0 and \fBCOLORS\fR (the 0 color pair is wired -to white on black and cannot be changed). +third arguments must be between 0 and \fBCOLORS\fR. +Color pair 0 is assumed to be white on black, +but is actually whatever the terminal implements before color is initialized. +It cannot be modified by the application. .PP If the color-pair was previously -initialized, the screen is refreshed and all occurrences of that color-pair is -changed to the new definition. - +initialized, the screen is refreshed and all occurrences of that color-pair +are changed to the new definition. +.PP As an extension, ncurses allows you to set color pair 0 via the \fBassume_default_colors\fR routine, or to specify the use of default colors (color number \fB-1\fR) if you first invoke the \fBuse_default_colors\fR routine. - +.PP The \fBinit_color\fR routine changes the definition of a color. It takes four arguments: the number of the color to be changed followed by three RGB values (for the amounts of red, green, and blue components). The value of the first @@ -118,18 +124,18 @@ argument must be between \fB0\fR and \fBCOLORS\fR. (See the section must be a value between 0 and 1000. When \fBinit_color\fR is used, all occurrences of that color on the screen immediately change to the new definition. - +.PP The \fBhas_colors\fR routine requires no arguments. It returns \fBTRUE\fR if the terminal can manipulate colors; otherwise, it returns \fBFALSE\fR. This routine facilitates writing terminal-independent programs. For example, a programmer can use it to decide whether to use color or some other video attribute. - +.PP The \fBcan_change_color\fR routine requires no arguments. It returns \fBTRUE\fR if the terminal supports colors and can change their definitions; other, it returns \fBFALSE\fR. This routine facilitates writing terminal-independent programs. - +.PP The \fBcolor_content\fR routine gives programmers a way to find the intensity of the red, green, and blue (RGB) components in a color. It requires four arguments: the color number, and three addresses of \fBshort\fRs for storing @@ -138,7 +144,7 @@ given color. The value of the first argument must be between 0 and \fBCOLORS\fR. The values that are stored at the addresses pointed to by the last three arguments are between 0 (no component) and 1000 (maximum amount of component). - +.PP The \fBpair_content\fR routine allows programmers to find out what colors a given color-pair consists of. It requires three arguments: the color-pair number, and two addresses of \fBshort\fRs for storing the foreground and the @@ -149,7 +155,7 @@ to by the second and third arguments are between 0 and \fBCOLORS\fR. In \fB<curses.h>\fR the following macros are defined. These are the default colors. \fBcurses\fR also assumes that \fBCOLOR_BLACK\fR is the default background color for all terminals. - +.PP .nf \fBCOLOR_BLACK\fR \fBCOLOR_RED\fR @@ -163,22 +169,44 @@ background color for all terminals. .SH RETURN VALUE The routines \fBcan_change_color()\fR and \fBhas_colors()\fR return \fBTRUE\fR or \fBFALSE\fR. - +.PP All other routines return the integer \fBERR\fR upon failure and an \fBOK\fR (SVr4 specifies only "an integer value other than \fBERR\fR") upon successful completion. +.PP +X/Open defines no error conditions. +This implementation will return \fBERR\fR on attempts to +use color values outside the range 0 to COLORS-1 +(except for the default colors extension), +or use color pairs outside the range 0 to COLOR_PAIR-1. +Color values used in \fBinit_color\fP must be in the range 0 to 1000. +An error is returned from all functions +if the terminal has not been initialized. +An error is returned from secondary functions such as \fBinit_pair\fP +if \fBstart_color\fP was not called. +.RS +.TP 5 +\fBinit_color\fP +returns an error if the terminal does not support +this feature, e.g., if the \fIinitialize_color\fP capability is absent +from the terminal description. +.TP 5 +\fBstart_color\fP +returns an error +If the color table cannot be allocated. +.RE .SH NOTES In the \fIncurses\fR implementation, there is a separate color activation flag, color palette, color pairs table, and associated COLORS and COLOR_PAIRS counts for each screen; the \fBstart_color\fR function only affects the current screen. The SVr4/XSI interface is not really designed with this in mind, and historical implementations may use a single shared color palette. - +.PP Note that setting an implicit background color via a color pair affects only character cells that a character write operation explicitly touches. To change the background color used when parts of a window are blanked by erasing or scrolling operations, see \fBcurs_bkgd\fR(3). - +.PP Several caveats apply on 386 and 486 machines with VGA-compatible graphics: .TP 5 - @@ -203,8 +231,12 @@ but only if that routine has been first invoked. .PP The assumption that \fBCOLOR_BLACK\fR is the default background color for all terminals can be modified using the -\fBassume_default_colors\fP extension, -.. +\fBassume_default_colors\fP extension. +.PP +This implementation checks the pointers, +e.g., for the values returned by +\fBcolor_content\fP and \fBpair_content\fP, +and will treat those as optional parameters when null. .SH SEE ALSO \fBcurses\fR(3), \fBcurs_initscr\fR(3), diff --git a/lib/libcurses/curs_delch.3 b/lib/libcurses/curs_delch.3 index 17ac6bd95b5..143fbcc0f12 100644 --- a/lib/libcurses/curs_delch.3 +++ b/lib/libcurses/curs_delch.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_delch.3,v 1.6 2000/07/10 03:06:05 millert Exp $ +.\" $OpenBSD: curs_delch.3,v 1.7 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998,2000 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2000,2006 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,7 +28,7 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_delch.3x,v 1.7 2000/07/01 19:55:37 tom Exp $ +.\" $Id: curs_delch.3,v 1.7 2010/01/12 23:21:59 nicm Exp $ .TH curs_delch 3 "" .SH NAME \fBdelch\fR, @@ -37,7 +37,7 @@ \fBmvwdelch\fR - delete character under the cursor in a \fBcurses\fR window .SH SYNOPSIS \fB#include <curses.h>\fR - +.sp \fBint delch(void);\fR .br \fBint wdelch(WINDOW *win);\fR diff --git a/lib/libcurses/curs_deleteln.3 b/lib/libcurses/curs_deleteln.3 index 26f04cdfff2..cf34da5b26f 100644 --- a/lib/libcurses/curs_deleteln.3 +++ b/lib/libcurses/curs_deleteln.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_deleteln.3,v 1.9 2003/05/12 11:06:49 jmc Exp $ +.\" $OpenBSD: curs_deleteln.3,v 1.10 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998,2000 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,7 +28,7 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_deleteln.3x,v 1.7 2000/11/11 20:43:20 Bernhard.Rosenkraenzer Exp $ +.\" $Id: curs_deleteln.3,v 1.10 2010/01/12 23:21:59 nicm Exp $ .TH curs_deleteln 3 "" .SH NAME \fBdeleteln\fR, @@ -39,7 +39,7 @@ \fBwinsertln\fR - delete and insert lines in a \fBcurses\fR window .SH SYNOPSIS \fB#include <curses.h>\fR - +.sp \fBint deleteln(void);\fR .br \fBint wdeleteln(WINDOW *win);\fR @@ -56,28 +56,32 @@ The \fBdeleteln\fR and \fBwdeleteln\fR routines delete the line under the cursor in the window; all lines below the current line are moved up one line. The bottom line of the window is cleared. The cursor position does not change. - +.PP The \fBinsdelln\fR and \fBwinsdelln\fR routines, for positive \fIn\fR, insert \fIn\fR lines into the specified window above the current line. The \fIn\fR bottom lines are lost. For negative \fIn\fR, delete \fIn\fR lines (starting with the one under the cursor), and move the remaining lines up. The bottom \fIn\fR lines are cleared. The current cursor position remains the same. - +.PP The \fBinsertln\fR and \fBwinsertln\fR routines insert a blank line above the current line and the bottom line is lost. .SH RETURN VALUE All routines return the integer \fBERR\fR upon failure and an \fBOK\fR (SVr4 specifies only "an integer value other than \fBERR\fR") upon successful completion. +.PP +X/Open defines no error conditions. +In this implementation, +if the window parameter is null, an error is returned. .SH PORTABILITY These functions are described in the XSI Curses standard, Issue 4. The standard specifies that they return \fBERR\fR on failure, but specifies no error conditions. .SH NOTES Note that all but \fBwinsdelln\fR may be macros. - +.PP These routines do not require a hardware line delete or insert feature in the -terminal. In fact, they won't use hardware line delete/insert unless +terminal. In fact, they will not use hardware line delete/insert unless \fBidlok(..., TRUE)\fR has been set on the current window. .SH SEE ALSO \fBcurses\fR(3) diff --git a/lib/libcurses/curs_extend.3 b/lib/libcurses/curs_extend.3 index d33fb1ec949..f8629c72438 100644 --- a/lib/libcurses/curs_extend.3 +++ b/lib/libcurses/curs_extend.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_extend.3,v 1.5 2003/05/12 11:06:49 jmc Exp $ +.\" $OpenBSD: curs_extend.3,v 1.6 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1999,2000 Free Software Foundation, Inc. * +.\" Copyright (c) 1999-2004,2006 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,22 +28,20 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" Author: Thomas E. Dickey <dickey@clark.net> 1999 +.\" Author: Thomas E. Dickey 1999-on .\" -.\" $From: curs_extend.3x,v 1.6 2000/07/15 22:57:20 tom Exp $ +.\" $Id: curs_extend.3,v 1.6 2010/01/12 23:21:59 nicm Exp $ .TH curs_extend 3 "" .SH NAME -\fBcurs_extend\fR, \fBcurses_version\fP, \fBuse_extended_names\fP \- miscellaneous curses extensions -.. +. .SH SYNOPSIS \fB#include <curses.h>\fP - +.sp \fBconst char * curses_version(void);\fP .br \fBint use_extended_names(bool enable);\fP -.. .SH DESCRIPTION These functions are extensions to the curses library which do not fit easily into other categories. @@ -60,27 +58,25 @@ is able to use user-defined or nonstandard names which may be compiled into the terminfo description, i.e., via the terminfo or termcap interfaces. Normally these names are available for use, since the essential decision -is made by using the \fB-x\fP option of \fItic\fP to compile +is made by using the \fB-x\fP option of \fBtic\fP to compile extended terminal definitions. However you can disable this feature to ensure compatibility with other implementations of curses. -.. .SH PORTABILITY These routines are specific to ncurses. They were not supported on Version 7, BSD or System V implementations. It is recommended that any code depending on them be conditioned using NCURSES_VERSION. -.. .SH SEE ALSO \fBcurs_getch\fR(3), \fBcurs_mouse\fR(3), \fBcurs_print\fR(3), +\fBcurs_util\fR(3), \fBdefault_colors\fR(3), \fBdefine_key\fR(3), \fBkeybound\fR(3), \fBkeyok\fR(3), \fBresizeterm\fR(3), \fBwresize\fR(3). -.. .SH AUTHOR Thomas Dickey. .\"# diff --git a/lib/libcurses/curs_getch.3tbl b/lib/libcurses/curs_getch.3tbl index 978b261e616..92d06582845 100644 --- a/lib/libcurses/curs_getch.3tbl +++ b/lib/libcurses/curs_getch.3tbl @@ -1,8 +1,8 @@ -'\" t -.\" $OpenBSD: curs_getch.3tbl,v 1.11 2003/05/12 11:06:49 jmc Exp $ +'\" t +.\" $OpenBSD: curs_getch.3tbl,v 1.12 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998,2000 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -29,8 +29,10 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_getch.3x,v 1.18 2001/02/25 00:20:30 tom Exp $ +.\" $Id: curs_getch.3tbl,v 1.12 2010/01/12 23:21:59 nicm Exp $ .TH curs_getch 3 "" +.na +.hy 0 .SH NAME \fBgetch\fR, \fBwgetch\fR, @@ -38,9 +40,11 @@ \fBmvwgetch\fR, \fBungetch\fR, \fBhas_key\fR \- get (or push back) characters from \fBcurses\fR terminal keyboard +.ad +.hy .SH SYNOPSIS \fB#include <curses.h>\fR - +.PP \fBint getch(void);\fR .br \fBint wgetch(WINDOW *win);\fR @@ -55,14 +59,19 @@ .br .SH DESCRIPTION The \fBgetch\fR, \fBwgetch\fR, \fBmvgetch\fR and \fBmvwgetch\fR, routines read -a character from the window. In no-delay mode, if no input is waiting, the -value \fBERR\fR is returned. In delay mode, the program waits until the system -passes text through to the program. Depending on the setting of \fBcbreak\fR, -this is after one character (cbreak mode), or after the first newline (nocbreak -mode). In half-delay mode, the program waits until a character is typed or the +a character from the window. +In no-delay mode, if no input is waiting, the value \fBERR\fR is returned. +In delay mode, the program waits until the system +passes text through to the program. +Depending on the setting of \fBcbreak\fR, +this is after one character (cbreak mode), +or after the first newline (nocbreak mode). +In half-delay mode, +the program waits until a character is typed or the specified timeout has been reached. - -Unless \fBnoecho\fR has been set, then the character will also be echoed into the +.PP +Unless \fBnoecho\fR has been set, +then the character will also be echoed into the designated window according to the following rules: If the character is the current erase character, left arrow, or backspace, the cursor is moved one space to the left and that screen position is erased @@ -70,32 +79,36 @@ as if \fBdelch\fR had been called. If the character value is any other \fBKEY_\fR define, the user is alerted with a \fBbeep\fR call. Otherwise the character is simply output to the screen. - +.PP If the window is not a pad, and it has been moved or modified since the last call to \fBwrefresh\fR, \fBwrefresh\fR will be called before another character is read. - +.PP If \fBkeypad\fR is \fBTRUE\fR, and a function key is pressed, the token for -that function key is returned instead of the raw characters. Possible function +that function key is returned instead of the raw characters. +Possible function keys are defined in \fB<curses.h>\fR as macros with values outside the range of 8-bit characters whose names begin with \fBKEY_\fR. Thus, a variable intended to hold the return value of a function key must be of short size or larger. - +.PP When a character that could be the beginning of a function key is received -(which, on modern terminals, means an escape character), \fBcurses\fR sets a -timer. If the remainder of the sequence does not come in within the designated -time, the character is passed through; otherwise, the function key value is -returned. For this reason, many terminals experience a delay between the time +(which, on modern terminals, means an escape character), +\fBcurses\fR sets a timer. +If the remainder of the sequence does not come in within the designated +time, the character is passed through; +otherwise, the function key value is returned. +For this reason, many terminals experience a delay between the time a user presses the escape key and the escape is returned to the program. - +.PP The \fBungetch\fR routine places \fIch\fR back onto the input queue to be -returned by the next call to \fBwgetch\fR. Note that there is, in effect, -just one input queue for all windows. - +returned by the next call to \fBwgetch\fR. +There is just one input queue for all windows. +.PP .SS Function Keys The following function keys, defined in \fB<curses.h>\fR, might be returned by -\fBgetch\fR if \fBkeypad\fR has been enabled. Note that not all of these are +\fBgetch\fR if \fBkeypad\fR has been enabled. +Note that not all of these are necessarily supported on any particular terminal. .sp .TS @@ -103,7 +116,6 @@ center tab(/) ; l l l l . \fIName\fR/\fIKey\fR \fIname\fR - KEY_BREAK/Break key KEY_DOWN/The four arrow keys ... KEY_UP @@ -201,7 +213,7 @@ KEY_SUNDO/Shifted undo key KEY_SUSPEND/Suspend key KEY_UNDO/Undo key .TE - +.PP Keypad is arranged like this: .sp .TS @@ -213,73 +225,103 @@ c c c . .TE .sp The \fBhas_key\fR routine takes a key value from the above list, and -returns TRUE or FALSE according to whether the current terminal type -recognizes a key with that value. - +returns TRUE or FALSE according to whether +the current terminal type recognizes a key with that value. +Note that a few values do not correspond to a real key, +e.g., \fBKEY_RESIZE\fP and \fBKEY_MOUSE\fP. +See \fBresizeterm\fR(3) for more details about \fBKEY_RESIZE\fP, and +\fBcurs_mouse\fR(3) for a discussion of \fBKEY_MOUSE\fP. +.PP .SH RETURN VALUE All routines return the integer \fBERR\fR upon failure and an integer value other than \fBERR\fR (\fBOK\fR in the case of ungetch()) upon successful completion. +.RS +.TP 5 +\fBungetch\fP +returns an error +if there is no more room in the FIFO. +.TP 5 +\fBwgetch\fP +returns an error +if the window pointer is null, or +if its timeout expires without having any data. +.RE .SH NOTES Use of the escape key by a programmer for a single character function is discouraged, as it will cause a delay of up to one second while the keypad code looks for a following function-key sequence. - +.PP Note that some keys may be the same as commonly used control -keys, e.g., KEY_ENTER versus control/M, KEY_BACKSPACE versus control/H. +keys, e.g., \fBKEY_ENTER\fP versus control/M, \fBKEY_BACKSPACE\fP versus control/H. Some curses implementations may differ according to whether they treat these control keys specially (and ignore the terminfo), or use the terminfo definitions. \fBNcurses\fR uses the terminfo definition. -If it says that KEY_ENTER is control/M, \fBgetch\fR will return KEY_ENTER +If it says that \fBKEY_ENTER\fP is control/M, +\fBgetch\fR will return \fBKEY_ENTER\fP when you press control/M. - +.PP When using \fBgetch\fR, \fBwgetch\fR, \fBmvgetch\fR, or \fBmvwgetch\fR, nocbreak mode (\fBnocbreak\fR) and echo mode -(\fBecho\fR) should not be used at the same time. Depending on the +(\fBecho\fR) should not be used at the same time. +Depending on the state of the tty driver when each character is typed, the program may produce undesirable results. - +.PP Note that \fBgetch\fR, \fBmvgetch\fR, and \fBmvwgetch\fR may be macros. - +.PP Historically, the set of keypad macros was largely defined by the extremely -function-key-rich keyboard of the AT&T 7300, aka 3B1, aka Safari 4. Modern -personal computers usually have only a small subset of these. IBM PC-style +function-key-rich keyboard of the AT&T 7300, aka 3B1, aka Safari 4. +Modern +personal computers usually have only a small subset of these. +IBM PC-style consoles typically support little more than \fBKEY_UP\fR, \fBKEY_DOWN\fR, \fBKEY_LEFT\fR, \fBKEY_RIGHT\fR, \fBKEY_HOME\fR, \fBKEY_END\fR, -\fBKEY_NPAGE\fR, \fBKEY_PPAGE\fR, and function keys 1 through 12. The Ins key +\fBKEY_NPAGE\fR, \fBKEY_PPAGE\fR, and function keys 1 through 12. +The Ins key is usually mapped to \fBKEY_IC\fR. .SH PORTABILITY -The *get* functions are described in the XSI Curses standard, Issue 4. They -read single-byte characters only. The standard specifies that they return +The *get* functions are described in the XSI Curses standard, Issue 4. +They +read single-byte characters only. +The standard specifies that they return \fBERR\fR on failure, but specifies no error conditions. - +.PP The echo behavior of these functions on input of \fBKEY_\fR or backspace -characters was not specified in the SVr4 documentation. This description is +characters was not specified in the SVr4 documentation. +This description is adopted from the XSI Curses standard. - +.PP The behavior of \fBgetch\fR and friends in the presence of handled signals is -unspecified in the SVr4 and XSI Curses documentation. Under historical curses +unspecified in the SVr4 and XSI Curses documentation. +Under historical curses implementations, it varied depending on whether the operating system's implementation of handled signal receipt interrupts a \fBread\fR(2) call in progress or not, and also (in some implementations) depending on whether an -input timeout or non-blocking mode hsd been set. - +input timeout or non-blocking mode has been set. +.PP Programmers concerned about portability should be prepared for either of two cases: (a) signal receipt does not interrupt \fBgetch\fR; (b) signal receipt interrupts \fBgetch\fR and causes it to return ERR with \fBerrno\fR set to -\fBEINTR\fR. Under the \fBncurses\fR implementation, handled signals never +\fBEINTR\fR. +Under the \fBncurses\fR implementation, handled signals never interrupt \fBgetch\fR. - -The \fBhas_key\fR function is unique to \fBncurses\fR. We recommend that +.PP +The \fBhas_key\fR function is unique to \fBncurses\fR. +We recommend that any code using it be conditionalized on the \fBNCURSES_VERSION\fR feature macro. .SH SEE ALSO \fBcurses\fR(3), \fBcurs_inopts\fR(3), \fBcurs_mouse\fR(3), \fBcurs_move\fR(3), -\fBcurs_refresh\fR(3). +\fBcurs_refresh\fR(3), \fBresizeterm\fR(3). +.PP +Comparable functions in the wide-character (ncursesw) library are +described in +\fBcurs_get_wch\fR(3). .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_getstr.3 b/lib/libcurses/curs_getstr.3 index 2b082892fbd..7edf7fc2c65 100644 --- a/lib/libcurses/curs_getstr.3 +++ b/lib/libcurses/curs_getstr.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_getstr.3,v 1.8 2003/05/12 11:06:49 jmc Exp $ +.\" $OpenBSD: curs_getstr.3,v 1.9 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998,2000 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2003,2005 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,8 +28,10 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_getstr.3x,v 1.9 2000/07/01 17:39:31 tom Exp $ +.\" $Id: curs_getstr.3,v 1.9 2010/01/12 23:21:59 nicm Exp $ .TH curs_getstr 3 "" +.na +.hy 0 .SH NAME \fBgetstr\fR, \fBgetnstr\fR, @@ -39,9 +41,11 @@ \fBmvgetnstr\fR, \fBmvwgetstr\fR, \fBmvwgetnstr\fR - accept character strings from \fBcurses\fR terminal keyboard +.ad +.hy .SH SYNOPSIS \fB#include <curses.h>\fR - +.sp \fBint getstr(char *str);\fR .br \fBint getnstr(char *str, int n);\fR @@ -63,17 +67,17 @@ The function \fBgetstr\fR is equivalent to a series of calls to \fBgetch\fR, until a newline or carriage return is received (the terminating character is not included in the returned string). The resulting value is placed in the area pointed to by the character pointer \fIstr\fR. - +.PP \fBwgetnstr\fR reads at most \fIn\fR characters, thus preventing a possible overflow of the input buffer. Any attempt to enter more characters (other than the terminating newline or carriage return) causes a beep. Function keys also cause a beep and are ignored. The \fBgetnstr\fR function reads from the \fIstdscr\fR default window. - +.PP The user's erase and kill characters are interpreted. If keypad mode is on for the window, \fBKEY_LEFT\fR and \fBKEY_BACKSPACE\fR are both considered equivalent to the user's kill character. - +.PP Characters input are echoed only if \fBecho\fR is currently on. In that case, backspace is echoed as deletion of the previous character (typically a left motion). @@ -81,22 +85,33 @@ motion). All routines return the integer \fBERR\fR upon failure and an \fBOK\fR (SVr4 specifies only "an integer value other than \fBERR\fR") upon successful completion. +.PP +X/Open defines no error conditions. +.PP +In this implementation, +these functions return an error +if the window pointer is null, or +if its timeout expires without having any data. +.PP +This implementation provides an extension as well. +If a SIGWINCH interrupts the function, it will return \fBKEY_RESIZE\fP +rather than \fBOK\fP or \fBERR\fP. .SH NOTES Note that \fBgetstr\fR, \fBmvgetstr\fR, and \fBmvwgetstr\fR may be macros. .SH PORTABILITY -These functions are described in the XSI Curses standard, Issue 4. They read -single-byte characters only. The standard specifies that they return \fBERR\fR -on failure, but the single error condition \fBEOVERFLOW\fR associated with -extended-level conformance is not yet returned (the XSI curses support for -multi-byte characters is not yet present). - +These functions are described in the XSI Curses standard, Issue 4. +They read single-byte characters only. +The standard does not define any error conditions. +This implementation returns ERR if the window pointer is null, +or if the lower-level \fBwgetch\fR call returns an ERR. +.PP SVr3 and early SVr4 curses implementations did not reject function keys; the SVr4.0 documentation claimed that "special keys" (such as function -keys, "home" key, "clear" key, etc.) are "interpreted", without +keys, "home" key, "clear" key, \fIetc\fR.) are "interpreted", without giving details. It lied. In fact, the `character' value appended to the string by those implementations was predictable but not useful (being, in fact, the low-order eight bits of the key's KEY_ value). - +.PP The functions \fBgetnstr\fR, \fBmvgetnstr\fR, and \fBmvwgetnstr\fR were present but not documented in SVr4. .SH SEE ALSO diff --git a/lib/libcurses/curs_getyx.3 b/lib/libcurses/curs_getyx.3 index 95921476314..ee882cc497f 100644 --- a/lib/libcurses/curs_getyx.3 +++ b/lib/libcurses/curs_getyx.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_getyx.3,v 1.6 2003/05/12 11:06:49 jmc Exp $ +.\" $OpenBSD: curs_getyx.3,v 1.7 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,14 +28,16 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_getyx.3x,v 1.6 1998/03/11 21:12:53 juergen Exp $ +.\" $Id: curs_getyx.3,v 1.7 2010/01/12 23:21:59 nicm Exp $ .TH curs_getyx 3 "" .SH NAME -\fBgetyx\fR, \fBgetparyx\fR, \fBgetbegyx\fR, +\fBgetyx\fR, +\fBgetparyx\fR, +\fBgetbegyx\fR, \fBgetmaxyx\fR - get \fBcurses\fR cursor and window coordinates .SH SYNOPSIS \fB#include <curses.h>\fR - +.sp \fBvoid getyx(WINDOW *win, int y, int x);\fR .br \fBvoid getparyx(WINDOW *win, int y, int x);\fR @@ -47,25 +49,57 @@ .SH DESCRIPTION The \fBgetyx\fR macro places the current cursor position of the given window in the two integer variables \fIy\fR and \fIx\fR. - +.PP If \fIwin\fR is a subwindow, the \fBgetparyx\fR macro places the beginning coordinates of the subwindow relative to the parent window into two integer -variables \fIy\fR and \fIx\fR. Otherwise, \fB-1\fR is placed into \fIy\fR and -\fIx\fR. - +variables \fIy\fR and \fIx\fR. +Otherwise, \fB-1\fR is placed into \fIy\fR and \fIx\fR. +.PP Like \fBgetyx\fR, the \fBgetbegyx\fR and \fBgetmaxyx\fR macros store the current beginning coordinates and size of the specified window. .SH RETURN VALUE The return values of these macros are undefined (i.e., -they should not be used as the right-hand side of assignment -statements). +they should not be used as the right-hand side of assignment statements). .SH NOTES -All of these interfaces are macros and that "\fB&\fR" is not -necessary before the variables \fIy\fR and \fIx\fR. +All of these interfaces are macros. +A "\fB&\fR" is not necessary before the variables \fIy\fR and \fIx\fR. .SH PORTABILITY -These functions are described in the XSI Curses standard, Issue 4. +The +\fBgetyx\fR, +\fBgetparyx\fR, +\fBgetbegyx\fR and +\fBgetmaxyx\fR +macros are described in the XSI Curses standard, Issue 4. +.PP +This implementation also provides functions +\fBgetbegx\fR, +\fBgetbegy\fR, +\fBgetcurx\fR, +\fBgetcury\fR, +\fBgetmaxx\fR, +\fBgetmaxy\fR, +\fBgetparx\fR and +\fBgetpary\fR +for compatibility with older versions of curses. +.PP +Although X/Open Curses does not address this, +many implementations provide members of the WINDOW structure +containing values corresponding to these macros. +For best portability, do not rely on using the data in WINDOW, +since some implementations make WINDOW opaque (do not allow +direct use of its members). +.PP +Besides the problem of opaque structures, +the data stored in like-named members may not have like-values in +different implementations. +For example, the WINDOW._maxx and WINDOW._maxy values in ncurses +have (at least since release 1.8.1) differed by one from some +other implementations. +The difference is hidden by means of the macro \fBgetmaxyx\fP. .SH SEE ALSO -\fBcurses\fR(3) +\fBcurses\fR(3), +\fBcurs_legacy\fR(3), +\fBcurs_opaque\fR(3) .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_inch.3tbl b/lib/libcurses/curs_inch.3tbl index d29aac44a90..9a65becd6a6 100644 --- a/lib/libcurses/curs_inch.3tbl +++ b/lib/libcurses/curs_inch.3tbl @@ -1,8 +1,8 @@ -'\" t -.\" $OpenBSD: curs_inch.3tbl,v 1.7 1999/01/18 19:07:13 millert Exp $ +'\" t +.\" $OpenBSD: curs_inch.3tbl,v 1.8 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998 Free Software Foundation, Inc. * +.\" Copyright (c) 1998,2006 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -29,14 +29,14 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_inch.3x,v 1.11 1998/11/29 01:04:34 Rick.Ohnemus Exp $ +.\" $Id: curs_inch.3tbl,v 1.8 2010/01/12 23:21:59 nicm Exp $ .TH curs_inch 3 "" .SH NAME \fBinch\fR, \fBwinch\fR, \fBmvinch\fR, \fBmvwinch\fR - get a character and attributes from a \fBcurses\fR window .SH SYNOPSIS \fB#include <curses.h>\fR - +.sp \fBchtype inch(void);\fR .br \fBchtype winch(WINDOW *win);\fR @@ -51,10 +51,10 @@ position in the named window. If any attributes are set for that position, their values are OR'ed into the value returned. Constants defined in \fB<curses.h>\fR can be used with the \fB&\fR (logical AND) operator to extract the character or attributes alone. - +. .SS Attributes The following bit-masks may be AND-ed with characters returned by \fBwinch\fR. - +. .TS l l . \fBA_CHARTEXT\fR Bit-mask to extract character @@ -67,6 +67,10 @@ Note that all of these routines may be macros. These functions are described in the XSI Curses standard, Issue 4. .SH SEE ALSO \fBcurses\fR(3). +.PP +Comparable functions in the wide-character (ncursesw) library are +described in +\fBcurs_in_wch\fR(3). .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_inchstr.3 b/lib/libcurses/curs_inchstr.3 index 4bf3827b29a..f9f2907fc42 100644 --- a/lib/libcurses/curs_inchstr.3 +++ b/lib/libcurses/curs_inchstr.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_inchstr.3,v 1.7 2000/07/10 03:06:07 millert Exp $ +.\" $OpenBSD: curs_inchstr.3,v 1.8 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998,2000 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,8 +28,10 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_inchstr.3x,v 1.8 2000/07/01 20:16:18 tom Exp $ +.\" $Id: curs_inchstr.3,v 1.8 2010/01/12 23:21:59 nicm Exp $ .TH curs_inchstr 3 "" +.na +.hy 0 .SH NAME \fBinchstr\fR, \fBinchnstr\fR, @@ -39,9 +41,11 @@ \fBmvinchnstr\fR, \fBmvwinchstr\fR, \fBmvwinchnstr\fR - get a string of characters (and attributes) from a \fBcurses\fR window +.ad +.hy .SH SYNOPSIS \fB#include <curses.h>\fR - +.sp \fBint inchstr(chtype *chstr);\fR .br \fBint inchnstr(chtype *chstr, int n);\fR @@ -71,6 +75,11 @@ in the \fIchstr\fR [see \fBcurs_inch\fR(3)]. All routines return the integer \fBERR\fR upon failure and an integer value other than \fBERR\fR upon successful completion (the number of characters retrieved, exclusive of the trailing 0). +.PP +No error conditions are defined. +If the \fIchstr\fP parameter is null, +no data is returned, +and the return value is zero. .SH NOTES Note that all routines except \fBwinchnstr\fR may be macros. SVr4 does not document whether the result string is 0-terminated; it does not document @@ -82,6 +91,10 @@ more specific than the SVr4 documentation on the trailing 0. It does specify that the successful return of the functions is \fBOK\fR. .SH SEE ALSO \fBcurses\fR(3), \fBcurs_inch\fR(3). +.PP +Comparable functions in the wide-character (ncursesw) library are +described in +\fBcurs_in_wchstr\fR(3). .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_initscr.3 b/lib/libcurses/curs_initscr.3 index fb57f12a83e..61de6f22c00 100644 --- a/lib/libcurses/curs_initscr.3 +++ b/lib/libcurses/curs_initscr.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_initscr.3,v 1.8 2003/05/12 11:06:49 jmc Exp $ +.\" $OpenBSD: curs_initscr.3,v 1.9 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998,2000 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2003,2005 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,8 +28,10 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_initscr.3x,v 1.10 2000/07/08 12:47:39 tom Exp $ +.\" $Id: curs_initscr.3,v 1.9 2010/01/12 23:21:59 nicm Exp $ .TH curs_initscr 3 "" +.na +.hy 0 .SH NAME \fBinitscr\fR, \fBnewterm\fR, @@ -37,16 +39,18 @@ \fBisendwin\fR, \fBset_term\fR, \fBdelscreen\fR - \fBcurses\fR screen initialization and manipulation routines +.ad +.hy .SH SYNOPSIS \fB#include <curses.h>\fR - +.sp \fBWINDOW *initscr(void);\fR .br \fBint endwin(void);\fR .br \fBbool isendwin(void);\fR .br -\fBSCREEN *newterm(const char *type, FILE *outfd, FILE *infd);\fR +\fBSCREEN *newterm(char *type, FILE *outfd, FILE *infd);\fR .br \fBSCREEN *set_term(SCREEN *new);\fR .br @@ -58,13 +62,13 @@ initializing a program. A few special routines sometimes need to be called before it; these are \fBslk_init\fR, \fBfilter\fR, \fBripoffline\fR, \fBuse_env\fR. For multiple-terminal applications, \fBnewterm\fR may be called before \fBinitscr\fR. - +.PP The initscr code determines the terminal type and initializes all \fBcurses\fR data structures. \fBinitscr\fR also causes the first call to \fBrefresh\fR to clear the screen. If errors occur, \fBinitscr\fR writes an appropriate error message to standard error and exits; otherwise, a pointer is returned to \fBstdscr\fR. - +.PP A program that outputs to more than one terminal should use the \fBnewterm\fR routine for each terminal instead of \fBinitscr\fR. A program that needs to inspect capabilities, so it can continue to run in a line-oriented mode if the @@ -78,23 +82,23 @@ is \fBNULL\fR, \fB$TERM\fR will be used). The program must also call \fBendwin\fR for each terminal being used before exiting from \fBcurses\fR. If \fBnewterm\fR is called more than once for the same terminal, the first terminal referred to must be the last one for which \fBendwin\fR is called. - +.PP A program should always call \fBendwin\fR before exiting or escaping from \fBcurses\fR mode temporarily. This routine restores tty modes, moves the cursor to the lower left-hand corner of the screen and resets the terminal into the proper non-visual mode. Calling \fBrefresh\fR or \fBdoupdate\fR after a temporary escape causes the program to resume visual mode. - +.PP The \fBisendwin\fR routine returns \fBTRUE\fR if \fBendwin\fR has been called without any subsequent calls to \fBwrefresh\fR, and \fBFALSE\fR otherwise. - +.PP The \fBset_term\fR routine is used to switch between different terminals. The screen reference \fBnew\fR becomes the new current terminal. The previous terminal is returned by the routine. This is the only routine which manipulates \fBSCREEN\fR pointers; all other routines affect only the current terminal. - +.PP The \fBdelscreen\fR routine frees storage associated with the \fBSCREEN\fR data structure. The \fBendwin\fR routine does not do this, so \fBdelscreen\fR should be called after \fBendwin\fR if a @@ -102,15 +106,19 @@ particular \fBSCREEN\fR is no longer needed. .SH RETURN VALUE \fBendwin\fR returns the integer \fBERR\fR upon failure and \fBOK\fR upon successful completion. - +.PP Routines that return pointers always return \fBNULL\fR on error. +.PP +X/Open defines no error conditions. +In this implementation +\fBendwin\fP returns an error if the terminal was not initialized. .SH NOTES Note that \fBinitscr\fR and \fBnewterm\fR may be macros. .SH PORTABILITY These functions are described in the XSI Curses standard, Issue 4. It specifies that portable applications must not call \fBinitscr\fR more than once. - +.PP Old versions of curses, e.g., BSD 4.4, may have returned a null pointer from \fBinitscr\fR when an error is detected, rather than exiting. It is safe but redundant to check the return value of \fBinitscr\fR diff --git a/lib/libcurses/curs_inopts.3 b/lib/libcurses/curs_inopts.3 index 05fe55c9815..4172ca9fbae 100644 --- a/lib/libcurses/curs_inopts.3 +++ b/lib/libcurses/curs_inopts.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_inopts.3,v 1.7 2003/05/12 11:06:49 jmc Exp $ +.\" $OpenBSD: curs_inopts.3,v 1.8 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2003,2005 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,17 +28,33 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_inopts.3x,v 1.8 1998/03/11 21:12:53 juergen Exp $ +.\" $Id: curs_inopts.3,v 1.8 2010/01/12 23:21:59 nicm Exp $ .TH curs_inopts 3 "" +.na +.hy 0 .SH NAME -\fBcbreak\fR, \fBnocbreak\fR, \fBecho\fR, -\fBnoecho\fR, \fBhalfdelay\fR, \fBintrflush\fR, \fBkeypad\fR, -\fBmeta\fR, \fBnodelay\fR, \fBnotimeout\fR, \fBraw\fR, \fBnoraw\fR, -\fBnoqiflush\fR, \fBqiflush\fR, \fBtimeout\fR, \fBwtimeout\fR, +\fBcbreak\fR, +\fBnocbreak\fR, +\fBecho\fR, +\fBnoecho\fR, +\fBhalfdelay\fR, +\fBintrflush\fR, +\fBkeypad\fR, +\fBmeta\fR, +\fBnodelay\fR, +\fBnotimeout\fR, +\fBraw\fR, +\fBnoraw\fR, +\fBnoqiflush\fR, +\fBqiflush\fR, +\fBtimeout\fR, +\fBwtimeout\fR, \fBtypeahead\fR - \fBcurses\fR input options +.ad +.hy .SH SYNOPSIS \fB#include <curses.h>\fR - +.PP \fBint cbreak(void);\fR .br \fBint nocbreak(void);\fR @@ -80,14 +96,14 @@ erase/kill character-processing (interrupt and flow control characters are unaffected), making characters typed by the user immediately available to the program. The \fBnocbreak\fR routine returns the terminal to normal (cooked) mode. - +.PP Initially the terminal may or may not be in \fBcbreak\fR mode, as the mode is inherited; therefore, a program should call \fBcbreak\fR or \fBnocbreak\fR explicitly. Most interactive programs using \fBcurses\fR set the \fBcbreak\fR mode. Note that \fBcbreak\fR overrides \fBraw\fR. [See \fBcurs_getch\fR(3) for a discussion of how these routines interact with \fBecho\fR and \fBnoecho\fR.] - +.PP The \fBecho\fR and \fBnoecho\fR routines control whether characters typed by the user are echoed by \fBgetch\fR as they are typed. Echoing by the tty driver is always disabled, but initially \fBgetch\fR is in echo mode, so @@ -97,14 +113,14 @@ they disable echoing by calling \fBnoecho\fR. [See \fBcurs_getch\fR(3) for a discussion of how these routines interact with \fBcbreak\fR and \fBnocbreak\fR.] - +.PP The \fBhalfdelay\fR routine is used for half-delay mode, which is similar to \fBcbreak\fR mode in that characters typed by the user are immediately available to the program. However, after blocking for \fItenths\fR tenths of seconds, ERR is returned if nothing has been typed. The value of \fBtenths\fR must be a number between 1 and 255. Use \fBnocbreak\fR to leave half-delay mode. - +.PP If the \fBintrflush\fR option is enabled, (\fIbf\fR is \fBTRUE\fR), when an interrupt key is pressed on the keyboard (interrupt, break, quit) all output in the tty driver queue will be flushed, giving the effect of faster response to @@ -112,7 +128,7 @@ the interrupt, but causing \fBcurses\fR to have the wrong idea of what is on the screen. Disabling (\fIbf\fR is \fBFALSE\fR), the option prevents the flush. The default for the option is inherited from the tty driver settings. The window argument is ignored. - +.PP The \fBkeypad\fR option enables the keypad of the user's terminal. If enabled (\fIbf\fR is \fBTRUE\fR), the user can press a function key (such as an arrow key) and \fBwgetch\fR returns a single value @@ -123,30 +139,30 @@ itself. If the keypad in the terminal can be turned on (made to transmit) and off (made to work locally), turning on this option causes the terminal keypad to be turned on when \fBwgetch\fR is called. The default value for keypad is false. - +.PP Initially, whether the terminal returns 7 or 8 significant bits on input depends on the control mode of the tty driver [see termio(7)]. To force 8 bits to be returned, invoke \fBmeta\fR(\fIwin\fR, \fBTRUE\fR); this is equivalent, under POSIX, to setting the CS8 flag on the terminal. To force 7 bits to be returned, invoke \fBmeta\fR(\fIwin\fR, \fBFALSE\fR); this is equivalent, under POSIX, -to setting the CS8 flag on the terminal. The window argument, +to setting the CS7 flag on the terminal. The window argument, \fIwin\fR, is always ignored. If the terminfo capabilities \fBsmm\fR (meta_on) and \fBrmm\fR (meta_off) are defined for the terminal, \fBsmm\fR is sent to the terminal when \fBmeta\fR(\fIwin\fR, \fBTRUE\fR) is called and \fBrmm\fR is sent when \fBmeta\fR(\fIwin\fR, \fBFALSE\fR) is called. - +.PP The \fBnodelay\fR option causes \fBgetch\fR to be a non-blocking call. If no input is ready, \fBgetch\fR returns \fBERR\fR. If disabled (\fIbf\fR is \fBFALSE\fR), \fBgetch\fR waits until a key is pressed. - +.PP While interpreting an input escape sequence, \fBwgetch\fR sets a timer while waiting for the next character. If \fBnotimeout(\fR\fIwin\fR, \fBTRUE\fR) is called, then \fBwgetch\fR does not set a timer. The purpose of the timeout is to differentiate between sequences received from a function key and those typed by a user. - +.PP The \fBraw\fR and \fBnoraw\fR routines place the terminal into or out of raw mode. Raw mode is similar to \fBcbreak\fR mode, in that characters typed are immediately passed through to the user program. The differences are that in @@ -154,7 +170,7 @@ raw mode, the interrupt, quit, suspend, and flow control characters are all passed through uninterpreted, instead of generating a signal. The behavior of the BREAK key depends on other bits in the tty driver that are not set by \fBcurses\fR. - +.PP When the \fBnoqiflush\fR routine is used, normal flush of input and output queues associated with the \fBINTR\fR, \fBQUIT\fR and \fBSUSP\fR characters will not be done [see termio(7)]. When @@ -162,7 +178,7 @@ output queues associated with the \fBINTR\fR, \fBQUIT\fR and characters are read. You may want to call \fBnoqiflush()\fR in a signal handler if you want output to continue as though the interrupt had not occurred, after the handler exits. - +.PP The \fBtimeout\fR and \fBwtimeout\fR routines set blocking or non-blocking read for a given window. If \fIdelay\fR is negative, blocking read is used (i.e., waits indefinitely for @@ -173,7 +189,7 @@ milliseconds, and returns \fBERR\fR if there is still no input. Hence, these routines provide the same functionality as \fBnodelay\fR, plus the additional capability of being able to block for only \fIdelay\fR milliseconds (where \fIdelay\fR is positive). - +.PP The \fBcurses\fR library does ``line-breakout optimization'' by looking for typeahead periodically while updating the screen. If input is found, and it is coming from a tty, the current update is postponed until @@ -188,9 +204,21 @@ The \fBtypeahead\fR routine specifies that the file descriptor All routines that return an integer return \fBERR\fR upon failure and OK (SVr4 specifies only "an integer value other than \fBERR\fR") upon successful completion, unless otherwise noted in the preceding routine descriptions. +.PP +X/Open does not define any error conditions. +In this implementation, +functions with a window parameter will return an error if it is null. +Any function will also return an error if the terminal was not initialized. +Also, +.RS +.TP 5 +\fBhalfdelay\fP +returns an error +if its parameter is outside the range 1..255. +.RE .SH PORTABILITY These functions are described in the XSI Curses standard, Issue 4. - +.PP The ncurses library obeys the XPG4 standard and the historical practice of the AT&T curses implementations, in that the echo bit is cleared when curses initializes the terminal state. BSD curses differed from this slightly; it @@ -201,7 +229,7 @@ just after initialization, even if your program remains in cooked mode. Note that \fBecho\fR, \fBnoecho\fR, \fBhalfdelay\fR, \fBintrflush\fR, \fBmeta\fR, \fBnodelay\fR, \fBnotimeout\fR, \fBnoqiflush\fR, \fBqiflush\fR, \fBtimeout\fR, and \fBwtimeout\fR may be macros. - +.PP The \fBnoraw\fR and \fBnocbreak\fR calls follow historical practice in that they attempt to restore to normal (`cooked') mode from raw and cbreak modes respectively. Mixing raw/noraw and cbreak/nocbreak calls leads to tty driver diff --git a/lib/libcurses/curs_insch.3 b/lib/libcurses/curs_insch.3 index 57099f36dbe..4895ebce40d 100644 --- a/lib/libcurses/curs_insch.3 +++ b/lib/libcurses/curs_insch.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_insch.3,v 1.7 2003/05/12 11:06:49 jmc Exp $ +.\" $OpenBSD: curs_insch.3,v 1.8 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998,2000 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2003,2006 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,7 +28,7 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_insch.3x,v 1.7 2000/07/01 19:57:21 tom Exp $ +.\" $Id: curs_insch.3,v 1.8 2010/01/12 23:21:59 nicm Exp $ .TH curs_insch 3 "" .SH NAME \fBinsch\fR, @@ -37,7 +37,7 @@ \fBmvwinsch\fR - insert a character before cursor in a \fBcurses\fR window .SH SYNOPSIS \fB#include <curses.h>\fR - +.sp \fBint insch(chtype ch);\fR .br \fBint winsch(WINDOW *win, chtype ch);\fR @@ -58,12 +58,16 @@ completion, unless otherwise noted in the preceding routine descriptions. .SH NOTES These routines do not necessarily imply use of a hardware insert character feature. - +.PP Note that \fBinsch\fR, \fBmvinsch\fR, and \fBmvwinsch\fR may be macros. .SH PORTABILITY These functions are described in the XSI Curses standard, Issue 4. .SH SEE ALSO \fBcurses\fR(3). +.PP +Comparable functions in the wide-character (ncursesw) library are +described in +\fBcurs_ins_wch\fR(3). .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_insstr.3 b/lib/libcurses/curs_insstr.3 index abc21ff7598..e5d824f99fd 100644 --- a/lib/libcurses/curs_insstr.3 +++ b/lib/libcurses/curs_insstr.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_insstr.3,v 1.9 2000/07/10 03:06:07 millert Exp $ +.\" $OpenBSD: curs_insstr.3,v 1.10 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998,2000 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,7 +28,7 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_insstr.3x,v 1.11 2000/07/01 19:57:49 tom Exp $ +.\" $Id: curs_insstr.3,v 1.10 2010/01/12 23:21:59 nicm Exp $ .TH curs_insstr 3 "" .SH NAME \fBinsstr\fR, @@ -59,36 +59,42 @@ \fBint mvwinsnstr(WINDOW *win, int y, int x, const char *str, int n);\fR .br .SH DESCRIPTION -These routines insert a character string (as many characters as will fit on the -line) before the character under the cursor. All characters to the right of -the cursor are shifted right, with the possibility of the rightmost characters -on the line being lost. The cursor position does not change (after moving to -\fIy\fR, \fIx\fR, if specified). The four routines with \fIn\fR as the last -argument insert a leading substring of at most \fIn\fR characters. If -\fIn\fR<=0, then the entire string is inserted. - -If a character in \fIstr\fR is a tab, newline, carriage return or -backspace, the cursor is moved appropriately within the window. A -newline also does a \fBclrtoeol\fR before moving. Tabs are considered -to be at every eighth column. If a character in \fIstr\fR is another -control character, it is drawn in the \fB^\fR\fIX\fR notation. -Calling \fBwinch\fR after adding a control character (and moving to -it, if necessary) does not return the control character, but instead -returns a character in the ^-representation of the control character. +These routines insert a character string +(as many characters as will fit on the line) +before the character under the cursor. +All characters to the right of the cursor are shifted right +with the possibility of the rightmost characters on the line being lost. +The cursor position does not change +(after moving to \fIy\fR, \fIx\fR, if specified). +The functions with \fIn\fR as the last argument +insert a leading substring of at most \fIn\fR characters. +If \fIn\fR<=0, then the entire string is inserted. +.PP +Special characters are handled as in \fBaddch\fP. .SH RETURN VALUE All routines that return an integer return \fBERR\fR upon failure and OK (SVr4 specifies only "an integer value other than \fBERR\fR") upon successful completion, unless otherwise noted in the preceding routine descriptions. +.PP +X/Open defines no error conditions. +In this implementation, +if the window parameter is null or the str parameter is null, +an error is returned. .SH NOTES Note that all but \fBwinsnstr\fR may be macros. .SH PORTABILITY These functions are described in the XSI Curses standard, Issue 4, which adds -const qualifiers to the arguments. The XSI Curses error conditions -\fBEILSEQ\fR and \fBEILOVERFLOW\fR associated with extended-level conformance -are not yet detected (this implementation does not yet support XPG4 multi-byte -characters). +const qualifiers to the arguments. +.LP +The Single Unix Specification, Version 2 states that +\fBinsnstr\fP and \fBwinsnstr\fP perform wrapping. +This is probably an error, since it makes this group of functions inconsistent. +Also, no implementation of curses documents this inconsistency. .SH SEE ALSO -\fBcurses\fR(3), \fBcurs_clear\fR(3), \fBcurs_inch\fR(3). +\fBcurses\fR(3), +\fBcurs_util\fR(3), +\fBcurs_clear\fR(3), +\fBcurs_inch\fR(3). .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_instr.3 b/lib/libcurses/curs_instr.3 index dcf93b6e030..140ffcde798 100644 --- a/lib/libcurses/curs_instr.3 +++ b/lib/libcurses/curs_instr.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_instr.3,v 1.7 2000/07/10 03:06:07 millert Exp $ +.\" $OpenBSD: curs_instr.3,v 1.8 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998,2000 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,7 +28,7 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_instr.3x,v 1.9 2000/07/01 20:05:03 tom Exp $ +.\" $Id: curs_instr.3,v 1.8 2010/01/12 23:21:59 nicm Exp $ .TH curs_instr 3 "" .SH NAME \fBinstr\fR, @@ -41,7 +41,7 @@ \fBmvwinnstr\fR - get a string of characters from a \fBcurses\fR window .SH SYNOPSIS \fB#include <curses.h>\fR - +.sp \fBint instr(char *str);\fR .br \fBint innstr(char *str, int n);\fR @@ -67,13 +67,14 @@ functions with \fIn\fR as the last argument return a leading substring at most .SH RETURN VALUE All of the functions return \fBERR\fR upon failure, or the number of characters actually read into the string. +.PP +X/Open defines no error conditions. +In this implementation, +if the window parameter is null or the str parameter is null, +a zero is returned. .SH NOTES Note that all routines except \fBwinnstr\fR may be macros. .SH PORTABILITY -The XSI Curses -error conditions \fBEILSEQ\fR and \fBEILOVERFLOW\fR associated with -extended-level conformance are not yet detected (this implementation does not -yet support XPG4 multi-byte characters). SVr4 does not document whether a length limit includes or excludes the trailing NUL. .PP @@ -88,4 +89,3 @@ In this case, the functions return the string ending at the right margin. .\"# mode:nroff .\"# fill-column:79 .\"# End: - diff --git a/lib/libcurses/curs_kernel.3 b/lib/libcurses/curs_kernel.3 index 32affd776c9..4a69f9aab1f 100644 --- a/lib/libcurses/curs_kernel.3 +++ b/lib/libcurses/curs_kernel.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_kernel.3,v 1.8 2000/03/10 01:35:01 millert Exp $ +.\" $OpenBSD: curs_kernel.3,v 1.9 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2001,2005 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,16 +28,27 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_kernel.3x,v 1.12 2000/02/27 01:37:46 tom Exp $ +.\" $Id: curs_kernel.3,v 1.9 2010/01/12 23:21:59 nicm Exp $ .TH curs_kernel 3 "" +.na +.hy 0 .SH NAME -\fBdef_prog_mode\fR, \fBdef_shell_mode\fR, -\fBreset_prog_mode\fR, \fBreset_shell_mode\fR, \fBresetty\fR, -\fBsavetty\fR, \fBgetsyx\fR, \fBsetsyx\fR, \fBripoffline\fR, -\fBcurs_set\fR, \fBnapms\fR - low-level \fBcurses\fR routines +\fBdef_prog_mode\fR, +\fBdef_shell_mode\fR, +\fBreset_prog_mode\fR, +\fBreset_shell_mode\fR, +\fBresetty\fR, +\fBsavetty\fR, +\fBgetsyx\fR, +\fBsetsyx\fR, +\fBripoffline\fR, +\fBcurs_set\fR, +\fBnapms\fR - low-level \fBcurses\fR routines +.ad +.hy .SH SYNOPSIS \fB#include <curses.h>\fR - +.sp \fBint def_prog_mode(void);\fR .br \fBint def_shell_mode(void);\fR @@ -64,32 +75,32 @@ The following routines give low-level access to various \fBcurses\fR capabilities. Theses routines typically are used inside library routines. - +.PP The \fBdef_prog_mode\fR and \fBdef_shell_mode\fR routines save the current terminal modes as the "program" (in \fBcurses\fR) or "shell" (not in \fBcurses\fR) state for use by the \fBreset_prog_mode\fR and \fBreset_shell_mode\fR routines. This is done automatically by \fBinitscr\fR. There is one such save area for each screen context allocated by \fBnewterm()\fR. - +.PP The \fBreset_prog_mode\fR and \fBreset_shell_mode\fR routines restore the terminal to "program" (in \fBcurses\fR) or "shell" (out of \fBcurses\fR) state. These are done automatically by \fBendwin\fR and, after an \fBendwin\fR, by \fBdoupdate\fR, so they normally are not called. - +.PP The \fBresetty\fR and \fBsavetty\fR routines save and restore the state of the terminal modes. \fBsavetty\fR saves the current state in a buffer and \fBresetty\fR restores the state to what it was at the last call to \fBsavetty\fR. - +.PP The \fBgetsyx\fR routine returns the current coordinates of the virtual screen cursor in \fIy\fR and \fIx\fR. If \fBleaveok\fR is currently \fBTRUE\fR, then \fB-1\fR,\fB-1\fR is returned. If lines have been removed from the top of the screen, using \fBripoffline\fR, \fIy\fR and \fIx\fR include these lines; therefore, \fIy\fR and \fIx\fR should be used only as arguments for \fBsetsyx\fR. - +.PP The \fBsetsyx\fR routine sets the virtual screen cursor to \fIy\fR, \fIx\fR. If \fIy\fR and \fIx\fR are both \fB-1\fR, then \fBleaveok\fR is set. The two routines \fBgetsyx\fR and \fBsetsyx\fR @@ -99,7 +110,7 @@ of the program's cursor. The library routine would call \fBgetsyx\fR at the beginning, do its manipulation of its own windows, do a \fBwnoutrefresh\fR on its windows, call \fBsetsyx\fR, and then call \fBdoupdate\fR. - +.PP The \fBripoffline\fR routine provides access to the same facility that \fBslk_init\fR [see \fBcurs_slk\fR(3)] uses to reduce the size of the screen. \fBripoffline\fR must be called before \fBinitscr\fR or @@ -114,39 +125,55 @@ and \fBCOLS\fR (defined in \fB<curses.h>\fR) are not guaranteed to be accurate and \fBwrefresh\fR or \fBdoupdate\fR must not be called. It is allowable to call \fBwnoutrefresh\fR during the initialization routine. - +.PP \fBripoffline\fR can be called up to five times before calling \fBinitscr\fR or \fBnewterm\fR. - +.PP The \fBcurs_set\fR routine sets the cursor state is set to invisible, normal, or very visible for \fBvisibility\fR equal to \fB0\fR, \fB1\fR, or \fB2\fR respectively. If the terminal supports the \fIvisibility\fR requested, the previous \fIcursor\fR state is returned; otherwise, \fBERR\fR is returned. - +.PP The \fBnapms\fR routine is used to sleep for \fIms\fR milliseconds. .SH RETURN VALUE Except for \fBcurs_set\fR, these routines always return \fBOK\fR. -\fBcurs_set\fR returns the previous cursor state, or \fBERR\fR if the +.PP +\fBcurs_set\fR +returns the previous cursor state, or \fBERR\fR if the requested \fIvisibility\fR is not supported. +.PP +X/Open defines no error conditions. +In this implementation +.RS +.TP 5 +\fBdef_prog_mode\fR, \fBdef_shell_mode\fR, \fBreset_prog_mode\fR, \fBreset_shell_mode\fR +return an error +if the terminal was not initialized, or +if the I/O call to obtain the terminal settings fails. +.TP 5 +\fBripoffline\fP +returns an error if the maximum number of ripped-off lines +exceeds the maximum (NRIPS = 5). +.RE .SH NOTES Note that \fBgetsyx\fR is a macro, so \fB&\fR is not necessary before the variables \fIy\fR and \fIx\fR. - +.PP Older SVr4 man pages warn that the return value of \fBcurs_set\fR "is currently incorrect". This implementation gets it right, but it may be unwise to count on the correctness of the return value anywhere else. - +.PP Both ncurses and SVr4 will call \fBcurs_set\fR in \fBendwin\fR if \fBcurs_set\fR has been called to make the cursor other than normal, i.e., either -visible or very visible. +invisible or very visible. There is no way for ncurses to determine the initial cursor state to restore that. .SH PORTABILITY The functions \fBsetsyx\fR and \fBgetsyx\fR are not described in the XSI Curses standard, Issue 4. All other functions are as described in XSI Curses. - +.PP The SVr4 documentation describes \fBsetsyx\fR and \fBgetsyx\fR as having return type int. This is misleading, as they are macros with no documented semantics for the return value. diff --git a/lib/libcurses/curs_legacy.3 b/lib/libcurses/curs_legacy.3 new file mode 100644 index 00000000000..21ac9e5db77 --- /dev/null +++ b/lib/libcurses/curs_legacy.3 @@ -0,0 +1,95 @@ +.\" $OpenBSD: curs_legacy.3,v 1.1 2010/01/12 23:21:59 nicm Exp $ +.\" +.\"*************************************************************************** +.\" Copyright (c) 2007 Free Software Foundation, Inc. * +.\" * +.\" Permission is hereby granted, free of charge, to any person obtaining a * +.\" copy of this software and associated documentation files (the * +.\" "Software"), to deal in the Software without restriction, including * +.\" without limitation the rights to use, copy, modify, merge, publish, * +.\" distribute, distribute with modifications, sublicense, and/or sell * +.\" copies of the Software, and to permit persons to whom the Software is * +.\" furnished to do so, subject to the following conditions: * +.\" * +.\" The above copyright notice and this permission notice shall be included * +.\" in all copies or substantial portions of the Software. * +.\" * +.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * +.\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * +.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * +.\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * +.\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * +.\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * +.\" THE USE OR OTHER DEALINGS IN THE SOFTWARE. * +.\" * +.\" Except as contained in this notice, the name(s) of the above copyright * +.\" holders shall not be used in advertising or otherwise to promote the * +.\" sale, use or other dealings in this Software without prior written * +.\" authorization. * +.\"*************************************************************************** +.\" +.\" $Id: curs_legacy.3,v 1.1 2010/01/12 23:21:59 nicm Exp $ +.TH curs_legacy 3 "" +.SH NAME +\fBgetbegx\fR, +\fBgetbegy\fR, +\fBgetcurx\fR, +\fBgetcury\fR, +\fBgetmaxx\fR, +\fBgetmaxy\fR, +\fBgetparx\fR, +\fBgetpary\fR - get \fBcurses\fR cursor and window coordinates +.SH SYNOPSIS +\fB#include <curses.h>\fR +.sp +\fBint getbegx(WINDOW *win);\fR +.br +\fBint getbegy(WINDOW *win);\fR +.br +\fBint getcurx(WINDOW *win);\fR +.br +\fBint getcury(WINDOW *win);\fR +.br +\fBint getmaxx(WINDOW *win);\fR +.br +\fBint getmaxy(WINDOW *win);\fR +.br +\fBint getparx(WINDOW *win);\fR +.br +\fBint getpary(WINDOW *win);\fR +.br +.SH DESCRIPTION +The \fBgetbegy\fR and \fBgetbegx\fR functions return the same +data as \fBgetbegyx\fR. +.PP +The \fBgetcury\fR and \fBgetcurx\fR functions return the same +data as \fBgetyx\fR. +.PP +The \fBgetmaxy\fR and \fBgetmaxx\fR functions return the same +data as \fBgetmaxyx\fR. +.PP +The \fBgetpary\fR and \fBgetparx\fR functions return the same +data as \fBgetparyx\fR. +.SH RETURN VALUE +These functions return an integer, +or ERR if the window parameter is null. +.SH NOTES +All of these interfaces are provided as macros and functions. +The macros are suppressed (and only the functions provided) +when \fBNCURSES_OPAQUE\fR is defined. +The standard forms such as \fBgetyx\fP must be implemented as macros, +and (in this implementation) are defined in terms of the functions +described here, +to avoid reliance on internal details of the WINDOW structure. +.SH PORTABILITY +These functions were supported on Version 7, BSD or System V implementations. +.SH SEE ALSO +\fBcurses\fR(3), +\fBcurs_getyx\fR(3), +\fBcurs_opaque\fR(3) +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_mouse.3tbl b/lib/libcurses/curs_mouse.3tbl index 8c06b5aca66..802fd0c8560 100644 --- a/lib/libcurses/curs_mouse.3tbl +++ b/lib/libcurses/curs_mouse.3tbl @@ -1,8 +1,8 @@ '\" t -.\" $OpenBSD: curs_mouse.3tbl,v 1.9 2000/07/10 03:06:08 millert Exp $ +.\" $OpenBSD: curs_mouse.3tbl,v 1.10 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -29,19 +29,23 @@ .\" authorization. * .\"*************************************************************************** .\" -.'" $From: curs_mouse.3x,v 1.15 2000/07/08 12:50:08 tom Exp $ +.\" $Id: curs_mouse.3tbl,v 1.10 2010/01/12 23:21:59 nicm Exp $ .TH curs_mouse 3 "" +.na +.hy 0 .SH NAME \fBgetmouse\fR, \fBungetmouse\fR, \fBmousemask\fR, \fBwenclose\fR, \fBmouse_trafo\fR, \fBwmouse_trafo\fR, \fBmouseinterval\fR - mouse interface through curses +.ad +.hy .SH SYNOPSIS .nf -\fB#include <curses.h>\fR - +\fB#include <curses.h> +.PP \fBtypedef unsigned long mmask_t; - +.PP typedef struct { short id; \fI/* ID to distinguish multiple devices */\fB @@ -57,7 +61,7 @@ MEVENT;\fR .br \fBmmask_t mousemask(mmask_t newmask, mmask_t *oldmask);\fR .br -\fBbool wenclose(WINDOW *win, int y, int x);\fR +\fBbool wenclose(const WINDOW *win, int y, int x);\fR .br \fBbool mouse_trafo(int* pY, int* pX, bool to_screen);\fR .br @@ -69,22 +73,26 @@ MEVENT;\fR .br .SH DESCRIPTION These functions provide an interface to mouse events from -\fBcurses\fR(3). Mouse events are represented by \fBKEY_MOUSE\fR +\fBncurses\fR(3). +Mouse events are represented by \fBKEY_MOUSE\fR pseudo-key values in the \fBwgetch\fR input stream. - -To make mouse events visible, use the \fBmousemask\fR function. This will set -the mouse events to be reported. By default, no mouse events are reported. +.PP +To make mouse events visible, use the \fBmousemask\fR function. +This will set +the mouse events to be reported. +By default, no mouse events are reported. The function will return a mask to indicate which of the specified mouse events -can be reported; on complete failure it returns 0. If oldmask is non-NULL, +can be reported; on complete failure it returns 0. +If oldmask is non-NULL, this function fills the indicated location with the previous value of the given window's mouse event mask. - +.PP As a side effect, setting a zero mousemask may turn off the mouse pointer; -setting a nonzero mask may turn it on. Whether this happens is -device-dependent. - -Here are the mouse event type masks: - +setting a nonzero mask may turn it on. +Whether this happens is device-dependent. +.PP +Here are the mouse event type masks which may be defined: +.PP .TS l l _ _ @@ -95,122 +103,207 @@ BUTTON1_RELEASED mouse button 1 up BUTTON1_CLICKED mouse button 1 clicked BUTTON1_DOUBLE_CLICKED mouse button 1 double clicked BUTTON1_TRIPLE_CLICKED mouse button 1 triple clicked +_ BUTTON2_PRESSED mouse button 2 down BUTTON2_RELEASED mouse button 2 up BUTTON2_CLICKED mouse button 2 clicked BUTTON2_DOUBLE_CLICKED mouse button 2 double clicked BUTTON2_TRIPLE_CLICKED mouse button 2 triple clicked +_ BUTTON3_PRESSED mouse button 3 down BUTTON3_RELEASED mouse button 3 up BUTTON3_CLICKED mouse button 3 clicked BUTTON3_DOUBLE_CLICKED mouse button 3 double clicked BUTTON3_TRIPLE_CLICKED mouse button 3 triple clicked +_ BUTTON4_PRESSED mouse button 4 down BUTTON4_RELEASED mouse button 4 up BUTTON4_CLICKED mouse button 4 clicked BUTTON4_DOUBLE_CLICKED mouse button 4 double clicked BUTTON4_TRIPLE_CLICKED mouse button 4 triple clicked +_ +BUTTON5_PRESSED mouse button 5 down +BUTTON5_RELEASED mouse button 5 up +BUTTON5_CLICKED mouse button 5 clicked +BUTTON5_DOUBLE_CLICKED mouse button 5 double clicked +BUTTON5_TRIPLE_CLICKED mouse button 5 triple clicked +_ BUTTON_SHIFT shift was down during button state change BUTTON_CTRL control was down during button state change BUTTON_ALT alt was down during button state change ALL_MOUSE_EVENTS report all button state changes REPORT_MOUSE_POSITION report mouse movement +_ .TE - +.PP Once a class of mouse events have been made visible in a window, calling the \fBwgetch\fR function on that window may return \fBKEY_MOUSE\fR as an indicator that a mouse event has been queued. To read the event data and pop the event off the queue, call -\fBgetmouse\fR. This function will return \fBOK\fR if a mouse event +\fBgetmouse\fR. +This function will return \fBOK\fR if a mouse event is actually visible in the given window, \fBERR\fR otherwise. When \fBgetmouse\fR returns \fBOK\fR, the data deposited as y and x in the event structure coordinates will be screen-relative character-cell -coordinates. The returned state mask will have exactly one bit set to +coordinates. +The returned state mask will have exactly one bit set to indicate the event type. - -The \fBungetmouse\fR function behaves analogously to \fBungetch\fR. It pushes +.PP +The \fBungetmouse\fR function behaves analogously to \fBungetch\fR. +It pushes a \fBKEY_MOUSE\fR event onto the input queue, and associates with that event the given state data and screen-relative character-cell coordinates. - +.PP The \fBwenclose\fR function tests whether a given pair of screen-relative character-cell coordinates is enclosed by a given window, returning TRUE -if it is and FALSE otherwise. It is useful for determining what subset of +if it is and FALSE otherwise. +It is useful for determining what subset of the screen windows enclose the location of a mouse event. - -The \fBwmouse_trafo\fR function transforms a given pair of coordinates from -stdscr-relative coordinates to screen-relative coordinates or vice versa. +.PP +The \fBwmouse_trafo\fR function transforms a given pair of coordinates +from stdscr-relative coordinates +to coordinates relative to the given window or vice versa. Please remember, that stdscr-relative coordinates are not always identical -to screen-relative coordinates due to the mechanism to reserve lines on top -or bottom of the screen for other purposes (ripoff() call, see also slk_... -functions). If the parameter \fBto_screen\fR is \fBTRUE\fR, the pointers -\fBpY, pX\fR must reference the coordinates of a location inside the window -\fBwin\fR. They are converted to screen-relative coordinates and returned -through the pointers. If the conversion was successful, the function -returns \fBTRUE\fR. If one of the parameters was NULL or the location is -not inside the window, \fBFALSE\fR is returned. If \fBto_screen\fR is -\fBFALSE\fR, the pointers \fBpY, pX\fR must reference screen-relative -coordinates. They are converted to stdscr-relative coordinates if the -window \fBwin\fR encloses this point. In this case the function returns -\fBTRUE\fR. If one of the parameters is NULL or the point is not inside the -window, \fBFALSE\fR is returned. Please notice, that the referenced coordinates +to window-relative coordinates due to the mechanism to reserve lines on top +or bottom of the screen for other purposes +(see the \fBripoffline()\fP and \fBslk_init\fR calls, for example). +If the parameter \fBto_screen\fR is \fBTRUE\fR, the pointers +\fBpY, pX\fR must reference the coordinates of a location +inside the window \fBwin\fR. +They are converted to window-relative coordinates and returned +through the pointers. +If the conversion was successful, the function returns \fBTRUE\fR. +If one of the parameters was NULL or the location is +not inside the window, \fBFALSE\fR is returned. +If \fBto_screen\fR is +\fBFALSE\fR, the pointers \fBpY, pX\fR must reference window-relative +coordinates. +They are converted to stdscr-relative coordinates if the +window \fBwin\fR encloses this point. +In this case the function returns \fBTRUE\fR. +If one of the parameters is NULL or the point is not inside the +window, \fBFALSE\fR is returned. +Please notice, that the referenced coordinates are only replaced by the converted coordinates if the transformation was successful. - +.PP +The \fBmouse_trafo\fR function performs the same translation +as \fBwmouse_trafo\fR, +using stdscr for \fBwin\fR. +.PP The \fBmouseinterval\fR function sets the maximum time (in thousands of a -second) that can elapse between press and release events in order for them to -be recognized as a click. This function returns the previous interval value. -The default is one fifth of a second. - +second) that can elapse between press and release events for them to +be recognized as a click. +Use \fBmouseinterval(0)\fR to disable click resolution. +This function returns the previous interval value. +Use \fBmouseinterval(-1)\fR to obtain the interval without altering it. +The default is one sixth of a second. +.PP Note that mouse events will be ignored when input is in cooked mode, and will cause an error beep when cooked mode is being simulated in a window by a function such as \fBgetstr\fR that expects a linefeed for input-loop termination. - .SH RETURN VALUE -\fBgetmouse\fR, \fBungetmouse\fR and \fBmouseinterval\fR +\fBgetmouse\fR and \fBungetmouse\fR return the integer \fBERR\fR upon failure or \fBOK\fR -upon successful completion. \fBmousemask\fR returns the -mask of reportable events. \fBwenclose\fR and \fBwmouse_trafo\fR +upon successful completion. +.RS +.TP 5 +\fBgetmouse\fP +returns an error. +If no mouse driver was initialized, or +if the mask parameter is zero, +.TP 5 +\fBungetmouse\fP +returns an error if the FIFO is full. +.RE +.PP +\fBmousemask\fR +returns the mask of reportable events. +.PP +\fBmouseinterval\fR +returns the previous interval value, unless +the terminal was not initialized. +In that case, it returns the maximum interval value (166). +.PP +\fBwenclose\fR and \fBwmouse_trafo\fR are boolean functions returning \fBTRUE\fR or \fBFALSE\fR depending on their test result. .SH PORTABILITY -These calls were designed for \fBncurses\fR, and are not found in SVr4 +These calls were designed for \fBncurses\fR(3), and are not found in SVr4 curses, 4.4BSD curses, or any other previous version of curses. - +.PP The feature macro \fBNCURSES_MOUSE_VERSION\fR is provided so the preprocessor -can be used to test whether these features are present (its value is 1). +can be used to test whether these features are present. If the interface is changed, the value of \fBNCURSES_MOUSE_VERSION\fR will be incremented. - +These values for \fBNCURSES_MOUSE_VERSION\fR may be +specified when configuring ncurses: +.RS +.TP 3 +1 +has definitions for reserved events. +The mask uses 28 bits. +.TP 3 +2 +adds definitions for button 5, +removes the definitions for reserved events. +The mask uses 29 bits. +.RE +.PP The order of the \fBMEVENT\fR structure members is not guaranteed. Additional fields may be added to the structure in the future. - -Under \fBncurses\fR, these calls are implemented using either -xterm's built-in mouse-tracking API or Alessandro Rubini's gpm server. -If you are using something other than xterm and there is no gpm daemon -running on your machine, mouse events will not be visible to -\fBcurses\fR(3) (and the \fBwmousemask\fR function will always +.PP +Under \fBncurses\fR(3), these calls are implemented using either +xterm's built-in mouse-tracking API or +platform-specific drivers including +.RS +Alessandro Rubini's gpm server. +.br +FreeBSD sysmouse +.br +OS/2 EMX +.RE +If you are using an unsupported configuration, +mouse events will not be visible to +\fBncurses\fR(3) (and the \fBmousemask\fR function will always return \fB0\fR). - -The z member in the event structure is not presently used. It is intended +.PP +If the terminfo entry contains a \fBXM\fR string, +this is used in the xterm mouse driver to control the +way the terminal is initialized for mouse operation. +The default, if \fBXM\fR is not found, +corresponds to private mode 1000 of xterm: +.RS +\\E[?1000%?%p1%{1}%=%th%el%; +.RE +The z member in the event structure is not presently used. +It is intended for use with touch screens (which may be pressure-sensitive) or with 3D-mice/trackballs/power gloves. .SH BUGS Mouse events under xterm will not in fact be ignored during cooked mode, -if they have been enabled by \fBwmousemask\fR. Instead, the xterm mouse +if they have been enabled by \fBmousemask\fR. +Instead, the xterm mouse report sequence will appear in the string read. - +.PP Mouse events under xterm will not be detected correctly in a window with its keypad bit off, since they are interpreted as a variety of function key. -Your terminfo description must have \fBkmous\fR set to "\\E[M" (the beginning -of the response from xterm for mouse clicks). - +Your terminfo description should have \fBkmous\fR set to "\\E[M" +(the beginning of the response from xterm for mouse clicks). +Other values for \fBkmous\fR are permitted, +but under the same assumption, +i.e., it is the beginning of the response. +.PP Because there are no standard terminal responses that would serve to identify terminals which support the xterm mouse protocol, \fBncurses\fR assumes that -if your $DISPLAY environment variable is set, and \fBkmous\fR is defined in +if your $TERM environment variable contains "xterm", +or \fBkmous\fR is defined in the terminal description, then the terminal may send mouse events. .SH SEE ALSO -\fBcurses\fR(3). +\fBcurses\fR(3), +\fBcurs_kernel\fR(3), +\fBcurs_slk\fR(3). .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_move.3 b/lib/libcurses/curs_move.3 index 271c1f7a7a1..9244f61405f 100644 --- a/lib/libcurses/curs_move.3 +++ b/lib/libcurses/curs_move.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_move.3,v 1.5 1998/09/13 19:16:20 millert Exp $ +.\" $OpenBSD: curs_move.3,v 1.6 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,13 +28,18 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_move.3x,v 1.6 1998/03/11 21:12:53 juergen Exp $ +.\" $Id: curs_move.3,v 1.6 2010/01/12 23:21:59 nicm Exp $ .TH curs_move 3 "" +.na +.hy 0 .SH NAME -\fBmove\fR, \fBwmove\fR - move \fBcurses\fR window cursor +\fBmove\fR, +\fBwmove\fR - move \fBcurses\fR window cursor +.ad +.hy .SH SYNOPSIS \fB#include <curses.h>\fR - +.sp \fBint move(int y, int x);\fR .br \fBint wmove(WINDOW *win, int y, int x);\fR @@ -48,13 +53,14 @@ left-hand corner of the window, which is (0,0). These routines return \fBERR\fR upon failure and OK (SVr4 specifies only "an integer value other than \fBERR\fR") upon successful completion. +.PP +Specifically, they return an error +if the window pointer is null, or +if the position is outside the window. .SH NOTES Note that \fBmove\fR may be a macro. .SH PORTABILITY -These functions are described in the XSI Curses standard, Issue 4. The -standard specifies that if (y,x) is within a multi-column character, the cursor -is moved to the first column of that character; however, this implementation -does not yet support the extended-level XSI multi-byte characters. +These functions are described in the XSI Curses standard, Issue 4. .SH SEE ALSO \fBcurses\fR(3), \fBcurs_refresh\fR(3) .\"# diff --git a/lib/libcurses/curs_opaque.3 b/lib/libcurses/curs_opaque.3 new file mode 100644 index 00000000000..5985f01d03c --- /dev/null +++ b/lib/libcurses/curs_opaque.3 @@ -0,0 +1,135 @@ +.\" $OpenBSD: curs_opaque.3,v 1.1 2010/01/12 23:21:59 nicm Exp $ +.\" +.\"*************************************************************************** +.\" Copyright (c) 2007 Free Software Foundation, Inc. * +.\" * +.\" Permission is hereby granted, free of charge, to any person obtaining a * +.\" copy of this software and associated documentation files (the * +.\" "Software"), to deal in the Software without restriction, including * +.\" without limitation the rights to use, copy, modify, merge, publish, * +.\" distribute, distribute with modifications, sublicense, and/or sell * +.\" copies of the Software, and to permit persons to whom the Software is * +.\" furnished to do so, subject to the following conditions: * +.\" * +.\" The above copyright notice and this permission notice shall be included * +.\" in all copies or substantial portions of the Software. * +.\" * +.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * +.\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * +.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * +.\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * +.\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * +.\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * +.\" THE USE OR OTHER DEALINGS IN THE SOFTWARE. * +.\" * +.\" Except as contained in this notice, the name(s) of the above copyright * +.\" holders shall not be used in advertising or otherwise to promote the * +.\" sale, use or other dealings in this Software without prior written * +.\" authorization. * +.\"*************************************************************************** +.\" +.\" $Id: curs_opaque.3,v 1.1 2010/01/12 23:21:59 nicm Exp $ +.TH curs_opaque 3 "" +.na +.hy 0 +.SH NAME +\fBis_cleared\fR, +\fBis_idlok\fR, +\fBis_idcok\fR, +\fBis_immedok\fR, +\fBis_keypad\fR, +\fBis_leaveok\fR, +\fBis_nodelay\fR, +\fBis_timeout\fR, +\fBis_scrollok\fR, +\fBis_syncok\fR - \fBcurses\fR window properties +.ad +.hy +.SH SYNOPSIS +\fB#include <curses.h>\fR +.sp +\fBbool is_cleared(const WINDOW *win);\fR +.br +\fBbool is_idcok(const WINDOW *win);\fR +.br +\fBbool is_idlok(const WINDOW *win);\fR +.br +\fBbool is_immedok(const WINDOW *win);\fR +.br +\fBbool is_keypad(const WINDOW *win);\fR +.br +\fBbool is_leaveok(const WINDOW *win);\fR +.br +\fBbool is_nodelay(const WINDOW *win);\fR +.br +\fBbool is_notimeout(const WINDOW *win);\fR +.br +\fBbool is_scrollok(const WINDOW *win);\fR +.br +\fBbool is_syncok(const WINDOW *win);\fR +.br +\fBWINDOW * wgetparent(const WINDOW *win);\fR +.br +\fBint wgetscrreg(const WINDOW *win, int *top, int *bottom);\fR +.br +.SH DESCRIPTION +This implementation provides functions which return properties +set in the WINDOW structure, allowing it to be ``opaque'' if +the symbol \fBNCURSES_OPAQUE\fR is defined: +.TP 5 +\fBis_cleared\fR +returns the value set in \fBclearok\fR +.TP 5 +\fBis_idcok\fR +returns the value set in \fBidcok\fR +.TP 5 +\fBis_idlok\fR +returns the value set in \fBidlok\fR +.TP 5 +\fBis_immedok\fR +returns the value set in \fBimmedok\fR +.TP 5 +\fBis_keypad\fR +returns the value set in \fBkeypad\fR +.TP 5 +\fBis_leaveok\fR +returns the value set in \fBleaveok\fR +.TP 5 +\fBis_nodelay\fR +returns the value set in \fBnodelay\fR +.TP 5 +\fBis_notimeout\fR +returns the value set in \fBnotimeout\fR +.TP 5 +\fBis_scrollok\fR +returns the value set in \fBscrollok\fR +.TP 5 +\fBis_syncok\fR +returns the value set in \fBsyncok\fR +.TP 5 +\fBwgetparent\fR +returns the parent WINDOW pointer for subwindows, +or NULL for windows having no parent. +.TP 5 +\fBwgetscrreg\fR +returns the top and bottom rows for the scrolling margin as set in \fBwsetscrreg\fP. +.SH RETURN VALUE +These functions all return TRUE or FALSE, except as noted. +.SH NOTES +Both a macro and a function are provided for each name. +.SH PORTABILITY +These routines are specific to ncurses. +They were not supported on Version 7, BSD or System V implementations. +It is recommended that any code depending on ncurses extensions +be conditioned using NCURSES_VERSION. +.SH SEE ALSO +\fBcurses\fR(3), +\fBcurs_inopts\fR(3), +\fBcurs_outopts\fR(3), +\fBcurs_window\fR(3) +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_outopts.3 b/lib/libcurses/curs_outopts.3 index f4067e387f9..302b40891a2 100644 --- a/lib/libcurses/curs_outopts.3 +++ b/lib/libcurses/curs_outopts.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_outopts.3,v 1.11 2003/05/12 11:06:49 jmc Exp $ +.\" $OpenBSD: curs_outopts.3,v 1.12 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2005,2007 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,15 +28,26 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_outopts.3x,v 1.14 2000/02/27 01:41:58 tom Exp $ +.\" $Id: curs_outopts.3,v 1.12 2010/01/12 23:21:59 nicm Exp $ .TH curs_outopts 3 "" +.na +.hy 0 .SH NAME -\fBclearok\fR, \fBidlok\fR, \fBidcok\fR, \fBimmedok\fR, -\fBleaveok\fR, \fBsetscrreg\fR, \fBwsetscrreg\fR, \fBscrollok\fR, -\fBnl\fR, \fBnonl\fR - \fBcurses\fR output options +\fBclearok\fR, +\fBidlok\fR, +\fBidcok\fR, +\fBimmedok\fR, +\fBleaveok\fR, +\fBsetscrreg\fR, +\fBwsetscrreg\fR, +\fBscrollok\fR, +\fBnl\fR, +\fBnonl\fR - \fBcurses\fR output options +.ad +.hy .SH SYNOPSIS \fB#include <curses.h>\fR - +.sp \fBint clearok(WINDOW *win, bool bf);\fR .br \fBint idlok(WINDOW *win, bool bf);\fR @@ -59,97 +70,139 @@ .br .SH DESCRIPTION These routines set options that change the style of output within -\fBcurses\fR. All options are initially \fBFALSE\fR, unless otherwise stated. +\fBcurses\fR. +All options are initially \fBFALSE\fR, unless otherwise stated. It is not necessary to turn these options off before calling \fBendwin\fR. - +.PP If \fBclearok\fR is called with \fBTRUE\fR as argument, the next call to \fBwrefresh\fR with this window will clear the screen completely and -redraw the entire screen from scratch. This is useful when the contents of the -screen are uncertain, or in some cases for a more pleasing visual effect. If +redraw the entire screen from scratch. +This is useful when the contents of the +screen are uncertain, or in some cases for a more pleasing visual effect. +If the \fIwin\fR argument to \fBclearok\fR is the global variable \fBcurscr\fR, the next call to \fBwrefresh\fR with any window causes the screen to be cleared and repainted from scratch. - +.PP If \fBidlok\fR is called with \fBTRUE\fR as second argument, \fBcurses\fR considers using the hardware insert/delete line feature of terminals so -equipped. Calling \fBidlok\fR with \fBFALSE\fR as second argument disables use -of line insertion and deletion. This option should be enabled only if the -application needs insert/delete line, for example, for a screen editor. It is +equipped. +Calling \fBidlok\fR with \fBFALSE\fR as second argument disables use +of line insertion and deletion. +This option should be enabled only if the +application needs insert/delete line, for example, for a screen editor. +It is disabled by default because insert/delete line tends to be visually annoying -when used in applications where it isn't really needed. If insert/delete line +when used in applications where it is not really needed. +If insert/delete line cannot be used, \fBcurses\fR redraws the changed portions of all lines. - +.PP If \fBidcok\fR is called with \fBFALSE\fR as second argument, \fBcurses\fR no longer considers using the hardware insert/delete character feature of -terminals so equipped. Use of character insert/delete is enabled by default. +terminals so equipped. +Use of character insert/delete is enabled by default. Calling \fBidcok\fR with \fBTRUE\fR as second argument re-enables use of character insertion and deletion. - -If \fBimmedok\fR is called with \fBTRUE\fR as argument, any change +.PP +If \fBimmedok\fR is called with \fBTRUE as argument\fR, any change in the window image, such as the ones caused by \fBwaddch, wclrtobot, wscrl\fR, -etc., automatically cause a call to \fBwrefresh\fR. However, it may +etc., automatically cause a call to \fBwrefresh\fR. +However, it may degrade performance considerably, due to repeated calls to \fBwrefresh\fR. It is disabled by default. - +.PP Normally, the hardware cursor is left at the location of the window cursor -being refreshed. The \fBleaveok\fR option allows the cursor to be left -wherever the update happens to leave it. It is useful for applications where -the cursor is not used, since it reduces the need for cursor motions. If -possible, the cursor is made invisible when this option is enabled. - +being refreshed. +The \fBleaveok\fR option allows the cursor to be left +wherever the update happens to leave it. +It is useful for applications where +the cursor is not used, since it reduces the need for cursor motions. +.PP The \fBsetscrreg\fR and \fBwsetscrreg\fR routines allow the application -programmer to set a software scrolling region in a window. \fItop\fR and +programmer to set a software scrolling region in a window. +\fItop\fR and \fIbot\fR are the line numbers of the top and bottom margin of the scrolling -region. (Line 0 is the top line of the window.) If this option and +region. +(Line 0 is the top line of the window.) If this option and \fBscrollok\fR are enabled, an attempt to move off the bottom margin line causes all lines in the scrolling region to scroll one line in the direction -of the first line. Only the text of the window is scrolled. (Note that this +of the first line. +Only the text of the window is scrolled. +(Note that this has nothing to do with the use of a physical scrolling region capability in the -terminal, like that in the VT100. If \fBidlok\fR is enabled and the terminal +terminal, like that in the VT100. +If \fBidlok\fR is enabled and the terminal has either a scrolling region or insert/delete line capability, they will probably be used by the output routines.) - +.PP The \fBscrollok\fR option controls what happens when the cursor of a window is moved off the edge of the window or scrolling region, either as a result of a newline action on the bottom line, or typing the last character of the last -line. If disabled, (\fIbf\fR is \fBFALSE\fR), the cursor is left on the bottom -line. If enabled, (\fIbf\fR is \fBTRUE\fR), the window is scrolled up one line -(Note that in order to get the physical scrolling effect on the terminal, it is +line. +If disabled, (\fIbf\fR is \fBFALSE\fR), the cursor is left on the bottom +line. +If enabled, (\fIbf\fR is \fBTRUE\fR), the window is scrolled up one line +(Note that to get the physical scrolling effect on the terminal, it is also necessary to call \fBidlok\fR). - +.PP The \fBnl\fR and \fBnonl\fR routines control whether the underlying display device translates the return key into newline on input, and whether it translates newline into return and line-feed on output (in either case, the call \fBaddch('\\n')\fR does the equivalent of return and line feed on the -virtual screen). Initially, these translations do occur. If you disable them +virtual screen). +Initially, these translations do occur. +If you disable them using \fBnonl\fR, \fBcurses\fR will be able to make better use of the line-feed -capability, resulting in faster cursor motion. Also, \fBcurses\fR will then be +capability, resulting in faster cursor motion. +Also, \fBcurses\fR will then be able to detect the return key. .SH RETURN VALUE The functions \fBsetscrreg\fR and \fBwsetscrreg\fR return \fBOK\fR upon success -and \fBERR\fR upon failure. All other routines that return an integer always +and \fBERR\fR upon failure. +All other routines that return an integer always return \fBOK\fR. +.PP +X/Open does not define any error conditions. +.PP +In this implementation, those functions that have a window pointer +will return an error if the window pointer is null. +.RS +.TP 5 +.B wclrtoeol +returns an error +if the cursor position is about to wrap. +.TP 5 +.B wsetscrreg +returns an error if the scrolling region limits extend outside the window. +.RE +.PP +X/Open does not define any error conditions. +This implementation returns an error +if the window pointer is null. .SH PORTABILITY These functions are described in the XSI Curses standard, Issue 4. - +.PP The XSI Curses standard is ambiguous on the question of whether \fBraw\fR() should disable the CRLF translations controlled by \fBnl\fR() and \fBnonl\fR(). BSD curses did turn off these translations; AT&T curses (at least as late as -SVr1) did not. We choose to do so, on the theory that a programmer requesting +SVr1) did not. +We choose to do so, on the theory that a programmer requesting raw input wants a clean (ideally 8-bit clean) connection that the operating -system does not mess with. - +system will not alter. +.PP Some historic curses implementations had, as an undocumented feature, the ability to do the equivalent of \fBclearok(..., 1)\fR by saying -\fBtouchwin(stdscr)\fR or \fBclear(stdscr)\fR. This will not work under +\fBtouchwin(stdscr)\fR or \fBclear(stdscr)\fR. +This will not work under ncurses. - +.PP Earlier System V curses implementations specified that with \fBscrollok\fR enabled, any window modification triggering a scroll also forced a physical -refresh. XSI Curses does not require this, and \fBncurses\fR avoids doing -it in order to perform better vertical-motion optimization at \fBwrefresh\fR +refresh. +XSI Curses does not require this, and \fBncurses\fR avoids doing +it to perform better vertical-motion optimization at \fBwrefresh\fR time. - +.PP The XSI Curses standard does not mention that the cursor should be made invisible as a side-effect of \fBleaveok\fR. SVr4 curses documentation does this, but the code does not. @@ -157,7 +210,7 @@ Use \fBcurs_set\fR to make the cursor invisible. .SH NOTES Note that \fBclearok\fR, \fBleaveok\fR, \fBscrollok\fR, \fBidcok\fR, \fBnl\fR, \fBnonl\fR and \fBsetscrreg\fR may be macros. - +.PP The \fBimmedok\fR routine is useful for windows that are used as terminal emulators. .SH SEE ALSO diff --git a/lib/libcurses/curs_overlay.3 b/lib/libcurses/curs_overlay.3 index 4a3a31627b2..1c82f91bc93 100644 --- a/lib/libcurses/curs_overlay.3 +++ b/lib/libcurses/curs_overlay.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_overlay.3,v 1.7 2000/07/10 03:06:08 millert Exp $ +.\" $OpenBSD: curs_overlay.3,v 1.8 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998,2000 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,20 +28,24 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_overlay.3x,v 1.9 2000/07/01 20:05:31 tom Exp $ +.\" $Id: curs_overlay.3,v 1.8 2010/01/12 23:21:59 nicm Exp $ .TH curs_overlay 3 "" +.na +.hy 0 .SH NAME \fBoverlay\fR, \fBoverwrite\fR, \fBcopywin\fR - overlay and manipulate overlapped \fBcurses\fR windows +.ad +.hy .SH SYNOPSIS \fB#include <curses.h>\fR - +.sp \fBint overlay(const WINDOW *srcwin, WINDOW *dstwin);\fR .br \fBint overwrite(const WINDOW *srcwin, WINDOW *dstwin);\fR .br -\fBint copywin(WINDOW *srcwin, WINDOW *dstwin, int sminrow,\fR +\fBint copywin(const WINDOW *srcwin, WINDOW *dstwin, int sminrow,\fR \fBint smincol, int dminrow, int dmincol, int dmaxrow,\fR \fBint dmaxcol, int overlay);\fR .SH DESCRIPTION @@ -50,7 +54,7 @@ top of \fIdstwin\fR. \fIscrwin\fR and \fIdstwin\fR are not required to be the same size; only text where the two windows overlap is copied. The difference is that \fBoverlay\fR is non-destructive (blanks are not copied) whereas \fBoverwrite\fR is destructive. - +.PP The \fBcopywin\fR routine provides a finer granularity of control over the \fBoverlay\fR and \fBoverwrite\fR routines. Like in the \fBprefresh\fR routine, a rectangle is specified in the destination window, (\fIdminrow\fR, @@ -62,12 +66,19 @@ argument \fIoverlay\fR is \fBtrue\fR, then copying is non-destructive, as in Routines that return an integer return \fBERR\fR upon failure, and \fBOK\fR (SVr4 only specifies "an integer value other than \fBERR\fR") upon successful completion. +.PP +X/Open defines no error conditions. +In this implementation, +\fBcopywin\fP, +\fBoverlay\fP and \fBoverwrite\fP return an error +if either of the window pointers are null, or +if some part of the window would be placed off-screen. .SH NOTES Note that \fBoverlay\fR and \fBoverwrite\fR may be macros. .SH PORTABILITY The XSI Curses standard, Issue 4 describes these functions (adding the const qualifiers). It further specifies their behavior in the presence of characters -with multi-byte renditions (not yet supported in this implementation). +with multibyte renditions (not yet supported in this implementation). .SH SEE ALSO \fBcurses\fR(3), \fBcurs_pad\fR(3), \fBcurs_refresh\fR(3) .\"# diff --git a/lib/libcurses/curs_pad.3 b/lib/libcurses/curs_pad.3 index 9544c759a33..8562f93d035 100644 --- a/lib/libcurses/curs_pad.3 +++ b/lib/libcurses/curs_pad.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_pad.3,v 1.8 2003/05/14 08:55:19 jmc Exp $ +.\" $OpenBSD: curs_pad.3,v 1.9 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998,2000 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2004,2005 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,14 +28,22 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_pad.3x,v 1.9 2000/07/04 22:38:13 tom Exp $ +.\" $Id: curs_pad.3,v 1.9 2010/01/12 23:21:59 nicm Exp $ .TH curs_pad 3 "" +.na +.hy 0 .SH NAME -\fBnewpad\fR, \fBsubpad\fR, \fBprefresh\fR, -\fBpnoutrefresh\fR, \fBpechochar\fR - create and display \fBcurses\fR pads +\fBnewpad\fR, +\fBsubpad\fR, +\fBprefresh\fR, +\fBpnoutrefresh\fR, +\fBpechochar\fR, +\fBpecho_wchar\fR - create and display \fBcurses\fR pads +.ad +.hy .SH SYNOPSIS \fB#include <curses.h>\fR - +.sp \fBWINDOW *newpad(int nlines, int ncols);\fR .br \fBWINDOW *subpad(WINDOW *orig, int nlines, int ncols,\fR @@ -48,56 +56,100 @@ \fBint sminrow, int smincol, int smaxrow, int smaxcol);\fR .br \fBint pechochar(WINDOW *pad, chtype ch);\fR +.br +\fBint pecho_wchar(WINDOW *pad, const cchar_t *wch);\fR .SH DESCRIPTION The \fBnewpad\fR routine creates and returns a pointer to a new pad data structure with the given number of lines, \fInlines\fR, and columns, -\fIncols\fR. A pad is like a window, except that it is not restricted by the +\fIncols\fR. +A pad is like a window, except that it is not restricted by the screen size, and is not necessarily associated with a particular part of the -screen. Pads can be used when a large window is needed, and only a part of the -window will be on the screen at one time. Automatic refreshes of pads -(e.g., from scrolling or echoing of input) do not occur. It is not +screen. +Pads can be used when a large window is needed, and only a part of the +window will be on the screen at one time. +Automatic refreshes of pads +(e.g., from scrolling or echoing of input) do not occur. +It is not legal to call \fBwrefresh\fR with a \fIpad\fR as an argument; the routines -\fBprefresh\fR or \fBpnoutrefresh\fR should be called instead. Note that these +\fBprefresh\fR or \fBpnoutrefresh\fR should be called instead. +Note that these routines require additional parameters to specify the part of the pad to be displayed and the location on the screen to be used for the display. - +.PP The \fBsubpad\fR routine creates and returns a pointer to a subwindow within a pad with the given number of lines, \fInlines\fR, and columns, \fIncols\fR. Unlike \fBsubwin\fR, which uses screen coordinates, the window is at position -(\fIbegin\fR_\fIx\fR\fB,\fR \fIbegin\fR_\fIy\fR) on the pad. The window is +(\fIbegin\fR_\fIx\fR\fB,\fR \fIbegin\fR_\fIy\fR) on the pad. +The window is made in the middle of the window \fIorig\fR, so that changes made to one window -affect both windows. During the use of this routine, it will often be +affect both windows. +During the use of this routine, it will often be necessary to call \fBtouchwin\fR or \fBtouchline\fR on \fIorig\fR before calling \fBprefresh\fR. - +.PP The \fBprefresh\fR and \fBpnoutrefresh\fR routines are analogous to \fBwrefresh\fR and \fBwnoutrefresh\fR except that they relate to pads instead -of windows. The additional parameters are needed to indicate what part of the -pad and screen are involved. \fIpminrow\fR and \fIpmincol\fR specify the upper -left-hand corner of the rectangle to be displayed in the pad. \fIsminrow\fR, +of windows. +The additional parameters are needed to indicate what part of the +pad and screen are involved. +\fIpminrow\fR and \fIpmincol\fR specify the upper +left-hand corner of the rectangle to be displayed in the pad. +\fIsminrow\fR, \fIsmincol\fR, \fIsmaxrow\fR, and \fIsmaxcol\fR specify the edges of the -rectangle to be displayed on the screen. The lower right-hand corner of the +rectangle to be displayed on the screen. +The lower right-hand corner of the rectangle to be displayed in the pad is calculated from the screen coordinates, -since the rectangles must be the same size. Both rectangles must be entirely -contained within their respective structures. Negative values of +since the rectangles must be the same size. +Both rectangles must be entirely +contained within their respective structures. +Negative values of \fIpminrow\fR, \fIpmincol\fR, \fIsminrow\fR, or \fIsmincol\fR are treated as if they were zero. - +.PP The \fBpechochar\fR routine is functionally equivalent to a call to \fBaddch\fR followed by a call to \fBrefresh\fR, a call to \fBwaddch\fR followed by a call to \fBwrefresh\fR, or a call to \fBwaddch\fR followed by a call to -\fBprefresh\fR. The knowledge that only a single character is being output is +\fBprefresh\fR. +The knowledge that only a single character is being output is taken into consideration and, for non-control characters, a considerable performance gain might be seen by using these routines instead of their -equivalents. In the case of \fBpechochar\fR, the last location of the pad on +equivalents. +In the case of \fBpechochar\fR, the last location of the pad on the screen is reused for the arguments to \fBprefresh\fR. +.PP +The \fBpecho_wchar\fR function is the analogous wide-character +form of \fBpechochar\fR. +It outputs one character to a pad and immediately refreshes the pad. +It does this by a call to \fBwadd_wch\fR followed by a call to \fBprefresh\fR. .SH RETURN VALUE Routines that return an integer return \fBERR\fR upon failure and \fBOK\fR (SVr4 only specifies "an integer value other than \fBERR\fR") upon successful completion. - +.PP Routines that return pointers return \fBNULL\fR on error, and set \fBerrno\fR to \fBENOMEM\fR. +.PP +X/Open does not define any error conditions. +In this implementation +.RS +.TP 5 +\fBprefresh\fP and \fBpnoutrefresh\fP +return an error +if the window pointer is null, or +if the window is not really a pad or +if the area to refresh extends off-screen or +if the minimum coordinates are greater than the maximum. +.TP 5 +\fBpechochar\fP +returns an error +if the window is not really a pad, and the associated call +to \fBwechochar\fP returns an error. +.TP 5 +\fBpecho_wchar\fP +returns an error +if the window is not really a pad, and the associated call +to \fBwecho_wchar\fP returns an error. +.RE .SH NOTES Note that \fBpechochar\fR may be a macro. .SH PORTABILITY diff --git a/lib/libcurses/curs_print.3 b/lib/libcurses/curs_print.3 index b598ef04575..ad2c33f5fbc 100644 --- a/lib/libcurses/curs_print.3 +++ b/lib/libcurses/curs_print.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_print.3,v 1.8 2003/05/14 08:55:19 jmc Exp $ +.\" $OpenBSD: curs_print.3,v 1.9 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,40 +28,40 @@ .\" authorization. * .\"*************************************************************************** .\" -.'" $From: curs_print.3x,v 1.3 1998/03/11 21:12:53 juergen Exp $ +.\" $Id: curs_print.3,v 1.9 2010/01/12 23:21:59 nicm Exp $ .TH curs_print 3 "" .SH NAME \fBmcprint\fR - ship binary data to printer .SH SYNOPSIS \fB#include <curses.h>\fR - +.sp \fBint mcprint(char *data, int len);\fR .SH DESCRIPTION This function uses the \fBmc5p\fR or \fBmc4\fR and \fBmc5\fR capabilities, if they are present, to ship given data to a printer attached to the terminal. - +.PP Note that the \fBmcprint\fR code has no way to do flow control with the printer or to know how much buffering it has. Your application is responsible for keeping the rate of writes to the printer below its continuous throughput rate (typically about half of its nominal cps rating). Dot-matrix printers and 6-page-per-minute lasers can typically handle 80cps, so a good conservative rule of thumb is to sleep for a second after shipping each 80-character line. - +. .SH RETURN VALUE The \fBmcprint\fR function returns \fBERR\fR if the write operation aborted for some reason. In this case, errno will contain either an error associated with \fBwrite(2)\fR or one of the following: .TP 5 ENODEV -Capabilities for printer redirection don't exist. +Capabilities for printer redirection do not exist. .TP 5 ENOMEM Couldn't allocate sufficient memory to buffer the printer write. - +.PP When \fBmcprint\fR succeeds, it returns the number of characters actually sent to the printer. .SH PORTABILITY -The \fBmcprint\fR call was designed for \fBncurses\fR, and is not found +The \fBmcprint\fR call was designed for \fBncurses\fR(3), and is not found in SVr4 curses, 4.4BSD curses, or any other previous version of curses. .SH BUGS Padding in the \fBmc5p\fR, \fBmc4\fR and \fBmc5\fR capabilities will not be diff --git a/lib/libcurses/curs_printw.3 b/lib/libcurses/curs_printw.3 index 1b1fefc2644..02333f945aa 100644 --- a/lib/libcurses/curs_printw.3 +++ b/lib/libcurses/curs_printw.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_printw.3,v 1.10 2001/07/27 05:32:05 millert Exp $ +.\" $OpenBSD: curs_printw.3,v 1.11 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998,2000 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,50 +28,64 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_printw.3x,v 1.11 2000/07/01 20:11:32 tom Exp $ +.\" $Id: curs_printw.3,v 1.11 2010/01/12 23:21:59 nicm Exp $ .TH curs_printw 3 "" +.na +.hy 0 .SH NAME \fBprintw\fR, \fBwprintw\fR, \fBmvprintw\fR, \fBmvwprintw\fR, \fBvwprintw\fR, \fBvw_printw\fR - print formatted output in \fBcurses\fR windows +.ad +.hy .SH SYNOPSIS \fB#include <curses.h>\fR - -\fBint printw(char *fmt\fR [\fB, arg\fR] \fB...);\fR +.sp +\fBint printw(const char *fmt, ...);\fR .br -\fBint wprintw(WINDOW *win, char *fmt\fR [\fB, arg\fR] \fB...);\fR +\fBint wprintw(WINDOW *win, const char *fmt, ...);\fR .br -\fBint mvprintw(int y, int x, char *fmt\fR [\fB, arg\fR] \fB...);\fR +\fBint mvprintw(int y, int x, const char *fmt, ...);\fR .br -\fBint mvwprintw(WINDOW *win, int y, int x,\fR - \fBchar *fmt\fR [\fB, arg]\fR ...); - -\fB#include <stdarg.h>\fR +\fBint mvwprintw(WINDOW *win, int y, int x, const char *fmt, ...);\fR .br -\fBint vwprintw(WINDOW *win, char *fmt, varglist);\fR +\fBint vwprintw(WINDOW *win, const char *fmt, va_list varglist);\fR .br -\fBint vw_printw(WINDOW *win, char *fmt, varglist);\fR +\fBint vw_printw(WINDOW *win, const char *fmt, va_list varglist);\fR .br .SH DESCRIPTION The \fBprintw\fR, \fBwprintw\fR, \fBmvprintw\fR and \fBmvwprintw\fR routines are analogous to \fBprintf\fR [see \fBprintf\fR(3)]. In effect, the string that would be output by \fBprintf\fR is output instead as though \fBwaddstr\fR were used on the given window. - -The \fBvwprintw\fR routine is analogous to \fBvprintf\fR [see -\fBprintf\fR(3)] and performs a \fBwprintw\fR using a variable -argument list. The third argument is a \fBva_list\fR, a pointer to a +.PP +The \fBvwprintw\fR and \fBwv_printw\fR routines are analogous +to \fBvprintf\fR [see \fBprintf\fR(3)] +and perform a \fBwprintw\fR using a variable argument list. +The third argument is a \fBva_list\fR, a pointer to a list of arguments, as defined in \fB<stdarg.h>\fR. .SH RETURN VALUE Routines that return an integer return \fBERR\fR upon failure and \fBOK\fR (SVr4 only specifies "an integer value other than \fBERR\fR") upon successful completion. +.PP +X/Open defines no error conditions. +In this implementation, +an error may be returned if it cannot allocate enough memory for the +buffer used to format the results. +It will return an error if the window pointer is null. .SH PORTABILITY The XSI Curses standard, Issue 4 describes these functions. The function \fBvwprintw\fR is marked TO BE WITHDRAWN, and is to be replaced by a function \fBvw_printw\fR using the \fB<stdarg.h>\fR interface. +The Single Unix Specification, Version 2 states that +\fBvw_printw\fR is preferred to \fBvwprintw\fR since the latter requires +including \fB<varargs.h>\fR, which +cannot be used in the same file as \fB<stdarg.h>\fR. +This implementation uses \fB<stdarg.h>\fR for both, because that header +is included in \fB<curses.h\fR>. .SH SEE ALSO \fBcurses\fR(3), \fBprintf\fR(3), \fBvprintf(3)\fR .\"# diff --git a/lib/libcurses/curs_refresh.3 b/lib/libcurses/curs_refresh.3 index 3968930ce13..b9c53bd85a4 100644 --- a/lib/libcurses/curs_refresh.3 +++ b/lib/libcurses/curs_refresh.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_refresh.3,v 1.6 2000/07/10 03:06:08 millert Exp $ +.\" $OpenBSD: curs_refresh.3,v 1.7 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998,2000 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2001,2005 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,18 +28,22 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_refresh.3x,v 1.8 2000/07/01 20:06:14 tom Exp $ +.\" $Id: curs_refresh.3,v 1.7 2010/01/12 23:21:59 nicm Exp $ .TH curs_refresh 3 "" +.na +.hy 0 .SH NAME -\fBrefresh\fR, -\fBwrefresh\fR, -\fBwnoutrefresh\fR, \fBdoupdate\fR, \fBredrawwin\fR, -\fBwredrawln\fR - refresh \fBcurses\fR windows and lines +\fBrefresh\fR, +\fBwnoutrefresh\fR, +\fBwredrawln\fR, +\fBwrefresh\fR - refresh \fBcurses\fR windows and lines +.ad +.hy .SH SYNOPSIS \fB#include <curses.h>\fR - +.sp \fBint refresh(void);\fR .br \fBint wrefresh(WINDOW *win);\fR @@ -55,39 +59,48 @@ .SH DESCRIPTION The \fBrefresh\fR and \fBwrefresh\fR routines (or \fBwnoutrefresh\fR and \fBdoupdate\fR) must be called to get actual output to the terminal, as other -routines merely manipulate data structures. The routine \fBwrefresh\fR copies +routines merely manipulate data structures. +The routine \fBwrefresh\fR copies the named window to the physical terminal screen, taking into account what is -already there in order to do optimizations. The \fBrefresh\fR routine is the -same, using \fBstdscr\fR as the default window. Unless \fBleaveok\fR has been +already there to do optimizations. +The \fBrefresh\fR routine is the +same, using \fBstdscr\fR as the default window. +Unless \fBleaveok\fR has been enabled, the physical cursor of the terminal is left at the location of the cursor for that window. - +.PP The \fBwnoutrefresh\fR and \fBdoupdate\fR routines allow multiple updates with -more efficiency than \fBwrefresh\fR alone. In addition to all the window +more efficiency than \fBwrefresh\fR alone. +In addition to all the window structures, \fBcurses\fR keeps two data structures representing the terminal screen: a physical screen, describing what is actually on the screen, and a virtual screen, describing what the programmer wants to have on the screen. - +.PP The routine \fBwrefresh\fR works by first calling \fBwnoutrefresh\fR, which copies the named window to the virtual screen, and then calling \fBdoupdate\fR, which compares the virtual screen to the physical screen and does the actual -update. If the programmer wishes to output several windows at once, a series +update. +If the programmer wishes to output several windows at once, a series of calls to \fBwrefresh\fR results in alternating calls to \fBwnoutrefresh\fR -and \fBdoupdate\fR, causing several bursts of output to the screen. By first +and \fBdoupdate\fR, causing several bursts of output to the screen. +By first calling \fBwnoutrefresh\fR for each window, it is then possible to call \fBdoupdate\fR once, resulting in only one burst of output, with fewer total -characters transmitted and less CPU time used. If the \fIwin\fR argument to +characters transmitted and less CPU time used. +If the \fIwin\fR argument to \fBwrefresh\fR is the global variable \fBcurscr\fR, the screen is immediately cleared and repainted from scratch. - +.PP The phrase "copies the named window to the virtual screen" above is ambiguous. What actually happens is that all \fItouched\fR (changed) lines in the window -are copied to the virtual screen. This affects programs that use overlapping +are copied to the virtual screen. +This affects programs that use overlapping windows; it means that if two windows overlap, you can refresh them in either order and the overlap region will be modified only when it is explicitly -changed. (But see the section on \fBPORTABILITY\fR below for a warning about +changed. +(But see the section on \fBPORTABILITY\fR below for a warning about exploiting this behavior.) - +.PP The \fBwredrawln\fR routine indicates to \fBcurses\fR that some screen lines are corrupted and should be thrown away before anything is written over them. It touches the indicated lines (marking them changed). @@ -96,16 +109,32 @@ The routine \fBredrawwin\fR() touches the entire window. Routines that return an integer return \fBERR\fR upon failure, and \fBOK\fR (SVr4 only specifies "an integer value other than \fBERR\fR") upon successful completion. +.PP +X/Open does not define any error conditions. +In this implementation +.RS +.TP 5 +\fBwnoutrefresh\fP +returns an error +if the window pointer is null, or +if the window is really a pad. +.TP 5 +\fBwredrawln\fP +returns an error +if the associated call to \fBtouchln\fP returns an error. +.RE .SH NOTES Note that \fBrefresh\fR and \fBredrawwin\fR may be macros. .SH PORTABILITY The XSI Curses standard, Issue 4 describes these functions. - +.PP Whether \fBwnoutrefresh()\fR copies to the virtual screen the entire contents of a window or just its changed portions has never been well-documented in -historic curses versions (including SVr4). It might be unwise to rely on +historic curses versions (including SVr4). +It might be unwise to rely on either behavior in programs that might have to be linked with other curses -implementations. Instead, you can do an explicit \fBtouchwin()\fR before the +implementations. +Instead, you can do an explicit \fBtouchwin()\fR before the \fBwnoutrefresh()\fR call to guarantee an entire-contents copy anywhere. .SH SEE ALSO \fBcurses\fR(3), \fBcurs_outopts\fR(3) diff --git a/lib/libcurses/curs_scanw.3 b/lib/libcurses/curs_scanw.3 index 0509a3e9b88..4e287ec0aea 100644 --- a/lib/libcurses/curs_scanw.3 +++ b/lib/libcurses/curs_scanw.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_scanw.3,v 1.10 2001/07/27 05:32:05 millert Exp $ +.\" $OpenBSD: curs_scanw.3,v 1.11 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998,2000 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2000,2006 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,7 +28,7 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_scanw.3x,v 1.11 2000/07/15 21:48:17 tom Exp $ +.\" $Id: curs_scanw.3,v 1.11 2010/01/12 23:21:59 nicm Exp $ .TH curs_scanw 3 "" .SH NAME \fBscanw\fR, @@ -38,15 +38,14 @@ \fBvwscanw\fR, \fBvw_scanw\fR - convert formatted input from a \fBcurses\fR window .SH SYNOPSIS \fB#include <curses.h>\fR - -\fBint scanw(char *fmt\fR [\fB, arg\fR] \fB...);\fR +.sp +\fBint scanw(char *fmt, ...);\fR .br -\fBint wscanw(WINDOW *win, char *fmt\fR [\fB, arg\fR] \fB...);\fR +\fBint wscanw(WINDOW *win, char *fmt, ...);\fR .br -\fBint mvscanw(int y, int x, char *fmt\fR [\fB, arg\fR] \fB...);\fR +\fBint mvscanw(int y, int x, char *fmt, ...);\fR .br -\fBint mvwscanw(WINDOW *win, int y, int x,\fR - \fBchar *fmt\fR [\fB, arg]\fR \fB...);\fR +\fBint mvwscanw(WINDOW *win, int y, int x, char *fmt, ...);\fR .br \fBint vw_scanw(WINDOW *win, char *fmt, va_list varglist);\fR .br @@ -57,15 +56,15 @@ The \fBscanw\fR, \fBwscanw\fR and \fBmvscanw\fR routines are analogous to \fBwgetstr\fR were called on the window, and the resulting line used as input for \fBsscanf\fR(3). Fields which do not map to a variable in the \fIfmt\fR field are lost. - -The \fBvwscanw\fR routine is similar to \fBvwprintw\fR in that it performs a -\fBwscanw\fR using a variable argument list. The third argument is a -\fIva\fR_\fIlist\fR, a pointer to a list of arguments, as defined in -\fB<stdarg.h>\fR. +.PP +The \fBvwscanw\fR and \fBvw_scanw\fR routines are analogous to \fBvscanf\fR. +They perform a \fBwscanw\fR using a variable argument list. +The third argument is a \fIva_list\fR, +a pointer to a list of arguments, as defined in \fB<stdarg.h>\fR. .SH RETURN VALUE \fBvwscanw\fR returns \fBERR\fR on failure and an integer equal to the number of fields scanned on success. - +.PP Applications may use the return value from the \fBscanw\fR, \fBwscanw\fR, \fBmvscanw\fR and \fBmvwscanw\fR routines to determine the number of fields which were mapped in the call. @@ -73,6 +72,23 @@ which were mapped in the call. The XSI Curses standard, Issue 4 describes these functions. The function \fBvwscanw\fR is marked TO BE WITHDRAWN, and is to be replaced by a function \fBvw_scanw\fR using the \fB<stdarg.h>\fR interface. +The Single Unix Specification, Version 2 states that +\fBvw_scanw\fR is preferred to \fBvwscanw\fR since the latter requires +including \fB<varargs.h>\fR, which +cannot be used in the same file as \fB<stdarg.h>\fR. +This implementation uses \fB<stdarg.h>\fR for both, because that header +is included in \fB<curses.h\fR>. +.LP +Both XSI and The Single Unix Specification, Version 2 state that these +functions return ERR or OK. +Since the underlying \fBscanf\fR can return the number of items scanned, +and the SVr4 code was documented to use this feature, +this is probably an editing error which was introduced in XSI, +rather than being done intentionally. +Portable applications should only test if the return value is ERR, +since the OK value (zero) is likely to be misleading. +One possible way to get useful results would be to use a "%n" conversion +at the end of the format string to ensure that something was processed. .SH SEE ALSO \fBcurses\fR(3), \fBcurs_getstr\fR(3), \fBcurs_printw\fR(3), \fBscanf\fR(3) .\"# diff --git a/lib/libcurses/curs_scr_dump.3 b/lib/libcurses/curs_scr_dump.3 index 4026e87ec1a..168ae84f75b 100644 --- a/lib/libcurses/curs_scr_dump.3 +++ b/lib/libcurses/curs_scr_dump.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_scr_dump.3,v 1.2 2000/07/10 03:06:08 millert Exp $ +.\" $OpenBSD: curs_scr_dump.3,v 1.3 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998,2000 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,16 +28,20 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_scr_dump.3x,v 1.2 2000/07/01 20:06:53 tom Exp $ +.\" $Id: curs_scr_dump.3,v 1.3 2010/01/12 23:21:59 nicm Exp $ .TH curs_scr_dump 3 "" +.na +.hy 0 .SH NAME \fBscr_dump\fR, \fBscr_restore\fR, \fBscr_init\fR, \fBscr_set\fR - read (write) a \fBcurses\fR screen from (to) a file +.ad +.hy .SH SYNOPSIS \fB#include <curses.h>\fR - +.sp \fBint scr_dump(const char *filename);\fR .br \fBint scr_restore(const char *filename);\fR @@ -49,41 +53,45 @@ .SH DESCRIPTION The \fBscr_dump\fR routine dumps the current contents of the virtual screen to the file \fIfilename\fR. - +.PP The \fBscr_restore\fR routine sets the virtual screen to the contents of \fIfilename\fR, which must have been written using \fBscr_dump\fR. The next call to \fBdoupdate\fR restores the screen to the way it looked in the dump file. - +.PP The \fBscr_init\fR routine reads in the contents of \fIfilename\fR and uses them to initialize the \fBcurses\fR data structures about what the terminal currently has on its screen. If the data is determined to be valid, \fBcurses\fR bases its next update of the screen on this information rather than clearing the screen and starting from scratch. \fBscr_init\fR is used -after \fBinitscr\fR or a \fBsystem\fR [see \fBsystem\fR(BA_LIB)] call to share +after \fBinitscr\fR or a \fBsystem\fR call to share the screen with another process which has done a \fBscr_dump\fR after its \fBendwin\fR call. The data is declared invalid if the terminfo capabilities \fBrmcup\fR and \fBnrrmc\fR exist; also if the terminal has been written to since the preceding \fBscr_dump\fR call. - +.PP The \fBscr_set\fR routine is a combination of \fBscr_restore\fR and \fBscr_init\fR. It tells the program that the information in \fIfilename\fR is what is currently on the screen, and also what the program wants on the screen. This can be thought of as a screen inheritance function. - +.PP To read (write) a window from (to) a file, use the \fBgetwin\fR and \fBputwin\fR routines [see \fBcurs_util\fR(3)]. .SH RETURN VALUE All routines return the integer \fBERR\fR upon failure and \fBOK\fR upon success. +.PP +X/Open defines no error conditions. +In this implementation, +each will return an error if the file cannot be opened. .SH NOTES Note that \fBscr_init\fR, \fBscr_set\fR, and \fBscr_restore\fR may be macros. .SH PORTABILITY The XSI Curses standard, Issue 4, describes these functions (adding the const qualifiers). - +.PP The SVr4 docs merely say under \fBscr_init\fR that the dump data is also -considered invalid "if the time-stamp of the tty is old" but don't define +considered invalid "if the time-stamp of the tty is old" but do not define "old". .SH SEE ALSO \fBcurses\fR(3), \fBcurs_initscr\fR(3), \fBcurs_refresh\fR(3), diff --git a/lib/libcurses/curs_scroll.3 b/lib/libcurses/curs_scroll.3 index df86d4792c9..b88c95ed1ea 100644 --- a/lib/libcurses/curs_scroll.3 +++ b/lib/libcurses/curs_scroll.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_scroll.3,v 1.8 2003/05/14 08:55:19 jmc Exp $ +.\" $OpenBSD: curs_scroll.3,v 1.9 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998,2000 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,13 +28,19 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_scroll.3x,v 1.8 2000/07/01 17:54:23 tom Exp $ +.\" $Id: curs_scroll.3,v 1.9 2010/01/12 23:21:59 nicm Exp $ .TH curs_scroll 3 "" +.na +.hy 0 .SH NAME -\fBscroll\fR, \fBscrl\fR, \fBwscrl\fR - scroll a \fBcurses\fR window +\fBscroll\fR, +\fBscrl\fR, +\fBwscrl\fR - scroll a \fBcurses\fR window +.ad +.hy .SH SYNOPSIS \fB#include <curses.h>\fR - +.sp \fBint scroll(WINDOW *win);\fR .br \fBint scrl(int n);\fR @@ -42,29 +48,40 @@ \fBint wscrl(WINDOW *win, int n);\fR .br .SH DESCRIPTION -The \fBscroll\fR routine scrolls the window up one line. This involves moving -the lines in the window data structure. As an optimization, if the scrolling +The \fBscroll\fR routine scrolls the window up one line. +This involves moving +the lines in the window data structure. +As an optimization, if the scrolling region of the window is the entire screen, the physical screen may be scrolled at the same time. - +.PP For positive \fIn\fR, the \fBscrl\fR and \fBwscrl\fR routines scroll the window up \fIn\fR lines (line \fIi\fR+\fIn\fR becomes \fIi\fR); otherwise -scroll the window down \fIn\fR lines. This involves moving the lines in the -window character image structure. The current cursor position is not changed. - +scroll the window down \fIn\fR lines. +This involves moving the lines in the +window character image structure. +The current cursor position is not changed. +.PP For these functions to work, scrolling must be enabled via \fBscrollok\fR. .SH RETURN VALUE These routines return \fBERR\fR upon failure, and \fBOK\fR (SVr4 only specifies "an integer value other than \fBERR\fR") upon successful completion. +.PP +X/Open defines no error conditions. +.PP +This implementation returns an error +if the window pointer is null, or +if scrolling is not enabled in the window, e.g., with \fBscrollok\fP. .SH NOTES Note that \fBscrl\fR and \fBscroll\fR may be macros. - +.PP The SVr4 documentation says that the optimization of physically scrolling immediately if the scroll region is the entire screen "is" performed, not -"may be" performed. This implementation deliberately does not guarantee -that this will occur, in order to leave open the possibility of smarter +"may be" performed. +This implementation deliberately does not guarantee +that this will occur, to leave open the possibility of smarter optimization of multiple scroll actions on the next update. - +.PP Neither the SVr4 nor the XSI documentation specify whether the current attribute or current color-pair of blanks generated by the scroll function is zeroed. diff --git a/lib/libcurses/curs_slk.3 b/lib/libcurses/curs_slk.3 index 41f21ead54a..ff4dc2cc90c 100644 --- a/lib/libcurses/curs_slk.3 +++ b/lib/libcurses/curs_slk.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_slk.3,v 1.9 2003/05/14 08:55:19 jmc Exp $ +.\" $OpenBSD: curs_slk.3,v 1.10 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998,2000 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,18 +28,32 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_slk.3x,v 1.10 2000/07/01 17:52:44 tom Exp $ +.\" $Id: curs_slk.3,v 1.10 2010/01/12 23:21:59 nicm Exp $ .TH curs_slk 3 "" +.na +.hy 0 .SH NAME -\fBslk_init\fR, \fBslk_set\fR, \fBslk_refresh\fR, -\fBslk_noutrefresh\fR, \fBslk_label\fR, -\fBslk_clear\fR, \fBslk_restore\fR, \fBslk_touch\fR, -\fBslk_attron\fR, \fBslk_attrset\fR, \fBslk_attroff\fR, -\fBslk_attr_on\fR, \fBslk_attr_set\fR, \fBslk_attr_off\fR, -\fBslk_attr\fR, \fBslk_color\fR - \fBcurses\fR soft label routines +\fBslk_init\fR, +\fBslk_set\fR, +\fBslk_refresh\fR, +\fBslk_noutrefresh\fR, +\fBslk_label\fR, +\fBslk_clear\fR, +\fBslk_restore\fR, +\fBslk_touch\fR, +\fBslk_attron\fR, +\fBslk_attrset\fR, +\fBslk_attroff\fR, +\fBslk_attr_on\fR, +\fBslk_attr_set\fR, +\fBslk_attr_off\fR, +\fBslk_attr\fR, +\fBslk_color\fR - \fBcurses\fR soft label routines +.ad +.hy .SH SYNOPSIS \fB#include <curses.h>\fR - +.sp \fBint slk_init(int fmt);\fR .br \fBint slk_set(int labnum, const char *label, int fmt);\fR @@ -83,9 +97,9 @@ labels of up to eight characters each. In addition to this, the ncurses implementation supports a mode where it simulates 12 labels of up to five characters each. This is most common for todays PC like enduser devices. Please note that ncurses simulates this mode by taking over up to two lines at -the bottom of the screen, it doesn't try to use any hardware support for this +the bottom of the screen, it does not try to use any hardware support for this mode. - +.PP The \fBslk_init\fR routine must be called before \fBinitscr\fR or \fBnewterm\fR is called. If \fBinitscr\fR eventually uses a line from \fBstdscr\fR to emulate the soft labels, then \fIfmt\fR determines how the labels are arranged @@ -94,7 +108,7 @@ the labels, \fB1\fR indicates a 4-4 arrangement and \fB2\fR indicates the PC like 4-4-4 mode. If \fBfmt\fR is set to \fB3\fR, it is again the PC like 4-4-4 mode, but in addition an index line is generated, helping the user to identify the key numbers easily. - +.PP The \fBslk_set\fR routine requires \fIlabnum\fR to be a label number, from \fB1\fR to \fB8\fR (resp. \fB12\fR); \fIlabel\fR must be the string to be put on the label, up to eight (resp. five) characters in length. @@ -102,36 +116,78 @@ A null string or a null pointer sets up a blank label. \fIfmt\fR is either \fB0\fR, \fB1\fR, or \fB2\fR, indicating whether the label is to be left-justified, centered, or right-justified, respectively, within the label. - +.PP The \fBslk_refresh\fR and \fBslk_noutrefresh\fR routines correspond to the \fBwrefresh\fR and \fBwnoutrefresh\fR routines. - +.PP The \fBslk_label\fR routine returns the current label for label number \fIlabnum\fR, with leading and trailing blanks stripped. - +.PP The \fBslk_clear\fR routine clears the soft labels from the screen. - +.PP The \fBslk_restore\fR routine restores the soft labels to the screen after a \fBslk_clear\fR has been performed. - +.PP The \fBslk_touch\fR routine forces all the soft labels to be output the next time a \fBslk_noutrefresh\fR is performed. - +.PP The \fBslk_attron\fR, \fBslk_attrset\fR, \fBslk_attroff\fR and \fBslk_attr\fR routines correspond to \fBattron\fR, \fBattrset\fR, \fBattroff\fR and \fBattr_get\fR. They have an effect only if soft labels are simulated on the bottom line of the screen. The default highlight for soft keys is A_STANDOUT (as in System V curses, which does not document this fact). - +.PP The \fBslk_color\fR routine corresponds to \fBcolor_set\fR. It has an effect only if soft labels are simulated on the bottom line of the screen. - +. .SH RETURN VALUE These routines return \fBERR\fR upon failure and OK (SVr4 specifies only "an -integer value other than \fBERR\fR") upon successful completion. \fBslk_attr\fR +integer value other than \fBERR\fR") upon successful completion. +.PP +X/Open defines no error conditions. +In this implementation +.RS +.TP 5 +\fBslk_attr\fR returns the attribute used for the soft keys. - -\fBslk_label\fR returns \fBNULL\fR on error. +.TP 5 +.na +.hy 0 +\fBslk_attroff\fP, \fBslk_attron\fP, \fBslk_clear\fP, \fBslk_noutrefresh\fP, \fBslk_refresh\fP, \fBslk_touch\fP +.ad +.hy +return an error +if the terminal or the softkeys were not initialized. +.TP 5 +\fBslk_attrset\fP +returns an error +if the terminal or the softkeys were not initialized. +.TP 5 +\fBslk_attr_set\fP +returns an error +if the terminal or the softkeys were not initialized, or +the color pair is outside the range 0..COLOR_PAIRS-1, +or opts is not null. +.TP 5 +\fBslk_color\fP +returns an error +if the terminal or the softkeys were not initialized, or +the color pair is outside the range 0..COLOR_PAIRS-1. +.TP 5 +\fBslk_init\fR +returns an error +if the format parameter is outside the range 0..3. +.TP 5 +\fBslk_label\fR +returns \fBNULL\fR on error. +.TP 5 +\fBslk_set\fP +returns an error +if the terminal or the softkeys were not initialized, or +the \fIlabnum\fP parameter is outside the range of label counts, or +if the format parameter is outside the range 0..2, or if +memory for the labels cannot be allocated. +.RE .SH NOTES Most applications would use \fBslk_noutrefresh\fR because a \fBwrefresh\fR is likely to follow soon. diff --git a/lib/libcurses/curs_termattrs.3 b/lib/libcurses/curs_termattrs.3 index 49c1720dd27..bbc9a1ffc8a 100644 --- a/lib/libcurses/curs_termattrs.3 +++ b/lib/libcurses/curs_termattrs.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_termattrs.3,v 1.7 2000/07/10 03:06:09 millert Exp $ +.\" $OpenBSD: curs_termattrs.3,v 1.8 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998,2000 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2003,2007 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,28 +28,42 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_termattrs.3x,v 1.6 2000/07/08 12:53:34 tom Exp $ +.\" $Id: curs_termattrs.3,v 1.8 2010/01/12 23:21:59 nicm Exp $ .TH curs_termattrs 3 "" .SH NAME -\fBbaudrate\fR, \fBerasechar\fR, \fBhas_ic\fR, -\fBhas_il\fR, \fBkillchar\fR, \fBlongname\fR, \fBtermattrs\fR, +\fBbaudrate\fR, +\fBerasechar\fR, +\fBerasewchar\fR, +\fBhas_ic\fR, +\fBhas_il\fR, +\fBkillchar\fR, +\fBkillwchar\fR, +\fBlongname\fR, +\fBterm_attrs\fR, +\fBtermattrs\fR, \fBtermname\fR - \fBcurses\fR environment query routines .SH SYNOPSIS \fB#include <curses.h>\fR - +.PP \fBint baudrate(void);\fR .br \fBchar erasechar(void);\fR .br +\fBint erasewchar(wchar_t *\fR\fIch\fR\fB);\fR +.br \fBbool has_ic(void);\fR .br \fBbool has_il(void);\fR .br \fBchar killchar(void);\fR .br +\fBint killwchar(wchar_t *\fR\fIch\fR\fB);\fR +.br \fBchar *longname(void);\fR .br -\fBattr_t termattrs(void);\fR +\fBattr_t term_attrs(void);\fR +.br +\fBchtype termattrs(void);\fR .br \fBchar *termname(void);\fR .br @@ -57,19 +71,29 @@ The \fBbaudrate\fR routine returns the output speed of the terminal. The number returned is in bits per second, for example \fB9600\fR, and is an integer. - +.PP The \fBerasechar\fR routine returns the user's current erase character. - +.PP +The \fBerasewchar\fR routine stores the current erase character +in the location referenced by \fIch\fR. +If no erase character has been defined, the routine fails +and the location referenced by \fIch\fR is not changed. +.PP The \fBhas_ic\fR routine is true if the terminal has insert- and delete- character capabilities. - +.PP The \fBhas_il\fR routine is true if the terminal has insert- and delete-line capabilities, or can simulate them using scrolling regions. This might be used to determine if it would be appropriate to turn on physical scrolling using \fBscrollok\fR. - +.PP The \fBkillchar\fR routine returns the user's current line kill character. - +.PP +The \fBkillwchar\fR routine stores the current line-kill character +in the location referenced by \fIch\fR. +If no line-kill character has been defined, +the routine fails and the location referenced by \fIch\fR is not changed. +.PP The \fBlongname\fR routine returns a pointer to a static area containing a verbose description of the current terminal. The maximum length of a verbose description is 128 characters. It is defined only @@ -78,19 +102,20 @@ overwritten by each call to \fBnewterm\fR and is not restored by \fBset_term\fR, so the value should be saved between calls to \fBnewterm\fR if \fBlongname\fR is going to be used with multiple terminals. - -If a given terminal doesn't support a video attribute that an +.PP +If a given terminal does not support a video attribute that an application program is trying to use, \fBcurses\fR may substitute a -different video attribute for it. The \fBtermattrs\fR function -returns a logical \fBOR\fR of all video attributes supported by the -terminal. This information is useful when a \fBcurses\fR program +different video attribute for it. +The \fBtermattrs\fR and \fBterm_attrs\fR functions +return a logical \fBOR\fR of all video attributes supported by the +terminal using \fIA_\fR and \fIWA_\fR constants respectively. +This information is useful when a \fBcurses\fR program needs complete control over the appearance of the screen. - -The \fBtermname\fR routine returns the value of the environmental -variable \fBTERM\fR (truncated to 14 characters). +.PP +The \fBtermname\fR routine returns the terminal name used by \fBsetupterm\fR. .SH RETURN VALUE \fBlongname\fR and \fBtermname\fR return \fBNULL\fR on error. - +.PP Routines that return an integer return \fBERR\fR upon failure and \fBOK\fR (SVr4 only specifies "an integer value other than \fBERR\fR") upon successful completion. @@ -99,6 +124,8 @@ Note that \fBtermattrs\fR may be a macro. .SH PORTABILITY The XSI Curses standard, Issue 4 describes these functions. It changes the return type of \fBtermattrs\fR to the new type \fBattr_t\fR. +Most versions of curses truncate the result returned by \fBtermname\fR to +14 characters. .SH SEE ALSO \fBcurses\fR(3), \fBcurs_initscr\fR(3), \fBcurs_outopts\fR(3) .\"# diff --git a/lib/libcurses/curs_touch.3 b/lib/libcurses/curs_touch.3 index 1cd02bc1f26..e18a0bf7e42 100644 --- a/lib/libcurses/curs_touch.3 +++ b/lib/libcurses/curs_touch.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_touch.3,v 1.6 2000/07/10 03:06:09 millert Exp $ +.\" $OpenBSD: curs_touch.3,v 1.7 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998,2000 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,8 +28,10 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_touch.3x,v 1.8 2000/07/08 11:07:57 tom Exp $ +.\" $Id: curs_touch.3,v 1.7 2010/01/12 23:21:59 nicm Exp $ .TH curs_touch 3 "" +.na +.hy 0 .SH NAME \fBtouchwin\fR, \fBtouchline\fR, @@ -37,6 +39,8 @@ \fBwtouchln\fR, \fBis_linetouched\fR, \fBis_wintouched\fR - \fBcurses\fR refresh control routines +.ad +.hy .SH SYNOPSIS \fB#include <curses.h>\fR .br @@ -61,15 +65,15 @@ to one window affects the other window, but the records of which lines have been changed in the other window do not reflect the change. The routine \fBtouchline\fR only pretends that \fIcount\fR lines have been changed, beginning with line \fIstart\fR. - +.PP The \fBuntouchwin\fR routine marks all lines in the window as unchanged since the last call to \fBwrefresh\fR. - +.PP The \fBwtouchln\fR routine makes \fIn\fR lines in the window, starting at line \fIy\fR, look as if they have (\fIchanged\fR\fB=1\fR) or have not (\fIchanged\fR\fB=0\fR) been changed since the last call to \fBwrefresh\fR. - +.PP The \fBis_linetouched\fR and \fBis_wintouched\fR routines return \fBTRUE\fR if the specified line/window was modified since the last call to \fBwrefresh\fR; otherwise they return \fBFALSE\fR. In @@ -79,9 +83,25 @@ valid for the given window. All routines return the integer \fBERR\fR upon failure and an integer value other than \fBERR\fR upon successful completion, unless otherwise noted in the preceding routine descriptions. +.PP +X/Open does not define any error conditions. +In this implementation +.RS +.TP 5 +\fBis_linetouched\fP +returns an error +if the window pointer is null, or +if the line number is outside the window. +Note that ERR is distinct from TRUE and FALSE, which are the normal return values of this function. +.TP 5 +\fBwtouchln\fP +returns an error +if the window pointer is null, or +if the line number is outside the window. +.RE .SH PORTABILITY The XSI Curses standard, Issue 4 describes these functions. - +.PP Some historic curses implementations had, as an undocumented feature, the ability to do the equivalent of \fBclearok(..., 1)\fR by saying \fBtouchwin(stdscr)\fR or \fBclear(stdscr)\fR. This will not work under diff --git a/lib/libcurses/curs_util.3 b/lib/libcurses/curs_util.3 index d0eb4bf34b4..d88cc4c5bc7 100644 --- a/lib/libcurses/curs_util.3 +++ b/lib/libcurses/curs_util.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_util.3,v 1.5 1998/09/13 19:16:23 millert Exp $ +.\" $OpenBSD: curs_util.3,v 1.6 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,22 +28,40 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_util.3x,v 1.6 1998/03/11 21:12:53 juergen Exp $ +.\" $Id: curs_util.3,v 1.6 2010/01/12 23:21:59 nicm Exp $ .TH curs_util 3 "" +.na +.hy 0 .SH NAME -\fBunctrl\fR, \fBkeyname\fR, \fBfilter\fR, -\fBuse_env\fR, \fBputwin\fR, \fBgetwin\fR, \fBdelay_output\fR, -\fBflushinp\fR - miscellaneous \fBcurses\fR utility routines +\fBdelay_output\fR, +\fBfilter\fR, +\fBflushinp\fR, +\fBgetwin\fR, +\fBkey_name\fR, +\fBkeyname\fR, +\fBnofilter\fR, +\fBputwin\fR, +\fBunctrl\fR, +\fBuse_env\fR, +\fBwunctrl\fR - miscellaneous \fBcurses\fR utility routines +.ad +.hy .SH SYNOPSIS \fB#include <curses.h>\fR - +.sp \fBchar *unctrl(chtype c);\fR .br +\fBwchar_t *wunctrl(cchar_t *c);\fR +.br \fBchar *keyname(int c);\fR .br +\fBchar *key_name(wchar_t w);\fR +.br \fBvoid filter(void);\fR .br -\fBvoid use_env(char bool);\fR +\fBvoid nofilter(void);\fR +.br +\fBvoid use_env(bool f);\fR .br \fBint putwin(WINDOW *win, FILE *filep);\fR .br @@ -54,19 +72,62 @@ \fBint flushinp(void);\fR .br .SH DESCRIPTION -The \fBunctrl\fR macro expands to a character string which is a printable -representation of the character \fIc\fR. Control characters are displayed in -the \fB^\fR\fIX\fR notation. Printing characters are displayed as is. - -The \fBkeyname\fR routine returns a character string corresponding to -the key \fIc\fR. - +The \fBunctrl\fR routine returns a character string which is a printable +representation of the character \fIc\fR, ignoring attributes. +Control characters are displayed in the \fB^\fR\fIX\fR notation. +Printing characters are displayed as is. +The corresponding \fBwunctrl\fR returns a printable representation of +a wide-character. +.PP +The \fBkeyname\fR routine returns a character string corresponding to the key \fIc\fR: +.RS 3 +.TP 3 +- +Printable characters are displayed as themselves, e.g., a one-character string containing the key. +.TP 3 +- +Control characters are displayed in the \fB^\fR\fIX\fR notation. +.TP 3 +- +DEL (character 127) is displayed as \fB^?\fP. +.TP 3 +- +Values above 128 are either meta characters +(if the screen has not been initialized, +or if \fBmeta\fP has been called with a TRUE parameter), +shown in the \fBM-\fR\fIX\fR notation, +or are displayed as themselves. +In the latter case, the values may not be printable; +this follows the X/Open specification. +.TP 3 +- +Values above 256 may be the names of the names of function keys. +.TP 3 +- +Otherwise (if there is no corresponding name) the function returns null, +to denote an error. +X/Open also lists an "UNKNOWN KEY" return value, which some implementations +return rather than null. +.RE +.LP +The corresponding \fBkey_name\fR returns a character string corresponding +to the wide-character value \fIw\fR. +The two functions do not return the same set of strings; +the latter returns null where the former would display a meta character. +.PP The \fBfilter\fR routine, if used, must be called before \fBinitscr\fR or \fBnewterm\fR are called. The effect is that, during those calls, \fBLINES\fR is set to 1; the capabilities \fBclear\fR, \fBcup\fR, \fBcud\fR, \fBcud1\fR, \fBcuu1\fR, \fBcuu\fR, \fBvpa\fR are disabled; and the \fBhome\fR string is set to the value of \fBcr\fR. - +.PP +The \fBnofilter\fP routine cancels the effect of a preceding \fBfilter\fP +call. +That allows the caller to initialize a screen on a different device, +using a different value of \fB$TERM\fP. +The limitation arises because the \fBfilter\fP routine modifies the +in-memory copy of the terminal information. +.PP The \fBuse_env\fR routine, if used, is called before \fBinitscr\fR or \fBnewterm\fR are called. When called with \fBFALSE\fR as an argument, the values of \fBlines\fR and \fBcolumns\fR specified in the @@ -75,39 +136,122 @@ argument, the values of \fBlines\fR and \fBcolumns\fR specified in the \fBcurses\fR is running in a window (in which case default behavior would be to use the window size if \fBLINES\fR and \fBCOLUMNS\fR are not set). - +Note that setting \fBLINES\fR or \fBCOLUMNS\fR overrides the +corresponding size which may be obtained from the operating system. +.PP The \fBputwin\fR routine writes all data associated with window \fIwin\fR into the file to which \fIfilep\fR points. This information can be later retrieved using the \fBgetwin\fR function. - +.PP The \fBgetwin\fR routine reads window related data stored in the file by \fBputwin\fR. The routine then creates and initializes a new window using that data. It returns a pointer to the new window. - +.PP The \fBdelay_output\fR routine inserts an \fIms\fR millisecond pause in output. This routine should not be used extensively because padding characters are used rather than a CPU pause. - +If no padding character is specified, this uses \fBnapms\fR to perform the delay. +.PP The \fBflushinp\fR routine throws away any typeahead that has been typed by the user and has not yet been read by the program. .SH RETURN VALUE Except for \fBflushinp\fR, routines that return an integer return \fBERR\fR upon failure and \fBOK\fR (SVr4 specifies only "an integer value other than \fBERR\fR") upon successful completion. - -\fBflushinp\fR always returns \fBOK\fR. - +.PP Routines that return pointers return \fBNULL\fR on error. +.PP +X/Open does not define any error conditions. +In this implementation +.RS 3 +.TP 5 +\fBflushinp\fR +returns an error if the terminal was not initialized. +.TP 5 +\fBmeta\fR +returns an error if the terminal was not initialized. +.TP 5 +\fBputwin\fP +returns an error if the associated \fBfwrite\fP calls return an error. +.RE .SH PORTABILITY The XSI Curses standard, Issue 4 describes these functions. - +It states that \fBunctrl\fR and \fBwunctrl\fR will return a null pointer if +unsuccessful, but does not define any error conditions. +This implementation checks for three cases: +.RS +.TP 5 +- +the parameter is a 7-bit US-ASCII code. +This is the case that X/Open Curses documented. +.TP 5 +- +the parameter is in the range 128-159, i.e., a C1 control code. +If \fBuse_legacy_coding\fP has been called with a \fB2\fP parameter, +\fBunctrl\fP returns the parameter, i.e., a one-character string with +the parameter as the first character. +Otherwise, it returns ``~@'', ``~A'', etc., analogous to ``^@'', ``^A'', C0 controls. +.IP +X/Open Curses does not document whether \fBunctrl\fP can be called before +initializing curses. +This implementation permits that, +and returns the ``~@'', etc., values in that case. +.TP 5 +- +parameter values outside the 0 to 255 range. +\fBunctrl\fP returns a null pointer. +.RE +.PP The SVr4 documentation describes the action of \fBfilter\fR only in the vaguest terms. The description here is adapted from the XSI Curses standard (which erroneously fails to describe the disabling of \fBcuu\fR). -.SH NOTES -Note that \fBunctrl\fR is a macro, which is defined in <\fBunctrl.h\fR>. +.PP +The strings returned by \fBunctrl\fR in this implementation are determined +at compile time, +showing C1 controls from the upper-128 codes with a `~' prefix rather than `^'. +Other implementations have different conventions. +For example, they may show both sets of control characters with `^', +and strip the parameter to 7 bits. +Or they may ignore C1 controls and treat all of the upper-128 codes as +printable. +This implementation uses 8 bits but does not modify the string to reflect +locale. +The \fBuse_legacy_coding\fP function allows the caller to +change the output of \fBunctrl\fP. +.PP +Likewise, the \fBmeta\fP function allows the caller to change the +output of \fBkeyname\fP, i.e., +it determines whether to use the `M-' prefix +for ``meta'' keys (codes in the range 128 to 255). +Both \fBuse_legacy_coding\fP and \fBmeta\fP succeed only after +curses is initialized. +X/Open Curses does not document the treatment of codes 128 to 159. +When treating them as ``meta'' keys +(or if \fBkeyname\fP is called before initializing curses), +this implementation returns strings ``M-^@'', ``M-^A'', etc. +.PP +The \fBkeyname\fP function may return the names of user-defined +string capabilities which are defined in the terminfo entry via the \fB-x\fP +option of \fBtic\fP. +This implementation automatically assigns at run-time keycodes to +user-defined strings which begin with "k". +The keycodes start at KEY_MAX, but are not guaranteed to be +the same value for different runs because user-defined codes are +merged from all terminal descriptions which have been loaded. +The \fBuse_extended_names\fP function controls whether this data is +loaded when the terminal description is read by the library. +.PP +The \fBnofilter\fP routine is specific to ncurses. +It was not supported on Version 7, BSD or System V implementations. +It is recommended that any code depending on ncurses extensions +be conditioned using NCURSES_VERSION. .SH SEE ALSO -\fBcurses\fR(3), \fBcurs_initscr\fR(3), \fBcurs_scr_dump\fR(3). +\fBlegacy_coding\fR(3), +\fBcurses\fR(3), +\fBcurs_initscr\fR(3), +\fBcurs_kernel\fR(3), +\fBcurs_scr_dump\fR(3), +\fBlegacy_coding\fR(3). .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_window.3 b/lib/libcurses/curs_window.3 index ac75191a5ad..f4d112bc6b4 100644 --- a/lib/libcurses/curs_window.3 +++ b/lib/libcurses/curs_window.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: curs_window.3,v 1.9 2003/05/14 08:55:19 jmc Exp $ +.\" $OpenBSD: curs_window.3,v 1.10 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998,2000 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,8 +28,10 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_window.3x,v 1.9 2000/07/01 20:08:37 tom Exp $ +.\" $Id: curs_window.3,v 1.10 2010/01/12 23:21:59 nicm Exp $ .TH curs_window 3 "" +.na +.hy 0 .SH NAME \fBnewwin\fR, \fBdelwin\fR, @@ -42,9 +44,11 @@ \fBsyncok\fR, \fBwcursyncup\fR, \fBwsyncdown\fR - create \fBcurses\fR windows +.ad +.hy .SH SYNOPSIS \fB#include <curses.h>\fR - +.sp \fBWINDOW *newwin(int nlines, int ncols, int begin_y,\fR \fBint begin_x);\fR .br @@ -77,17 +81,17 @@ at line \fIbegin\fR_\fIy\fR, column \fIbegin\fR_\fIx\fR. If either \fInlines\fR or \fIncols\fR is zero, they default to \fBLINES -\fR \fIbegin\fR_\fIy\fR and \fBCOLS -\fR \fIbegin\fR_\fIx\fR. A new full-screen window is created by calling \fBnewwin(0,0,0,0)\fR. - +.PP Calling \fBdelwin\fR deletes the named window, freeing all memory associated with it (it does not actually erase the window's screen image). Subwindows must be deleted before the main window can be deleted. - +.PP Calling \fBmvwin\fR moves the window so that the upper left-hand corner is at position (\fIx\fR, \fIy\fR). If the move would cause the window to be off the screen, it is an error and the window is not moved. Moving subwindows is allowed, but should be avoided. - +.PP Calling \fBsubwin\fR creates and returns a pointer to a new window with the given number of lines, \fInlines\fR, and columns, \fIncols\fR. The window is at position (\fIbegin\fR_\fIy\fR, @@ -98,29 +102,29 @@ will affect both windows. The subwindow shares memory with the window \fIorig\fR. When using this routine, it is necessary to call \fBtouchwin\fR or \fBtouchline\fR on \fIorig\fR before calling \fBwrefresh\fR on the subwindow. - +.PP Calling \fBderwin\fR is the same as calling \fBsubwin,\fR except that \fIbegin\fR_\fIy\fR and \fIbegin\fR_\fIx\fR are relative to the origin of the window \fIorig\fR rather than the screen. There is no difference between the subwindows and the derived windows. - +.PP Calling \fBmvderwin\fR moves a derived window (or subwindow) inside its parent window. The screen-relative parameters of the window are not changed. This routine is used to display different parts of the parent window at the same physical position on the screen. - +.PP Calling \fBdupwin\fR creates an exact duplicate of the window \fIwin\fR. - +.PP Calling \fBwsyncup\fR touches all locations in ancestors of \fIwin\fR that are changed in \fIwin\fR. If \fBsyncok\fR is called with second argument \fBTRUE\fR then \fBwsyncup\fR is called automatically whenever there is a change in the window. - +.PP The \fBwsyncdown\fR routine touches each location in \fIwin\fR that has been touched in any of its ancestor windows. This routine is called by \fBwrefresh\fR, so it should almost never be necessary to call it manually. - +.PP The routine \fBwcursyncup\fR updates the current cursor position of all the ancestors of the window to reflect the current cursor position of the window. @@ -128,21 +132,46 @@ window. Routines that return an integer return the integer \fBERR\fR upon failure and \fBOK\fR (SVr4 only specifies "an integer value other than \fBERR\fR") upon successful completion. - -\fBdelwin\fR returns the integer \fBERR\fR upon failure and \fBOK\fR -upon successful completion. - +.PP Routines that return pointers return \fBNULL\fR on error. +.PP +X/Open defines no error conditions. +In this implementation +.RS +.TP 5 +\fBdelwin\fR +returns an error if the window pointer is null, or +if the window is the parent of another window. +.IP +This implementation also maintains a list of windows, +and checks that the pointer passed to \fBdelwin\fP is one that +it created, returning an error if it was not.. +.TP 5 +\fBmvderwin\fP +returns an error +if the window pointer is null, or +if some part of the window would be placed off-screen. +.TP 5 +\fBmvwin\fP +returns an error +if the window pointer is null, or +if the window is really a pad, or +if some part of the window would be placed off-screen. +.TP 5 +\fBsyncok\fP +returns an error +if the window pointer is null. +.RE .SH NOTES If many small changes are made to the window, the \fBwsyncup\fR option could degrade performance. - +.PP Note that \fBsyncok\fR may be a macro. .SH BUGS The subwindow functions (\fIsubwin\fR, \fIderwin\fR, \fImvderwin\fR, \fBwsyncup\fR, \fBwsyncdown\fR, \fBwcursyncup\fR, \fBsyncok\fR) are flaky, incompletely implemented, and not well tested. - +.PP The System V curses documentation is very unclear about what \fBwsyncup\fR and \fBwsyncdown\fR actually do. It seems to imply that they are only supposed to touch exactly those lines that are affected by ancestor changes. diff --git a/lib/libcurses/curses.3tbl b/lib/libcurses/curses.3tbl index 7595cd82d17..13bf0c7adfa 100644 --- a/lib/libcurses/curses.3tbl +++ b/lib/libcurses/curses.3tbl @@ -1,8 +1,8 @@ '\" t -.\" $OpenBSD: curses.3tbl,v 1.19 2003/05/14 08:55:19 jmc Exp $ +.\" $OpenBSD: curses.3tbl,v 1.20 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998,1999 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -29,165 +29,260 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: ncurses.3x,v 1.46 2000/11/25 21:58:45 tom Exp $ +.\" $Id: curses.3tbl,v 1.20 2010/01/12 23:21:59 nicm Exp $ +.hy 0 .TH ncurses 3 "" .ds n 5 -.ds d /usr/share/terminfo +.ds d /usr/share/misc/terminfo .SH NAME -\fBcurses\fR - CRT screen handling and optimization package +\fBncurses\fR - CRT screen handling and optimization package .SH SYNOPSIS \fB#include <curses.h>\fR .br .SH DESCRIPTION -The \fBcurses\fR library routines give the user a terminal-independent method -of updating character screens with reasonable optimization. This -implementation is ``new curses'' (ncurses) and is the approved replacement for +The \fBncurses\fR library routines give the user a terminal-independent method +of updating character screens with reasonable optimization. +This implementation is ``new curses'' (ncurses) and +is the approved replacement for 4.4BSD classic curses, which has been discontinued. - -The \fBncurses\fR routines emulate the \fBcurses\fR(3) library of System V -Release 4 UNIX, and the XPG4 curses standard (XSI curses) but the \fBncurses\fR -library is freely redistributable in source form. Differences from the SVr4 -curses are summarized under the EXTENSIONS and BUGS sections below and -described in detail in the EXTENSIONS and BUGS sections of individual man -pages. - -A program using these routines must be linked with the \fB-lcurses\fR option. - -The \fBcurses\fR package supports: overall screen, window and pad +This describes \fBncurses\fR +version 5.7. +.PP +The \fBncurses\fR library emulates the \fBcurses\fR(3) library of +System V Release 4 UNIX, +and XPG4 (X/Open Portability Guide) curses (also known as XSI curses). +XSI stands for X/Open System Interfaces Extension. +The \fBncurses\fR library is freely redistributable in source form. +Differences from the SVr4 +curses are summarized under the \fBEXTENSIONS\fP and \fBPORTABILITY\fP sections below and +described in detail in the respective \fBEXTENSIONS\fP, \fBPORTABILITY\fP and \fBBUGS\fP sections +of individual man pages. +.PP +The \fBncurses\fR library also provides many useful extensions, +i.e., features which cannot be implemented by a simple add-on library +but which require access to the internals of the library. +.PP +A program using these routines must be linked with the \fB-lncurses\fR option. +.PP +The \fBncurses\fR package supports: overall screen, window and pad manipulation; output to windows and pads; reading terminal input; control over terminal and \fBcurses\fR input and output options; environment query routines; color manipulation; use of soft label keys; terminfo capabilities; and access to low-level terminal-manipulation routines. - -To initialize the routines, the routine \fBinitscr\fR or \fBnewterm\fR -must be called before any of the other routines that deal with windows -and screens are used. The routine \fBendwin\fR must be called before -exiting. To get character-at-a-time input without echoing (most +.PP +The library uses the locale which the calling program has initialized. +That is normally done with \fBsetlocale\fP: +.sp + \fBsetlocale(LC_ALL, "");\fP +.sp +If the locale is not initialized, +the library assumes that characters are printable as in ISO-8859-1, +to work with certain legacy programs. +You should initialize the locale and not rely on specific details of +the library when the locale has not been setup. +.PP +The function \fBinitscr\fR or \fBnewterm\fR +must be called to initialize the library +before any of the other routines that deal with windows +and screens are used. +The routine \fBendwin\fR must be called before exiting. +.PP +To get character-at-a-time input without echoing (most interactive, screen oriented programs want this), the following sequence should be used: - +.sp \fBinitscr(); cbreak(); noecho();\fR - +.sp Most programs would additionally use the sequence: - +.sp \fBnonl();\fR \fBintrflush(stdscr, FALSE);\fR \fBkeypad(stdscr, TRUE);\fR - +.sp Before a \fBcurses\fR program is run, the tab stops of the terminal -should be set and its initialization strings, if defined, must be -output. This can be done by executing the \fBtput init\fR command +should be set and its initialization strings, if defined, must be output. +This can be done by executing the \fBtput init\fR command after the shell environment variable \fBTERM\fR has been exported. \fBtset(1)\fR is usually responsible for doing this. [See \fBterminfo\fR(\*n) for further details.] - -The \fBcurses\fR library permits manipulation of data structures, +.PP +The \fBncurses\fR library permits manipulation of data structures, called \fIwindows\fR, which can be thought of as two-dimensional -arrays of characters representing all or part of a CRT screen. A -default window called \fBstdscr\fR, which is the size of the terminal -screen, is supplied. Others may be created with \fBnewwin\fR. - +arrays of characters representing all or part of a CRT screen. +A default window called \fBstdscr\fR, which is the size of the terminal +screen, is supplied. +Others may be created with \fBnewwin\fR. +.PP Note that \fBcurses\fR does not handle overlapping windows, that's done by -the \fBpanel\fR(3) library. This means that you can either use +the \fBpanel\fR(3) library. +This means that you can either use \fBstdscr\fR or divide the screen into tiled windows and not using -\fBstdscr\fR at all. Mixing the two will result in unpredictable, and -undesired, effects. - +\fBstdscr\fR at all. +Mixing the two will result in unpredictable, and undesired, effects. +.PP Windows are referred to by variables declared as \fBWINDOW *\fR. These data structures are manipulated with routines described here and -elsewhere in the \fBcurses\fR manual pages. Among which the most basic -routines are \fBmove\fR and \fBaddch\fR. More general versions of +elsewhere in the \fBncurses\fR manual pages. +Among those, the most basic +routines are \fBmove\fR and \fBaddch\fR. +More general versions of these routines are included with names beginning with \fBw\fR, -allowing the user to specify a window. The routines not beginning -with \fBw\fR affect \fBstdscr\fR.) - +allowing the user to specify a window. +The routines not beginning +with \fBw\fR affect \fBstdscr\fR. +.PP After using routines to manipulate a window, \fBrefresh\fR is called, telling \fBcurses\fR to make the user's CRT screen look like -\fBstdscr\fR. The characters in a window are actually of type +\fBstdscr\fR. +The characters in a window are actually of type \fBchtype\fR, (character and attribute data) so that other information about the character may also be stored with each character. - -Special windows called \fIpads\fR may also be manipulated. These are windows +.PP +Special windows called \fIpads\fR may also be manipulated. +These are windows which are not constrained to the size of the screen and whose contents need not -be completely displayed. See \fBcurs_pad\fR(3) for more information. - +be completely displayed. +See \fBcurs_pad\fR(3) for more information. +.PP In addition to drawing characters on the screen, video attributes and colors may be supported, causing the characters to show up in such modes as underlined, in reverse video, or in color on terminals that support such -display enhancements. Line drawing characters may be specified to be output. +display enhancements. +Line drawing characters may be specified to be output. On input, \fBcurses\fR is also able to translate arrow and function keys that -transmit escape sequences into single values. The video attributes, line +transmit escape sequences into single values. +The video attributes, line drawing characters, and input values use names, defined in \fB<curses.h>\fR, such as \fBA_REVERSE\fR, \fBACS_HLINE\fR, and \fBKEY_LEFT\fR. - +.PP If the environment variables \fBLINES\fR and \fBCOLUMNS\fR are set, or if the program is executing in a window environment, line and column information in -the environment will override information read by \fIterminfo\fR. This would -effect a program running in an AT&T 630 layer, for example, where the size of a +the environment will override information read by \fIterminfo\fR. +This would affect a program running in an AT&T 630 layer, +for example, where the size of a screen is changeable (see \fBENVIRONMENT\fR). - +.PP If the environment variable \fBTERMINFO\fR is defined, any program using \fBcurses\fR checks for a local terminal definition before checking in the -standard place. For example, if \fBTERM\fR is set to \fBatt4424\fR, then the +standard place. +For example, if \fBTERM\fR is set to \fBatt4424\fR, then the compiled terminal definition is found in - +.sp \fB\*d/a/att4424\fR. - +.sp (The \fBa\fR is copied from the first letter of \fBatt4424\fR to avoid creation of huge directories.) However, if \fBTERMINFO\fR is set to \fB$HOME/myterms\fR, \fBcurses\fR first checks - +.sp \fB$HOME/myterms/a/att4424\fR, - +.sp and if that fails, it then checks - +.sp \fB\*d/a/att4424\fR. - +.sp This is useful for developing experimental definitions or when write permission in \fB\*d\fR is not available. - +.PP The integer variables \fBLINES\fR and \fBCOLS\fR are defined in \fB<curses.h>\fR and will be filled in by \fBinitscr\fR with the size of the -screen. The constants \fBTRUE\fR and \fBFALSE\fR have the values \fB1\fR and +screen. +The constants \fBTRUE\fR and \fBFALSE\fR have the values \fB1\fR and \fB0\fR, respectively. - +.PP The \fBcurses\fR routines also define the \fBWINDOW *\fR variable \fBcurscr\fR which is used for certain low-level operations like clearing and redrawing a -screen containing garbage. The \fBcurscr\fR can be used in only a few -routines. - +screen containing garbage. +The \fBcurscr\fR can be used in only a few routines. +.\" .SS Routine and Argument Names -Many \fBcurses\fR routines have two or more versions. The routines prefixed -with \fBw\fR require a window argument. The routines prefixed with \fBp\fR -require a pad argument. Those without a prefix generally use \fBstdscr\fR. - +Many \fBcurses\fR routines have two or more versions. +The routines prefixed with \fBw\fR require a window argument. +The routines prefixed with \fBp\fR require a pad argument. +Those without a prefix generally use \fBstdscr\fR. +.PP The routines prefixed with \fBmv\fR require a \fIy\fR and \fIx\fR -coordinate to move to before performing the appropriate action. The -\fBmv\fR routines imply a call to \fBmove\fR before the call to the -other routine. The coordinate \fIy\fR always refers to the row (of -the window), and \fIx\fR always refers to the column. The upper -left-hand corner is always (0,0), not (1,1). - +coordinate to move to before performing the appropriate action. +The \fBmv\fR routines imply a call to \fBmove\fR before the call to the +other routine. +The coordinate \fIy\fR always refers to the row (of +the window), and \fIx\fR always refers to the column. +The upper left-hand corner is always (0,0), not (1,1). +.PP The routines prefixed with \fBmvw\fR take both a window argument and -\fIx\fR and \fIy\fR coordinates. The window argument is always -specified before the coordinates. - +\fIx\fR and \fIy\fR coordinates. +The window argument is always specified before the coordinates. +.PP In each case, \fIwin\fR is the window affected, and \fIpad\fR is the pad affected; \fIwin\fR and \fIpad\fR are always pointers to type \fBWINDOW\fR. - +.PP Option setting routines require a Boolean flag \fIbf\fR with the value -\fBTRUE\fR or \fBFALSE\fR; \fIbf\fR is always of type \fBbool\fR. The -variables \fIch\fR and \fIattrs\fR below are always of type -\fBchtype\fR. The types \fBWINDOW\fR, \fBSCREEN\fR, \fBbool\fR, and -\fBchtype\fR are defined in \fB<curses.h>\fR. The type \fBTERMINAL\fR -is defined in \fB<term.h>\fR. All other arguments are integers. - +\fBTRUE\fR or \fBFALSE\fR; \fIbf\fR is always of type \fBbool\fR. +Most of the data types used in the library routines, +such as \fBWINDOW\fR, \fBSCREEN\fR, \fBbool\fR, and \fBchtype\fR +are defined in \fB<curses.h>\fR. +Types used for the terminfo routines such as +\fBTERMINAL\fR are defined in \fB<term.h>\fR. +.PP +This manual page describes functions which may appear in any configuration +of the library. +There are two common configurations of the library: +.RS +.TP 5 +ncurses +the "normal" library, which handles 8-bit characters. +The normal (8-bit) library stores characters combined with attributes +in \fBchtype\fP data. +.IP +Attributes alone (no corresponding character) may be stored in \fBchtype\fP +or the equivalent \fBattr_t\fP data. +In either case, the data is stored in something like an integer. +.IP +Each cell (row and column) in a \fBWINDOW\fP is stored as a \fBchtype\fP. +.TP 5 +ncursesw +the so-called "wide" library, which handles multibyte characters +The "wide" library includes all of the calls from the "normal" library. +The "wide" library includes all of the calls from the "normal" library. +It adds about one third more calls using data types which store +multibyte characters: +.RS +.TP 5 +.B cchar_t +corresponds to \fBchtype\fP. +However it is a structure, because more data is stored than can fit into +an integer. +The characters are large enough to require a full integer value - and there +may be more than one character per cell. +The video attributes and color are stored in separate fields of the structure. +.IP +Each cell (row and column) in a \fBWINDOW\fP is stored as a \fBcchar_t\fP. +.TP 5 +.B wchar_t +stores a "wide" character. +Like \fBchtype\fP, this may be an integer. +.TP 5 +.B wint_t +stores a \fBwchar_t\fP or \fBWEOF\fP - not the same, though both may have +the same size. +.RE +.IP +The "wide" library provides new functions which are analogous to +functions in the "normal" library. +There is a naming convention which relates many of the normal/wide variants: +a "_w" is inserted into the name. +For example, \fBwaddch\fP becomes \fBwadd_wch\fP. +.IP +ncursesw is not currently supported on OpenBSD. +.RE +.PP +.\" .SS Routine Name Index The following table lists each \fBcurses\fR routine and the name of -the manual page on which it is described. Routines flagged with `*' +the manual page on which it is described. +Routines flagged with `*' are ncurses-specific, not described by XPG4 or present in SVr4. - +.PP .TS center tab(/); l l @@ -196,16 +291,32 @@ l l . = COLOR_PAIR/\fBcurs_color\fR(3) PAIR_NUMBER/\fBcurs_attr\fR(3) +_nc_free_and_exit/\fBcurs_memleaks\fR(3)* +_nc_freeall/\fBcurs_memleaks\fR(3)* +_nc_tracebits/\fBcurs_trace\fR(3)* +_traceattr/\fBcurs_trace\fR(3)* +_traceattr2/\fBcurs_trace\fR(3)* +_tracechar/\fBcurs_trace\fR(3)* +_tracechtype/\fBcurs_trace\fR(3)* +_tracechtype2/\fBcurs_trace\fR(3)* +_tracedump/\fBcurs_trace\fR(3)* +_tracef/\fBcurs_trace\fR(3)* +_tracemouse/\fBcurs_trace\fR(3)* +add_wch/\fBcurs_add_wch\fR(3) +add_wchnstr/\fBcurs_add_wchstr\fR(3) +add_wchstr/\fBcurs_add_wchstr\fR(3) addch/\fBcurs_addch\fR(3) addchnstr/\fBcurs_addchstr\fR(3) addchstr/\fBcurs_addchstr\fR(3) addnstr/\fBcurs_addstr\fR(3) +addnwstr/\fBcurs_addwstr\fR(3) +addstr/\fBcurs_addstr\fR(3) +addwstr/\fBcurs_addwstr\fR(3) assume_default_colors/\fBdefault_colors\fR(3)* attr_get/\fBcurs_attr\fR(3) attr_off/\fBcurs_attr\fR(3) attr_on/\fBcurs_attr\fR(3) attr_set/\fBcurs_attr\fR(3) -addstr/\fBcurs_addstr\fR(3) attroff/\fBcurs_attr\fR(3) attron/\fBcurs_attr\fR(3) attrset/\fBcurs_attr\fR(3) @@ -213,8 +324,12 @@ baudrate/\fBcurs_termattrs\fR(3) beep/\fBcurs_beep\fR(3) bkgd/\fBcurs_bkgd\fR(3) bkgdset/\fBcurs_bkgd\fR(3) +bkgrnd/\fBcurs_bkgrnd\fR(3) +bkgrndset/\fBcurs_bkgrnd\fR(3) border/\fBcurs_border\fR(3) +border_set/\fBcurs_border_set\fR(3) box/\fBcurs_border\fR(3) +box_set/\fBcurs_border_set\fR(3) can_change_color/\fBcurs_color\fR(3) cbreak/\fBcurs_inopts\fR(3) chgat/\fBcurs_attr\fR(3) @@ -240,19 +355,35 @@ derwin/\fBcurs_window\fR(3) doupdate/\fBcurs_refresh\fR(3) dupwin/\fBcurs_window\fR(3) echo/\fBcurs_inopts\fR(3) +echo_wchar/\fBcurs_add_wch\fR(3) echochar/\fBcurs_addch\fR(3) endwin/\fBcurs_initscr\fR(3) erase/\fBcurs_clear\fR(3) erasechar/\fBcurs_termattrs\fR(3) +erasewchar/\fBcurs_termattrs\fR(3) filter/\fBcurs_util\fR(3) flash/\fBcurs_beep\fR(3) flushinp/\fBcurs_util\fR(3) +get_wch/\fBcurs_get_wch\fR(3) +get_wstr/\fBcurs_get_wstr\fR(3) +getattrs/\fBcurs_attr\fR(3) +getbegx/\fBcurs_legacy\fR(3)* +getbegy/\fBcurs_legacy\fR(3)* getbegyx/\fBcurs_getyx\fR(3) getbkgd/\fBcurs_bkgd\fR(3) +getbkgrnd/\fBcurs_bkgrnd\fR(3) +getcchar/\fBcurs_getcchar\fR(3) getch/\fBcurs_getch\fR(3) +getcurx/\fBcurs_legacy\fR(3)* +getcury/\fBcurs_legacy\fR(3)* +getmaxx/\fBcurs_legacy\fR(3)* +getmaxy/\fBcurs_legacy\fR(3)* getmaxyx/\fBcurs_getyx\fR(3) getmouse/\fBcurs_mouse\fR(3)* +getn_wstr/\fBcurs_get_wstr\fR(3) getnstr/\fBcurs_getstr\fR(3) +getparx/\fBcurs_legacy\fR(3)* +getpary/\fBcurs_legacy\fR(3)* getparyx/\fBcurs_getyx\fR(3) getstr/\fBcurs_getstr\fR(3) getsyx/\fBcurs_kernel\fR(3) @@ -264,9 +395,13 @@ has_ic/\fBcurs_termattrs\fR(3) has_il/\fBcurs_termattrs\fR(3) has_key/\fBcurs_getch\fR(3)* hline/\fBcurs_border\fR(3) +hline_set/\fBcurs_border_set\fR(3) idcok/\fBcurs_outopts\fR(3) idlok/\fBcurs_outopts\fR(3) immedok/\fBcurs_outopts\fR(3) +in_wch/\fBcurs_in_wch\fR(3) +in_wchnstr/\fBcurs_in_wchstr\fR(3) +in_wchstr/\fBcurs_in_wchstr\fR(3) inch/\fBcurs_inch\fR(3) inchnstr/\fBcurs_inchstr\fR(3) inchstr/\fBcurs_inchstr\fR(3) @@ -274,6 +409,10 @@ init_color/\fBcurs_color\fR(3) init_pair/\fBcurs_color\fR(3) initscr/\fBcurs_initscr\fR(3) innstr/\fBcurs_instr\fR(3) +innwstr/\fBcurs_inwstr\fR(3) +ins_nwstr/\fBcurs_ins_wstr\fR(3) +ins_wch/\fBcurs_ins_wch\fR(3) +ins_wstr/\fBcurs_ins_wstr\fR(3) insch/\fBcurs_insch\fR(3) insdelln/\fBcurs_deleteln\fR(3) insertln/\fBcurs_deleteln\fR(3) @@ -281,14 +420,29 @@ insnstr/\fBcurs_insstr\fR(3) insstr/\fBcurs_insstr\fR(3) instr/\fBcurs_instr\fR(3) intrflush/\fBcurs_inopts\fR(3) +inwstr/\fBcurs_inwstr\fR(3) +is_cleared/\fBcurs_opaque\fR(3)* +is_idcok/\fBcurs_opaque\fR(3)* +is_idlok/\fBcurs_opaque\fR(3)* +is_immedok/\fBcurs_opaque\fR(3)* +is_keypad/\fBcurs_opaque\fR(3)* +is_leaveok/\fBcurs_opaque\fR(3)* is_linetouched/\fBcurs_touch\fR(3) +is_nodelay/\fBcurs_opaque\fR(3)* +is_notimeout/\fBcurs_opaque\fR(3)* +is_scrollok/\fBcurs_opaque\fR(3)* +is_syncok/\fBcurs_opaque\fR(3)* +is_term_resized/\fBresizeterm\fR(3)* is_wintouched/\fBcurs_touch\fR(3) isendwin/\fBcurs_initscr\fR(3) +key_defined/\fBkey_defined\fR(3)* +key_name/\fBcurs_util\fR(3) keybound/\fBkeybound\fR(3)* keyname/\fBcurs_util\fR(3) keyok/\fBkeyok\fR(3)* keypad/\fBcurs_inopts\fR(3) killchar/\fBcurs_termattrs\fR(3) +killwchar/\fBcurs_termattrs\fR(3) leaveok/\fBcurs_outopts\fR(3) longname/\fBcurs_termattrs\fR(3) mcprint/\fBcurs_print\fR(3)* @@ -297,53 +451,89 @@ mouse_trafo/\fBcurs_mouse\fR(3)* mouseinterval/\fBcurs_mouse\fR(3)* mousemask/\fBcurs_mouse\fR(3)* move/\fBcurs_move\fR(3) +mvadd_wch/\fBcurs_add_wch\fR(3) +mvadd_wchnstr/\fBcurs_add_wchstr\fR(3) +mvadd_wchstr/\fBcurs_add_wchstr\fR(3) mvaddch/\fBcurs_addch\fR(3) mvaddchnstr/\fBcurs_addchstr\fR(3) mvaddchstr/\fBcurs_addchstr\fR(3) mvaddnstr/\fBcurs_addstr\fR(3) +mvaddnwstr/\fBcurs_addwstr\fR(3) mvaddstr/\fBcurs_addstr\fR(3) +mvaddwstr/\fBcurs_addwstr\fR(3) mvchgat/\fBcurs_attr\fR(3) mvcur/\fBterminfo\fR(3) mvdelch/\fBcurs_delch\fR(3) mvderwin/\fBcurs_window\fR(3) +mvget_wch/\fBcurs_get_wch\fR(3) +mvget_wstr/\fBcurs_get_wstr\fR(3) mvgetch/\fBcurs_getch\fR(3) +mvgetn_wstr/\fBcurs_get_wstr\fR(3) mvgetnstr/\fBcurs_getstr\fR(3) mvgetstr/\fBcurs_getstr\fR(3) mvhline/\fBcurs_border\fR(3) +mvhline_set/\fBcurs_border_set\fR(3) +mvin_wch/\fBcurs_in_wch\fR(3) +mvin_wchnstr/\fBcurs_in_wchstr\fR(3) +mvin_wchstr/\fBcurs_in_wchstr\fR(3) mvinch/\fBcurs_inch\fR(3) mvinchnstr/\fBcurs_inchstr\fR(3) mvinchstr/\fBcurs_inchstr\fR(3) mvinnstr/\fBcurs_instr\fR(3) +mvinnwstr/\fBcurs_inwstr\fR(3) +mvins_nwstr/\fBcurs_ins_wstr\fR(3) +mvins_wch/\fBcurs_ins_wch\fR(3) +mvins_wstr/\fBcurs_ins_wstr\fR(3) mvinsch/\fBcurs_insch\fR(3) mvinsnstr/\fBcurs_insstr\fR(3) mvinsstr/\fBcurs_insstr\fR(3) mvinstr/\fBcurs_instr\fR(3) +mvinwstr/\fBcurs_inwstr\fR(3) mvprintw/\fBcurs_printw\fR(3) mvscanw/\fBcurs_scanw\fR(3) mvvline/\fBcurs_border\fR(3) +mvvline_set/\fBcurs_border_set\fR(3) +mvwadd_wch/\fBcurs_add_wch\fR(3) +mvwadd_wchnstr/\fBcurs_add_wchstr\fR(3) +mvwadd_wchstr/\fBcurs_add_wchstr\fR(3) mvwaddch/\fBcurs_addch\fR(3) mvwaddchnstr/\fBcurs_addchstr\fR(3) mvwaddchstr/\fBcurs_addchstr\fR(3) mvwaddnstr/\fBcurs_addstr\fR(3) +mvwaddnwstr/\fBcurs_addwstr\fR(3) mvwaddstr/\fBcurs_addstr\fR(3) +mvwaddwstr/\fBcurs_addwstr\fR(3) mvwchgat/\fBcurs_attr\fR(3) mvwdelch/\fBcurs_delch\fR(3) +mvwget_wch/\fBcurs_get_wch\fR(3) +mvwget_wstr/\fBcurs_get_wstr\fR(3) mvwgetch/\fBcurs_getch\fR(3) +mvwgetn_wstr/\fBcurs_get_wstr\fR(3) mvwgetnstr/\fBcurs_getstr\fR(3) mvwgetstr/\fBcurs_getstr\fR(3) mvwhline/\fBcurs_border\fR(3) +mvwhline_set/\fBcurs_border_set\fR(3) mvwin/\fBcurs_window\fR(3) +mvwin_wch/\fBcurs_in_wch\fR(3) +mvwin_wchnstr/\fBcurs_in_wchstr\fR(3) +mvwin_wchstr/\fBcurs_in_wchstr\fR(3) mvwinch/\fBcurs_inch\fR(3) mvwinchnstr/\fBcurs_inchstr\fR(3) mvwinchstr/\fBcurs_inchstr\fR(3) mvwinnstr/\fBcurs_instr\fR(3) +mvwinnwstr/\fBcurs_inwstr\fR(3) +mvwins_nwstr/\fBcurs_ins_wstr\fR(3) +mvwins_wch/\fBcurs_ins_wch\fR(3) +mvwins_wstr/\fBcurs_ins_wstr\fR(3) mvwinsch/\fBcurs_insch\fR(3) mvwinsnstr/\fBcurs_insstr\fR(3) mvwinsstr/\fBcurs_insstr\fR(3) mvwinstr/\fBcurs_instr\fR(3) +mvwinwstr/\fBcurs_inwstr\fR(3) mvwprintw/\fBcurs_printw\fR(3) mvwscanw/\fBcurs_scanw\fR(3) mvwvline/\fBcurs_border\fR(3) +mvwvline_set/\fBcurs_border_set\fR(3) napms/\fBcurs_kernel\fR(3) newpad/\fBcurs_pad\fR(3) newterm/\fBcurs_initscr\fR(3) @@ -352,6 +542,7 @@ nl/\fBcurs_outopts\fR(3) nocbreak/\fBcurs_inopts\fR(3) nodelay/\fBcurs_inopts\fR(3) noecho/\fBcurs_inopts\fR(3) +nofilter/\fBcurs_util\fR(3)* nonl/\fBcurs_outopts\fR(3) noqiflush/\fBcurs_inopts\fR(3) noraw/\fBcurs_inopts\fR(3) @@ -386,6 +577,7 @@ scroll/\fBcurs_scroll\fR(3) scrollok/\fBcurs_outopts\fR(3) set_curterm/\fBterminfo\fR(3) set_term/\fBcurs_initscr\fR(3) +setcchar/\fBcurs_getcchar\fR(3) setscrreg/\fBcurs_outopts\fR(3) setsyx/\fBcurs_kernel\fR(3) setterm/\fBterminfo\fR(3) @@ -412,6 +604,7 @@ start_color/\fBcurs_color\fR(3) subpad/\fBcurs_pad\fR(3) subwin/\fBcurs_window\fR(3) syncok/\fBcurs_window\fR(3) +term_attrs/\fBcurs_termattrs\fR(3) termattrs/\fBcurs_termattrs\fR(3) termname/\fBcurs_termattrs\fR(3) tgetent/\fBtermcap\fR(3) @@ -428,26 +621,37 @@ touchwin/\fBcurs_touch\fR(3) tparm/\fBterminfo\fR(3) tputs/\fBtermcap\fR(3) tputs/\fBterminfo\fR(3) +trace/\fBcurs_trace\fR(3)* typeahead/\fBcurs_inopts\fR(3) unctrl/\fBcurs_util\fR(3) +unget_wch/\fBcurs_get_wch\fR(3) ungetch/\fBcurs_getch\fR(3) ungetmouse/\fBcurs_mouse\fR(3)* untouchwin/\fBcurs_touch\fR(3) use_default_colors/\fBdefault_colors\fR(3)* use_env/\fBcurs_util\fR(3) use_extended_names/\fBcurs_extend\fR(3)* +use_legacy_coding/\fBlegacy_coding\fR(3)* +vid_attr/\fBterminfo\fR(3) +vid_puts/\fBterminfo\fR(3) vidattr/\fBterminfo\fR(3) vidputs/\fBterminfo\fR(3) vline/\fBcurs_border\fR(3) +vline_set/\fBcurs_border_set\fR(3) vw_printw/\fBcurs_printw\fR(3) vw_scanw/\fBcurs_scanw\fR(3) vwprintw/\fBcurs_printw\fR(3) vwscanw/\fBcurs_scanw\fR(3) +wadd_wch/\fBcurs_add_wch\fR(3) +wadd_wchnstr/\fBcurs_add_wchstr\fR(3) +wadd_wchstr/\fBcurs_add_wchstr\fR(3) waddch/\fBcurs_addch\fR(3) waddchnstr/\fBcurs_addchstr\fR(3) waddchstr/\fBcurs_addchstr\fR(3) waddnstr/\fBcurs_addstr\fR(3) +waddnwstr/\fBcurs_addwstr\fR(3) waddstr/\fBcurs_addstr\fR(3) +waddwstr/\fBcurs_addwstr\fR(3) wattr_get/\fBcurs_attr\fR(3) wattr_off/\fBcurs_attr\fR(3) wattr_on/\fBcurs_attr\fR(3) @@ -457,7 +661,10 @@ wattron/\fBcurs_attr\fR(3) wattrset/\fBcurs_attr\fR(3) wbkgd/\fBcurs_bkgd\fR(3) wbkgdset/\fBcurs_bkgd\fR(3) +wbkgrnd/\fBcurs_bkgrnd\fR(3) +wbkgrndset/\fBcurs_bkgrnd\fR(3) wborder/\fBcurs_border\fR(3) +wborder_set/\fBcurs_border_set\fR(3) wchgat/\fBcurs_attr\fR(3) wclear/\fBcurs_clear\fR(3) wclrtobot/\fBcurs_clear\fR(3) @@ -466,23 +673,37 @@ wcolor_set/\fBcurs_attr\fR(3) wcursyncup/\fBcurs_window\fR(3) wdelch/\fBcurs_delch\fR(3) wdeleteln/\fBcurs_deleteln\fR(3) +wecho_wchar/\fBcurs_add_wch\fR(3) wechochar/\fBcurs_addch\fR(3) wenclose/\fBcurs_mouse\fR(3)* werase/\fBcurs_clear\fR(3) +wget_wch/\fBcurs_get_wch\fR(3) +wget_wstr/\fBcurs_get_wstr\fR(3) +wgetbkgrnd/\fBcurs_bkgrnd\fR(3) wgetch/\fBcurs_getch\fR(3) +wgetn_wstr/\fBcurs_get_wstr\fR(3) wgetnstr/\fBcurs_getstr\fR(3) wgetstr/\fBcurs_getstr\fR(3) whline/\fBcurs_border\fR(3) +whline_set/\fBcurs_border_set\fR(3) +win_wch/\fBcurs_in_wch\fR(3) +win_wchnstr/\fBcurs_in_wchstr\fR(3) +win_wchstr/\fBcurs_in_wchstr\fR(3) winch/\fBcurs_inch\fR(3) winchnstr/\fBcurs_inchstr\fR(3) winchstr/\fBcurs_inchstr\fR(3) winnstr/\fBcurs_instr\fR(3) +winnwstr/\fBcurs_inwstr\fR(3) +wins_nwstr/\fBcurs_ins_wstr\fR(3) +wins_wch/\fBcurs_ins_wch\fR(3) +wins_wstr/\fBcurs_ins_wstr\fR(3) winsch/\fBcurs_insch\fR(3) winsdelln/\fBcurs_deleteln\fR(3) winsertln/\fBcurs_deleteln\fR(3) winsnstr/\fBcurs_insstr\fR(3) winsstr/\fBcurs_insstr\fR(3) winstr/\fBcurs_instr\fR(3) +winwstr/\fBcurs_inwstr\fR(3) wmouse_trafo/\fBcurs_mouse\fR(3)* wmove/\fBcurs_move\fR(3) wnoutrefresh/\fBcurs_refresh\fR(3) @@ -499,30 +720,32 @@ wsyncdown/\fBcurs_window\fR(3) wsyncup/\fBcurs_window\fR(3) wtimeout/\fBcurs_inopts\fR(3) wtouchln/\fBcurs_touch\fR(3) +wunctrl/\fBcurs_util\fR(3) wvline/\fBcurs_border\fR(3) +wvline_set/\fBcurs_border_set\fR(3) .TE .SH RETURN VALUE Routines that return an integer return \fBERR\fR upon failure and an integer value other than \fBERR\fR upon successful completion, unless otherwise noted in the routine descriptions. - +.PP All macros return the value of the \fBw\fR version, except \fBsetscrreg\fR, -\fBwsetscrreg\fR, \fBgetyx\fR, \fBgetbegyx\fR, and \fBgetmaxyx\fR. The return -values of \fBsetscrreg\fR, \fBwsetscrreg\fR, \fBgetyx\fR, \fBgetbegyx\fR, and +\fBwsetscrreg\fR, \fBgetyx\fR, \fBgetbegyx\fR, and \fBgetmaxyx\fR. +The return values of \fBsetscrreg\fR, \fBwsetscrreg\fR, \fBgetyx\fR, \fBgetbegyx\fR, and \fBgetmaxyx\fR are undefined (i.e., these should not be used as the right-hand side of assignment statements). - +.PP Routines that return pointers return \fBNULL\fR on error. .SH ENVIRONMENT The following environment symbols are useful for customizing the -runtime behavior of the \fBcurses\fR library. The most important -ones have already been discussed in detail. +runtime behavior of the \fBncurses\fR library. +The most important ones have been already discussed in detail. .TP 5 BAUDRATE The debugging library checks this environment symbol when the application has redirected output to a file. The symbol's numeric value is used for the baudrate. -If no value is found, \fBcurses\fR uses 9600. +If no value is found, \fBncurses\fR uses 9600. This allows testers to construct repeatable test-cases that take into account costs that depend on baudrate. .TP 5 @@ -536,45 +759,55 @@ COLUMNS Specify the width of the screen in characters. Applications running in a windowing environment usually are able to obtain the width of the window in which they are executing. -If neither the $COLUMNS value nor the terminal's screen size is available, -\fBcurses\fR uses the size which may be specified in the terminfo database +If neither the \fBCOLUMNS\fP value nor the terminal's screen size is available, +\fBncurses\fR uses the size which may be specified in the terminfo database (i.e., the \fBcols\fR capability). - +.IP It is important that your application use a correct size for the screen. -However, this is not always possible because your application may be +This is not always possible because your application may be running on a host which does not honor NAWS (Negotiations About Window Size), or because you are temporarily running as another user. - -Either COLUMNS or LINES symbols may be specified independently. +However, setting \fBCOLUMNS\fP and/or \fBLINES\fP overrides the library's +use of the screen size obtained from the operating system. +.IP +Either \fBCOLUMNS\fP or \fBLINES\fP symbols may be specified independently. This is mainly useful to circumvent legacy misfeatures of terminal descriptions, e.g., xterm which commonly specifies a 65 line screen. For best results, \fBlines\fR and \fBcols\fR should not be specified in a terminal description for terminals which are run as emulations. - -Use the \fBuse_env\fR function to disable this feature. +.IP +Use the \fBuse_env\fR function to disable all use of external environment +(including system calls) to determine the screen size. .TP 5 ESCDELAY -Specifies the total time, in milliseconds, for which curses will +Specifies the total time, in milliseconds, for which ncurses will await a character sequence, e.g., a function key. The default value, 1000 milliseconds, is enough for most uses. However, it is made a variable to accommodate unusual applications. - +.IP The most common instance where you may wish to change this value is to work with slow hosts, e.g., running on a network. If the host cannot read characters rapidly enough, it will have the same effect as if the terminal did not send characters rapidly enough. The library will still see a timeout. - +.IP Note that xterm mouse events are built up from character sequences received from the xterm. If your application makes heavy use of multiple-clicking, you may wish to lengthen this default value because the timeout applies to the composed multi-click event as well as the individual clicks. +.IP +In addition to the environment variable, +this implementation provides a global variable with the same name. +Portable applications should not rely upon the presence of ESCDELAY +in either form, +but setting the environment variable rather than the global variable +does not create problems when compiling an application. .TP 5 HOME -Tells \fBcurses\fR where your home directory is. +Tells \fBncurses\fR where your home directory is. That is where it may read and write auxiliary terminal descriptions: - +.IP $HOME/.termcap .br $HOME/.terminfo @@ -588,16 +821,52 @@ This applies only to the OS/2 EMX port. It specifies the order of buttons on the mouse. OS/2 numbers a 3-button mouse inconsistently from other platforms: - +.sp 1 = left .br 2 = right .br 3 = middle. - +.sp This symbol lets you customize the mouse. The symbol must be three numeric digits 1-3 in any order, e.g., 123 or 321. -If it is not specified, \fBcurses\fR uses 132. +If it is not specified, \fBncurses\fR uses 132. +.TP 5 +NCURSES_ASSUMED_COLORS +Override the compiled-in assumption that the +terminal's default colors are white-on-black +(see \fBdefault_colors\fR(3)). +You may set the foreground and background color values with this environment +variable by proving a 2-element list: foreground,background. +For example, to tell ncurses to not assume anything +about the colors, set this to "-1,-1". +To make it green-on-black, set it to "2,0". +Any positive value from zero to the terminfo \fBmax_colors\fR value is allowed. +.TP 5 +NCURSES_GPM_TERMS +This applies only to ncurses configured to use the GPM interface. +.IP +If present, +the environment variable is a list of one or more terminal names +against which the TERM environment variable is matched. +Setting it to an empty value disables the GPM interface; +using the built-in support for xterm, etc. +.IP +If the environment variable is absent, +ncurses will attempt to open GPM if TERM contains "linux". +.TP 5 +NCURSES_NO_HARD_TABS +\fBNcurses\fP may use tabs as part of the cursor movement optimization. +In some cases, +your terminal driver may not handle these properly. +Set this environment variable to disable the feature. +You can also adjust your \fBstty\fP settings to avoid the problem. +.TP 5 +NCURSES_NO_MAGIC_COOKIES +Some terminals use a magic-cookie feature which requires special handling +to make highlighting and other video attributes display properly. +You can suppress the highlighting entirely for these terminals by +setting this environment variable. .TP 5 NCURSES_NO_PADDING Most of the terminal descriptions in the terminfo database are written @@ -615,29 +884,50 @@ it (or your application) must manage dataflow, preventing overruns. The cheapest solution (no hardware cost) is for your program to do this by pausing after operations that the terminal does slowly, such as clearing the display. - +.IP As a result, many terminal descriptions (including the vt100) -have delay times embedded. You may wish to use these descriptions, +have delay times embedded. +You may wish to use these descriptions, but not want to pay the performance penalty. - +.IP Set the NCURSES_NO_PADDING symbol to disable all but mandatory -padding. Mandatory padding is used as a part of special control +padding. +Mandatory padding is used as a part of special control sequences such as \fIflash\fR. .TP 5 NCURSES_NO_SETBUF -Normally \fBcurses\fR enables buffered output during terminal initialization. +Normally \fBncurses\fR enables buffered output during terminal initialization. This is done (as in SVr4 curses) for performance reasons. -For testing purposes, both of \fBcurses\fR and certain applications, -this feature is made optional. Setting the NCURSES_NO_SETBUF variable +For testing purposes, both of \fBncurses\fR and certain applications, +this feature is made optional. +Setting the NCURSES_NO_SETBUF variable disables output buffering, leaving the output in the original (usually line buffered) mode. .TP 5 +NCURSES_NO_UTF8_ACS +During initialization, the \fBncurses\fR library +checks for special cases where VT100 line-drawing (and the corresponding +alternate character set capabilities) described in the terminfo are known +to be missing. +Specifically, when running in a UTF-8 locale, +the Linux console emulator and the GNU screen program ignore these. +Ncurses checks the TERM environment variable for these. +For other special cases, you should set this environment variable. +Doing this tells ncurses to use Unicode values which correspond to +the VT100 line-drawing glyphs. +That works for the special cases cited, +and is likely to work for terminal emulators. +.IP +When setting this variable, you should set it to a nonzero value. +Setting it to zero (or to a nonnumber) +disables the special check for Linux and screen. +.TP 5 NCURSES_TRACE -During initialization, the \fBcurses\fR debugging library +During initialization, the \fBncurses\fR debugging library checks the NCURSES_TRACE symbol. -If it is defined, to a numeric value, \fBcurses\fR calls the \fBtrace\fR +If it is defined, to a numeric value, \fBncurses\fR calls the \fBtrace\fR function, using that value as the argument. - +.IP The argument values, which are defined in \fBcurses.h\fR, provide several types of information. When running with traces enabled, your application will write the @@ -648,25 +938,25 @@ Denotes your terminal type. Each terminal type is distinct, though many are similar. .TP 5 TERMCAP -If the \fBcurses\fR library has been configured with \fItermcap\fR -support, \fBcurses\fR will check for a terminal's description in +If the \fBncurses\fR library has been configured with \fItermcap\fR +support, \fBncurses\fR will check for a terminal's description in termcap form if it is not available in the terminfo database. - +.IP The TERMCAP symbol contains either a terminal description (with newlines stripped out), or a file name telling where the information denoted by the TERM symbol exists. -In either case, setting it directs \fBcurses\fR to ignore +In either case, setting it directs \fBncurses\fR to ignore the usual place for this information, e.g., /etc/termcap. .TP 5 TERMINFO -Overrides the directory in which \fBcurses\fR searches for your terminal +Overrides the directory in which \fBncurses\fR searches for your terminal description. This is the simplest, but not the only way to change the list of directories. The complete list of directories in order follows: .RS .TP 3 - -the last directory to which \fBcurses\fR wrote, if any, is searched first +the last directory to which \fBncurses\fR wrote, if any, is searched first .TP 3 - the directory specified by the TERMINFO symbol @@ -679,35 +969,36 @@ directories listed in the TERMINFO_DIRS symbol .TP 3 - one or more directories whose names are configured and compiled into the -curses library, e.g., -/usr/share/terminfo +ncurses library, e.g., +/usr/share/misc/terminfo .RE .TP 5 TERMINFO_DIRS Specifies a list of directories to search for terminal descriptions. -The list is separated by colons (i.e., ":"). +The list is separated by colons (i.e., ":") on Unix, semicolons on OS/2 EMX. All of the terminal descriptions are in terminfo form, which makes a subdirectory named for the first letter of the terminal names therein. .TP 5 TERMPATH -If TERMCAP does not hold a file name then \fBcurses\fR checks +If TERMCAP does not hold a file name then \fBncurses\fR checks the TERMPATH symbol. -This is a list of filenames separated by colons (i.e., ":"). -If the TERMPATH symbol is not set, \fBcurses\fR looks in the files -/etc/termcap, /usr/share/termcap and $HOME/.termcap, in that order. +This is a list of filenames separated by spaces or colons (i.e., ":") on Unix, semicolons on OS/2 EMX. +If the TERMPATH symbol is not set, \fBncurses\fR looks in the files +/etc/termcap, /usr/share/misc/termcap and $HOME/.termcap, in that order. .PP -The library will disregard the following variables when the -application uses setuid or setgid permissions: -$TERMCAP, $TERMINFO, $TERMINFO_DIRS, $TERMPATH, as well as $HOME. +The library may be configured to disregard the following variables when the +current user is the superuser (root), or if the application uses setuid or +setgid permissions: +$TERMINFO, $TERMINFO_DIRS, $TERMPATH, as well as $HOME. .SH FILES .TP 5 /usr/share/tabset directory containing initialization files for the terminal capability database -/usr/share/terminfo +/usr/share/misc/terminfo terminal capability database .SH SEE ALSO -\fBterminfo\fR(\*n), \fBterminfo\fR(3), and 3 pages whose names begin with -"curs_" for detailed routine descriptions. +\fBterminfo\fR(\*n) and related pages whose names begin "curs_" for detailed routine +descriptions. .TP /usr/share/doc/html/curses/ncurses-intro.html intro to ncurses. @@ -715,198 +1006,91 @@ intro to ncurses. /usr/share/doc/html/curses/hackguide.html ncurses hacker's guide. .SH EXTENSIONS -The \fBcurses\fR library can be compiled with an option (\fB-DUSE_GETCAP\fR) +The \fBncurses\fR library can be compiled with an option (\fB-DUSE_GETCAP\fR) that falls back to the old-style /etc/termcap file if the terminal setup code -cannot find a terminfo entry corresponding to \fBTERM\fR. Use of this feature +cannot find a terminfo entry corresponding to \fBTERM\fR. +Use of this feature is not recommended, as it essentially includes an entire termcap compiler in -the \fBcurses\fR startup code, at significant cost in core and startup cycles. - -The \fBcurses\fR library includes facilities for capturing mouse events on -certain terminals (including xterm). See the \fBcurs_mouse\fR(3) +the \fBncurses\fR startup code, at significant cost in core and startup cycles. +.PP +The \fBncurses\fR library includes facilities for capturing mouse events on +certain terminals (including xterm). +See the \fBcurs_mouse\fR(3) manual page for details. - -The \fBcurses\fR library includes facilities for responding to window +.PP +The \fBncurses\fR library includes facilities for responding to window resizing events, e.g., when running in an xterm. See the \fBresizeterm\fR(3) and \fBwresize\fR(3) manual pages for details. In addition, the library may be configured with a SIGWINCH handler. - -The \fBcurses\fR library extends the fixed set of function key capabilities +.PP +The \fBncurses\fR library extends the fixed set of function key capabilities of terminals by allowing the application designer to define additional key sequences at runtime. See the \fBdefine_key\fR(3) +\fBkey_defined\fR(3), and \fBkeyok\fR(3) manual pages for details. - -The \fBcurses\fR library can exploit the capabilities of terminals which +.PP +The \fBncurses\fR library can exploit the capabilities of terminals which implement the ISO-6429 SGR 39 and SGR 49 controls, which allow an application to reset the terminal to its original foreground and background colors. From the users' perspective, the application is able to draw colored text on a background whose color is set independently, providing better control over color contrasts. -See the \fBuse_default_colors\fR(3) manual page for details. - -The \fBcurses\fR library includes a function for directing application output -to a printer attached to the terminal device. See the \fBcurs_print\fR(3) -manual page for details. +See the \fBdefault_colors\fR(3) manual page for details. +.PP +The \fBncurses\fR library includes a function for directing application output +to a printer attached to the terminal device. +See the \fBcurs_print\fR(3) manual page for details. .SH PORTABILITY -The \fBcurses\fR library is intended to be BASE-level conformant with the XSI -Curses standard. Certain portions of the EXTENDED XSI Curses functionality -(including color support) are supported. The following EXTENDED XSI Curses -calls in support of wide (multibyte) characters are not yet implemented: -\fBadd_wch\fP, -\fBadd_wchnstr\fP, -\fBadd_wchstr\fP, -\fBaddnwstr\fP, -\fBaddwstr\fP, -\fBbkgrnd\fP, -\fBbkgrndset\fP, -\fBborder_set\fP, -\fBbox_set\fP, -\fBecho_wchar\fP, -\fBerasewchar\fP, -\fBget_wch\fP, -\fBget_wstr\fP, -\fBgetbkgrnd\fP, -\fBgetcchar\fP, -\fBgetn_wstr\fP, -\fBgetwchtype\fP, -\fBhline_set\fP, -\fBin_wch\fP, -\fBin_wchnstr\fP, -\fBin_wchstr\fP, -\fBinnwstr\fP, -\fBins_nwstr\fP, -\fBins_wch\fP, -\fBins_wstr\fP, -\fBinwchnstr\fP, -\fBinwchstr\fP, -\fBinwstr\fP, -\fBkey_name\fP, -\fBkillwchar\fP, -\fBmvadd_wch\fP, -\fBmvadd_wchnstr\fP, -\fBmvadd_wchstr\fP, -\fBmvaddnwstr\fP, -\fBmvaddwstr\fP, -\fBmvget_wch\fP, -\fBmvget_wstr\fP, -\fBmvgetn_wstr\fP, -\fBmvhline_set\fP, -\fBmvin_wch\fP, -\fBmvinnwstr\fP, -\fBmvins_nwstr\fP, -\fBmvins_wch\fP, -\fBmvins_wstr\fP, -\fBmvinwchnstr\fP, -\fBmvinwchstr\fP, -\fBmvinwchstr\fP, -\fBmvinwstr\fP, -\fBmvvline_set\fP, -\fBmvwadd_wch\fP, -\fBmvwadd_wchnstr\fP, -\fBmvwadd_wchstr\fP, -\fBmvwaddnwstr\fP, -\fBmvwaddwstr\fP, -\fBmvwget_ch\fP, -\fBmvwget_wch\fP, -\fBmvwget_wstr\fP, -\fBmvwgetn_wstr\fP, -\fBmvwhline_set\fP, -\fBmvwin_wch\fP, -\fBmvwin_wchnstr\fP, -\fBmvwin_wchstr\fP, -\fBmvwinnwstr\fP, -\fBmvwins_nwstr\fP, -\fBmvwins_wch\fP, -\fBmvwins_wstr\fP, -\fBmvwinwchnstr\fP, -\fBmvwinwstr\fP, -\fBmvwvline_set\fP, -\fBpecho_wchar\fP, -\fBsetcchar\fP, -\fBslk_wset\fP, -\fBterm_attrs\fP, -\fBunget_wch\fP, -\fBvhline_set\fP, -\fBvid_attr\fP, -\fBvid_puts\fP, -\fBvline_set\fP, -\fBwadd_wch\fP, -\fBwadd_wchnstr\fP, -\fBwadd_wchstr\fP, -\fBwaddnwstr\fP, -\fBwaddwstr\fP, -\fBwaddwstr\fP, -\fBwbkgrnd\fP, -\fBwbkgrndset\fP, -\fBwbkgrndset\fP, -\fBwborder_set\fP, -\fBwecho_wchar\fP, -\fBwecho_wchar\fP, -\fBwget_wch\fP, -\fBwget_wstr\fP, -\fBwgetbkgrnd\fP, -\fBwgetn_wstr\fP, -\fBwhline_set\fP, -\fBwin_wch\fP, -\fBwin_wchnstr\fP, -\fBwin_wchstr\fP, -\fBwinnwstr\fP, -\fBwins_nwstr\fP, -\fBwins_wch\fP, -\fBwins_wstr\fP, -\fBwinwchnstr\fP, -\fBwinwchstr\fP, -\fBwinwstr\fP, -\fBwunctrl\fP, -\fBwvline_set\fP, +The \fBncurses\fR library is intended to be BASE-level conformant with XSI +Curses. +The EXTENDED XSI Curses functionality +(including color support) is supported. .PP A small number of local differences (that is, individual differences between -the XSI Curses and \fBcurses\fR calls) are described in \fBPORTABILITY\fR +the XSI Curses and \fBncurses\fR calls) are described in \fBPORTABILITY\fR sections of the library man pages. .PP -The routine \fBhas_key\fR is not part of XPG4, nor is it present in SVr4. See -the \fBcurs_getch\fR(3) manual page for details. +This implementation also contains several extensions: +.RS 5 +.PP +The routine \fBhas_key\fR is not part of XPG4, nor is it present in SVr4. +See the \fBcurs_getch\fR(3) manual page for details. .PP -The routine \fBslk_attr\fR is not part of XPG4, nor is it present in SVr4. See -the \fBcurs_slk\fR(3) manual page for details. +The routine \fBslk_attr\fR is not part of XPG4, nor is it present in SVr4. +See the \fBcurs_slk\fR(3) manual page for details. .PP The routines \fBgetmouse\fR, \fBmousemask\fR, \fBungetmouse\fR, \fBmouseinterval\fR, and \fBwenclose\fR relating to mouse interfacing are not -part of XPG4, nor are they present in SVr4. See the \fBcurs_mouse\fR(3) -manual page for details. +part of XPG4, nor are they present in SVr4. +See the \fBcurs_mouse\fR(3) manual page for details. .PP -The routine \fBmcprint\fR was not present in any previous curses -implementation. See the \fBcurs_print\fR(3) manual page for details. +The routine \fBmcprint\fR was not present in any previous curses implementation. +See the \fBcurs_print\fR(3) manual page for details. .PP -The routine \fBwresize\fR is not part of XPG4, nor is it present in SVr4. See -the \fBwresize\fR(3) manual page for details. +The routine \fBwresize\fR is not part of XPG4, nor is it present in SVr4. +See the \fBwresize\fR(3) manual page for details. +.PP +The WINDOW structure's internal details can be hidden from application +programs. +See \fBcurs_opaque\fR(3) for the discussion of \fBis_scrollok\fR, etc. +.RE .PP In historic curses versions, delays embedded in the capabilities \fBcr\fR, \fBind\fR, \fBcub1\fR, \fBff\fR and \fBtab\fR activated corresponding delay -bits in the UNIX tty driver. In this implementation, all padding is done by -NUL sends. This method is slightly more expensive, but narrows the interface +bits in the UNIX tty driver. +In this implementation, all padding is done by sending NUL bytes. +This method is slightly more expensive, but narrows the interface to the UNIX kernel significantly and increases the package's portability correspondingly. -.PP -In the XSI standard and SVr4 manual pages, many entry points have prototype -arguments of the for \fBchar *const\fR (or \fBcchar_t *const\fR, or -\fBwchar_t *const\fR, or \fBvoid *const\fR). Depending on one's interpretation of the -ANSI C standard (see section 3.5.4.1), these declarations are either (a) -meaningless, or (b) meaningless and illegal. The declaration -\fBconst char *x\fR is a modifiable pointer to unmodifiable data, but -\fBchar *const x\fR' is -an unmodifiable pointer to modifiable data. Given that C passes arguments by -value, \fB<type> *const\fR as a formal type is at best dubious. Some compilers -choke on the prototypes. Therefore, in this implementation, they have been -changed to \fBconst <type> *\fR globally. .SH NOTES The header file \fB<curses.h>\fR automatically includes the header files \fB<stdio.h>\fR and \fB<unctrl.h>\fR. - -If standard output from a \fBcurses\fR program is re-directed to something -which is not a tty, screen updates will be directed to standard error. This -was an undocumented feature of AT&T System V Release 3 curses. +.PP +If standard output from a \fBncurses\fR program is re-directed to something +which is not a tty, screen updates will be directed to standard error. +This was an undocumented feature of AT&T System V Release 3 curses. .SH AUTHORS Zeyd M. Ben-Halim, Eric S. Raymond, Thomas E. Dickey. Based on pcurses by Pavel Curtis. diff --git a/lib/libcurses/curses.h b/lib/libcurses/curses.h index d632b4eb468..574b6906abb 100644 --- a/lib/libcurses/curses.h +++ b/lib/libcurses/curses.h @@ -1,7 +1,7 @@ -/* $OpenBSD: curses.h,v 1.59 2001/02/28 22:58:53 millert Exp $ */ +/* $OpenBSD: curses.h,v 1.60 2010/01/12 23:21:59 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,9 +31,10 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ -/* $From: curses.h.in,v 1.97 2000/12/10 02:00:24 tom Exp $ */ +/* $Id: curses.h,v 1.60 2010/01/12 23:21:59 nicm Exp $ */ #ifndef __NCURSES_H #define __NCURSES_H @@ -42,19 +43,19 @@ #define CURSES_H 1 /* This should be defined for the enhanced functionality to be visible. - * However, none of the wide-character (enhanced) functionality is implemented. + * However, some of the wide-character (enhanced) functionality is missing. * So we do not define it (yet). #define _XOPEN_CURSES 1 */ /* These are defined only in curses.h, and are used for conditional compiles */ #define NCURSES_VERSION_MAJOR 5 -#define NCURSES_VERSION_MINOR 2 -#define NCURSES_VERSION_PATCH 20010224 +#define NCURSES_VERSION_MINOR 7 +#define NCURSES_VERSION_PATCH 20081102 /* This is defined in more than one ncurses header, for identification */ #undef NCURSES_VERSION -#define NCURSES_VERSION "5.2" +#define NCURSES_VERSION "5.7" #if !defined(NCURSES_IMPEXP) # define NCURSES_IMPEXP /* nothing */ @@ -69,24 +70,82 @@ # define NCURSES_EXPORT_VAR(type) NCURSES_IMPEXP type #endif +/* + * Identify the mouse encoding version. + */ +#define NCURSES_MOUSE_VERSION 1 + +/* + * User-definable tweak to disable the include of <stdbool.h>. + */ +#ifndef NCURSES_ENABLE_STDBOOL_H +#define NCURSES_ENABLE_STDBOOL_H 1 +#endif + +/* + * NCURSES_ATTR_T is used to quiet compiler warnings when building ncurses + * configured using --disable-macros. + */ #ifdef NCURSES_NOMACROS +#ifndef NCURSES_ATTR_T #define NCURSES_ATTR_T attr_t #endif +#endif /* NCURSES_NOMACROS */ #ifndef NCURSES_ATTR_T #define NCURSES_ATTR_T int #endif +/* + * Expands to 'const' if ncurses is configured using --enable-const. Note that + * doing so makes it incompatible with other implementations of X/Open Curses. + */ #undef NCURSES_CONST #define NCURSES_CONST /*nothing*/ +#undef NCURSES_INLINE +#define NCURSES_INLINE inline + +/* + * The internal type used for color values + */ #undef NCURSES_COLOR_T #define NCURSES_COLOR_T short +/* + * Definition used to make WINDOW and similar structs opaque. + */ +#ifndef NCURSES_OPAQUE +#define NCURSES_OPAQUE 0 +#endif + +/* + * The internal type used for window dimensions. + */ #undef NCURSES_SIZE_T #define NCURSES_SIZE_T short -typedef unsigned long chtype; +/* + * Control whether tparm() supports varargs or fixed-parameter list. + */ +#undef NCURSES_TPARM_VARARGS +#define NCURSES_TPARM_VARARGS 1 + +/* + * NCURSES_CH_T is used in building the library, but not used otherwise in + * this header file, since that would make the normal/wide-character versions + * of the header incompatible. + */ +#undef NCURSES_CH_T +#define NCURSES_CH_T chtype + +#if 0 && defined(_LP64) +typedef unsigned chtype; +typedef unsigned mmask_t; +#else +typedef unsigned int chtype; +typedef unsigned long mmask_t; +#endif #include <stdio.h> #include <unctrl.h> @@ -95,9 +154,16 @@ typedef unsigned long chtype; #include <stddef.h> /* we want wchar_t */ #endif /* _XOPEN_SOURCE_EXTENDED */ -/* XSI and SVr4 specify that curses implements 'bool'. However, C++ may also +/* X/Open and SVr4 specify that curses implements 'bool'. However, C++ may also * implement it. If so, we must use the C++ compiler's type to avoid conflict * with other interfaces. + * + * A further complication is that <stdbool.h> may declare 'bool' to be a + * different type, such as an enum which is not necessarily compatible with + * C++. If we have <stdbool.h>, make 'bool' a macro, so users may #undef it. + * Otherwise, let it remain a typedef to avoid conflicts with other #define's. + * In either case, make a typedef for NCURSES_BOOL which can be used if needed + * from either C or C++. */ #undef TRUE @@ -106,17 +172,36 @@ typedef unsigned long chtype; #undef FALSE #define FALSE 0 -#if !defined(__cplusplus) +typedef unsigned char NCURSES_BOOL; + +#if defined(__cplusplus) /* __cplusplus, etc. */ + +/* use the C++ compiler's bool type */ +#define NCURSES_BOOL bool + +#else /* c89, c99, etc. */ + +#if NCURSES_ENABLE_STDBOOL_H +#include <stdbool.h> +/* use whatever the C compiler decides bool really is */ +#define NCURSES_BOOL bool +#else +/* there is no predefined bool - use our own */ #undef bool -typedef unsigned char bool; +#define bool NCURSES_BOOL #endif +#endif /* !__cplusplus, etc. */ + #ifdef __cplusplus extern "C" { +#define NCURSES_CAST(type,value) static_cast<type>(value) +#else +#define NCURSES_CAST(type,value) (type)(value) #endif /* - * XSI attributes. In the ncurses implementation, they are identical to the + * X/Open attributes. In the ncurses implementation, they are identical to the * A_ attributes. */ #define WA_ATTRIBUTES A_ATTRIBUTES @@ -138,9 +223,6 @@ extern "C" { #define WA_VERTICAL A_VERTICAL /* colors */ -extern NCURSES_EXPORT_VAR(int) COLORS; -extern NCURSES_EXPORT_VAR(int) COLOR_PAIRS; - #define COLOR_BLACK 0 #define COLOR_RED 1 #define COLOR_GREEN 2 @@ -152,47 +234,54 @@ extern NCURSES_EXPORT_VAR(int) COLOR_PAIRS; /* line graphics */ +#if 0 || 0 +NCURSES_WRAPPED_VAR(chtype*, acs_map); +#define acs_map (_nc_acs_map()) +#else extern NCURSES_EXPORT_VAR(chtype) acs_map[]; +#endif + +#define NCURSES_ACS(c) (acs_map[NCURSES_CAST(unsigned char,c)]) /* VT100 symbols begin here */ -#define ACS_ULCORNER (acs_map['l']) /* upper left corner */ -#define ACS_LLCORNER (acs_map['m']) /* lower left corner */ -#define ACS_URCORNER (acs_map['k']) /* upper right corner */ -#define ACS_LRCORNER (acs_map['j']) /* lower right corner */ -#define ACS_LTEE (acs_map['t']) /* tee pointing right */ -#define ACS_RTEE (acs_map['u']) /* tee pointing left */ -#define ACS_BTEE (acs_map['v']) /* tee pointing up */ -#define ACS_TTEE (acs_map['w']) /* tee pointing down */ -#define ACS_HLINE (acs_map['q']) /* horizontal line */ -#define ACS_VLINE (acs_map['x']) /* vertical line */ -#define ACS_PLUS (acs_map['n']) /* large plus or crossover */ -#define ACS_S1 (acs_map['o']) /* scan line 1 */ -#define ACS_S9 (acs_map['s']) /* scan line 9 */ -#define ACS_DIAMOND (acs_map['`']) /* diamond */ -#define ACS_CKBOARD (acs_map['a']) /* checker board (stipple) */ -#define ACS_DEGREE (acs_map['f']) /* degree symbol */ -#define ACS_PLMINUS (acs_map['g']) /* plus/minus */ -#define ACS_BULLET (acs_map['~']) /* bullet */ +#define ACS_ULCORNER NCURSES_ACS('l') /* upper left corner */ +#define ACS_LLCORNER NCURSES_ACS('m') /* lower left corner */ +#define ACS_URCORNER NCURSES_ACS('k') /* upper right corner */ +#define ACS_LRCORNER NCURSES_ACS('j') /* lower right corner */ +#define ACS_LTEE NCURSES_ACS('t') /* tee pointing right */ +#define ACS_RTEE NCURSES_ACS('u') /* tee pointing left */ +#define ACS_BTEE NCURSES_ACS('v') /* tee pointing up */ +#define ACS_TTEE NCURSES_ACS('w') /* tee pointing down */ +#define ACS_HLINE NCURSES_ACS('q') /* horizontal line */ +#define ACS_VLINE NCURSES_ACS('x') /* vertical line */ +#define ACS_PLUS NCURSES_ACS('n') /* large plus or crossover */ +#define ACS_S1 NCURSES_ACS('o') /* scan line 1 */ +#define ACS_S9 NCURSES_ACS('s') /* scan line 9 */ +#define ACS_DIAMOND NCURSES_ACS('`') /* diamond */ +#define ACS_CKBOARD NCURSES_ACS('a') /* checker board (stipple) */ +#define ACS_DEGREE NCURSES_ACS('f') /* degree symbol */ +#define ACS_PLMINUS NCURSES_ACS('g') /* plus/minus */ +#define ACS_BULLET NCURSES_ACS('~') /* bullet */ /* Teletype 5410v1 symbols begin here */ -#define ACS_LARROW (acs_map[',']) /* arrow pointing left */ -#define ACS_RARROW (acs_map['+']) /* arrow pointing right */ -#define ACS_DARROW (acs_map['.']) /* arrow pointing down */ -#define ACS_UARROW (acs_map['-']) /* arrow pointing up */ -#define ACS_BOARD (acs_map['h']) /* board of squares */ -#define ACS_LANTERN (acs_map['i']) /* lantern symbol */ -#define ACS_BLOCK (acs_map['0']) /* solid square block */ +#define ACS_LARROW NCURSES_ACS(',') /* arrow pointing left */ +#define ACS_RARROW NCURSES_ACS('+') /* arrow pointing right */ +#define ACS_DARROW NCURSES_ACS('.') /* arrow pointing down */ +#define ACS_UARROW NCURSES_ACS('-') /* arrow pointing up */ +#define ACS_BOARD NCURSES_ACS('h') /* board of squares */ +#define ACS_LANTERN NCURSES_ACS('i') /* lantern symbol */ +#define ACS_BLOCK NCURSES_ACS('0') /* solid square block */ /* * These aren't documented, but a lot of System Vs have them anyway * (you can spot pprryyzz{{||}} in a lot of AT&T terminfo strings). * The ACS_names may not match AT&T's, our source didn't know them. */ -#define ACS_S3 (acs_map['p']) /* scan line 3 */ -#define ACS_S7 (acs_map['r']) /* scan line 7 */ -#define ACS_LEQUAL (acs_map['y']) /* less/equal */ -#define ACS_GEQUAL (acs_map['z']) /* greater/equal */ -#define ACS_PI (acs_map['{']) /* Pi */ -#define ACS_NEQUAL (acs_map['|']) /* not equal */ -#define ACS_STERLING (acs_map['}']) /* UK pound sign */ +#define ACS_S3 NCURSES_ACS('p') /* scan line 3 */ +#define ACS_S7 NCURSES_ACS('r') /* scan line 7 */ +#define ACS_LEQUAL NCURSES_ACS('y') /* less/equal */ +#define ACS_GEQUAL NCURSES_ACS('z') /* greater/equal */ +#define ACS_PI NCURSES_ACS('{') /* Pi */ +#define ACS_NEQUAL NCURSES_ACS('|') /* not equal */ +#define ACS_STERLING NCURSES_ACS('}') /* UK pound sign */ /* * Line drawing ACS names are of the form ACS_trbl, where t is the top, r @@ -212,13 +301,11 @@ extern NCURSES_EXPORT_VAR(chtype) acs_map[]; #define ACS_SBSB ACS_VLINE #define ACS_SSSS ACS_PLUS -#if !defined(ERR) || ((ERR) != -1) +#undef ERR #define ERR (-1) -#endif -#if !defined(OK) || ((OK) != 0) +#undef OK #define OK (0) -#endif /* values for the _flags member */ #define _SUBWIN 0x01 /* is this a sub-window? */ @@ -247,29 +334,43 @@ typedef struct _win_st WINDOW; typedef chtype attr_t; /* ...must be at least as wide as chtype */ #ifdef _XOPEN_SOURCE_EXTENDED -#ifndef _WCHAR_T -typedef unsigned long wchar_t; -#endif /* _WCHAR_T */ -#ifndef _WINT_T -typedef long int wint_t; -#endif /* _WINT_T */ + +#if 0 +#ifdef mblen /* libutf8.h defines it w/o undefining first */ +#undef mblen +#endif +#include <libutf8.h> +#endif + +#if 0 +#include <wchar.h> /* ...to get mbstate_t, etc. */ +#endif + +#if 0 +typedef unsigned short wchar_t; +#endif + +#if 0 +typedef unsigned int wint_t; +#endif #define CCHARW_MAX 5 typedef struct { attr_t attr; wchar_t chars[CCHARW_MAX]; +#if 0 +#undef NCURSES_EXT_COLORS +#define NCURSES_EXT_COLORS 20081102 + int ext_color; /* color pair, must be more than 16-bits */ +#endif } cchar_t; + #endif /* _XOPEN_SOURCE_EXTENDED */ -struct ldat -{ - chtype *text; /* text of the line */ - NCURSES_SIZE_T firstchar; /* first changed character in the line */ - NCURSES_SIZE_T lastchar; /* last changed character in the line */ - NCURSES_SIZE_T oldindex; /* index of the line at last update */ -}; +#if !NCURSES_OPAQUE +struct ldat; struct _win_st { @@ -287,14 +388,14 @@ struct _win_st /* option values set by user */ bool _notimeout; /* no time out on function-key entry? */ - bool _clear; /* consider all data in the window invalid? */ - bool _leaveok; /* OK to not reset cursor on exit? */ - bool _scroll; /* OK to scroll this window? */ - bool _idlok; /* OK to use insert/delete line? */ - bool _idcok; /* OK to use insert/delete char? */ + bool _clear; /* consider all data in the window invalid? */ + bool _leaveok; /* OK to not reset cursor on exit? */ + bool _scroll; /* OK to scroll this window? */ + bool _idlok; /* OK to use insert/delete line? */ + bool _idcok; /* OK to use insert/delete char? */ bool _immed; /* window in immed mode? (not yet used) */ bool _sync; /* window in sync mode? */ - bool _use_keypad; /* process function keys into KEY_ symbols? */ + bool _use_keypad; /* process function keys into KEY_ symbols? */ int _delay; /* 0 = nodelay, <0 = blocking, >0 = delay */ struct ldat *_line; /* the actual line data */ @@ -317,72 +418,99 @@ struct _win_st } _pad; NCURSES_SIZE_T _yoffset; /* real begy is _begy + _yoffset */ -}; - -extern NCURSES_EXPORT_VAR(WINDOW *) stdscr; -extern NCURSES_EXPORT_VAR(WINDOW *) curscr; -extern NCURSES_EXPORT_VAR(WINDOW *) newscr; -extern NCURSES_EXPORT_VAR(int) LINES; -extern NCURSES_EXPORT_VAR(int) COLS; -extern NCURSES_EXPORT_VAR(int) TABSIZE; +#ifdef _XOPEN_SOURCE_EXTENDED + cchar_t _bkgrnd; /* current background char/attribute pair */ +#if 0 + int _color; /* current color-pair for non-space character */ +#endif +#endif +}; +#endif /* NCURSES_OPAQUE */ /* - * This global was an undocumented feature under AIX curses. + * This is an extension to support events... */ -extern NCURSES_EXPORT_VAR(int) ESCDELAY; /* ESC expire time in milliseconds */ - -extern NCURSES_EXPORT_VAR(char) ttytype[]; /* needed for backward compatibility */ +#if 1 +#ifdef NCURSES_WGETCH_EVENTS +#if !defined(__BEOS__) || defined(__HAIKU__) + /* Fix _nc_timed_wait() on BEOS... */ +# define NCURSES_EVENT_VERSION 1 +#endif /* !defined(__BEOS__) */ /* - * These functions are extensions - not in XSI Curses. + * Bits to set in _nc_event.data.flags */ -extern NCURSES_EXPORT(char *) keybound (int, int); -extern NCURSES_EXPORT(const char *) curses_version (void); -extern NCURSES_EXPORT(int) assume_default_colors (int, int); -extern NCURSES_EXPORT(int) define_key (char *, int); -extern NCURSES_EXPORT(int) keyok (int, bool); -extern NCURSES_EXPORT(int) resizeterm (int, int); -extern NCURSES_EXPORT(int) use_default_colors (void); -extern NCURSES_EXPORT(int) use_extended_names (bool); -extern NCURSES_EXPORT(int) wresize (WINDOW *, int, int); +# define _NC_EVENT_TIMEOUT_MSEC 1 +# define _NC_EVENT_FILE 2 +# define _NC_EVENT_FILE_READABLE 2 +# if 0 /* Not supported yet... */ +# define _NC_EVENT_FILE_WRITABLE 4 +# define _NC_EVENT_FILE_EXCEPTION 8 +# endif + +typedef struct +{ + int type; + union + { + long timeout_msec; /* _NC_EVENT_TIMEOUT_MSEC */ + struct + { + unsigned int flags; + int fd; + unsigned int result; + } fev; /* _NC_EVENT_FILE */ + } data; +} _nc_event; + +typedef struct +{ + int count; + int result_flags; /* _NC_EVENT_TIMEOUT_MSEC or _NC_EVENT_FILE_READABLE */ + _nc_event *events[1]; +} _nc_eventlist; + +extern NCURSES_EXPORT(int) wgetch_events(WINDOW *, _nc_eventlist *); /* experimental */ +extern NCURSES_EXPORT(int) wgetnstr_events(WINDOW *,char *,int,_nc_eventlist *);/* experimental */ + +#endif /* NCURSES_WGETCH_EVENTS */ +#endif /* NCURSES_EXT_FUNCS */ /* * GCC (and some other compilers) define '__attribute__'; we're using this * macro to alert the compiler to flag inconsistencies in printf/scanf-like * function calls. Just in case '__attribute__' isn't defined, make a dummy. - * G++ doesn't accept it anyway. + * Old versions of G++ do not accept it anyway, at least not consistently with + * GCC. */ -#if !defined(__GNUC__) && !defined(__attribute__) +#if !(defined(__GNUC__) || defined(__GNUG__) || defined(__attribute__)) #define __attribute__(p) /* nothing */ #endif /* - * For g++, turn off our macros that use __attribute__ (g++ recognizes some - * of them, but not at the same version levels as gcc). - */ -#ifdef __cplusplus -#undef GCC_NORETURN -#undef GCC_PRINTF -#undef GCC_SCANF -#undef GCC_UNUSED -#endif - -/* * We cannot define these in ncurses_cfg.h, since they require parameters to be - * passed (that's non-portable). + * passed (that is non-portable). If you happen to be using gcc with warnings + * enabled, define + * GCC_PRINTF + * GCC_SCANF + * to improve checking of calls to printw(), etc. */ -#ifdef GCC_PRINTF +#ifndef GCC_PRINTFLIKE +#if defined(GCC_PRINTF) && !defined(printf) #define GCC_PRINTFLIKE(fmt,var) __attribute__((__format__(printf,fmt,var))) #else #define GCC_PRINTFLIKE(fmt,var) /*nothing*/ #endif +#endif -#ifdef GCC_SCANF +#ifndef GCC_SCANFLIKE +#if defined(GCC_SCANF) && !defined(scanf) #define GCC_SCANFLIKE(fmt,var) __attribute__((__format__(scanf,fmt,var))) #else #define GCC_SCANFLIKE(fmt,var) /*nothing*/ #endif +#endif #ifndef GCC_NORETURN #define GCC_NORETURN /* nothing */ @@ -393,7 +521,7 @@ extern NCURSES_EXPORT(int) wresize (WINDOW *, int, int); #endif /* - * Function prototypes. This is the complete XSI Curses list of required + * Function prototypes. This is the complete X/Open Curses list of required * functions. Those marked `generated' will have sources generated from the * macro definitions later in this file, in order to satisfy XPG4.2 * requirements. @@ -404,13 +532,6 @@ extern NCURSES_EXPORT(int) addchnstr (const chtype *, int); /* generated */ extern NCURSES_EXPORT(int) addchstr (const chtype *); /* generated */ extern NCURSES_EXPORT(int) addnstr (const char *, int); /* generated */ extern NCURSES_EXPORT(int) addstr (const char *); /* generated */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) addnwstr (const wchar_t *, int); /* missing */ -extern NCURSES_EXPORT(int) addwstr (const wchar_t *); /* missing */ -extern NCURSES_EXPORT(int) add_wch (const cchar_t *); /* missing */ -extern NCURSES_EXPORT(int) add_wchnstr (const cchar_t *, int); /* missing */ -extern NCURSES_EXPORT(int) add_wchstr (const cchar_t *); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) attroff (NCURSES_ATTR_T); /* generated */ extern NCURSES_EXPORT(int) attron (NCURSES_ATTR_T); /* generated */ extern NCURSES_EXPORT(int) attrset (NCURSES_ATTR_T); /* generated */ @@ -422,18 +543,8 @@ extern NCURSES_EXPORT(int) baudrate (void); /* implemented */ extern NCURSES_EXPORT(int) beep (void); /* implemented */ extern NCURSES_EXPORT(int) bkgd (chtype); /* generated */ extern NCURSES_EXPORT(void) bkgdset (chtype); /* generated */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(void) bkgrndset (const cchar_t *); /* missing */ -extern NCURSES_EXPORT(int) bkgrnd (const cchar_t *); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) border (chtype,chtype,chtype,chtype,chtype,chtype,chtype,chtype); /* generated */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(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*); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) box (WINDOW *, chtype, chtype); /* generated */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) box_set (WINDOW *, const cchar_t *, const cchar_t *); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(bool) can_change_color (void); /* implemented */ extern NCURSES_EXPORT(int) cbreak (void); /* implemented */ extern NCURSES_EXPORT(int) chgat (int, attr_t, short, const void *); /* generated */ @@ -459,41 +570,21 @@ extern NCURSES_EXPORT(WINDOW *) dupwin (WINDOW *); /* implemented */ extern NCURSES_EXPORT(int) echo (void); /* implemented */ extern NCURSES_EXPORT(int) echochar (const chtype); /* generated */ extern NCURSES_EXPORT(int) erase (void); /* generated */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) echo_wchar (const cchar_t *); /* missing */ -extern NCURSES_EXPORT(int) erasewchar (wchar_t*); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) endwin (void); /* implemented */ extern NCURSES_EXPORT(char) erasechar (void); /* implemented */ extern NCURSES_EXPORT(void) filter (void); /* implemented */ extern NCURSES_EXPORT(int) flash (void); /* implemented */ extern NCURSES_EXPORT(int) flushinp (void); /* implemented */ extern NCURSES_EXPORT(chtype) getbkgd (WINDOW *); /* generated */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) getbkgrnd (cchar_t *); /* missing */ -extern NCURSES_EXPORT(int) getcchar (const cchar_t *, wchar_t*, attr_t*, short*, void*); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) getch (void); /* generated */ extern NCURSES_EXPORT(int) getnstr (char *, int); /* generated */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) getn_wstr (wint_t *, int); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) getstr (char *); /* generated */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) get_wch (wint_t *); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(WINDOW *) getwin (FILE *); /* implemented */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) get_wstr (wint_t *); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) halfdelay (int); /* implemented */ extern NCURSES_EXPORT(bool) has_colors (void); /* implemented */ extern NCURSES_EXPORT(bool) has_ic (void); /* implemented */ extern NCURSES_EXPORT(bool) has_il (void); /* implemented */ extern NCURSES_EXPORT(int) hline (chtype, int); /* generated */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) hline_set (const cchar_t *, int); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(void) idcok (WINDOW *, bool); /* implemented */ extern NCURSES_EXPORT(int) idlok (WINDOW *, bool); /* implemented */ extern NCURSES_EXPORT(void) immedok (WINDOW *, bool); /* implemented */ @@ -504,39 +595,19 @@ extern NCURSES_EXPORT(WINDOW *) initscr (void); /* implemented */ extern NCURSES_EXPORT(int) init_color (short,short,short,short); /* implemented */ extern NCURSES_EXPORT(int) init_pair (short,short,short); /* implemented */ extern NCURSES_EXPORT(int) innstr (char *, int); /* generated */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) innwstr (wchar_t *, int); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) insch (chtype); /* generated */ extern NCURSES_EXPORT(int) insdelln (int); /* generated */ extern NCURSES_EXPORT(int) insertln (void); /* generated */ extern NCURSES_EXPORT(int) insnstr (const char *, int); /* generated */ extern NCURSES_EXPORT(int) insstr (const char *); /* generated */ extern NCURSES_EXPORT(int) instr (char *); /* generated */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) ins_nwstr (const wchar_t *, int); /* missing */ -extern NCURSES_EXPORT(int) ins_wch (const cchar_t *); /* missing */ -extern NCURSES_EXPORT(int) ins_wstr (const wchar_t *); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) intrflush (WINDOW *,bool); /* implemented */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) inwstr (wchar_t *); /* missing */ -extern NCURSES_EXPORT(int) in_wch (NCURSES_CONST cchar_t *); /* missing */ -extern NCURSES_EXPORT(int) in_wchstr (NCURSES_CONST cchar_t *); /* missing */ -extern NCURSES_EXPORT(int) in_wchnstr (NCURSES_CONST cchar_t *, int); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(bool) isendwin (void); /* implemented */ extern NCURSES_EXPORT(bool) is_linetouched (WINDOW *,int); /* implemented */ extern NCURSES_EXPORT(bool) is_wintouched (WINDOW *); /* implemented */ extern NCURSES_EXPORT(NCURSES_CONST char *) keyname (int); /* implemented */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(char *) key_name (wchar_t); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) keypad (WINDOW *,bool); /* implemented */ extern NCURSES_EXPORT(char) killchar (void); /* implemented */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) killwchar (wchar_t *); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) leaveok (WINDOW *,bool); /* implemented */ extern NCURSES_EXPORT(char *) longname (void); /* implemented */ extern NCURSES_EXPORT(int) meta (WINDOW *,bool); /* implemented */ @@ -546,120 +617,52 @@ extern NCURSES_EXPORT(int) mvaddchnstr (int, int, const chtype *, int); /* gener extern NCURSES_EXPORT(int) mvaddchstr (int, int, const chtype *); /* generated */ extern NCURSES_EXPORT(int) mvaddnstr (int, int, const char *, int); /* generated */ extern NCURSES_EXPORT(int) mvaddstr (int, int, const char *); /* generated */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) mvaddnwstr (int, int, const wchar_t *, int); /* missing */ -extern NCURSES_EXPORT(int) mvaddwstr (int, int, const wchar_t *); /* missing */ -extern NCURSES_EXPORT(int) mvadd_wch (int, int, const cchar_t *); /* missing */ -extern NCURSES_EXPORT(int) mvadd_wchnstr (int, int, const cchar_t *, int);/* missing */ -extern NCURSES_EXPORT(int) mvadd_wchstr (int, int, const cchar_t *); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) mvchgat (int, int, int, attr_t, short, const void *); /* generated */ extern NCURSES_EXPORT(int) mvcur (int,int,int,int); /* implemented */ extern NCURSES_EXPORT(int) mvdelch (int, int); /* generated */ extern NCURSES_EXPORT(int) mvderwin (WINDOW *, int, int); /* implemented */ extern NCURSES_EXPORT(int) mvgetch (int, int); /* generated */ extern NCURSES_EXPORT(int) mvgetnstr (int, int, char *, int); /* generated */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) mvgetn_wstr (int, int, wint_t *, int); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) mvgetstr (int, int, char *); /* generated */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) mvget_wch (int, int, wint_t *); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) mvget_wstr (int, int, wint_t *); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) mvhline (int, int, chtype, int); /* generated */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) mvhline_set (int, int, const cchar_t *, int); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(chtype) mvinch (int, int); /* generated */ extern NCURSES_EXPORT(int) mvinchnstr (int, int, chtype *, int); /* generated */ extern NCURSES_EXPORT(int) mvinchstr (int, int, chtype *); /* generated */ extern NCURSES_EXPORT(int) mvinnstr (int, int, char *, int); /* generated */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) mvinnwstr (int, int, wchar_t *, int); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) mvinsch (int, int, chtype); /* generated */ extern NCURSES_EXPORT(int) mvinsnstr (int, int, const char *, int); /* generated */ extern NCURSES_EXPORT(int) mvinsstr (int, int, const char *); /* generated */ extern NCURSES_EXPORT(int) mvinstr (int, int, char *); /* generated */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) mvins_nwstr (int, int, const wchar_t *, int); /* missing */ -extern NCURSES_EXPORT(int) mvins_wch (int, int, const cchar_t *); /* missing */ -extern NCURSES_EXPORT(int) mvins_wstr (int, int, const wchar_t *); /* missing */ -extern NCURSES_EXPORT(int) mvinwstr (int, int, wchar_t *); /* missing */ -extern NCURSES_EXPORT(int) mvin_wch (int, int, NCURSES_CONST cchar_t *); /* missing */ -extern NCURSES_EXPORT(int) mvin_wchstr (int, int, NCURSES_CONST cchar_t *); /* missing */ -extern NCURSES_EXPORT(int) mvin_wchnstr (int, int, NCURSES_CONST cchar_t *, int); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ -extern NCURSES_EXPORT(int) mvprintw (int,int, NCURSES_CONST char *,...) /* implemented */ +extern NCURSES_EXPORT(int) mvprintw (int,int, const char *,...) /* implemented */ GCC_PRINTFLIKE(3,4); extern NCURSES_EXPORT(int) mvscanw (int,int, NCURSES_CONST char *,...) /* implemented */ GCC_SCANFLIKE(3,4); extern NCURSES_EXPORT(int) mvvline (int, int, chtype, int); /* generated */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) mvvline_set (int, int, const cchar_t *, int); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) mvwaddch (WINDOW *, int, int, const chtype); /* generated */ extern NCURSES_EXPORT(int) mvwaddchnstr (WINDOW *, int, int, const chtype *, int);/* generated */ extern NCURSES_EXPORT(int) mvwaddchstr (WINDOW *, int, int, const chtype *); /* generated */ extern NCURSES_EXPORT(int) mvwaddnstr (WINDOW *, int, int, const char *, int); /* generated */ extern NCURSES_EXPORT(int) mvwaddstr (WINDOW *, int, int, const char *); /* generated */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) mvwaddnwstr (WINDOW *, int, int, const wchar_t *, int);/* missing */ -extern NCURSES_EXPORT(int) mvwaddwstr (WINDOW *, int, int, const wchar_t *); /* missing */ -extern NCURSES_EXPORT(int) mvwadd_wch (WINDOW *, int, int, const cchar_t *); /* missing */ -extern NCURSES_EXPORT(int) mvwadd_wchnstr (WINDOW *, int, int, const cchar_t *, int); /* missing */ -extern NCURSES_EXPORT(int) mvwadd_wchstr (WINDOW *, int, int, const cchar_t *); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) mvwchgat (WINDOW *, int, int, int, attr_t, short, const void *);/* generated */ extern NCURSES_EXPORT(int) mvwdelch (WINDOW *, int, int); /* generated */ extern NCURSES_EXPORT(int) mvwgetch (WINDOW *, int, int); /* generated */ extern NCURSES_EXPORT(int) mvwgetnstr (WINDOW *, int, int, char *, int); /* generated */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) mvwgetn_wstr (WINDOW *, int, int, wint_t *, int);/* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) mvwgetstr (WINDOW *, int, int, char *); /* generated */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) mvwget_wch (WINDOW *, int, int, wint_t *); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) mvwget_wstr (WINDOW *, int, int, wint_t *); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) mvwhline (WINDOW *, int, int, chtype, int); /* generated */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) mvwhline_set (WINDOW *, int, int, const cchar_t *, int);/* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) mvwin (WINDOW *,int,int); /* implemented */ extern NCURSES_EXPORT(chtype) mvwinch (WINDOW *, int, int); /* generated */ extern NCURSES_EXPORT(int) mvwinchnstr (WINDOW *, int, int, chtype *, int); /* generated */ extern NCURSES_EXPORT(int) mvwinchstr (WINDOW *, int, int, chtype *); /* generated */ extern NCURSES_EXPORT(int) mvwinnstr (WINDOW *, int, int, char *, int); /* generated */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) mvwinnwstr (WINDOW *, int, int, wchar_t *, int); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) mvwinsch (WINDOW *, int, int, chtype); /* generated */ extern NCURSES_EXPORT(int) mvwinsnstr (WINDOW *, int, int, const char *, int); /* generated */ extern NCURSES_EXPORT(int) mvwinsstr (WINDOW *, int, int, const char *); /* generated */ extern NCURSES_EXPORT(int) mvwinstr (WINDOW *, int, int, char *); /* generated */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) mvwins_nwstr (WINDOW *, int,int, const wchar_t *,int); /* missing */ -extern NCURSES_EXPORT(int) mvwins_wch (WINDOW *, int, int, const cchar_t *); /* missing */ -extern NCURSES_EXPORT(int) mvwins_wstr (WINDOW *, int, int, const wchar_t *); /* missing */ -extern NCURSES_EXPORT(int) mvwinwstr (WINDOW *, int, int, wchar_t *); /* missing */ -extern NCURSES_EXPORT(int) mvwin_wch (WINDOW *, int, int, NCURSES_CONST cchar_t *); /* missing */ -extern NCURSES_EXPORT(int) mvwin_wchnstr (WINDOW *, int,int, NCURSES_CONST cchar_t *,int); /* missing */ -extern NCURSES_EXPORT(int) mvwin_wchstr (WINDOW *, int, int, NCURSES_CONST cchar_t *); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ -extern NCURSES_EXPORT(int) mvwprintw (WINDOW*,int,int, NCURSES_CONST char *,...) /* implemented */ +extern NCURSES_EXPORT(int) mvwprintw (WINDOW*,int,int, const char *,...) /* implemented */ GCC_PRINTFLIKE(4,5); extern NCURSES_EXPORT(int) mvwscanw (WINDOW *,int,int, NCURSES_CONST char *,...) /* implemented */ GCC_SCANFLIKE(4,5); extern NCURSES_EXPORT(int) mvwvline (WINDOW *,int, int, chtype, int); /* generated */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) mvwvline_set (WINDOW *, int,int, const cchar_t *,int); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) napms (int); /* implemented */ extern NCURSES_EXPORT(WINDOW *) newpad (int,int); /* implemented */ extern NCURSES_EXPORT(SCREEN *) newterm (NCURSES_CONST char *,FILE *,FILE *); /* implemented */ @@ -677,14 +680,10 @@ extern NCURSES_EXPORT(int) overwrite (const WINDOW*,WINDOW *); /* implemented * extern NCURSES_EXPORT(int) pair_content (short,short*,short*); /* implemented */ extern NCURSES_EXPORT(int) PAIR_NUMBER (int); /* generated */ extern NCURSES_EXPORT(int) pechochar (WINDOW *, const chtype); /* implemented */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) pecho_wchar (WINDOW *, const cchar_t *); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) pnoutrefresh (WINDOW*,int,int,int,int,int,int);/* implemented */ extern NCURSES_EXPORT(int) prefresh (WINDOW *,int,int,int,int,int,int); /* implemented */ -extern NCURSES_EXPORT(int) printw (NCURSES_CONST char *,...) /* implemented */ +extern NCURSES_EXPORT(int) printw (const char *,...) /* implemented */ GCC_PRINTFLIKE(1,2); -extern NCURSES_EXPORT(int) putp (const char *); /* implemented */ extern NCURSES_EXPORT(int) putwin (WINDOW *, FILE *); /* implemented */ extern NCURSES_EXPORT(void) qiflush (void); /* implemented */ extern NCURSES_EXPORT(int) raw (void); /* implemented */ @@ -693,7 +692,7 @@ extern NCURSES_EXPORT(int) refresh (void); /* generated */ extern NCURSES_EXPORT(int) resetty (void); /* implemented */ extern NCURSES_EXPORT(int) reset_prog_mode (void); /* implemented */ extern NCURSES_EXPORT(int) reset_shell_mode (void); /* implemented */ -extern NCURSES_EXPORT(int) ripoffline (int, int (*init)(WINDOW *, int)); /* implemented */ +extern NCURSES_EXPORT(int) ripoffline (int, int (*)(WINDOW *, int)); /* implemented */ extern NCURSES_EXPORT(int) savetty (void); /* implemented */ extern NCURSES_EXPORT(int) scanw (NCURSES_CONST char *,...) /* implemented */ GCC_SCANFLIKE(1,2); @@ -704,9 +703,6 @@ extern NCURSES_EXPORT(int) scroll (WINDOW *); /* generated */ extern NCURSES_EXPORT(int) scrollok (WINDOW *,bool); /* implemented */ extern NCURSES_EXPORT(int) scr_restore (const char *); /* implemented */ extern NCURSES_EXPORT(int) scr_set (const char *); /* implemented */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) setcchar (cchar_t *, const wchar_t *, const attr_t, short, const void *); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) setscrreg (int,int); /* generated */ extern NCURSES_EXPORT(SCREEN *) set_term (SCREEN *); /* implemented */ extern NCURSES_EXPORT(int) slk_attroff (const chtype); /* implemented */ @@ -725,75 +721,43 @@ extern NCURSES_EXPORT(int) slk_refresh (void); /* implemented */ extern NCURSES_EXPORT(int) slk_restore (void); /* implemented */ extern NCURSES_EXPORT(int) slk_set (int,const char *,int); /* implemented */ extern NCURSES_EXPORT(int) slk_touch (void); /* implemented */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) slk_wset (int, const wchar_t *, int); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) standout (void); /* generated */ extern NCURSES_EXPORT(int) standend (void); /* generated */ extern NCURSES_EXPORT(int) start_color (void); /* implemented */ extern NCURSES_EXPORT(WINDOW *) subpad (WINDOW *, int, int, int, int); /* implemented */ -extern NCURSES_EXPORT(WINDOW *) subwin (WINDOW *,int,int,int,int); /* implemented */ +extern NCURSES_EXPORT(WINDOW *) subwin (WINDOW *, int, int, int, int); /* implemented */ extern NCURSES_EXPORT(int) syncok (WINDOW *, bool); /* implemented */ extern NCURSES_EXPORT(chtype) termattrs (void); /* implemented */ -extern NCURSES_EXPORT(attr_t) term_attrs (void); /* missing */ extern NCURSES_EXPORT(char *) termname (void); /* implemented */ -extern NCURSES_EXPORT(int) tigetflag (NCURSES_CONST char *); /* implemented */ -extern NCURSES_EXPORT(int) tigetnum (NCURSES_CONST char *); /* implemented */ -extern NCURSES_EXPORT(char *) tigetstr (NCURSES_CONST char *); /* implemented */ extern NCURSES_EXPORT(void) timeout (int); /* generated */ extern NCURSES_EXPORT(int) touchline (WINDOW *, int, int); /* generated */ extern NCURSES_EXPORT(int) touchwin (WINDOW *); /* generated */ -extern NCURSES_EXPORT(char *) tparm (NCURSES_CONST char *, ...); /* implemented */ extern NCURSES_EXPORT(int) typeahead (int); /* implemented */ extern NCURSES_EXPORT(int) ungetch (int); /* implemented */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) unget_wch (const wchar_t); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) untouchwin (WINDOW *); /* generated */ extern NCURSES_EXPORT(void) use_env (bool); /* implemented */ extern NCURSES_EXPORT(int) vidattr (chtype); /* implemented */ -extern NCURSES_EXPORT(int) vid_attr (attr_t, short, void *); /* generated:WIDEC */ extern NCURSES_EXPORT(int) vidputs (chtype, int (*)(int)); /* implemented */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) vid_puts (attr_t, short, void *, int (*)(int)); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) vline (chtype, int); /* generated */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) vline_set (const cchar_t *, int); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ -extern NCURSES_EXPORT(int) vwprintw (WINDOW *, NCURSES_CONST char *,va_list); /* implemented */ -extern NCURSES_EXPORT(int) vw_printw (WINDOW *, NCURSES_CONST char *,va_list); /* generated */ +extern NCURSES_EXPORT(int) vwprintw (WINDOW *, const char *,va_list); /* implemented */ +extern NCURSES_EXPORT(int) vw_printw (WINDOW *, const char *,va_list); /* generated */ extern NCURSES_EXPORT(int) vwscanw (WINDOW *, NCURSES_CONST char *,va_list); /* implemented */ extern NCURSES_EXPORT(int) vw_scanw (WINDOW *, NCURSES_CONST char *,va_list); /* generated */ extern NCURSES_EXPORT(int) waddch (WINDOW *, const chtype); /* implemented */ -extern NCURSES_EXPORT(int) waddchnstr (WINDOW *,const chtype *const,int); /* implemented */ +extern NCURSES_EXPORT(int) waddchnstr (WINDOW *,const chtype *,int); /* implemented */ extern NCURSES_EXPORT(int) waddchstr (WINDOW *,const chtype *); /* generated */ -extern NCURSES_EXPORT(int) waddnstr (WINDOW *,const char *const,int); /* implemented */ +extern NCURSES_EXPORT(int) waddnstr (WINDOW *,const char *,int); /* implemented */ extern NCURSES_EXPORT(int) waddstr (WINDOW *,const char *); /* generated */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) waddwstr (WINDOW *,const wchar_t *); /* missing */ -extern NCURSES_EXPORT(int) waddnwstr (WINDOW *,const wchar_t *,int); /* missing */ -extern NCURSES_EXPORT(int) wadd_wch (WINDOW *,const cchar_t *); /* missing */ -extern NCURSES_EXPORT(int) wadd_wchnstr (WINDOW *,const cchar_t *,int); /* missing */ -extern NCURSES_EXPORT(int) wadd_wchstr (WINDOW *,const cchar_t *); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) wattron (WINDOW *, int); /* generated */ extern NCURSES_EXPORT(int) wattroff (WINDOW *, int); /* generated */ extern NCURSES_EXPORT(int) wattrset (WINDOW *, int); /* generated */ extern NCURSES_EXPORT(int) wattr_get (WINDOW *, attr_t *, short *, void *); /* generated */ -extern NCURSES_EXPORT(int) wattr_on (WINDOW *, NCURSES_CONST attr_t, void *); /* implemented */ -extern NCURSES_EXPORT(int) wattr_off (WINDOW *, NCURSES_CONST attr_t, void *); /* implemented */ -extern NCURSES_EXPORT(int) wattr_set (WINDOW *, attr_t, short, void *); /* generated */ -extern NCURSES_EXPORT(int) wbkgd (WINDOW *,const chtype); /* implemented */ +extern NCURSES_EXPORT(int) wattr_on (WINDOW *, attr_t, void *); /* implemented */ +extern NCURSES_EXPORT(int) wattr_off (WINDOW *, attr_t, void *); /* implemented */ +extern NCURSES_EXPORT(int) wattr_set (WINDOW *, attr_t, short, void *); /* generated */ +extern NCURSES_EXPORT(int) wbkgd (WINDOW *, chtype); /* implemented */ extern NCURSES_EXPORT(void) wbkgdset (WINDOW *,chtype); /* implemented */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(void) wbkgrndset (WINDOW *,const cchar_t *); /* missing */ -extern NCURSES_EXPORT(int) wbkgrnd (WINDOW *,const cchar_t *); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) wborder (WINDOW *,chtype,chtype,chtype,chtype,chtype,chtype,chtype,chtype); /* implemented */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(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*); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) wchgat (WINDOW *, int, attr_t, short, const void *);/* implemented */ extern NCURSES_EXPORT(int) wclear (WINDOW *); /* implemented */ extern NCURSES_EXPORT(int) wclrtobot (WINDOW *); /* implemented */ @@ -803,52 +767,24 @@ extern NCURSES_EXPORT(void) wcursyncup (WINDOW *); /* implemented */ extern NCURSES_EXPORT(int) wdelch (WINDOW *); /* implemented */ extern NCURSES_EXPORT(int) wdeleteln (WINDOW *); /* generated */ extern NCURSES_EXPORT(int) wechochar (WINDOW *, const chtype); /* implemented */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) wecho_wchar (WINDOW *, const cchar_t *); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) werase (WINDOW *); /* implemented */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) wgetbkgrnd (WINDOW *, cchar_t *); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) wgetch (WINDOW *); /* implemented */ extern NCURSES_EXPORT(int) wgetnstr (WINDOW *,char *,int); /* implemented */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) wgetn_wstr (WINDOW *,wint_t *, int); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) wgetstr (WINDOW *, char *); /* generated */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) wget_wch (WINDOW *, wint_t *); /* missing */ -extern NCURSES_EXPORT(int) wget_wstr (WINDOW *, wint_t *); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) whline (WINDOW *, chtype, int); /* implemented */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) whline_set (WINDOW *, const cchar_t *, int); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(chtype) winch (WINDOW *); /* implemented */ extern NCURSES_EXPORT(int) winchnstr (WINDOW *, chtype *, int); /* implemented */ extern NCURSES_EXPORT(int) winchstr (WINDOW *, chtype *); /* generated */ extern NCURSES_EXPORT(int) winnstr (WINDOW *, char *, int); /* implemented */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) winnwstr (WINDOW *, wchar_t *, int); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) winsch (WINDOW *, chtype); /* implemented */ extern NCURSES_EXPORT(int) winsdelln (WINDOW *,int); /* implemented */ extern NCURSES_EXPORT(int) winsertln (WINDOW *); /* generated */ extern NCURSES_EXPORT(int) winsnstr (WINDOW *, const char *,int); /* implemented */ extern NCURSES_EXPORT(int) winsstr (WINDOW *, const char *); /* generated */ extern NCURSES_EXPORT(int) winstr (WINDOW *, char *); /* generated */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) wins_nwstr (WINDOW *, const wchar_t *, int); /* missing */ -extern NCURSES_EXPORT(int) wins_wch (WINDOW *, const cchar_t *); /* missing */ -extern NCURSES_EXPORT(int) wins_wstr (WINDOW *, const wchar_t *); /* missing */ -extern NCURSES_EXPORT(int) winwstr (WINDOW *, wchar_t *); /* missing */ -extern NCURSES_EXPORT(int) win_wch (WINDOW *, NCURSES_CONST cchar_t *); /* missing */ -extern NCURSES_EXPORT(int) win_wchnstr (WINDOW *, NCURSES_CONST cchar_t *, int); /* missing */ -extern NCURSES_EXPORT(int) win_wchstr (WINDOW *, NCURSES_CONST cchar_t *); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) wmove (WINDOW *,int,int); /* implemented */ extern NCURSES_EXPORT(int) wnoutrefresh (WINDOW *); /* implemented */ -extern NCURSES_EXPORT(int) wprintw (WINDOW *, NCURSES_CONST char *,...) /* implemented */ +extern NCURSES_EXPORT(int) wprintw (WINDOW *, const char *,...) /* implemented */ GCC_PRINTFLIKE(2,3); extern NCURSES_EXPORT(int) wredrawln (WINDOW *,int,int); /* implemented */ extern NCURSES_EXPORT(int) wrefresh (WINDOW *); /* implemented */ @@ -862,60 +798,155 @@ extern NCURSES_EXPORT(void) wsyncdown (WINDOW *); /* implemented */ extern NCURSES_EXPORT(void) wsyncup (WINDOW *); /* implemented */ extern NCURSES_EXPORT(void) wtimeout (WINDOW *,int); /* implemented */ extern NCURSES_EXPORT(int) wtouchln (WINDOW *,int,int,int); /* implemented */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(wchar_t *) wunctrl (cchar_t *); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ extern NCURSES_EXPORT(int) wvline (WINDOW *,chtype,int); /* implemented */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern NCURSES_EXPORT(int) wvline_set (WINDOW *, const cchar_t *, int); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ -extern NCURSES_EXPORT(bool) mouse_trafo (int*, int*, bool); /* generated */ +/* + * These are also declared in <term.h>: + */ +extern NCURSES_EXPORT(int) tigetflag (NCURSES_CONST char *); /* implemented */ +extern NCURSES_EXPORT(int) tigetnum (NCURSES_CONST char *); /* implemented */ +extern NCURSES_EXPORT(char *) tigetstr (NCURSES_CONST char *); /* implemented */ +extern NCURSES_EXPORT(int) putp (const char *); /* implemented */ -/* attributes */ +#if NCURSES_TPARM_VARARGS +extern NCURSES_EXPORT(char *) tparm (NCURSES_CONST char *, ...); /* special */ +#else +extern NCURSES_EXPORT(char *) tparm (NCURSES_CONST char *, long,long,long,long,long,long,long,long,long); /* special */ +extern NCURSES_EXPORT(char *) tparm_varargs (NCURSES_CONST char *, ...); /* special */ +#endif + +/* + * These functions are not in X/Open, but we use them in macro definitions: + */ +extern NCURSES_EXPORT(int) getattrs (const WINDOW *); /* generated */ +extern NCURSES_EXPORT(int) getcurx (const WINDOW *); /* generated */ +extern NCURSES_EXPORT(int) getcury (const WINDOW *); /* generated */ +extern NCURSES_EXPORT(int) getbegx (const WINDOW *); /* generated */ +extern NCURSES_EXPORT(int) getbegy (const WINDOW *); /* generated */ +extern NCURSES_EXPORT(int) getmaxx (const WINDOW *); /* generated */ +extern NCURSES_EXPORT(int) getmaxy (const WINDOW *); /* generated */ +extern NCURSES_EXPORT(int) getparx (const WINDOW *); /* generated */ +extern NCURSES_EXPORT(int) getpary (const WINDOW *); /* generated */ + +/* + * vid_attr() was implemented originally based on a draft of X/Open curses. + */ +#ifndef _XOPEN_SOURCE_EXTENDED +#define vid_attr(a,pair,opts) vidattr(a) +#endif + +/* + * These functions are extensions - not in X/Open Curses. + */ +#if 1 +#undef NCURSES_EXT_FUNCS +#define NCURSES_EXT_FUNCS 20081102 +typedef int (*NCURSES_WINDOW_CB)(WINDOW *, void *); +typedef int (*NCURSES_SCREEN_CB)(SCREEN *, void *); +extern NCURSES_EXPORT(bool) is_term_resized (int, int); +extern NCURSES_EXPORT(char *) keybound (int, int); +extern NCURSES_EXPORT(const char *) curses_version (void); +extern NCURSES_EXPORT(int) assume_default_colors (int, int); +extern NCURSES_EXPORT(int) define_key (const char *, int); +extern NCURSES_EXPORT(int) key_defined (const char *); +extern NCURSES_EXPORT(int) keyok (int, bool); +extern NCURSES_EXPORT(int) resize_term (int, int); +extern NCURSES_EXPORT(int) resizeterm (int, int); +extern NCURSES_EXPORT(int) set_escdelay (int); +extern NCURSES_EXPORT(int) set_tabsize (int); +extern NCURSES_EXPORT(int) use_default_colors (void); +extern NCURSES_EXPORT(int) use_extended_names (bool); +extern NCURSES_EXPORT(int) use_legacy_coding (int); +extern NCURSES_EXPORT(int) use_screen (SCREEN *, NCURSES_SCREEN_CB, void *); +extern NCURSES_EXPORT(int) use_window (WINDOW *, NCURSES_WINDOW_CB, void *); +extern NCURSES_EXPORT(int) wresize (WINDOW *, int, int); +extern NCURSES_EXPORT(void) nofilter(void); -#define NCURSES_BITS(mask,shift) ((mask) << ((shift) + 8)) - -#define A_NORMAL 0L -#define A_ATTRIBUTES NCURSES_BITS(~(1UL - 1UL),0) -#define A_CHARTEXT (NCURSES_BITS(1UL,0) - 1UL) -#define A_COLOR NCURSES_BITS(((1UL) << 8) - 1UL,0) -#define A_STANDOUT NCURSES_BITS(1UL,8) -#define A_UNDERLINE NCURSES_BITS(1UL,9) -#define A_REVERSE NCURSES_BITS(1UL,10) -#define A_BLINK NCURSES_BITS(1UL,11) -#define A_DIM NCURSES_BITS(1UL,12) -#define A_BOLD NCURSES_BITS(1UL,13) -#define A_ALTCHARSET NCURSES_BITS(1UL,14) -#define A_INVIS NCURSES_BITS(1UL,15) - -/* Tradeoff on 32-bit machines ('protect' vs widec). The others (e.g., left - * highlight are not implemented in any terminal descriptions, anyway. +/* + * These extensions provide access to information stored in the WINDOW even + * when NCURSES_OPAQUE is set: */ -#if ((16 + 8) < 32) -#define A_PROTECT NCURSES_BITS(1UL,16) -#define A_HORIZONTAL NCURSES_BITS(1UL,17) -#define A_LEFT NCURSES_BITS(1UL,18) -#define A_LOW NCURSES_BITS(1UL,19) -#define A_RIGHT NCURSES_BITS(1UL,20) -#define A_TOP NCURSES_BITS(1UL,21) -#define A_VERTICAL NCURSES_BITS(1UL,22) +extern NCURSES_EXPORT(WINDOW *) wgetparent (const WINDOW *); /* generated */ +extern NCURSES_EXPORT(bool) is_cleared (const WINDOW *); /* generated */ +extern NCURSES_EXPORT(bool) is_idcok (const WINDOW *); /* generated */ +extern NCURSES_EXPORT(bool) is_idlok (const WINDOW *); /* generated */ +extern NCURSES_EXPORT(bool) is_immedok (const WINDOW *); /* generated */ +extern NCURSES_EXPORT(bool) is_keypad (const WINDOW *); /* generated */ +extern NCURSES_EXPORT(bool) is_leaveok (const WINDOW *); /* generated */ +extern NCURSES_EXPORT(bool) is_nodelay (const WINDOW *); /* generated */ +extern NCURSES_EXPORT(bool) is_notimeout (const WINDOW *); /* generated */ +extern NCURSES_EXPORT(bool) is_scrollok (const WINDOW *); /* generated */ +extern NCURSES_EXPORT(bool) is_syncok (const WINDOW *); /* generated */ +extern NCURSES_EXPORT(int) wgetscrreg (const WINDOW *, int *, int *); /* generated */ + #else -#define A_PROTECT 0L -#define A_HORIZONTAL 0L -#define A_LEFT 0L -#define A_LOW 0L -#define A_RIGHT 0L -#define A_TOP 0L -#define A_VERTICAL 0L +#define curses_version() NCURSES_VERSION #endif -#define COLOR_PAIR(n) NCURSES_BITS(n, 0) -#define PAIR_NUMBER(a) (((a) & A_COLOR) >> 8) +/* attributes */ + +#define NCURSES_ATTR_SHIFT 8 +#define NCURSES_BITS(mask,shift) ((mask) << ((shift) + NCURSES_ATTR_SHIFT)) + +#define A_NORMAL (1U - 1U) +#define A_ATTRIBUTES NCURSES_BITS(~(1U - 1U),0) +#define A_CHARTEXT (NCURSES_BITS(1U,0) - 1U) +#define A_COLOR NCURSES_BITS(((1U) << 8) - 1U,0) +#define A_STANDOUT NCURSES_BITS(1U,8) +#define A_UNDERLINE NCURSES_BITS(1U,9) +#define A_REVERSE NCURSES_BITS(1U,10) +#define A_BLINK NCURSES_BITS(1U,11) +#define A_DIM NCURSES_BITS(1U,12) +#define A_BOLD NCURSES_BITS(1U,13) +#define A_ALTCHARSET NCURSES_BITS(1U,14) +#define A_INVIS NCURSES_BITS(1U,15) +#define A_PROTECT NCURSES_BITS(1U,16) +#define A_HORIZONTAL NCURSES_BITS(1U,17) +#define A_LEFT NCURSES_BITS(1U,18) +#define A_LOW NCURSES_BITS(1U,19) +#define A_RIGHT NCURSES_BITS(1U,20) +#define A_TOP NCURSES_BITS(1U,21) +#define A_VERTICAL NCURSES_BITS(1U,22) /* - * pseudo functions + * Most of the pseudo functions are macros that either provide compatibility + * with older versions of curses, or provide inline functionality to improve + * performance. */ + +/* + * These pseudo functions are always implemented as macros: + */ + +#define getyx(win,y,x) (y = getcury(win), x = getcurx(win)) +#define getbegyx(win,y,x) (y = getbegy(win), x = getbegx(win)) +#define getmaxyx(win,y,x) (y = getmaxy(win), x = getmaxx(win)) +#define getparyx(win,y,x) (y = getpary(win), x = getparx(win)) + +#define getsyx(y,x) do { if (newscr) { \ + if (is_leaveok(newscr)) \ + (y) = (x) = -1; \ + else \ + getyx(newscr,(y), (x)); \ + } \ + } while(0) + +#define setsyx(y,x) do { if (newscr) { \ + if ((y) == -1 && (x) == -1) \ + leaveok(newscr, TRUE); \ + else { \ + leaveok(newscr, FALSE); \ + wmove(newscr, (y), (x)); \ + } \ + } \ + } while(0) + +#ifndef NCURSES_NOMACROS + +/* + * These miscellaneous pseudo functions are provided for compatibility: + */ + #define wgetstr(w, s) wgetnstr(w, s, -1) #define getnstr(s, n) wgetnstr(stdscr, s, n) @@ -928,35 +959,33 @@ extern NCURSES_EXPORT(bool) mouse_trafo (int*, int*, bool); /* gene #define nocrmode() nocbreak() #define gettmode() -#define getyx(win,y,x) (y = (win)?(win)->_cury:ERR, x = (win)?(win)->_curx:ERR) -#define getbegyx(win,y,x) (y = (win)?(win)->_begy:ERR, x = (win)?(win)->_begx:ERR) -#define getmaxyx(win,y,x) (y = (win)?((win)->_maxy + 1):ERR, x = (win)?((win)->_maxx + 1):ERR) -#define getparyx(win,y,x) (y = (win)?(win)->_pary:ERR, x = (win)?(win)->_parx:ERR) -#define getsyx(y,x) do { if(newscr->_leaveok) (y)=(x)=-1; \ - else getyx(newscr,(y),(x)); \ - } while(0) -#define setsyx(y,x) do { if((y)==-1 && (x)==-1) newscr->_leaveok=TRUE; \ - else {newscr->_leaveok=FALSE;wmove(newscr,(y),(x));} \ - } while(0) - /* It seems older SYSV curses versions define these */ -#define getattrs(win) ((win)?(win)->_attrs:A_NORMAL) -#define getcurx(win) ((win)?(win)->_curx:ERR) -#define getcury(win) ((win)?(win)->_cury:ERR) -#define getbegx(win) ((win)?(win)->_begx:ERR) -#define getbegy(win) ((win)?(win)->_begy:ERR) -#define getmaxx(win) ((win)?((win)->_maxx + 1):ERR) -#define getmaxy(win) ((win)?((win)->_maxy + 1):ERR) -#define getparx(win) ((win)?(win)->_parx:ERR) -#define getpary(win) ((win)?(win)->_pary:ERR) +#if !NCURSES_OPAQUE +#define getattrs(win) ((win) ? (win)->_attrs : A_NORMAL) +#define getcurx(win) ((win) ? (win)->_curx : ERR) +#define getcury(win) ((win) ? (win)->_cury : ERR) +#define getbegx(win) ((win) ? (win)->_begx : ERR) +#define getbegy(win) ((win) ? (win)->_begy : ERR) +#define getmaxx(win) ((win) ? ((win)->_maxx + 1) : ERR) +#define getmaxy(win) ((win) ? ((win)->_maxy + 1) : ERR) +#define getparx(win) ((win) ? (win)->_parx : ERR) +#define getpary(win) ((win) ? (win)->_pary : ERR) +#endif /* NCURSES_OPAQUE */ #define wstandout(win) (wattrset(win,A_STANDOUT)) #define wstandend(win) (wattrset(win,A_NORMAL)) -#define wattr_set(win,a,p,opts) ((win)->_attrs = (((a) & ~A_COLOR) | COLOR_PAIR(p)), OK) -#define wattron(win,at) wattr_on(win, at, (void *)0) -#define wattroff(win,at) wattr_off(win, at, (void *)0) -#define wattrset(win,at) ((win)->_attrs = (at)) +#define wattron(win,at) wattr_on(win, NCURSES_CAST(attr_t, at), NULL) +#define wattroff(win,at) wattr_off(win, NCURSES_CAST(attr_t, at), NULL) + +#if !NCURSES_OPAQUE +#if defined(_XOPEN_SOURCE_EXTENDED) && 0 +#define wattrset(win,at) ((win)->_color = PAIR_NUMBER(at), \ + (win)->_attrs = (at)) +#else +#define wattrset(win,at) ((win)->_attrs = (at)) +#endif +#endif /* NCURSES_OPAQUE */ #define scroll(win) wscrl(win,1) @@ -973,183 +1002,142 @@ extern NCURSES_EXPORT(bool) mouse_trafo (int*, int*, bool); /* gene #define winchstr(w, s) winchnstr(w, s, -1) #define winsstr(w, s) winsnstr(w, s, -1) +#if !NCURSES_OPAQUE #define redrawwin(win) wredrawln(win, 0, (win)->_maxy+1) +#endif /* NCURSES_OPAQUE */ + #define waddstr(win,str) waddnstr(win,str,-1) #define waddchstr(win,str) waddchnstr(win,str,-1) /* + * These apply to the first 256 color pairs. + */ +#define COLOR_PAIR(n) NCURSES_BITS(n, 0) +#define PAIR_NUMBER(a) (NCURSES_CAST(int,(((a) & A_COLOR) >> NCURSES_ATTR_SHIFT))) + +/* * pseudo functions for standard screen */ -#define addch(ch) waddch(stdscr,ch) +#define addch(ch) waddch(stdscr,ch) #define addchnstr(str,n) waddchnstr(stdscr,str,n) #define addchstr(str) waddchstr(stdscr,str) #define addnstr(str,n) waddnstr(stdscr,str,n) -#define addstr(str) waddnstr(stdscr,str,-1) -#define attroff(at) wattroff(stdscr,at) -#define attron(at) wattron(stdscr,at) -#define attrset(at) wattrset(stdscr,at) +#define addstr(str) waddnstr(stdscr,str,-1) +#define attroff(at) wattroff(stdscr,at) +#define attron(at) wattron(stdscr,at) +#define attrset(at) wattrset(stdscr,at) +#define attr_get(ap,cp,o) wattr_get(stdscr,ap,cp,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,c,o) wattr_set(stdscr,a,c,o) #define bkgd(ch) wbkgd(stdscr,ch) #define bkgdset(ch) wbkgdset(stdscr,ch) -#define clear() wclear(stdscr) -#define clrtobot() wclrtobot(stdscr) -#define clrtoeol() wclrtoeol(stdscr) +#define chgat(n,a,c,o) wchgat(stdscr,n,a,c,o) +#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() winsdelln(stdscr,-1) +#define delch() wdelch(stdscr) +#define deleteln() winsdelln(stdscr,-1) #define echochar(c) wechochar(stdscr,c) -#define erase() werase(stdscr) -#define getch() wgetch(stdscr) -#define getstr(str) wgetstr(stdscr,str) -#define inch() winch(stdscr) +#define erase() werase(stdscr) +#define getch() wgetch(stdscr) +#define getstr(str) wgetstr(stdscr,str) +#define inch() winch(stdscr) #define inchnstr(s,n) winchnstr(stdscr,s,n) #define inchstr(s) winchstr(stdscr,s) #define innstr(s,n) winnstr(stdscr,s,n) -#define insch(c) winsch(stdscr,c) +#define insch(c) winsch(stdscr,c) #define insdelln(n) winsdelln(stdscr,n) -#define insertln() winsdelln(stdscr,1) +#define insertln() winsdelln(stdscr,1) #define insnstr(s,n) winsnstr(stdscr,s,n) #define insstr(s) winsstr(stdscr,s) #define instr(s) winstr(stdscr,s) -#define move(y,x) wmove(stdscr,y,x) -#define refresh() wrefresh(stdscr) +#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 setscrreg(t,b) wsetscrreg(stdscr,t,b) +#define standend() wstandend(stdscr) +#define standout() wstandout(stdscr) #define timeout(delay) wtimeout(stdscr,delay) -#define wdeleteln(win) winsdelln(win,-1) -#define winsertln(win) winsdelln(win,1) +#define wdeleteln(win) winsdelln(win,-1) +#define winsertln(win) winsdelln(win,1) /* * mv functions */ -#define mvwaddch(win,y,x,ch) (wmove(win,y,x) == ERR ? ERR : waddch(win,ch)) +#define mvwaddch(win,y,x,ch) (wmove(win,y,x) == ERR ? ERR : waddch(win,ch)) #define mvwaddchnstr(win,y,x,str,n) (wmove(win,y,x) == ERR ? ERR : waddchnstr(win,str,n)) -#define mvwaddchstr(win,y,x,str) (wmove(win,y,x) == ERR ? ERR : waddchnstr(win,str,-1)) +#define mvwaddchstr(win,y,x,str) (wmove(win,y,x) == ERR ? ERR : waddchnstr(win,str,-1)) #define mvwaddnstr(win,y,x,str,n) (wmove(win,y,x) == ERR ? ERR : waddnstr(win,str,n)) -#define mvwaddstr(win,y,x,str) (wmove(win,y,x) == ERR ? ERR : waddnstr(win,str,-1)) -#define mvwdelch(win,y,x) (wmove(win,y,x) == ERR ? ERR : wdelch(win)) -#define mvwgetch(win,y,x) (wmove(win,y,x) == ERR ? ERR : wgetch(win)) -#define mvwgetnstr(win,y,x,str,n) (wmove(win,y,x) == ERR ? ERR : wgetnstr(win,str,n)) -#define mvwgetstr(win,y,x,str) (wmove(win,y,x) == ERR ? ERR : wgetstr(win,str)) -#define mvwhline(win,y,x,c,n) (wmove(win,y,x) == ERR ? ERR : whline(win,c,n)) -#define mvwinch(win,y,x) (wmove(win,y,x) == ERR ? (chtype)ERR : winch(win)) +#define mvwaddstr(win,y,x,str) (wmove(win,y,x) == ERR ? ERR : waddnstr(win,str,-1)) +#define mvwdelch(win,y,x) (wmove(win,y,x) == ERR ? ERR : wdelch(win)) +#define mvwchgat(win,y,x,n,a,c,o) (wmove(win,y,x) == ERR ? ERR : wchgat(win,n,a,c,o)) +#define mvwgetch(win,y,x) (wmove(win,y,x) == ERR ? ERR : wgetch(win)) +#define mvwgetnstr(win,y,x,str,n) (wmove(win,y,x) == ERR ? ERR : wgetnstr(win,str,n)) +#define mvwgetstr(win,y,x,str) (wmove(win,y,x) == ERR ? ERR : wgetstr(win,str)) +#define mvwhline(win,y,x,c,n) (wmove(win,y,x) == ERR ? ERR : whline(win,c,n)) +#define mvwinch(win,y,x) (wmove(win,y,x) == ERR ? NCURSES_CAST(chtype, ERR) : winch(win)) #define mvwinchnstr(win,y,x,s,n) (wmove(win,y,x) == ERR ? ERR : winchnstr(win,s,n)) #define mvwinchstr(win,y,x,s) (wmove(win,y,x) == ERR ? ERR : winchstr(win,s)) #define mvwinnstr(win,y,x,s,n) (wmove(win,y,x) == ERR ? ERR : winnstr(win,s,n)) -#define mvwinsch(win,y,x,c) (wmove(win,y,x) == ERR ? ERR : winsch(win,c)) +#define mvwinsch(win,y,x,c) (wmove(win,y,x) == ERR ? ERR : winsch(win,c)) #define mvwinsnstr(win,y,x,s,n) (wmove(win,y,x) == ERR ? ERR : winsnstr(win,s,n)) #define mvwinsstr(win,y,x,s) (wmove(win,y,x) == ERR ? ERR : winsstr(win,s)) #define mvwinstr(win,y,x,s) (wmove(win,y,x) == ERR ? ERR : winstr(win,s)) -#define mvwvline(win,y,x,c,n) (wmove(win,y,x) == ERR ? ERR : wvline(win,c,n)) +#define mvwvline(win,y,x,c,n) (wmove(win,y,x) == ERR ? ERR : wvline(win,c,n)) -#define mvaddch(y,x,ch) mvwaddch(stdscr,y,x,ch) +#define mvaddch(y,x,ch) mvwaddch(stdscr,y,x,ch) #define mvaddchnstr(y,x,str,n) mvwaddchnstr(stdscr,y,x,str,n) #define mvaddchstr(y,x,str) mvwaddchstr(stdscr,y,x,str) #define mvaddnstr(y,x,str,n) mvwaddnstr(stdscr,y,x,str,n) -#define mvaddstr(y,x,str) mvwaddstr(stdscr,y,x,str) -#define mvdelch(y,x) mvwdelch(stdscr,y,x) -#define mvgetch(y,x) mvwgetch(stdscr,y,x) +#define mvaddstr(y,x,str) mvwaddstr(stdscr,y,x,str) +#define mvchgat(y,x,n,a,c,o) mvwchgat(stdscr,y,x,n,a,c,o) +#define mvdelch(y,x) mvwdelch(stdscr,y,x) +#define mvgetch(y,x) mvwgetch(stdscr,y,x) #define mvgetnstr(y,x,str,n) mvwgetnstr(stdscr,y,x,str,n) -#define mvgetstr(y,x,str) mvwgetstr(stdscr,y,x,str) +#define mvgetstr(y,x,str) mvwgetstr(stdscr,y,x,str) #define mvhline(y,x,c,n) mvwhline(stdscr,y,x,c,n) -#define mvinch(y,x) mvwinch(stdscr,y,x) +#define mvinch(y,x) mvwinch(stdscr,y,x) #define mvinchnstr(y,x,s,n) mvwinchnstr(stdscr,y,x,s,n) #define mvinchstr(y,x,s) mvwinchstr(stdscr,y,x,s) #define mvinnstr(y,x,s,n) mvwinnstr(stdscr,y,x,s,n) -#define mvinsch(y,x,c) mvwinsch(stdscr,y,x,c) +#define mvinsch(y,x,c) mvwinsch(stdscr,y,x,c) #define mvinsnstr(y,x,s,n) mvwinsnstr(stdscr,y,x,s,n) #define mvinsstr(y,x,s) mvwinsstr(stdscr,y,x,s) #define mvinstr(y,x,s) mvwinstr(stdscr,y,x,s) #define mvvline(y,x,c,n) mvwvline(stdscr,y,x,c,n) /* - * XSI curses macros for XPG4 conformance. - * The underlying functions needed to make these work are: - * waddnwstr(), waddchnwstr(), wadd_wch(), wborder_set(), wchgat(), - * wecho_wchar(), wgetn_wstr(), wget_wch(), whline_set(), vhline_set(), - * winnwstr(), wins_nwstr(), wins_wch(), win_wch(), win_wchnstr(). - * Except for wchgat(), these are not yet implemented. They will be someday. + * Some wide-character functions can be implemented without the extensions. */ -#define add_wch(c) wadd_wch(stdscr,c) -#define addnwstr(wstr,n) waddnwstr(stdscr,wstr,n) -#define addwstr(wstr,n) waddnwstr(stdscr,wstr,-1) -#define attr_get(a,pair,opts) wattr_get(stdscr,a,pair,opts) -#define attr_off(a,opts) wattr_off(stdscr,a,opts) -#define attr_on(a,opts) wattr_on(stdscr,a,opts) -#define attr_set(a,pair,opts) wattr_set(stdscr,a,pair,opts) -#define box_set(w,v,h) wborder_set(w,v,v,h,h,0,0,0,0) -#define chgat(n,a,c,o) wchgat(stdscr,n,a,c,o) -#define echo_wchar(c) wecho_wchar(stdscr,c) -#define getbkgd(win) ((win)->_bkgd) -#define get_wch(c) wget_wch(stdscr,c) -#define get_wstr(t) wgetn_wstr(stdscr,t,-1) -#define getn_wstr(t,n) wgetn_wstr(stdscr,t,n) -#define hline_set(c,n) whline_set(stdscr,c,n) -#define in_wch(c) win_wch(stdscr,c) -#define in_wchnstr(c,n) win_wchnstr(stdscr,c,n) -#define in_wchstr(c) win_wchnstr(stdscr,c,-1) -#define innwstr(c,n) winnwstr(stdscr,c,n) -#define ins_nwstr(t,n) wins_nwstr(stdscr,t,n) -#define ins_wch(c) wins_wch(stdscr,c) -#define ins_wstr(t) wins_nwstr(stdscr,t,-1) -#define inwstr(c) winnwstr(stdscr,c,-1) - -#define mvadd_wch(y,x,c) mvwadd_wch(stdscr,y,x,c) -#define mvaddnwstr(y,x,wstr,n) mvwaddnwstr(stdscr,y,x,wstr,n) -#define mvaddwstr(y,x,wstr,n) mvwaddnwstr(stdscr,y,x,wstr,-1) -#define mvchgat(y,x,n,a,c,o) mvwchgat(stdscr,y,x,n,a,c,o) -#define mvget_wch(y,x,c) mvwget_wch(stdscr,y,x,c) -#define mvget_wstr(y,x,t) mvwgetn_wstr(stdscr,y,x,t,-1) -#define mvgetn_wstr(y,x,t,n) mvwgetn_wstr(stdscr,y,x,t,n) -#define mvhline_set(y,x,c,n) mvwhline_set(stdscr,y,x,c,n) -#define mvin_wch(y,x,c) mvwin_wch(stdscr,y,x,c) -#define mvin_wchnstr(y,x,c,n) mvwin_wchnstr(stdscr,y,x,c,n) -#define mvin_wchstr(y,x,c) mvwin_wchnstr(stdscr,y,x,c,-1) -#define mvinnwstr(y,x,c,n) mvwinnwstr(stdscr,y,x,c,n) -#define mvins_nwstr(y,x,t,n) mvwins_nwstr(stdscr,y,x,t,n) -#define mvins_wch(y,x,c) mvwins_wch(stdscr,y,x,c) -#define mvins_wstr(y,x,t) mvwins_nwstr(stdscr,y,x,t,-1) -#define mvinwstr(y,x,c) mvwinnwstr(stdscr,y,x,c,-1) -#define mvvline_set(y,x,c,n) mvwvline_set(stdscr,y,x,c,n) - -#define mvwadd_wch(win,y,x,c) (wmove(win,y,x) == ERR ? ERR : wadd_wch(stdscr,c)) -#define mvwaddnwstr(win,y,x,wstr,n) (wmove(win,y,x) == ERR ? ERR : waddnwstr(stdscr,wstr,n)) -#define mvwaddwstr(win,y,x,wstr,n) (wmove(win,y,x) == ERR ? ERR : waddnwstr(stdscr,wstr,-1)) -#define mvwchgat(win,y,x,n,a,c,o) (wmove(win,y,x) == ERR ? ERR : wchgat(win,n,a,c,o)) -#define mvwget_wch(win,y,x,c) (wmove(win,y,x) == ERR ? ERR : wget_wch(win,c)) -#define mvwget_wstr(win,y,x,t) (wmove(win,y,x) == ERR ? ERR : wgetn_wstr(win,t,-1)) -#define mvwgetn_wstr(win,y,x,t,n) (wmove(win,y,x) == ERR ? ERR : wgetn_wstr(win,t,n)) -#define mvwhline_set(win,y,x,c,n) (wmove(win,y,x) == ERR ? ERR : whline_set(win,c,n)) -#define mvwin_wch(win,y,x,c) (wmove(win,y,x) == ERR ? ERR : win_wch(win,c)) -#define mvwin_wchnstr(win,y,x,c,n) (wmove(win,y,x) == ERR ? ERR : win_wchnstr(stdscr,c,n)) -#define mvwin_wchstr(win,y,x,c) (wmove(win,y,x) == ERR ? ERR : win_wchnstr(stdscr,c,-1)) -#define mvwinnwstr(win,y,x,c,n) (wmove(win,y,x) == ERR ? ERR : winnwstr(stdscr,c,n)) -#define mvwins_nwstr(win,y,x,t,n) (wmove(win,y,x) == ERR ? ERR : wins_nwstr(stdscr,t,n)) -#define mvwins_wch(win,y,x,c) (wmove(win,y,x) == ERR ? ERR : wins_wch(stdscr,c)) -#define mvwins_wstr(win,y,x,t) (wmove(win,y,x) == ERR ? ERR : wins_nwstr(stdscr,t,-1)) -#define mvwinwstr(win,y,x,c) (wmove(win,y,x) == ERR ? ERR : winnwstr(stdscr,c,-1)) -#define mvwvline_set(win,y,x,c,n) (wmove(win,y,x) == ERR ? ERR : wvline_set(win,c,n)) +#if !NCURSES_OPAQUE +#define getbkgd(win) ((win)->_bkgd) +#endif /* NCURSES_OPAQUE */ #define slk_attr_off(a,v) ((v) ? ERR : slk_attroff(a)) #define slk_attr_on(a,v) ((v) ? ERR : slk_attron(a)) -#define vid_attr(a,pair,opts) vidattr(a) -#define vline_set(c,n) wvline_set(stdscr,c,n) -#define waddwstr(win,wstr,n) waddnwstr(win,wstr,-1) -#define wattr_get(win,a,p,opts) ((void)((a) != 0 && (*(a) = (win)->_attrs)), \ - (void)((p) != 0 && (*(p) = PAIR_NUMBER((win)->_attrs))), \ +#if !NCURSES_OPAQUE +#if defined(_XOPEN_SOURCE_EXTENDED) && 0 +#define wattr_set(win,a,p,opts) ((win)->_attrs = ((a) & ~A_COLOR), \ + (win)->_color = (p), \ OK) -#define wget_wstr(w,t) wgetn_wstr(w,t,-1) -#define win_wchstr(w,c) win_wchnstr(w,c,-1) -#define wins_wstr(w,t) wins_nwstr(w,t,-1) -#define winwstr(w,c) winnwstr(w,c,-1) - +#define wattr_get(win,a,p,opts) ((void)((a) != (void *)0 && (*(a) = (win)->_attrs)), \ + (void)((p) != (void *)0 && (*(p) = (win)->_color)), \ + OK) +#else +#define wattr_set(win,a,p,opts) ((win)->_attrs = (((a) & ~A_COLOR) | COLOR_PAIR(p)), OK) +#define wattr_get(win,a,p,opts) ((void)((a) != (void *)0 && (*(a) = (win)->_attrs)), \ + (void)((p) != (void *)0 && (*(p) = PAIR_NUMBER((win)->_attrs))), \ + OK) +#endif +#endif /* NCURSES_OPAQUE */ /* - * XSI curses deprecates SVr4 vwprintw/vwscanw, which are supposed to use + * X/Open curses deprecates SVr4 vwprintw/vwscanw, which are supposed to use * varargs.h. It adds new calls vw_printw/vw_scanw, which are supposed to * use POSIX stdarg.h. The ncurses versions of vwprintw/vwscanw already * use stdarg.h, so... @@ -1158,155 +1146,281 @@ extern NCURSES_EXPORT(bool) mouse_trafo (int*, int*, bool); /* gene #define vw_scanw vwscanw /* + * Export fallback function for use in C++ binding. + */ +#if !1 +#define vsscanf(a,b,c) _nc_vsscanf(a,b,c) +NCURSES_EXPORT(int) vsscanf(const char *, const char *, va_list); +#endif + +/* + * These macros are extensions - not in X/Open Curses. + */ +#if 1 +#if !NCURSES_OPAQUE +#define is_cleared(win) ((win)->_clear) +#define is_idcok(win) ((win)->_idcok) +#define is_idlok(win) ((win)->_idlok) +#define is_immedok(win) ((win)->_immed) +#define is_keypad(win) ((win)->_use_keypad) +#define is_leaveok(win) ((win)->_leaveok) +#define is_nodelay(win) ((win)->_delay == 0) +#define is_notimeout(win) ((win)->_notimeout) +#define is_scrollok(win) ((win)->_scroll) +#define is_syncok(win) ((win)->_sync) +#define wgetparent(win) ((win) ? (win)->_parent : 0) +#define wgetscrreg(win,t,b) ((win) ? (*(t) = (win)->_regtop, *(b) = (win)->_regbottom, OK) : ERR) +#endif +#endif + +#endif /* NCURSES_NOMACROS */ + +/* + * Public variables. + * + * Notes: + * a. ESCDELAY was an undocumented feature under AIX curses. + * It gives the ESC expire time in milliseconds. + * b. ttytype is needed for backward compatibility + */ +#if 0 + +NCURSES_WRAPPED_VAR(WINDOW *, curscr); +NCURSES_WRAPPED_VAR(WINDOW *, newscr); +NCURSES_WRAPPED_VAR(WINDOW *, stdscr); +NCURSES_WRAPPED_VAR(char *, ttytype); +NCURSES_WRAPPED_VAR(int, COLORS); +NCURSES_WRAPPED_VAR(int, COLOR_PAIRS); +NCURSES_WRAPPED_VAR(int, COLS); +NCURSES_WRAPPED_VAR(int, ESCDELAY); +NCURSES_WRAPPED_VAR(int, LINES); +NCURSES_WRAPPED_VAR(int, TABSIZE); + +#define curscr NCURSES_PUBLIC_VAR(curscr()) +#define newscr NCURSES_PUBLIC_VAR(newscr()) +#define stdscr NCURSES_PUBLIC_VAR(stdscr()) +#define ttytype NCURSES_PUBLIC_VAR(ttytype()) +#define COLORS NCURSES_PUBLIC_VAR(COLORS()) +#define COLOR_PAIRS NCURSES_PUBLIC_VAR(COLOR_PAIRS()) +#define COLS NCURSES_PUBLIC_VAR(COLS()) +#define ESCDELAY NCURSES_PUBLIC_VAR(ESCDELAY()) +#define LINES NCURSES_PUBLIC_VAR(LINES()) +#define TABSIZE NCURSES_PUBLIC_VAR(TABSIZE()) + +#else + +extern NCURSES_EXPORT_VAR(WINDOW *) curscr; +extern NCURSES_EXPORT_VAR(WINDOW *) newscr; +extern NCURSES_EXPORT_VAR(WINDOW *) stdscr; +extern NCURSES_EXPORT_VAR(char) ttytype[]; +extern NCURSES_EXPORT_VAR(int) COLORS; +extern NCURSES_EXPORT_VAR(int) COLOR_PAIRS; +extern NCURSES_EXPORT_VAR(int) COLS; +extern NCURSES_EXPORT_VAR(int) ESCDELAY; +extern NCURSES_EXPORT_VAR(int) LINES; +extern NCURSES_EXPORT_VAR(int) TABSIZE; + +#endif + +/* * Pseudo-character tokens outside ASCII range. The curses wgetch() function * will return any given one of these only if the corresponding k- capability * is defined in your terminal's terminfo entry. + * + * Some keys (KEY_A1, etc) are arranged like this: + * a1 up a3 + * left b2 right + * c1 down c3 + * + * A few key codes do not depend upon the terminfo entry. */ #define KEY_CODE_YES 0400 /* A wchar_t contains a key code */ #define KEY_MIN 0401 /* Minimum curses key */ -#define KEY_BREAK 0401 /* Break key (unreliable) */ -#define KEY_DOWN 0402 /* Down-arrow */ -#define KEY_UP 0403 /* Up-arrow */ -#define KEY_LEFT 0404 /* Left-arrow */ -#define KEY_RIGHT 0405 /* Right-arrow */ -#define KEY_HOME 0406 /* Home key (upward+left arrow) */ -#define KEY_BACKSPACE 0407 /* Backspace (unreliable) */ -#define KEY_F0 0410 /* Function keys. Space for 64 */ -#define KEY_F(n) (KEY_F0+(n)) /* Value of function key n */ -#define KEY_DL 0510 /* Delete line */ -#define KEY_IL 0511 /* Insert line */ -#define KEY_DC 0512 /* Delete character */ -#define KEY_IC 0513 /* Insert char or enter insert mode */ -#define KEY_EIC 0514 /* Exit insert char mode */ -#define KEY_CLEAR 0515 /* Clear screen */ -#define KEY_EOS 0516 /* Clear to end of screen */ -#define KEY_EOL 0517 /* Clear to end of line */ -#define KEY_SF 0520 /* Scroll 1 line forward */ -#define KEY_SR 0521 /* Scroll 1 line backward (reverse) */ -#define KEY_NPAGE 0522 /* Next page */ -#define KEY_PPAGE 0523 /* Previous page */ -#define KEY_STAB 0524 /* Set tab */ -#define KEY_CTAB 0525 /* Clear tab */ -#define KEY_CATAB 0526 /* Clear all tabs */ -#define KEY_ENTER 0527 /* Enter or send (unreliable) */ -#define KEY_SRESET 0530 /* Soft (partial) reset (unreliable) */ -#define KEY_RESET 0531 /* Reset or hard reset (unreliable) */ -#define KEY_PRINT 0532 /* Print */ -#define KEY_LL 0533 /* Home down or bottom (lower left) */ - -/* The keypad is arranged like this: */ -/* a1 up a3 */ -/* left b2 right */ -/* c1 down c3 */ - -#define KEY_A1 0534 /* Upper left of keypad */ -#define KEY_A3 0535 /* Upper right of keypad */ -#define KEY_B2 0536 /* Center of keypad */ -#define KEY_C1 0537 /* Lower left of keypad */ -#define KEY_C3 0540 /* Lower right of keypad */ -#define KEY_BTAB 0541 /* Back tab */ -#define KEY_BEG 0542 /* Beg (beginning) */ -#define KEY_CANCEL 0543 /* Cancel */ -#define KEY_CLOSE 0544 /* Close */ -#define KEY_COMMAND 0545 /* Cmd (command) */ -#define KEY_COPY 0546 /* Copy */ -#define KEY_CREATE 0547 /* Create */ -#define KEY_END 0550 /* End */ -#define KEY_EXIT 0551 /* Exit */ -#define KEY_FIND 0552 /* Find */ -#define KEY_HELP 0553 /* Help */ -#define KEY_MARK 0554 /* Mark */ -#define KEY_MESSAGE 0555 /* Message */ -#define KEY_MOVE 0556 /* Move */ -#define KEY_NEXT 0557 /* Next */ -#define KEY_OPEN 0560 /* Open */ -#define KEY_OPTIONS 0561 /* Options */ -#define KEY_PREVIOUS 0562 /* Prev (previous) */ -#define KEY_REDO 0563 /* Redo */ -#define KEY_REFERENCE 0564 /* Ref (reference) */ -#define KEY_REFRESH 0565 /* Refresh */ -#define KEY_REPLACE 0566 /* Replace */ -#define KEY_RESTART 0567 /* Restart */ -#define KEY_RESUME 0570 /* Resume */ -#define KEY_SAVE 0571 /* Save */ -#define KEY_SBEG 0572 /* Shifted Beg (beginning) */ -#define KEY_SCANCEL 0573 /* Shifted Cancel */ -#define KEY_SCOMMAND 0574 /* Shifted Command */ -#define KEY_SCOPY 0575 /* Shifted Copy */ -#define KEY_SCREATE 0576 /* Shifted Create */ -#define KEY_SDC 0577 /* Shifted Delete char */ -#define KEY_SDL 0600 /* Shifted Delete line */ -#define KEY_SELECT 0601 /* Select */ -#define KEY_SEND 0602 /* Shifted End */ -#define KEY_SEOL 0603 /* Shifted Clear line */ -#define KEY_SEXIT 0604 /* Shifted Dxit */ -#define KEY_SFIND 0605 /* Shifted Find */ -#define KEY_SHELP 0606 /* Shifted Help */ -#define KEY_SHOME 0607 /* Shifted Home */ -#define KEY_SIC 0610 /* Shifted Input */ -#define KEY_SLEFT 0611 /* Shifted Left arrow */ -#define KEY_SMESSAGE 0612 /* Shifted Message */ -#define KEY_SMOVE 0613 /* Shifted Move */ -#define KEY_SNEXT 0614 /* Shifted Next */ -#define KEY_SOPTIONS 0615 /* Shifted Options */ -#define KEY_SPREVIOUS 0616 /* Shifted Prev */ -#define KEY_SPRINT 0617 /* Shifted Print */ -#define KEY_SREDO 0620 /* Shifted Redo */ -#define KEY_SREPLACE 0621 /* Shifted Replace */ -#define KEY_SRIGHT 0622 /* Shifted Right arrow */ -#define KEY_SRSUME 0623 /* Shifted Resume */ -#define KEY_SSAVE 0624 /* Shifted Save */ -#define KEY_SSUSPEND 0625 /* Shifted Suspend */ -#define KEY_SUNDO 0626 /* Shifted Undo */ -#define KEY_SUSPEND 0627 /* Suspend */ -#define KEY_UNDO 0630 /* Undo */ +#define KEY_BREAK 0401 /* Break key (unreliable) */ +#define KEY_SRESET 0530 /* Soft (partial) reset (unreliable) */ +#define KEY_RESET 0531 /* Reset or hard reset (unreliable) */ +/* + * These definitions were generated by ./MKkey_defs.sh ./Caps + */ +#define KEY_DOWN 0402 /* down-arrow key */ +#define KEY_UP 0403 /* up-arrow key */ +#define KEY_LEFT 0404 /* left-arrow key */ +#define KEY_RIGHT 0405 /* right-arrow key */ +#define KEY_HOME 0406 /* home key */ +#define KEY_BACKSPACE 0407 /* backspace key */ +#define KEY_F0 0410 /* Function keys. Space for 64 */ +#define KEY_F(n) (KEY_F0+(n)) /* Value of function key n */ +#define KEY_DL 0510 /* delete-line key */ +#define KEY_IL 0511 /* insert-line key */ +#define KEY_DC 0512 /* delete-character key */ +#define KEY_IC 0513 /* insert-character key */ +#define KEY_EIC 0514 /* sent by rmir or smir in insert mode */ +#define KEY_CLEAR 0515 /* clear-screen or erase key */ +#define KEY_EOS 0516 /* clear-to-end-of-screen key */ +#define KEY_EOL 0517 /* clear-to-end-of-line key */ +#define KEY_SF 0520 /* scroll-forward key */ +#define KEY_SR 0521 /* scroll-backward key */ +#define KEY_NPAGE 0522 /* next-page key */ +#define KEY_PPAGE 0523 /* previous-page key */ +#define KEY_STAB 0524 /* set-tab key */ +#define KEY_CTAB 0525 /* clear-tab key */ +#define KEY_CATAB 0526 /* clear-all-tabs key */ +#define KEY_ENTER 0527 /* enter/send key */ +#define KEY_PRINT 0532 /* print key */ +#define KEY_LL 0533 /* lower-left key (home down) */ +#define KEY_A1 0534 /* upper left of keypad */ +#define KEY_A3 0535 /* upper right of keypad */ +#define KEY_B2 0536 /* center of keypad */ +#define KEY_C1 0537 /* lower left of keypad */ +#define KEY_C3 0540 /* lower right of keypad */ +#define KEY_BTAB 0541 /* back-tab key */ +#define KEY_BEG 0542 /* begin key */ +#define KEY_CANCEL 0543 /* cancel key */ +#define KEY_CLOSE 0544 /* close key */ +#define KEY_COMMAND 0545 /* command key */ +#define KEY_COPY 0546 /* copy key */ +#define KEY_CREATE 0547 /* create key */ +#define KEY_END 0550 /* end key */ +#define KEY_EXIT 0551 /* exit key */ +#define KEY_FIND 0552 /* find key */ +#define KEY_HELP 0553 /* help key */ +#define KEY_MARK 0554 /* mark key */ +#define KEY_MESSAGE 0555 /* message key */ +#define KEY_MOVE 0556 /* move key */ +#define KEY_NEXT 0557 /* next key */ +#define KEY_OPEN 0560 /* open key */ +#define KEY_OPTIONS 0561 /* options key */ +#define KEY_PREVIOUS 0562 /* previous key */ +#define KEY_REDO 0563 /* redo key */ +#define KEY_REFERENCE 0564 /* reference key */ +#define KEY_REFRESH 0565 /* refresh key */ +#define KEY_REPLACE 0566 /* replace key */ +#define KEY_RESTART 0567 /* restart key */ +#define KEY_RESUME 0570 /* resume key */ +#define KEY_SAVE 0571 /* save key */ +#define KEY_SBEG 0572 /* shifted begin key */ +#define KEY_SCANCEL 0573 /* shifted cancel key */ +#define KEY_SCOMMAND 0574 /* shifted command key */ +#define KEY_SCOPY 0575 /* shifted copy key */ +#define KEY_SCREATE 0576 /* shifted create key */ +#define KEY_SDC 0577 /* shifted delete-character key */ +#define KEY_SDL 0600 /* shifted delete-line key */ +#define KEY_SELECT 0601 /* select key */ +#define KEY_SEND 0602 /* shifted end key */ +#define KEY_SEOL 0603 /* shifted clear-to-end-of-line key */ +#define KEY_SEXIT 0604 /* shifted exit key */ +#define KEY_SFIND 0605 /* shifted find key */ +#define KEY_SHELP 0606 /* shifted help key */ +#define KEY_SHOME 0607 /* shifted home key */ +#define KEY_SIC 0610 /* shifted insert-character key */ +#define KEY_SLEFT 0611 /* shifted left-arrow key */ +#define KEY_SMESSAGE 0612 /* shifted message key */ +#define KEY_SMOVE 0613 /* shifted move key */ +#define KEY_SNEXT 0614 /* shifted next key */ +#define KEY_SOPTIONS 0615 /* shifted options key */ +#define KEY_SPREVIOUS 0616 /* shifted previous key */ +#define KEY_SPRINT 0617 /* shifted print key */ +#define KEY_SREDO 0620 /* shifted redo key */ +#define KEY_SREPLACE 0621 /* shifted replace key */ +#define KEY_SRIGHT 0622 /* shifted right-arrow key */ +#define KEY_SRSUME 0623 /* shifted resume key */ +#define KEY_SSAVE 0624 /* shifted save key */ +#define KEY_SSUSPEND 0625 /* shifted suspend key */ +#define KEY_SUNDO 0626 /* shifted undo key */ +#define KEY_SUSPEND 0627 /* suspend key */ +#define KEY_UNDO 0630 /* undo key */ #define KEY_MOUSE 0631 /* Mouse event has occurred */ #define KEY_RESIZE 0632 /* Terminal resize event */ -#define KEY_MAX 0777 /* Maximum key value */ +#define KEY_EVENT 0633 /* We were interrupted by an event */ + +#define KEY_MAX 0777 /* Maximum key value is 0633 */ +/* $Id: curses.h,v 1.60 2010/01/12 23:21:59 nicm Exp $ */ +/* + * vile:cmode: + * This file is part of ncurses, designed to be appended after curses.h.in + * (see that file for the relevant copyright). + */ /* mouse interface */ -#define NCURSES_MOUSE_VERSION 1 + +#if NCURSES_MOUSE_VERSION > 1 +#define NCURSES_MOUSE_MASK(b,m) ((m) << (((b) - 1) * 5)) +#else +#define NCURSES_MOUSE_MASK(b,m) ((m) << (((b) - 1) * 6)) +#endif + +#define NCURSES_BUTTON_RELEASED 001L +#define NCURSES_BUTTON_PRESSED 002L +#define NCURSES_BUTTON_CLICKED 004L +#define NCURSES_DOUBLE_CLICKED 010L +#define NCURSES_TRIPLE_CLICKED 020L +#define NCURSES_RESERVED_EVENT 040L /* event masks */ -#define BUTTON1_RELEASED 000000000001L -#define BUTTON1_PRESSED 000000000002L -#define BUTTON1_CLICKED 000000000004L -#define BUTTON1_DOUBLE_CLICKED 000000000010L -#define BUTTON1_TRIPLE_CLICKED 000000000020L -#define BUTTON1_RESERVED_EVENT 000000000040L -#define BUTTON2_RELEASED 000000000100L -#define BUTTON2_PRESSED 000000000200L -#define BUTTON2_CLICKED 000000000400L -#define BUTTON2_DOUBLE_CLICKED 000000001000L -#define BUTTON2_TRIPLE_CLICKED 000000002000L -#define BUTTON2_RESERVED_EVENT 000000004000L -#define BUTTON3_RELEASED 000000010000L -#define BUTTON3_PRESSED 000000020000L -#define BUTTON3_CLICKED 000000040000L -#define BUTTON3_DOUBLE_CLICKED 000000100000L -#define BUTTON3_TRIPLE_CLICKED 000000200000L -#define BUTTON3_RESERVED_EVENT 000000400000L -#define BUTTON4_RELEASED 000001000000L -#define BUTTON4_PRESSED 000002000000L -#define BUTTON4_CLICKED 000004000000L -#define BUTTON4_DOUBLE_CLICKED 000010000000L -#define BUTTON4_TRIPLE_CLICKED 000020000000L -#define BUTTON4_RESERVED_EVENT 000040000000L -#define BUTTON_CTRL 000100000000L -#define BUTTON_SHIFT 000200000000L -#define BUTTON_ALT 000400000000L -#define ALL_MOUSE_EVENTS 000777777777L -#define REPORT_MOUSE_POSITION 001000000000L +#define BUTTON1_RELEASED NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_RELEASED) +#define BUTTON1_PRESSED NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_PRESSED) +#define BUTTON1_CLICKED NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_CLICKED) +#define BUTTON1_DOUBLE_CLICKED NCURSES_MOUSE_MASK(1, NCURSES_DOUBLE_CLICKED) +#define BUTTON1_TRIPLE_CLICKED NCURSES_MOUSE_MASK(1, NCURSES_TRIPLE_CLICKED) + +#define BUTTON2_RELEASED NCURSES_MOUSE_MASK(2, NCURSES_BUTTON_RELEASED) +#define BUTTON2_PRESSED NCURSES_MOUSE_MASK(2, NCURSES_BUTTON_PRESSED) +#define BUTTON2_CLICKED NCURSES_MOUSE_MASK(2, NCURSES_BUTTON_CLICKED) +#define BUTTON2_DOUBLE_CLICKED NCURSES_MOUSE_MASK(2, NCURSES_DOUBLE_CLICKED) +#define BUTTON2_TRIPLE_CLICKED NCURSES_MOUSE_MASK(2, NCURSES_TRIPLE_CLICKED) + +#define BUTTON3_RELEASED NCURSES_MOUSE_MASK(3, NCURSES_BUTTON_RELEASED) +#define BUTTON3_PRESSED NCURSES_MOUSE_MASK(3, NCURSES_BUTTON_PRESSED) +#define BUTTON3_CLICKED NCURSES_MOUSE_MASK(3, NCURSES_BUTTON_CLICKED) +#define BUTTON3_DOUBLE_CLICKED NCURSES_MOUSE_MASK(3, NCURSES_DOUBLE_CLICKED) +#define BUTTON3_TRIPLE_CLICKED NCURSES_MOUSE_MASK(3, NCURSES_TRIPLE_CLICKED) + +#define BUTTON4_RELEASED NCURSES_MOUSE_MASK(4, NCURSES_BUTTON_RELEASED) +#define BUTTON4_PRESSED NCURSES_MOUSE_MASK(4, NCURSES_BUTTON_PRESSED) +#define BUTTON4_CLICKED NCURSES_MOUSE_MASK(4, NCURSES_BUTTON_CLICKED) +#define BUTTON4_DOUBLE_CLICKED NCURSES_MOUSE_MASK(4, NCURSES_DOUBLE_CLICKED) +#define BUTTON4_TRIPLE_CLICKED NCURSES_MOUSE_MASK(4, NCURSES_TRIPLE_CLICKED) -/* macros to extract single event-bits from masks */ -#define BUTTON_RELEASE(e, x) ((e) & (001 << (6 * ((x) - 1)))) -#define BUTTON_PRESS(e, x) ((e) & (002 << (6 * ((x) - 1)))) -#define BUTTON_CLICK(e, x) ((e) & (004 << (6 * ((x) - 1)))) -#define BUTTON_DOUBLE_CLICK(e, x) ((e) & (010 << (6 * ((x) - 1)))) -#define BUTTON_TRIPLE_CLICK(e, x) ((e) & (020 << (6 * ((x) - 1)))) -#define BUTTON_RESERVED_EVENT(e, x) ((e) & (040 << (6 * ((x) - 1)))) +/* + * In 32 bits the version-1 scheme does not provide enough space for a 5th + * button, unless we choose to change the ABI by omitting the reserved-events. + */ +#if NCURSES_MOUSE_VERSION > 1 -typedef unsigned long mmask_t; +#define BUTTON5_RELEASED NCURSES_MOUSE_MASK(5, NCURSES_BUTTON_RELEASED) +#define BUTTON5_PRESSED NCURSES_MOUSE_MASK(5, NCURSES_BUTTON_PRESSED) +#define BUTTON5_CLICKED NCURSES_MOUSE_MASK(5, NCURSES_BUTTON_CLICKED) +#define BUTTON5_DOUBLE_CLICKED NCURSES_MOUSE_MASK(5, NCURSES_DOUBLE_CLICKED) +#define BUTTON5_TRIPLE_CLICKED NCURSES_MOUSE_MASK(5, NCURSES_TRIPLE_CLICKED) + +#define BUTTON_CTRL NCURSES_MOUSE_MASK(6, 0001L) +#define BUTTON_SHIFT NCURSES_MOUSE_MASK(6, 0002L) +#define BUTTON_ALT NCURSES_MOUSE_MASK(6, 0004L) +#define REPORT_MOUSE_POSITION NCURSES_MOUSE_MASK(6, 0010L) + +#else + +#define BUTTON1_RESERVED_EVENT NCURSES_MOUSE_MASK(1, NCURSES_RESERVED_EVENT) +#define BUTTON2_RESERVED_EVENT NCURSES_MOUSE_MASK(2, NCURSES_RESERVED_EVENT) +#define BUTTON3_RESERVED_EVENT NCURSES_MOUSE_MASK(3, NCURSES_RESERVED_EVENT) +#define BUTTON4_RESERVED_EVENT NCURSES_MOUSE_MASK(4, NCURSES_RESERVED_EVENT) + +#define BUTTON_CTRL NCURSES_MOUSE_MASK(5, 0001L) +#define BUTTON_SHIFT NCURSES_MOUSE_MASK(5, 0002L) +#define BUTTON_ALT NCURSES_MOUSE_MASK(5, 0004L) +#define REPORT_MOUSE_POSITION NCURSES_MOUSE_MASK(5, 0010L) + +#endif + +#define ALL_MOUSE_EVENTS (REPORT_MOUSE_POSITION - 1) + +/* macros to extract single event-bits from masks */ +#define BUTTON_RELEASE(e, x) ((e) & NCURSES_MOUSE_MASK(x, 001)) +#define BUTTON_PRESS(e, x) ((e) & NCURSES_MOUSE_MASK(x, 002)) +#define BUTTON_CLICK(e, x) ((e) & NCURSES_MOUSE_MASK(x, 004)) +#define BUTTON_DOUBLE_CLICK(e, x) ((e) & NCURSES_MOUSE_MASK(x, 010)) +#define BUTTON_TRIPLE_CLICK(e, x) ((e) & NCURSES_MOUSE_MASK(x, 020)) +#define BUTTON_RESERVED_EVENT(e, x) ((e) & NCURSES_MOUSE_MASK(x, 040)) typedef struct { @@ -1321,7 +1435,8 @@ extern NCURSES_EXPORT(int) ungetmouse (MEVENT *); extern NCURSES_EXPORT(mmask_t) mousemask (mmask_t, mmask_t *); extern NCURSES_EXPORT(bool) wenclose (const WINDOW *, int, int); extern NCURSES_EXPORT(int) mouseinterval (int); -extern NCURSES_EXPORT(bool) wmouse_trafo (const WINDOW* win,int* y, int* x, bool to_screen); +extern NCURSES_EXPORT(bool) wmouse_trafo (const WINDOW*, int*, int*, bool); +extern NCURSES_EXPORT(bool) mouse_trafo (int*, int*, bool); /* generated */ #define mouse_trafo(y,x,to_screen) wmouse_trafo(stdscr,y,x,to_screen) @@ -1337,9 +1452,18 @@ extern NCURSES_EXPORT(void) _tracedump (const char *, WINDOW *); extern NCURSES_EXPORT(char *) _traceattr (attr_t); extern NCURSES_EXPORT(char *) _traceattr2 (int, chtype); extern NCURSES_EXPORT(char *) _nc_tracebits (void); -extern NCURSES_EXPORT(char *) _tracechar (const unsigned char); +extern NCURSES_EXPORT(char *) _tracechar (int); extern NCURSES_EXPORT(char *) _tracechtype (chtype); extern NCURSES_EXPORT(char *) _tracechtype2 (int, chtype); +#ifdef _XOPEN_SOURCE_EXTENDED +#define _tracech_t _tracecchar_t +extern NCURSES_EXPORT(char *) _tracecchar_t (const cchar_t *); +#define _tracech_t2 _tracecchar_t2 +extern NCURSES_EXPORT(char *) _tracecchar_t2 (int, const cchar_t *); +#else +#define _tracech_t _tracechtype +#define _tracech_t2 _tracechtype2 +#endif extern NCURSES_EXPORT(char *) _tracemouse (const MEVENT *); extern NCURSES_EXPORT(void) trace (const unsigned int); @@ -1359,7 +1483,9 @@ extern NCURSES_EXPORT(void) trace (const unsigned int); #define TRACE_CCALLS 0x0400 /* trace per-character calls */ #define TRACE_DATABASE 0x0800 /* trace read/write of terminfo/termcap data */ #define TRACE_ATTRS 0x1000 /* trace attribute updates */ -#define TRACE_MAXIMUM 0xffff /* maximum trace level */ + +#define TRACE_SHIFT 13 /* number of bits in the trace masks */ +#define TRACE_MAXIMUM ((1 << TRACE_SHIFT) - 1) /* maximum trace level */ #if defined(TRACE) || defined(NCURSES_TEST) extern NCURSES_EXPORT_VAR(int) _nc_optimize_enable; /* enable optimizations */ @@ -1372,6 +1498,8 @@ extern NCURSES_EXPORT(const char *) _nc_visbuf (const char *); #ifdef __cplusplus +#ifndef NCURSES_NOMACROS + /* these names conflict with STL */ #undef box #undef clear @@ -1379,6 +1507,8 @@ extern NCURSES_EXPORT(const char *) _nc_visbuf (const char *); #undef move #undef refresh +#endif /* NCURSES_NOMACROS */ + } #endif diff --git a/lib/libcurses/curses.priv.h b/lib/libcurses/curses.priv.h index 989a5158751..1b63370a674 100644 --- a/lib/libcurses/curses.priv.h +++ b/lib/libcurses/curses.priv.h @@ -1,7 +1,7 @@ -/* $OpenBSD: curses.priv.h,v 1.32 2003/04/13 11:20:47 jmc Exp $ */ +/* $OpenBSD: curses.priv.h,v 1.33 2010/01/12 23:21:59 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,11 +31,12 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* - * $From: curses.priv.h,v 1.171 2000/12/10 00:13:52 tom Exp $ + * $Id: curses.priv.h,v 1.33 2010/01/12 23:21:59 nicm Exp $ * * curses.priv.h * @@ -90,6 +91,11 @@ extern "C" { # include <sys/param.h> #endif +#include <assert.h> +#include <stdio.h> + +#include <errno.h> + #ifndef PATH_MAX # if defined(_POSIX_PATH_MAX) # define PATH_MAX _POSIX_PATH_MAX @@ -100,11 +106,6 @@ extern "C" { # endif #endif -#include <assert.h> -#include <stdio.h> - -#include <errno.h> - #if DECL_ERRNO extern int errno; #endif @@ -123,6 +124,9 @@ extern int errno; #define USE_FUNC_POLL 0 #endif +/* include signal.h before curses.h to work-around defect in glibc 2.1.3 */ +#include <signal.h> + /* Alessandro Rubini's GPM (general-purpose mouse) */ #if HAVE_LIBGPM && HAVE_GPM_H #define USE_GPM_SUPPORT 1 @@ -139,7 +143,9 @@ extern int errno; /* EMX mouse support */ #ifdef __EMX__ -#define USE_EMX_MOUSE +#define USE_EMX_MOUSE 1 +#else +#define USE_EMX_MOUSE 0 #endif #define DEFAULT_MAXCLICK 166 @@ -151,12 +157,15 @@ extern int errno; */ #if !NCURSES_EXT_FUNCS #undef HAVE_SIZECHANGE +#define HAVE_SIZECHANGE 0 #endif -#if HAVE_SIZECHANGE +#if HAVE_SIZECHANGE && USE_SIGWINCH && defined(SIGWINCH) #define USE_SIZECHANGE 1 #else +#define USE_SIZECHANGE 0 #undef USE_SIGWINCH +#define USE_SIGWINCH 0 #endif /* @@ -210,27 +219,26 @@ extern NCURSES_EXPORT(void *) _nc_memmove (void *, const void *, size_t); * delays and expansion in raw mode. */ -struct tries { - struct tries *child; /* ptr to child. NULL if none */ - struct tries *sibling; /* ptr to sibling. NULL if none */ +#define TRIES struct tries +typedef TRIES { + TRIES *child; /* ptr to child. NULL if none */ + TRIES *sibling; /* ptr to sibling. NULL if none */ unsigned char ch; /* character at this node */ unsigned short value; /* code of string so far. 0 if none. */ -}; - -/* - * Definitions for color pairs - */ -#define C_SHIFT 8 /* we need more bits than there are colors */ -#define C_MASK ((1 << C_SHIFT) - 1) - -#define PAIR_OF(fg, bg) ((((fg) & C_MASK) << C_SHIFT) | ((bg) & C_MASK)) +#undef TRIES +} TRIES; /* * Common/troublesome character definitions */ +#define StringOf(ch) {ch, 0} + #define L_BRACE '{' #define R_BRACE '}' #define S_QUOTE '\'' +#define D_QUOTE '"' + +#define VT_ACSC "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~" /* * Structure for palette tables @@ -238,7 +246,9 @@ struct tries { typedef struct { - short red, green, blue; + short red, green, blue; /* what color_content() returns */ + short r, g, b; /* params to init_color() */ + int init; /* true if we called init_color() */ } color_t; @@ -250,136 +260,574 @@ color_t; #define WINDOWLIST struct _win_list +#if USE_WIDEC_SUPPORT +#define _nc_bkgd _bkgrnd +#else +#undef _XOPEN_SOURCE_EXTENDED +#define _nc_bkgd _bkgd +#define wgetbkgrnd(win, wch) *wch = win->_bkgd +#define wbkgrnd wbkgd +#endif + +#undef NCURSES_OPAQUE +#define NCURSES_INTERNALS 1 +#define NCURSES_OPAQUE 0 + #include <curses.h> /* we'll use -Ipath directive to get the right one! */ +#include <term.h> +#include <term_entry.h> +#include <nc_tparm.h> + +#if NCURSES_EXT_COLORS && USE_WIDEC_SUPPORT +#define if_EXT_COLORS(stmt) stmt +#define NetPair(value,p) (value).ext_color = (p), \ + AttrOf(value) &= ALL_BUT_COLOR, \ + AttrOf(value) |= (A_COLOR & COLOR_PAIR((p > 255) ? 255 : p)) +#define SetPair(value,p) (value).ext_color = (p) +#define GetPair(value) (value).ext_color +#define unColor(n) (AttrOf(n) & ALL_BUT_COLOR) +#define GET_WINDOW_PAIR(w) (w)->_color +#define SET_WINDOW_PAIR(w,p) (w)->_color = (p) +#define SameAttrOf(a,b) (AttrOf(a) == AttrOf(b) && GetPair(a) == GetPair(b)) +#define VIDATTR(attr, pair) vid_attr(attr, pair, 0) +#else +#define if_EXT_COLORS(stmt) /* nothing */ +#define SetPair(value,p) RemAttr(value, A_COLOR), \ + SetAttr(value, AttrOf(value) | (A_COLOR & COLOR_PAIR(p))) +#define GetPair(value) PAIR_NUMBER(AttrOf(value)) +#define unColor(n) (AttrOf(n) & ALL_BUT_COLOR) +#define GET_WINDOW_PAIR(w) PAIR_NUMBER(WINDOW_ATTRS(w)) +#define SET_WINDOW_PAIR(w,p) WINDOW_ATTRS(w) &= ALL_BUT_COLOR, \ + WINDOW_ATTRS(w) |= (A_COLOR & COLOR_PAIR(p)) +#define SameAttrOf(a,b) (AttrOf(a) == AttrOf(b)) +#define VIDATTR(attr, pair) vidattr(attr) +#endif + +#if NCURSES_NO_PADDING +#define GetNoPadding(sp) ((sp) ? (sp)->_no_padding : _nc_prescreen._no_padding) +#define SetNoPadding(sp) _nc_set_no_padding(sp) +extern NCURSES_EXPORT(void) _nc_set_no_padding(SCREEN *); +#else +#define GetNoPadding(sp) FALSE +#define SetNoPadding(sp) /*nothing*/ +#endif + +#define WINDOW_ATTRS(w) ((w)->_attrs) + +#define SCREEN_ATTRS(s) (*((s)->_current_attr)) +#define GET_SCREEN_PAIR(s) GetPair(SCREEN_ATTRS(s)) +#define SET_SCREEN_PAIR(s,p) SetPair(SCREEN_ATTRS(s), p) + +#if USE_REENTRANT +NCURSES_EXPORT(int *) _nc_ptr_Lines (void); +NCURSES_EXPORT(int *) _nc_ptr_Cols (void); +#define ptrLines() (SP ? &(SP->_LINES) : &(_nc_prescreen._LINES)) +#define ptrCols() (SP ? &(SP->_COLS) : &(_nc_prescreen._COLS)) +#define SET_LINES(value) *_nc_ptr_Lines() = value +#define SET_COLS(value) *_nc_ptr_Cols() = value +#else +#define ptrLines() &LINES +#define ptrCols() &COLS +#define SET_LINES(value) LINES = value +#define SET_COLS(value) COLS = value +#endif + +#define TR_MUTEX(data) _tracef("%s@%d: me:%08lX COUNT:%2u/%2d/%6d/%2d/%s%9u: " #data, \ + __FILE__, __LINE__, \ + (unsigned long) (pthread_self()), \ + data.__data.__lock, \ + data.__data.__count, \ + data.__data.__owner, \ + data.__data.__kind, \ + (data.__data.__nusers > 5) ? " OOPS " : "", \ + data.__data.__nusers) +#define TR_GLOBAL_MUTEX(name) TR_MUTEX(_nc_globals.mutex_##name) + +#ifdef USE_PTHREADS + +#if USE_REENTRANT +#include <pthread.h> +extern NCURSES_EXPORT(void) _nc_init_pthreads(void); +extern NCURSES_EXPORT(void) _nc_mutex_init(pthread_mutex_t *); +extern NCURSES_EXPORT(int) _nc_mutex_lock(pthread_mutex_t *); +extern NCURSES_EXPORT(int) _nc_mutex_trylock(pthread_mutex_t *); +extern NCURSES_EXPORT(int) _nc_mutex_unlock(pthread_mutex_t *); +#define _nc_lock_global(name) _nc_mutex_lock(&_nc_globals.mutex_##name) +#define _nc_try_global(name) _nc_mutex_trylock(&_nc_globals.mutex_##name) +#define _nc_unlock_global(name) _nc_mutex_unlock(&_nc_globals.mutex_##name) + +#else +#error POSIX threads requires --enable-reentrant option +#endif + +#if USE_WEAK_SYMBOLS +#if defined(__GNUC__) +# if defined __USE_ISOC99 +# define _cat_pragma(exp) _Pragma(#exp) +# define _weak_pragma(exp) _cat_pragma(weak name) +# else +# define _weak_pragma(exp) +# endif +# define _declare(name) __extension__ extern __typeof__(name) name +# define weak_symbol(name) _weak_pragma(name) _declare(name) __attribute__((weak)) +#endif +#endif + +#ifdef USE_PTHREADS +# if USE_WEAK_SYMBOLS +weak_symbol(pthread_sigmask); +weak_symbol(pthread_self); +weak_symbol(pthread_equal); +weak_symbol(pthread_mutex_init); +weak_symbol(pthread_mutex_lock); +weak_symbol(pthread_mutex_unlock); +weak_symbol(pthread_mutex_trylock); +weak_symbol(pthread_mutexattr_settype); +weak_symbol(pthread_mutexattr_init); +extern NCURSES_EXPORT(int) _nc_sigprocmask(int, const sigset_t *, sigset_t *); +# undef sigprocmask +# define sigprocmask _nc_sigprocmask +# endif +#endif + +#if HAVE_NANOSLEEP +#undef HAVE_NANOSLEEP +#define HAVE_NANOSLEEP 0 /* nanosleep suspends all threads */ +#endif + +#else /* !USE_PTHREADS */ + +#define _nc_init_pthreads() /* nothing */ +#define _nc_mutex_init(obj) /* nothing */ + +#define _nc_lock_global(name) /* nothing */ +#define _nc_try_global(name) 0 +#define _nc_unlock_global(name) /* nothing */ + +#endif /* USE_PTHREADS */ + +#if HAVE_GETTIMEOFDAY +# define PRECISE_GETTIME 1 +# define TimeType struct timeval +#else +# define PRECISE_GETTIME 0 +# define TimeType time_t +#endif /* - * Structure for soft labels. + * Definitions for color pairs */ +typedef unsigned colorpair_t; /* type big enough to store PAIR_OF() */ +#define C_SHIFT 9 /* we need more bits than there are colors */ +#define C_MASK ((1 << C_SHIFT) - 1) +#define PAIR_OF(fg, bg) ((((fg) & C_MASK) << C_SHIFT) | ((bg) & C_MASK)) +#define isDefaultColor(c) ((c) >= COLOR_DEFAULT || (c) < 0) + +#define COLOR_DEFAULT C_MASK + +#if defined(USE_TERMLIB) && !defined(NEED_NCURSES_CH_T) + +#undef NCURSES_CH_T /* this is not a termlib feature */ +#define NCURSES_CH_T void /* ...but we need a pointer in SCREEN */ + +#endif /* USE_TERMLIB */ + +#ifndef USE_TERMLIB +struct ldat +{ + NCURSES_CH_T *text; /* text of the line */ + NCURSES_SIZE_T firstchar; /* first changed character in the line */ + NCURSES_SIZE_T lastchar; /* last changed character in the line */ + NCURSES_SIZE_T oldindex; /* index of the line at last update */ +}; +#endif /* USE_TERMLIB */ + +typedef enum { + M_XTERM = -1 /* use xterm's mouse tracking? */ + ,M_NONE = 0 /* no mouse device */ +#if USE_GPM_SUPPORT + ,M_GPM /* use GPM */ +#endif +#if USE_SYSMOUSE + ,M_SYSMOUSE /* FreeBSD sysmouse on console */ +#endif +} MouseType; + +/* + * Structures for scrolling. + */ + +typedef struct { + unsigned long hashval; + int oldcount, newcount; + int oldindex, newindex; +} HASHMAP; + +/* + * Structures for soft labels. + */ + +struct _SLK; + +#ifndef USE_TERMLIB typedef struct { - char *text; /* text for the label */ - char *form_text; /* formatted text (left/center/...) */ - int x; /* x coordinate of this field */ - char dirty; /* this label has changed */ - char visible; /* field is visible */ + char *ent_text; /* text for the label */ + char *form_text; /* formatted text (left/center/...) */ + int ent_x; /* x coordinate of this field */ + char dirty; /* this label has changed */ + char visible; /* field is visible */ } slk_ent; -typedef struct { - char dirty; /* all labels have changed */ - char hidden; /* soft labels are hidden */ - struct _win_st *win; +typedef struct _SLK { + char dirty; /* all labels have changed */ + char hidden; /* soft labels are hidden */ + WINDOW *win; slk_ent *ent; - char* buffer; /* buffer for labels */ - short maxlab; /* number of available labels */ - short labcnt; /* number of allocated labels */ - short maxlen; /* length of labels */ - chtype attr; /* soft label attribute */ + short maxlab; /* number of available labels */ + short labcnt; /* number of allocated labels */ + short maxlen; /* length of labels */ + NCURSES_CH_T attr; /* soft label attribute */ } SLK; +#endif /* USE_TERMLIB */ + +typedef struct { + WINDOW *win; /* the window used in the hook */ + int line; /* lines to take, < 0 => from bottom*/ + int (*hook)(WINDOW *, int); /* callback for user */ +} ripoff_t; + +#if USE_GPM_SUPPORT +#undef buttons /* term.h defines this, and gpm uses it! */ +#include <gpm.h> + +#ifdef HAVE_LIBDL +/* link dynamically to GPM */ +typedef int *TYPE_gpm_fd; +typedef int (*TYPE_Gpm_Open) (Gpm_Connect *, int); +typedef int (*TYPE_Gpm_Close) (void); +typedef int (*TYPE_Gpm_GetEvent) (Gpm_Event *); + +#define my_gpm_fd SP->_mouse_gpm_fd +#define my_Gpm_Open SP->_mouse_Gpm_Open +#define my_Gpm_Close SP->_mouse_Gpm_Close +#define my_Gpm_GetEvent SP->_mouse_Gpm_GetEvent +#else +/* link statically to GPM */ +#define my_gpm_fd &gpm_fd +#define my_Gpm_Open Gpm_Open +#define my_Gpm_Close Gpm_Close +#define my_Gpm_GetEvent Gpm_GetEvent +#endif /* HAVE_LIBDL */ +#endif /* USE_GPM_SUPPORT */ + +typedef struct { + long sequence; + bool last_used; + char *fix_sgr0; /* this holds the filtered sgr0 string */ + char *last_bufp; /* help with fix_sgr0 leak */ + TERMINAL *last_term; +} TGETENT_CACHE; + +#define TGETENT_MAX 4 + +/* + * State of tparm(). + */ +#define STACKSIZE 20 + +typedef struct { + union { + int num; + char *str; + } data; + bool num_type; +} STACK_FRAME; + +#define NUM_VARS 26 + +typedef struct { +#ifdef TRACE + const char *tname; +#endif + const char *tparam_base; + + STACK_FRAME stack[STACKSIZE]; + int stack_ptr; + + char *out_buff; + size_t out_size; + size_t out_used; + + char *fmt_buff; + size_t fmt_size; + + int dynamic_var[NUM_VARS]; + int static_vars[NUM_VARS]; +} TPARM_STATE; + +typedef struct { + char *text; + size_t size; +} TRACEBUF; + +/* + * The filesystem database normally uses a single-letter for the lower level + * of directories. Use a hexadecimal code for filesystems which do not + * preserve mixed-case names. + */ +#if MIXEDCASE_FILENAMES +#define LEAF_FMT "%c" +#else +#define LEAF_FMT "%02x" +#endif + +/* + * TRACEMSE_FMT is no longer than 80 columns, there are 5 numbers that + * could at most have 10 digits, and the mask contains no more than 32 bits + * with each bit representing less than 15 characters. Usually the whole + * string is less than 80 columns, but this buffer size is an absolute + * limit. + */ +#define TRACEMSE_MAX (80 + (5 * 10) + (32 * 15)) +#define TRACEMSE_FMT "id %2d at (%2d, %2d, %2d) state %4lx = {" /* } */ + +/* + * Global data which is not specific to a screen. + */ +typedef struct { + SIG_ATOMIC_T have_sigwinch; + SIG_ATOMIC_T cleanup_nested; + + bool init_signals; + bool init_screen; + + const char *comp_sourcename; + char *comp_termtype; + + bool have_tic_directory; + bool keep_tic_directory; + const char *tic_directory; + + char *dbi_list; + int dbi_size; + + char *first_name; + char **keyname_table; + + int slk_format; + + char *safeprint_buf; + size_t safeprint_used; + + TGETENT_CACHE tgetent_cache[TGETENT_MAX]; + int tgetent_index; + long tgetent_sequence; + + WINDOWLIST *_nc_windowlist; +#define _nc_windows _nc_globals._nc_windowlist + +#if USE_HOME_TERMINFO + char *home_terminfo; +#endif + +#if !USE_SAFE_SPRINTF + int safeprint_cols; + int safeprint_rows; +#endif + +#ifdef TRACE + bool init_trace; + char trace_fname[PATH_MAX]; + int trace_level; + FILE *trace_fp; + + char *tracearg_buf; + size_t tracearg_used; + + TRACEBUF *tracebuf_ptr; + size_t tracebuf_used; + + char tracechr_buf[40]; + + char *tracedmp_buf; + size_t tracedmp_used; + + unsigned char *tracetry_buf; + size_t tracetry_used; + +#define _nc_globals_traceatr_color_buf_size 80 + char traceatr_color_buf[2][_nc_globals_traceatr_color_buf_size]; + int traceatr_color_sel; + int traceatr_color_last; + +#endif /* TRACE */ + +#ifdef USE_PTHREADS + pthread_mutex_t mutex_curses; + pthread_mutex_t mutex_tst_tracef; + pthread_mutex_t mutex_tracef; + int nested_tracef; + int use_pthreads; +#define _nc_use_pthreads _nc_globals.use_pthreads +#endif +} NCURSES_GLOBALS; + +extern NCURSES_EXPORT_VAR(NCURSES_GLOBALS) _nc_globals; + +#define N_RIPS 5 + +/* + * Global data which can be swept up into a SCREEN when one is created. + * It may be modified before the next SCREEN is created. + */ +typedef struct { + bool use_env; + bool filter_mode; + attr_t previous_attr; + ripoff_t rippedoff[N_RIPS]; + ripoff_t *rsp; + TPARM_STATE tparm_state; + TTY *saved_tty; /* savetty/resetty information */ +#if NCURSES_NO_PADDING + bool _no_padding; /* flag to set if padding disabled */ +#endif +#if BROKEN_LINKER || USE_REENTRANT + chtype *real_acs_map; + int _LINES; + int _COLS; + TERMINAL *_cur_term; +#ifdef TRACE + long _outchars; + const char *_tputs_trace; +#endif +#endif +} NCURSES_PRESCREEN; + +#define ripoff_sp _nc_prescreen.rsp +#define ripoff_stack _nc_prescreen.rippedoff + +extern NCURSES_EXPORT_VAR(NCURSES_PRESCREEN) _nc_prescreen; + +/* + * The SCREEN structure. + */ + struct screen { - int _ifd; /* input file ptr for screen */ - FILE *_ofp; /* output file ptr for screen */ - char *_setbuf; /* buffered I/O for output */ - int _buffered; /* setvbuf uses _setbuf data */ - int _checkfd; /* filedesc for typeahead check */ - struct term *_term; /* terminal type information */ - short _lines; /* screen lines */ - short _columns; /* screen columns */ - short _lines_avail; /* lines available for stdscr */ - short _topstolen; /* lines stolen from top */ - - WINDOW *_curscr; /* current screen */ - WINDOW *_newscr; /* virtual screen to be updated to */ - WINDOW *_stdscr; /* screen's full-window context */ - - struct tries *_keytry; /* "Try" for use with keypad mode */ - struct tries *_key_ok; /* Disabled keys via keyok(,FALSE) */ - int _tried; /* keypad mode was initialized */ - - unsigned int _fifo[FIFO_SIZE]; /* input push-back buffer */ - short _fifohead, /* head of fifo queue */ - _fifotail, /* tail of fifo queue */ - _fifopeek, /* where to peek for next char */ - _fifohold; /* set if breakout marked */ - - int _endwin; /* are we out of window mode? */ - unsigned long _current_attr; /* terminal attribute current set */ - int _coloron; /* is color enabled? */ - int _cursor; /* visibility of the cursor */ - int _cursrow; /* physical cursor row */ - int _curscol; /* physical cursor column */ - int _nl; /* True if NL -> CR/NL is on */ - int _raw; /* True if in raw mode */ - int _cbreak; /* 1 if in cbreak mode */ - /* > 1 if in halfdelay mode */ - int _echo; /* True if echo on */ - int _use_meta; /* use the meta key? */ - SLK *_slk; /* ptr to soft key struct / NULL */ - int slk_format; /* selected format for this screen */ + int _ifd; /* input file ptr for screen */ + FILE *_ofp; /* output file ptr for screen */ + char *_setbuf; /* buffered I/O for output */ + bool _filtered; /* filter() was called */ + bool _buffered; /* setvbuf uses _setbuf data */ + int _checkfd; /* filedesc for typeahead check */ + TERMINAL *_term; /* terminal type information */ + TTY _saved_tty; /* savetty/resetty information */ + NCURSES_SIZE_T _lines; /* screen lines */ + NCURSES_SIZE_T _columns; /* screen columns */ + + NCURSES_SIZE_T _lines_avail; /* lines available for stdscr */ + NCURSES_SIZE_T _topstolen; /* lines stolen from top */ + + WINDOW *_curscr; /* current screen */ + WINDOW *_newscr; /* virtual screen to be updated to */ + WINDOW *_stdscr; /* screen's full-window context */ + + TRIES *_keytry; /* "Try" for use with keypad mode */ + TRIES *_key_ok; /* Disabled keys via keyok(,FALSE) */ + bool _tried; /* keypad mode was initialized */ + bool _keypad_on; /* keypad mode is currently on */ + + bool _called_wgetch; /* check for recursion in wgetch() */ + int _fifo[FIFO_SIZE]; /* input push-back buffer */ + short _fifohead, /* head of fifo queue */ + _fifotail, /* tail of fifo queue */ + _fifopeek, /* where to peek for next char */ + _fifohold; /* set if breakout marked */ + + int _endwin; /* are we out of window mode? */ + NCURSES_CH_T *_current_attr; /* holds current attributes set */ + int _coloron; /* is color enabled? */ + int _color_defs; /* are colors modified */ + int _cursor; /* visibility of the cursor */ + int _cursrow; /* physical cursor row */ + int _curscol; /* physical cursor column */ + bool _notty; /* true if we cannot switch non-tty */ + int _nl; /* True if NL -> CR/NL is on */ + int _raw; /* True if in raw mode */ + int _cbreak; /* 1 if in cbreak mode */ + /* > 1 if in halfdelay mode */ + int _echo; /* True if echo on */ + int _use_meta; /* use the meta key? */ + struct _SLK *_slk; /* ptr to soft key struct / NULL */ + int slk_format; /* selected format for this screen */ /* cursor movement costs; units are 10ths of milliseconds */ #if NCURSES_NO_PADDING - int _no_padding; /* flag to set if padding disabled */ + bool _no_padding; /* flag to set if padding disabled */ #endif - int _char_padding; /* cost of character put */ - int _cr_cost; /* cost of (carriage_return) */ - int _cup_cost; /* cost of (cursor_address) */ - int _home_cost; /* cost of (cursor_home) */ - int _ll_cost; /* cost of (cursor_to_ll) */ + int _char_padding; /* cost of character put */ + int _cr_cost; /* cost of (carriage_return) */ + int _cup_cost; /* cost of (cursor_address) */ + int _home_cost; /* cost of (cursor_home) */ + int _ll_cost; /* cost of (cursor_to_ll) */ #if USE_HARD_TABS - int _ht_cost; /* cost of (tab) */ - int _cbt_cost; /* cost of (backtab) */ + int _ht_cost; /* cost of (tab) */ + int _cbt_cost; /* cost of (backtab) */ #endif /* USE_HARD_TABS */ - int _cub1_cost; /* cost of (cursor_left) */ - int _cuf1_cost; /* cost of (cursor_right) */ - int _cud1_cost; /* cost of (cursor_down) */ - int _cuu1_cost; /* cost of (cursor_up) */ - int _cub_cost; /* cost of (parm_cursor_left) */ - int _cuf_cost; /* cost of (parm_cursor_right) */ - int _cud_cost; /* cost of (parm_cursor_down) */ - int _cuu_cost; /* cost of (parm_cursor_up) */ - int _hpa_cost; /* cost of (column_address) */ - int _vpa_cost; /* cost of (row_address) */ + int _cub1_cost; /* cost of (cursor_left) */ + int _cuf1_cost; /* cost of (cursor_right) */ + int _cud1_cost; /* cost of (cursor_down) */ + int _cuu1_cost; /* cost of (cursor_up) */ + int _cub_cost; /* cost of (parm_cursor_left) */ + int _cuf_cost; /* cost of (parm_cursor_right) */ + int _cud_cost; /* cost of (parm_cursor_down) */ + int _cuu_cost; /* cost of (parm_cursor_up) */ + int _hpa_cost; /* cost of (column_address) */ + int _vpa_cost; /* cost of (row_address) */ /* used in tty_update.c, must be chars */ - int _ed_cost; /* cost of (clr_eos) */ - int _el_cost; /* cost of (clr_eol) */ - int _el1_cost; /* cost of (clr_bol) */ - int _dch1_cost; /* cost of (delete_character) */ - int _ich1_cost; /* cost of (insert_character) */ - int _dch_cost; /* cost of (parm_dch) */ - int _ich_cost; /* cost of (parm_ich) */ - int _ech_cost; /* cost of (erase_chars) */ - int _rep_cost; /* cost of (repeat_char) */ - int _hpa_ch_cost; /* cost of (column_address) */ - int _cup_ch_cost; /* cost of (cursor_address) */ - int _cuf_ch_cost; /* cost of (parm_cursor_right) */ - int _inline_cost; /* cost of inline-move */ - int _smir_cost; /* cost of (enter_insert_mode) */ - int _rmir_cost; /* cost of (exit_insert_mode) */ - int _ip_cost; /* cost of (insert_padding) */ + int _ed_cost; /* cost of (clr_eos) */ + int _el_cost; /* cost of (clr_eol) */ + int _el1_cost; /* cost of (clr_bol) */ + int _dch1_cost; /* cost of (delete_character) */ + int _ich1_cost; /* cost of (insert_character) */ + int _dch_cost; /* cost of (parm_dch) */ + int _ich_cost; /* cost of (parm_ich) */ + int _ech_cost; /* cost of (erase_chars) */ + int _rep_cost; /* cost of (repeat_char) */ + int _hpa_ch_cost; /* cost of (column_address) */ + int _cup_ch_cost; /* cost of (cursor_address) */ + int _cuf_ch_cost; /* cost of (parm_cursor_right) */ + int _inline_cost; /* cost of inline-move */ + int _smir_cost; /* cost of (enter_insert_mode) */ + int _rmir_cost; /* cost of (exit_insert_mode) */ + int _ip_cost; /* cost of (insert_padding) */ /* used in lib_mvcur.c */ - char * _address_cursor; + char * _address_cursor; /* used in tty_update.c */ - int _scrolling; /* 1 if terminal's smart enough to */ + int _scrolling; /* 1 if terminal's smart enough to */ /* used in lib_color.c */ - color_t *_color_table; /* screen's color palette */ - int _color_count; /* count of colors in palette */ - unsigned short *_color_pairs; /* screen's color pair list */ - int _pair_count; /* count of color pairs */ + color_t *_color_table; /* screen's color palette */ + int _color_count; /* count of colors in palette */ + colorpair_t *_color_pairs; /* screen's color pair list */ + int _pair_count; /* count of color pairs */ #if NCURSES_EXT_FUNCS - bool _default_color; /* use default colors */ - bool _has_sgr_39_49; /* has ECMA default color support */ - int _default_fg; /* assumed default foreground */ - int _default_bg; /* assumed default background */ + bool _default_color; /* use default colors */ + bool _has_sgr_39_49; /* has ECMA default color support */ + int _default_fg; /* assumed default foreground */ + int _default_bg; /* assumed default background */ #endif - chtype _xmc_suppress; /* attributes to suppress if xmc */ - chtype _xmc_triggers; /* attributes to process if xmc */ - chtype _acs_map[ACS_LEN]; + chtype _ok_attributes; /* valid attributes for terminal */ + chtype _xmc_suppress; /* attributes to suppress if xmc */ + chtype _xmc_triggers; /* attributes to process if xmc */ + chtype * _acs_map; /* the real alternate-charset map */ + bool * _screen_acs_map; + /* used in lib_vidattr.c */ - bool _use_rmso; /* true if we may use 'rmso' */ - bool _use_rmul; /* true if we may use 'rmul' */ + bool _use_rmso; /* true if we may use 'rmso' */ + bool _use_rmul; /* true if we may use 'rmul' */ /* * These data correspond to the state of the idcok() and idlok() @@ -388,21 +836,58 @@ struct screen { * is given as an argument. However, ncurses implements this logic * only for the newscr/curscr update process, _not_ per-window. */ - bool _nc_sp_idlok; - bool _nc_sp_idcok; + bool _nc_sp_idlok; + bool _nc_sp_idcok; #define _nc_idlok SP->_nc_sp_idlok #define _nc_idcok SP->_nc_sp_idcok /* * These are the data that support the mouse interface. */ - int _maxclick; - bool (*_mouse_event) (SCREEN *); - bool (*_mouse_inline)(SCREEN *); - bool (*_mouse_parse) (int); - void (*_mouse_resume)(SCREEN *); - void (*_mouse_wrap) (SCREEN *); - int _mouse_fd; /* file-descriptor, if any */ + bool _mouse_initialized; + MouseType _mouse_type; + int _maxclick; + bool (*_mouse_event) (SCREEN *); + bool (*_mouse_inline)(SCREEN *); + bool (*_mouse_parse) (SCREEN *, int); + void (*_mouse_resume)(SCREEN *); + void (*_mouse_wrap) (SCREEN *); + int _mouse_fd; /* file-descriptor, if any */ + bool _mouse_active; /* true if initialized */ + mmask_t _mouse_mask; + NCURSES_CONST char *_mouse_xtermcap; /* string to enable/disable mouse */ + MEVENT _mouse_events[EV_MAX]; /* hold the last mouse event seen */ + MEVENT *_mouse_eventp; /* next free slot in event queue */ + +#if USE_GPM_SUPPORT + bool _mouse_gpm_loaded; + bool _mouse_gpm_found; +#ifdef HAVE_LIBDL + void *_dlopen_gpm; + TYPE_gpm_fd _mouse_gpm_fd; + TYPE_Gpm_Open _mouse_Gpm_Open; + TYPE_Gpm_Close _mouse_Gpm_Close; + TYPE_Gpm_GetEvent _mouse_Gpm_GetEvent; +#endif + Gpm_Connect _mouse_gpm_connect; +#endif /* USE_GPM_SUPPORT */ + +#if USE_EMX_MOUSE + int _emxmouse_wfd; + int _emxmouse_thread; + int _emxmouse_activated; + char _emxmouse_buttons[4]; +#endif + +#if USE_SYSMOUSE + MEVENT _sysmouse_fifo[FIFO_SIZE]; + int _sysmouse_head; + int _sysmouse_tail; + int _sysmouse_char_width; /* character width */ + int _sysmouse_char_height; /* character height */ + int _sysmouse_old_buttons; + int _sysmouse_new_buttons; +#endif /* * This supports automatic resizing @@ -411,48 +896,83 @@ struct screen { int (*_resize)(int,int); #endif - /* + /* * These are data that support the proper handling of the panel stack on an * per screen basis. */ - struct panelhook _panelHook; - /* - * Linked-list of all windows, to support '_nc_resizeall()' and - * '_nc_freeall()' - */ - WINDOWLIST *_nc_sp_windows; -#define _nc_windows SP->_nc_sp_windows + struct panelhook _panelHook; - bool _sig_winch; - SCREEN *_next_screen; + bool _sig_winch; + SCREEN *_next_screen; /* hashes for old and new lines */ unsigned long *oldhash, *newhash; + HASHMAP *hashtab; + int hashtab_len; + int *_oldnum_list; + int _oldnum_size; + + bool _cleanup; /* cleanup after int/quit signal */ + int (*_outch)(int); /* output handler if not putc */ + + int _legacy_coding; /* see use_legacy_coding() */ + +#if USE_REENTRANT + char _ttytype[NAMESIZE]; + int _ESCDELAY; + int _TABSIZE; + int _LINES; + int _COLS; +#ifdef TRACE + long _outchars; + const char *_tputs_trace; +#endif +#endif - bool _cleanup; /* cleanup after int/quit signal */ - int (*_outch)(int); /* output handler if not putc */ +#ifdef TRACE +#define _nc_screen_tracechr_buf_size 40 + char tracechr_buf[_nc_screen_tracechr_buf_size]; + char tracemse_buf[TRACEMSE_MAX]; +#endif + /* + * ncurses/ncursesw are the same up to this point. + */ +#if USE_WIDEC_SUPPORT + /* recent versions of 'screen' have partially-working support for + * UTF-8, but do not permit ACS at the same time (see tty_update.c). + */ + bool _screen_acs_fix; +#endif }; extern NCURSES_EXPORT_VAR(SCREEN *) _nc_screen_chain; - -#if NCURSES_NOMACROS -#include <nomacros.h> -#endif +extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch; WINDOWLIST { + WINDOW win; /* first, so WINDOW_EXT() works */ WINDOWLIST *next; - WINDOW *win; + SCREEN *screen; /* screen containing the window */ +#ifdef _XOPEN_SOURCE_EXTENDED + char addch_work[(MB_LEN_MAX * 9) + 1]; + unsigned addch_used; /* number of bytes in addch_work[] */ + int addch_x; /* x-position for addch_work[] */ + int addch_y; /* y-position for addch_work[] */ +#endif }; -typedef struct { - int line; /* lines to take, < 0 => from bottom*/ - int (*hook)(struct _win_st *, int); /* callback for user */ - struct _win_st *w; /* maybe we need this for cleanup */ -} ripoff_t; +#define WINDOW_EXT(win,field) (((WINDOWLIST *)(win))->field) + +/* usually in <limits.h> */ +#ifndef UCHAR_MAX +#define UCHAR_MAX 255 +#endif /* The terminfo source is assumed to be 7-bit ASCII */ #define is7bits(c) ((unsigned)(c) < 128) +/* Checks for isprint() should be done on 8-bit characters (non-wide) */ +#define is8bits(c) ((unsigned)(c) <= UCHAR_MAX) + #ifndef min #define min(a,b) ((a) > (b) ? (b) : (a)) #endif @@ -503,14 +1023,162 @@ typedef struct { #define O_BINARY 0 #endif -#define CharOf(c) ((unsigned char)(c)) -#define TextOf(c) ((c) & (chtype)A_CHARTEXT) -#define AttrOf(c) ((c) & (chtype)A_ATTRIBUTES) +#ifdef TRACE +#if USE_REENTRANT +#define COUNT_OUTCHARS(n) _nc_count_outchars(n); +#else +#define COUNT_OUTCHARS(n) _nc_outchars += (n); +#endif +#else +#define COUNT_OUTCHARS(n) /* nothing */ +#endif + +#define RESET_OUTCHARS() COUNT_OUTCHARS(-_nc_outchars) + +#define UChar(c) ((unsigned char)(c)) +#define ChCharOf(c) ((c) & (chtype)A_CHARTEXT) +#define ChAttrOf(c) ((c) & (chtype)A_ATTRIBUTES) + +#ifndef MB_LEN_MAX +#define MB_LEN_MAX 8 /* should be >= MB_CUR_MAX, but that may be a function */ +#endif -#define BLANK (' '|A_NORMAL) +#if USE_WIDEC_SUPPORT /* { */ +#define isEILSEQ(status) (((size_t)status == (size_t)-1) && (errno == EILSEQ)) + +#define init_mb(state) memset(&state, 0, sizeof(state)) + +#if NCURSES_EXT_COLORS +#define NulColor , 0 +#else +#define NulColor /* nothing */ +#endif + +#define NulChar 0,0,0,0 /* FIXME: see CCHARW_MAX */ +#define CharOf(c) ((c).chars[0]) +#define AttrOf(c) ((c).attr) + +#define AddAttr(c,a) AttrOf(c) |= ((a) & A_ATTRIBUTES) +#define RemAttr(c,a) AttrOf(c) &= ~((a) & A_ATTRIBUTES) +#define SetAttr(c,a) AttrOf(c) = ((a) & A_ATTRIBUTES) | WidecExt(c) + +#define NewChar2(c,a) { a, { c, NulChar } NulColor } +#define NewChar(ch) NewChar2(ChCharOf(ch), ChAttrOf(ch)) + +#if CCHARW_MAX == 5 +#define CharEq(a,b) (((a).attr == (b).attr) \ + && (a).chars[0] == (b).chars[0] \ + && (a).chars[1] == (b).chars[1] \ + && (a).chars[2] == (b).chars[2] \ + && (a).chars[3] == (b).chars[3] \ + && (a).chars[4] == (b).chars[4] \ + if_EXT_COLORS(&& (a).ext_color == (b).ext_color)) +#else +#define CharEq(a,b) (!memcmp(&(a), &(b), sizeof(a))) +#endif + +#define SetChar(ch,c,a) do { \ + NCURSES_CH_T *_cp = &ch; \ + memset(_cp, 0, sizeof(ch)); \ + _cp->chars[0] = (c); \ + _cp->attr = (a); \ + if_EXT_COLORS(SetPair(ch, PAIR_NUMBER(a))); \ + } while (0) +#define CHREF(wch) (&wch) +#define CHDEREF(wch) (*wch) +#define ARG_CH_T NCURSES_CH_T * +#define CARG_CH_T const NCURSES_CH_T * +#define PUTC_DATA char PUTC_buf[MB_LEN_MAX]; int PUTC_i, PUTC_n; \ + mbstate_t PUT_st; wchar_t PUTC_ch +#define PUTC_INIT init_mb (PUT_st) +#define PUTC(ch,b) do { if(!isWidecExt(ch)) { \ + if (Charable(ch)) { \ + fputc(CharOf(ch), b); \ + COUNT_OUTCHARS(1); \ + } else { \ + PUTC_INIT; \ + for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) { \ + PUTC_ch = (ch).chars[PUTC_i]; \ + if (PUTC_ch == L'\0') \ + break; \ + PUTC_n = wcrtomb(PUTC_buf, \ + (ch).chars[PUTC_i], &PUT_st); \ + if (PUTC_n <= 0) { \ + if (PUTC_ch && is8bits(PUTC_ch) && PUTC_i == 0) \ + putc(PUTC_ch,b); \ + break; \ + } \ + fwrite(PUTC_buf, (unsigned) PUTC_n, 1, b); \ + } \ + COUNT_OUTCHARS(PUTC_i); \ + } } } while (0) + +#define BLANK NewChar2(' ', WA_NORMAL) +#define ZEROS NewChar2('\0', WA_NORMAL) +#define ISBLANK(ch) ((ch).chars[0] == L' ' && (ch).chars[1] == L'\0') + + /* + * Wide characters cannot be represented in the A_CHARTEXT mask of + * attr_t's but an application might have set a narrow character there. + * But even in that case, it would only be a printable character, or + * zero. Otherwise we can use those bits to tell if a cell is the + * first or extension part of a wide character. + */ +#define WidecExt(ch) (AttrOf(ch) & A_CHARTEXT) +#define isWidecBase(ch) (WidecExt(ch) == 1) +#define isWidecExt(ch) (WidecExt(ch) > 1 && WidecExt(ch) < 32) +#define SetWidecExt(dst, ext) AttrOf(dst) &= ~A_CHARTEXT, \ + AttrOf(dst) |= (ext + 1) + +#define if_WIDEC(code) code +#define Charable(ch) ((SP != 0 && SP->_legacy_coding) \ + || (AttrOf(ch) & A_ALTCHARSET) \ + || (!isWidecExt(ch) && \ + (ch).chars[1] == L'\0' && \ + _nc_is_charable(CharOf(ch)))) + +#define L(ch) L ## ch +#else /* }{ */ +#define CharOf(c) ChCharOf(c) +#define AttrOf(c) ChAttrOf(c) +#define AddAttr(c,a) c |= (a) +#define RemAttr(c,a) c &= ~((a) & A_ATTRIBUTES) +#define SetAttr(c,a) c = ((c) & ~A_ATTRIBUTES) | (a) +#define NewChar(ch) (ch) +#define NewChar2(c,a) ((c) | (a)) +#define CharEq(a,b) ((a) == (b)) +#define SetChar(ch,c,a) ch = (c) | (a) +#define CHREF(wch) wch +#define CHDEREF(wch) wch +#define ARG_CH_T NCURSES_CH_T +#define CARG_CH_T NCURSES_CH_T +#define PUTC_DATA int data = 0 +#define PUTC(ch,b) do { data = CharOf(ch); putc(data,b); } while (0) + +#define BLANK (' '|A_NORMAL) +#define ZEROS ('\0'|A_NORMAL) +#define ISBLANK(ch) (CharOf(ch) == ' ') + +#define isWidecExt(ch) (0) +#define if_WIDEC(code) /* nothing */ + +#define L(ch) ch +#endif /* } */ + +#define AttrOfD(ch) AttrOf(CHDEREF(ch)) +#define CharOfD(ch) CharOf(CHDEREF(ch)) +#define SetChar2(wch,ch) SetChar(wch,ChCharOf(ch),ChAttrOf(ch)) + +#define BLANK_ATTR A_NORMAL +#define BLANK_TEXT L(' ') #define CHANGED -1 +#define LEGALYX(w, y, x) \ + ((w) != 0 && \ + ((x) >= 0 && (x) <= (w)->_maxx && \ + (y) >= 0 && (y) <= (w)->_maxy)) + #define CHANGED_CELL(line,col) \ if (line->firstchar == _NOCHANGE) \ line->firstchar = line->lastchar = col; \ @@ -545,75 +1213,176 @@ typedef struct { #include <nc_alloc.h> /* + * TTY bit definition for converting tabs to spaces. + */ +#ifdef TAB3 +# define OFLAGS_TABS TAB3 /* POSIX specifies TAB3 */ +#else +# ifdef XTABS +# define OFLAGS_TABS XTABS /* XTABS is usually the "same" */ +# else +# ifdef OXTABS +# define OFLAGS_TABS OXTABS /* the traditional BSD equivalent */ +# else +# define OFLAGS_TABS 0 +# endif +# endif +#endif + +/* + * Standardize/simplify common loops + */ +#define each_screen(p) p = _nc_screen_chain; p != 0; p = (p)->_next_screen +#define each_window(p) p = _nc_windows; p != 0; p = (p)->next +#define each_ripoff(p) p = ripoff_stack; (p - ripoff_stack) < N_RIPS; ++p + +/* * Prefixes for call/return points of library function traces. We use these to * instrument the public functions so that the traces can be easily transformed * into regression scripts. */ -#define T_CALLED(fmt) "called " fmt -#define T_CREATE(fmt) "create " fmt -#define T_RETURN(fmt) "return " fmt +#define T_CALLED(fmt) "called {" fmt +#define T_CREATE(fmt) "create :" fmt +#define T_RETURN(fmt) "return }" fmt #ifdef TRACE -#define TR(n, a) if (_nc_tracing & (n)) _tracef a -#define T(a) TR(TRACE_CALLS, a) + +#if USE_REENTRANT +#define TPUTS_TRACE(s) _nc_set_tputs_trace(s); +#else #define TPUTS_TRACE(s) _nc_tputs_trace = s; +#endif + +#define START_TRACE() \ + if ((_nc_tracing & TRACE_MAXIMUM) == 0) { \ + int t = _nc_getenv_num("NCURSES_TRACE"); \ + if (t >= 0) \ + trace((unsigned) t); \ + } + +/* + * Many of the _tracef() calls use static buffers; lock the trace state before + * trying to fill them. + */ +#if USE_REENTRANT +#define USE_TRACEF(mask) _nc_use_tracef(mask) +extern NCURSES_EXPORT(int) _nc_use_tracef (unsigned); +extern NCURSES_EXPORT(void) _nc_locked_tracef (const char *, ...) GCC_PRINTFLIKE(1,2); +#else +#define USE_TRACEF(mask) (_nc_tracing & (mask)) +#define _nc_locked_tracef _tracef +#endif + +#define TR(n, a) if (USE_TRACEF(n)) _nc_locked_tracef a +#define T(a) TR(TRACE_CALLS, a) #define TRACE_RETURN(value,type) return _nc_retrace_##type(value) -#define returnAttr(code) TRACE_RETURN(code,attr_t) -#define returnChar(code) TRACE_RETURN(code,chtype) -#define returnCode(code) TRACE_RETURN(code,int) -#define returnPtr(code) TRACE_RETURN(code,ptr) -#define returnVoid T((T_RETURN(""))); return -#define returnWin(code) TRACE_RETURN(code,win) -extern NCURSES_EXPORT(WINDOW *) _nc_retrace_win (WINDOW *); -extern NCURSES_EXPORT(attr_t) _nc_retrace_attr_t (attr_t); -extern NCURSES_EXPORT(attr_t) _nc_retrace_chtype (chtype); -extern NCURSES_EXPORT(char *) _nc_retrace_ptr (char *); -extern NCURSES_EXPORT_VAR(const char *) _nc_tputs_trace; -extern NCURSES_EXPORT(int) _nc_retrace_int (int); -extern NCURSES_EXPORT_VAR(long) _nc_outchars; -extern NCURSES_EXPORT(void) _nc_fifo_dump (void); + +#define returnAttr(code) TRACE_RETURN(code,attr_t) +#define returnBits(code) TRACE_RETURN(code,unsigned) +#define returnBool(code) TRACE_RETURN(code,bool) +#define returnCPtr(code) TRACE_RETURN(code,cptr) +#define returnCVoidPtr(code) TRACE_RETURN(code,cvoid_ptr) +#define returnChar(code) TRACE_RETURN(code,chtype) +#define returnCode(code) TRACE_RETURN(code,int) +#define returnPtr(code) TRACE_RETURN(code,ptr) +#define returnSP(code) TRACE_RETURN(code,sp) +#define returnVoid T((T_RETURN(""))); return +#define returnVoidPtr(code) TRACE_RETURN(code,void_ptr) +#define returnWin(code) TRACE_RETURN(code,win) + +extern NCURSES_EXPORT(NCURSES_BOOL) _nc_retrace_bool (NCURSES_BOOL); +extern NCURSES_EXPORT(NCURSES_CONST void *) _nc_retrace_cvoid_ptr (NCURSES_CONST void *); +extern NCURSES_EXPORT(SCREEN *) _nc_retrace_sp (SCREEN *); +extern NCURSES_EXPORT(WINDOW *) _nc_retrace_win (WINDOW *); +extern NCURSES_EXPORT(attr_t) _nc_retrace_attr_t (attr_t); +extern NCURSES_EXPORT(char *) _nc_retrace_ptr (char *); +extern NCURSES_EXPORT(char *) _nc_trace_ttymode(TTY *tty); +extern NCURSES_EXPORT(char *) _nc_varargs (const char *, va_list); +extern NCURSES_EXPORT(chtype) _nc_retrace_chtype (chtype); +extern NCURSES_EXPORT(const char *) _nc_altcharset_name(attr_t, chtype); +extern NCURSES_EXPORT(const char *) _nc_retrace_cptr (const char *); +extern NCURSES_EXPORT(int) _nc_retrace_int (int); +extern NCURSES_EXPORT(unsigned) _nc_retrace_unsigned (unsigned); +extern NCURSES_EXPORT(void *) _nc_retrace_void_ptr (void *); +extern NCURSES_EXPORT(void) _nc_fifo_dump (SCREEN *); + +#if USE_REENTRANT +NCURSES_WRAPPED_VAR(long, _nc_outchars); +NCURSES_WRAPPED_VAR(const char *, _nc_tputs_trace); +#define _nc_outchars NCURSES_PUBLIC_VAR(_nc_outchars()) +#define _nc_tputs_trace NCURSES_PUBLIC_VAR(_nc_tputs_trace()) +extern NCURSES_EXPORT(void) _nc_set_tputs_trace (const char *); +extern NCURSES_EXPORT(void) _nc_count_outchars (long); #else +extern NCURSES_EXPORT_VAR(const char *) _nc_tputs_trace; +extern NCURSES_EXPORT_VAR(long) _nc_outchars; +#endif + +extern NCURSES_EXPORT_VAR(unsigned) _nc_tracing; + +#if USE_WIDEC_SUPPORT +extern NCURSES_EXPORT(const char *) _nc_viswbuf2 (int, const wchar_t *); +extern NCURSES_EXPORT(const char *) _nc_viswbufn (const wchar_t *, int); +#endif + +extern NCURSES_EXPORT(const char *) _nc_viscbuf2 (int, const NCURSES_CH_T *, int); +extern NCURSES_EXPORT(const char *) _nc_viscbuf (const NCURSES_CH_T *, int); + +#else /* !TRACE */ + +#define START_TRACE() /* nothing */ + #define T(a) #define TR(n, a) #define TPUTS_TRACE(s) -#define returnAttr(code) return code -#define returnChar(code) return code -#define returnCode(code) return code -#define returnPtr(code) return code -#define returnVoid return -#define returnWin(code) return code -#endif -extern NCURSES_EXPORT_VAR(unsigned) _nc_tracing; +#define returnAttr(code) return code +#define returnBits(code) return code +#define returnBool(code) return code +#define returnCPtr(code) return code +#define returnCVoidPtr(code) return code +#define returnChar(code) return code +#define returnCode(code) return code +#define returnPtr(code) return code +#define returnSP(code) return code +#define returnVoid return +#define returnVoidPtr(code) return code +#define returnWin(code) return code + +#endif /* TRACE/!TRACE */ + +/* + * Return-codes for tgetent() and friends. + */ +#define TGETENT_YES 1 /* entry is found */ +#define TGETENT_NO 0 /* entry is not found */ +#define TGETENT_ERR -1 /* an error occurred */ + extern NCURSES_EXPORT(const char *) _nc_visbuf2 (int, const char *); +extern NCURSES_EXPORT(const char *) _nc_visbufn (const char *, int); -#define _trace_key(ch) ((ch > KEY_MIN) ? keyname(ch) : _tracechar((unsigned char)ch)) +#define EMPTY_MODULE(name) \ +extern NCURSES_EXPORT(void) name (void); \ + NCURSES_EXPORT(void) name (void) { } #define ALL_BUT_COLOR ((chtype)~(A_COLOR)) -#define IGNORE_COLOR_OFF FALSE -#define NONBLANK_ATTR (A_BOLD|A_DIM|A_BLINK) +#define NONBLANK_ATTR (A_NORMAL|A_BOLD|A_DIM|A_BLINK) #define XMC_CHANGES(c) ((c) & SP->_xmc_suppress) - #define toggle_attr_on(S,at) {\ - if (PAIR_NUMBER(at) > 0)\ + if (PAIR_NUMBER(at) > 0) {\ (S) = ((S) & ALL_BUT_COLOR) | (at);\ - else\ + } else {\ (S) |= (at);\ + }\ TR(TRACE_ATTRS, ("new attribute is %s", _traceattr((S))));} #define toggle_attr_off(S,at) {\ - if (IGNORE_COLOR_OFF == TRUE) {\ - if (PAIR_NUMBER(at) == 0xff) /* turn off color */\ - (S) &= ~(at);\ - else /* leave color alone */\ - (S) &= ~((at)&ALL_BUT_COLOR);\ + if (PAIR_NUMBER(at) > 0) {\ + (S) &= ~(at|A_COLOR);\ } else {\ - if (PAIR_NUMBER(at) > 0x00) /* turn off color */\ - (S) &= ~(at|A_COLOR);\ - else /* leave color alone */\ - (S) &= ~(at);\ + (S) &= ~(at);\ }\ TR(TRACE_ATTRS, ("new attribute is %s", _traceattr((S))));} @@ -630,17 +1399,16 @@ extern NCURSES_EXPORT(const char *) _nc_visbuf2 (int, const char *); : ((enter_insert_mode && exit_insert_mode) \ ? SP->_smir_cost + SP->_rmir_cost + (SP->_ip_cost * count) \ : ((insert_character != 0) \ - ? (SP->_ich1_cost * count) \ + ? ((SP->_ich1_cost + SP->_ip_cost) * count) \ : INFINITY))) #if USE_XMC_SUPPORT -#define UpdateAttrs(c) if (SP->_current_attr != AttrOf(c)) { \ - attr_t chg = SP->_current_attr; \ - vidattr(AttrOf(c)); \ +#define UpdateAttrs(c) if (!SameAttrOf(SCREEN_ATTRS(SP), c)) { \ + attr_t chg = AttrOf(SCREEN_ATTRS(SP)); \ + VIDATTR(AttrOf(c), GetPair(c)); \ if (magic_cookie_glitch > 0 \ - && XMC_CHANGES((chg ^ SP->_current_attr))) { \ - TR(TRACE_ATTRS, \ - ("%s @%d before glitch %d,%d", \ + && XMC_CHANGES((chg ^ AttrOf(SCREEN_ATTRS(SP))))) { \ + T(("%s @%d before glitch %d,%d", \ __FILE__, __LINE__, \ SP->_cursrow, \ SP->_curscol)); \ @@ -648,8 +1416,21 @@ extern NCURSES_EXPORT(const char *) _nc_visbuf2 (int, const char *); } \ } #else -#define UpdateAttrs(c) if (SP->_current_attr != AttrOf(c)) \ - vidattr(AttrOf(c)) +#define UpdateAttrs(c) if (!SameAttrOf(SCREEN_ATTRS(SP), c)) \ + VIDATTR(AttrOf(c), GetPair(c)); +#endif + +/* + * Macros to make additional parameter to implement wgetch_events() + */ +#ifdef NCURSES_WGETCH_EVENTS +#define EVENTLIST_0th(param) param +#define EVENTLIST_1st(param) param +#define EVENTLIST_2nd(param) , param +#else +#define EVENTLIST_0th(param) void +#define EVENTLIST_1st(param) /* nothing */ +#define EVENTLIST_2nd(param) /* nothing */ #endif #if NCURSES_EXPANDED && NCURSES_EXT_FUNCS @@ -672,7 +1453,7 @@ extern NCURSES_EXPORT(int) _nc_InsCharCost (int); #undef UpdateAttrs #define UpdateAttrs(c) _nc_UpdateAttrs(c) -extern NCURSES_EXPORT(void) _nc_UpdateAttrs (chtype); +extern NCURSES_EXPORT(void) _nc_UpdateAttrs (NCURSES_CH_T); #else @@ -680,10 +1461,36 @@ extern NCURSES_EXPORT(void) _nc_expanded (void); #endif +#if !NCURSES_EXT_FUNCS +#define set_escdelay(value) ESCDELAY = value +#endif + #if !HAVE_GETCWD #define getcwd(buf,len) getwd(buf) #endif +/* charable.c */ +#if USE_WIDEC_SUPPORT +extern NCURSES_EXPORT(bool) _nc_is_charable(wchar_t); +extern NCURSES_EXPORT(int) _nc_to_char(wint_t); +extern NCURSES_EXPORT(wint_t) _nc_to_widechar(int); +#endif + +/* comp_captab.c */ +typedef struct { + short nte_name; /* offset of name to hash on */ + int nte_type; /* BOOLEAN, NUMBER or STRING */ + short nte_index; /* index of associated variable in its array */ + short nte_link; /* index in table of next hash, or -1 */ +} name_table_data; + +typedef struct +{ + short from; + short to; + short source; +} alias_table_data; + /* doupdate.c */ #if USE_XMC_SUPPORT extern NCURSES_EXPORT(void) _nc_do_xmc_glitch (attr_t); @@ -698,6 +1505,25 @@ extern NCURSES_EXPORT(void) _nc_linedump (void); extern NCURSES_EXPORT(void) _nc_init_acs (void); /* corresponds to traditional 'init_acs()' */ extern NCURSES_EXPORT(int) _nc_msec_cost (const char *const, int); /* used by 'tack' program */ +/* lib_addch.c */ +#if USE_WIDEC_SUPPORT +NCURSES_EXPORT(int) _nc_build_wch(WINDOW *win, ARG_CH_T ch); +#endif + +/* lib_addstr.c */ +#if USE_WIDEC_SUPPORT && !defined(USE_TERMLIB) +extern NCURSES_EXPORT(int) _nc_wchstrlen(const cchar_t *); +#endif + +/* lib_color.c */ +extern NCURSES_EXPORT(bool) _nc_reset_colors(void); + +/* lib_getch.c */ +extern NCURSES_EXPORT(int) _nc_wgetch(WINDOW *, unsigned long *, int EVENTLIST_2nd(_nc_eventlist *)); + +/* lib_insch.c */ +extern NCURSES_EXPORT(int) _nc_insert_ch(WINDOW *, chtype); + /* lib_mvcur.c */ #define INFINITY 1000000 /* cost: too high to use */ @@ -716,29 +1542,43 @@ extern NCURSES_EXPORT(int) _nc_has_mouse (void); /* lib_mvcur.c */ #define INFINITY 1000000 /* cost: too high to use */ +#define BAUDBYTE 9 /* 9 = 7 bits + 1 parity + 1 stop */ + +/* lib_setup.c */ +extern NCURSES_EXPORT(char *) _nc_get_locale(void); +extern NCURSES_EXPORT(int) _nc_unicode_locale(void); +extern NCURSES_EXPORT(int) _nc_locale_breaks_acs(TERMINAL *); +extern NCURSES_EXPORT(int) _nc_setupterm(NCURSES_CONST char *, int, int *, bool); +extern NCURSES_EXPORT(void) _nc_get_screensize(SCREEN *, int *, int *); + +/* lib_tstp.c */ +#if USE_SIGWINCH +extern NCURSES_EXPORT(int) _nc_handle_sigwinch(SCREEN *); +#else +#define _nc_handle_sigwinch(a) /* nothing */ +#endif + +/* lib_ungetch.c */ +extern NCURSES_EXPORT(int) _nc_ungetch (SCREEN *, int); + +/* lib_wacs.c */ +#if USE_WIDEC_SUPPORT +extern NCURSES_EXPORT(void) _nc_init_wacs(void); +#endif typedef struct { - char *s_head; - char *s_tail; - size_t s_size; + char *s_head; /* beginning of the string (may be null) */ + char *s_tail; /* end of the string (may be null) */ + size_t s_size; /* current remaining size available */ + size_t s_init; /* total size available */ } string_desc; /* strings.c */ -extern NCURSES_EXPORT(string_desc *) _nc_str_init (string_desc * dst, char *src, size_t len); -extern NCURSES_EXPORT(string_desc *) _nc_str_null (string_desc * dst, size_t len); -extern NCURSES_EXPORT(string_desc *) _nc_str_copy (string_desc * dst, string_desc * src); -extern NCURSES_EXPORT(bool) _nc_safe_strcat (string_desc * dst, const char *src); -extern NCURSES_EXPORT(bool) _nc_safe_strcpy (string_desc * dst, const char *src); - -extern NCURSES_EXPORT(void) _nc_mvcur_init (void); -extern NCURSES_EXPORT(void) _nc_mvcur_resume (void); -extern NCURSES_EXPORT(void) _nc_mvcur_wrap (void); - -extern NCURSES_EXPORT(int) _nc_scrolln (int, int, int, int); - -extern NCURSES_EXPORT(void) _nc_screen_init (void); -extern NCURSES_EXPORT(void) _nc_screen_resume (void); -extern NCURSES_EXPORT(void) _nc_screen_wrap (void); +extern NCURSES_EXPORT(string_desc *) _nc_str_init (string_desc *, char *, size_t); +extern NCURSES_EXPORT(string_desc *) _nc_str_null (string_desc *, size_t); +extern NCURSES_EXPORT(string_desc *) _nc_str_copy (string_desc *, string_desc *); +extern NCURSES_EXPORT(bool) _nc_safe_strcat (string_desc *, const char *); +extern NCURSES_EXPORT(bool) _nc_safe_strcpy (string_desc *, const char *); #if !HAVE_STRSTR #define strstr _nc_strstr @@ -746,52 +1586,93 @@ extern NCURSES_EXPORT(char *) _nc_strstr (const char *, const char *); #endif /* safe_sprintf.c */ -extern NCURSES_EXPORT(char *) _nc_printf_string (const char *fmt, va_list ap); +extern NCURSES_EXPORT(char *) _nc_printf_string (const char *, va_list); /* tries.c */ -extern NCURSES_EXPORT(void) _nc_add_to_try (struct tries **tree, const char *str, unsigned short code); -extern NCURSES_EXPORT(char *) _nc_expand_try (struct tries *tree, unsigned short code, int *count, size_t len); -extern NCURSES_EXPORT(int) _nc_remove_key (struct tries **tree, unsigned short code); -extern NCURSES_EXPORT(int) _nc_remove_string (struct tries **tree, char *string); +extern NCURSES_EXPORT(int) _nc_add_to_try (TRIES **, const char *, unsigned); +extern NCURSES_EXPORT(char *) _nc_expand_try (TRIES *, unsigned, int *, size_t); +extern NCURSES_EXPORT(int) _nc_remove_key (TRIES **, unsigned); +extern NCURSES_EXPORT(int) _nc_remove_string (TRIES **, const char *); /* elsewhere ... */ +extern NCURSES_EXPORT(ENTRY *) _nc_delink_entry (ENTRY *, TERMTYPE *); +extern NCURSES_EXPORT(NCURSES_CONST char *) _nc_keyname (SCREEN *, int); +extern NCURSES_EXPORT(NCURSES_CONST char *) _nc_unctrl (SCREEN *, chtype); +extern NCURSES_EXPORT(SCREEN *) _nc_screen_of (WINDOW *); extern NCURSES_EXPORT(WINDOW *) _nc_makenew (int, int, int, int, int); -extern NCURSES_EXPORT(char *) _nc_home_terminfo (void); extern NCURSES_EXPORT(char *) _nc_trace_buf (int, size_t); -extern NCURSES_EXPORT(chtype) _nc_background (WINDOW *); -extern NCURSES_EXPORT(chtype) _nc_render (WINDOW *, chtype); -extern NCURSES_EXPORT(int) _nc_access (const char *, int); +extern NCURSES_EXPORT(char *) _nc_trace_bufcat (int, const char *); +extern NCURSES_EXPORT(char *) _nc_tracechar (SCREEN *, int); +extern NCURSES_EXPORT(char *) _nc_tracemouse (SCREEN *, MEVENT const *); +extern NCURSES_EXPORT(int) _nc_access (const char *, int); extern NCURSES_EXPORT(int) _nc_baudrate (int); -extern NCURSES_EXPORT(int) _nc_freewin (WINDOW *win); +extern NCURSES_EXPORT(int) _nc_freewin (WINDOW *); extern NCURSES_EXPORT(int) _nc_getenv_num (const char *); -extern NCURSES_EXPORT(int) _nc_keypad (bool); +extern NCURSES_EXPORT(int) _nc_keypad (SCREEN *, bool); extern NCURSES_EXPORT(int) _nc_ospeed (int); extern NCURSES_EXPORT(int) _nc_outch (int); -extern NCURSES_EXPORT(int) _nc_setupscreen (short, short const, FILE *); -extern NCURSES_EXPORT(int) _nc_timed_wait (int, int, int *); -extern NCURSES_EXPORT(int) _nc_waddch_nosync (WINDOW *, const chtype); -extern NCURSES_EXPORT(void) _nc_do_color (int, int, bool, int (*)(int)); +extern NCURSES_EXPORT(int) _nc_read_termcap_entry (const char *const, TERMTYPE *const); +extern NCURSES_EXPORT(int) _nc_setupscreen (int, int, FILE *, bool, int); +extern NCURSES_EXPORT(int) _nc_timed_wait (SCREEN *, int, int, int * EVENTLIST_2nd(_nc_eventlist *)); +extern NCURSES_EXPORT(void) _nc_do_color (short, short, bool, int (*)(int)); extern NCURSES_EXPORT(void) _nc_flush (void); +extern NCURSES_EXPORT(void) _nc_free_and_exit (int); +extern NCURSES_EXPORT(void) _nc_free_entry (ENTRY *, TERMTYPE *); extern NCURSES_EXPORT(void) _nc_freeall (void); extern NCURSES_EXPORT(void) _nc_hash_map (void); -extern NCURSES_EXPORT(void) _nc_init_keytry (void); +extern NCURSES_EXPORT(void) _nc_init_keytry (SCREEN *); extern NCURSES_EXPORT(void) _nc_keep_tic_dir (const char *); extern NCURSES_EXPORT(void) _nc_make_oldhash (int i); -extern NCURSES_EXPORT(void) _nc_outstr (const char *str); extern NCURSES_EXPORT(void) _nc_scroll_oldhash (int n, int top, int bot); extern NCURSES_EXPORT(void) _nc_scroll_optimize (void); -extern NCURSES_EXPORT(void) _nc_scroll_window (WINDOW *, int const, short const, short const, chtype); extern NCURSES_EXPORT(void) _nc_set_buffer (FILE *, bool); extern NCURSES_EXPORT(void) _nc_signal_handler (bool); -extern NCURSES_EXPORT(void) _nc_synchook (WINDOW *win); -extern NCURSES_EXPORT(void) _nc_trace_tries (struct tries *tree); +extern NCURSES_EXPORT(void) _nc_synchook (WINDOW *); +extern NCURSES_EXPORT(void) _nc_trace_tries (TRIES *); + +#if NO_LEAKS +extern NCURSES_EXPORT(void) _nc_alloc_entry_leaks(void); +extern NCURSES_EXPORT(void) _nc_captoinfo_leaks(void); +extern NCURSES_EXPORT(void) _nc_codes_leaks(void); +extern NCURSES_EXPORT(void) _nc_comp_captab_leaks(void); +extern NCURSES_EXPORT(void) _nc_comp_scan_leaks(void); +extern NCURSES_EXPORT(void) _nc_keyname_leaks(void); +extern NCURSES_EXPORT(void) _nc_names_leaks(void); +extern NCURSES_EXPORT(void) _nc_tgetent_leaks(void); +#endif + +#ifndef USE_TERMLIB +extern NCURSES_EXPORT(NCURSES_CH_T) _nc_render (WINDOW *, NCURSES_CH_T); +extern NCURSES_EXPORT(int) _nc_waddch_nosync (WINDOW *, const NCURSES_CH_T); +extern NCURSES_EXPORT(void) _nc_scroll_window (WINDOW *, int const, NCURSES_SIZE_T const, NCURSES_SIZE_T const, NCURSES_CH_T); +#endif + +#if USE_WIDEC_SUPPORT && !defined(USE_TERMLIB) +extern NCURSES_EXPORT(size_t) _nc_wcrtomb (char *, wchar_t, mbstate_t *); +#endif #if USE_SIZECHANGE -extern NCURSES_EXPORT(void) _nc_update_screensize (void); +extern NCURSES_EXPORT(void) _nc_update_screensize (SCREEN *); #endif -#if USE_WIDEC_SUPPORT -extern NCURSES_EXPORT(int) _nc_utf8_outch (int); +#if HAVE_RESIZETERM +extern NCURSES_EXPORT(void) _nc_resize_margins (WINDOW *); +#else +#define _nc_resize_margins(wp) /* nothing */ +#endif + +#ifdef NCURSES_WGETCH_EVENTS +extern NCURSES_EXPORT(int) _nc_eventlist_timeout(_nc_eventlist *); +#else +#define wgetch_events(win, evl) wgetch(win) +#define wgetnstr_events(win, str, maxlen, evl) wgetnstr(win, str, maxlen) +#endif + +/* + * Not everyone has vsscanf(), but we'd like to use it for scanw(). + */ +#if !HAVE_VSSCANF +extern int vsscanf(const char *str, const char *format, va_list __arg); #endif /* scroll indices */ @@ -799,9 +1680,7 @@ extern NCURSES_EXPORT_VAR(int *) _nc_oldnums; #define USE_SETBUF_0 0 -#define NC_BUFFERED(flag) \ - if ((SP->_buffered != 0) != flag) \ - _nc_set_buffer(SP->_ofp, flag) +#define NC_BUFFERED(flag) _nc_set_buffer(SP->_ofp, flag) #define NC_OUTPUT ((SP != 0) ? SP->_ofp : stdout) @@ -822,15 +1701,13 @@ extern NCURSES_EXPORT_VAR(SCREEN *) SP; #endif /* - * We don't want to use the lines or columns capabilities internally, - * because if the application is running multiple screens under - * the X Window System, it's quite possible they could all have type xterm - * but have different sizes! So... + * We don't want to use the lines or columns capabilities internally, because + * if the application is running multiple screens under X, it's quite possible + * they could all have type xterm but have different sizes! So... */ #define screen_lines SP->_lines #define screen_columns SP->_columns -extern NCURSES_EXPORT_VAR(int) _nc_slk_format; /* != 0 if slk_init() called */ extern NCURSES_EXPORT(int) _nc_slk_initialize (WINDOW *, int); /* @@ -851,6 +1728,12 @@ extern NCURSES_EXPORT(int) _nc_slk_initialize (WINDOW *, int); extern NCURSES_EXPORT(int) _nc_ripoffline (int line, int (*init)(WINDOW *,int)); +/* + * Common error messages + */ +#define MSG_NO_MEMORY "Out of memory" +#define MSG_NO_INPUTS "Premature EOF" + #ifdef __cplusplus } #endif diff --git a/lib/libcurses/default_colors.3 b/lib/libcurses/default_colors.3 index 16e224d2c4c..e0848a8e824 100644 --- a/lib/libcurses/default_colors.3 +++ b/lib/libcurses/default_colors.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: default_colors.3,v 1.1 2000/07/24 04:06:10 millert Exp $ +.\" $OpenBSD: default_colors.3,v 1.2 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,22 +28,19 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" Author: Thomas E. Dickey <dickey@clark.net> 1997,1999,2000 +.\" Author: Thomas E. Dickey 1997,1999,2000,2005 .\" -.\" $From: default_colors.3x,v 1.13 2000/07/15 22:06:50 tom Exp $ +.\" $Id: default_colors.3,v 1.2 2010/01/12 23:21:59 nicm Exp $ .TH default_colors 3 "" .SH NAME -\fBdefault_colors\fR, \fBuse_default_colors\fR, \fBassume_default_colors\fR \- use terminal's default colors -.. .SH SYNOPSIS \fB#include <curses.h>\fP - +.sp \fBint use_default_colors(void);\fP .br \fBint assume_default_colors(int fg, int bg);\fP -.. .SH DESCRIPTION The .I use_default_colors() @@ -102,28 +99,42 @@ or .I assume_default_colors() ncurses will paint a white foreground (text) with black background for color pair 0. -.. .SH RETURN VALUE These functions return the integer \fBERR\fP upon failure and \fBOK\fP on success. They will fail if either the terminal does not support the \fIorig_pair\fP or \fIorig_colors\fP capability. If the \fIinitialize_pair\fP capability is found, this causes an error as well. -.. .SH NOTES -Associated with this extension, the \fBinit_pair\fR(3) function accepts -negative arguments to specify default foreground or background -colors. -.. +Associated with this extension, the \fBinit_pair\fR function accepts +negative arguments to specify default foreground or background colors. +.PP +The \fIuse_default_colors()\fP function was added to support \fIded\fP. +This is a full-screen application which uses curses to manage only part +of the screen. The bottom portion of the screen, which is of adjustable +size, is left uncolored to display the results from shell commands. +The top portion of the screen colors filenames using a scheme like the +"color ls" programs. +Attempting to manage the background color of the screen for this application +would give unsatisfactory results for a variety of reasons. +This extension was devised after +noting that color xterm (and similar programs) provides a background color +which does not necessarily correspond to any of the ANSI colors. +While a special terminfo entry could be constructed using nine colors, +there was no mechanism provided within curses to account for the related +\fIorig_pair\fP and \fIback_color_erase\fP capabilities. +.PP +The \fIassume_default_colors()\fP function was added to solve +a different problem: support for applications which would use +environment variables and other configuration to bypass curses' +notion of the terminal's default colors, setting specific values. .SH PORTABILITY These routines are specific to ncurses. They were not supported on Version 7, BSD or System V implementations. It is recommended that any code depending on them be conditioned using NCURSES_VERSION. -.. .SH SEE ALSO \fBcurs_color\fR(3), \fBded\fP(1). -.. .SH AUTHOR Thomas Dickey (from an analysis of the requirements for color xterm for XFree86 3.1.2C, February 1996). diff --git a/lib/libcurses/define_key.3 b/lib/libcurses/define_key.3 index c0e10afb70c..9104ca26fd7 100644 --- a/lib/libcurses/define_key.3 +++ b/lib/libcurses/define_key.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: define_key.3,v 1.4 1999/05/08 20:28:58 millert Exp $ +.\" $OpenBSD: define_key.3,v 1.5 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2004,2006 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,40 +28,35 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" Author: Thomas E. Dickey <dickey@clark.net> 1997 +.\" Author: Thomas E. Dickey 1997 .\" -.\" $From: define_key.3x,v 1.6 1999/02/19 11:43:17 tom Exp $ +.\" $Id: define_key.3,v 1.5 2010/01/12 23:21:59 nicm Exp $ .TH define_key 3 "" .SH NAME \fBdefine_key\fP \- define a keycode -.. .SH SYNOPSIS \fB#include <curses.h>\fP - -\fBint define_key(char *definition, int keycode);\fP -.. +.sp +\fBint define_key(const char *definition, int keycode);\fP .SH DESCRIPTION This is an extension to the curses library. It permits an application to define keycodes with their corresponding control -strings, so that the curses library will interpret them just as it would +strings, so that the ncurses library will interpret them just as it would the predefined codes in the terminfo database. .PP If the given string is null, any existing definition for the keycode is removed. Similarly, if the given keycode is negative or zero, any existing string for the given definition is removed. -.. .SH RETURN VALUE The keycode must be greater than zero, else ERR is returned. -.. .SH PORTABILITY These routines are specific to ncurses. They were not supported on Version 7, BSD or System V implementations. It is recommended that any code depending on them be conditioned using NCURSES_VERSION. -.. .SH SEE ALSO -\fBkeyok\fR(3). -.. +\fBkeyok\fR(3), +\fBkey_defined\fR(3). .SH AUTHOR Thomas Dickey. .\"# diff --git a/lib/libcurses/doc/hackguide.html b/lib/libcurses/doc/hackguide.html index 4e1d237f3b7..938fa4c0969 100644 --- a/lib/libcurses/doc/hackguide.html +++ b/lib/libcurses/doc/hackguide.html @@ -1,11 +1,39 @@ <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 3.0//EN"> <!-- - $From: hackguide.html,v 1.25 2000/03/25 18:45:21 tom Exp $ + $Id: hackguide.html,v 1.6 2010/01/12 23:22:06 nicm Exp $ + **************************************************************************** + * Copyright (c) 1998-2003,2005 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + **************************************************************************** --> <HTML> <HEAD> <TITLE>A Hacker's Guide to Ncurses Internals</TITLE> <link rev="made" href="mailto:bugs-ncurses@gnu.org"> +<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <!-- This document is self-contained, *except* that there is one relative link to the ncurses-intro.html document, expected to be in the same directory with @@ -286,10 +314,6 @@ header comments of <CODE>hardscroll.c</CODE> and <CODE>hashmap.c</CODE>; then tr it out. You can also test the hardware-scrolling optimization separately with <CODE>hardscroll</CODE>. <P> -There's one other interactive tester, <CODE>tctest</CODE>, that exercises -translation between termcap and terminfo formats. If you have a serious -need to run this, you probably belong on our development team! - <H1><A NAME="ncurslib">A Tour of the Ncurses Library</A></H1> <H2><A NAME="loverview">Library Overview</A></H2> @@ -377,7 +401,7 @@ trace_buf.c </code> </blockquote> It is rather unlikely you will ever need to change these, unless -you want to introduce a new debug trace level for some reasoon.<P> +you want to introduce a new debug trace level for some reason.<P> There is another group of files that do direct I/O via <EM>tputs()</EM>, computations on the terminal capabilities, or queries to the OS diff --git a/lib/libcurses/doc/ncurses-intro.html b/lib/libcurses/doc/ncurses-intro.html index f6d505a50ad..d0ccb74e719 100644 --- a/lib/libcurses/doc/ncurses-intro.html +++ b/lib/libcurses/doc/ncurses-intro.html @@ -1,11 +1,39 @@ <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 3.0//EN"> <!-- - $From: ncurses-intro.html,v 1.34 2000/06/11 00:03:55 tom Exp $ + $Id: ncurses-intro.html,v 1.7 2010/01/12 23:22:06 nicm Exp $ + **************************************************************************** + * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + **************************************************************************** --> <HTML> <HEAD> <TITLE>Writing Programs with NCURSES</TITLE> <link rev="made" href="mailto:bugs-ncurses@gnu.org"> +<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </HEAD> <BODY> @@ -221,16 +249,11 @@ maintainer of this package is <esr@snark.thyrsus.com> wrote many of the new features in versions after 1.8.1 and wrote most of this introduction. -<A HREF="mailto:juergen.pfeifer@gmx.net">Jürgen Pfeifer</A> +Jürgen Pfeifer wrote all of the menu and forms code as well as the <A HREF="http://www.adahome.com">Ada95</A> binding. Ongoing work is being done by -<A HREF="mailto:dickey@herndon4.his.com">Thomas Dickey</A> -and -<A HREF="mailto:juergen.pfeifer@gmx.net">Jürgen Pfeifer</A>. -<A HREF="mailto:florian@gnu.org">Florian La Roche</A> -acts as the maintainer for the Free Software Foundation, which holds the -copyright on ncurses. +<A HREF="mailto:dickey@invisible-island.net">Thomas Dickey</A> (maintainer). Contact the current maintainers at <A HREF="mailto:bug-ncurses@gnu.org">bug-ncurses@gnu.org</A>. <P> @@ -613,6 +636,7 @@ Presently, mouse event reporting works in the following environments: <li>xterm and similar programs such as rxvt. <li>Linux console, when configured with <CODE>gpm</CODE>(1), Alessandro Rubini's mouse server. +<li>FreeBSD sysmouse (console) <li>OS/2 EMX </ul> <P> @@ -690,7 +714,7 @@ the first call to <CODE>refresh()</CODE> will clear the screen. If an error occurs a message is written to standard error and the program exits. Otherwise it returns a pointer to stdscr. A few functions may be called before initscr (<CODE>slk_init()</CODE>, <CODE>filter()</CODE>, -<CODE>ripofflines()</CODE>, <CODE>use_env()</CODE>, and, if you are using multiple +<CODE>ripoffline()</CODE>, <CODE>use_env()</CODE>, and, if you are using multiple terminals, <CODE>newterm()</CODE>.) <DT> <CODE>endwin()</CODE> <DD> Your program should always call <CODE>endwin()</CODE> before exiting or @@ -704,7 +728,11 @@ restore the ncurses screen from before the escape. <CODE>newterm()</CODE> instead of <CODE>initscr()</CODE>. <CODE>newterm()</CODE> should be called once for each terminal. It returns a variable of type <CODE>SCREEN *</CODE> which should be saved as a reference to that -terminal. The arguments are the type of the terminal (a string) and +terminal. +(NOTE: a SCREEN variable is not a <em>screen</em> in the sense we +are describing in this introduction, but a collection of +parameters used to assist in optimizing the display.) +The arguments are the type of the terminal (a string) and <CODE>FILE</CODE> pointers for the output and input of the terminal. If type is NULL then the environment variable <CODE>$TERM</CODE> is used. <CODE>endwin()</CODE> should called once at wrapup time for each terminal @@ -728,7 +756,7 @@ the terminal, as other routines merely manipulate data structures. <CODE>wrefresh()</CODE> copies the named window to the physical terminal screen, taking into account what is already there in order to do optimizations. <CODE>refresh()</CODE> does a -refresh of <CODE>stdscr()</CODE>. Unless <CODE>leaveok()</CODE> has been +refresh of <CODE>stdscr</CODE>. Unless <CODE>leaveok()</CODE> has been enabled, the physical cursor of the terminal is left at the location of the window's cursor. <DT> <CODE>doupdate()</CODE> and <CODE>wnoutrefresh(win)</CODE> @@ -886,15 +914,14 @@ Here is some sample code for shellout: <H3><A NAME="xterm">Using NCURSES under XTERM</A></H3> -A resize operation in X sends SIGWINCH to the application running under xterm. -The <CODE>ncurses</CODE> library provides an experimental signal -handler, but in general does not catch this signal, because it cannot -know how you want the screen re-painted. You will usually have to write the -SIGWINCH handler yourself. Ncurses can give you some help. <P> +A resize operation in X sends <CODE>SIGWINCH</CODE> to the application running +under xterm. -The easiest way to code your SIGWINCH handler is to have it do an -<CODE>endwin</CODE>, followed by an <CODE>refresh</CODE> and a screen repaint you code -yourself. The <CODE>refresh</CODE> will pick up the new screen size from the +The easiest way to handle <CODE>SIGWINCH</CODE> +is to do an <CODE>endwin</CODE>, +followed by an <CODE>refresh</CODE> and a screen repaint you code +yourself. +The <CODE>refresh</CODE> will pick up the new screen size from the xterm's environment. <P> That is the standard way, of course (it even works with some vendor's curses @@ -906,8 +933,17 @@ not resize subwindows which must be shrunk. are limited to the new screen dimensions, and pads <CODE>stdscr</CODE> with blanks if the screen is larger. <P> -Finally, ncurses can be configured to provide its own SIGWINCH handler, -based on <CODE>resizeterm</CODE>. +The <CODE>ncurses</CODE> library provides a SIGWINCH signal handler, +which pushes a <CODE>KEY_RESIZE</CODE> via the wgetch() calls. +When <CODE>ncurses</CODE> returns that code, +it calls <code>resizeterm</CODE> +to update the size of the standard screen's window, repainting that +(filling with blanks or truncating as needed). +It also resizes other windows, +but its effect may be less satisfactory because it cannot +know how you want the screen re-painted. +You will usually have to write special-purpose code to handle +<CODE>KEY_RESIZE</CODE> yourself. <H3><A NAME="screens">Handling Multiple Terminal Screens</A></H3> @@ -1016,7 +1052,7 @@ guarantee an entire-contents copy anywhere. <P> The really clean way to handle this is to use the panels library. If, when you want a screen update, you do <CODE>update_panels()</CODE>, it will -do all the necessary <CODE>wnoutrfresh()</CODE> calls for whatever panel +do all the necessary <CODE>wnoutrefresh()</CODE> calls for whatever panel stacking order you have defined. Then you can do one <CODE>doupdate()</CODE> and there will be a <EM>single</EM> burst of physical I/O that will do all your updates. @@ -1218,10 +1254,10 @@ The general flow of control of a menu program looks like this: <LI>Initialize <CODE>curses</CODE>. <LI>Create the menu items, using <CODE>new_item()</CODE>. <LI>Create the menu using <CODE>new_menu()</CODE>. -<LI>Post the menu using <CODE>menu_post()</CODE>. +<LI>Post the menu using <CODE>post_menu()</CODE>. <LI>Refresh the screen. <LI>Process user requests via an input loop. -<LI>Unpost the menu using <CODE>menu_unpost()</CODE>. +<LI>Unpost the menu using <CODE>unpost_menu()</CODE>. <LI>Free the menu, using <CODE>free_menu()</CODE>. <LI>Free the items using <CODE>free_item()</CODE>. <LI>Terminate <CODE>curses</CODE>. @@ -1304,8 +1340,8 @@ refreshed or erased at post/unpost time. The inner window or By default, both windows are <CODE>stdscr</CODE>. You can set them with the functions in <CODE>menu_win(3x)</CODE>. <P> -When you call <CODE>menu_post()</CODE>, you write the menu to its -subwindow. When you call <CODE>menu_unpost()</CODE>, you erase the +When you call <CODE>post_menu()</CODE>, you write the menu to its +subwindow. When you call <CODE>unpost_menu()</CODE>, you erase the subwindow, However, neither of these actually modifies the screen. To do that, call <CODE>wrefresh()</CODE> or some equivalent. @@ -1437,10 +1473,10 @@ The general flow of control of a form program looks like this: <LI>Initialize <CODE>curses</CODE>. <LI>Create the form fields, using <CODE>new_field()</CODE>. <LI>Create the form using <CODE>new_form()</CODE>. -<LI>Post the form using <CODE>form_post()</CODE>. +<LI>Post the form using <CODE>post_form()</CODE>. <LI>Refresh the screen. <LI>Process user requests via an input loop. -<LI>Unpost the form using <CODE>form_unpost()</CODE>. +<LI>Unpost the form using <CODE>unpost_form()</CODE>. <LI>Free the form, using <CODE>free_form()</CODE>. <LI>Free the fields using <CODE>free_field()</CODE>. <LI>Terminate <CODE>curses</CODE>. @@ -1476,7 +1512,7 @@ the screen (the third and fourth arguments, which must be zero or greater). Note that these coordinates are relative to the form subwindow, which will coincide with <CODE>stdscr</CODE> by default but need not be <CODE>stdscr</CODE> if you've done an explicit -<CODE>set_form_window()</CODE> call. <P> +<CODE>set_form_win()</CODE> call. <P> The fifth argument allows you to specify a number of off-screen rows. If this is zero, the entire field will always be displayed. If it is @@ -2156,7 +2192,7 @@ These requests treat the list as cyclic; that is, <CODE>REQ_NEXT_PAGE</CODE> from the last page goes to the first, and <CODE>REQ_PREV_PAGE</CODE> from the first page goes to the last. -<H3><A NAME="#ffield">Inter-Field Navigation Requests</A></H3> +<H3><A NAME="ffield">Inter-Field Navigation Requests</A></H3> These requests handle navigation between fields on the same page. @@ -2210,7 +2246,7 @@ of B and C to the right of B. A <CODE>REQ_MOVE_RIGHT</CODE> from A will go to B only if A, B, and C <EM>all</EM> share the same first line; otherwise it will skip over B to C. -<H3><A NAME="#fifield">Intra-Field Navigation Requests</A></H3> +<H3><A NAME="fifield">Intra-Field Navigation Requests</A></H3> These requests drive movement of the edit cursor within the currently selected field. @@ -2515,13 +2551,13 @@ By default, all options are on. Here are the available option bits: <DL> <DT> O_NL_OVERLOAD <DD> Enable overloading of <CODE>REQ_NEW_LINE</CODE> as described in <A -NAME="fedit">Editing Requests</A>. The value of this option is +href="#fedit">Editing Requests</A>. The value of this option is ignored on dynamic fields that have not reached their size limit; these have no last line, so the circumstances for triggering a <CODE>REQ_NEXT_FIELD</CODE> never arise. <DT> O_BS_OVERLOAD <DD> Enable overloading of <CODE>REQ_DEL_PREV</CODE> as described in -<A NAME="fedit">Editing Requests</A>. +<A href="#fedit">Editing Requests</A>. </DL> The option values are bit-masks and can be composed with logical-or in diff --git a/lib/libcurses/fifo_defs.h b/lib/libcurses/fifo_defs.h index 8fd487fd33c..babc3c05ad7 100644 --- a/lib/libcurses/fifo_defs.h +++ b/lib/libcurses/fifo_defs.h @@ -1,7 +1,7 @@ -/* $OpenBSD: fifo_defs.h,v 1.2 1998/07/23 21:18:17 millert Exp $ */ +/* $OpenBSD: fifo_defs.h,v 1.3 2010/01/12 23:21:59 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998 Free Software Foundation, Inc. * + * Copyright (c) 1998-2002,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -36,25 +36,25 @@ /* * Common macros for lib_getch.c, lib_ungetch.c * - * $From: fifo_defs.h,v 1.2 1998/02/11 12:13:56 tom Exp $ + * $Id: fifo_defs.h,v 1.3 2010/01/12 23:21:59 nicm Exp $ */ #ifndef FIFO_DEFS_H #define FIFO_DEFS_H 1 -#define head SP->_fifohead -#define tail SP->_fifotail +#define head sp->_fifohead +#define tail sp->_fifotail /* peek points to next uninterpreted character */ -#define peek SP->_fifopeek +#define peek sp->_fifopeek #define h_inc() { head == FIFO_SIZE-1 ? head = 0 : head++; if (head == tail) head = -1, tail = 0;} -#define h_dec() { head == 0 ? head = FIFO_SIZE-1 : head--; if (head == tail) tail = -1;} +#define h_dec() { head == 0 ? head = FIFO_SIZE-1 : head--; if (head == tail) tail = -1;} #define t_inc() { tail == FIFO_SIZE-1 ? tail = 0 : tail++; if (tail == head) tail = -1;} -#define t_dec() { tail == 0 ? tail = FIFO_SIZE-1 : tail--; if (head == tail) fifo_clear();} +#define t_dec() { tail == 0 ? tail = FIFO_SIZE-1 : tail--; if (head == tail) fifo_clear(sp);} #define p_inc() { peek == FIFO_SIZE-1 ? peek = 0 : peek++;} -#define cooked_key_in_fifo() (head!=-1 && peek!=head) -#define raw_key_in_fifo() (head!=-1 && peek!=tail) +#define cooked_key_in_fifo() ((head != -1) && (peek != head)) +#define raw_key_in_fifo() ((head != -1) && (peek != tail)) #undef HIDE_EINTR diff --git a/lib/libcurses/hashed_db.h b/lib/libcurses/hashed_db.h new file mode 100644 index 00000000000..c8557e5c9c2 --- /dev/null +++ b/lib/libcurses/hashed_db.h @@ -0,0 +1,69 @@ +/* $OpenBSD: hashed_db.h,v 1.1 2010/01/12 23:21:59 nicm Exp $ */ + +/**************************************************************************** + * Copyright (c) 2006 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey 2006 * + ****************************************************************************/ + +/* + * $Id: hashed_db.h,v 1.1 2010/01/12 23:21:59 nicm Exp $ + */ + +#ifndef HASHED_DB_H +#define HASHED_DB_H 1 + +#include <curses.h> + +#if USE_HASHED_DB + +#include <db.h> + +#ifndef DBN_SUFFIX +#define DBM_SUFFIX ".db" +#endif + +#ifdef DB_VERSION_MAJOR +#define HASHED_DB_API DB_VERSION_MAJOR +#else +#define HASHED_DB_API 1 /* e.g., db 1.8.5 */ +#endif + +extern NCURSES_EXPORT(DB *) _nc_db_open(const char * /* path */, bool /* modify */); +extern NCURSES_EXPORT(bool) _nc_db_have_data(DBT * /* key */, DBT * /* data */, char ** /* buffer */, int * /* size */); +extern NCURSES_EXPORT(bool) _nc_db_have_index(DBT * /* key */, DBT * /* data */, char ** /* buffer */, int * /* size */); +extern NCURSES_EXPORT(int) _nc_db_close(DB * /* db */); +extern NCURSES_EXPORT(int) _nc_db_first(DB * /* db */, DBT * /* key */, DBT * /* data */); +extern NCURSES_EXPORT(int) _nc_db_next(DB * /* db */, DBT * /* key */, DBT * /* data */); +extern NCURSES_EXPORT(int) _nc_db_get(DB * /* db */, DBT * /* key */, DBT * /* data */); +extern NCURSES_EXPORT(int) _nc_db_put(DB * /* db */, DBT * /* key */, DBT * /* data */); + +#endif + +#endif /* HASHED_DB_H */ diff --git a/lib/libcurses/hashsize.h b/lib/libcurses/hashsize.h index b6992abc67f..3e9e040ba9c 100644 --- a/lib/libcurses/hashsize.h +++ b/lib/libcurses/hashsize.h @@ -1,8 +1,8 @@ -/* $OpenBSD: hashsize.h,v 1.2 1999/01/18 19:07:24 millert Exp $ */ +/* $OpenBSD: hashsize.h,v 1.3 2010/01/12 23:21:59 nicm Exp $ */ /* * hashsize.h -- hash and token table constants */ -#define CAPTABSIZE 497 -#define HASHTABSIZE ( 497 * 2) +#define CAPTABSIZE 497 +#define HASHTABSIZE ( 497 * 2) diff --git a/lib/libcurses/key_defined.3 b/lib/libcurses/key_defined.3 new file mode 100644 index 00000000000..1ca4ddac1a7 --- /dev/null +++ b/lib/libcurses/key_defined.3 @@ -0,0 +1,62 @@ +.\" $OpenBSD: key_defined.3,v 1.1 2010/01/12 23:21:59 nicm Exp $ +.\" +.\"*************************************************************************** +.\" Copyright (c) 2003-2004,2006 Free Software Foundation, Inc. * +.\" * +.\" Permission is hereby granted, free of charge, to any person obtaining a * +.\" copy of this software and associated documentation files (the * +.\" "Software"), to deal in the Software without restriction, including * +.\" without limitation the rights to use, copy, modify, merge, publish, * +.\" distribute, distribute with modifications, sublicense, and/or sell * +.\" copies of the Software, and to permit persons to whom the Software is * +.\" furnished to do so, subject to the following conditions: * +.\" * +.\" The above copyright notice and this permission notice shall be included * +.\" in all copies or substantial portions of the Software. * +.\" * +.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * +.\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * +.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * +.\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * +.\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * +.\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * +.\" THE USE OR OTHER DEALINGS IN THE SOFTWARE. * +.\" * +.\" Except as contained in this notice, the name(s) of the above copyright * +.\" holders shall not be used in advertising or otherwise to promote the * +.\" sale, use or other dealings in this Software without prior written * +.\" authorization. * +.\"*************************************************************************** +.\" +.\" Author: Thomas E. Dickey 2003 +.\" +.\" $Id: key_defined.3,v 1.1 2010/01/12 23:21:59 nicm Exp $ +.TH key_defined 3 "" +.SH NAME +\fBkey_defined\fP \- check if a keycode is defined +.SH SYNOPSIS +\fB#include <curses.h>\fP +.sp +\fBint key_defined(const char *definition);\fP +.SH DESCRIPTION +This is an extension to the curses library. +It permits an application to determine if a string is currently bound +to any keycode. +.SH RETURN VALUE +If the string is bound to a keycode, its value (greater than zero) is returned. +If no keycode is bound, zero is returned. +If the string conflicts with longer strings which are bound to keys, -1 is returned. +.SH PORTABILITY +These routines are specific to ncurses. They were not supported on +Version 7, BSD or System V implementations. It is recommended that +any code depending on them be conditioned using NCURSES_VERSION. +.SH SEE ALSO +\fBdefine_key\fR(3). +.SH AUTHOR +Thomas Dickey. +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/keybound.3 b/lib/libcurses/keybound.3 index bad5d9e4486..bd586434234 100644 --- a/lib/libcurses/keybound.3 +++ b/lib/libcurses/keybound.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: keybound.3,v 1.2 2008/12/07 08:59:22 jmc Exp $ +.\" $OpenBSD: keybound.3,v 1.3 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1999 Free Software Foundation, Inc. * +.\" Copyright (c) 1999-2003,2006 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,37 +28,34 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" Author: Thomas E. Dickey <dickey@clark.net> 1999 +.\" Author: Thomas E. Dickey 1999 .\" -.\" $From: keybound.3x,v 1.1 1999/02/19 11:59:24 tom Exp $ +.\" $Id: keybound.3,v 1.3 2010/01/12 23:21:59 nicm Exp $ .TH keybound 3 "" .SH NAME \fBkeybound\fP \- return definition of keycode -.. .SH SYNOPSIS \fB#include <curses.h>\fP - +.sp \fBchar * keybound(int keycode, int count);\fP -.. .SH DESCRIPTION This is an extension to the curses library. It permits an application to determine the string which is defined in the terminfo for specific keycodes. -.. .SH RETURN VALUE -The keycode must be greater than zero, else NULL is returned. +The \fIkeycode\fP parameter must be greater than zero, else NULL is returned. If it does not correspond to a defined key, then NULL is returned. -Otherwise, the function returns a string, which must be freed by the caller. -.. +The \fIcount\fP parameter is used to allow the application to iterate +through multiple definitions, counting from zero. +When successful, +the function returns a string which must be freed by the caller. .SH PORTABILITY These routines are specific to ncurses. They were not supported on Version 7, BSD or System V implementations. It is recommended that any code depending on them be conditioned using NCURSES_VERSION. -.. .SH SEE ALSO \fBdefine_key\fR(3), \fBkeyok\fR(3). -.. .SH AUTHOR Thomas Dickey. .\"# diff --git a/lib/libcurses/keyok.3 b/lib/libcurses/keyok.3 index 9d44325a6dd..4168f9d246b 100644 --- a/lib/libcurses/keyok.3 +++ b/lib/libcurses/keyok.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: keyok.3,v 1.3 1998/09/13 19:16:27 millert Exp $ +.\" $OpenBSD: keyok.3,v 1.4 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2003,2006 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,39 +28,33 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" Author: Thomas E. Dickey <dickey@clark.net> 1997 +.\" Author: Thomas E. Dickey 1997 .\" -.\" $From: keyok.3x,v 1.5 1998/03/14 23:43:07 tom Exp $ +.\" $Id: keyok.3,v 1.4 2010/01/12 23:21:59 nicm Exp $ .TH keyok 3 "" .SH NAME \fBkeyok\fP \- enable or disable a keycode -.. .SH SYNOPSIS \fB#include <curses.h>\fP - +.sp \fBint keyok(int keycode, bool enable);\fP -.. .SH DESCRIPTION This is an extension to the curses library. It permits an application to disable specific keycodes, rather than use the \fIkeypad\fP function to disable all keycodes. Keys that have been disabled can be reenabled. -.. .SH RETURN VALUE The keycode must be greater than zero, else ERR is returned. If it does not correspond to a defined key, then ERR is returned. If the \fIenable\fP parameter is true, then the key must have been disabled, and vice versa. Otherwise, the function returns OK. -.. .SH PORTABILITY These routines are specific to ncurses. They were not supported on Version 7, BSD or System V implementations. It is recommended that any code depending on them be conditioned using NCURSES_VERSION. -.. .SH SEE ALSO \fBdefine_key\fR(3). -.. .SH AUTHOR Thomas Dickey. .\"# diff --git a/lib/libcurses/nc_alloc.h b/lib/libcurses/nc_alloc.h index 525a0850e0d..93a12b3cdf6 100644 --- a/lib/libcurses/nc_alloc.h +++ b/lib/libcurses/nc_alloc.h @@ -1,7 +1,7 @@ -/* $OpenBSD: nc_alloc.h,v 1.6 2000/06/19 03:53:36 millert Exp $ */ +/* $OpenBSD: nc_alloc.h,v 1.7 2010/01/12 23:21:59 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,14 +29,20 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey <dickey@clark.net> 1996,1997 * + * Author: Thomas E. Dickey 1996-on * ****************************************************************************/ -/* $From: nc_alloc.h,v 1.8 2000/04/08 23:42:57 tom Exp $ */ +/* $Id: nc_alloc.h,v 1.7 2010/01/12 23:21:59 nicm Exp $ */ #ifndef NC_ALLOC_included #define NC_ALLOC_included 1 +#ifdef __cplusplus +extern "C" { +#endif + #if HAVE_LIBDMALLOC +#include <string.h> +#undef strndup /* workaround for #define in GLIBC 2.7 */ #include <dmalloc.h> /* Gray Watson's library */ #else #undef HAVE_LIBDMALLOC @@ -50,6 +56,13 @@ #define HAVE_LIBDBMALLOC 0 #endif +#if HAVE_LIBMPATROL +#include <mpatrol.h> /* Memory-Patrol library */ +#else +#undef HAVE_LIBMPATROL +#define HAVE_LIBMPATROL 0 +#endif + #ifndef NO_LEAKS #define NO_LEAKS 0 #endif @@ -57,9 +70,12 @@ #if HAVE_LIBDBMALLOC || HAVE_LIBDMALLOC || NO_LEAKS #define HAVE_NC_FREEALL 1 struct termtype; -extern void _nc_free_and_exit(int) GCC_NORETURN; -extern void _nc_free_tparm(void); -extern void _nc_leaks_dump_entry(void); +extern NCURSES_EXPORT(void) _nc_free_and_exit(int) GCC_NORETURN; +extern NCURSES_EXPORT(void) _nc_free_tinfo(int) GCC_NORETURN; +extern NCURSES_EXPORT(void) _nc_free_tic(int) GCC_NORETURN; +extern NCURSES_EXPORT(void) _nc_free_tparm(void); +extern NCURSES_EXPORT(void) _nc_leaks_dump_entry(void); +extern NCURSES_EXPORT(void) _nc_leaks_tic(void); #define ExitProgram(code) _nc_free_and_exit(code) #endif @@ -68,18 +84,25 @@ extern void _nc_leaks_dump_entry(void); #endif #ifndef ExitProgram -#define ExitProgram(code) return code +#define ExitProgram(code) exit(code) #endif /* doalloc.c */ -extern void *_nc_doalloc(void *, size_t); +extern NCURSES_EXPORT(void *) _nc_doalloc(void *, size_t); #if !HAVE_STRDUP #define strdup _nc_strdup -extern char *_nc_strdup(const char *); +extern NCURSES_EXPORT(char *) _nc_strdup(const char *); #endif +/* entries.c */ +extern NCURSES_EXPORT(void) _nc_leaks_tinfo(void); + #define typeMalloc(type,elts) (type *)malloc((elts)*sizeof(type)) #define typeCalloc(type,elts) (type *)calloc((elts),sizeof(type)) #define typeRealloc(type,elts,ptr) (type *)_nc_doalloc(ptr, (elts)*sizeof(type)) +#ifdef __cplusplus +} +#endif + #endif /* NC_ALLOC_included */ diff --git a/lib/libcurses/nc_panel.h b/lib/libcurses/nc_panel.h index 107f555d5e4..83c4e3a8ece 100644 --- a/lib/libcurses/nc_panel.h +++ b/lib/libcurses/nc_panel.h @@ -1,7 +1,7 @@ -/* $OpenBSD: nc_panel.h,v 1.3 2001/01/22 18:01:34 millert Exp $ */ +/* $OpenBSD: nc_panel.h,v 1.4 2010/01/12 23:21:59 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2000,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,13 +29,13 @@ ****************************************************************************/ /**************************************************************************** - * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * - * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * Author: Juergen Pfeifer 1997 * + * and: Thomas E. Dickey * ****************************************************************************/ /* - * $From: nc_panel.h,v 1.3 2000/12/10 02:04:35 tom Exp $ + * $Id: nc_panel.h,v 1.4 2010/01/12 23:21:59 nicm Exp $ * * nc_panel.h * @@ -56,6 +56,9 @@ struct panelhook { struct panel* top_panel; struct panel* bottom_panel; struct panel* stdscr_pseudo_panel; +#if NO_LEAKS + int (*destroy)(struct panel *); +#endif }; /* Retrieve the panelhook of the current screen */ diff --git a/lib/libcurses/nc_tparm.h b/lib/libcurses/nc_tparm.h new file mode 100644 index 00000000000..0100cd76e03 --- /dev/null +++ b/lib/libcurses/nc_tparm.h @@ -0,0 +1,67 @@ +/* $OpenBSD: nc_tparm.h,v 1.1 2010/01/12 23:21:59 nicm Exp $ */ + +/**************************************************************************** + * Copyright (c) 2006 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey 2006 * + ****************************************************************************/ + +/* $Id: nc_tparm.h,v 1.1 2010/01/12 23:21:59 nicm Exp $ */ + +/* + * Cast parameters past the formatting-string for tparm() to match the + * assumption of the varargs code. + */ +#define TPARM_ARG long +#define TPARM_N(n) (TPARM_ARG)(n) + +#define TPARM_9(a,b,c,d,e,f,g,h,i,j) tparm(a,TPARM_N(b),TPARM_N(c),TPARM_N(d),TPARM_N(e),TPARM_N(f),TPARM_N(g),TPARM_N(h),TPARM_N(i),TPARM_N(j)) + +#if NCURSES_TPARM_VARARGS +#define TPARM_8(a,b,c,d,e,f,g,h,i) tparm(a,TPARM_N(b),TPARM_N(c),TPARM_N(d),TPARM_N(e),TPARM_N(f),TPARM_N(g),TPARM_N(h),TPARM_N(i)) +#define TPARM_7(a,b,c,d,e,f,g,h) tparm(a,TPARM_N(b),TPARM_N(c),TPARM_N(d),TPARM_N(e),TPARM_N(f),TPARM_N(g),TPARM_N(h)) +#define TPARM_6(a,b,c,d,e,f,g) tparm(a,TPARM_N(b),TPARM_N(c),TPARM_N(d),TPARM_N(e),TPARM_N(f),TPARM_N(g)) +#define TPARM_5(a,b,c,d,e,f) tparm(a,TPARM_N(b),TPARM_N(c),TPARM_N(d),TPARM_N(e),TPARM_N(f)) +#define TPARM_4(a,b,c,d,e) tparm(a,TPARM_N(b),TPARM_N(c),TPARM_N(d),TPARM_N(e)) +#define TPARM_3(a,b,c,d) tparm(a,TPARM_N(b),TPARM_N(c),TPARM_N(d)) +#define TPARM_2(a,b,c) tparm(a,TPARM_N(b),TPARM_N(c)) +#define TPARM_1(a,b) tparm(a,TPARM_N(b)) +#define TPARM_0(a) tparm(a) +#else +#define TPARM_8(a,b,c,d,e,f,g,h,i) TPARM_9(a,b,c,d,e,f,g,h,i,0) +#define TPARM_7(a,b,c,d,e,f,g,h) TPARM_8(a,b,c,d,e,f,g,h,0) +#define TPARM_6(a,b,c,d,e,f,g) TPARM_7(a,b,c,d,e,f,g,0) +#define TPARM_5(a,b,c,d,e,f) TPARM_6(a,b,c,d,e,f,0) +#define TPARM_4(a,b,c,d,e) TPARM_5(a,b,c,d,e,0) +#define TPARM_3(a,b,c,d) TPARM_4(a,b,c,d,0) +#define TPARM_2(a,b,c) TPARM_3(a,b,c,0) +#define TPARM_1(a,b) TPARM_2(a,b,0) +#define TPARM_1(a,b) TPARM_2(a,b,0) +#define TPARM_0(a) TPARM_1(a,0) +#endif diff --git a/lib/libcurses/ncurses_cfg.h b/lib/libcurses/ncurses_cfg.h index 493f1fcb2c4..24a1212830b 100644 --- a/lib/libcurses/ncurses_cfg.h +++ b/lib/libcurses/ncurses_cfg.h @@ -1,6 +1,8 @@ +/* $OpenBSD: ncurses_cfg.h,v 1.24 2010/01/12 23:21:59 nicm Exp $ */ + /* include/ncurses_cfg.h. Generated automatically by configure. */ /**************************************************************************** - * Copyright (c) 1998 Free Software Foundation, Inc. * + * Copyright (c) 1998-2004,2005 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,7 +33,7 @@ * Author: Thomas E. Dickey <dickey@clark.net> 1997 * ****************************************************************************/ /* - * $From: ncurses_cfg.hin,v 1.3 2000/09/02 17:13:32 tom Exp $ + * $Id: ncurses_cfg.h,v 1.24 2010/01/12 23:21:59 nicm Exp $ * * This is a template-file used to generate the "ncurses_cfg.h" file. * @@ -40,16 +42,16 @@ * 971222) to autoconf 2.12 or 2.13 to do this. * * See: - * http://dickey.his.com/autoconf/ - * ftp://dickey.his.com/autoconf/ + * http://invisible-island.net/autoconf/ + * ftp://invisible-island.net/autoconf/ */ #ifndef NC_CONFIG_H #define NC_CONFIG_H #define BSD_TPUTS 1 -#define CC_HAS_INLINE_FUNCS 1 #define CC_HAS_PROTOS 1 -#define CPP_HAS_PARAM_INIT 1 +#define CPP_HAS_STATIC_CAST 1 +#define ETIP_NEEDS_MATH_H 1 #define GCC_NORETURN __attribute__((__noreturn__)) #define GCC_PRINTF 1 #define GCC_SCANF 1 @@ -61,22 +63,24 @@ #define HAVE_ERRNO 1 #define HAVE_FCNTL_H 1 #define HAVE_FORM_H 1 +#define HAVE_FSEEKO 1 #define HAVE_GETCWD 1 #define HAVE_GETEGID 1 #define HAVE_GETEUID 1 +#define HAVE_GETOPT_H 1 #define HAVE_GETTIMEOFDAY 1 #define HAVE_GETTTYNAM 1 #define HAVE_HAS_KEY 1 +#define HAVE_INTTYPES_H 1 +#define HAVE_IOSTREAM 1 #define HAVE_ISASCII 1 #define HAVE_ISSETUGID 1 -/* #define HAVE_LIBFORM 1 */ -/* #define HAVE_LIBMENU 1 */ -/* #define HAVE_LIBPANEL 1 */ +#define HAVE_LANGINFO_CODESET 1 #define HAVE_LIMITS_H 1 #define HAVE_LINK 1 #define HAVE_LOCALE_H 1 #define HAVE_LONG_FILE_NAMES 1 -#define HAVE_MEMCCPY 1 +#define HAVE_MEMORY_H 1 #define HAVE_MENU_H 1 #define HAVE_MKSTEMP 1 #define HAVE_NANOSLEEP 1 @@ -86,7 +90,9 @@ #define HAVE_POLL_H 1 #define HAVE_REGEX_H_FUNCS 1 #define HAVE_REMOVE 1 +#define HAVE_REMOVE 1 #define HAVE_RESIZETERM 1 +#define HAVE_RESIZE_TERM 1 #define HAVE_SELECT 1 #define HAVE_SETBUF 1 #define HAVE_SETBUFFER 1 @@ -94,16 +100,23 @@ #define HAVE_SIGACTION 1 #define HAVE_SIGVEC 1 #define HAVE_SIZECHANGE 1 +#define HAVE_SLK_COLOR 1 +#define HAVE_STDINT_H 1 +#define HAVE_STDLIB_H 1 #define HAVE_STRDUP 1 +#define HAVE_STRINGS_H 1 +#define HAVE_STRING_H 1 #define HAVE_STRSTR 1 #define HAVE_SYMLINK 1 #define HAVE_SYS_IOCTL_H 1 #define HAVE_SYS_PARAM_H 1 #define HAVE_SYS_POLL_H 1 #define HAVE_SYS_SELECT_H 1 +#define HAVE_SYS_STAT_H 1 #define HAVE_SYS_TIMES_H 1 #define HAVE_SYS_TIME_H 1 #define HAVE_SYS_TIME_SELECT 1 +#define HAVE_SYS_TYPES_H 1 #define HAVE_TCGETATTR 1 #define HAVE_TCGETPGRP 1 #define HAVE_TERMIOS_H 1 @@ -111,28 +124,44 @@ #define HAVE_TTYENT_H 1 #define HAVE_TYPEINFO 1 #define HAVE_UNISTD_H 1 +#define HAVE_UNISTD_H 1 +#define HAVE_UNISTD_H 1 #define HAVE_UNLINK 1 #define HAVE_USE_DEFAULT_COLORS 1 #define HAVE_VSNPRINTF 1 #define HAVE_VSSCANF 1 +#define HAVE_WCTYPE_H 1 #define HAVE_WORKING_POLL 1 #define HAVE_WRESIZE 1 +#define IOSTREAM_NAMESPACE 1 #define MIXEDCASE_FILENAMES 1 #define NCURSES_EXT_FUNCS 1 #define NCURSES_NO_PADDING 1 #define NCURSES_PATHSEP ':' +#define NCURSES_VERSION_STRING "5.7.20081102" #define NDEBUG 1 +#define PURE_TERMINFO 0 #define RETSIGTYPE void +#define SIG_ATOMIC_T volatile sig_atomic_t +#define SIZEOF_SIGNED_CHAR 1 #define STDC_HEADERS 1 -#define SYSTEM_NAME "openbsd2.8" +#define SYSTEM_NAME "openbsd" #define TERMINFO "/usr/share/terminfo" #define TERMINFO_DIRS "/usr/share/terminfo" +#define TIME_WITH_SYS_TIME 1 #define TYPEOF_CHTYPE long #define USE_ASSUMED_COLOR 1 #define USE_DATABASE 1 -#define USE_GETCAP 1 +#define USE_GETCAP 1 #define USE_HASHMAP 1 +#define USE_HOME_TERMINFO 1 +#define USE_LINKS 1 +#define USE_OPENPTY_HEADER <util.h> #define USE_ROOT_ENVIRON 1 +#define USE_XTERM_PTY 1 +/* #define HAVE_LIBFORM 1 */ +/* #define HAVE_LIBMENU 1 */ +/* #define HAVE_LIBPANEL 1 */ /* #define USE_SIGWINCH 1 */ #include <ncurses_def.h> @@ -148,4 +177,14 @@ #endif #endif + /* On HP-UX, the C compiler doesn't grok mbstate_t without + -D_XOPEN_SOURCE=500. However, this causes problems on + IRIX. So, we #define mbstate_t to int in configure.in + only for the C compiler if needed. */ +#ifndef __cplusplus +#ifdef NEED_MBSTATE_T_DEF +#define mbstate_t int +#endif +#endif + #endif /* NC_CONFIG_H */ diff --git a/lib/libcurses/ncurses_def.h b/lib/libcurses/ncurses_def.h index 0be36557211..87ff0cc7393 100644 --- a/lib/libcurses/ncurses_def.h +++ b/lib/libcurses/ncurses_def.h @@ -1,3 +1,5 @@ +/* $OpenBSD: ncurses_def.h,v 1.2 2010/01/12 23:21:59 nicm Exp $ */ + /* * This file is generated by ./MKncurses_def.sh */ @@ -13,10 +15,6 @@ #define BSD_TPUTS 0 #endif -#ifndef CC_HAS_INLINE_FUNCS -#define CC_HAS_INLINE_FUNCS 0 -#endif - #ifndef CC_HAS_PROTOS #define CC_HAS_PROTOS 0 #endif @@ -25,6 +23,14 @@ #define CPP_HAS_PARAM_INIT 0 #endif +#ifndef CURSES_ACS_ARRAY +#define CURSES_ACS_ARRAY acs_map +#endif + +#ifndef CURSES_WACS_ARRAY +#define CURSES_WACS_ARRAY _nc_wacs +#endif + #ifndef DECL_ERRNO #define DECL_ERRNO 0 #endif @@ -49,10 +55,26 @@ #define HAVE_BSD_CGETENT 0 #endif +#ifndef HAVE_BSD_SIGNAL_H +#define HAVE_BSD_SIGNAL_H 0 +#endif + +#ifndef HAVE_BTOWC +#define HAVE_BTOWC 0 +#endif + #ifndef HAVE_BUILTIN_H #define HAVE_BUILTIN_H 0 #endif +#ifndef HAVE_CHGAT +#define HAVE_CHGAT 1 +#endif + +#ifndef HAVE_COLOR_SET +#define HAVE_COLOR_SET 1 +#endif + #ifndef HAVE_DIRENT_H #define HAVE_DIRENT_H 0 #endif @@ -65,10 +87,22 @@ #define HAVE_FCNTL_H 0 #endif +#ifndef HAVE_FILTER +#define HAVE_FILTER 1 +#endif + #ifndef HAVE_FORM_H #define HAVE_FORM_H 0 #endif +#ifndef HAVE_GETBEGX +#define HAVE_GETBEGX 1 +#endif + +#ifndef HAVE_GETCURX +#define HAVE_GETCURX 1 +#endif + #ifndef HAVE_GETCWD #define HAVE_GETCWD 0 #endif @@ -81,10 +115,22 @@ #define HAVE_GETEUID 0 #endif +#ifndef HAVE_GETMAXX +#define HAVE_GETMAXX 1 +#endif + +#ifndef HAVE_GETNSTR +#define HAVE_GETNSTR 0 +#endif + #ifndef HAVE_GETOPT_H #define HAVE_GETOPT_H 0 #endif +#ifndef HAVE_GETPARX +#define HAVE_GETPARX 1 +#endif + #ifndef HAVE_GETTIMEOFDAY #define HAVE_GETTIMEOFDAY 0 #endif @@ -93,6 +139,14 @@ #define HAVE_GETTTYNAM 0 #endif +#ifndef HAVE_GETWIN +#define HAVE_GETWIN 1 +#endif + +#ifndef HAVE_GPM_H +#define HAVE_GPM_H 0 +#endif + #ifndef HAVE_GPP_BUILTIN_H #define HAVE_GPP_BUILTIN_H 0 #endif @@ -105,6 +159,10 @@ #define HAVE_HAS_KEY 0 #endif +#ifndef HAVE_IOSTREAM +#define HAVE_IOSTREAM 0 +#endif + #ifndef HAVE_ISASCII #define HAVE_ISASCII 0 #endif @@ -113,6 +171,14 @@ #define HAVE_ISSETUGID 0 #endif +#ifndef HAVE_LANGINFO_CODESET +#define HAVE_LANGINFO_CODESET 0 +#endif + +#ifndef HAVE_LIBC_H +#define HAVE_LIBC_H 0 +#endif + #ifndef HAVE_LIBDBMALLOC #define HAVE_LIBDBMALLOC 0 #endif @@ -133,6 +199,10 @@ #define HAVE_LIBMENU 0 #endif +#ifndef HAVE_LIBMPATROL +#define HAVE_LIBMPATROL 0 +#endif + #ifndef HAVE_LIBPANEL #define HAVE_LIBPANEL 0 #endif @@ -153,8 +223,28 @@ #define HAVE_LONG_FILE_NAMES 0 #endif -#ifndef HAVE_MEMCCPY -#define HAVE_MEMCCPY 0 +#ifndef HAVE_MBLEN +#define HAVE_MBLEN 0 +#endif + +#ifndef HAVE_MBRLEN +#define HAVE_MBRLEN 0 +#endif + +#ifndef HAVE_MBRTOWC +#define HAVE_MBRTOWC 0 +#endif + +#ifndef HAVE_MBSRTOWCS +#define HAVE_MBSRTOWCS 0 +#endif + +#ifndef HAVE_MBSTOWCS +#define HAVE_MBSTOWCS 0 +#endif + +#ifndef HAVE_MBTOWC +#define HAVE_MBTOWC 0 #endif #ifndef HAVE_MENU_H @@ -165,6 +255,14 @@ #define HAVE_MKSTEMP 0 #endif +#ifndef HAVE_MVVLINE +#define HAVE_MVVLINE 1 +#endif + +#ifndef HAVE_MVWVLINE +#define HAVE_MVWVLINE 1 +#endif + #ifndef HAVE_NANOSLEEP #define HAVE_NANOSLEEP 0 #endif @@ -185,6 +283,18 @@ #define HAVE_POLL_H 0 #endif +#ifndef HAVE_PURIFY +#define HAVE_PURIFY 0 +#endif + +#ifndef HAVE_PUTWC +#define HAVE_PUTWC 0 +#endif + +#ifndef HAVE_PUTWIN +#define HAVE_PUTWIN 1 +#endif + #ifndef HAVE_REGEXPR_H_FUNCS #define HAVE_REGEXPR_H_FUNCS 0 #endif @@ -205,6 +315,14 @@ #define HAVE_RESIZETERM 0 #endif +#ifndef HAVE_RESIZE_TERM +#define HAVE_RESIZE_TERM 0 +#endif + +#ifndef HAVE_RIPOFFLINE +#define HAVE_RIPOFFLINE 1 +#endif + #ifndef HAVE_SELECT #define HAVE_SELECT 0 #endif @@ -217,6 +335,10 @@ #define HAVE_SETBUFFER 0 #endif +#ifndef HAVE_SETUPTERM +#define HAVE_SETUPTERM 1 +#endif + #ifndef HAVE_SETVBUF #define HAVE_SETVBUF 0 #endif @@ -233,6 +355,14 @@ #define HAVE_SIZECHANGE 0 #endif +#ifndef HAVE_SLK_COLOR +#define HAVE_SLK_COLOR 0 +#endif + +#ifndef HAVE_SLK_INIT +#define HAVE_SLK_INIT 1 +#endif + #ifndef HAVE_STRDUP #define HAVE_STRDUP 0 #endif @@ -293,6 +423,10 @@ #define HAVE_TELL 0 #endif +#ifndef HAVE_TERMATTRS +#define HAVE_TERMATTRS 1 +#endif + #ifndef HAVE_TERMIOS_H #define HAVE_TERMIOS_H 0 #endif @@ -301,6 +435,26 @@ #define HAVE_TERMIO_H 0 #endif +#ifndef HAVE_TERMNAME +#define HAVE_TERMNAME 1 +#endif + +#ifndef HAVE_TERM_H +#define HAVE_TERM_H 1 +#endif + +#ifndef HAVE_TGETENT +#define HAVE_TGETENT 1 +#endif + +#ifndef HAVE_TIGETNUM +#define HAVE_TIGETNUM 1 +#endif + +#ifndef HAVE_TIGETSTR +#define HAVE_TIGETSTR 1 +#endif + #ifndef HAVE_TIMES #define HAVE_TIMES 0 #endif @@ -309,10 +463,18 @@ #define HAVE_TTYENT_H 0 #endif +#ifndef HAVE_TYPEAHEAD +#define HAVE_TYPEAHEAD 1 +#endif + #ifndef HAVE_TYPEINFO #define HAVE_TYPEINFO 0 #endif +#ifndef HAVE_TYPE_ATTR_T +#define HAVE_TYPE_ATTR_T 0 +#endif + #ifndef HAVE_TYPE_SIGACTION #define HAVE_TYPE_SIGACTION 0 #endif @@ -341,6 +503,30 @@ #define HAVE_VSSCANF 0 #endif +#ifndef HAVE_WCSRTOMBS +#define HAVE_WCSRTOMBS 0 +#endif + +#ifndef HAVE_WCSTOMBS +#define HAVE_WCSTOMBS 0 +#endif + +#ifndef HAVE_WCTOB +#define HAVE_WCTOB 0 +#endif + +#ifndef HAVE_WCTOMB +#define HAVE_WCTOMB 0 +#endif + +#ifndef HAVE_WCTYPE_H +#define HAVE_WCTYPE_H 0 +#endif + +#ifndef HAVE_WINSSTR +#define HAVE_WINSSTR 1 +#endif + #ifndef HAVE_WORKING_POLL #define HAVE_WORKING_POLL 0 #endif @@ -349,26 +535,38 @@ #define HAVE_WRESIZE 0 #endif +#ifndef HAVE__DOSCAN +#define HAVE__DOSCAN 0 +#endif + #ifndef MIXEDCASE_FILENAMES #define MIXEDCASE_FILENAMES 0 #endif +#ifndef NCURSES_CHAR_EQ +#define NCURSES_CHAR_EQ 0 +#endif + #ifndef NCURSES_EXPANDED #define NCURSES_EXPANDED 0 #endif -#ifndef NCURSES_EXT_FUNCS -#define NCURSES_EXT_FUNCS 0 +#ifndef NCURSES_EXT_COLORS +#define NCURSES_EXT_COLORS 0 #endif -#ifndef NCURSES_NOMACROS -#define NCURSES_NOMACROS 0 +#ifndef NCURSES_EXT_FUNCS +#define NCURSES_EXT_FUNCS 0 #endif #ifndef NCURSES_NO_PADDING #define NCURSES_NO_PADDING 0 #endif +#ifndef NCURSES_PATHSEP +#define NCURSES_PATHSEP ':' +#endif + #ifndef NDEBUG #define NDEBUG 0 #endif @@ -409,6 +607,14 @@ #define TERMINFO "none" #endif +#ifndef TERMPATH +#define TERMPATH "none" +#endif + +#ifndef TIME_WITH_SYS_TIME +#define TIME_WITH_SYS_TIME 0 +#endif + #ifndef TYPEOF_CHTYPE #define TYPEOF_CHTYPE 0 #endif @@ -433,10 +639,18 @@ #define USE_HARD_TABS 0 #endif +#ifndef USE_HASHED_DB +#define USE_HASHED_DB 0 +#endif + #ifndef USE_HASHMAP #define USE_HASHMAP 0 #endif +#ifndef USE_HOME_TERMINFO +#define USE_HOME_TERMINFO 0 +#endif + #ifndef USE_LINKS #define USE_LINKS 0 #endif @@ -453,6 +667,10 @@ #define USE_RCS_IDS 0 #endif +#ifndef USE_REENTRANT +#define USE_REENTRANT 0 +#endif + #ifndef USE_SAFE_SPRINTF #define USE_SAFE_SPRINTF 0 #endif @@ -469,6 +687,18 @@ #define USE_SYMLINKS 0 #endif +#ifndef USE_SYSMOUSE +#define USE_SYSMOUSE 0 +#endif + +#ifndef USE_TERMCAP +#define USE_TERMCAP 0 +#endif + +#ifndef USE_WEAK_SYMBOLS +#define USE_WEAK_SYMBOLS 0 +#endif + #ifndef USE_WIDEC_SUPPORT #define USE_WIDEC_SUPPORT 0 #endif diff --git a/lib/libcurses/parametrized.h b/lib/libcurses/parametrized.h index fefc00c0406..9d40a537a1b 100644 --- a/lib/libcurses/parametrized.h +++ b/lib/libcurses/parametrized.h @@ -1,9 +1,9 @@ -/* $OpenBSD: parametrized.h,v 1.2 1999/01/18 19:09:04 millert Exp $ */ +/* $OpenBSD: parametrized.h,v 1.3 2010/01/12 23:21:59 nicm Exp $ */ /* * parametrized.h --- is a termcap capability parametrized? * - * Note: this file is generated using parametrized.sh, do not edit by hand. + * Note: this file is generated using MKparametrized.sh, do not edit by hand. * A value of -1 in the table means suppress both pad and % translations. * A value of 0 in the table means do pad but not % translations. * A value of 1 in the table means do both pad and % translations. @@ -25,7 +25,7 @@ static short const parametrized[] = { 0, /* home */ 0, /* civis */ 0, /* cub1 */ -0, /* mrcup */ +1, /* mrcup */ 0, /* cnorm */ 0, /* cuf1 */ 0, /* ll */ @@ -145,7 +145,7 @@ static short const parametrized[] = { 0, /* hts */ 1, /* wind */ 0, /* ht */ -0, /* tsl */ +1, /* tsl */ 0, /* uc */ 0, /* hu */ 0, /* iprog */ @@ -285,7 +285,7 @@ static short const parametrized[] = { 0, /* smgr */ 0, /* fln */ 1, /* sclk */ -1, /* dclk */ +0, /* dclk */ 0, /* rmclk */ 1, /* cwin */ 1, /* wingo */ @@ -314,11 +314,11 @@ static short const parametrized[] = { 1, /* scp */ 1, /* setf */ 1, /* setb */ -0, /* cpi */ -0, /* lpi */ -0, /* chr */ -0, /* cvr */ -0, /* defc */ +1, /* cpi */ +1, /* lpi */ +1, /* chr */ +1, /* cvr */ +1, /* defc */ 0, /* swidm */ 0, /* sdrfq */ 0, /* sitm */ @@ -342,14 +342,14 @@ static short const parametrized[] = { 0, /* mcud1 */ 0, /* mcub1 */ 0, /* mcuf1 */ -0, /* mvpa */ +1, /* mvpa */ 0, /* mcuu1 */ 0, /* porder */ 0, /* mcud */ 0, /* mcub */ 0, /* mcuf */ 0, /* mcuu */ -0, /* scs */ +1, /* scs */ 0, /* smgb */ 1, /* smgbp */ 1, /* smglp */ @@ -357,20 +357,20 @@ static short const parametrized[] = { 0, /* smgt */ 1, /* smgtp */ 0, /* sbim */ -0, /* scsd */ +1, /* scsd */ 0, /* rbim */ -0, /* rcsd */ +1, /* rcsd */ 0, /* subcs */ 0, /* supcs */ 0, /* docr */ 0, /* zerom */ -0, /* csnm */ +1, /* csnm */ 0, /* kmous */ 0, /* minfo */ 0, /* reqmp */ -0, /* getm */ -0, /* setaf */ -0, /* setab */ +1, /* getm */ +1, /* setaf */ +1, /* setab */ 1, /* pfxl */ 0, /* devt */ 0, /* csin */ @@ -388,7 +388,7 @@ static short const parametrized[] = { 0, /* endbi */ 1, /* setcolor */ 1, /* slines */ -0, /* dispc */ +1, /* dispc */ 0, /* smpch */ 0, /* rmpch */ 0, /* smsc */ @@ -553,61 +553,10 @@ static short const parametrized[] = { 0, /* ksf10 */ 0, /* kf11 */ 0, /* kf12 */ -0, /* kf13 */ -0, /* kf14 */ -0, /* kf15 */ -0, /* kf16 */ -0, /* kf17 */ -0, /* kf18 */ -0, /* kf19 */ -0, /* kf20 */ -0, /* kf21 */ -0, /* kf22 */ -0, /* kf23 */ -0, /* kf24 */ -0, /* kf25 */ -0, /* kf26 */ -0, /* kf26 */ -0, /* kf28 */ -0, /* kf29 */ -0, /* kf30 */ -0, /* kf31 */ -0, /* kf31 */ -0, /* kf33 */ -0, /* kf34 */ -0, /* kf35 */ -0, /* kf36 */ -0, /* kf37 */ -0, /* kf38 */ -0, /* kf39 */ -0, /* kf40 */ -0, /* kf41 */ -0, /* kf42 */ -0, /* kf43 */ -0, /* kf44 */ -0, /* kf45 */ -0, /* kf46 */ -0, /* kf47 */ -0, /* kf48 */ -0, /* kf49 */ -0, /* kf50 */ -0, /* kf51 */ -0, /* kf52 */ -0, /* kf53 */ -0, /* kf54 */ -0, /* kf55 */ -0, /* kf56 */ -0, /* kf57 */ -0, /* kf58 */ -0, /* kf59 */ -0, /* kf60 */ -0, /* kf61 */ -0, /* kf62 */ -0, /* kf63 */ 0, /* kact */ 0, /* topl */ 0, /* btml */ 0, /* rvert */ 0, /* lvert */ -} /* 599 entries */; +} /* 548 entries */; diff --git a/lib/libcurses/resizeterm.3 b/lib/libcurses/resizeterm.3 index 5b472cd6928..7b500cc8695 100644 --- a/lib/libcurses/resizeterm.3 +++ b/lib/libcurses/resizeterm.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: resizeterm.3,v 1.4 2003/05/14 08:55:19 jmc Exp $ +.\" $OpenBSD: resizeterm.3,v 1.5 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2003,2005 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,57 +28,70 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" Author: Thomas E. Dickey <dickey@clark.net> 1996,1997 +.\" Author: Thomas E. Dickey 1996-2005 .\" -.\" $From: resizeterm.3x,v 1.7 1998/03/14 23:42:52 tom Exp $ +.\" $Id: resizeterm.3,v 1.5 2010/01/12 23:21:59 nicm Exp $ .TH resizeterm 3 "" .SH NAME +\fBis_term_resized\fR, +\fBresize_term\fR, \fBresizeterm\fR - change the curses terminal size -.. .SH SYNOPSIS \fB#include <curses.h>\fR - +.sp +\fBbool is_term_resized(int lines, int columns);\fR +.br +\fBint resize_term(int lines, int columns);\fR +.br \fBint resizeterm(int lines, int columns);\fR -.. .SH DESCRIPTION This is an extension to the curses library. -It provides callers with a hook into the \fBcurses\fR data to resize windows, +It provides callers with a hook into the \fBncurses\fR data to resize windows, primarily for use by programs running in an X Window terminal (e.g., xterm). The function \fBresizeterm\fR resizes the standard and current windows to the specified dimensions, and adjusts other bookkeeping data used by -the \fBcurses\fR library that record the window dimensions. - -When resizing the windows, the function blank-fills the areas that are -extended. The calling application should fill in these areas with -appropriate data. - -The function attempts to resize all windows. +the \fBncurses\fR library that record the window dimensions. +.LP +Most of the work is done by the inner function \fBresize_term\fR. +The outer function \fBresizeterm\fR adds bookkeeping for the SIGWINCH handler. +When resizing the windows, +\fBresize_term\fR blank-fills the areas that are extended. +The calling application should fill in these areas with appropriate data. +The \fBresize_term\fR function attempts to resize all windows. However, due to the calling convention of pads, it is not possible to resize these without additional interaction with the application. -.. +.LP +A support function \fBis_term_resized\fR is provided so that applications +can check if the \fBresize_term\fR function would modify the window structures. +It returns TRUE if the windows would be modified, and FALSE otherwise. .SH RETURN VALUE -The function returns the integer \fBERR\fR upon failure and \fBOK\fR on success. -It will fail if either of the dimensions less than or equal to zero, +Except as notes, these function return +the integer \fBERR\fR upon failure and \fBOK\fR on success. +They will fail if either of the dimensions are less than or equal to zero, or if an error occurs while (re)allocating memory for the windows. -.. .SH NOTES -While this function is intended to be used to support a signal handler -(i.e., for SIGWINCH), care should be taken to avoid invoking it in a +While these functions are intended to be used to support a signal handler +(i.e., for SIGWINCH), care should be taken to avoid invoking them in a context where \fBmalloc\fR or \fBrealloc\fR may have been interrupted, since it uses those functions. -.. .PP -If curses is configured to supply its own SIGWINCH handler, +If ncurses is configured to supply its own SIGWINCH handler, the \fBresizeterm\fR function ungetch's a \fBKEY_RESIZE\fR which will be read on the next call to \fBgetch\fR. This is used to alert an application that the screen size has changed, and that it should repaint special features such as pads that cannot be done automatically. -.. +.PP +If the environment variables \fBLINES\fP or \fBCOLUMNS\fP are set, +this overrides the library's use of the window size obtained from +the operating system. +Thus, even if a SIGWINCH is received, +no screen size change may be recorded. +In that case, no \fBKEY_RESIZE\fP is queued for the next call to \fBgetch\fP; +an \fBERR\fP will be returned instead. .SH SEE ALSO \fBwresize\fR(3). -.. .SH AUTHOR Thomas Dickey (from an equivalent function written in 1988 for BSD curses). .\"# diff --git a/lib/libcurses/shlib_version b/lib/libcurses/shlib_version index c10074d52ae..f461c533903 100644 --- a/lib/libcurses/shlib_version +++ b/lib/libcurses/shlib_version @@ -1,2 +1,2 @@ -major=10 +major=11 minor=0 diff --git a/lib/libcurses/term.5tbl b/lib/libcurses/term.5tbl index ebc5a1fef50..cebb5f4b891 100644 --- a/lib/libcurses/term.5tbl +++ b/lib/libcurses/term.5tbl @@ -1,5 +1,5 @@ .\"*************************************************************************** -.\" Copyright (c) 1998 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2004,2006 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -26,24 +26,22 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: term.5,v 1.10 2000/08/13 01:56:45 tom Exp $ -.\" $OpenBSD: term.5tbl,v 1.5 2004/11/04 15:36:47 otto Exp $ -.TH TERM 5 +.\" $Id: term.5tbl,v 1.6 2010/01/12 23:21:59 nicm Exp $ +.TH term 5 .ds n 5 -.ds d /usr/share/terminfo +.ds d /usr/share/misc/terminfo .SH NAME term \- format of compiled term file. .SH SYNOPSIS .B term .SH DESCRIPTION -.PP -NOTE: OpenBSD uses a Berkeley DB-style terminfo database instead -of the SVR4 method of one description per file described below. -.PP +.SS STORAGE LOCATION Compiled terminfo descriptions are placed under the directory \fB\*d\fP. -In order to avoid a linear search of a huge \s-1UNIX\s+1 system directory, a -two-level scheme is used: \fB\*b/c/name\fP -where +Two configurations are supported (when building the ncurses libraries): +.TP 5 +.B directory tree +A two-level scheme is used to avoid a linear search +of a huge \s-1UNIX\s+1 system directory: \fB\*d/c/name\fP where .I name is the name of the terminal, and .I c @@ -54,7 +52,23 @@ Thus, can be found in the file \fB\*d/a/act4\fP. Synonyms for the same terminal are implemented by multiple links to the same compiled file. -.PP +.TP 5 +.B hashed database +Using Berkeley database, two types of records are stored: +the terminfo data in the same format as stored in a directory tree with +the terminfo's primary name as a key, +and records containing only aliases pointing to the primary name. +.IP +If built to write hashed databases, +ncurses can still read terminfo databases organized as a directory tree, +but cannot write entries into the directory tree. +It can write (or rewrite) entries in the hashed database. +.IP +ncurses distinguishes the two cases in the TERMINFO and TERMINFO_DIRS +environment variable by assuming a directory tree for entries that +correspond to an existing directory, +and hashed database otherwise. +.SS STORAGE FORMAT The format has been chosen so that it will be the same on all hardware. An 8 or more bit byte is assumed, but no assumptions about byte ordering or sign extension are made. @@ -76,18 +90,26 @@ The header section begins the file. This section contains six short integers in the format described below. These integers are +.RS 5 +.TP 5 (1) the magic number (octal 0432); +.TP 5 (2) the size, in bytes, of the names section; +.TP 5 (3) the number of bytes in the boolean section; +.TP 5 (4) the number of short integers in the numbers section; +.TP 5 (5) the number of offsets (short integers) in the strings section; +.TP 5 (6) the size, in bytes, of the string table. +.RE .PP Short integers are stored in two 8-bit bytes. The first byte contains the least significant 8 bits of the value, and the second byte contains the most significant 8 bits. (Thus, the value represented is 256*second+first.) -The value \-1 is represented by the two bytes 0377, 0377; other negative +The value -1 is represented by the two bytes 0377, 0377; other negative values are illegal. This value generally means that the corresponding capability is missing from this terminal. Note that this format corresponds to the hardware of the \s-1VAX\s+1 @@ -116,11 +138,11 @@ All short integers are aligned on a short word boundary. The numbers section is similar to the flags section. Each capability takes up two bytes, and is stored as a little-endian short integer. -If the value represented is \-1, the capability is taken to be missing. +If the value represented is -1, the capability is taken to be missing. .PP The strings section is also similar. Each capability is stored as a short integer, in the format above. -A value of \-1 means the capability is missing. +A value of -1 means the capability is missing. Otherwise, the value is taken as an offset from the beginning of the string table. Special characters in ^X or \ec notation are stored in their @@ -132,7 +154,48 @@ The final section is the string table. It contains all the values of string capabilities referenced in the string section. Each string is null terminated. +.SS EXTENDED STORAGE FORMAT +The previous section describes the conventional terminfo binary format. +With some minor variations of the offsets (see PORTABILITY), +the same binary format is used in all modern UNIX systems. +Each system uses a predefined set of boolean, number or string capabilities. +.PP +The ncurses libraries and applications support extended terminfo binary format, +allowing users to define capabilities which are loaded at runtime. This +extension is made possible by using the fact that the other implementations +stop reading the terminfo data when they have reached the end of the size given +in the header. +ncurses checks the size, and if it exceeds that due to the predefined data, +continues to parse according to its own scheme. +.PP +First, it reads the extended header (5 short integers): +.RS 5 +.TP 5 +(1) +count of extended boolean capabilities +.TP 5 +(2) +count of extended numeric capabilities +.TP 5 +(3) +count of extended string capabilities +.TP 5 +(4) +size of the extended string table in bytes. +.TP 5 +(5) +last offset of the extended string table in bytes. +.RE .PP +Using the counts and sizes, ncurses allocates arrays and reads data +for the extended capabilties in the same order as the header information. +.PP +The extended string table contains values for string capabilities. +After the end of these values, it contains the names for each of +the extended capabilities in order, e.g., booleans, then numbers and +finally strings. +. +.SH PORTABILITY Note that it is possible for .I setupterm to expect a different set of capabilities @@ -159,7 +222,7 @@ diverged from System V terminfo after SVr1, and have added extension capabilities to the string table that (in the binary format) collide with System V and XSI Curses extensions. See \fBterminfo\fR(\*n) for detailed discussion of terminfo source compatibility issues. -.PP +.SH EXAMPLE As an example, here is a hex dump of the description for the Lear-Siegler ADM-3, a popular though rather stupid early terminal: .nf @@ -168,7 +231,7 @@ adm3a|lsi adm3a, am, cols#80, lines#24, bel=^G, clear=\032$<1>, cr=^M, cub1=^H, cud1=^J, - cuf1=^L, cup=\E=%p1%{32}%+%c%p2%{32}%+%c, cuu1=^K, + cuf1=^L, cup=\\E=%p1%{32}%+%c%p2%{32}%+%c, cuu1=^K, home=^^, ind=^J, .sp .ft CW @@ -197,13 +260,21 @@ adm3a|lsi adm3a, .ft R .fi .sp -.PP +.SH LIMITS Some limitations: total compiled entries cannot exceed 4096 bytes. The name field cannot exceed 128 bytes. .SH FILES -\*d/?/* compiled terminal capability data base -.SH "SEE ALSO" +\*d/?/* compiled terminal capability database +.SH SEE ALSO \fBcurses\fR(3), \fBterminfo\fR(\*n). +.SH AUTHORS +Thomas E. Dickey +.br +extended terminfo format for ncurses 5.0 +.br +hashed database support for ncurses 5.6 +.sp +Eric S. Raymond .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/term.7 b/lib/libcurses/term.7 index e30a1e67df6..cbe38e6d734 100644 --- a/lib/libcurses/term.7 +++ b/lib/libcurses/term.7 @@ -1,7 +1,7 @@ -.\" $OpenBSD: term.7,v 1.7 2003/05/14 08:55:19 jmc Exp $ +.\" $OpenBSD: term.7,v 1.8 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,11 +28,10 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: term.7,v 1.12 2000/08/13 01:56:42 tom Exp $ -.\" $OpenBSD: term.7,v 1.7 2003/05/14 08:55:19 jmc Exp $ -.TH TERM 7 +.\" $Id: term.7,v 1.8 2010/01/12 23:21:59 nicm Exp $ +.TH term 7 .ds n 5 -.ds d /usr/share/terminfo +.ds d /usr/share/misc/terminfo .SH NAME term \- conventions for naming terminal types .SH DESCRIPTION @@ -68,16 +67,16 @@ which you wish to override the system default type for your line. .PP Terminal type descriptions are stored as files of capability data underneath \*d. To browse a list of all terminal names recognized by the system, do - +.sp toe | more - +.sp from your shell. These capability files are in a binary format optimized for retrieval speed (unlike the old text-based \fBtermcap\fR format they replace); -to examine an entry, you must use the \fBinfocmp\fR(1) command. Invoke it as -follows: - +to examine an entry, you must use the \fBinfocmp\fR(1) command. +Invoke it as follows: +.sp infocmp \fIentry-name\fR - +.sp where \fIentry-name\fR is the name of the type you wish to examine (and the name of its capability file the subdirectory of \*d named for its first letter). This command dumps a capability file in the text format described by @@ -99,7 +98,7 @@ terminals that also explains how to parse them: First, choose a root name. The root will consist of a lower-case letter followed by up to seven lower-case letters or digits. You need to avoid using punctuation characters in root names, because they are used and interpreted as -filenames, and shell meta-characters (such as !, $, *, ?, etc.) embedded in them +filenames and shell meta-characters (such as !, $, *, ?, etc.) embedded in them may cause odd and unhelpful behavior. The slash (/), or any other character that may be interpreted by anyone's file system (\e, $, [, ]), is especially dangerous (terminfo is platform-independent, and choosing names with special @@ -122,7 +121,7 @@ i.e. \fBlinux\fR, \fBbsdos\fR, \fBfreebsd\fR, \fBnetbsd\fR. It should multi-platform environment! If a model number follows, it should indicate either the OS release level or the console driver release level. .PP -The root name for a terminal emulator (assuming it doesn't fit one of the +The root name for a terminal emulator (assuming it does not fit one of the standard ANSI or vt100 types) should be the program name or a readily recognizable abbreviation of it (i.e. \fBversaterm\fR, \fBctrm\fR). .PP @@ -197,7 +196,7 @@ tty line initialization (AT&T-like UNIXes) .TP 5 /etc/ttys tty line initialization (BSD-like UNIXes) -.SH "SEE ALSO" +.SH SEE ALSO \fBcurses\fR(3), \fBterminfo\fR(\*n), \fBterm\fR(\*n). .\"# .\"# The following sets edit modes for GNU EMACS diff --git a/lib/libcurses/term.h b/lib/libcurses/term.h index c912cfd5252..0942f33ad8f 100644 --- a/lib/libcurses/term.h +++ b/lib/libcurses/term.h @@ -1,7 +1,7 @@ -/* $OpenBSD: term.h,v 1.13 2002/02/18 22:24:32 deraadt Exp $ */ +/* $OpenBSD: term.h,v 1.14 2010/01/12 23:21:59 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,23 +31,24 @@ /****************************************************************************/ /* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 */ /* and: Eric S. Raymond <esr@snark.thyrsus.com> */ +/* and: Thomas E. Dickey 1995-on */ /****************************************************************************/ -/* $From: MKterm.h.awk.in,v 1.38 2000/12/09 23:54:00 tom Exp $ */ +/* $Id: term.h,v 1.14 2010/01/12 23:21:59 nicm Exp $ */ /* ** term.h -- Definition of struct term */ -#ifndef _NCU_TERM_H -#define _NCU_TERM_H 1 +#ifndef NCURSES_TERM_H_incl +#define NCURSES_TERM_H_incl 1 #ifdef _USE_OLD_CURSES_ #error Cannot mix ncurses term.h with old curses.h #endif #undef NCURSES_VERSION -#define NCURSES_VERSION "5.2" +#define NCURSES_VERSION "5.7" #if !defined(NCURSES_IMPEXP) # define NCURSES_IMPEXP /* nothing */ @@ -62,42 +63,20 @@ # define NCURSES_EXPORT_VAR(type) NCURSES_IMPEXP type #endif - #ifdef __cplusplus extern "C" { #endif /* Make this file self-contained by providing defaults for the HAVE_TERMIO[S]_H - * and BROKEN_LINKER definition (based on the system for which this was - * configured). + * definition (based on the system for which this was configured). */ -#ifdef __OpenBSD__ -#define BROKEN_LINKER 0 -#define TERMIOS 1 -#define NCURSES_CONST /*nothing*/ -#define NCURSES_XNAMES 1 - -#include <termios.h> -#define TTY struct termios - -#else - -#undef HAVE_TERMIOS_H -#define HAVE_TERMIOS_H 1 - -#undef HAVE_TERMIO_H -#define HAVE_TERMIO_H 0 - -#undef HAVE_TCGETATTR -#define HAVE_TCGETATTR 1 - -#undef BROKEN_LINKER -#define BROKEN_LINKER 0 - #undef NCURSES_CONST #define NCURSES_CONST /*nothing*/ +#undef NCURSES_SBOOL +#define NCURSES_SBOOL signed char + #undef NCURSES_XNAMES #define NCURSES_XNAMES 1 @@ -108,8 +87,9 @@ extern "C" { #undef SET_TTY #undef GET_TTY -/* Assume Posix termio if we have the header and function */ -#if HAVE_TERMIOS_H && HAVE_TCGETATTR +/* Assume POSIX termio if we have the header and function */ +/* #if HAVE_TERMIOS_H && HAVE_TCGETATTR */ +#if 1 && 1 #undef TERMIOS #define TERMIOS 1 @@ -119,7 +99,8 @@ extern "C" { #else /* !HAVE_TERMIOS_H */ -#if HAVE_TERMIO_H +/* #if HAVE_TERMIO_H */ +#if 0 #undef TERMIOS #define TERMIOS 1 @@ -173,8 +154,6 @@ extern "C" { #endif /* HAVE_TERMIOS_H */ -#endif /* OpenBSD */ - #ifdef TERMIOS #define GET_TTY(fd, buf) tcgetattr(fd, buf) #define SET_TTY(fd, buf) tcsetattr(fd, TCSADRAIN, buf) @@ -706,12 +685,12 @@ extern "C" { #define STRCOUNT 414 /* used by code for comparing entries */ -#define acs_chars_index 146 +#define acs_chars_index 146 typedef struct termtype { /* in-core form of terminfo data */ char *term_names; /* str_table offset of term names */ char *str_table; /* pointer to string table */ - signed char *Booleans; /* array of boolean values */ + NCURSES_SBOOL *Booleans; /* array of boolean values */ short *Numbers; /* array of integer values */ char **Strings; /* array of string offsets */ @@ -732,37 +711,40 @@ typedef struct termtype { /* in-core form of terminfo data */ typedef struct term { /* describe an actual terminal */ TERMTYPE type; /* terminal type description */ - short Filedes; /* file description being written to */ + short Filedes; /* file description being written to */ TTY Ottyb, /* original state of the terminal */ Nttyb; /* current state of the terminal */ int _baudrate; /* used to compute padding */ + char * _termname; /* used for termname() */ } TERMINAL; -extern NCURSES_EXPORT_VAR(TERMINAL *) cur_term; - -#if BROKEN_LINKER -#define boolnames _nc_boolnames() -#define boolcodes _nc_boolcodes() -#define boolfnames _nc_boolfnames() -#define numnames _nc_numnames() -#define numcodes _nc_numcodes() -#define numfnames _nc_numfnames() -#define strnames _nc_strnames() -#define strcodes _nc_strcodes() -#define strfnames _nc_strfnames() - -extern NCURSES_EXPORT(NCURSES_CONST char * const *) _nc_boolnames (void); -extern NCURSES_EXPORT(NCURSES_CONST char * const *) _nc_boolcodes (void); -extern NCURSES_EXPORT(NCURSES_CONST char * const *) _nc_boolfnames (void); -extern NCURSES_EXPORT(NCURSES_CONST char * const *) _nc_numnames (void); -extern NCURSES_EXPORT(NCURSES_CONST char * const *) _nc_numcodes (void); -extern NCURSES_EXPORT(NCURSES_CONST char * const *) _nc_numfnames (void); -extern NCURSES_EXPORT(NCURSES_CONST char * const *) _nc_strnames (void); -extern NCURSES_EXPORT(NCURSES_CONST char * const *) _nc_strcodes (void); -extern NCURSES_EXPORT(NCURSES_CONST char * const *) _nc_strfnames (void); +#if 0 || 0 +NCURSES_WRAPPED_VAR(TERMINAL *, cur_term); +NCURSES_WRAPPED_VAR(NCURSES_CONST char * const *, boolnames); +NCURSES_WRAPPED_VAR(NCURSES_CONST char * const *, boolcodes); +NCURSES_WRAPPED_VAR(NCURSES_CONST char * const *, boolfnames); +NCURSES_WRAPPED_VAR(NCURSES_CONST char * const *, numnames); +NCURSES_WRAPPED_VAR(NCURSES_CONST char * const *, numcodes); +NCURSES_WRAPPED_VAR(NCURSES_CONST char * const *, numfnames); +NCURSES_WRAPPED_VAR(NCURSES_CONST char * const *, strnames); +NCURSES_WRAPPED_VAR(NCURSES_CONST char * const *, strcodes); +NCURSES_WRAPPED_VAR(NCURSES_CONST char * const *, strfnames); + +#define cur_term NCURSES_PUBLIC_VAR(cur_term()) +#define boolnames NCURSES_PUBLIC_VAR(boolnames()) +#define boolcodes NCURSES_PUBLIC_VAR(boolcodes()) +#define boolfnames NCURSES_PUBLIC_VAR(boolfnames()) +#define numnames NCURSES_PUBLIC_VAR(numnames()) +#define numcodes NCURSES_PUBLIC_VAR(numcodes()) +#define numfnames NCURSES_PUBLIC_VAR(numfnames()) +#define strnames NCURSES_PUBLIC_VAR(strnames()) +#define strcodes NCURSES_PUBLIC_VAR(strcodes()) +#define strfnames NCURSES_PUBLIC_VAR(strfnames()) #else +extern NCURSES_EXPORT_VAR(TERMINAL *) cur_term; + extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) boolnames[]; extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) boolcodes[]; extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) boolfnames[]; @@ -780,9 +762,9 @@ extern NCURSES_EXPORT(int) _nc_set_tty_mode (TTY *buf); extern NCURSES_EXPORT(int) _nc_get_tty_mode (TTY *buf); extern NCURSES_EXPORT(int) _nc_read_entry (const char * const, char * const, TERMTYPE *const); extern NCURSES_EXPORT(int) _nc_read_file_entry (const char *const, TERMTYPE *); +extern NCURSES_EXPORT(int) _nc_read_termtype (TERMTYPE *, char *, int); extern NCURSES_EXPORT(char *) _nc_first_name (const char *const); extern NCURSES_EXPORT(int) _nc_name_match (const char *const, const char *const, const char *const); -extern NCURSES_EXPORT(int) _nc_read_termcap_entry (const char *const, TERMTYPE *const); extern NCURSES_EXPORT(const TERMTYPE *) _nc_fallback (const char *); /* entry points */ @@ -796,25 +778,32 @@ extern NCURSES_EXPORT(int) setupterm (NCURSES_CONST char *,int,int *); /* terminfo entry points, also declared in curses.h */ #if !defined(__NCURSES_H) extern NCURSES_EXPORT(char *) tigetstr (NCURSES_CONST char *); -extern NCURSES_EXPORT(char *) tparm (NCURSES_CONST char *, ...); extern NCURSES_EXPORT_VAR(char) ttytype[]; extern NCURSES_EXPORT(int) putp (const char *); extern NCURSES_EXPORT(int) tigetflag (NCURSES_CONST char *); extern NCURSES_EXPORT(int) tigetnum (NCURSES_CONST char *); + +#if 1 /* NCURSES_TPARM_VARARGS */ +extern NCURSES_EXPORT(char *) tparm (NCURSES_CONST char *, ...); /* special */ +#else +extern NCURSES_EXPORT(char *) tparm (NCURSES_CONST char *, long,long,long,long,long,long,long,long,long); /* special */ +extern NCURSES_EXPORT(char *) tparm_varargs (NCURSES_CONST char *, ...); /* special */ +#endif + #endif /* __NCURSES_H */ /* termcap database emulation (XPG4 uses const only for 2nd param of tgetent) */ -#if !defined(_NCU_TERMCAP_H) +#if !defined(NCURSES_TERMCAP_H_incl) extern NCURSES_EXPORT(char *) tgetstr (NCURSES_CONST char *, char **); extern NCURSES_EXPORT(char *) tgoto (const char *, int, int); extern NCURSES_EXPORT(int) tgetent (char *, const char *); extern NCURSES_EXPORT(int) tgetflag (NCURSES_CONST char *); extern NCURSES_EXPORT(int) tgetnum (NCURSES_CONST char *); extern NCURSES_EXPORT(int) tputs (const char *, int, int (*)(int)); -#endif /* _NCU_TERMCAP_H */ +#endif /* NCURSES_TERMCAP_H_incl */ #ifdef __cplusplus } #endif -#endif /* _NCU_TERM_H */ +#endif /* NCURSES_TERM_H_incl */ diff --git a/lib/libcurses/term_entry.h b/lib/libcurses/term_entry.h index d8d4b36c631..3cd0a59aa1c 100644 --- a/lib/libcurses/term_entry.h +++ b/lib/libcurses/term_entry.h @@ -1,7 +1,7 @@ -/* $OpenBSD: term_entry.h,v 1.11 2001/01/22 18:01:35 millert Exp $ */ +/* $OpenBSD: term_entry.h,v 1.12 2010/01/12 23:21:59 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2005,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,16 +31,17 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1998-on * ****************************************************************************/ -/* $From: term_entry.h,v 1.31 2001/01/13 22:44:41 tom Exp $ */ +/* $Id: term_entry.h,v 1.12 2010/01/12 23:21:59 nicm Exp $ */ /* * term_entry.h -- interface to entry-manipulation code */ -#ifndef _TERM_ENTRY_H -#define _TERM_ENTRY_H +#ifndef NCURSES_TERM_ENTRY_H_incl +#define NCURSES_TERM_ENTRY_H_incl 1 #ifdef __cplusplus extern "C" { @@ -53,12 +54,12 @@ extern "C" { typedef struct entry { TERMTYPE tterm; - int nuses; + unsigned nuses; struct { char *name; struct entry *link; - long line; + long line; } uses[MAX_USES]; int ncrosslinks; @@ -135,6 +136,9 @@ extern NCURSES_EXPORT(void) _nc_free_termtype (TERMTYPE *); /* lib_acs.c */ extern NCURSES_EXPORT(void) _nc_init_acs (void); /* corresponds to traditional 'init_acs()' */ +/* lib_termcap.c: trim sgr0 string for termcap users */ +extern NCURSES_EXPORT(char *) _nc_trim_sgr0 (TERMTYPE *); + /* parse_entry.c: entry-parsing code */ #if NCURSES_XNAMES extern NCURSES_EXPORT_VAR(bool) _nc_user_definable; @@ -150,9 +154,11 @@ extern NCURSES_EXPORT(void) _nc_write_entry (TERMTYPE *const); /* comp_parse.c: entry list handling */ extern NCURSES_EXPORT(void) _nc_read_entry_source (FILE*, char*, int, bool, bool (*)(ENTRY*)); extern NCURSES_EXPORT(bool) _nc_entry_match (char *, char *); -extern NCURSES_EXPORT(int) _nc_resolve_uses (bool); +extern NCURSES_EXPORT(int) _nc_resolve_uses (bool); /* obs 20040705 */ +extern NCURSES_EXPORT(int) _nc_resolve_uses2 (bool, bool); extern NCURSES_EXPORT(void) _nc_free_entries (ENTRY *); -extern NCURSES_IMPEXP void NCURSES_API (*_nc_check_termtype)(TERMTYPE *); +extern NCURSES_IMPEXP void NCURSES_API (*_nc_check_termtype)(TERMTYPE *); /* obs 20040705 */ +extern NCURSES_IMPEXP void NCURSES_API (*_nc_check_termtype2)(TERMTYPE *, bool); /* trace_xnames.c */ extern NCURSES_EXPORT(void) _nc_trace_xnames (TERMTYPE *); @@ -167,4 +173,4 @@ extern int _nc_read_bsd_terminfo_file(const char * const, TERMTYPE *const); } #endif -#endif /* _TERM_ENTRY_H */ +#endif /* NCURSES_TERM_ENTRY_H_incl */ diff --git a/lib/libcurses/termcap.3 b/lib/libcurses/termcap.3 index 294515b5bb0..ac9d2fea6db 100644 --- a/lib/libcurses/termcap.3 +++ b/lib/libcurses/termcap.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: termcap.3,v 1.7 2003/05/14 08:55:19 jmc Exp $ +.\" $OpenBSD: termcap.3,v 1.8 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998,2000 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,7 +28,7 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_termcap.3x,v 1.14 2000/12/02 22:47:14 tom Exp $ +.\" $Id: termcap.3,v 1.8 2010/01/12 23:21:59 nicm Exp $ .TH termcap 3 "" .ds n 5 .SH NAME @@ -42,7 +42,15 @@ \fB#include <curses.h>\fR .br \fB#include <term.h>\fR +.sp +\fBextern char PC;\fR .br +\fBextern char * UP;\fR +.br +\fBextern char * BC;\fR +.br +\fBextern short ospeed;\fR +.sp \fBint tgetent(char *bp, const char *name);\fR .br \fBint tgetflag(char *id);\fR @@ -61,64 +69,96 @@ the \fItermcap\fR library. Their parameters are the same and the routines are emulated using the \fIterminfo\fR database. Thus, they can only be used to query the capabilities of entries for which a terminfo entry has been compiled. - +.PP The \fBtgetent\fR routine loads the entry for \fIname\fR. It returns 1 on success, 0 if there is no such entry, and -1 if the terminfo database could not be found. The emulation ignores the buffer pointer \fIbp\fR. - +.PP The \fBtgetflag\fR routine gets the boolean entry for \fIid\fR, or zero if it is not available. - +.PP The \fBtgetnum\fR routine gets the numeric entry for \fIid\fR, or -1 if it is not available. - +.PP The \fBtgetstr\fR routine returns the string entry for \fIid\fR, or zero if it is not available. Use \fBtputs\fR to output the returned string. The return value will also be copied to the buffer pointed to by \fIarea\fR, and the \fIarea\fR value will be updated to point past the null ending this value. - +.PP Only the first two characters of the \fBid\fR parameter of \fBtgetflag\fR, \fBtgetnum\fR and \fBtgetstr\fR are compared in lookups. - +.PP The \fBtgoto\fR routine instantiates the parameters into the given capability. The output from this routine is to be passed to \fBtputs\fR. - -The \fBtputs\fR routine is described in the \fBterminfo\fR(3) manual +.PP +The \fBtputs\fR routine is described on the \fBterminfo\fR(3) manual page. It can retrieve capabilities by either termcap or terminfo name. - +.PP +The variables +\fBPC\fR, +\fBUP\fR and +\fBBC\fR +are set by \fBtgetent\fR to the terminfo entry's data for +\fBpad_char\fR, +\fBcursor_up\fR and +\fBbackspace_if_not_bs\fR, +respectively. +\fBUP\fR is not used by ncurses. +\fBPC\fR is used in the \fBtdelay_output\fR function. +\fBBC\fR is used in the \fBtgoto\fR emulation. +The variable \fBospeed\fR is set by ncurses in a system-specific coding +to reflect the terminal speed. +. .SH RETURN VALUE Except where explicitly noted, routines that return an integer return \fBERR\fR upon failure and \fBOK\fR (SVr4 only specifies "an integer value other than \fBERR\fR") upon successful completion. - +.PP Routines that return pointers return \fBNULL\fR on error. .SH BUGS If you call \fBtgetstr\fR to fetch \fBca\fR or any other parameterized string, be aware that it will be returned in terminfo notation, not the older and -not-quite-compatible termcap notation. This won't cause problems if all +not-quite-compatible termcap notation. This will not cause problems if all you do with it is call \fBtgoto\fR or \fBtparm\fR, which both expand terminfo-style strings as terminfo. (The \fBtgoto\fR function, if configured to support termcap, will check if the string is indeed terminfo-style by looking for "%p" parameters or "$<..>" delays, and invoke a termcap-style parser if the string does not appear to be terminfo). - +.PP Because terminfo conventions for representing padding in string capabilities differ from termcap's, \fBtputs("50");\fR will put out a literal "50" rather than busy-waiting for 50 milliseconds. Cope with it. +.PP +Note that termcap has nothing analogous to terminfo's \fBsgr\fR string. +One consequence of this is that termcap applications assume \fRme\fR +(terminfo \fBsgr0\fR) does not reset the alternate character set. +This implementation checks for, and modifies the data shown to the +termcap interface to accommodate termcap's limitation in this respect. .SH PORTABILITY The XSI Curses standard, Issue 4 describes these functions. However, they are marked TO BE WITHDRAWN and may be removed in future versions. - +.PP Neither the XSI Curses standard nor the SVr4 man pages documented the return values of \fBtgetent\fR correctly, though all three were in fact returned ever since SVr1. +In particular, an omission in the XSI Curses documentation has been +misinterpreted to mean that \fBtgetent\fR returns \fBOK\fR or \fBERR\fR. +Because the purpose of these functions is to provide compatibility with +the \fItermcap\fR library, that is a defect in XCurses, Issue 4, Version 2 +rather than in ncurses. +.PP +External variables are provided for support of certain termcap applications. +However, termcap applications' use of those variables is poorly documented, +e.g., not distinguishing between input and output. +In particular, some applications are reported to declare and/or +modify \fBospeed\fR. .SH SEE ALSO \fBcurses\fR(3), \fBterminfo\fR(\*n), \fBputc\fR(3). .\"# diff --git a/lib/libcurses/termcap.h b/lib/libcurses/termcap.h index f4e1a62ecd0..2020f138bf3 100644 --- a/lib/libcurses/termcap.h +++ b/lib/libcurses/termcap.h @@ -1,4 +1,4 @@ -/* $OpenBSD: termcap.h,v 1.8 2001/01/22 18:01:35 millert Exp $ */ +/* $OpenBSD: termcap.h,v 1.9 2010/01/12 23:21:59 nicm Exp $ */ /**************************************************************************** * Copyright (c) 1998,2000 Free Software Foundation, Inc. * @@ -33,13 +33,13 @@ * and: Eric S. Raymond <esr@snark.thyrsus.com> * ****************************************************************************/ -/* $From: termcap.h.in,v 1.15 2000/12/10 02:01:50 tom Exp $ */ +/* $Id: termcap.h,v 1.9 2010/01/12 23:21:59 nicm Exp $ */ -#ifndef _NCU_TERMCAP_H -#define _NCU_TERMCAP_H 1 +#ifndef NCURSES_TERMCAP_H_incl +#define NCURSES_TERMCAP_H_incl 1 #undef NCURSES_VERSION -#define NCURSES_VERSION "5.2" +#define NCURSES_VERSION "5.7" #if !defined(NCURSES_IMPEXP) # define NCURSES_IMPEXP /* nothing */ @@ -62,7 +62,7 @@ extern "C" #include <sys/types.h> #undef NCURSES_CONST -#define NCURSES_CONST +#define NCURSES_CONST /*nothing*/ #undef NCURSES_OSPEED #define NCURSES_OSPEED short @@ -72,7 +72,7 @@ extern NCURSES_EXPORT_VAR(char *) UP; extern NCURSES_EXPORT_VAR(char *) BC; extern NCURSES_EXPORT_VAR(NCURSES_OSPEED) ospeed; -#if !defined(_NCU_TERM_H) +#if !defined(NCURSES_TERM_H_incl) extern NCURSES_EXPORT(char *) tgetstr (NCURSES_CONST char *, char **); extern NCURSES_EXPORT(char *) tgoto (const char *, int, int); extern NCURSES_EXPORT(int) tgetent (char *, const char *); @@ -85,4 +85,4 @@ extern NCURSES_EXPORT(int) tputs (const char *, int, int (*)(int)); } #endif -#endif /* _NCU_TERMCAP_H */ +#endif /* NCURSES_TERMCAP_H_incl */ diff --git a/lib/libcurses/terminfo.3 b/lib/libcurses/terminfo.3 index 6abb958638a..c2471742827 100644 --- a/lib/libcurses/terminfo.3 +++ b/lib/libcurses/terminfo.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: terminfo.3,v 1.9 2003/05/14 08:55:19 jmc Exp $ +.\" $OpenBSD: terminfo.3,v 1.10 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1999,2000 Free Software Foundation, Inc. * +.\" Copyright (c) 1999-2007,2008 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,90 +28,110 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_terminfo.3x,v 1.14 2000/12/03 00:07:23 tom Exp $ +.\" $Id: terminfo.3,v 1.10 2010/01/12 23:21:59 nicm Exp $ .TH terminfo 3 "" .ds n 5 +.na +.hy 0 .SH NAME -\fBsetupterm\fR, -\fBsetterm\fR, -\fBset_curterm\fR, \fBdel_curterm\fR, +\fBmvcur\fR, +\fBputp\fR, \fBrestartterm\fR, +\fBset_curterm\fR, +\fBsetterm\fR, +\fBsetupterm\fR, +\fBtigetflag\fR, +\fBtigetnum\fR, +\fBtigetstr\fR, \fBtparm\fR, \fBtputs\fR, -\fBputp\fR, -\fBvidputs\fR, +\fBvid_attr\fR, +\fBvid_puts\fR, \fBvidattr\fR, -\fBmvcur\fR, -\fBtigetflag\fR, -\fBtigetnum\fR, -\fBtigetstr\fR - \fBcurses\fR interfaces to terminfo database +\fBvidputs\fR - \fBcurses\fR interfaces to terminfo database +.ad +.hy .SH SYNOPSIS +.nf \fB#include <curses.h>\fR .br \fB#include <term.h>\fR - -\fBint setupterm(const char *term, int fildes, int *errret);\fR +.PP +\fBint setupterm(char *\fR\fIterm\fR\fB, int \fR\fIfildes\fR\fB, int *\fR\fIerrret\fR\fB);\fR +.br +\fBint setterm(char *\fR\fIterm\fR\fB);\fR .br -\fBint setterm(const char *term);\fR +\fBTERMINAL *set_curterm(TERMINAL *\fR\fInterm\fR\fB);\fR .br -\fBTERMINAL *set_curterm(TERMINAL *nterm);\fR +\fBint del_curterm(TERMINAL *\fR\fIoterm\fR\fB);\fR .br -\fBint del_curterm(TERMINAL *oterm);\fR +\fBint restartterm(char *\fR\fIterm\fR\fB, int \fR\fIfildes\fR\fB, int *\fR\fIerrret\fR\fB);\fR .br -\fBint restartterm(const char *term, int fildes, int *errret);\fR +\fBchar *tparm(char *\fR\fIstr\fR\fB, ...);\fR .br -\fBchar *tparm(const char *str, ...);\fR +\fBint tputs(const char *\fR\fIstr\fR\fB, int \fR\fIaffcnt\fR\fB, int (*\fR\fIputc\fR\fB)(int));\fR .br -\fBint tputs(const char *str, int affcnt, int (*putc)(int));\fR +\fBint putp(const char *\fR\fIstr\fR\fB);\fR .br -\fBint putp(const char *str);\fR +\fBint vidputs(chtype \fR\fIattrs\fR\fB, int (*\fR\fIputc\fR\fB)(int));\fR .br -\fBint vidputs(chtype attrs, int (*putc)(char));\fR +\fBint vidattr(chtype \fR\fIattrs\fR\fB);\fR .br -\fBint vidattr(chtype attrs);\fR +\fBint vid_puts(attr_t \fR\fIattrs\fR\fB, short \fR\fIpair\fR\fB, void *\fR\fIopts\fR\fB, int (*\fR\fIputc\fR\fB)(char));\fR .br -\fBint mvcur(int oldrow, int oldcol, int newrow, int newcol);\fR +\fBint vid_attr(attr_t \fR\fIattrs\fR\fB, short \fR\fIpair\fR\fB, void *\fR\fIopts\fR\fB);\fR .br -\fBint tigetflag(const char *capname);\fR +\fBint mvcur(int \fR\fIoldrow\fR\fB, int \fR\fIoldcol\fR\fB, int \fR\fInewrow\fR, int \fR\fInewcol\fR\fB);\fR .br -\fBint tigetnum(const char *capname);\fR +\fBint tigetflag(char *\fR\fIcapname\fR\fB);\fR .br -\fBchar *tigetstr(const char *capname);\fR +\fBint tigetnum(char *\fR\fIcapname\fR\fB);\fR .br +\fBchar *tigetstr(char *\fR\fIcapname\fR\fB);\fR +.br +.fi .SH DESCRIPTION These low-level routines must be called by programs that have to deal directly with the \fBterminfo\fR database to handle certain terminal capabilities, such as programming function keys. For all other functionality, \fBcurses\fR routines are more suitable and their use is recommended. - +.PP Initially, \fBsetupterm\fR should be called. Note that \fBsetupterm\fR is automatically called by \fBinitscr\fR and \fBnewterm\fR. This defines the set of terminal-dependent variables -[listed in \fBterminfo\fR(\*n)]. The \fBterminfo\fR variables +[listed in \fBterminfo\fR(\*n)]. +The \fBterminfo\fR variables \fBlines\fR and \fBcolumns\fR are initialized by \fBsetupterm\fR as -follows: If \fBuse_env(FALSE)\fR has been called, values for +follows: +.RS +.PP +If \fBuse_env(FALSE)\fR has been called, values for \fBlines\fR and \fBcolumns\fR specified in \fBterminfo\fR are used. +.PP Otherwise, if the environment variables \fBLINES\fR and \fBCOLUMNS\fR exist, their values are used. If these environment variables do not exist and the program is running in a window, the current window size is used. Otherwise, if the environment variables do not exist, the values for \fBlines\fR and \fBcolumns\fR specified in the \fBterminfo\fR database are used. - +.RE +.PP The header files \fBcurses.h\fR and \fBterm.h\fR should be included (in this order) to get the definitions for these strings, numbers, and flags. -Parameterized strings should be passed through \fBtparm\fR to instantiate them. +Parameterized strings should be passed through \fBtparm\fR to instantiate them. All \fBterminfo\fR strings [including the output of \fBtparm\fR] should be printed with \fBtputs\fR or \fBputp\fR. Call the \fBreset_shell_mode\fR to restore the tty modes before exiting [see \fBcurs_kernel\fR(3)]. Programs which use cursor addressing should output \fBenter_ca_mode\fR upon startup and should output \fBexit_ca_mode\fR before exiting. Programs desiring shell escapes -should call \fBreset_shell_mode\fR and output \fBexit_ca_mode\fR before the -shell is called and should output \fBenter_ca_mode\fR and call +should call +.PP +\fBreset_shell_mode\fR and output \fBexit_ca_mode\fR before the shell +is called and should output \fBenter_ca_mode\fR and call \fBreset_prog_mode\fR after returning from the shell. - +.PP The \fBsetupterm\fR routine reads in the \fBterminfo\fR database, initializing the \fBterminfo\fR structures, but does not set up the output virtualization structures used by \fBcurses\fR. The terminal @@ -142,88 +162,102 @@ means that the \fBterminfo\fR database could not be found. If \fIerrret\fR is null, \fBsetupterm\fR prints an error message upon finding an error and exits. Thus, the simplest call is: - +.sp \fBsetupterm((char *)0, 1, (int *)0);\fR, - +.sp which uses all the defaults and sends the output to \fBstdout\fR. - +.PP The \fBsetterm\fR routine is being replaced by \fBsetupterm\fR. The call: - +.sp \fBsetupterm(\fR\fIterm\fR\fB, 1, (int *)0)\fR - +.sp provides the same functionality as \fBsetterm(\fR\fIterm\fR\fB)\fR. The \fBsetterm\fR routine is included here for BSD compatibility, and is not recommended for new programs. - +.PP The \fBset_curterm\fR routine sets the variable \fBcur_term\fR to \fInterm\fR, and makes all of the \fBterminfo\fR boolean, numeric, and string variables use the values from \fInterm\fR. It returns the old value of \fBcur_term\fR. - +.PP The \fBdel_curterm\fR routine frees the space pointed to by \fIoterm\fR and makes it available for further use. If \fIoterm\fR is the same as \fBcur_term\fR, references to any of the \fBterminfo\fR boolean, numeric, and string variables thereafter may refer to invalid memory locations until another \fBsetupterm\fR has been called. - +.PP The \fBrestartterm\fR routine is similar to \fBsetupterm\fR and \fBinitscr\fR, except that it is called after restoring memory to a previous state (for example, when reloading a game saved as a core image dump). It assumes that the windows and the input and output options are the same as when memory was saved, but the terminal type and baud rate may be different. Accordingly, -it saves various tty state bits, does a setupterm, and then restores the bits. - +it saves various tty state bits, calls \fBsetupterm\fP, +and then restores the bits. +.PP The \fBtparm\fR routine instantiates the string \fIstr\fR with parameters \fIpi\fR. A pointer is returned to the result of \fIstr\fR with the parameters applied. - +.PP The \fBtputs\fR routine applies padding information to the string \fIstr\fR and outputs it. The \fIstr\fR must be a terminfo string variable or the return value from \fBtparm\fR, \fBtgetstr\fR, or \fBtgoto\fR. \fIaffcnt\fR is the number of lines affected, or 1 if not applicable. \fIputc\fR is a \fBputchar\fR-like routine to which the characters are passed, one at a time. - +.PP The \fBputp\fR routine calls \fBtputs(\fR\fIstr\fR\fB, 1, putchar)\fR. Note that the output of \fBputp\fR always goes to \fBstdout\fR, not to the \fIfildes\fR specified in \fBsetupterm\fR. - +.PP The \fBvidputs\fR routine displays the string on the terminal in the video attribute mode \fIattrs\fR, which is any combination of the attributes listed in \fBcurses\fR(3). The characters are passed to the \fBputchar\fR-like routine \fIputc\fR. - +.PP The \fBvidattr\fR routine is like the \fBvidputs\fR routine, except that it outputs through \fBputchar\fR. - +.PP +The \fBvid_attr\fR and \fBvid_puts\fR routines correspond to vidattr and vidputs, +respectively. +They use a set of arguments for representing the video attributes plus color, +i.e., +one of type attr_t for the attributes and one of short for +the color_pair number. +The \fBvid_attr\fR and \fBvid_puts\fR routines +are designed to use the attribute constants with the \fIWA_\fR prefix. +The opts argument is reserved for future use. +Currently, applications must provide a null pointer for that argument. +.PP The \fBmvcur\fR routine provides low-level cursor motion. It takes effect immediately (rather than at the next refresh). - +.PP The \fBtigetflag\fR, \fBtigetnum\fR and \fBtigetstr\fR routines return the value of the capability corresponding to the \fBterminfo\fR \fIcapname\fR passed to them, such as \fBxenl\fR. - +.PP The \fBtigetflag\fR routine returns the value \fB-1\fR if \fIcapname\fR is not a boolean capability, or \fB0\fR if it is canceled or absent from the terminal description. - +.PP The \fBtigetnum\fR routine returns the value \fB-2\fR if \fIcapname\fR is not a numeric capability, or \fB-1\fR if it is canceled or absent from the terminal description. - +.PP The \fBtigetstr\fR routine returns the value \fB(char *)-1\fR if \fIcapname\fR is not a string capability, or \fB0\fR if it is canceled or absent from the terminal description. - +.PP The \fIcapname\fR for each capability is given in the table column entitled \fIcapname\fR code in the capabilities section of \fBterminfo\fR(\*n). - -\fBchar *boolnames\fR, \fB*boolcodes\fR, \fB*boolfnames\fR - -\fBchar *numnames\fR, \fB*numcodes\fR, \fB*numfnames\fR - -\fBchar *strnames\fR, \fB*strcodes\fR, \fB*strfnames\fR - +.sp +.RS +\fBchar *boolnames[]\fR, \fB*boolcodes[]\fR, \fB*boolfnames[]\fR +.sp +\fBchar *numnames[]\fR, \fB*numcodes[]\fR, \fB*numfnames[]\fR +.sp +\fBchar *strnames[]\fR, \fB*strcodes[]\fR, \fB*strfnames[]\fR +.RE +.PP These null-terminated arrays contain the \fIcapnames\fR, the \fBtermcap\fR codes, and the full C names, for each of the \fBterminfo\fR variables. @@ -231,43 +265,87 @@ These null-terminated arrays contain the \fIcapnames\fR, the Routines that return an integer return \fBERR\fR upon failure and \fBOK\fR (SVr4 only specifies "an integer value other than \fBERR\fR") upon successful completion, unless otherwise noted in the preceding routine descriptions. - +.PP Routines that return pointers always return \fBNULL\fR on error. +.PP +X/Open defines no error conditions. +In this implementation +.RS +.TP 5 +\fBdel_curterm\fP +returns an error +if its terminal parameter is null. +.TP 5 +\fBputp\fP +calls \fBtputs\fP, returning the same error-codes. +.TP 5 +\fBrestartterm\fP +returns an error +if the associated call to \fBsetupterm\fP returns an error. +.TP 5 +\fBsetupterm\fP +returns an error +if it cannot allocate enough memory, or +create the initial windows (stdscr, curscr, newscr). +Other error conditions are documented above. +.TP 5 +\fBtputs\fP +returns an error if the string parameter is null. +It does not detect I/O errors: +X/Open states that \fBtputs\fP ignores the return value +of the output function \fIputc\fP. +.RE .SH NOTES The \fBsetupterm\fR routine should be used in place of \fBsetterm\fR. It may be useful when you want to test for terminal capabilities without committing to the allocation of storage involved in \fBinitscr\fR. - +.PP Note that \fBvidattr\fR and \fBvidputs\fR may be macros. .SH PORTABILITY -The function \fBsetterm\fR is not described in the XSI Curses standard and must -be considered non-portable. All other functions are as described in the XSI -curses standard. - +The function \fBsetterm\fR is not described by X/Open and must +be considered non-portable. All other functions are as described by X/Open. +.PP +\fBsetupterm\fP copies the terminal name to the array \fBttytype\fP. +This is not part of X/Open Curses, but is assumed by some applications. +.PP In System V Release 4, \fBset_curterm\fR has an \fBint\fR return type and -returns \fBOK\fR or \fBERR\fR. We have chosen to implement the XSI Curses +returns \fBOK\fR or \fBERR\fR. We have chosen to implement the X/Open Curses semantics. - +.PP In System V Release 4, the third argument of \fBtputs\fR has the type \fBint (*putc)(char)\fR. - -The XSI Curses standard prototypes \fBtparm\fR with a fixed number of parameters, +.PP +At least one implementation of X/Open Curses (Solaris) returns a value +other than OK/ERR from \fBtputs\fP. +That returns the length of the string, and does no error-checking. +.PP +X/Open Curses prototypes \fBtparm\fR with a fixed number of parameters, rather than a variable argument list. -That prototype assumes that none of the parameters are strings -(or if so, that a long is big enough to hold a pointer). -The variable argument list implemented in ncurses does not rely on -that assumption. - -XSI notes that after calling \fBmvcur\fR, the curses state may not match the +This implementation uses a variable argument list. +Portable applications should provide 9 parameters after the format; +zeroes are fine for this purpose. +.PP +X/Open notes that after calling \fBmvcur\fR, the curses state may not match the actual terminal state, and that an application should touch and refresh the window before resuming normal curses calls. Both ncurses and System V Release 4 curses implement \fBmvcur\fR using the SCREEN data allocated in either \fBinitscr\fR or \fBnewterm\fR. So though it is documented as a terminfo function, \fBmvcur\fR is really a curses function which is not well specified. +.PP +X/Open states that the old location must be given for \fBmvcur\fP. +This implementation allows the caller to use -1's for the old ordinates. +In that case, the old location is unknown. +.PP +Extended terminal capability names, e.g., as defined by \fBtic\ -x\fP, +are not stored in the arrays described in this section. .SH SEE ALSO -\fBcurses\fR(3), \fBcurs_initscr\fR(3), \fBcurs_kernel\fR(3), \fBtermcap\fR(3), -\fBputc\fR(3), \fBterminfo\fR(\*n) +\fBcurses\fR(3), +\fBcurs_initscr\fR(3), +\fBcurs_kernel\fR(3), +\fBputc\fR(3), +\fBtermcap\fR(3), +\fBterminfo\fR(\*n) .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/terminfo.5tbl b/lib/libcurses/terminfo.5tbl index f3b446ad18c..87a3e37bbb2 100644 --- a/lib/libcurses/terminfo.5tbl +++ b/lib/libcurses/terminfo.5tbl @@ -5,7 +5,7 @@ .\" Note: this must be run through tbl before nroff. .\" The magic cookie on the first line triggers this under some man programs. .\"*************************************************************************** -.\" Copyright (c) 1998 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2004,2006 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -32,21 +32,18 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: terminfo.head,v 1.9 2000/08/13 01:56:40 tom Exp $ -.\" $OpenBSD: terminfo.5tbl,v 1.12 2004/11/04 15:36:47 otto Exp $ -.TH TERMINFO 5 "" "" "File Formats" +.\" $Id: terminfo.5tbl,v 1.13 2010/01/12 23:21:59 nicm Exp $ +.TH terminfo 5 "" "" "File Formats" .ds n 5 .ds d /usr/share/misc/terminfo .SH NAME -terminfo \- terminal capability data base +terminfo \- terminal capability database .SH SYNOPSIS -\*d.db -.br -/usr/share/terminfo/?/* +\*d/*/* .SH DESCRIPTION .I Terminfo is a data base describing terminals, used by screen-oriented programs such as -\fBvi\fR(1), +\fBnvi\fR(1), \fBrogue\fR(1) and libraries such as \fBcurses\fR(3). @@ -54,11 +51,13 @@ and libraries such as describes terminals by giving a set of capabilities which they have, by specifying how to perform screen operations, and by specifying padding requirements and initialization sequences. +This describes \fBncurses\fR +version 5.7. .PP Entries in .I terminfo consist of a sequence of `,' separated fields (embedded commas may be -escaped with a backslash or notated as \e072). +escaped with a backslash or notated as \\054). White space after the `,' separator is ignored. The first entry for each terminal gives the names which are known for the terminal, separated by `|' characters. @@ -68,6 +67,16 @@ and all others are understood as synonyms for the terminal name. All names but the last should be in lower case and contain no blanks; the last name may well contain upper case and blanks for readability. .PP +Lines beginning with a `#' in the first column are treated as comments. +While comment lines are legal at any point, the output of \fBcaptoinfo\fP +and \fBinfotocap\fP (aliases for \fBtic\fP) +will move comments so they occur only between entries. +.PP +Newlines and leading tabs may be used for formatting entries for readability. +These are removed from parsed entries. +The \fBinfocmp\ -f\fP option relies on this to format if-then-else expressions: +the result can be read by \fB@tic\fP. +.PP Terminal names (except for the last, verbose entry) should be chosen using the following conventions. The particular piece of hardware making up the terminal should @@ -164,16 +173,16 @@ T} back_color_erase bce ut T{ screen erased with background color T} -can_change ccc cc T{ +can_change ccc cc T{ terminal can re-define existing colors T} ceol_standout_glitch xhp xs T{ standout not erased by overwriting (hp) T} -col_addr_glitch xhpa YA T{ +col_addr_glitch xhpa YA T{ only positive motion for hpa/mhpa caps T} -cpi_changes_res cpix YF T{ +cpi_changes_res cpix YF T{ changing character pitch changes resolution T} cr_cancels_micro_mode crxm YB T{ @@ -188,22 +197,22 @@ T} erase_overstrike eo eo T{ can erase overstrikes with a blank T} -generic_type gn gn T{ +generic_type gn gn T{ generic line type T} -hard_copy hc hc T{ +hard_copy hc hc T{ hardcopy terminal T} -hard_cursor chts HC T{ +hard_cursor chts HC T{ cursor is hard to see T} -has_meta_key km km T{ -Has a meta key (shift, sets parity bit) +has_meta_key km km T{ +Has a meta key (i.e., sets 8th-bit) T} -has_print_wheel daisy YC T{ +has_print_wheel daisy YC T{ printer needs operator to change character set T} -has_status_line hs hs T{ +has_status_line hs hs T{ has extra status line T} hue_lightness_saturation hls hl T{ @@ -212,13 +221,13 @@ T} insert_null_glitch in in T{ insert mode distinguishes nulls T} -lpi_changes_res lpix YG T{ +lpi_changes_res lpix YG T{ changing line pitch changes resolution T} -memory_above da da T{ +memory_above da da T{ display may be retained above the screen T} -memory_below db db T{ +memory_below db db T{ display may be retained below the screen T} move_insert_mode mir mi T{ @@ -227,28 +236,28 @@ T} move_standout_mode msgr ms T{ safe to move while in standout mode T} -needs_xon_xoff nxon nx T{ -padding won't work, xon/xoff required +needs_xon_xoff nxon nx T{ +padding will not work, xon/xoff required T} -no_esc_ctlc xsb xb T{ +no_esc_ctlc xsb xb T{ beehive (f1=escape, f2=ctrl C) T} -no_pad_char npc NP T{ +no_pad_char npc NP T{ pad character does not exist T} non_dest_scroll_region ndscr ND T{ scrolling region is non-destructive T} -non_rev_rmcup nrrmc NR T{ +non_rev_rmcup nrrmc NR T{ smcup does not reverse rmcup T} -over_strike os os T{ +over_strike os os T{ terminal can overstrike T} -prtr_silent mc5i 5i T{ -printer won't echo on screen +prtr_silent mc5i 5i T{ +printer will not echo on screen T} -row_addr_glitch xvpa YD T{ +row_addr_glitch xvpa YD T{ only positive motion for vpa/mvpa caps T} semi_auto_right_margin sam YE T{ @@ -257,13 +266,13 @@ T} status_line_esc_ok eslok es T{ escape can be used on the status line T} -tilde_glitch hz hz T{ -can't print ~'s (hazeltine) +tilde_glitch hz hz T{ +cannot print ~'s (hazeltine) T} transparent_underline ul ul T{ underline character overstrikes T} -xon_xoff xon xo T{ +xon_xoff xon xo T{ terminal uses xon/xoff handshaking T} .TE @@ -279,43 +288,43 @@ c l l c lw25 lw6 lw2 lw20. \fBVariable Cap- TCap Description\fR \fBNumeric name Code\fR -columns cols co T{ +columns cols co T{ number of columns in a line T} -init_tabs it it T{ +init_tabs it it T{ tabs initially every # spaces T} -label_height lh lh T{ +label_height lh lh T{ rows in each label T} -label_width lw lw T{ +label_width lw lw T{ columns in each label T} -lines lines li T{ +lines lines li T{ number of lines on screen or page T} -lines_of_memory lm lm T{ +lines_of_memory lm lm T{ lines of memory if > line. 0 means varies T} magic_cookie_glitch xmc sg T{ number of blank characters left by smso or rmso T} -max_attributes ma ma T{ +max_attributes ma ma T{ maximum combined attributes terminal can handle T} -max_colors colors Co T{ +max_colors colors Co T{ maximum number of colors on screen T} -max_pairs pairs pa T{ +max_pairs pairs pa T{ maximum number of color-pairs on the screen T} -maximum_windows wnum MW T{ +maximum_windows wnum MW T{ maximum number of defineable windows T} -no_color_video ncv NC T{ -video attributes that can't be used with colors +no_color_video ncv NC T{ +video attributes that cannot be used with colors T} -num_labels nlab Nl T{ +num_labels nlab Nl T{ number of labels on screen T} padding_baud_rate pb pb T{ @@ -345,13 +354,13 @@ lw25 lw6 lw2 lw20. bit_image_entwining bitwin Yo T{ number of passes for each bit-image row T} -bit_image_type bitype Yp T{ +bit_image_type bitype Yp T{ type of bit-image device T} -buffer_capacity bufsz Ya T{ +buffer_capacity bufsz Ya T{ numbers of bytes buffered before printing T} -buttons btns BT T{ +buttons btns BT T{ number of buttons on mouse T} dot_horz_spacing spinh Yc T{ @@ -363,34 +372,34 @@ T} max_micro_address maddr Yd T{ maximum value in micro_..._address T} -max_micro_jump mjump Ye T{ +max_micro_jump mjump Ye T{ maximum value in parm_..._micro T} -micro_col_size mcs Yf T{ +micro_col_size mcs Yf T{ character step size when in micro mode T} -micro_line_size mls Yg T{ +micro_line_size mls Yg T{ line step size when in micro mode T} -number_of_pins npins Yh T{ +number_of_pins npins Yh T{ numbers of pins in print-head T} -output_res_char orc Yi T{ +output_res_char orc Yi T{ horizontal resolution in units per line T} output_res_horz_inch orhi Yk T{ horizontal resolution in units per inch T} -output_res_line orl Yj T{ +output_res_line orl Yj T{ vertical resolution in units per line T} output_res_vert_inch orvi Yl T{ vertical resolution in units per inch T} -print_rate cps Ym T{ +print_rate cps Ym T{ print rate in characters per second T} -wide_char_size widcs Yn T{ +wide_char_size widcs Yn T{ character step size when in double wide mode T} .TE @@ -406,139 +415,139 @@ c l l c lw25 lw6 lw2 lw20. \fBVariable Cap- TCap Description\fR \fBString name Code\fR -acs_chars acsc ac T{ +acs_chars acsc ac T{ graphics charset pairs, based on vt100 T} -back_tab cbt bt T{ +back_tab cbt bt T{ back tab (P) T} -bell bel bl T{ +bell bel bl T{ audible signal (bell) (P) T} -carriage_return cr cr T{ +carriage_return cr cr T{ carriage return (P*) (P*) T} change_char_pitch cpi ZA T{ -Change number of characters per inch +Change number of characters per inch to #1 T} change_line_pitch lpi ZB T{ -Change number of lines per inch +Change number of lines per inch to #1 T} -change_res_horz chr ZC T{ -Change horizontal resolution +change_res_horz chr ZC T{ +Change horizontal resolution to #1 T} -change_res_vert cvr ZD T{ -Change vertical resolution +change_res_vert cvr ZD T{ +Change vertical resolution to #1 T} change_scroll_region csr cs T{ change region to line #1 to line #2 (P) T} -char_padding rmp rP T{ +char_padding rmp rP T{ like ip but when in insert mode T} -clear_all_tabs tbc ct T{ +clear_all_tabs tbc ct T{ clear all tab stops (P) T} -clear_margins mgc MC T{ +clear_margins mgc MC T{ clear right and left soft margins T} -clear_screen clear cl T{ +clear_screen clear cl T{ clear screen and home cursor (P*) T} -clr_bol el1 cb T{ +clr_bol el1 cb T{ Clear to beginning of line T} -clr_eol el ce T{ +clr_eol el ce T{ clear to end of line (P) T} -clr_eos ed cd T{ +clr_eos ed cd T{ clear to end of screen (P*) T} -column_address hpa ch T{ +column_address hpa ch T{ horizontal position #1, absolute (P) T} command_character cmdch CC T{ terminal settable cmd character in prototype !? T} -create_window cwin CW T{ +create_window cwin CW T{ define a window #1 from #2,#3 to #4,#5 T} -cursor_address cup cm T{ +cursor_address cup cm T{ move to row #1 columns #2 T} -cursor_down cud1 do T{ +cursor_down cud1 do T{ down one line T} -cursor_home home ho T{ +cursor_home home ho T{ home cursor (if no cup) T} cursor_invisible civis vi T{ make cursor invisible T} -cursor_left cub1 le T{ +cursor_left cub1 le T{ move left one space T} cursor_mem_address mrcup CM T{ -memory relative cursor addressing +memory relative cursor addressing, move to row #1 columns #2 T} -cursor_normal cnorm ve T{ +cursor_normal cnorm ve T{ make cursor appear normal (undo civis/cvvis) T} -cursor_right cuf1 nd T{ +cursor_right cuf1 nd T{ non-destructive space (move right one space) T} -cursor_to_ll ll ll T{ +cursor_to_ll ll ll T{ last line, first column (if no cup) T} -cursor_up cuu1 up T{ +cursor_up cuu1 up T{ up one line T} -cursor_visible cvvis vs T{ +cursor_visible cvvis vs T{ make cursor very visible T} -define_char defc ZE T{ -Define a character +define_char defc ZE T{ +Define a character #1, #2 dots wide, descender #3 T} delete_character dch1 dc T{ delete character (P*) T} -delete_line dl1 dl T{ +delete_line dl1 dl T{ delete line (P*) T} -dial_phone dial DI T{ +dial_phone dial DI T{ dial number #1 T} -dis_status_line dsl ds T{ +dis_status_line dsl ds T{ disable status line T} -display_clock dclk DK T{ -display clock at (#1,#2) +display_clock dclk DK T{ +display clock T} -down_half_line hd hd T{ +down_half_line hd hd T{ half a line down T} -ena_acs enacs eA T{ +ena_acs enacs eA T{ enable alternate char set T} enter_alt_charset_mode smacs as T{ start alternate character set (P) T} -enter_am_mode smam SA T{ +enter_am_mode smam SA T{ turn on automatic margins T} enter_blink_mode blink mb T{ turn on blinking T} -enter_bold_mode bold md T{ +enter_bold_mode bold md T{ turn on bold (extra bright) mode T} -enter_ca_mode smcup ti T{ +enter_ca_mode smcup ti T{ string to start programs using cup T} enter_delete_mode smdc dm T{ enter delete mode T} -enter_dim_mode dim mh T{ +enter_dim_mode dim mh T{ turn on half-bright mode T} enter_doublewide_mode swidm ZF T{ @@ -592,22 +601,22 @@ T} enter_upward_mode sum ZP T{ Start upward carriage motion T} -enter_xon_mode smxon SX T{ +enter_xon_mode smxon SX T{ turn on xon/xoff handshaking T} -erase_chars ech ec T{ +erase_chars ech ec T{ erase #1 characters (P) T} exit_alt_charset_mode rmacs ae T{ end alternate character set (P) T} -exit_am_mode rmam RA T{ +exit_am_mode rmam RA T{ turn off automatic margins T} exit_attribute_mode sgr0 me T{ turn off all attributes T} -exit_ca_mode rmcup te T{ +exit_ca_mode rmcup te T{ strings to end programs using cup T} exit_delete_mode rmdc ed T{ @@ -625,7 +634,7 @@ T} exit_leftward_mode rlm ZS T{ End left-motion mode T} -exit_micro_mode rmicm ZT T{ +exit_micro_mode rmicm ZT T{ End micro-motion mode T} exit_shadow_mode rshm ZU T{ @@ -646,595 +655,595 @@ T} exit_upward_mode rum ZX T{ End reverse character motion T} -exit_xon_mode rmxon RX T{ +exit_xon_mode rmxon RX T{ turn off xon/xoff handshaking T} -fixed_pause pause PA T{ +fixed_pause pause PA T{ pause for 2-3 seconds T} -flash_hook hook fh T{ +flash_hook hook fh T{ flash switch hook T} -flash_screen flash vb T{ +flash_screen flash vb T{ visible bell (may not move cursor) T} -form_feed ff ff T{ +form_feed ff ff T{ hardcopy terminal page eject (P*) T} from_status_line fsl fs T{ return from status line T} -goto_window wingo WG T{ +goto_window wingo WG T{ go to window #1 T} -hangup hup HU T{ +hangup hup HU T{ hang-up phone T} -init_1string is1 i1 T{ +init_1string is1 i1 T{ initialization string T} -init_2string is2 is T{ +init_2string is2 is T{ initialization string T} -init_3string is3 i3 T{ +init_3string is3 i3 T{ initialization string T} -init_file if if T{ +init_file if if T{ name of initialization file T} -init_prog iprog iP T{ +init_prog iprog iP T{ path name of program for initialization T} initialize_color initc Ic T{ initialize color #1 to (#2,#3,#4) T} -initialize_pair initp Ip T{ +initialize_pair initp Ip T{ Initialize color pair #1 to fg=(#2,#3,#4), bg=(#5,#6,#7) T} insert_character ich1 ic T{ insert character (P) T} -insert_line il1 al T{ +insert_line il1 al T{ insert line (P*) T} -insert_padding ip ip T{ +insert_padding ip ip T{ insert padding after inserted character T} -key_a1 ka1 K1 T{ +key_a1 ka1 K1 T{ upper left of keypad T} -key_a3 ka3 K3 T{ +key_a3 ka3 K3 T{ upper right of keypad T} -key_b2 kb2 K2 T{ +key_b2 kb2 K2 T{ center of keypad T} -key_backspace kbs kb T{ +key_backspace kbs kb T{ backspace key T} -key_beg kbeg @1 T{ +key_beg kbeg @1 T{ begin key T} -key_btab kcbt kB T{ +key_btab kcbt kB T{ back-tab key T} -key_c1 kc1 K4 T{ +key_c1 kc1 K4 T{ lower left of keypad T} -key_c3 kc3 K5 T{ +key_c3 kc3 K5 T{ lower right of keypad T} -key_cancel kcan @2 T{ +key_cancel kcan @2 T{ cancel key T} -key_catab ktbc ka T{ +key_catab ktbc ka T{ clear-all-tabs key T} -key_clear kclr kC T{ +key_clear kclr kC T{ clear-screen or erase key T} -key_close kclo @3 T{ +key_close kclo @3 T{ close key T} -key_command kcmd @4 T{ +key_command kcmd @4 T{ command key T} -key_copy kcpy @5 T{ +key_copy kcpy @5 T{ copy key T} -key_create kcrt @6 T{ +key_create kcrt @6 T{ create key T} -key_ctab kctab kt T{ +key_ctab kctab kt T{ clear-tab key T} -key_dc kdch1 kD T{ +key_dc kdch1 kD T{ delete-character key T} -key_dl kdl1 kL T{ +key_dl kdl1 kL T{ delete-line key T} -key_down kcud1 kd T{ +key_down kcud1 kd T{ down-arrow key T} -key_eic krmir kM T{ +key_eic krmir kM T{ sent by rmir or smir in insert mode T} -key_end kend @7 T{ +key_end kend @7 T{ end key T} -key_enter kent @8 T{ +key_enter kent @8 T{ enter/send key T} -key_eol kel kE T{ +key_eol kel kE T{ clear-to-end-of-line key T} -key_eos ked kS T{ +key_eos ked kS T{ clear-to-end-of-screen key T} -key_exit kext @9 T{ +key_exit kext @9 T{ exit key T} -key_f0 kf0 k0 T{ +key_f0 kf0 k0 T{ F0 function key T} -key_f1 kf1 k1 T{ +key_f1 kf1 k1 T{ F1 function key T} -key_f10 kf10 k; T{ +key_f10 kf10 k; T{ F10 function key T} -key_f11 kf11 F1 T{ +key_f11 kf11 F1 T{ F11 function key T} -key_f12 kf12 F2 T{ +key_f12 kf12 F2 T{ F12 function key T} -key_f13 kf13 F3 T{ +key_f13 kf13 F3 T{ F13 function key T} -key_f14 kf14 F4 T{ +key_f14 kf14 F4 T{ F14 function key T} -key_f15 kf15 F5 T{ +key_f15 kf15 F5 T{ F15 function key T} -key_f16 kf16 F6 T{ +key_f16 kf16 F6 T{ F16 function key T} -key_f17 kf17 F7 T{ +key_f17 kf17 F7 T{ F17 function key T} -key_f18 kf18 F8 T{ +key_f18 kf18 F8 T{ F18 function key T} -key_f19 kf19 F9 T{ +key_f19 kf19 F9 T{ F19 function key T} -key_f2 kf2 k2 T{ +key_f2 kf2 k2 T{ F2 function key T} -key_f20 kf20 FA T{ +key_f20 kf20 FA T{ F20 function key T} -key_f21 kf21 FB T{ +key_f21 kf21 FB T{ F21 function key T} -key_f22 kf22 FC T{ +key_f22 kf22 FC T{ F22 function key T} -key_f23 kf23 FD T{ +key_f23 kf23 FD T{ F23 function key T} -key_f24 kf24 FE T{ +key_f24 kf24 FE T{ F24 function key T} -key_f25 kf25 FF T{ +key_f25 kf25 FF T{ F25 function key T} -key_f26 kf26 FG T{ +key_f26 kf26 FG T{ F26 function key T} -key_f27 kf27 FH T{ +key_f27 kf27 FH T{ F27 function key T} -key_f28 kf28 FI T{ +key_f28 kf28 FI T{ F28 function key T} -key_f29 kf29 FJ T{ +key_f29 kf29 FJ T{ F29 function key T} -key_f3 kf3 k3 T{ +key_f3 kf3 k3 T{ F3 function key T} -key_f30 kf30 FK T{ +key_f30 kf30 FK T{ F30 function key T} -key_f31 kf31 FL T{ +key_f31 kf31 FL T{ F31 function key T} -key_f32 kf32 FM T{ +key_f32 kf32 FM T{ F32 function key T} -key_f33 kf33 FN T{ +key_f33 kf33 FN T{ F33 function key T} -key_f34 kf34 FO T{ +key_f34 kf34 FO T{ F34 function key T} -key_f35 kf35 FP T{ +key_f35 kf35 FP T{ F35 function key T} -key_f36 kf36 FQ T{ +key_f36 kf36 FQ T{ F36 function key T} -key_f37 kf37 FR T{ +key_f37 kf37 FR T{ F37 function key T} -key_f38 kf38 FS T{ +key_f38 kf38 FS T{ F38 function key T} -key_f39 kf39 FT T{ +key_f39 kf39 FT T{ F39 function key T} -key_f4 kf4 k4 T{ +key_f4 kf4 k4 T{ F4 function key T} -key_f40 kf40 FU T{ +key_f40 kf40 FU T{ F40 function key T} -key_f41 kf41 FV T{ +key_f41 kf41 FV T{ F41 function key T} -key_f42 kf42 FW T{ +key_f42 kf42 FW T{ F42 function key T} -key_f43 kf43 FX T{ +key_f43 kf43 FX T{ F43 function key T} -key_f44 kf44 FY T{ +key_f44 kf44 FY T{ F44 function key T} -key_f45 kf45 FZ T{ +key_f45 kf45 FZ T{ F45 function key T} -key_f46 kf46 Fa T{ +key_f46 kf46 Fa T{ F46 function key T} -key_f47 kf47 Fb T{ +key_f47 kf47 Fb T{ F47 function key T} -key_f48 kf48 Fc T{ +key_f48 kf48 Fc T{ F48 function key T} -key_f49 kf49 Fd T{ +key_f49 kf49 Fd T{ F49 function key T} -key_f5 kf5 k5 T{ +key_f5 kf5 k5 T{ F5 function key T} -key_f50 kf50 Fe T{ +key_f50 kf50 Fe T{ F50 function key T} -key_f51 kf51 Ff T{ +key_f51 kf51 Ff T{ F51 function key T} -key_f52 kf52 Fg T{ +key_f52 kf52 Fg T{ F52 function key T} -key_f53 kf53 Fh T{ +key_f53 kf53 Fh T{ F53 function key T} -key_f54 kf54 Fi T{ +key_f54 kf54 Fi T{ F54 function key T} -key_f55 kf55 Fj T{ +key_f55 kf55 Fj T{ F55 function key T} -key_f56 kf56 Fk T{ +key_f56 kf56 Fk T{ F56 function key T} -key_f57 kf57 Fl T{ +key_f57 kf57 Fl T{ F57 function key T} -key_f58 kf58 Fm T{ +key_f58 kf58 Fm T{ F58 function key T} -key_f59 kf59 Fn T{ +key_f59 kf59 Fn T{ F59 function key T} -key_f6 kf6 k6 T{ +key_f6 kf6 k6 T{ F6 function key T} -key_f60 kf60 Fo T{ +key_f60 kf60 Fo T{ F60 function key T} -key_f61 kf61 Fp T{ +key_f61 kf61 Fp T{ F61 function key T} -key_f62 kf62 Fq T{ +key_f62 kf62 Fq T{ F62 function key T} -key_f63 kf63 Fr T{ +key_f63 kf63 Fr T{ F63 function key T} -key_f7 kf7 k7 T{ +key_f7 kf7 k7 T{ F7 function key T} -key_f8 kf8 k8 T{ +key_f8 kf8 k8 T{ F8 function key T} -key_f9 kf9 k9 T{ +key_f9 kf9 k9 T{ F9 function key T} -key_find kfnd @0 T{ +key_find kfnd @0 T{ find key T} -key_help khlp %1 T{ +key_help khlp %1 T{ help key T} -key_home khome kh T{ +key_home khome kh T{ home key T} -key_ic kich1 kI T{ +key_ic kich1 kI T{ insert-character key T} -key_il kil1 kA T{ +key_il kil1 kA T{ insert-line key T} -key_left kcub1 kl T{ +key_left kcub1 kl T{ left-arrow key T} -key_ll kll kH T{ +key_ll kll kH T{ lower-left key (home down) T} -key_mark kmrk %2 T{ +key_mark kmrk %2 T{ mark key T} -key_message kmsg %3 T{ +key_message kmsg %3 T{ message key T} -key_move kmov %4 T{ +key_move kmov %4 T{ move key T} -key_next knxt %5 T{ +key_next knxt %5 T{ next key T} -key_npage knp kN T{ +key_npage knp kN T{ next-page key T} -key_open kopn %6 T{ +key_open kopn %6 T{ open key T} -key_options kopt %7 T{ +key_options kopt %7 T{ options key T} -key_ppage kpp kP T{ +key_ppage kpp kP T{ previous-page key T} -key_previous kprv %8 T{ +key_previous kprv %8 T{ previous key T} -key_print kprt %9 T{ +key_print kprt %9 T{ print key T} -key_redo krdo %0 T{ +key_redo krdo %0 T{ redo key T} -key_reference kref &1 T{ +key_reference kref &1 T{ reference key T} -key_refresh krfr &2 T{ +key_refresh krfr &2 T{ refresh key T} -key_replace krpl &3 T{ +key_replace krpl &3 T{ replace key T} -key_restart krst &4 T{ +key_restart krst &4 T{ restart key T} -key_resume kres &5 T{ +key_resume kres &5 T{ resume key T} -key_right kcuf1 kr T{ +key_right kcuf1 kr T{ right-arrow key T} -key_save ksav &6 T{ +key_save ksav &6 T{ save key T} -key_sbeg kBEG &9 T{ +key_sbeg kBEG &9 T{ shifted begin key T} -key_scancel kCAN &0 T{ +key_scancel kCAN &0 T{ shifted cancel key T} -key_scommand kCMD *1 T{ +key_scommand kCMD *1 T{ shifted command key T} -key_scopy kCPY *2 T{ +key_scopy kCPY *2 T{ shifted copy key T} -key_screate kCRT *3 T{ +key_screate kCRT *3 T{ shifted create key T} -key_sdc kDC *4 T{ +key_sdc kDC *4 T{ shifted delete-character key T} -key_sdl kDL *5 T{ +key_sdl kDL *5 T{ shifted delete-line key T} -key_select kslt *6 T{ +key_select kslt *6 T{ select key T} -key_send kEND *7 T{ +key_send kEND *7 T{ shifted end key T} -key_seol kEOL *8 T{ +key_seol kEOL *8 T{ shifted clear-to-end-of-line key T} -key_sexit kEXT *9 T{ +key_sexit kEXT *9 T{ shifted exit key T} -key_sf kind kF T{ +key_sf kind kF T{ scroll-forward key T} -key_sfind kFND *0 T{ +key_sfind kFND *0 T{ shifted find key T} -key_shelp kHLP #1 T{ +key_shelp kHLP #1 T{ shifted help key T} -key_shome kHOM #2 T{ +key_shome kHOM #2 T{ shifted home key T} -key_sic kIC #3 T{ +key_sic kIC #3 T{ shifted insert-character key T} -key_sleft kLFT #4 T{ +key_sleft kLFT #4 T{ shifted left-arrow key T} -key_smessage kMSG %a T{ +key_smessage kMSG %a T{ shifted message key T} -key_smove kMOV %b T{ +key_smove kMOV %b T{ shifted move key T} -key_snext kNXT %c T{ +key_snext kNXT %c T{ shifted next key T} -key_soptions kOPT %d T{ +key_soptions kOPT %d T{ shifted options key T} -key_sprevious kPRV %e T{ +key_sprevious kPRV %e T{ shifted previous key T} -key_sprint kPRT %f T{ +key_sprint kPRT %f T{ shifted print key T} -key_sr kri kR T{ +key_sr kri kR T{ scroll-backward key T} -key_sredo kRDO %g T{ +key_sredo kRDO %g T{ shifted redo key T} -key_sreplace kRPL %h T{ +key_sreplace kRPL %h T{ shifted replace key T} -key_sright kRIT %i T{ +key_sright kRIT %i T{ shifted right-arrow key T} -key_srsume kRES %j T{ +key_srsume kRES %j T{ shifted resume key T} -key_ssave kSAV !1 T{ +key_ssave kSAV !1 T{ shifted save key T} -key_ssuspend kSPD !2 T{ +key_ssuspend kSPD !2 T{ shifted suspend key T} -key_stab khts kT T{ +key_stab khts kT T{ set-tab key T} -key_sundo kUND !3 T{ +key_sundo kUND !3 T{ shifted undo key T} -key_suspend kspd &7 T{ +key_suspend kspd &7 T{ suspend key T} -key_undo kund &8 T{ +key_undo kund &8 T{ undo key T} -key_up kcuu1 ku T{ +key_up kcuu1 ku T{ up-arrow key T} -keypad_local rmkx ke T{ +keypad_local rmkx ke T{ leave 'keyboard_transmit' mode T} -keypad_xmit smkx ks T{ +keypad_xmit smkx ks T{ enter 'keyboard_transmit' mode T} -lab_f0 lf0 l0 T{ +lab_f0 lf0 l0 T{ label on function key f0 if not f0 T} -lab_f1 lf1 l1 T{ +lab_f1 lf1 l1 T{ label on function key f1 if not f1 T} -lab_f10 lf10 la T{ +lab_f10 lf10 la T{ label on function key f10 if not f10 T} -lab_f2 lf2 l2 T{ +lab_f2 lf2 l2 T{ label on function key f2 if not f2 T} -lab_f3 lf3 l3 T{ +lab_f3 lf3 l3 T{ label on function key f3 if not f3 T} -lab_f4 lf4 l4 T{ +lab_f4 lf4 l4 T{ label on function key f4 if not f4 T} -lab_f5 lf5 l5 T{ +lab_f5 lf5 l5 T{ label on function key f5 if not f5 T} -lab_f6 lf6 l6 T{ +lab_f6 lf6 l6 T{ label on function key f6 if not f6 T} -lab_f7 lf7 l7 T{ +lab_f7 lf7 l7 T{ label on function key f7 if not f7 T} -lab_f8 lf8 l8 T{ +lab_f8 lf8 l8 T{ label on function key f8 if not f8 T} -lab_f9 lf9 l9 T{ +lab_f9 lf9 l9 T{ label on function key f9 if not f9 T} -label_format fln Lf T{ +label_format fln Lf T{ label format T} -label_off rmln LF T{ +label_off rmln LF T{ turn off soft labels T} -label_on smln LO T{ +label_on smln LO T{ turn on soft labels T} -meta_off rmm mo T{ +meta_off rmm mo T{ turn off meta mode T} -meta_on smm mm T{ +meta_on smm mm T{ turn on meta mode (8th-bit on) T} micro_column_address mhpa ZY T{ Like column_address in micro mode T} -micro_down mcud1 ZZ T{ +micro_down mcud1 ZZ T{ Like cursor_down in micro mode T} -micro_left mcub1 Za T{ +micro_left mcub1 Za T{ Like cursor_left in micro mode T} -micro_right mcuf1 Zb T{ +micro_right mcuf1 Zb T{ Like cursor_right in micro mode T} micro_row_address mvpa Zc T{ -Like row_address in micro mode +Like row_address #1 in micro mode T} -micro_up mcuu1 Zd T{ +micro_up mcuu1 Zd T{ Like cursor_up in micro mode T} -newline nel nw T{ +newline nel nw T{ newline (behave like cr followed by lf) T} -order_of_pins porder Ze T{ +order_of_pins porder Ze T{ Match software bits to print-head pins T} -orig_colors oc oc T{ +orig_colors oc oc T{ Set all color pairs to the original ones T} -orig_pair op op T{ +orig_pair op op T{ Set default pair to its original value T} -pad_char pad pc T{ +pad_char pad pc T{ padding char (instead of null) T} -parm_dch dch DC T{ +parm_dch dch DC T{ delete #1 characters (P*) T} parm_delete_line dl DL T{ @@ -1243,13 +1252,13 @@ T} parm_down_cursor cud DO T{ down #1 lines (P*) T} -parm_down_micro mcud Zf T{ +parm_down_micro mcud Zf T{ Like parm_down_cursor in micro mode T} -parm_ich ich IC T{ +parm_ich ich IC T{ insert #1 characters (P*) T} -parm_index indn SF T{ +parm_index indn SF T{ scroll forward #1 lines (P) T} parm_insert_line il AL T{ @@ -1258,7 +1267,7 @@ T} parm_left_cursor cub LE T{ move #1 characters to the left (P) T} -parm_left_micro mcub Zg T{ +parm_left_micro mcub Zg T{ Like parm_left_cursor in micro mode T} parm_right_cursor cuf RI T{ @@ -1267,110 +1276,110 @@ T} parm_right_micro mcuf Zh T{ Like parm_right_cursor in micro mode T} -parm_rindex rin SR T{ +parm_rindex rin SR T{ scroll back #1 lines (P) T} -parm_up_cursor cuu UP T{ +parm_up_cursor cuu UP T{ up #1 lines (P*) T} -parm_up_micro mcuu Zi T{ +parm_up_micro mcuu Zi T{ Like parm_up_cursor in micro mode T} -pkey_key pfkey pk T{ +pkey_key pfkey pk T{ program function key #1 to type string #2 T} -pkey_local pfloc pl T{ +pkey_local pfloc pl T{ program function key #1 to execute string #2 T} -pkey_xmit pfx px T{ +pkey_xmit pfx px T{ program function key #1 to transmit string #2 T} -plab_norm pln pn T{ +plab_norm pln pn T{ program label #1 to show string #2 T} -print_screen mc0 ps T{ +print_screen mc0 ps T{ print contents of screen T} -prtr_non mc5p pO T{ +prtr_non mc5p pO T{ turn on printer for #1 bytes T} -prtr_off mc4 pf T{ +prtr_off mc4 pf T{ turn off printer T} -prtr_on mc5 po T{ +prtr_on mc5 po T{ turn on printer T} -pulse pulse PU T{ +pulse pulse PU T{ select pulse dialing T} -quick_dial qdial QD T{ +quick_dial qdial QD T{ dial number #1 without checking T} -remove_clock rmclk RC T{ +remove_clock rmclk RC T{ remove clock T} -repeat_char rep rp T{ +repeat_char rep rp T{ repeat char #1 #2 times (P*) T} -req_for_input rfi RF T{ +req_for_input rfi RF T{ send next input char (for ptys) T} -reset_1string rs1 r1 T{ +reset_1string rs1 r1 T{ reset string T} -reset_2string rs2 r2 T{ +reset_2string rs2 r2 T{ reset string T} -reset_3string rs3 r3 T{ +reset_3string rs3 r3 T{ reset string T} -reset_file rf rf T{ +reset_file rf rf T{ name of reset file T} -restore_cursor rc rc T{ +restore_cursor rc rc T{ restore cursor to position of last save_cursor T} -row_address vpa cv T{ +row_address vpa cv T{ vertical position #1 absolute (P) T} -save_cursor sc sc T{ +save_cursor sc sc T{ save current cursor position (P) T} -scroll_forward ind sf T{ +scroll_forward ind sf T{ scroll text up (P) T} -scroll_reverse ri sr T{ +scroll_reverse ri sr T{ scroll text down (P) T} -select_char_set scs Zj T{ -Select character set +select_char_set scs Zj T{ +Select character set, #1 T} -set_attributes sgr sa T{ +set_attributes sgr sa T{ define video attributes #1-#9 (PG9) T} -set_background setb Sb T{ +set_background setb Sb T{ Set background color #1 T} set_bottom_margin smgb Zk T{ Set bottom margin at current line T} set_bottom_margin_parm smgbp Zl T{ -Set bottom margin at line #1 or #2 lines from bottom +Set bottom margin at line #1 or (if smgtp is not given) #2 lines from bottom T} -set_clock sclk SC T{ +set_clock sclk SC T{ set clock, #1 hrs #2 mins #3 secs T} -set_color_pair scp sp T{ +set_color_pair scp sp T{ Set current color pair to #1 T} -set_foreground setf Sf T{ +set_foreground setf Sf T{ Set foreground color #1 T} -set_left_margin smgl ML T{ -set left soft margin at current column +set_left_margin smgl ML T{ +set left soft margin at current column. See smgl. (ML is not in BSD termcap). T} set_left_margin_parm smglp Zm T{ -Set left (right) margin at column #1 (#2) +Set left (right) margin at column #1 T} set_right_margin smgr MR T{ set right soft margin at current column @@ -1378,29 +1387,29 @@ T} set_right_margin_parm smgrp Zn T{ Set right margin at column #1 T} -set_tab hts st T{ +set_tab hts st T{ set a tab in every row, current columns T} -set_top_margin smgt Zo T{ +set_top_margin smgt Zo T{ Set top margin at current line T} set_top_margin_parm smgtp Zp T{ -Set top (bottom) margin at row #1 (#2) +Set top (bottom) margin at row #1 T} -set_window wind wi T{ +set_window wind wi T{ current window is lines #1-#2 cols #3-#4 T} -start_bit_image sbim Zq T{ +start_bit_image sbim Zq T{ Start printing bit image graphics T} start_char_set_def scsd Zr T{ -Start character set definition +Start character set definition #1, with #2 characters in the set T} -stop_bit_image rbim Zs T{ +stop_bit_image rbim Zs T{ Stop printing bit image graphics T} stop_char_set_def rcsd Zt T{ -End definition of character set +End definition of character set #1 T} subscript_characters subcs Zu T{ List of subscriptable characters @@ -1408,64 +1417,64 @@ T} superscript_characters supcs Zv T{ List of superscriptable characters T} -tab ht ta T{ +tab ht ta T{ tab to next 8-space hardware tab stop T} -these_cause_cr docr Zw T{ +these_cause_cr docr Zw T{ Printing any of these characters causes CR T} -to_status_line tsl ts T{ -move to status line +to_status_line tsl ts T{ +move to status line, column #1 T} -tone tone TO T{ +tone tone TO T{ select touch tone dialing T} -underline_char uc uc T{ +underline_char uc uc T{ underline char and move past it T} -up_half_line hu hu T{ +up_half_line hu hu T{ half a line up T} -user0 u0 u0 T{ +user0 u0 u0 T{ User string #0 T} -user1 u1 u1 T{ +user1 u1 u1 T{ User string #1 T} -user2 u2 u2 T{ +user2 u2 u2 T{ User string #2 T} -user3 u3 u3 T{ +user3 u3 u3 T{ User string #3 T} -user4 u4 u4 T{ +user4 u4 u4 T{ User string #4 T} -user5 u5 u5 T{ +user5 u5 u5 T{ User string #5 T} -user6 u6 u6 T{ +user6 u6 u6 T{ User string #6 T} -user7 u7 u7 T{ +user7 u7 u7 T{ User string #7 T} -user8 u8 u8 T{ +user8 u8 u8 T{ User string #8 T} -user9 u9 u9 T{ +user9 u9 u9 T{ User string #9 T} -wait_tone wait WA T{ +wait_tone wait WA T{ wait for dial-tone T} -xoff_character xoffc XF T{ +xoff_character xoffc XF T{ XOFF character T} -xon_character xonc XN T{ +xon_character xonc XN T{ XON character T} -zero_motion zerom Zx T{ +zero_motion zerom Zx T{ No motion for subsequent character T} .TE @@ -1494,23 +1503,23 @@ T} bit_image_repeat birep Xy T{ Repeat bit image cell #1 #2 times T} -char_set_names csnm Zy T{ -List of character set names +char_set_names csnm Zy T{ +Produce #1'th item from list of character set names T} -code_set_init csin ci T{ +code_set_init csin ci T{ Init sequence for multiple codesets T} -color_names colornm Yw T{ +color_names colornm Yw T{ Give name for color #1 T} define_bit_image_region defbi Yx T{ Define rectangualar bit image region T} -device_type devt dv T{ +device_type devt dv T{ Indicate language/codeset support T} -display_pc_char dispc S1 T{ -Display PC character +display_pc_char dispc S1 T{ +Display PC character #1 T} end_bit_image_region endbi Yy T{ End a bit-image region @@ -1527,55 +1536,55 @@ T} exit_scancode_mode rmsc S5 T{ Exit PC scancode mode T} -get_mouse getm Gm T{ -Curses should get button events +get_mouse getm Gm T{ +Curses should get button events, parameter #1 not documented. T} -key_mouse kmous Km T{ +key_mouse kmous Km T{ Mouse event has occurred T} -mouse_info minfo Mi T{ +mouse_info minfo Mi T{ Mouse status information T} -pc_term_options pctrm S6 T{ +pc_term_options pctrm S6 T{ PC terminal options T} -pkey_plab pfxl xl T{ +pkey_plab pfxl xl T{ Program function key #1 to type string #2 and show string #3 T} -req_mouse_pos reqmp RQ T{ +req_mouse_pos reqmp RQ T{ Request mouse position T} -scancode_escape scesc S7 T{ +scancode_escape scesc S7 T{ Escape for scancode emulation T} -set0_des_seq s0ds s0 T{ -Shift to code set 0 (EUC set 0, ASCII) +set0_des_seq s0ds s0 T{ +Shift to codeset 0 (EUC set 0, ASCII) T} -set1_des_seq s1ds s1 T{ -Shift to code set 1 +set1_des_seq s1ds s1 T{ +Shift to codeset 1 T} -set2_des_seq s2ds s2 T{ -Shift to code set 2 +set2_des_seq s2ds s2 T{ +Shift to codeset 2 T} -set3_des_seq s3ds s3 T{ -Shift to code set 3 +set3_des_seq s3ds s3 T{ +Shift to codeset 3 T} set_a_background setab AB T{ -Set background color using ANSI escape +Set background color to #1, using ANSI escape T} set_a_foreground setaf AF T{ -Set foreground color using ANSI escape +Set foreground color to #1, using ANSI escape T} -set_color_band setcolor Yz T{ +set_color_band setcolor Yz T{ Change to ribbon color #1 T} -set_lr_margin smglr ML T{ -Set both left and right margins to #1, #2 +set_lr_margin smglr ML T{ +Set both left and right margins to #1, #2. (ML is not in BSD termcap). T} -set_page_length slines YZ T{ +set_page_length slines YZ T{ Set page length to #1 lines T} -set_tb_margin smgtb MT T{ +set_tb_margin smgtb MT T{ Sets both top and bottom margins to #1, #2 T} .TE @@ -1618,17 +1627,19 @@ T} set_a_attributes sgr1 sA T{ Define second set of video attributes #1-#6 T} -set_pglen_inch slength sL T{ +set_pglen_inch slength sL T{ YI Set page length to #1 hundredth of an inch T} .TE .ad -.\" $From: terminfo.tail,v 1.33 2000/10/14 14:06:50 tom Exp $ +.\" $Id: terminfo.5tbl,v 1.13 2010/01/12 23:21:59 nicm Exp $ .\" Beginning of terminfo.tail file +.\" This file is part of ncurses. +.\" See "terminfo.head" for copyright. .ps +1 -.PP +. .SS A Sample Entry -.PP +. The following entry, describing an ANSI-standard terminal, is representative of what a \fBterminfo\fR entry for a modern terminal typically looks like. .PP @@ -1674,7 +1685,8 @@ terminal operations. .PP .SS Types of Capabilities .PP -All capabilities have names. For instance, the fact that +All capabilities have names. +For instance, the fact that ANSI-standard terminals have .I "automatic margins" (i.e., an automatic return and line-feed @@ -1691,7 +1703,8 @@ sequence) are given by the two-character code, an `=', and then a string ending at the next following `,'. .PP A number of escape sequences are provided in the string valued capabilities -for easy encoding of characters there. Both \fB\eE\fR and \fB\ee\fR +for easy encoding of characters there. +Both \fB\eE\fR and \fB\ee\fR map to an \s-1ESCAPE\s0 character, \fB^x\fR maps to a control-x for any appropriate x, and the sequences \fB\en \el \er \et \eb \ef \es\fR give @@ -1702,21 +1715,26 @@ Other escapes include \fB\e^\fR for \fB^\fR, \fB\e:\fR for \fB:\fR, and \fB\e0\fR for null. (\fB\e0\fR will produce \e200, which does not terminate a string but behaves -as a null character on most terminals, providing CS7 is specified. See stty(1).) +as a null character on most terminals, providing CS7 is specified. +See stty(1).) Finally, characters may be given as three octal digits after a \fB\e\fR. .PP A delay in milliseconds may appear anywhere in a string capability, enclosed in $<..> brackets, as in \fBel\fP=\eEK$<5>, and padding characters are supplied by .I tputs -to provide this delay. The delay must be a number with at most one decimal -place of precision; it may be followed by suffixes `*' or '/' or both. A `*' +to provide this delay. +The delay must be a number with at most one decimal +place of precision; it may be followed by suffixes `*' or '/' or both. +A `*' indicates that the padding required is proportional to the number of lines affected by the operation, and the amount given is the per-affected-unit -padding required. (In the case of insert character, the factor is still the +padding required. +(In the case of insert character, the factor is still the number of .IR lines affected.) Normally, padding is advisory if the device has the \fBxon\fR -capability; it is used for cost computation but does not trigger delays. A `/' +capability; it is used for cost computation but does not trigger delays. +A `/' suffix indicates that the padding is mandatory and forces a delay of the given number of milliseconds even on devices for which \fBxon\fR is present to indicate flow control. @@ -1732,7 +1750,8 @@ in the example above. .SS Fetching Compiled Descriptions .PP If the environment variable TERMINFO is set, it is interpreted as the pathname -of a directory containing the compiled description you are working on. Only +of a directory containing the compiled description you are working on. +Only that directory is searched. .PP If TERMINFO is not set, the \fBncurses\fR version of the terminfo reader code @@ -1741,7 +1760,8 @@ for a compiled description. If it fails to find one there, and the environment variable TERMINFO_DIRS is set, it will interpret the contents of that variable as a list of colon- separated directories to be searched (an empty entry is interpreted as a -command to search \fI\*d\fR). If no description is found in any of the +command to search \fI\*d\fR). +If no description is found in any of the TERMINFO_DIRS directories, the fetch fails. .PP If neither TERMINFO nor TERMINFO_DIRS is set, the last place tried will be the @@ -1776,7 +1796,8 @@ A similar test can be used for insert character. .SS Basic Capabilities .PP The number of columns on each line for the terminal is given by the -\fBcols\fR numeric capability. If the terminal is a \s-1CRT\s0, then the +\fBcols\fR numeric capability. +If the terminal is a \s-1CRT\s0, then the number of lines on the screen is given by the \fBlines\fR capability. If the terminal wraps around to the beginning of the next line when it reaches the right margin, then it should have the \fBam\fR capability. @@ -1886,22 +1907,22 @@ Thus the model 33 teletype is described as .DT .nf .ft CW -.in -7 - \s-133\||\|tty33\||\|tty\||\|model 33 teletype, +.\".in -2 +\s-133\||\|tty33\||\|tty\||\|model 33 teletype, bel=^G, cols#72, cr=^M, cud1=^J, hc, ind=^J, os,\s+1 -.in +7 +.\".in +2 .ft R .PP -while the Lear Siegler \s-1ADM\-3\s0 is described as +while the Lear Siegler \s-1ADM-3\s0 is described as .PP .DT .nf .ft CW -.in -7 - \s-1adm3\||\|3\||\|lsi adm3, +.\".in -2 +\s-1adm3\||\|3\||\|lsi adm3, am, bel=^G, clear=^Z, cols#80, cr=^M, cub1=^H, cud1=^J, ind=^J, lines#24,\s+1 -.in +7 +.\".in +2 .ft R .fi .PP @@ -1910,7 +1931,7 @@ while the Lear Siegler \s-1ADM\-3\s0 is described as Cursor addressing and other strings requiring parameters in the terminal are described by a parameterized string capability, with -.IR printf (3 +.IR printf (3) like escapes \fB%x\fR in it. For example, to address the cursor, the .B cup @@ -1923,51 +1944,107 @@ that can be indicated by .BR mrcup . .PP The parameter mechanism uses a stack and special \fB%\fP codes -to manipulate it. Typically a sequence will push one of the +to manipulate it. +Typically a sequence will push one of the parameters onto the stack and then print it in some format. -Often more complex operations are necessary. +Print (e.g., "%d") is a special case. +Other operations, including "%t" pop their operand from the stack. +It is noted that more complex operations are often necessary, +e.g., in the \fBsgr\fP string. .PP The \fB%\fR encodings have the following meanings: .PP -.DT -.nf -.ta .5i 1.5i - \s-1%% outputs `%' - %\fI[[\fP:\fI]flags][width[.precision]][\fPdoxXs\fI]\fP - as in \fBprintf\fP, flags are [-+#] and space - %c print pop() like %c in printf() - %s print pop() like %s in printf() - - %p[1-9] push \fIi\fP'th parm - %P[a-z] set dynamic variable [a-z] to pop() - %g[a-z] get dynamic variable [a-z] and push it - %P[A-Z] set static variable [a-z] to pop() - %g[A-Z] get static variable [a-z] and push it - %'\fIc\fP' char constant \fIc\fP - %{\fInn\fP} integer constant \fInn\fP - %l push strlen(pop) - - %+ %- %* %/ %m - arithmetic (%m is mod): push(pop() op pop()) - %& %| %^ bit operations: push(pop() op pop()) - %= %> %< logical operations: push(pop() op pop()) - %A, %O logical and & or operations (for conditionals) - %! %~ unary operations push(op pop()) - %i add 1 to first two parameters (for ANSI terminals) - - %? expr %t thenpart %e elsepart %; - if-then-else, %e elsepart is optional. - else-if's are possible a la Algol 68: - %? c\d1\u %t b\d1\u %e c\d2\u %t b\d2\u %e c\d3\u %t b\d3\u %e c\d4\u %t b\d4\u %e %; -\s+1 c\di\u are conditions, b\di\u are bodies. -.fi +.TP 5 +\s-1%% +outputs `%' +.TP +%\fI[[\fP:\fI]flags][width[.precision]][\fPdoxXs\fI]\fP +as in \fBprintf\fP, flags are [-+#] and space. +Use a `:' to allow the next character to be a `-' flag, +avoiding interpreting "%-" as an operator. +.TP +%c +print pop() like %c in \fBprintf\fP +.TP +%s +print pop() like %s in \fBprintf\fP +.TP +%p[1-9] +push \fIi\fP'th parameter +.TP +%P[a-z] +set dynamic variable [a-z] to pop() +.TP +%g[a-z] +get dynamic variable [a-z] and push it +.TP +%P[A-Z] +set static variable [a-z] to pop() +.TP +%g[A-Z] +get static variable [a-z] and push it +.IP +The terms "static" and "dynamic" are misleading. +Historically, these are simply two different sets of variables, +whose values are not reset between calls to \fBtparm\fP. +However, that fact is not documented in other implementations. +Relying on it will adversely impact portability to other implementations. +.TP +%'\fIc\fP' +char constant \fIc\fP +.TP +%{\fInn\fP} +integer constant \fInn\fP +.TP +%l +push strlen(pop) +.TP +%+ %- %* %/ %m +arithmetic (%m is mod): push(pop() op pop()) +.TP +%& %| %^ +bit operations (AND, OR and exclusive-OR): push(pop() op pop()) +.TP +%= %> %< +logical operations: push(pop() op pop()) +.TP +%A, %O +logical AND and OR operations (for conditionals) +.TP +%! %~ +unary operations (logical and bit complement): push(op pop()) +.TP +%i +add 1 to first two parameters (for ANSI terminals) +.TP +%? \fIexpr\fP %t \fIthenpart\fP %e \fIelsepart\fP %; +This forms an if-then-else. +The %e \fIelsepart\fP is optional. +Usually the %? \fIexpr\fP part pushes a value onto the stack, +and %t pops it from the stack, testing if it is nonzero (true). +If it is zero (false), control passes to the %e (else) part. +.IP +It is possible to form else-if's a la Algol 68: +.RS +%? c\d1\u %t b\d1\u %e c\d2\u %t b\d2\u %e c\d3\u %t b\d3\u %e c\d4\u %t b\d4\u %e %; +.RE +.IP +where c\di\u are conditions, b\di\u are bodies. +.IP +Use the \fB-f\fP option of \fBtic\fP or \fBinfocmp\fP to see +the structure of if-the-else's. +Some strings, e.g., \fBsgr\fP can be very complicated when written +on one line. +The \fB-f\fP option splits the string into lines with the parts indented. .PP Binary operations are in postfix form with the operands in the usual order. -That is, to get x-5 one would use "%gx%{5}%-". %P and %g variables are +That is, to get x-5 one would use "%gx%{5}%-". +%P and %g variables are persistent across escape-string evaluations. .PP Consider the HP2645, which, to get to row 3 and column 12, needs -to be sent \eE&a12c03Y padded for 6 milliseconds. Note that the order +to be sent \eE&a12c03Y padded for 6 milliseconds. +Note that the order of the rows and columns is inverted here, and that the row and column are printed as two digits. Thus its \fBcup\fR capability is \*(lqcup=6\eE&%p2%2dc%p1%2dY\*(rq. @@ -2064,7 +2141,8 @@ is not available.) .PP If the terminal can open a new blank line before the line where the cursor is, this should be given as \fBil1\fR; this is done only from the first -position of a line. The cursor must then appear on the newly blank line. +position of a line. +The cursor must then appear on the newly blank line. If the terminal can delete the line which the cursor is on, then this should be given as \fBdl1\fR; this is done only from the first position on the line to be deleted. @@ -2110,12 +2188,15 @@ on many terminals without a true insert/delete line, and is often faster even on terminals with those features. .PP The boolean \fBnon_dest_scroll_region\fR should be set if each scrolling -window is effectively a view port on a screen-sized canvas. To test for +window is effectively a view port on a screen-sized canvas. +To test for this capability, create a scrolling region in the middle of the screen, write something to the bottom line, move the cursor to the top of the region, -and do \fBri\fR followed by \fBdl1\fR or \fBind\fR. If the data scrolled +and do \fBri\fR followed by \fBdl1\fR or \fBind\fR. +If the data scrolled off the bottom of the region by the \fBri\fR re-appears, then scrolling -is non-destructive. System V and XSI Curses expect that \fBind\fR, \fBri\fR, +is non-destructive. +System V and XSI Curses expect that \fBind\fR, \fBri\fR, \fBindn\fR, and \fBrin\fR will simulate destructive scrolling; their documentation cautions you not to define \fBcsr\fR unless this is true. This \fBcurses\fR implementation is more liberal and will do explicit erases @@ -2130,7 +2211,8 @@ and the starting and ending columns in memory, in that order. .PP If the terminal can retain display memory above, then the \fBda\fR capability should be given; if display memory can be retained -below, then \fBdb\fR should be given. These indicate +below, then \fBdb\fR should be given. +These indicate that deleting a line or scrolling may bring non-blank lines up from below or that scrolling back with \fBri\fR may bring down non-blank lines. .PP @@ -2144,19 +2226,23 @@ on the current line and shift characters off the end of the line rigidly. Other terminals, such as the Concept 100 and the Perkin Elmer Owl, make a distinction between typed and untyped blanks on the screen, shifting upon an insert or delete only to an untyped blank on the screen which is -either eliminated, or expanded to two untyped blanks. You can determine the +either eliminated, or expanded to two untyped blanks. +You can determine the kind of terminal you have by clearing the screen and then typing -text separated by cursor motions. Type \*(lqabc\ \ \ \ def\*(rq using local +text separated by cursor motions. +Type \*(lqabc\ \ \ \ def\*(rq using local cursor motions (not spaces) between the \*(lqabc\*(rq and the \*(lqdef\*(rq. Then position the cursor before the \*(lqabc\*(rq and put the terminal in insert -mode. If typing characters causes the rest of the line to shift +mode. +If typing characters causes the rest of the line to shift rigidly and characters to fall off the end, then your terminal does -not distinguish between blanks and untyped positions. If the \*(lqabc\*(rq +not distinguish between blanks and untyped positions. +If the \*(lqabc\*(rq shifts over to the \*(lqdef\*(rq which then move together around the end of the current line and onto the next as you insert, you have the second type of terminal, and should give the capability \fBin\fR, which stands for \*(lqinsert null\*(rq. -While these are two logically separate attributes (one line vs. multi-line +While these are two logically separate attributes (one line versus multi-line insert mode, and special treatment of untyped spaces) we have seen no terminals whose insert mode cannot be described with the single attribute. .PP @@ -2165,24 +2251,30 @@ which send a simple sequence to open a blank position on the current line. Give as \fBsmir\fR the sequence to get into insert mode. Give as \fBrmir\fR the sequence to leave insert mode. Now give as \fBich1\fR any sequence needed to be sent just before sending -the character to be inserted. Most terminals with a true insert mode +the character to be inserted. +Most terminals with a true insert mode will not give \fBich1\fR; terminals which send a sequence to open a screen position should give it here. .PP If your terminal has both, insert mode is usually preferable to \fBich1\fR. Technically, you should not give both unless the terminal actually requires -both to be used in combination. Accordingly, some non-curses applications get +both to be used in combination. +Accordingly, some non-curses applications get confused if both are present; the symptom is doubled characters in an update -using insert. This requirement is now rare; most \fBich\fR sequences do not +using insert. +This requirement is now rare; most \fBich\fR sequences do not require previous smir, and most smir insert modes do not require \fBich1\fR -before each character. Therefore, the new \fBcurses\fR actually assumes this +before each character. +Therefore, the new \fBcurses\fR actually assumes this is the case and uses either \fBrmir\fR/\fBsmir\fR or \fBich\fR/\fBich1\fR as -appropriate (but not both). If you have to write an entry to be used under +appropriate (but not both). +If you have to write an entry to be used under new curses for a terminal old enough to need both, include the \fBrmir\fR/\fBsmir\fR sequences in \fBich1\fR. .PP If post insert padding is needed, give this as a number of milliseconds -in \fBip\fR (a string option). Any other sequence which may need to be +in \fBip\fR (a string option). +Any other sequence which may need to be sent after an insert of a single character may also be given in \fBip\fR. If your terminal needs both to be placed into an `insert mode' and a special code to precede each inserted character, then both @@ -2204,9 +2296,12 @@ in insert mode, give this as a number of milliseconds padding in \fBrmp\fP. .PP It is occasionally necessary to move around while in insert mode to delete characters on the same line (e.g., if there is a tab after -the insertion position). If your terminal allows motion while in +the insertion position). +If your terminal allows motion while in insert mode you can give the capability \fBmir\fR to speed up inserting -in this case. Omitting \fBmir\fR will affect only speed. Some terminals +in this case. +Omitting \fBmir\fR will affect only speed. +Some terminals (notably Datamedia's) must not have \fBmir\fR because of the way their insert mode works. .PP @@ -2356,6 +2451,12 @@ Putting this all together into the sgr sequence gives: .fi .PP Remember that if you specify sgr, you must also specify sgr0. +Also, some implementations rely on sgr being given if sgr0 is, +Not all terminfo entries necessarily have an sgr string, however. +Many terminfo entries are derived from termcap entries +which have no sgr string. +The only drawback to adding an sgr string is that termcap also +assumes that sgr0 does not exit alternate character set mode. .PP Terminals with the ``magic cookie'' glitch .RB ( xmc ) @@ -2397,7 +2498,8 @@ then this should be indicated by giving \fBeo\fR. .SS Keypad and Function Keys .PP If the terminal has a keypad that transmits codes when the keys are pressed, -this information can be given. Note that it is not possible to handle +this information can be given. +Note that it is not possible to handle terminals where the keypad only works in local (this applies, for example, to the unshifted HP 2621 keys). If the keypad can be set to transmit or not transmit, @@ -2530,25 +2632,33 @@ option of the .IR tput program, each time the user logs in. They will be printed in the following order: +.RS +.TP run the program -.BR iprog ; +.BR iprog +.TP output -.BR is1 ; -.BR is2 ; +.BR is1 +.BR is2 +.TP set the margins using .BR mgc , .BR smgl and -.BR smgr ; +.BR smgr +.TP set tabs using .B tbc and -.BR hts ; +.BR hts +.TP print the file -.BR if ; +.BR if +.TP and finally output .BR is3 . +.RE .PP Most initialization is done with .BR is2 . @@ -2559,17 +2669,21 @@ and special cases in .B is1 and .BR is3 . -A pair of sequences that does a harder reset from a totally unknown state -can be analogously given as +.PP +A set of sequences that does a harder reset from a totally unknown state +can be given as .BR rs1 , .BR rs2 , -.BR rf , +.BR rf and .BR rs3 , analogous to -.B is2 +.B is1 , +.B is2 , +.B if and -.BR if . +.BR is3 +respectively. These strings are output by the .IR reset program, which is used when the terminal gets into a wedged state. @@ -2587,6 +2701,28 @@ normally be part of but it causes an annoying glitch of the screen and is not normally needed since the terminal is usually already in 80 column mode. .PP +The +.IR reset +program writes strings +including +.BR iprog , +etc., in the same order as the +.IR init +program, using +.BR rs1 , +etc., instead of +.BR is1 , +etc. +If any of +.BR rs1 , +.BR rs2 , +.BR rs3 , +or +.BR rf +reset capability strings are missing, the +.IR reset +program falls back upon the corresponding initialization capability string. +.PP If there are commands to set and clear tab stops, they can be given as .B tbc (clear all tab stops) @@ -2600,23 +2736,26 @@ or .BR if . .SS Delays and Padding .PP -Many older and slower terminals don't support either XON/XOFF or DTR +Many older and slower terminals do not support either XON/XOFF or DTR handshaking, including hard copy terminals and some very archaic CRTs -(including, for example, DEC VT100s). These may require padding characters +(including, for example, DEC VT100s). +These may require padding characters after certain cursor motions and screen changes. .PP If the terminal uses xon/xoff handshaking for flow control (that is, it automatically emits ^S back to the host when its input buffers are close to full), set .BR xon . -This capability suppresses the emission of padding. You can also set it -for memory-mapped console devices effectively that don't have a speed limit. +This capability suppresses the emission of padding. +You can also set it +for memory-mapped console devices effectively that do not have a speed limit. Padding information should still be included so that routines can make better decisions about relative costs, but actual pad characters will not be transmitted. .PP If \fBpb\fR (padding baud rate) is given, padding is suppressed at baud rates -below the value of \fBpb\fR. If the entry has no padding baud rate, then +below the value of \fBpb\fR. +If the entry has no padding baud rate, then whether padding is emitted or not is completely controlled by \fBxon\fR. .PP If the terminal requires other than a null (zero) character as a pad, @@ -2632,25 +2771,30 @@ software (and thus not counted in the terminal's \fBlines\fR capability). The simplest case is a status line which is cursor-addressable but not part of the main scrolling region on the screen; the Heathkit H19 has a status line of this kind, as would a 24-line VT100 with a 23-line -scrolling region set up on initialization. This situation is indicated +scrolling region set up on initialization. +This situation is indicated by the \fBhs\fR capability. .PP Some terminals with status lines need special sequences to access the -status line. These may be expressed as a string with single parameter +status line. +These may be expressed as a string with single parameter \fBtsl\fR which takes the cursor to a given zero-origin column on the -status line. The capability \fBfsl\fR must return to the main-screen -cursor positions before the last \fBtsl\fR. You may need to embed the +status line. +The capability \fBfsl\fR must return to the main-screen +cursor positions before the last \fBtsl\fR. +You may need to embed the string values of \fBsc\fR (save cursor) and \fBrc\fR (restore cursor) in \fBtsl\fR and \fBfsl\fR to accomplish this. .PP The status line is normally assumed to be the same width as the width -of the terminal. If this is untrue, you can specify it with the numeric +of the terminal. +If this is untrue, you can specify it with the numeric capability \fBwsl\fR. .PP A command to erase or blank the status line may be specified as \fBdsl\fR. .PP The boolean capability \fBeslok\fR specifies that escape sequences, tabs, -etc. work ordinarily in the status line. +etc., work ordinarily in the status line. .PP The \fBncurses\fR implementation does not yet use any of these capabilities. They are documented here in case they ever become important. @@ -2707,25 +2851,33 @@ vertical line ACS_VLINE | x The best way to define a new device's graphics set is to add a column to a copy of this table for your terminal, giving the character which (when emitted between \fBsmacs\fR/\fBrmacs\fR switches) will be rendered -as the corresponding graphic. Then read off the VT100/your terminal +as the corresponding graphic. +Then read off the VT100/your terminal character pairs right to left in sequence; these become the ACSC string. .PP .SS Color Handling .PP -Most color terminals are either `Tektronix-like' or `HP-like'. Tektronix-like +Most color terminals are either `Tektronix-like' or `HP-like'. +Tektronix-like terminals have a predefined set of N colors (where N usually 8), and can set character-cell foreground and background characters independently, mixing them -into N * N color-pairs. On HP-like terminals, the use must set each color +into N * N color-pairs. +On HP-like terminals, the use must set each color pair up separately (foreground and background are not independently settable). -Up to M color-pairs may be set up from 2*M different colors. ANSI-compatible +Up to M color-pairs may be set up from 2*M different colors. +ANSI-compatible terminals are Tektronix-like. .PP -Some basic color capabilities are independent of the color method. The numeric +Some basic color capabilities are independent of the color method. +The numeric capabilities \fBcolors\fR and \fBpairs\fR specify the maximum numbers of colors -and color-pairs that can be displayed simultaneously. The \fBop\fR (original +and color-pairs that can be displayed simultaneously. +The \fBop\fR (original pair) string resets foreground and background colors to their default values -for the terminal. The \fBoc\fR string resets all colors or color-pairs to -their default values for the terminal. Some terminals (including many PC +for the terminal. +The \fBoc\fR string resets all colors or color-pairs to +their default values for the terminal. +Some terminals (including many PC terminal emulators) erase screen areas with the current background color rather than the power-up default background; these should have the boolean capability \fBbce\fR. @@ -2733,19 +2885,24 @@ than the power-up default background; these should have the boolean capability To change the current foreground or background color on a Tektronix-type terminal, use \fBsetaf\fR (set ANSI foreground) and \fBsetab\fR (set ANSI background) or \fBsetf\fR (set foreground) and \fBsetb\fR (set background). -These take one parameter, the color number. The SVr4 documentation describes +These take one parameter, the color number. +The SVr4 documentation describes only \fBsetaf\fR/\fBsetab\fR; the XPG4 draft says that "If the terminal supports ANSI escape sequences to set background and foreground, they should -be coded as \fBsetaf\fR and \fBsetab\fR, respectively. If the terminal +be coded as \fBsetaf\fR and \fBsetab\fR, respectively. +If the terminal supports other escape sequences to set background and foreground, they should -be coded as \fBsetf\fR and \fBsetb\fR, respectively. The \fIvidputs()\fR +be coded as \fBsetf\fR and \fBsetb\fR, respectively. +The \fIvidputs()\fR function and the refresh functions use \fBsetaf\fR and \fBsetab\fR if they are defined." .PP The \fBsetaf\fR/\fBsetab\fR and \fBsetf\fR/\fBsetb\fR capabilities take a -single numeric argument each. Argument values 0-7 are portably defined as +single numeric argument each. +Argument values 0-7 of \fBsetaf\fR/\fBsetab\fR are portably defined as follows (the middle column is the symbolic #define available in the header for -the \fBcurses\fR or \fBncurses\fR libraries). The terminal hardware is free to +the \fBcurses\fR or \fBncurses\fR libraries). +The terminal hardware is free to map these as it likes, but the RGB values indicate normal locations in color space. .PP @@ -2764,26 +2921,54 @@ cyan \fBCOLOR_CYAN\fR 6 0,max,max white \fBCOLOR_WHITE\fR 7 max,max,max .TE .PP +The argument values of \fBsetf\fR/\fBsetb\fR historically correspond to +a different mapping, i.e., +.TS H +center; +l c c c +l l n l. +\fBColor #define Value RGB\fR +black \fBCOLOR_BLACK\fR 0 0, 0, 0 +blue \fBCOLOR_BLUE\fR 1 0,0,max +green \fBCOLOR_GREEN\fR 2 0,max,0 +cyan \fBCOLOR_CYAN\fR 3 0,max,max +red \fBCOLOR_RED\ \fR 4 max,0,0 +magenta \fBCOLOR_MAGENTA\fR 5 max,0,max +yellow \fBCOLOR_YELLOW\fR 6 max,max,0 +white \fBCOLOR_WHITE\fR 7 max,max,max +.TE +It is important to not confuse the two sets of color capabilities; +otherwise red/blue will be interchanged on the display. +.PP On an HP-like terminal, use \fBscp\fR with a color-pair number parameter to set which color pair is current. .PP On a Tektronix-like terminal, the capability \fBccc\fR may be present to -indicate that colors can be modified. If so, the \fBinitc\fR capability will +indicate that colors can be modified. +If so, the \fBinitc\fR capability will take a color number (0 to \fBcolors\fR - 1)and three more parameters which -describe the color. These three parameters default to being interpreted as RGB -(Red, Green, Blue) values. If the boolean capability \fBhls\fR is present, -they are instead as HLS (Hue, Lightness, Saturation) indices. The ranges are +describe the color. +These three parameters default to being interpreted as RGB +(Red, Green, Blue) values. +If the boolean capability \fBhls\fR is present, +they are instead as HLS (Hue, Lightness, Saturation) indices. +The ranges are terminal-dependent. .PP On an HP-like terminal, \fBinitp\fR may give a capability for changing a -color-pair value. It will take seven parameters; a color-pair number (0 to +color-pair value. +It will take seven parameters; a color-pair number (0 to \fBmax_pairs\fR - 1), and two triples describing first background and then -foreground colors. These parameters must be (Red, Green, Blue) or +foreground colors. +These parameters must be (Red, Green, Blue) or (Hue, Lightness, Saturation) depending on \fBhls\fR. .PP -On some color terminals, colors collide with highlights. You can register -these collisions with the \fBncv\fR capability. This is a bit-mask of -attributes not to be used when colors are enabled. The correspondence with the +On some color terminals, colors collide with highlights. +You can register +these collisions with the \fBncv\fR capability. +This is a bit-mask of +attributes not to be used when colors are enabled. +The correspondence with the attributes understood by \fBcurses\fR is as follows: .PP .TS @@ -2803,7 +2988,8 @@ A_ALTCHARSET 8 256 .TE .PP For example, on many IBM PC consoles, the underline attribute collides with the -foreground color blue and is not available in color mode. These should have +foreground color blue and is not available in color mode. +These should have an \fBncv\fR capability of 2. .PP SVr4 curses does nothing with \fBncv\fR, ncurses recognizes it and optimizes @@ -2938,7 +3124,8 @@ older versions, it was teleray_glitch. This glitch is also taken to mean that it is not possible to position the cursor on top of a ``magic cookie'', that to erase standout mode it is instead necessary to use -delete and insert line. The ncurses implementation ignores this glitch. +delete and insert line. +The ncurses implementation ignores this glitch. .PP The Beehive Superbee, which is unable to correctly transmit the escape or control C characters, has @@ -2954,15 +3141,18 @@ capabilities of the form \fBx\fR\fIx\fR. .SS Similar Terminals .PP If there are two very similar terminals, one (the variant) can be defined as -being just like the other (the base) with certain exceptions. In the +being just like the other (the base) with certain exceptions. +In the definition of the variant, the string capability \fBuse\fR can be given with -the name of the base terminal. The capabilities given before +the name of the base terminal. +The capabilities given before .B use override those in the base type named by .BR use . If there are multiple \fBuse\fR capabilities, they are merged in reverse order. That is, the rightmost \fBuse\fR reference is processed first, then the one to -its left, and so forth. Capabilities given explicitly in the entry override +its left, and so forth. +Capabilities given explicitly in the entry override those brought in by \fBuse\fR references. .PP A capability can be canceled by placing \fBxx@\fR to the left of the @@ -2979,32 +3169,39 @@ user preferences. .SS Pitfalls of Long Entries .PP Long terminfo entries are unlikely to be a problem; to date, no entry has even -approached terminfo's 4K string-table maximum. Unfortunately, the termcap -translations are much more strictly limited (to 1K), thus termcap translations +approached terminfo's 4096-byte string-table maximum. +Unfortunately, the termcap +translations are much more strictly limited (to 1023 bytes), thus termcap translations of long terminfo entries can cause problems. .PP -The man pages for 4.3BSD and older versions of tgetent() instruct the user to -allocate a 1K buffer for the termcap entry. The entry gets null-terminated by +The man pages for 4.3BSD and older versions of \fBtgetent()\fP instruct the user to +allocate a 1024-byte buffer for the termcap entry. +The entry gets null-terminated by the termcap library, so that makes the maximum safe length for a termcap entry -1k-1 (1023) bytes. Depending on what the application and the termcap library -being used does, and where in the termcap file the terminal type that tgetent() +1k-1 (1023) bytes. +Depending on what the application and the termcap library +being used does, and where in the termcap file the terminal type that \fBtgetent()\fP is searching for is, several bad things can happen. .PP Some termcap libraries print a warning message or exit if they find an -entry that's longer than 1023 bytes; others don't; others truncate the -entries to 1023 bytes. Some application programs allocate more than -the recommended 1K for the termcap entry; others don't. +entry that's longer than 1023 bytes; others do not; others truncate the +entries to 1023 bytes. +Some application programs allocate more than +the recommended 1K for the termcap entry; others do not. .PP Each termcap entry has two important sizes associated with it: before -"tc" expansion, and after "tc" expansion. "tc" is the capability that +"tc" expansion, and after "tc" expansion. +"tc" is the capability that tacks on another termcap entry to the end of the current one, to add -on its capabilities. If a termcap entry doesn't use the "tc" +on its capabilities. +If a termcap entry does not use the "tc" capability, then of course the two lengths are the same. .PP The "before tc expansion" length is the most important one, because it -affects more than just users of that particular terminal. This is the +affects more than just users of that particular terminal. +This is the length of the entry as it exists in /etc/termcap, minus the -backslash-newline pairs, which tgetent() strips out while reading it. +backslash-newline pairs, which \fBtgetent()\fP strips out while reading it. Some termcap libraries strip off the final newline, too (GNU termcap does not). Now suppose: .TP 5 @@ -3017,70 +3214,81 @@ and the application has only allocated a 1k buffer, * and the termcap library (like the one in BSD/OS 1.1 and GNU) reads the whole entry into the buffer, no matter what its length, to see -if it's the entry it wants, +if it is the entry it wants, .TP 5 * -and tgetent() is searching for a terminal type that either is the +and \fBtgetent()\fP is searching for a terminal type that either is the long entry, appears in the termcap file after the long entry, or -doesn't appear in the file at all (so that tgetent() has to search +does not appear in the file at all (so that \fBtgetent()\fP has to search the whole termcap file). .PP -Then tgetent() will overwrite memory, perhaps its stack, and probably core dump -the program. Programs like telnet are particularly vulnerable; modern telnets -pass along values like the terminal type automatically. The results are almost +Then \fBtgetent()\fP will overwrite memory, perhaps its stack, and probably core dump +the program. +Programs like telnet are particularly vulnerable; modern telnets +pass along values like the terminal type automatically. +The results are almost as undesirable with a termcap library, like SunOS 4.1.3 and Ultrix 4.4, that -prints warning messages when it reads an overly long termcap entry. If a +prints warning messages when it reads an overly long termcap entry. +If a termcap library truncates long entries, like OSF/1 3.0, it is immune to dying here but will return incorrect data for the terminal. .PP The "after tc expansion" length will have a similar effect to the above, but only for people who actually set TERM to that terminal -type, since tgetent() only does "tc" expansion once it's found the +type, since \fBtgetent()\fP only does "tc" expansion once it is found the terminal type it was looking for, not while searching. .PP In summary, a termcap entry that is longer than 1023 bytes can cause, on various combinations of termcap libraries and applications, a core -dump, warnings, or incorrect operation. If it's too long even before +dump, warnings, or incorrect operation. +If it is too long even before "tc" expansion, it will have this effect even for users of some other terminal types and users whose TERM variable does not have a termcap entry. .PP When in -C (translate to termcap) mode, the \fBncurses\fR implementation of \fBtic\fR(1) issues warning messages when the pre-tc length of a termcap -translation is too long. The -c (check) option also checks resolved (after tc +translation is too long. +The -c (check) option also checks resolved (after tc expansion) lengths. .SS Binary Compatibility It is not wise to count on portability of binary terminfo entries between -commercial UNIX versions. The problem is that there are at least two versions +commercial UNIX versions. +The problem is that there are at least two versions of terminfo (under HP-UX and AIX) which diverged from System V terminfo after SVr1, and have added extension capabilities to the string table that (in the binary format) collide with System V and XSI Curses extensions. .SH EXTENSIONS -Some SVr4 \fBcurses\fR implementations, and all previous to SVr4, don't +Some SVr4 \fBcurses\fR implementations, and all previous to SVr4, do not interpret the %A and %O operators in parameter strings. .PP SVr4/XPG4 do not specify whether \fBmsgr\fR licenses movement while in an alternate-character-set mode (such modes may, among other things, map -CR and NL to characters that don't trigger local motions). +CR and NL to characters that do not trigger local motions). The \fBncurses\fR implementation ignores \fBmsgr\fR in \fBALTCHARSET\fR -mode. This raises the possibility that an XPG4 +mode. +This raises the possibility that an XPG4 implementation making the opposite interpretation may need terminfo entries made for \fBncurses\fR to have \fBmsgr\fR turned off. .PP The \fBncurses\fR library handles insert-character and insert-character modes -in a slightly non-standard way in order to get better update efficiency. See +in a slightly non-standard way to get better update efficiency. +See the \fBInsert/Delete Character\fR subsection above. .PP The parameter substitutions for \fBset_clock\fR and \fBdisplay_clock\fR are -not documented in SVr4 or the XSI Curses standard. They are deduced from the +not documented in SVr4 or the XSI Curses standard. +They are deduced from the documentation for the AT&T 505 terminal. .PP -Be careful assigning the \fBkmous\fR capability. The \fBncurses\fR wants to +Be careful assigning the \fBkmous\fR capability. +The \fBncurses\fR wants to interpret it as \fBKEY_MOUSE\fR, for use by terminals and emulators like xterm that can return mouse-tracking information in the keyboard-input stream. .PP Different commercial ports of terminfo and curses support different subsets of -the XSI Curses standard and (in some cases) different extension sets. Here +the XSI Curses standard and (in some cases) different extension sets. +Here is a summary, accurate as of October 1995: .PP \fBSVR4, Solaris, ncurses\fR -- @@ -3091,7 +3299,8 @@ Supports the SVr4 set, adds one undocumented extended string capability (\fBset_pglen\fR). .PP \fBSVr1, Ultrix\fR -- -These support a restricted subset of terminfo capabilities. The booleans +These support a restricted subset of terminfo capabilities. +The booleans end with \fBxon_xoff\fR; the numerics with \fBwidth_status_line\fR; and the strings with \fBprtr_non\fR. .PP @@ -3109,13 +3318,14 @@ of incompatible string table extensions. Supports both the SVr4 set and the AIX extensions. .SH FILES .TP 25 -\*d.db -file containing terminal descriptions on OpenBSD -.TP 25 -/usr/share/terminfo/?/* -files containing terminal descriptions on other systems -.SH "SEE ALSO" -\fBcap_mkdb(1)\fR, \fBtic\fR(1M), \fBcurses\fR(3), \fBprintf\fR(3), \fBterm\fR(\*n). +\*d/?/* +files containing terminal descriptions +.SH SEE ALSO +\fBtic\fR(1), +\fBinfocmp\fR(1), +\fBcurses\fR(3), +\fBprintf\fR(3), +\fBterm\fR(\*n). .SH AUTHORS Zeyd M. Ben-Halim, Eric S. Raymond, Thomas E. Dickey. Based on pcurses by Pavel Curtis. diff --git a/lib/libcurses/tic.h b/lib/libcurses/tic.h index 64943ee9068..97181a66132 100644 --- a/lib/libcurses/tic.h +++ b/lib/libcurses/tic.h @@ -1,7 +1,7 @@ -/* $OpenBSD: tic.h,v 1.13 2002/02/18 22:24:32 deraadt Exp $ */ +/* $OpenBSD: tic.h,v 1.14 2010/01/12 23:21:59 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998-2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,10 +31,11 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996 on * ****************************************************************************/ /* - * $From: tic.h,v 1.36 2000/12/10 02:03:28 tom Exp $ + * $Id: tic.h,v 1.14 2010/01/12 23:21:59 nicm Exp $ * tic.h - Global variables and structures for the terminfo * compiler. */ @@ -78,6 +79,15 @@ extern "C" { #define MAGIC 0432 /* first two bytes of a compiled entry */ +#undef BYTE +#define BYTE(p,n) (unsigned char)((p)[n]) + +#define IS_NEG1(p) ((BYTE(p,0) == 0377) && (BYTE(p,1) == 0377)) +#define IS_NEG2(p) ((BYTE(p,0) == 0376) && (BYTE(p,1) == 0377)) +#define LOW_MSB(p) (BYTE(p,0) + 256*BYTE(p,1)) + +#define IS_TIC_MAGIC(p) (LOW_MSB(p) == MAGIC) + /* * The "maximum" here is misleading; XSI guarantees minimum values, which a * given implementation may exceed. @@ -85,13 +95,14 @@ extern "C" { #define MAX_NAME_SIZE 512 /* maximum legal name field size (XSI:127) */ #define MAX_ENTRY_SIZE 4096 /* maximum legal entry size */ -/* The maximum size of individual name or alias is guaranteed in XSI to - * be 14, since that corresponds to the older filename lengths. Newer - * systems allow longer aliases, though not many terminal descriptions - * are written to use them. +/* + * The maximum size of individual name or alias is guaranteed in XSI to be at + * least 14, since that corresponds to the older filename lengths. Newer + * systems allow longer aliases, though not many terminal descriptions are + * written to use them. The MAX_ALIAS symbol is used for warnings. */ #if HAVE_LONG_FILE_NAMES -#define MAX_ALIAS 32 /* POSIX minimum for PATH_MAX */ +#define MAX_ALIAS 32 /* smaller than POSIX minimum for PATH_MAX */ #else #define MAX_ALIAS 14 /* SVr3 filename length */ #endif @@ -106,10 +117,10 @@ extern "C" { */ #define MAX_DEBUG_LEVEL 15 -#define DEBUG_LEVEL(n) ((n) << 12) /* see TRACE_MAXIMUM */ +#define DEBUG_LEVEL(n) ((n) << TRACE_SHIFT) #define set_trace_level(n) \ - _nc_tracing &= DEBUG_LEVEL(MAX_DEBUG_LEVEL), \ + _nc_tracing &= DEBUG_LEVEL(MAX_DEBUG_LEVEL), \ _nc_tracing |= DEBUG_LEVEL(n) #ifdef TRACE @@ -121,6 +132,7 @@ extern "C" { extern NCURSES_EXPORT_VAR(unsigned) _nc_tracing; extern NCURSES_EXPORT(void) _nc_tracef (char *, ...) GCC_PRINTFLIKE(1,2); extern NCURSES_EXPORT(const char *) _nc_visbuf (const char *); +extern NCURSES_EXPORT(const char *) _nc_visbuf2 (int, const char *); /* * These are the types of tokens returned by the scanner. The first @@ -154,16 +166,6 @@ struct token extern NCURSES_EXPORT_VAR(struct token) _nc_curr_token; /* - * List of keynames with their corresponding code. - */ -struct kn { - const char *name; - int code; -}; - -extern NCURSES_EXPORT_VAR(const struct kn) _nc_key_names[]; - - /* * Offsets to string capabilities, with the corresponding functionkey * codes. */ @@ -175,11 +177,11 @@ struct tinfo_fkeys { #if BROKEN_LINKER #define _nc_tinfo_fkeys _nc_tinfo_fkeysf() -extern NCURSES_EXPORT(struct tinfo_fkeys *) _nc_tinfo_fkeysf (void); +extern NCURSES_EXPORT(const struct tinfo_fkeys *) _nc_tinfo_fkeysf (void); #else -extern NCURSES_EXPORT_VAR(struct tinfo_fkeys) _nc_tinfo_fkeys[]; +extern NCURSES_EXPORT_VAR(const struct tinfo_fkeys) _nc_tinfo_fkeys[]; #endif @@ -204,30 +206,25 @@ struct alias const char *source; }; -extern NCURSES_EXPORT_VAR(const struct name_table_entry * const) _nc_info_hash_table[]; -extern NCURSES_EXPORT_VAR(const struct name_table_entry * const) _nc_cap_hash_table[]; - -extern NCURSES_EXPORT_VAR(const struct alias) _nc_capalias_table[]; -extern NCURSES_EXPORT_VAR(const struct alias) _nc_infoalias_table[]; - extern NCURSES_EXPORT(const struct name_table_entry *) _nc_get_table (bool); -extern NCURSES_EXPORT(const struct name_table_entry * const *) _nc_get_hash_table (bool); +extern NCURSES_EXPORT(const short *) _nc_get_hash_table (bool); +extern NCURSES_EXPORT(const struct alias *) _nc_get_alias_table (bool); #define NOTFOUND ((struct name_table_entry *) 0) /* out-of-band values for representing absent capabilities */ -#define ABSENT_BOOLEAN -1 -#define ABSENT_NUMERIC -1 +#define ABSENT_BOOLEAN ((signed char)-1) /* 255 */ +#define ABSENT_NUMERIC (-1) #define ABSENT_STRING (char *)0 /* out-of-band values for representing cancels */ -#define CANCELLED_BOOLEAN (signed char)(-2) -#define CANCELLED_NUMERIC -2 -#define CANCELLED_STRING (char *)-1 +#define CANCELLED_BOOLEAN ((signed char)-2) /* 254 */ +#define CANCELLED_NUMERIC (-2) +#define CANCELLED_STRING (char *)(-1) -#define VALID_BOOLEAN(s) ((s) >= 0) +#define VALID_BOOLEAN(s) ((unsigned char)(s) <= 1) /* reject "-1" */ #define VALID_NUMERIC(s) ((s) >= 0) -#define VALID_STRING(s) ((s) != CANCELLED_STRING && (s) != ABSENT_STRING) +#define VALID_STRING(s) ((s) != CANCELLED_STRING && (s) != ABSENT_STRING) /* termcap entries longer than this may break old binaries */ #define MAX_TERMCAP_LENGTH 1023 @@ -240,11 +237,16 @@ extern NCURSES_EXPORT(const struct name_table_entry * const *) _nc_get_hash_tabl #endif /* access.c */ +extern NCURSES_EXPORT(unsigned) _nc_pathlast (const char *); +extern NCURSES_EXPORT(bool) _nc_is_abs_path (const char *); +extern NCURSES_EXPORT(bool) _nc_is_dir_path (const char *); +extern NCURSES_EXPORT(bool) _nc_is_file_path (const char *); extern NCURSES_EXPORT(char *) _nc_basename (char *); +extern NCURSES_EXPORT(char *) _nc_rootname (char *); /* comp_hash.c: name lookup */ extern NCURSES_EXPORT(struct name_table_entry const *) _nc_find_entry - (const char *, const struct name_table_entry *const *); + (const char *, const short *); extern NCURSES_EXPORT(struct name_table_entry const *) _nc_find_type_entry (const char *, int, const struct name_table_entry *); @@ -264,11 +266,12 @@ extern NCURSES_EXPORT_VAR(long) _nc_start_line; #define SYN_TERMCAP 1 /* comp_error.c: warning & abort messages */ -extern NCURSES_EXPORT(void) _nc_set_source (const char *const name); +extern NCURSES_EXPORT(const char *) _nc_get_source (void); +extern NCURSES_EXPORT(void) _nc_err_abort (const char *const,...) GCC_PRINTFLIKE(1,2) GCC_NORETURN; extern NCURSES_EXPORT(void) _nc_get_type (char *name); -extern NCURSES_EXPORT(void) _nc_set_type (const char *const name); +extern NCURSES_EXPORT(void) _nc_set_source (const char *const); +extern NCURSES_EXPORT(void) _nc_set_type (const char *const); extern NCURSES_EXPORT(void) _nc_syserr_abort (const char *const,...) GCC_PRINTFLIKE(1,2) GCC_NORETURN; -extern NCURSES_EXPORT(void) _nc_err_abort (const char *const,...) GCC_PRINTFLIKE(1,2) GCC_NORETURN; extern NCURSES_EXPORT(void) _nc_warning (const char *const,...) GCC_PRINTFLIKE(1,2); extern NCURSES_EXPORT_VAR(bool) _nc_suppress_warnings; @@ -276,20 +279,50 @@ extern NCURSES_EXPORT_VAR(bool) _nc_suppress_warnings; extern NCURSES_EXPORT(char *) _nc_tic_expand (const char *, bool, int); /* comp_scan.c: decode string from readable form */ -extern NCURSES_EXPORT(char) _nc_trans_string (char *, char *); +extern NCURSES_EXPORT(int) _nc_trans_string (char *, char *); /* captoinfo.c: capability conversion */ extern NCURSES_EXPORT(char *) _nc_captoinfo (const char *, const char *, int const); extern NCURSES_EXPORT(char *) _nc_infotocap (const char *, const char *, int const); +/* home_terminfo.c */ +extern NCURSES_EXPORT(char *) _nc_home_terminfo (void); + +/* lib_tparm.c */ +#define NUM_PARM 9 + +extern NCURSES_EXPORT_VAR(int) _nc_tparm_err; + +extern NCURSES_EXPORT(int) _nc_tparm_analyze(const char *, char **, int *); + /* lib_tputs.c */ extern NCURSES_EXPORT_VAR(int) _nc_nulls_sent; /* Add one for every null sent */ /* comp_main.c: compiler main */ extern const char * _nc_progname; -/* read_entry.c */ +/* db_iterator.c */ +typedef enum { + dbdTIC = 0, +#if USE_DATABASE + dbdEnvOnce, + dbdHome, + dbdEnvList, + dbdCfgList, + dbdCfgOnce, +#endif +#if USE_TERMCAP + dbdEnvOnce2, + dbdEnvList2, + dbdCfgList2, +#endif + dbdLAST +} DBDIRS; + +extern NCURSES_EXPORT(const char *) _nc_next_db(DBDIRS *, int *); extern NCURSES_EXPORT(const char *) _nc_tic_dir (const char *); +extern NCURSES_EXPORT(void) _nc_first_db(DBDIRS *, int *); +extern NCURSES_EXPORT(void) _nc_last_db(void); /* write_entry.c */ extern NCURSES_EXPORT(int) _nc_tic_written (void); diff --git a/lib/libcurses/tinfo/MKcaptab.awk b/lib/libcurses/tinfo/MKcaptab.awk index 4f5df3afdb2..b105931c55d 100644 --- a/lib/libcurses/tinfo/MKcaptab.awk +++ b/lib/libcurses/tinfo/MKcaptab.awk @@ -1,72 +1,95 @@ -#!/bin/sh -# $OpenBSD: MKcaptab.awk,v 1.3 2001/01/22 18:01:49 millert Exp $ -# $From: MKcaptab.awk,v 1.12 2000/12/10 00:14:12 tom Exp $ -AWK=${1-awk} -DATA=${2-../include/Caps} - -cat <<'EOF' -/* - * comp_captab.c -- The names of the capabilities indexed via a hash - * table for the compiler. - * - */ - -#include <ncurses_cfg.h> -#include <curses.priv.h> -#include <tic.h> -#include <term.h> - -EOF - -./make_hash 1 info <$DATA -./make_hash 3 cap <$DATA - -cat <<'EOF' -const struct alias _nc_capalias_table[] = -{ -EOF +# $OpenBSD: MKcaptab.awk,v 1.4 2010/01/12 23:22:06 nicm Exp $ +############################################################################## +# Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. # +# # +# Permission is hereby granted, free of charge, to any person obtaining a # +# copy of this software and associated documentation files (the "Software"), # +# to deal in the Software without restriction, including without limitation # +# the rights to use, copy, modify, merge, publish, distribute, distribute # +# with modifications, sublicense, and/or sell copies of the Software, and to # +# permit persons to whom the Software is furnished to do so, subject to the # +# following conditions: # +# # +# The above copyright notice and this permission notice shall be included in # +# all copies or substantial portions of the Software. # +# # +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # +# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # +# DEALINGS IN THE SOFTWARE. # +# # +# Except as contained in this notice, the name(s) of the above copyright # +# holders shall not be used in advertising or otherwise to promote the sale, # +# use or other dealings in this Software without prior written # +# authorization. # +############################################################################## +# $Id: MKcaptab.awk,v 1.4 2010/01/12 23:22:06 nicm Exp $ +function add_string(text) { + if (text != "IGNORE") { + offsets[num_strings] = offset; + offset = offset + length(text) + 1; + printf "%s\\0", text; + } else { + offsets[num_strings] = -1; + } + num_strings = num_strings + 1; + if ((num_strings % 3) == 0) { + printf "\\\n"; + } + return offsets[num_strings - 1]; +} +BEGIN { + first = 1; + num_aliases = 0; + num_strings = 0; + offset = 0; +} -$AWK <$DATA ' -$1 == "capalias" { - if ($3 == "IGNORE") - to = "(char *)NULL"; - else - to = "\"" $3 "\""; - printf "\t{\"%s\", %s, \"%s\"},\t /* %s */\n", - $2, to, $4, $5 +/^[^#]/ { + if (first) { + printf "/* generated by MKcaptab.awk %s(%d) */\n", tablename, bigstrings; + print "" + if (bigstrings) { + printf "static struct alias *_nc_%s_table = 0;\n", tablename; + print ""; + printf "static const char %s_text[] = \"\\\n", tablename; + } else { + printf "static const struct alias _nc_%s_table[] =\n", tablename; + printf "{\n"; } -' - -cat <<'EOF' - {(char *)NULL, (char *)NULL, (char *)NULL} -}; - -const struct alias _nc_infoalias_table[] = -{ -EOF - -$AWK <$DATA ' -$1 == "infoalias" { - if ($3 == "IGNORE") - to = "(char *)NULL"; - else - to = "\"" $3 "\""; - printf "\t{\"%s\", %s, \"%s\"},\t /* %s */\n", - $2, to, $4, $5 + first = 0; + } + if ($1 == tablename) { + if ($3 == "IGNORE") { + to = "(char *)NULL"; + } else { + to = "\"" $3 "\""; } -' - -cat <<'EOF' - {(char *)NULL, (char *)NULL, (char *)NULL} -}; - -NCURSES_EXPORT(const struct name_table_entry *) _nc_get_table (bool termcap) -{ - return termcap ? _nc_cap_table: _nc_info_table ; -} - -NCURSES_EXPORT(const struct name_table_entry * const *) _nc_get_hash_table (bool termcap) -{ - return termcap ? _nc_cap_hash_table: _nc_info_hash_table ; -} -EOF + if (bigstrings) { + c1 = add_string($2); + c2 = add_string($3); + c3 = add_string($4); + aliases[num_aliases] = sprintf("\t{%5d, %5d, %5d},\t /* %s */", c1, c2, c3, $5); + num_aliases = num_aliases + 1; + } else { + printf "\t{\"%s\", %s, \"%s\"},\t /* %s */\n", $2, to, $4, $5; + } + } + } +END { + if (bigstrings) { + printf "\";\n\n"; + printf "static const alias_table_data %s_data[] = {\n", tablename; + for (n = 0; n < num_aliases; ++n) { + printf "%s\n", aliases[n]; + } + printf "};\n\n"; + } else { + printf "\t{(char *)NULL, (char *)NULL, (char *)NULL}\n"; + printf "};\n\n"; + } + } +# vile:sw=4: diff --git a/lib/libcurses/tinfo/MKcaptab.sh b/lib/libcurses/tinfo/MKcaptab.sh new file mode 100644 index 00000000000..d7305f2f88e --- /dev/null +++ b/lib/libcurses/tinfo/MKcaptab.sh @@ -0,0 +1,150 @@ +#!/bin/sh +# $OpenBSD: MKcaptab.sh,v 1.1 2010/01/12 23:22:06 nicm Exp $ +############################################################################## +# Copyright (c) 2007 Free Software Foundation, Inc. # +# # +# Permission is hereby granted, free of charge, to any person obtaining a # +# copy of this software and associated documentation files (the "Software"), # +# to deal in the Software without restriction, including without limitation # +# the rights to use, copy, modify, merge, publish, distribute, distribute # +# with modifications, sublicense, and/or sell copies of the Software, and to # +# permit persons to whom the Software is furnished to do so, subject to the # +# following conditions: # +# # +# The above copyright notice and this permission notice shall be included in # +# all copies or substantial portions of the Software. # +# # +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # +# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # +# DEALINGS IN THE SOFTWARE. # +# # +# Except as contained in this notice, the name(s) of the above copyright # +# holders shall not be used in advertising or otherwise to promote the sale, # +# use or other dealings in this Software without prior written # +# authorization. # +############################################################################## +# $Id: MKcaptab.sh,v 1.1 2010/01/12 23:22:06 nicm Exp $ +AWK=${1-awk} +OPT1=${2-0} +OPT2=${3-tinfo/MKcaptab.awk} +DATA=${4-../include/Caps} + +cat <<'EOF' +/* + * comp_captab.c -- The names of the capabilities indexed via a hash + * table for the compiler. + * + */ + +#include <curses.priv.h> +#include <tic.h> +#include <hashsize.h> + +EOF + +./make_hash 1 info $OPT1 <$DATA +./make_hash 3 cap $OPT1 <$DATA + +$AWK -f $OPT2 bigstrings=$OPT1 tablename=capalias <$DATA + +$AWK -f $OPT2 bigstrings=$OPT1 tablename=infoalias <$DATA + +cat <<EOF + +#if $OPT1 +static void +next_string(const char *strings, unsigned *offset) +{ + *offset += strlen(strings + *offset) + 1; +} + +static const struct name_table_entry * +_nc_build_names(struct name_table_entry **actual, + const name_table_data *source, + const char *strings) +{ + if (*actual == 0) { + *actual = typeCalloc(struct name_table_entry, CAPTABSIZE); + if (*actual != 0) { + unsigned n; + unsigned len = 0; + for (n = 0; n < CAPTABSIZE; ++n) { + (*actual)[n].nte_name = strings + len; + (*actual)[n].nte_type = source[n].nte_type; + (*actual)[n].nte_index = source[n].nte_index; + (*actual)[n].nte_link = source[n].nte_link; + next_string(strings, &len); + } + } + } + return *actual; +} + +#define add_alias(field) \\ + if (source[n].field >= 0) { \\ + (*actual)[n].field = strings + source[n].field; \\ + } + +static const struct alias * +_nc_build_alias(struct alias **actual, + const alias_table_data *source, + const char *strings, + unsigned tablesize) +{ + if (*actual == 0) { + *actual = typeCalloc(struct alias, tablesize + 1); + if (*actual != 0) { + unsigned n; + for (n = 0; n < tablesize; ++n) { + add_alias(from); + add_alias(to); + add_alias(source); + } + } + } + return *actual; +} + +#define build_names(root) _nc_build_names(&_nc_##root##_table, \\ + root##_names_data, \\ + root##_names_text) +#define build_alias(root) _nc_build_alias(&_nc_##root##alias_table, \\ + root##alias_data, \\ + root##alias_text, \\ + SIZEOF(root##alias_data)) +#else +#define build_names(root) _nc_ ## root ## _table +#define build_alias(root) _nc_ ## root ## alias_table +#endif + +NCURSES_EXPORT(const struct name_table_entry *) _nc_get_table (bool termcap) +{ + return termcap ? build_names(cap) : build_names(info) ; +} + +NCURSES_EXPORT(const short *) _nc_get_hash_table (bool termcap) +{ + return termcap ? _nc_cap_hash_table: _nc_info_hash_table ; +} + +NCURSES_EXPORT(const struct alias *) _nc_get_alias_table (bool termcap) +{ + return termcap ? build_alias(cap) : build_alias(info) ; +} + +#if NO_LEAKS +NCURSES_EXPORT(void) _nc_comp_captab_leaks(void) +{ +#if $OPT1 + FreeIfNeeded(_nc_cap_table); + FreeIfNeeded(_nc_info_table); + FreeIfNeeded(_nc_capalias_table); + FreeIfNeeded(_nc_infoalias_table); +#endif +} +#endif /* NO_LEAKS */ +EOF diff --git a/lib/libcurses/tinfo/MKcodes.awk b/lib/libcurses/tinfo/MKcodes.awk new file mode 100644 index 00000000000..669f673c91b --- /dev/null +++ b/lib/libcurses/tinfo/MKcodes.awk @@ -0,0 +1,165 @@ +# $OpenBSD: MKcodes.awk,v 1.1 2010/01/12 23:22:06 nicm Exp $ +############################################################################## +# Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. # +# # +# Permission is hereby granted, free of charge, to any person obtaining a # +# copy of this software and associated documentation files (the "Software"), # +# to deal in the Software without restriction, including without limitation # +# the rights to use, copy, modify, merge, publish, distribute, distribute # +# with modifications, sublicense, and/or sell copies of the Software, and to # +# permit persons to whom the Software is furnished to do so, subject to the # +# following conditions: # +# # +# The above copyright notice and this permission notice shall be included in # +# all copies or substantial portions of the Software. # +# # +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # +# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # +# DEALINGS IN THE SOFTWARE. # +# # +# Except as contained in this notice, the name(s) of the above copyright # +# holders shall not be used in advertising or otherwise to promote the sale, # +# use or other dealings in this Software without prior written # +# authorization. # +############################################################################## +# $Id: MKcodes.awk,v 1.1 2010/01/12 23:22:06 nicm Exp $ +function large_item(value) { + result = sprintf("%d,", offset); + offset = offset + length(value) + 1; + offcol = offcol + length(result) + 2; + if (offcol > 70) { + result = result "\n"; + offcol = 0; + } else { + result = result " "; + } + bigstr = bigstr sprintf("\"%s\\0\" ", value); + bigcol = bigcol + length(value) + 5; + if (bigcol > 70) { + bigstr = bigstr "\\\n"; + bigcol = 0; + } + return result; +} + +function small_item(value) { + return sprintf("\t\t\"%s\",\n", value); +} + +function print_strings(name,value) { + printf "DCL(%s) = {\n", name + print value + print "\t\t(NCURSES_CONST char *)0," + print "};" + print "" +} + +function print_offsets(name,value) { + printf "static const short _nc_offset_%s[] = {\n", name + printf "%s", value + print "};" + print "" + printf "static NCURSES_CONST char ** ptr_%s = 0;\n", name + print "" +} + +BEGIN { + print "/* This file was generated by MKcodes.awk */" + print "" + print "#include <curses.priv.h>" + print "" + print "#define IT NCURSES_CONST char * const" + print "" + offset = 0; + offcol = 0; + bigcol = 0; + } + +$1 ~ /^#/ {next;} + +$1 == "SKIPWARN" {next;} + +$3 == "bool" { + small_boolcodes = small_boolcodes small_item($4); + large_boolcodes = large_boolcodes large_item($4); + } + +$3 == "num" { + small_numcodes = small_numcodes small_item($4); + large_numcodes = large_numcodes large_item($4); + } + +$3 == "str" { + small_strcodes = small_strcodes small_item($4); + large_strcodes = large_strcodes large_item($4); + } + +END { + print "" + print "#if BROKEN_LINKER || USE_REENTRANT" + print "" + print "#include <term.h>" + print "" + if (bigstrings) { + printf "static const char _nc_code_blob[] = \n" + printf "%s;\n", bigstr; + print_offsets("boolcodes", large_boolcodes); + print_offsets("numcodes", large_numcodes); + print_offsets("strcodes", large_strcodes); + print "" + print "static IT *" + print "alloc_array(NCURSES_CONST char ***value, const short *offsets, unsigned size)" + print "{" + print " if (*value == 0) {" + print " if ((*value = typeCalloc(NCURSES_CONST char *, size + 1)) != 0) {" + print " unsigned n;" + print " for (n = 0; n < size; ++n) {" + print " (*value)[n] = _nc_code_blob + offsets[n];" + print " }" + print " }" + print " }" + print " return *value;" + print "}" + print "" + print "#define FIX(it) NCURSES_IMPEXP IT * NCURSES_API _nc_##it(void) { return alloc_array(&ptr_##it, _nc_offset_##it, SIZEOF(_nc_offset_##it)); }" + } else { + print "#define DCL(it) static IT data##it[]" + print "" + print_strings("boolcodes", small_boolcodes); + print_strings("numcodes", small_numcodes); + print_strings("strcodes", small_strcodes); + print "#define FIX(it) NCURSES_IMPEXP IT * NCURSES_API _nc_##it(void) { return data##it; }" + } + print "" + print "FIX(boolcodes)" + print "FIX(numcodes)" + print "FIX(strcodes)" + print "" + print "#define FREE_FIX(it) if (ptr_##it) { FreeAndNull(ptr_##it); }" + print "" + print "#if NO_LEAKS" + print "NCURSES_EXPORT(void)" + print "_nc_codes_leaks(void)" + print "{" + if (bigstrings) { + print "FREE_FIX(boolcodes)" + print "FREE_FIX(numcodes)" + print "FREE_FIX(strcodes)" + } + print "}" + print "#endif" + print "" + print "#else" + print "" + print "#define DCL(it) NCURSES_EXPORT_VAR(IT) it[]" + print "" + print_strings("boolcodes", small_boolcodes); + print_strings("numcodes", small_numcodes); + print_strings("strcodes", small_strcodes); + print "" + print "#endif /* BROKEN_LINKER */" + } diff --git a/lib/libcurses/tinfo/MKfallback.sh b/lib/libcurses/tinfo/MKfallback.sh index ce7d14cb7a4..c33d8489e9f 100644 --- a/lib/libcurses/tinfo/MKfallback.sh +++ b/lib/libcurses/tinfo/MKfallback.sh @@ -1,6 +1,33 @@ #!/bin/sh -# $OpenBSD: MKfallback.sh,v 1.3 2001/01/22 18:01:50 millert Exp $ -# $From: MKfallback.sh,v 1.10 2000/12/10 00:14:39 tom Exp $ +# $OpenBSD: MKfallback.sh,v 1.4 2010/01/12 23:22:06 nicm Exp $ +############################################################################## +# Copyright (c) 1998-2001,2006 Free Software Foundation, Inc. # +# # +# Permission is hereby granted, free of charge, to any person obtaining a # +# copy of this software and associated documentation files (the "Software"), # +# to deal in the Software without restriction, including without limitation # +# the rights to use, copy, modify, merge, publish, distribute, distribute # +# with modifications, sublicense, and/or sell copies of the Software, and to # +# permit persons to whom the Software is furnished to do so, subject to the # +# following conditions: # +# # +# The above copyright notice and this permission notice shall be included in # +# all copies or substantial portions of the Software. # +# # +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # +# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # +# DEALINGS IN THE SOFTWARE. # +# # +# Except as contained in this notice, the name(s) of the above copyright # +# holders shall not be used in advertising or otherwise to promote the sale, # +# use or other dealings in this Software without prior written # +# authorization. # +############################################################################## +# $Id: MKfallback.sh,v 1.4 2010/01/12 23:22:06 nicm Exp $ # # MKfallback.sh -- create fallback table for entry reads # @@ -9,6 +36,7 @@ # from an on-disk terminfo tree) tries to match the type with one of a # specified list of types generated in. # + cat <<EOF /* * DO NOT EDIT THIS FILE BY HAND! It is generated by MKfallback.sh. diff --git a/lib/libcurses/tinfo/MKkeys_list.sh b/lib/libcurses/tinfo/MKkeys_list.sh new file mode 100644 index 00000000000..e28d899fedf --- /dev/null +++ b/lib/libcurses/tinfo/MKkeys_list.sh @@ -0,0 +1,63 @@ +#! /bin/sh +# $OpenBSD: MKkeys_list.sh,v 1.1 2010/01/12 23:22:06 nicm Exp $ +# $Id: MKkeys_list.sh,v 1.1 2010/01/12 23:22:06 nicm Exp $ +############################################################################## +# Copyright (c) 2001,2003 Free Software Foundation, Inc. # +# # +# Permission is hereby granted, free of charge, to any person obtaining a # +# copy of this software and associated documentation files (the "Software"), # +# to deal in the Software without restriction, including without limitation # +# the rights to use, copy, modify, merge, publish, distribute, distribute # +# with modifications, sublicense, and/or sell copies of the Software, and to # +# permit persons to whom the Software is furnished to do so, subject to the # +# following conditions: # +# # +# The above copyright notice and this permission notice shall be included in # +# all copies or substantial portions of the Software. # +# # +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # +# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # +# DEALINGS IN THE SOFTWARE. # +# # +# Except as contained in this notice, the name(s) of the above copyright # +# holders shall not be used in advertising or otherwise to promote the sale, # +# use or other dealings in this Software without prior written # +# authorization. # +############################################################################## +# +# MKkey_defs.sh -- generate list of function-keys for terminfo database +# +# Author: Thomas E. Dickey 2001 +# +# Extract function-key names from the Caps file +# +: ${AWK-awk} +DATA=${1-../../include/Caps} + +data=data$$ +trap 'rm -f $data' 0 1 2 5 15 +sed -e 's/[ ][ ]*/ /g' < $DATA >$data + +cat <<EOF +# These definitions were generated by $0 $DATA +KEY_BREAK +KEY_SRESET +KEY_RESET +KEY_RESIZE +EOF + +${AWK-awk} <$data ' +/^#/ {next;} +/^capalias/ {next;} +/^infoalias/ {next;} + +$5 != "-" { + if (substr($5, 1, 4) == "KEY_" ) { + printf "%s %s\n", $5, $1 + } +} +' diff --git a/lib/libcurses/tinfo/MKnames.awk b/lib/libcurses/tinfo/MKnames.awk index 5fdb8c20690..64ce6431fb7 100644 --- a/lib/libcurses/tinfo/MKnames.awk +++ b/lib/libcurses/tinfo/MKnames.awk @@ -1,99 +1,187 @@ -# $OpenBSD: MKnames.awk,v 1.2 2001/01/22 18:01:50 millert Exp $ -# $From: MKnames.awk,v 1.11 2000/12/09 23:46:13 tom Exp $ -BEGIN { - print "/* This file was generated by MKnames.awk */" > "namehdr" - print "" > "namehdr" - print "#include <curses.priv.h>" > "namehdr" - print "" > "namehdr" - print "#define IT NCURSES_CONST char * const" > "namehdr" - print "" > "namehdr" - print "#if BROKEN_LINKER" > "namehdr" - print "#include <term.h>" > "namehdr" - print "#define DCL(it) static IT data##it[]" > "namehdr" - print "#else" > "namehdr" - print "#define DCL(it) NCURSES_EXPORT_VAR(IT) it[]" > "namehdr" - print "#endif" > "namehdr" - print "" > "namehdr" - print "/*" > "boolnames" - print " * names.c - Arrays of capability names and codes" > "boolnames" - print " *" > "boolnames" - print " */" > "boolnames" - print "" > "boolnames" - print "DCL(boolnames) = {" > "boolnames" - print "DCL(boolfnames) = {" > "boolfnames" - print "DCL(boolcodes) = {" > "boolcodes" - print "DCL(numnames) = {" > "numnames" - print "DCL(numfnames) = {" > "numfnames" - print "DCL(numcodes) = {" > "numcodes" - print "DCL(strnames) = {" > "strnames" - print "DCL(strfnames) = {" > "strfnames" - print "DCL(strcodes) = {" > "strcodes" - } +# $OpenBSD: MKnames.awk,v 1.3 2010/01/12 23:22:06 nicm Exp $ +############################################################################## +# Copyright (c) 2007,2008 Free Software Foundation, Inc. # +# # +# Permission is hereby granted, free of charge, to any person obtaining a # +# copy of this software and associated documentation files (the "Software"), # +# to deal in the Software without restriction, including without limitation # +# the rights to use, copy, modify, merge, publish, distribute, distribute # +# with modifications, sublicense, and/or sell copies of the Software, and to # +# permit persons to whom the Software is furnished to do so, subject to the # +# following conditions: # +# # +# The above copyright notice and this permission notice shall be included in # +# all copies or substantial portions of the Software. # +# # +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # +# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # +# DEALINGS IN THE SOFTWARE. # +# # +# Except as contained in this notice, the name(s) of the above copyright # +# holders shall not be used in advertising or otherwise to promote the sale, # +# use or other dealings in this Software without prior written # +# authorization. # +############################################################################## +# $Id: MKnames.awk,v 1.3 2010/01/12 23:22:06 nicm Exp $ +function large_item(value) { + result = sprintf("%d,", offset); + offset = offset + length(value) + 1; + offcol = offcol + length(result) + 2; + if (offcol > 70) { + result = result "\n"; + offcol = 0; + } else { + result = result " "; + } + bigstr = bigstr sprintf("\"%s\\0\" ", value); + bigcol = bigcol + length(value) + 5; + if (bigcol > 70) { + bigstr = bigstr "\\\n"; + bigcol = 0; + } + return result; +} + +function small_item(value) { + return sprintf("\t\t\"%s\",\n", value); +} + +function print_strings(name,value) { + printf "DCL(%s) = {\n", name + print value + print "\t\t(NCURSES_CONST char *)0," + print "};" + print "" +} + +function print_offsets(name,value) { + printf "static const short _nc_offset_%s[] = {\n", name + printf "%s", value + print "};" + print "" + printf "static NCURSES_CONST char ** ptr_%s = 0;\n", name + print "" +} + +BEGIN { + print "/* This file was generated by MKnames.awk */" + print "" + print "#include <curses.priv.h>" + print "" + print "#define IT NCURSES_CONST char * const" + print "" + offset = 0; + offcol = 0; + bigcol = 0; + } $1 ~ /^#/ {next;} $1 == "SKIPWARN" {next;} $3 == "bool" { - printf "\t\t\"%s\",\n", $2 > "boolnames" - printf "\t\t\"%s\",\n", $1 > "boolfnames" - printf "\t\t\"%s\",\n", $4 > "boolcodes" + small_boolnames = small_boolnames small_item($2); + large_boolnames = large_boolnames large_item($2); + small_boolfnames = small_boolfnames small_item($1); + large_boolfnames = large_boolfnames large_item($1); } $3 == "num" { - printf "\t\t\"%s\",\n", $2 > "numnames" - printf "\t\t\"%s\",\n", $1 > "numfnames" - printf "\t\t\"%s\",\n", $4 > "numcodes" + small_numnames = small_numnames small_item($2); + large_numnames = large_numnames large_item($2); + small_numfnames = small_numfnames small_item($1); + large_numfnames = large_numfnames large_item($1); } $3 == "str" { - printf "\t\t\"%s\",\n", $2 > "strnames" - printf "\t\t\"%s\",\n", $1 > "strfnames" - printf "\t\t\"%s\",\n", $4 > "strcodes" + small_strnames = small_strnames small_item($2); + large_strnames = large_strnames large_item($2); + small_strfnames = small_strfnames small_item($1); + large_strfnames = large_strfnames large_item($1); } -END { - print "\t\t(NCURSES_CONST char *)0," > "boolnames" - print "};" > "boolnames" - print "" > "boolnames" - print "\t\t(NCURSES_CONST char *)0," > "boolfnames" - print "};" > "boolfnames" - print "" > "boolfnames" - print "\t\t(NCURSES_CONST char *)0," > "boolcodes" - print "};" > "boolcodes" - print "" > "boolcodes" - print "\t\t(NCURSES_CONST char *)0," > "numnames" - print "};" > "numnames" - print "" > "numnames" - print "\t\t(NCURSES_CONST char *)0," > "numfnames" - print "};" > "numfnames" - print "" > "numfnames" - print "\t\t(NCURSES_CONST char *)0," > "numcodes" - print "};" > "numcodes" - print "" > "numcodes" - print "\t\t(NCURSES_CONST char *)0," > "strnames" - print "};" > "strnames" - print "" > "strnames" - print "\t\t(NCURSES_CONST char *)0," > "strfnames" - print "};" > "strfnames" - print "" > "strfnames" - print "\t\t(NCURSES_CONST char *)0," > "strcodes" - print "};" > "strcodes" - print "" > "strcodes" - print "#if BROKEN_LINKER" > "nameftr" - print "#define FIX(it) NCURSES_IMPEXP IT * NCURSES_API _nc_##it(void) { return data##it; }" > "nameftr" - print "FIX(boolnames)" > "nameftr" - print "FIX(boolfnames)" > "nameftr" - print "FIX(numnames)" > "nameftr" - print "FIX(numfnames)" > "nameftr" - print "FIX(strnames)" > "nameftr" - print "FIX(strfnames)" > "nameftr" - print "#endif /* BROKEN_LINKER */" > "nameftr" - print "" > "codeftr" - print "#if BROKEN_LINKER" > "codeftr" - print "#define FIX(it) NCURSES_IMPEXP IT * NCURSES_API _nc_##it(void) { return data##it; }" > "codeftr" - print "FIX(boolcodes)" > "codeftr" - print "FIX(numcodes)" > "codeftr" - print "FIX(strcodes)" > "codeftr" - print "#endif /* BROKEN_LINKER */" > "codeftr" +END { + print "" + print "#if BROKEN_LINKER || USE_REENTRANT" + print "" + print "#include <term.h>" + print "" + if (bigstrings) { + printf "static const char _nc_name_blob[] = \n" + printf "%s;\n", bigstr; + print_offsets("boolfnames", large_boolfnames); + print_offsets("boolnames", large_boolnames); + print_offsets("numfnames", large_numfnames); + print_offsets("numnames", large_numnames); + print_offsets("strfnames", large_strfnames); + print_offsets("strnames", large_strnames); + print "" + print "static IT *" + print "alloc_array(NCURSES_CONST char ***value, const short *offsets, unsigned size)" + print "{" + print " if (*value == 0) {" + print " if ((*value = typeCalloc(NCURSES_CONST char *, size + 1)) != 0) {" + print " unsigned n;" + print " for (n = 0; n < size; ++n) {" + print " (*value)[n] = (NCURSES_CONST char *) _nc_name_blob + offsets[n];" + print " }" + print " }" + print " }" + print " return *value;" + print "}" + print "" + print "#define FIX(it) NCURSES_IMPEXP IT * NCURSES_API _nc_##it(void) { return alloc_array(&ptr_##it, _nc_offset_##it, SIZEOF(_nc_offset_##it)); }" + } else { + print "#define DCL(it) static IT data##it[]" + print "" + print_strings("boolnames", small_boolnames); + print_strings("boolfnames", small_boolfnames); + print_strings("numnames", small_numnames); + print_strings("numfnames", small_numfnames); + print_strings("strnames", small_strnames); + print_strings("strfnames", small_strfnames); + print "#define FIX(it) NCURSES_IMPEXP IT * NCURSES_API _nc_##it(void) { return data##it; }" + } + print "" + print "FIX(boolnames)" + print "FIX(boolfnames)" + print "FIX(numnames)" + print "FIX(numfnames)" + print "FIX(strnames)" + print "FIX(strfnames)" + print "" + print "" + print "#define FREE_FIX(it) if (ptr_##it) { FreeAndNull(ptr_##it); }" + print "" + print "#if NO_LEAKS" + print "NCURSES_EXPORT(void)" + print "_nc_names_leaks(void)" + print "{" + if (bigstrings) { + print "FREE_FIX(boolnames)" + print "FREE_FIX(boolfnames)" + print "FREE_FIX(numnames)" + print "FREE_FIX(numfnames)" + print "FREE_FIX(strnames)" + print "FREE_FIX(strfnames)" } + print "}" + print "#endif" + print "" + print "#else" + print "" + print "#define DCL(it) NCURSES_EXPORT_VAR(IT) it[]" + print "" + print_strings("boolnames", small_boolnames); + print_strings("boolfnames", small_boolfnames); + print_strings("numnames", small_numnames); + print_strings("numfnames", small_numfnames); + print_strings("strnames", small_strnames); + print_strings("strfnames", small_strfnames); + print "" + print "#endif /* BROKEN_LINKER */" + } diff --git a/lib/libcurses/tinfo/access.c b/lib/libcurses/tinfo/access.c index a4a184e699c..0ea39c1106c 100644 --- a/lib/libcurses/tinfo/access.c +++ b/lib/libcurses/tinfo/access.c @@ -1,5 +1,7 @@ +/* $OpenBSD: access.c,v 1.5 2010/01/12 23:22:06 nicm Exp $ */ + /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -27,27 +29,83 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey <dickey@clark.net> 1998,2000 * + * Author: Thomas E. Dickey * ****************************************************************************/ #include <curses.priv.h> + +#include <ctype.h> +#include <sys/stat.h> + #include <tic.h> +#include <nc_alloc.h> -MODULE_ID("$From: access.c,v 1.7 2000/12/10 02:55:07 tom Exp $") +MODULE_ID("$Id: access.c,v 1.5 2010/01/12 23:22:06 nicm Exp $") + +#define LOWERCASE(c) ((isalpha(UChar(c)) && isupper(UChar(c))) ? tolower(UChar(c)) : (c)) NCURSES_EXPORT(char *) -_nc_basename(char *path) +_nc_rootname(char *path) { - char *result = strrchr(path, '/'); + char *result = _nc_basename(path); +#if !MIXEDCASE_FILENAMES || defined(PROG_EXT) + static char *temp; + char *s; + + temp = strdup(result); + result = temp; +#if !MIXEDCASE_FILENAMES + for (s = result; *s != '\0'; ++s) { + *s = LOWERCASE(*s); + } +#endif +#if defined(PROG_EXT) + if ((s = strrchr(result, '.')) != 0) { + if (!strcmp(s, PROG_EXT)) + *s = '\0'; + } +#endif +#endif + return result; +} + +/* + * Check if a string appears to be an absolute pathname. + */ +NCURSES_EXPORT(bool) +_nc_is_abs_path(const char *path) +{ +#if defined(__EMX__) || defined(__DJGPP__) +#define is_pathname(s) ((((s) != 0) && ((s)[0] == '/')) \ + || (((s)[0] != 0) && ((s)[1] == ':'))) +#else +#define is_pathname(s) ((s) != 0 && (s)[0] == '/') +#endif + return is_pathname(path); +} + +/* + * Return index of the basename + */ +NCURSES_EXPORT(unsigned) +_nc_pathlast(const char *path) +{ + const char *test = strrchr(path, '/'); #ifdef __EMX__ - if (result == 0) - result = strrchr(path, '\\'); + if (test == 0) + test = strrchr(path, '\\'); #endif - if (result == 0) - result = path; + if (test == 0) + test = path; else - result++; - return result; + test++; + return (test - path); +} + +NCURSES_EXPORT(char *) +_nc_basename(char *path) +{ + return path + _nc_pathlast(path); } NCURSES_EXPORT(int) @@ -59,10 +117,10 @@ _nc_access(const char *path, int mode) && strlen(path) < PATH_MAX) { char *leaf, head[PATH_MAX]; - strlcpy(head, path, sizeof(head)); - if ((leaf = _nc_basename(head)) == 0) - leaf = head; - *leaf = '\0'; + strlcpy(head, path, sizeof(head)); + if ((leaf = _nc_basename(head)) == 0) + leaf = head; + *leaf = '\0'; if (head == leaf) (void) strlcpy(head, ".", sizeof(head)); @@ -73,6 +131,32 @@ _nc_access(const char *path, int mode) return 0; } +NCURSES_EXPORT(bool) +_nc_is_dir_path(const char *path) +{ + bool result = FALSE; + struct stat sb; + + if (stat(path, &sb) == 0 + && (sb.st_mode & S_IFMT) == S_IFDIR) { + result = TRUE; + } + return result; +} + +NCURSES_EXPORT(bool) +_nc_is_file_path(const char *path) +{ + bool result = FALSE; + struct stat sb; + + if (stat(path, &sb) == 0 + && (sb.st_mode & S_IFMT) == S_IFREG) { + result = TRUE; + } + return result; +} + #ifndef USE_ROOT_ENVIRON /* * Returns true if we allow application to use environment variables that are diff --git a/lib/libcurses/tinfo/add_tries.c b/lib/libcurses/tinfo/add_tries.c index 55ad69543d5..247087fd815 100644 --- a/lib/libcurses/tinfo/add_tries.c +++ b/lib/libcurses/tinfo/add_tries.c @@ -1,7 +1,7 @@ -/* $OpenBSD: add_tries.c,v 1.3 2001/01/22 18:01:50 millert Exp $ */ +/* $OpenBSD: add_tries.c,v 1.4 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,7 +29,7 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey <dickey@clark.net> 1998 * + * Author: Thomas E. Dickey 1998-on * ****************************************************************************/ /* @@ -41,20 +41,20 @@ #include <curses.priv.h> -MODULE_ID("$From: add_tries.c,v 1.4 2000/12/10 02:55:07 tom Exp $") +MODULE_ID("$Id: add_tries.c,v 1.4 2010/01/12 23:22:06 nicm Exp $") #define SET_TRY(dst,src) if ((dst->ch = *src++) == 128) dst->ch = '\0' #define CMP_TRY(a,b) ((a)? (a == b) : (b == 128)) -NCURSES_EXPORT(void) -_nc_add_to_try(struct tries **tree, const char *str, unsigned short code) +NCURSES_EXPORT(int) +_nc_add_to_try(TRIES ** tree, const char *str, unsigned code) { - static bool out_of_memory = FALSE; - struct tries *ptr, *savedptr; + TRIES *ptr, *savedptr; unsigned const char *txt = (unsigned const char *) str; - if (txt == 0 || *txt == '\0' || out_of_memory || code == 0) - return; + T((T_CALLED("_nc_add_to_try(%p, %s, %u)"), *tree, _nc_visbuf(str), code)); + if (txt == 0 || *txt == '\0' || code == 0) + returnCode(ERR); if ((*tree) != 0) { ptr = savedptr = (*tree); @@ -69,16 +69,15 @@ _nc_add_to_try(struct tries **tree, const char *str, unsigned short code) if (CMP_TRY(ptr->ch, cmp)) { if (*(++txt) == '\0') { ptr->value = code; - return; + returnCode(OK); } if (ptr->child != 0) ptr = ptr->child; else break; } else { - if ((ptr->sibling = typeCalloc(struct tries, 1)) == 0) { - out_of_memory = TRUE; - return; + if ((ptr->sibling = typeCalloc(TRIES, 1)) == 0) { + returnCode(ERR); } savedptr = ptr = ptr->sibling; @@ -89,11 +88,10 @@ _nc_add_to_try(struct tries **tree, const char *str, unsigned short code) } } /* end for (;;) */ } else { /* (*tree) == 0 :: First sequence to be added */ - savedptr = ptr = (*tree) = typeCalloc(struct tries, 1); + savedptr = ptr = (*tree) = typeCalloc(TRIES, 1); if (ptr == 0) { - out_of_memory = TRUE; - return; + returnCode(ERR); } SET_TRY(ptr, txt); @@ -103,19 +101,16 @@ _nc_add_to_try(struct tries **tree, const char *str, unsigned short code) /* at this point, we are adding to the try. ptr->child == 0 */ while (*txt) { - ptr->child = typeCalloc(struct tries, 1); + ptr->child = typeCalloc(TRIES, 1); ptr = ptr->child; if (ptr == 0) { - out_of_memory = TRUE; - while ((ptr = savedptr) != 0) { savedptr = ptr->child; free(ptr); } - - return; + returnCode(ERR); } SET_TRY(ptr, txt); @@ -123,5 +118,5 @@ _nc_add_to_try(struct tries **tree, const char *str, unsigned short code) } ptr->value = code; - return; + returnCode(OK); } diff --git a/lib/libcurses/tinfo/alloc_entry.c b/lib/libcurses/tinfo/alloc_entry.c index b0bab761de8..c0861482018 100644 --- a/lib/libcurses/tinfo/alloc_entry.c +++ b/lib/libcurses/tinfo/alloc_entry.c @@ -1,7 +1,7 @@ -/* $OpenBSD: alloc_entry.c,v 1.5 2003/03/18 16:55:54 millert Exp $ */ +/* $OpenBSD: alloc_entry.c,v 1.6 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2006,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -49,21 +50,31 @@ #include <tic.h> #include <term_entry.h> -MODULE_ID("$From: alloc_entry.c,v 1.35 2001/01/13 22:40:17 tom Exp $") +MODULE_ID("$Id: alloc_entry.c,v 1.6 2010/01/12 23:22:06 nicm Exp $") #define ABSENT_OFFSET -1 #define CANCELLED_OFFSET -2 #define MAX_STRTAB 4096 /* documented maximum entry size */ -static char stringbuf[MAX_STRTAB]; /* buffer for string capabilities */ +static char *stringbuf; /* buffer for string capabilities */ static size_t next_free; /* next free character in stringbuf */ NCURSES_EXPORT(void) -_nc_init_entry(TERMTYPE * const tp) +_nc_init_entry(TERMTYPE *const tp) /* initialize a terminal type data block */ { - int i; + unsigned i; + +#if NO_LEAKS + if (tp == 0 && stringbuf != 0) { + FreeAndNull(stringbuf); + return; + } +#endif + + if (stringbuf == 0) + stringbuf = (char *) malloc(MAX_STRTAB); #if NCURSES_XNAMES tp->num_Booleans = BOOLCOUNT; @@ -74,7 +85,7 @@ _nc_init_entry(TERMTYPE * const tp) tp->ext_Strings = 0; #endif if (tp->Booleans == 0) - tp->Booleans = typeMalloc(char, BOOLCOUNT); + tp->Booleans = typeMalloc(NCURSES_SBOOL, BOOLCOUNT); if (tp->Numbers == 0) tp->Numbers = typeMalloc(short, NUMCOUNT); if (tp->Strings == 0) @@ -104,28 +115,42 @@ _nc_copy_entry(ENTRY * oldp) return newp; } +/* save a copy of string in the string buffer */ NCURSES_EXPORT(char *) _nc_save_str(const char *const string) -/* save a copy of string in the string buffer */ { + char *result = 0; size_t old_next_free = next_free; - size_t len; - - len = strlcpy(stringbuf + next_free, string, sizeof(stringbuf) - next_free); - if (++len < sizeof(stringbuf) - next_free) { + size_t len = strlen(string) + 1; + + if (len == 1 && next_free != 0) { + /* + * Cheat a little by making an empty string point to the end of the + * previous string. + */ + if (next_free < MAX_STRTAB) { + result = (stringbuf + next_free - 1); + } + } else if (next_free + len < MAX_STRTAB) { + strlcpy(&stringbuf[next_free], string, MAX_STRTAB - next_free); DEBUG(7, ("Saved string %s", _nc_visbuf(string))); DEBUG(7, ("at location %d", (int) next_free)); next_free += len; + result = (stringbuf + old_next_free); + } else { + _nc_warning("Too much data, some is lost"); } - return (stringbuf + old_next_free); + return result; } NCURSES_EXPORT(void) _nc_wrap_entry(ENTRY * const ep, bool copy_strings) /* copy the string parts to allocated storage, preserving pointers to it */ { - int offsets[MAX_ENTRY_SIZE / 2], useoffsets[MAX_USES]; - int i, n; + int offsets[MAX_ENTRY_SIZE / sizeof(short)]; + int useoffsets[MAX_USES]; + unsigned i, n; + unsigned nuses = ep->nuses; TERMTYPE *tp = &(ep->tterm); if (copy_strings) { @@ -140,7 +165,7 @@ _nc_wrap_entry(ENTRY * const ep, bool copy_strings) } } - for (i = 0; i < ep->nuses; i++) { + for (i = 0; i < nuses; i++) { if (ep->uses[i].name == 0) { ep->uses[i].name = _nc_save_str(ep->uses[i].name); } @@ -149,17 +174,21 @@ _nc_wrap_entry(ENTRY * const ep, bool copy_strings) free(tp->str_table); } - n = tp->term_names - stringbuf; + assert(tp->term_names >= stringbuf); + n = (unsigned) (tp->term_names - stringbuf); for_each_string(i, &(ep->tterm)) { - if (tp->Strings[i] == ABSENT_STRING) - offsets[i] = ABSENT_OFFSET; - else if (tp->Strings[i] == CANCELLED_STRING) - offsets[i] = CANCELLED_OFFSET; - else - offsets[i] = tp->Strings[i] - stringbuf; + if (i < SIZEOF(offsets)) { + if (tp->Strings[i] == ABSENT_STRING) { + offsets[i] = ABSENT_OFFSET; + } else if (tp->Strings[i] == CANCELLED_STRING) { + offsets[i] = CANCELLED_OFFSET; + } else { + offsets[i] = tp->Strings[i] - stringbuf; + } + } } - for (i = 0; i < ep->nuses; i++) { + for (i = 0; i < nuses; i++) { if (ep->uses[i].name == 0) useoffsets[i] = ABSENT_OFFSET; else @@ -167,43 +196,48 @@ _nc_wrap_entry(ENTRY * const ep, bool copy_strings) } if ((tp->str_table = typeMalloc(char, next_free)) == (char *) 0) - _nc_err_abort("Out of memory"); + _nc_err_abort(MSG_NO_MEMORY); (void) memcpy(tp->str_table, stringbuf, next_free); tp->term_names = tp->str_table + n; for_each_string(i, &(ep->tterm)) { - if (offsets[i] == ABSENT_OFFSET) - tp->Strings[i] = ABSENT_STRING; - else if (offsets[i] == CANCELLED_OFFSET) - tp->Strings[i] = CANCELLED_STRING; - else - tp->Strings[i] = tp->str_table + offsets[i]; + if (i < SIZEOF(offsets)) { + if (offsets[i] == ABSENT_OFFSET) { + tp->Strings[i] = ABSENT_STRING; + } else if (offsets[i] == CANCELLED_OFFSET) { + tp->Strings[i] = CANCELLED_STRING; + } else { + tp->Strings[i] = tp->str_table + offsets[i]; + } + } } #if NCURSES_XNAMES if (!copy_strings) { - if ((n = NUM_EXT_NAMES(tp)) != 0) { - size_t copied, length, strtabsize = 0; - for (i = 0; i < n; i++) { - strtabsize += strlen(tp->ext_Names[i]) + 1; - offsets[i] = tp->ext_Names[i] - stringbuf; - } - if ((tp->ext_str_table = typeMalloc(char, strtabsize)) == 0) - _nc_err_abort("Out of memory"); - for (i = 0, length = 0; i < n; i++) { - tp->ext_Names[i] = tp->ext_str_table + length; - copied = strlcpy(tp->ext_Names[i], stringbuf + offsets[i], - strtabsize) + 1; - if (copied > strtabsize) - _nc_err_abort("Buffer overflow"); - length += copied; - strtabsize -= copied; + if ((n = (unsigned) NUM_EXT_NAMES(tp)) != 0) { + if (n < SIZEOF(offsets)) { + size_t copied, length, strtabsize = 0; + for (i = 0; i < n; i++) { + strtabsize += strlen(tp->ext_Names[i]) + 1; + offsets[i] = tp->ext_Names[i] - stringbuf; + } + if ((tp->ext_str_table = typeMalloc(char, strtabsize)) == 0) + _nc_err_abort(MSG_NO_MEMORY); + for (i = 0, length = 0; i < n; i++) { + tp->ext_Names[i] = tp->ext_str_table + length; + copied = strlcpy(tp->ext_Names[i], stringbuf + offsets[i], + strtabsize) + 1; + if (copied > strtabsize) + _nc_err_abort("Buffer overflow"); + length += copied; + strtabsize -= copied; + } } } } #endif - for (i = 0; i < ep->nuses; i++) { + for (i = 0; i < nuses; i++) { if (useoffsets[i] == ABSENT_OFFSET) ep->uses[i].name = 0; else @@ -212,31 +246,34 @@ _nc_wrap_entry(ENTRY * const ep, bool copy_strings) } NCURSES_EXPORT(void) -_nc_merge_entry -(TERMTYPE * const to, TERMTYPE * const from) +_nc_merge_entry(TERMTYPE *const to, TERMTYPE *const from) /* merge capabilities from `from' entry into `to' entry */ { - int i; + unsigned i; #if NCURSES_XNAMES _nc_align_termtype(to, from); #endif for_each_boolean(i, from) { - int mergebool = from->Booleans[i]; + if (to->Booleans[i] != (char) CANCELLED_BOOLEAN) { + int mergebool = from->Booleans[i]; - if (mergebool == CANCELLED_BOOLEAN) - to->Booleans[i] = FALSE; - else if (mergebool == TRUE) - to->Booleans[i] = mergebool; + if (mergebool == CANCELLED_BOOLEAN) + to->Booleans[i] = FALSE; + else if (mergebool == TRUE) + to->Booleans[i] = (char) mergebool; + } } for_each_number(i, from) { - int mergenum = from->Numbers[i]; + if (to->Numbers[i] != CANCELLED_NUMERIC) { + short mergenum = from->Numbers[i]; - if (mergenum == CANCELLED_NUMERIC) - to->Numbers[i] = ABSENT_NUMERIC; - else if (mergenum != ABSENT_NUMERIC) - to->Numbers[i] = mergenum; + if (mergenum == CANCELLED_NUMERIC) + to->Numbers[i] = ABSENT_NUMERIC; + else if (mergenum != ABSENT_NUMERIC) + to->Numbers[i] = mergenum; + } } /* @@ -245,11 +282,24 @@ _nc_merge_entry * we ever want to deallocate entries. */ for_each_string(i, from) { - char *mergestring = from->Strings[i]; + if (to->Strings[i] != CANCELLED_STRING) { + char *mergestring = from->Strings[i]; + + if (mergestring == CANCELLED_STRING) + to->Strings[i] = ABSENT_STRING; + else if (mergestring != ABSENT_STRING) + to->Strings[i] = mergestring; + } + } +} - if (mergestring == CANCELLED_STRING) - to->Strings[i] = ABSENT_STRING; - else if (mergestring != ABSENT_STRING) - to->Strings[i] = mergestring; +#if NO_LEAKS +NCURSES_EXPORT(void) +_nc_alloc_entry_leaks(void) +{ + if (stringbuf != 0) { + FreeAndNull(stringbuf); } + next_free = 0; } +#endif diff --git a/lib/libcurses/tinfo/alloc_ttype.c b/lib/libcurses/tinfo/alloc_ttype.c index 43583824c0f..f474e502be4 100644 --- a/lib/libcurses/tinfo/alloc_ttype.c +++ b/lib/libcurses/tinfo/alloc_ttype.c @@ -1,7 +1,7 @@ -/* $OpenBSD: alloc_ttype.c,v 1.5 2001/01/22 18:01:50 millert Exp $ */ +/* $OpenBSD: alloc_ttype.c,v 1.6 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1999-2006,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,7 +29,7 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey <dickey@clark.net> 1999 * + * Author: Thomas E. Dickey <dickey@clark.net> 1999-on * ****************************************************************************/ /* @@ -45,7 +45,7 @@ #include <tic.h> #include <term_entry.h> -MODULE_ID("$From: alloc_ttype.c,v 1.12 2000/12/10 02:55:07 tom Exp $") +MODULE_ID("$Id: alloc_ttype.c,v 1.6 2010/01/12 23:22:06 nicm Exp $") #if NCURSES_XNAMES /* @@ -94,15 +94,17 @@ find_name(char **table, int length, char *name) } static void -realign_data(TERMTYPE * to, char **ext_Names, int ext_Booleans, int - ext_Numbers, int ext_Strings) +realign_data(TERMTYPE *to, char **ext_Names, + int ext_Booleans, + int ext_Numbers, + int ext_Strings) { int n, m, base; int limit = (to->ext_Booleans + to->ext_Numbers + to->ext_Strings); if (to->ext_Booleans != ext_Booleans) { to->num_Booleans += (ext_Booleans - to->ext_Booleans); - to->Booleans = typeRealloc(char, to->num_Booleans, to->Booleans); + to->Booleans = typeRealloc(NCURSES_SBOOL, to->num_Booleans, to->Booleans); for (n = to->ext_Booleans - 1, m = ext_Booleans - 1, base = to->num_Booleans - (m + 1); m >= 0; m--) { @@ -148,7 +150,7 @@ realign_data(TERMTYPE * to, char **ext_Names, int ext_Booleans, int * Returns the first index in ext_Names[] for the given token-type */ static int -_nc_first_ext_name(TERMTYPE * tp, int token_type) +_nc_first_ext_name(TERMTYPE *tp, int token_type) { int first; @@ -173,7 +175,7 @@ _nc_first_ext_name(TERMTYPE * tp, int token_type) * Returns the last index in ext_Names[] for the given token-type */ static int -_nc_last_ext_name(TERMTYPE * tp, int token_type) +_nc_last_ext_name(TERMTYPE *tp, int token_type) { int last; @@ -196,7 +198,7 @@ _nc_last_ext_name(TERMTYPE * tp, int token_type) * Lookup an entry from extended-names, returning -1 if not found */ static int -_nc_find_ext_name(TERMTYPE * tp, char *name, int token_type) +_nc_find_ext_name(TERMTYPE *tp, char *name, int token_type) { unsigned j; unsigned first = _nc_first_ext_name(tp, token_type); @@ -215,7 +217,7 @@ _nc_find_ext_name(TERMTYPE * tp, char *name, int token_type) * (e.g., Booleans[]). */ static int -_nc_ext_data_index(TERMTYPE * tp, int n, int token_type) +_nc_ext_data_index(TERMTYPE *tp, int n, int token_type) { switch (token_type) { case BOOLEAN: @@ -238,7 +240,7 @@ _nc_ext_data_index(TERMTYPE * tp, int n, int token_type) * data. */ static bool -_nc_del_ext_name(TERMTYPE * tp, char *name, int token_type) +_nc_del_ext_name(TERMTYPE *tp, char *name, int token_type) { int j; int first, last; @@ -282,7 +284,7 @@ _nc_del_ext_name(TERMTYPE * tp, char *name, int token_type) * index into the corresponding data array is returned. */ static int -_nc_ins_ext_name(TERMTYPE * tp, char *name, int token_type) +_nc_ins_ext_name(TERMTYPE *tp, char *name, int token_type) { unsigned first = _nc_first_ext_name(tp, token_type); unsigned last = _nc_last_ext_name(tp, token_type); @@ -293,7 +295,7 @@ _nc_ins_ext_name(TERMTYPE * tp, char *name, int token_type) int cmp = strcmp(name, tp->ext_Names[j]); if (cmp == 0) /* already present */ - return _nc_ext_data_index(tp, j, token_type); + return _nc_ext_data_index(tp, (int) j, token_type); if (cmp < 0) { break; } @@ -303,13 +305,13 @@ _nc_ins_ext_name(TERMTYPE * tp, char *name, int token_type) for (k = total - 1; k > j; k--) tp->ext_Names[k] = tp->ext_Names[k - 1]; tp->ext_Names[j] = name; - j = _nc_ext_data_index(tp, j, token_type); + j = _nc_ext_data_index(tp, (int) j, token_type); switch (token_type) { case BOOLEAN: tp->ext_Booleans += 1; tp->num_Booleans += 1; - tp->Booleans = typeRealloc(char, tp->num_Booleans, tp->Booleans); + tp->Booleans = typeRealloc(NCURSES_SBOOL, tp->num_Booleans, tp->Booleans); for (k = tp->num_Booleans - 1; k > j; k--) tp->Booleans[k] = tp->Booleans[k - 1]; break; @@ -337,7 +339,7 @@ _nc_ins_ext_name(TERMTYPE * tp, char *name, int token_type) * cancellation of a name that is inherited from another entry. */ static void -adjust_cancels(TERMTYPE * to, TERMTYPE * from) +adjust_cancels(TERMTYPE *to, TERMTYPE *from) { int first = to->ext_Booleans + to->ext_Numbers; int last = first + to->ext_Strings; @@ -365,6 +367,17 @@ adjust_cancels(TERMTYPE * to, TERMTYPE * from) } else { j++; } + } else if ((k = _nc_find_ext_name(from, to->ext_Names[j], + STRING)) >= 0) { + if (_nc_del_ext_name(to, name, NUMBER) + || _nc_del_ext_name(to, name, BOOLEAN)) { + k = _nc_ins_ext_name(to, name, STRING); + to->Strings[k] = CANCELLED_STRING; + } else { + j++; + } + } else { + j++; } } else { j++; @@ -373,8 +386,7 @@ adjust_cancels(TERMTYPE * to, TERMTYPE * from) } NCURSES_EXPORT(void) -_nc_align_termtype -(TERMTYPE * to, TERMTYPE * from) +_nc_align_termtype(TERMTYPE *to, TERMTYPE *from) { int na = NUM_EXT_NAMES(to); int nb = NUM_EXT_NAMES(from); @@ -382,6 +394,7 @@ _nc_align_termtype bool same; char **ext_Names; int ext_Booleans, ext_Numbers, ext_Strings; + bool used_ext_Names = FALSE; DEBUG(2, ("align_termtype to(%d:%s), from(%d:%s)", na, to->term_names, nb, from->term_names)); @@ -445,6 +458,7 @@ _nc_align_termtype to->ext_Names = ext_Names; DEBUG(2, ("realigned %d extended names for '%s' (to)", NUM_EXT_NAMES(to), to->term_names)); + used_ext_Names = TRUE; } if (nb != (ext_Booleans + ext_Numbers + ext_Strings)) { nb = (ext_Booleans + ext_Numbers + ext_Strings); @@ -454,18 +468,19 @@ _nc_align_termtype DEBUG(2, ("realigned %d extended names for '%s' (from)", NUM_EXT_NAMES(from), from->term_names)); } + if (!used_ext_Names) + free(ext_Names); } } #endif NCURSES_EXPORT(void) -_nc_copy_termtype -(TERMTYPE * dst, TERMTYPE * src) +_nc_copy_termtype(TERMTYPE *dst, TERMTYPE *src) { - int i; + unsigned i; *dst = *src; /* ...to copy the sizes and string-tables */ - dst->Booleans = typeMalloc(char, NUM_BOOLEANS(dst)); + dst->Booleans = typeMalloc(NCURSES_SBOOL, NUM_BOOLEANS(dst)); dst->Numbers = typeMalloc(short, NUM_NUMBERS(dst)); dst->Strings = typeMalloc(char *, NUM_STRINGS(dst)); diff --git a/lib/libcurses/tinfo/captoinfo.c b/lib/libcurses/tinfo/captoinfo.c index 7c6a4587f58..6caf24560d1 100644 --- a/lib/libcurses/tinfo/captoinfo.c +++ b/lib/libcurses/tinfo/captoinfo.c @@ -1,7 +1,7 @@ -/* $OpenBSD: captoinfo.c,v 1.15 2006/10/24 17:25:48 moritz Exp $ */ +/* $OpenBSD: captoinfo.c,v 1.16 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2006,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -41,7 +42,7 @@ * * There is just one entry point: * - * char *_nc_captoinfo(n, s, parametrized) + * char *_nc_captoinfo(n, s, parameterized) * * Convert value s for termcap string capability named n into terminfo * format. @@ -94,7 +95,7 @@ #include <ctype.h> #include <tic.h> -MODULE_ID("$From: captoinfo.c,v 1.40 2000/11/05 00:22:36 tom Exp $") +MODULE_ID("$Id: captoinfo.c,v 1.16 2010/01/12 23:22:06 nicm Exp $") #define MAX_PUSHED 16 /* max # args we can push onto the stack */ @@ -117,7 +118,7 @@ init_string(void) if (my_string == 0) my_string = typeMalloc(char, my_length = 256); if (my_string == 0) - _nc_err_abort("Out of memory"); + _nc_err_abort(MSG_NO_MEMORY); *my_string = '\0'; return my_string; @@ -132,19 +133,19 @@ save_string(char *d, const char *const s) if (need > my_length) { my_string = (char *) realloc(my_string, my_length = (need + need)); if (my_string == 0) - _nc_err_abort("Out of memory"); + _nc_err_abort(MSG_NO_MEMORY); d = my_string + have; } if ((copied = strlcpy(d, s, my_length - have)) >= my_length - have) - _nc_err_abort("Buffer overflow"); + _nc_err_abort("Buffer overflow"); return d + copied; } -static inline char * -save_char(char *s, char c) +static NCURSES_INLINE char * +save_char(char *s, int c) { static char temp[2]; - temp[0] = c; + temp[0] = (char) c; return save_string(s, temp); } @@ -152,7 +153,7 @@ static void push(void) /* push onstack on to the stack */ { - if (stackptr > MAX_PUSHED) + if (stackptr >= MAX_PUSHED) _nc_warning("string too complex to convert"); else stack[stackptr++] = onstack; @@ -186,7 +187,7 @@ cvtchar(register const char *sp) case '$': case '\\': case '%': - c = *sp; + c = (unsigned char) (*sp); len = 2; break; case '\0': @@ -198,13 +199,13 @@ cvtchar(register const char *sp) case '2': case '3': len = 1; - while (isdigit(CharOf(*sp))) { + while (isdigit(UChar(*sp))) { c = 8 * c + (*sp++ - '0'); len++; } break; default: - c = *sp; + c = (unsigned char) (*sp); len = 2; break; } @@ -214,7 +215,7 @@ cvtchar(register const char *sp) len = 2; break; default: - c = *sp; + c = (unsigned char) (*sp); len = 1; } if (isgraph(c) && c != ',' && c != '\'' && c != '\\' && c != ':') { @@ -276,12 +277,12 @@ getparm(int parm, int n) * Convert a termcap string to terminfo format. * 'cap' is the relevant terminfo capability index. * 's' is the string value of the capability. - * 'parametrized' tells what type of translations to do: + * 'parameterized' tells what type of translations to do: * % translations if 1 * pad translations if >=0 */ -char * -_nc_captoinfo(const char *cap, const char *s, int const parametrized) +NCURSES_EXPORT(char *) +_nc_captoinfo(const char *cap, const char *s, int const parameterized) { const char *capstart; @@ -298,16 +299,16 @@ _nc_captoinfo(const char *cap, const char *s, int const parametrized) capstart = 0; if (s == 0) s = ""; - if (parametrized >= 0 && isdigit(CharOf(*s))) + if (parameterized >= 0 && isdigit(UChar(*s))) for (capstart = s;; s++) - if (!(isdigit(CharOf(*s)) || *s == '*' || *s == '.')) + if (!(isdigit(UChar(*s)) || *s == '*' || *s == '.')) break; while (*s != '\0') { switch (*s) { case '%': s++; - if (parametrized < 1) { + if (parameterized < 1) { dp = save_char(dp, '%'); break; } @@ -468,7 +469,7 @@ _nc_captoinfo(const char *cap, const char *s, int const parametrized) dp = save_char(dp, '%'); s--; _nc_warning("unknown %% code %s (%#x) in %s", - unctrl((chtype) * s), CharOf(*s), cap); + unctrl((chtype) *s), UChar(*s), cap); break; } break; @@ -549,7 +550,7 @@ _nc_captoinfo(const char *cap, const char *s, int const parametrized) if (capstart) { dp = save_string(dp, "$<"); for (s = capstart;; s++) - if (isdigit(CharOf(*s)) || *s == '*' || *s == '.') + if (isdigit(UChar(*s)) || *s == '*' || *s == '.') dp = save_char(dp, *s); else break; @@ -573,8 +574,8 @@ bcd_expression(const char *str) char ch1, ch2; if (sscanf(str, fmt, &ch1, &ch2) == 2 - && isdigit(CharOf(ch1)) - && isdigit(CharOf(ch2)) + && isdigit(UChar(ch1)) + && isdigit(UChar(ch2)) && (ch1 == ch2)) { len = 28; #ifndef NDEBUG @@ -640,8 +641,8 @@ save_tc_inequality(char *bufptr, int c1, int c2) * Convert a terminfo string to termcap format. Parameters are as in * _nc_captoinfo(). */ -char * -_nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parametrized) +NCURSES_EXPORT(char *) +_nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parameterized) { int seenone = 0, seentwo = 0, saw_m = 0, saw_n = 0; const char *padding; @@ -655,13 +656,13 @@ _nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parametrize padding = str + strlen(str) - 1; if (padding > str && *padding == '>' && *--padding == '/') { --padding; - while (isdigit(CharOf(*padding)) || *padding == '.' || *padding == '*') + while (isdigit(UChar(*padding)) || *padding == '.' || *padding == '*') padding--; if (padding > str && *padding == '<' && *--padding == '$') trimmed = padding; padding += 2; - while (isdigit(CharOf(*padding)) || *padding == '.' || *padding == '*') + while (isdigit(UChar(*padding)) || *padding == '.' || *padding == '*') bufptr = save_char(bufptr, *padding++); } @@ -673,7 +674,7 @@ _nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parametrize bufptr = save_char(bufptr, *++str); } else if (str[0] == '$' && str[1] == '<') { /* discard padding */ str += 2; - while (isdigit(CharOf(*str)) + while (isdigit(UChar(*str)) || *str == '.' || *str == '*' || *str == '/' @@ -682,7 +683,8 @@ _nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parametrize --str; } else if (str[0] == '%' && str[1] == '%') { /* escaped '%' */ bufptr = save_string(bufptr, "%%"); - } else if (*str != '%' || (parametrized < 1)) { + ++str; + } else if (*str != '%' || (parameterized < 1)) { bufptr = save_char(bufptr, *str); } else if (sscanf(str, "%%?%%{%d}%%>%%t%%{%d}%%+%%;", &c1, &c2) == 2) { str = strchr(str, ';'); @@ -741,7 +743,7 @@ _nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parametrize case '8': case '9': bufptr = save_char(bufptr, '%'); - while (isdigit(CharOf(*str))) + while (isdigit(UChar(*str))) bufptr = save_char(bufptr, *str++); if (strchr("doxX.", *str)) { if (*str != 'd') /* termcap doesn't have octal, hex */ @@ -790,6 +792,11 @@ _nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parametrize } /* endswitch (*str) */ } /* endelse (*str == '%') */ + /* + * 'str' always points to the end of what was scanned in this step, + * but that may not be the end of the string. + */ + assert(str != 0); if (*str == '\0') break; @@ -807,7 +814,7 @@ main(int argc, char *argv[]) { int c, tc = FALSE; - while ((c = getopt(argc, argv, "c")) != -1) + while ((c = getopt(argc, argv, "c")) != EOF) switch (c) { case 'c': tc = TRUE; @@ -817,7 +824,6 @@ main(int argc, char *argv[]) curr_line = 0; for (;;) { char buf[BUFSIZ]; - size_t buflen; ++curr_line; if (fgets(buf, sizeof(buf), stdin) == NULL) @@ -840,4 +846,13 @@ main(int argc, char *argv[]) } #endif /* MAIN */ -/* captoinfo.c ends here */ +#if NO_LEAKS +NCURSES_EXPORT(void) +_nc_captoinfo_leaks(void) +{ + if (my_string != 0) { + FreeAndNull(my_string); + } + my_length = 0; +} +#endif diff --git a/lib/libcurses/tinfo/comp_error.c b/lib/libcurses/tinfo/comp_error.c index 13259e1efc4..319bd5fb35b 100644 --- a/lib/libcurses/tinfo/comp_error.c +++ b/lib/libcurses/tinfo/comp_error.c @@ -1,7 +1,7 @@ -/* $OpenBSD: comp_error.c,v 1.5 2003/03/18 16:55:54 millert Exp $ */ +/* $OpenBSD: comp_error.c,v 1.6 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2005,2007 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -42,48 +43,62 @@ #include <tic.h> -MODULE_ID("$From: comp_error.c,v 1.21 2000/12/10 02:55:07 tom Exp $") +MODULE_ID("$Id: comp_error.c,v 1.6 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT_VAR(bool) _nc_suppress_warnings = FALSE; -NCURSES_EXPORT_VAR(int) -_nc_curr_line = 0; /* current line # in input */ -NCURSES_EXPORT_VAR(int) -_nc_curr_col = 0; /* current column # in input */ +NCURSES_EXPORT_VAR(int) _nc_curr_line = 0; /* current line # in input */ +NCURSES_EXPORT_VAR(int) _nc_curr_col = 0; /* current column # in input */ - static const char *sourcename; - static char termtype[MAX_NAME_SIZE + 1]; +#define SourceName _nc_globals.comp_sourcename +#define TermType _nc_globals.comp_termtype + +NCURSES_EXPORT(const char *) +_nc_get_source(void) +{ + return SourceName; +} NCURSES_EXPORT(void) _nc_set_source(const char *const name) { - sourcename = name; + SourceName = name; } NCURSES_EXPORT(void) _nc_set_type(const char *const name) { - if (name) - strlcpy(termtype, name, sizeof(termtype)); - else - termtype[0] = '\0'; + if (TermType == 0) + TermType = typeMalloc(char, MAX_NAME_SIZE + 1); + if (TermType != 0) { + TermType[0] = '\0'; + if (name) + strncat(TermType, name, MAX_NAME_SIZE); + } } NCURSES_EXPORT(void) _nc_get_type(char *name) { - strlcpy(name, termtype, MAX_NAME_SIZE + 1); +#if NO_LEAKS + if (name == 0 && TermType != 0) { + FreeAndNull(TermType); + return; + } +#endif + if (name != 0) + strlcpy(name, TermType != 0 ? TermType : "", MAX_NAME_SIZE + 1); } -static inline void +static NCURSES_INLINE void where_is_problem(void) { - fprintf(stderr, "\"%s\"", sourcename); + fprintf(stderr, "\"%s\"", SourceName ? SourceName : "?"); if (_nc_curr_line >= 0) fprintf(stderr, ", line %d", _nc_curr_line); if (_nc_curr_col >= 0) fprintf(stderr, ", col %d", _nc_curr_col); - if (termtype[0]) - fprintf(stderr, ", terminal '%s'", termtype); + if (TermType != 0 && TermType[0] != '\0') + fprintf(stderr, ", terminal '%s'", TermType); fputc(':', stderr); fputc(' ', stderr); } diff --git a/lib/libcurses/tinfo/comp_expand.c b/lib/libcurses/tinfo/comp_expand.c index e78d365168c..598592856da 100644 --- a/lib/libcurses/tinfo/comp_expand.c +++ b/lib/libcurses/tinfo/comp_expand.c @@ -1,7 +1,7 @@ -/* $OpenBSD: comp_expand.c,v 1.6 2007/06/02 01:29:11 pvalchev Exp $ */ +/* $OpenBSD: comp_expand.c,v 1.7 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -37,7 +37,7 @@ #include <ctype.h> #include <tic.h> -MODULE_ID("$From: comp_expand.c,v 1.15 2000/12/10 01:30:10 tom Exp $") +MODULE_ID("$Id: comp_expand.c,v 1.7 2010/01/12 23:22:06 nicm Exp $") static int trailing_spaces(const char *src) @@ -48,30 +48,37 @@ trailing_spaces(const char *src) } /* this deals with differences over whether 0x7f and 0x80..0x9f are controls */ -#define CHAR_OF(s) (*(unsigned const char *)(s)) -#define REALCTL(s) (CHAR_OF(s) < 127 && iscntrl(CHAR_OF(s))) -#define REALPRINT(s) (CHAR_OF(s) < 127 && isprint(CHAR_OF(s))) +#define REALCTL(s) (UChar(*(s)) < 127 && iscntrl(UChar(*(s)))) +#define REALPRINT(s) (UChar(*(s)) < 127 && isprint(UChar(*(s)))) NCURSES_EXPORT(char *) -_nc_tic_expand -(const char *srcp, bool tic_format, int numbers) +_nc_tic_expand(const char *srcp, bool tic_format, int numbers) { static char *buffer; static size_t length; int bufp; - const char *str = VALID_STRING(srcp) ? srcp : ""; + const char *str = VALID_STRING(srcp) ? srcp : "\0\0"; bool islong = (strlen(str) > 3); size_t need = (2 + strlen(str)) * 4; int ch; +#if NO_LEAKS + if (srcp == 0) { + if (buffer != 0) { + FreeAndNull(buffer); + length = 0; + } + return 0; + } +#endif if (buffer == 0 || need > length) { if ((buffer = typeRealloc(char, length = need, buffer)) == 0) return 0; } bufp = 0; - while ((ch = CharOf(*str)) != 0) { + while ((ch = UChar(*str)) != 0) { if (ch == '%' && REALPRINT(str + 1)) { buffer[bufp++] = *str++; /* @@ -101,7 +108,7 @@ _nc_tic_expand */ case 1: if (str[0] == L_BRACE - && isdigit(CharOf(str[1]))) { + && isdigit(UChar(str[1]))) { char *dst = 0; long value = strtol(str + 1, &dst, 0); if (dst != 0 @@ -114,7 +121,7 @@ _nc_tic_expand if (ch == '\\' || ch == S_QUOTE) buffer[bufp++] = '\\'; - buffer[bufp++] = ch; + buffer[bufp++] = (char) ch; buffer[bufp++] = S_QUOTE; str = dst; } else { @@ -143,13 +150,13 @@ _nc_tic_expand buffer[bufp++] = 's'; } else if ((ch == ',' || ch == ':' || ch == '^') && tic_format) { buffer[bufp++] = '\\'; - buffer[bufp++] = ch; + buffer[bufp++] = (char) ch; } else if (REALPRINT(str) && (ch != ',' && ch != ':' && !(ch == '!' && !tic_format) && ch != '^')) - buffer[bufp++] = ch; + buffer[bufp++] = (char) ch; #if 0 /* FIXME: this would be more readable (in fact the whole 'islong' logic should be removed) */ else if (ch == '\b') { buffer[bufp++] = '\\'; @@ -171,7 +178,7 @@ _nc_tic_expand } #define UnCtl(c) ((c) + '@') else if (REALCTL(str) && ch != '\\' - && (!islong || isdigit(CharOf(str[1])))) { + && (!islong || isdigit(UChar(str[1])))) { (void) snprintf(buffer + bufp, length - bufp, "^%c", UnCtl(ch)); bufp += strlen(buffer + bufp); } else { diff --git a/lib/libcurses/tinfo/comp_hash.c b/lib/libcurses/tinfo/comp_hash.c index a4b10f3c546..87856a7e040 100644 --- a/lib/libcurses/tinfo/comp_hash.c +++ b/lib/libcurses/tinfo/comp_hash.c @@ -1,7 +1,7 @@ -/* $OpenBSD: comp_hash.c,v 1.7 2007/03/20 03:40:06 tedu Exp $ */ +/* $OpenBSD: comp_hash.c,v 1.8 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,15 +31,16 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ - /* * comp_hash.c --- Routines to deal with the hashtable of capability * names. * */ +#define USE_TERMLIB 1 #include <curses.priv.h> #include <tic.h> @@ -48,12 +49,12 @@ #ifdef MAIN_PROGRAM #include <ctype.h> #undef DEBUG -#define DEBUG(level, params) /*nothing*/ +#define DEBUG(level, params) /*nothing */ #endif -MODULE_ID("$From: comp_hash.c,v 1.21 1999/06/26 21:25:11 tom Exp $") +MODULE_ID("$Id: comp_hash.c,v 1.8 2010/01/12 23:22:06 nicm Exp $") -static int hash_function(const char *); +static int hash_function(const char *); /* * _nc_make_hash_table() @@ -67,59 +68,61 @@ static int hash_function(const char *); #ifdef MAIN_PROGRAM #undef MODULE_ID -#define MODULE_ID(id) /*nothing*/ +#define MODULE_ID(id) /*nothing */ #include <tinfo/doalloc.c> -static void _nc_make_hash_table(struct name_table_entry *table, - struct name_table_entry **hash_table) +static void +_nc_make_hash_table(struct name_table_entry *table, + short *hash_table) { -int i; -int hashvalue; -int collisions = 0; - - for (i = 0; i < CAPTABSIZE; i++) { - hashvalue = hash_function(table[i].nte_name); - - if (hash_table[hashvalue] != (struct name_table_entry *) 0) - collisions++; - - if (hash_table[hashvalue] != 0) - table[i].nte_link = (short)(hash_table[hashvalue] - table); - hash_table[hashvalue] = &table[i]; - } - - DEBUG(4, ("Hash table complete: %d collisions out of %d entries", collisions, CAPTABSIZE)); + short i; + int hashvalue; + int collisions = 0; + + for (i = 0; i < HASHTABSIZE; i++) { + hash_table[i] = -1; + } + for (i = 0; i < CAPTABSIZE; i++) { + hashvalue = hash_function(table[i].nte_name); + + if (hash_table[hashvalue] >= 0) + collisions++; + + if (hash_table[hashvalue] != 0) + table[i].nte_link = hash_table[hashvalue]; + hash_table[hashvalue] = i; + } + + DEBUG(4, ("Hash table complete: %d collisions out of %d entries", + collisions, CAPTABSIZE)); } #endif - /* * int hash_function(string) * * Computes the hashing function on the given string. * * The current hash function is the sum of each consectutive pair - * of characters, taken as two-byte integers, mod Hashtabsize. + * of characters, taken as two-byte integers, mod HASHTABSIZE. * */ -static -int +static int hash_function(const char *string) { -long sum = 0; + long sum = 0; - DEBUG(9, ("hashing %s", string)); - while (*string) { - sum += (long)(*string + (*(string + 1) << 8)); - string++; - } + DEBUG(9, ("hashing %s", string)); + while (*string) { + sum += (long) (*string + (*(string + 1) << 8)); + string++; + } - DEBUG(9, ("sum is %ld", sum)); - return (int)(sum % HASHTABSIZE); + DEBUG(9, ("sum is %ld", sum)); + return (int) (sum % HASHTABSIZE); } - /* * struct name_table_entry * * find_entry(string) @@ -130,23 +133,27 @@ long sum = 0; */ #ifndef MAIN_PROGRAM -struct name_table_entry const * -_nc_find_entry(const char *string, const struct name_table_entry *const *hash_table) +NCURSES_EXPORT(struct name_table_entry const *) +_nc_find_entry(const char *string, + const short *hash_table) { -int hashvalue; -struct name_table_entry const *ptr; - - hashvalue = hash_function(string); - - if ((ptr = hash_table[hashvalue]) != 0) { - while (strcmp(ptr->nte_name, string) != 0) { - if (ptr->nte_link < 0) - return 0; - ptr = ptr->nte_link + hash_table[HASHTABSIZE]; - } + int hashvalue; + struct name_table_entry const *ptr = 0; + struct name_table_entry const *real_table; + + hashvalue = hash_function(string); + + if (hash_table[hashvalue] >= 0) { + real_table = _nc_get_table(hash_table != _nc_get_hash_table(FALSE)); + ptr = real_table + hash_table[hashvalue]; + while (strcmp(ptr->nte_name, string) != 0) { + if (ptr->nte_link < 0) + return 0; + ptr = real_table + (ptr->nte_link + hash_table[HASHTABSIZE]); } + } - return (ptr); + return (ptr); } /* @@ -160,19 +167,19 @@ struct name_table_entry const *ptr; * in the table or 0 if not found. */ -struct name_table_entry const * +NCURSES_EXPORT(struct name_table_entry const *) _nc_find_type_entry(const char *string, int type, const struct name_table_entry *table) { -struct name_table_entry const *ptr; + struct name_table_entry const *ptr; - for (ptr = table; ptr < table + CAPTABSIZE; ptr++) { - if (ptr->nte_type == type && strcmp(string, ptr->nte_name) == 0) - return(ptr); - } + for (ptr = table; ptr < table + CAPTABSIZE; ptr++) { + if (ptr->nte_type == type && strcmp(string, ptr->nte_name) == 0) + return (ptr); + } - return ((struct name_table_entry *)NULL); + return ((struct name_table_entry *) NULL); } #endif @@ -189,140 +196,177 @@ struct name_table_entry const *ptr; #define MAX_COLUMNS BUFSIZ /* this _has_ to be worst-case */ -static char **parse_columns(char *buffer) +static char ** +parse_columns(char *buffer) { - static char **list; - - int col = 0; - - if (list == 0 && (list = typeCalloc(char *, MAX_COLUMNS)) == 0) - return(0); - - if (*buffer != '#') { - while (*buffer != '\0') { - char *s; - for (s = buffer; (*s != '\0') && !isspace(*s); s++) - /*EMPTY*/; - if (s != buffer) { - char mark = *s; - *s = '\0'; - if ((s - buffer) > 1 - && (*buffer == '"') - && (s[-1] == '"')) { /* strip the quotes */ - buffer++; - s[-1] = '\0'; - } - list[col] = buffer; - col++; - if (mark == '\0') - break; - while (isspace(*++s)) - /*EMPTY*/; - buffer = s; - } else - break; + static char **list; + + int col = 0; + + if (list == 0 && (list = typeCalloc(char *, MAX_COLUMNS)) == 0) + return (0); + + if (*buffer != '#') { + while (*buffer != '\0') { + char *s; + for (s = buffer; (*s != '\0') && !isspace(UChar(*s)); s++) + /*EMPTY */ ; + if (s != buffer) { + char mark = *s; + *s = '\0'; + if ((s - buffer) > 1 + && (*buffer == '"') + && (s[-1] == '"')) { /* strip the quotes */ + assert(s > buffer + 1); + s[-1] = '\0'; + buffer++; } + list[col] = buffer; + col++; + if (mark == '\0') + break; + while (*++s && isspace(UChar(*s))) + /*EMPTY */ ; + buffer = s; + } else + break; } - return col ? list : 0; + } + return col ? list : 0; } -int main(int argc, char **argv) +int +main(int argc, char **argv) { - struct name_table_entry *name_table = typeCalloc(struct name_table_entry, CAPTABSIZE); - struct name_table_entry **hash_table = typeCalloc(struct name_table_entry *, HASHTABSIZE); - const char *root_name = ""; - int column = 0; - int n; - char buffer[BUFSIZ]; - - static const char * typenames[] = { "BOOLEAN", "NUMBER", "STRING" }; - - short BoolCount = 0; - short NumCount = 0; - short StrCount = 0; - - /* The first argument is the column-number (starting with 0). - * The second is the root name of the tables to generate. - */ - if (argc <= 2 - || (column = atoi(argv[1])) <= 0 - || (column >= MAX_COLUMNS) - || *(root_name = argv[2]) == 0) { - fprintf(stderr, "usage: make_hash column root_name\n"); - exit(EXIT_FAILURE); + struct name_table_entry *name_table = typeCalloc(struct + name_table_entry, CAPTABSIZE); + short *hash_table = typeCalloc(short, HASHTABSIZE); + const char *root_name = ""; + int column = 0; + int bigstring = 0; + int n; + char buffer[BUFSIZ]; + + static const char *typenames[] = + {"BOOLEAN", "NUMBER", "STRING"}; + + short BoolCount = 0; + short NumCount = 0; + short StrCount = 0; + + /* The first argument is the column-number (starting with 0). + * The second is the root name of the tables to generate. + */ + if (argc <= 3 + || (column = atoi(argv[1])) <= 0 + || (column >= MAX_COLUMNS) + || *(root_name = argv[2]) == 0 + || (bigstring = atoi(argv[3])) < 0 + || name_table == 0 + || hash_table == 0) { + fprintf(stderr, "usage: make_hash column root_name bigstring\n"); + exit(EXIT_FAILURE); + } + + /* + * Read the table into our arrays. + */ + for (n = 0; (n < CAPTABSIZE) && fgets(buffer, BUFSIZ, stdin);) { + char **list, *nlp = strchr(buffer, '\n'); + if (nlp) + *nlp = '\0'; + list = parse_columns(buffer); + if (list == 0) /* blank or comment */ + continue; + name_table[n].nte_link = -1; /* end-of-hash */ + name_table[n].nte_name = strdup(list[column]); + if (!strcmp(list[2], "bool")) { + name_table[n].nte_type = BOOLEAN; + name_table[n].nte_index = BoolCount++; + } else if (!strcmp(list[2], "num")) { + name_table[n].nte_type = NUMBER; + name_table[n].nte_index = NumCount++; + } else if (!strcmp(list[2], "str")) { + name_table[n].nte_type = STRING; + name_table[n].nte_index = StrCount++; + } else { + fprintf(stderr, "Unknown type: %s\n", list[2]); + exit(EXIT_FAILURE); } - - /* - * Read the table into our arrays. - */ - for (n = 0; (n < CAPTABSIZE) && fgets(buffer, BUFSIZ, stdin); ) { - char **list, *nlp = strchr(buffer, '\n'); - if (nlp) - *nlp = '\0'; - list = parse_columns(buffer); - if (list == 0) /* blank or comment */ - continue; - name_table[n].nte_link = -1; /* end-of-hash */ - name_table[n].nte_name = strdup(list[column]); - if (!strcmp(list[2], "bool")) { - name_table[n].nte_type = BOOLEAN; - name_table[n].nte_index = BoolCount++; - } else if (!strcmp(list[2], "num")) { - name_table[n].nte_type = NUMBER; - name_table[n].nte_index = NumCount++; - } else if (!strcmp(list[2], "str")) { - name_table[n].nte_type = STRING; - name_table[n].nte_index = StrCount++; - } else { - fprintf(stderr, "Unknown type: %s\n", list[2]); - exit(EXIT_FAILURE); - } - n++; + n++; + } + _nc_make_hash_table(name_table, hash_table); + + /* + * Write the compiled tables to standard output + */ + if (bigstring) { + int len = 0; + int nxt; + + printf("static const char %s_names_text[] = \\\n", root_name); + for (n = 0; n < CAPTABSIZE; n++) { + nxt = (int) strlen(name_table[n].nte_name) + 5; + if (nxt + len > 72) { + printf("\\\n"); + len = 0; + } + printf("\"%s\\0\" ", name_table[n].nte_name); + len += nxt; } - _nc_make_hash_table(name_table, hash_table); + printf(";\n\n"); - /* - * Write the compiled tables to standard output - */ - printf("static struct name_table_entry const _nc_%s_table[] =\n", - root_name); + len = 0; + printf("static name_table_data const %s_names_data[] =\n", + root_name); printf("{\n"); for (n = 0; n < CAPTABSIZE; n++) { - snprintf(buffer, sizeof(buffer), "\"%s\"", - name_table[n].nte_name); - printf("\t{ %15s,\t%10s,\t%3d, %3d }%c\n", - buffer, - typenames[name_table[n].nte_type], - name_table[n].nte_index, - name_table[n].nte_link, - n < CAPTABSIZE - 1 ? ',' : ' '); + printf("\t{ %15d,\t%10s,\t%3d, %3d }%c\n", + len, + typenames[name_table[n].nte_type], + name_table[n].nte_index, + name_table[n].nte_link, + n < CAPTABSIZE - 1 ? ',' : ' '); + len += (int) strlen(name_table[n].nte_name) + 1; } printf("};\n\n"); + printf("static struct name_table_entry *_nc_%s_table = 0;\n\n", root_name); + } else { - printf("const struct name_table_entry * const _nc_%s_hash_table[%d] =\n", - root_name, - HASHTABSIZE+1); + printf("static struct name_table_entry %s _nc_%s_table[] =\n", + bigstring ? "" : "const", + root_name); printf("{\n"); - for (n = 0; n < HASHTABSIZE; n++) { - if (hash_table[n] != 0) { - snprintf(buffer, sizeof(buffer), "_nc_%s_table + %3ld", - root_name, - (long) (hash_table[n] - name_table)); - } else { - buffer[0] = '0'; - buffer[1] = '\0'; - } - printf("\t%s,\n", buffer); + for (n = 0; n < CAPTABSIZE; n++) { + snprintf(buffer, sizeof(buffer), "\"%s\"", + name_table[n].nte_name); + printf("\t{ %15s,\t%10s,\t%3d, %3d }%c\n", + buffer, + typenames[name_table[n].nte_type], + name_table[n].nte_index, + name_table[n].nte_link, + n < CAPTABSIZE - 1 ? ',' : ' '); } - printf("\t_nc_%s_table\t/* base-of-table */\n", root_name); printf("};\n\n"); - - printf("#if (BOOLCOUNT!=%d)||(NUMCOUNT!=%d)||(STRCOUNT!=%d)\n", - BoolCount, NumCount, StrCount); - printf("#error\t--> term.h and comp_captab.c disagree about the <--\n"); - printf("#error\t--> numbers of booleans, numbers and/or strings <--\n"); - printf("#endif\n\n"); - - return EXIT_SUCCESS; + } + + printf("static const short _nc_%s_hash_table[%d] =\n", + root_name, + HASHTABSIZE + 1); + printf("{\n"); + for (n = 0; n < HASHTABSIZE; n++) { + printf("\t%3d,\n", hash_table[n]); + } + printf("\t0\t/* base-of-table */\n"); + printf("};\n\n"); + + printf("#if (BOOLCOUNT!=%d)||(NUMCOUNT!=%d)||(STRCOUNT!=%d)\n", + BoolCount, NumCount, StrCount); + printf("#error\t--> term.h and comp_captab.c disagree about the <--\n"); + printf("#error\t--> numbers of booleans, numbers and/or strings <--\n"); + printf("#endif\n\n"); + + free(hash_table); + return EXIT_SUCCESS; } #endif diff --git a/lib/libcurses/tinfo/comp_parse.c b/lib/libcurses/tinfo/comp_parse.c index 4c9b83497d3..1cf53acb120 100644 --- a/lib/libcurses/tinfo/comp_parse.c +++ b/lib/libcurses/tinfo/comp_parse.c @@ -1,7 +1,7 @@ -/* $OpenBSD: comp_parse.c,v 1.11 2003/03/18 16:55:54 millert Exp $ */ +/* $OpenBSD: comp_parse.c,v 1.12 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,18 +31,19 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* * comp_parse.c -- parser driver loop and use handling. * * _nc_read_entry_source(FILE *, literal, bool, bool (*hook)()) - * _nc_resolve_uses(void) + * _nc_resolve_uses2(void) * _nc_free_entries(void) * * Use this code by calling _nc_read_entry_source() on as many source * files as you like (either terminfo or termcap syntax). If you - * want use-resolution, call _nc_resolve_uses(). To free the list + * want use-resolution, call _nc_resolve_uses2(). To free the list * storage, do _nc_free_entries(). * */ @@ -54,43 +55,23 @@ #include <tic.h> #include <term_entry.h> -MODULE_ID("$From: comp_parse.c,v 1.48 2001/01/15 00:44:51 tom Exp $") +MODULE_ID("$Id: comp_parse.c,v 1.12 2010/01/12 23:22:06 nicm Exp $") +static void sanity_check2(TERMTYPE *, bool); +NCURSES_IMPEXP void NCURSES_API(*_nc_check_termtype2) (TERMTYPE *, bool) = sanity_check2; + +/* obsolete: 20040705 */ static void sanity_check(TERMTYPE *); NCURSES_IMPEXP void NCURSES_API(*_nc_check_termtype) (TERMTYPE *) = sanity_check; -/**************************************************************************** - * - * Entry queue handling - * - ****************************************************************************/ -/* - * The entry list is a doubly linked list with NULLs terminating the lists: - * - * --------- --------- --------- - * | | | | | | offset - * |-------| |-------| |-------| - * | ----+-->| ----+-->| NULL | next - * |-------| |-------| |-------| - * | NULL |<--+---- |<--+---- | last - * --------- --------- --------- - * ^ ^ - * | | - * | | - * _nc_head _nc_tail - */ - -NCURSES_EXPORT_VAR(ENTRY *) _nc_head = 0; -NCURSES_EXPORT_VAR(ENTRY *) _nc_tail = 0; - - static void - enqueue(ENTRY * ep) +static void +enqueue(ENTRY * ep) /* add an entry to the in-core list */ { ENTRY *newp = _nc_copy_entry(ep); if (newp == 0) - _nc_err_abort("Out of memory"); + _nc_err_abort(MSG_NO_MEMORY); newp->last = _nc_tail; _nc_tail = newp; @@ -100,43 +81,18 @@ NCURSES_EXPORT_VAR(ENTRY *) _nc_tail = 0; newp->last->next = newp; } -NCURSES_EXPORT(void) -_nc_free_entries(ENTRY * headp) -/* free the allocated storage consumed by list entries */ -{ - ENTRY *ep, *next; - - for (ep = headp; ep; ep = next) { - /* - * This conditional lets us disconnect storage from the list. - * To do this, copy an entry out of the list, then null out - * the string-table member in the original and any use entries - * it references. - */ - FreeIfNeeded(ep->tterm.str_table); - - next = ep->next; - - free(ep); - if (ep == _nc_head) - _nc_head = 0; - if (ep == _nc_tail) - _nc_tail = 0; - } -} - static char * force_bar(char *dst, char *src, size_t siz) { if (strchr(src, '|') == 0) { - size_t len; - - len = strlcpy(dst, src, siz); - if (len > siz - 2) - len = siz - 2; - dst[len++] = '|'; - dst[len] = '\0'; - src = dst; + size_t len; + + len = strlcpy(dst, src, siz); + if (len > siz - 2) + len = siz - 2; + dst[len++] = '|'; + dst[len] = '\0'; + src = dst; } return src; } @@ -167,7 +123,7 @@ _nc_entry_match(char *n1, char *n2) ****************************************************************************/ NCURSES_EXPORT(void) -_nc_read_entry_source(FILE * fp, char *buf, +_nc_read_entry_source(FILE *fp, char *buf, int literal, bool silent, bool(*hook) (ENTRY *)) /* slurp all entries in the given file into core */ @@ -184,18 +140,29 @@ _nc_read_entry_source(FILE * fp, char *buf, memset(&thisentry, 0, sizeof(thisentry)); if (_nc_parse_entry(&thisentry, literal, silent) == ERR) break; - if (!isalnum(CharOf(thisentry.tterm.term_names[0]))) + if (!isalnum(UChar(thisentry.tterm.term_names[0]))) _nc_err_abort("terminal names must start with letter or digit"); /* - * This can be used for immediate compilation of entries with no - * use references to disk, so as to avoid chewing up a lot of - * core when the resolution code could fetch entries off disk. + * This can be used for immediate compilation of entries with no "use=" + * references to disk. That avoids consuming a lot of memory when the + * resolution code could fetch entries off disk. */ - if (hook != NULLHOOK && (*hook) (&thisentry)) + if (hook != NULLHOOK && (*hook) (&thisentry)) { immediate++; - else + } else { enqueue(&thisentry); + /* + * The enqueued entry is copied with _nc_copy_termtype(), so we can + * free some of the data from thisentry, i.e., the arrays. + */ + FreeIfNeeded(thisentry.tterm.Booleans); + FreeIfNeeded(thisentry.tterm.Numbers); + FreeIfNeeded(thisentry.tterm.Strings); +#if NCURSES_XNAMES + FreeIfNeeded(thisentry.tterm.ext_Names); +#endif + } } if (_nc_tail) { @@ -215,12 +182,13 @@ _nc_read_entry_source(FILE * fp, char *buf, } NCURSES_EXPORT(int) -_nc_resolve_uses(bool fullresolve) +_nc_resolve_uses2(bool fullresolve, bool literal) /* try to resolve all use capabilities */ { ENTRY *qp, *rp, *lastread = 0; bool keepgoing; - int i, j, unresolved, total_unresolved, multiples; + unsigned i; + int unresolved, total_unresolved, multiples; DEBUG(2, ("RESOLUTION BEGINNING")); @@ -293,7 +261,7 @@ _nc_resolve_uses(bool fullresolve) rp = typeMalloc(ENTRY, 1); if (rp == 0) - _nc_err_abort("Out of memory"); + _nc_err_abort(MSG_NO_MEMORY); rp->tterm = thisterm; rp->nuses = 0; rp->next = lastread; @@ -324,8 +292,8 @@ _nc_resolve_uses(bool fullresolve) DEBUG(2, ("NAME RESOLUTION COMPLETED OK")); /* - * OK, at this point all (char *) references in `name' mwmbers - * have been successfully converred to (ENTRY *) pointers in + * OK, at this point all (char *) references in `name' members + * have been successfully converted to (ENTRY *) pointers in * `link' members. Time to do the actual merges. */ if (fullresolve) { @@ -351,10 +319,10 @@ _nc_resolve_uses(bool fullresolve) } /* - * First, make sure there's no garbage in the - * merge block. as a side effect, copy into - * the merged entry the name field and string - * table pointer. + * First, make sure there is no garbage in the + * merge block. As a side effect, copy into + * the merged entry the name field and string + * table pointer. */ _nc_copy_termtype(&merged, &(qp->tterm)); @@ -377,6 +345,9 @@ _nc_resolve_uses(bool fullresolve) FreeIfNeeded(qp->tterm.Booleans); FreeIfNeeded(qp->tterm.Numbers); FreeIfNeeded(qp->tterm.Strings); +#if NCURSES_XNAMES + FreeIfNeeded(qp->tterm.ext_Names); +#endif qp->tterm = merged; _nc_wrap_entry(qp, TRUE); @@ -393,26 +364,6 @@ _nc_resolve_uses(bool fullresolve) (keepgoing); DEBUG(2, ("MERGES COMPLETED OK")); - - /* - * The exit condition of the loop above is such that all entries - * must now be resolved. Now handle cancellations. In a resolved - * entry there should be no cancellation markers. - */ - for_entry_list(qp) { - for_each_boolean(j, &(qp->tterm)) { - if ((int) qp->tterm.Booleans[j] == CANCELLED_BOOLEAN) - qp->tterm.Booleans[j] = ABSENT_BOOLEAN; - } - for_each_number(j, &(qp->tterm)) { - if (qp->tterm.Numbers[j] == CANCELLED_NUMERIC) - qp->tterm.Numbers[j] = ABSENT_NUMERIC; - } - for_each_string(j, &(qp->tterm)) { - if (qp->tterm.Strings[j] == CANCELLED_STRING) - qp->tterm.Strings[j] = ABSENT_STRING; - } - } } /* @@ -430,7 +381,7 @@ _nc_resolve_uses(bool fullresolve) for_entry_list(qp) { _nc_curr_line = qp->startline; _nc_set_type(_nc_first_name(qp->tterm.term_names)); - _nc_check_termtype(&qp->tterm); + _nc_check_termtype2(&qp->tterm, literal); } DEBUG(2, ("SANITY CHECK FINISHED")); } @@ -438,6 +389,13 @@ _nc_resolve_uses(bool fullresolve) return (TRUE); } +/* obsolete: 20040705 */ +NCURSES_EXPORT(int) +_nc_resolve_uses(bool fullresolve) +{ + return _nc_resolve_uses2(fullresolve, FALSE); +} + /* * This bit of legerdemain turns all the terminfo variable names into * references to locations in the arrays Booleans, Numbers, and Strings --- @@ -448,7 +406,7 @@ _nc_resolve_uses(bool fullresolve) #define CUR tp-> static void -sanity_check(TERMTYPE * tp) +sanity_check2(TERMTYPE *tp, bool literal) { if (!PRESENT(exit_attribute_mode)) { #ifdef __UNUSED__ /* this casts too wide a net */ @@ -465,14 +423,24 @@ sanity_check(TERMTYPE * tp) || PRESENT(enter_reverse_mode))) _nc_warning("no exit_attribute_mode"); #endif /* __UNUSED__ */ - PAIRED(enter_standout_mode, exit_standout_mode) - PAIRED(enter_underline_mode, exit_underline_mode) + PAIRED(enter_standout_mode, exit_standout_mode); + PAIRED(enter_underline_mode, exit_underline_mode); + } + + /* we do this check/fix in postprocess_termcap(), but some packagers + * prefer to bypass it... + */ + if (!literal) { + if (acs_chars == 0 + && enter_alt_charset_mode != 0 + && exit_alt_charset_mode != 0) + acs_chars = strdup(VT_ACSC); + ANDMISSING(enter_alt_charset_mode, acs_chars); + ANDMISSING(exit_alt_charset_mode, acs_chars); } /* listed in structure-member order of first argument */ PAIRED(enter_alt_charset_mode, exit_alt_charset_mode); - ANDMISSING(enter_alt_charset_mode, acs_chars); - ANDMISSING(exit_alt_charset_mode, acs_chars); ANDMISSING(enter_blink_mode, exit_attribute_mode); ANDMISSING(enter_bold_mode, exit_attribute_mode); PAIRED(exit_ca_mode, enter_ca_mode); @@ -490,6 +458,38 @@ sanity_check(TERMTYPE * tp) PAIRED(enter_xon_mode, exit_xon_mode); PAIRED(enter_am_mode, exit_am_mode); ANDMISSING(label_off, label_on); +#ifdef remove_clock PAIRED(display_clock, remove_clock); +#endif ANDMISSING(set_color_pair, initialize_pair); } + +/* obsolete: 20040705 */ +static void +sanity_check(TERMTYPE *tp) +{ + sanity_check2(tp, FALSE); +} + +#if NO_LEAKS +NCURSES_EXPORT(void) +_nc_leaks_tic(void) +{ + _nc_alloc_entry_leaks(); + _nc_captoinfo_leaks(); + _nc_comp_captab_leaks(); + _nc_comp_scan_leaks(); +#if BROKEN_LINKER || USE_REENTRANT + _nc_names_leaks(); + _nc_codes_leaks(); +#endif + _nc_tic_expand(0, FALSE, 0); +} + +NCURSES_EXPORT(void) +_nc_free_tic(int code) +{ + _nc_leaks_tic(); + _nc_free_tinfo(code); +} +#endif diff --git a/lib/libcurses/tinfo/comp_scan.c b/lib/libcurses/tinfo/comp_scan.c index a241322f188..ff3b9ac7ff2 100644 --- a/lib/libcurses/tinfo/comp_scan.c +++ b/lib/libcurses/tinfo/comp_scan.c @@ -1,5 +1,7 @@ +/* $OpenBSD: comp_scan.c,v 1.15 2010/01/12 23:22:06 nicm Exp $ */ + /**************************************************************************** - * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc. * + * Copyright (c) 1998-2006,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996 on * ****************************************************************************/ /* @@ -50,7 +53,7 @@ #include <term_entry.h> #include <tic.h> -MODULE_ID("$From: comp_scan.c,v 1.54 2001/02/04 01:09:26 tom Exp $") +MODULE_ID("$Id: comp_scan.c,v 1.15 2010/01/12 23:22:06 nicm Exp $") /* * Maximum length of string capability we'll accept before raising an error. @@ -84,23 +87,207 @@ _nc_curr_token = *****************************************************************************/ static bool first_column; /* See 'next_char()' below */ +static bool had_newline; static char separator; /* capability separator */ static int pushtype; /* type of pushback token */ -static char pushname[MAX_NAME_SIZE + 1]; +static char *pushname; #if NCURSES_EXT_FUNCS NCURSES_EXPORT_VAR(bool) _nc_disable_period = FALSE; /* used by tic -a option */ #endif -static int last_char(void); -static int next_char(void); -static long stream_pos(void); -static bool end_of_stream(void); -static void push_back(char c); +/***************************************************************************** + * + * Character-stream handling + * + *****************************************************************************/ + +#define LEXBUFSIZ 1024 + +static char *bufptr; /* otherwise, the input buffer pointer */ +static char *bufstart; /* start of buffer so we can compute offsets */ +static FILE *yyin; /* scanner's input file descriptor */ + +/* + * _nc_reset_input() + * + * Resets the input-reading routines. Used on initialization, + * or after a seek has been done. Exactly one argument must be + * non-null. + */ + +NCURSES_EXPORT(void) +_nc_reset_input(FILE *fp, char *buf) +{ + pushtype = NO_PUSHBACK; + if (pushname != 0) + pushname[0] = '\0'; + yyin = fp; + bufstart = bufptr = buf; + _nc_curr_file_pos = 0L; + if (fp != 0) + _nc_curr_line = 0; + _nc_curr_col = 0; +} + +/* + * int last_char() + * + * Returns the final nonblank character on the current input buffer + */ +static int +last_char(void) +{ + size_t len = strlen(bufptr); + while (len--) { + if (!isspace(UChar(bufptr[len]))) + return bufptr[len]; + } + return 0; +} + +/* + * int next_char() + * + * Returns the next character in the input stream. Comments and leading + * white space are stripped. + * + * The global state variable 'firstcolumn' is set TRUE if the character + * returned is from the first column of the input line. + * + * The global variable _nc_curr_line is incremented for each new line. + * The global variable _nc_curr_file_pos is set to the file offset of the + * beginning of each line. + */ + +static int +next_char(void) +{ + static char *result; + static size_t allocated; + int the_char; + + if (!yyin) { + if (result != 0) { + FreeAndNull(result); + FreeAndNull(pushname); + allocated = 0; + } + /* + * An string with an embedded null will truncate the input. This is + * intentional (we don't read binary files here). + */ + if (bufptr == 0 || *bufptr == '\0') + return (EOF); + if (*bufptr == '\n') { + _nc_curr_line++; + _nc_curr_col = 0; + } else if (*bufptr == '\t') { + _nc_curr_col = (_nc_curr_col | 7); + } + } else if (!bufptr || !*bufptr) { + /* + * In theory this could be recoded to do its I/O one character at a + * time, saving the buffer space. In practice, this turns out to be + * quite hard to get completely right. Try it and see. If you + * succeed, don't forget to hack push_back() correspondingly. + */ + size_t used; + size_t len; + + do { + bufstart = 0; + used = 0; + do { + if (used + (LEXBUFSIZ / 4) >= allocated) { + allocated += (allocated + LEXBUFSIZ); + result = typeRealloc(char, allocated, result); + if (result == 0) + return (EOF); + bufstart = result; + } + if (used == 0) + _nc_curr_file_pos = ftell(yyin); + + if (fgets(result + used, (int) (allocated - used), yyin) != 0) { + bufstart = result; + if (used == 0) { + _nc_curr_line++; + _nc_curr_col = 0; + } + } else { + if (used != 0) + strlcat(result, "\n", allocated); + } + if ((bufptr = bufstart) != 0) { + used = strlen(bufptr); + while (iswhite(*bufptr)) { + if (*bufptr == '\t') { + _nc_curr_col = (_nc_curr_col | 7) + 1; + } else { + _nc_curr_col++; + } + bufptr++; + } + + /* + * Treat a trailing <cr><lf> the same as a <newline> so we + * can read files on OS/2, etc. + */ + if ((len = strlen(bufptr)) > 1) { + if (bufptr[len - 1] == '\n' + && bufptr[len - 2] == '\r') { + len--; + bufptr[len - 1] = '\n'; + bufptr[len] = '\0'; + } + } + } else { + return (EOF); + } + } while (bufptr[len - 1] != '\n'); /* complete a line */ + } while (result[0] == '#'); /* ignore comments */ + } else if (*bufptr == '\t') { + _nc_curr_col = (_nc_curr_col | 7); + } + + first_column = (bufptr == bufstart); + if (first_column) + had_newline = FALSE; + + _nc_curr_col++; + the_char = *bufptr++; + return UChar(the_char); +} + +static void +push_back(char c) +/* push a character back onto the input stream */ +{ + if (bufptr == bufstart) + _nc_syserr_abort("Can't backspace off beginning of line"); + *--bufptr = c; + _nc_curr_col--; +} + +static long +stream_pos(void) +/* return our current character position in the input stream */ +{ + return (yyin ? ftell(yyin) : (bufptr ? bufptr - bufstart : 0)); +} + +static bool +end_of_stream(void) +/* are we at end of input? */ +{ + return ((yyin ? feof(yyin) : (bufptr && *bufptr == '\0')) + ? TRUE : FALSE); +} /* Assume we may be looking at a termcap-style continuation */ -static inline int +static NCURSES_INLINE int eat_escaped_newline(int ch) { if (ch == '\\') @@ -109,6 +296,15 @@ eat_escaped_newline(int ch) return ch; } +#define TOK_BUF_SIZE MAX_ENTRY_SIZE + +#define OkToAdd() \ + ((tok_ptr - tok_buf) < (TOK_BUF_SIZE - 2)) + +#define AddCh(ch) \ + *tok_ptr++ = (char) ch; \ + *tok_ptr = '\0' + /* * int * get_token() @@ -146,41 +342,65 @@ NCURSES_EXPORT(int) _nc_get_token(bool silent) { static const char terminfo_punct[] = "@%&*!#"; - long number; - int type; - int ch; + static char *tok_buf; + + char *after_list; + char *after_name; char *numchk; + char *tok_ptr; + char *s; char numbuf[80]; - unsigned found; - static char buffer[MAX_ENTRY_SIZE]; - char *ptr; + int ch; int dot_flag = FALSE; + int type; + long number; long token_start; + unsigned found; +#ifdef TRACE + int old_line; + int old_col; +#endif if (pushtype != NO_PUSHBACK) { int retval = pushtype; - _nc_set_type(pushname); + _nc_set_type(pushname != 0 ? pushname : ""); DEBUG(3, ("pushed-back token: `%s', class %d", _nc_curr_token.tk_name, pushtype)); pushtype = NO_PUSHBACK; - pushname[0] = '\0'; + if (pushname != 0) + pushname[0] = '\0'; /* currtok wasn't altered by _nc_push_token() */ return (retval); } - if (end_of_stream()) + if (end_of_stream()) { + yyin = 0; + next_char(); /* frees its allocated memory */ + if (tok_buf != 0) { + if (_nc_curr_token.tk_name == tok_buf) + _nc_curr_token.tk_name = 0; + FreeAndNull(tok_buf); + } return (EOF); + } start_token: token_start = stream_pos(); - while ((ch = next_char()) == '\n' || iswhite(ch)) + while ((ch = next_char()) == '\n' || iswhite(ch)) { + if (ch == '\n') + had_newline = TRUE; continue; + } ch = eat_escaped_newline(ch); +#ifdef TRACE + old_line = _nc_curr_line; + old_col = _nc_curr_col; +#endif if (ch == EOF) type = EOF; else { @@ -206,33 +426,44 @@ _nc_get_token(bool silent) } /* have to make some punctuation chars legal for terminfo */ - if (!isalnum(ch) + if (!isalnum(UChar(ch)) #if NCURSES_EXT_FUNCS && !(ch == '.' && _nc_disable_period) #endif && !strchr(terminfo_punct, (char) ch)) { if (!silent) - _nc_warning("Illegal character (expected alphanumeric or %s) - %s", + _nc_warning("Illegal character (expected alphanumeric or %s) - '%s'", terminfo_punct, unctrl((chtype) ch)); _nc_panic_mode(separator); goto start_token; } - ptr = buffer; - *(ptr++) = ch; + if (tok_buf == 0) + tok_buf = typeMalloc(char, TOK_BUF_SIZE); - if (first_column) { - char *desc; +#ifdef TRACE + old_line = _nc_curr_line; + old_col = _nc_curr_col; +#endif + tok_ptr = tok_buf; + AddCh(ch); + if (first_column) { _nc_comment_start = token_start; _nc_comment_end = _nc_curr_file_pos; _nc_start_line = _nc_curr_line; _nc_syntax = ERR; + after_name = 0; + after_list = 0; while ((ch = next_char()) != '\n') { - if (ch == EOF) - _nc_err_abort("premature EOF"); - else if (ch == ':' && last_char() != ',') { + if (ch == EOF) { + _nc_err_abort(MSG_NO_INPUTS); + } else if (ch == '|') { + after_list = tok_ptr; + if (after_name == 0) + after_name = tok_ptr; + } else if (ch == ':' && last_char() != ',') { _nc_syntax = SYN_TERMCAP; separator = ':'; break; @@ -240,20 +471,29 @@ _nc_get_token(bool silent) _nc_syntax = SYN_TERMINFO; separator = ','; /* - * Fall-through here is not an accident. The idea is that - * if we see a comma, we figure this is terminfo unless we - * subsequently run into a colon -- but we don't stop - * looking for that colon until hitting a newline. This + * If we did not see a '|', then we found a name with no + * aliases or description. + */ + if (after_name == 0) + break; + /* + * If we see a comma, we assume this is terminfo unless we + * subsequently run into a colon. But we don't stop + * looking for a colon until hitting a newline. This * allows commas to be embedded in description fields of * either syntax. */ - /* FALLTHRU */ } else ch = eat_escaped_newline(ch); - *ptr++ = ch; + if (OkToAdd()) { + AddCh(ch); + } else { + ch = EOF; + break; + } } - ptr[0] = '\0'; + *tok_ptr = '\0'; if (_nc_syntax == ERR) { /* * Grrr...what we ought to do here is barf, complaining that @@ -265,65 +505,71 @@ _nc_get_token(bool silent) separator = ':'; } else if (_nc_syntax == SYN_TERMINFO) { /* throw away trailing /, *$/ */ - for (--ptr; iswhite(*ptr) || *ptr == ','; ptr--) + for (--tok_ptr; + iswhite(*tok_ptr) || *tok_ptr == ','; + tok_ptr--) continue; - ptr[1] = '\0'; + tok_ptr[1] = '\0'; } /* * This is the soonest we have the terminal name fetched. Set up - * for following warning messages. + * for following warning messages. If there's no '|', then there + * is no description. */ - ptr = strchr(buffer, '|'); - if (ptr == (char *) NULL) - ptr = buffer + strlen(buffer); - ch = *ptr; - *ptr = '\0'; - _nc_set_type(buffer); - *ptr = ch; + if (after_name != 0) { + ch = *after_name; + *after_name = '\0'; + _nc_set_type(tok_buf); + *after_name = (char) ch; + } /* * Compute the boundary between the aliases and the description * field for syntax-checking purposes. */ - desc = strrchr(buffer, '|'); - if (!silent && desc) { - if (*desc == '\0') - _nc_warning("empty longname field"); - else if (strchr(desc, ' ') == (char *) NULL) - _nc_warning("older tic versions may treat the description field as an alias"); + if (after_list != 0) { + if (!silent) { + if (*after_list == '\0') + _nc_warning("empty longname field"); + else if (strchr(after_list, ' ') == 0) + _nc_warning("older tic versions may treat the description field as an alias"); + } + } else { + after_list = tok_buf + strlen(tok_buf); + DEBUG(1, ("missing description")); } - if (!desc) - desc = buffer + strlen(buffer); /* * Whitespace in a name field other than the long name can confuse * rdist and some termcap tools. Slashes are a no-no. Other * special characters can be dangerous due to shell expansion. */ - for (ptr = buffer; ptr < desc; ptr++) { - if (isspace(CharOf(*ptr))) { + for (s = tok_buf; s < after_list; ++s) { + if (isspace(UChar(*s))) { if (!silent) _nc_warning("whitespace in name or alias field"); break; - } else if (*ptr == '/') { + } else if (*s == '/') { if (!silent) _nc_warning("slashes aren't allowed in names or aliases"); break; - } else if (strchr("$[]!*?", *ptr)) { + } else if (strchr("$[]!*?", *s)) { if (!silent) - _nc_warning("dubious character `%c' in name or alias field", *ptr); + _nc_warning("dubious character `%c' in name or alias field", *s); break; } } - ptr = buffer; - - _nc_curr_token.tk_name = buffer; + _nc_curr_token.tk_name = tok_buf; type = NAMES; } else { + if (had_newline && _nc_syntax == SYN_TERMCAP) { + _nc_warning("Missing backslash before newline"); + had_newline = FALSE; + } while ((ch = next_char()) != EOF) { - if (!isalnum(ch)) { + if (!isalnum(UChar(ch))) { if (_nc_syntax == SYN_TERMINFO) { if (ch != '_') break; @@ -332,30 +578,35 @@ _nc_get_token(bool silent) break; } } - *(ptr++) = ch; + if (OkToAdd()) { + AddCh(ch); + } else { + ch = EOF; + break; + } } - *ptr++ = '\0'; + *tok_ptr++ = '\0'; /* separate name/value in buffer */ switch (ch) { case ',': case ':': if (ch != separator) _nc_err_abort("Separator inconsistent with syntax"); - _nc_curr_token.tk_name = buffer; + _nc_curr_token.tk_name = tok_buf; type = BOOLEAN; break; case '@': if ((ch = next_char()) != separator && !silent) _nc_warning("Missing separator after `%s', have %s", - buffer, unctrl((chtype) ch)); - _nc_curr_token.tk_name = buffer; + tok_buf, unctrl((chtype) ch)); + _nc_curr_token.tk_name = tok_buf; type = CANCEL; break; case '#': found = 0; while (isalnum(ch = next_char())) { - numbuf[found++] = ch; + numbuf[found++] = (char) ch; if (found >= sizeof(numbuf) - 1) break; } @@ -363,21 +614,21 @@ _nc_get_token(bool silent) number = strtol(numbuf, &numchk, 0); if (!silent) { if (numchk == numbuf) - _nc_warning("no value given for `%s'", buffer); + _nc_warning("no value given for `%s'", tok_buf); if ((*numchk != '\0') || (ch != separator)) _nc_warning("Missing separator"); } - _nc_curr_token.tk_name = buffer; + _nc_curr_token.tk_name = tok_buf; _nc_curr_token.tk_valnumber = number; type = NUMBER; break; case '=': - ch = _nc_trans_string(ptr, buffer + sizeof(buffer)); + ch = _nc_trans_string(tok_ptr, tok_buf + TOK_BUF_SIZE); if (!silent && ch != separator) _nc_warning("Missing separator"); - _nc_curr_token.tk_name = buffer; - _nc_curr_token.tk_valstring = ptr; + _nc_curr_token.tk_name = tok_buf; + _nc_curr_token.tk_valstring = tok_ptr; type = STRING; break; @@ -388,7 +639,7 @@ _nc_get_token(bool silent) /* just to get rid of the compiler warning */ type = UNDEF; if (!silent) - _nc_warning("Illegal character - %s", unctrl((chtype) ch)); + _nc_warning("Illegal character - '%s'", unctrl((chtype) ch)); } } /* end else (first_column == FALSE) */ } /* end else (ch != EOF) */ @@ -399,6 +650,11 @@ _nc_get_token(bool silent) if (dot_flag == TRUE) DEBUG(8, ("Commented out ")); + if (_nc_tracing >= DEBUG_LEVEL(8)) { + _tracef("parsed %d.%d to %d.%d", + old_line, old_col, + _nc_curr_line, _nc_curr_col); + } if (_nc_tracing >= DEBUG_LEVEL(7)) { switch (type) { case BOOLEAN: @@ -443,8 +699,9 @@ _nc_get_token(bool silent) type = _nc_get_token(silent); DEBUG(3, ("token: `%s', class %d", - _nc_curr_token.tk_name != 0 ? _nc_curr_token.tk_name : - "<null>", + ((_nc_curr_token.tk_name != 0) + ? _nc_curr_token.tk_name + : "<null>"), type)); return (type); @@ -469,7 +726,7 @@ _nc_get_token(bool silent) * */ -NCURSES_EXPORT(char) +NCURSES_EXPORT(int) _nc_trans_string(char *ptr, char *last) { int count = 0; @@ -480,17 +737,24 @@ _nc_trans_string(char *ptr, char *last) bool long_warning = FALSE; while ((ch = c = next_char()) != (chtype) separator && c != EOF) { - if (ptr == (last - 1)) + if (ptr >= (last - 1)) { + if (c != EOF) { + while ((c = next_char()) != separator && c != EOF) { + ; + } + ch = c; + } break; + } if ((_nc_syntax == SYN_TERMCAP) && c == '\n') break; if (ch == '^' && last_ch != '%') { ch = c = next_char(); if (c == EOF) - _nc_err_abort("Premature EOF"); + _nc_err_abort(MSG_NO_INPUTS); if (!(is7bits(ch) && isprint(ch))) { - _nc_warning("Illegal ^ character - %s", unctrl(ch)); + _nc_warning("Illegal ^ character - '%s'", unctrl(ch)); } if (ch == '?') { *(ptr++) = '\177'; @@ -504,14 +768,14 @@ _nc_trans_string(char *ptr, char *last) } else if (ch == '\\') { ch = c = next_char(); if (c == EOF) - _nc_err_abort("Premature EOF"); + _nc_err_abort(MSG_NO_INPUTS); if (ch >= '0' && ch <= '7') { number = ch - '0'; for (i = 0; i < 2; i++) { ch = c = next_char(); if (c == EOF) - _nc_err_abort("Premature EOF"); + _nc_err_abort(MSG_NO_INPUTS); if (c < '0' || c > '7') { if (isdigit(c)) { @@ -585,21 +849,31 @@ _nc_trans_string(char *ptr, char *last) continue; default: - _nc_warning("Illegal character %s in \\ sequence", + _nc_warning("Illegal character '%s' in \\ sequence", unctrl(ch)); + /* FALLTHRU */ + case '|': *(ptr++) = (char) ch; } /* endswitch (ch) */ } /* endelse (ch < '0' || ch > '7') */ } /* end else if (ch == '\\') */ else if (ch == '\n' && (_nc_syntax == SYN_TERMINFO)) { - /* newlines embedded in a terminfo string are ignored */ + /* + * Newlines embedded in a terminfo string are ignored, provided + * that the next line begins with whitespace. + */ ignored = TRUE; } else { *(ptr++) = (char) ch; } if (!ignored) { + if (_nc_curr_col <= 1) { + push_back((char) ch); + ch = '\n'; + break; + } last_ch = ch; count++; } @@ -629,14 +903,19 @@ _nc_push_token(int tokclass) /* * This implementation is kind of bogus, it will fail if we ever do more * than one pushback at a time between get_token() calls. It relies on the - * fact that curr_tok is static storage that nothing but get_token() - * touches. + * fact that _nc_curr_token is static storage that nothing but + * _nc_get_token() touches. */ pushtype = tokclass; + if (pushname == 0) + pushname = typeMalloc(char, MAX_NAME_SIZE + 1); _nc_get_type(pushname); DEBUG(3, ("pushing token: `%s', class %d", - _nc_curr_token.tk_name, pushtype)); + ((_nc_curr_token.tk_name != 0) + ? _nc_curr_token.tk_name + : "<null>"), + pushtype)); } /* @@ -656,168 +935,12 @@ _nc_panic_mode(char ch) } } -/***************************************************************************** - * - * Character-stream handling - * - *****************************************************************************/ - -#define LEXBUFSIZ 1024 - -static char *bufptr; /* otherwise, the input buffer pointer */ -static char *bufstart; /* start of buffer so we can compute offsets */ -static FILE *yyin; /* scanner's input file descriptor */ - -/* - * _nc_reset_input() - * - * Resets the input-reading routines. Used on initialization, - * or after a seek has been done. Exactly one argument must be - * non-null. - */ - +#if NO_LEAKS NCURSES_EXPORT(void) -_nc_reset_input(FILE * fp, char *buf) -{ - pushtype = NO_PUSHBACK; - pushname[0] = '\0'; - yyin = fp; - bufstart = bufptr = buf; - _nc_curr_file_pos = 0L; - if (fp != 0) - _nc_curr_line = 0; - _nc_curr_col = 0; -} - -/* - * int last_char() - * - * Returns the final nonblank character on the current input buffer - */ -static int -last_char(void) -{ - size_t len = strlen(bufptr); - while (len--) { - if (!isspace(CharOf(bufptr[len]))) - return bufptr[len]; - } - return 0; -} - -/* - * int next_char() - * - * Returns the next character in the input stream. Comments and leading - * white space are stripped. - * - * The global state variable 'firstcolumn' is set TRUE if the character - * returned is from the first column of the input line. - * - * The global variable _nc_curr_line is incremented for each new line. - * The global variable _nc_curr_file_pos is set to the file offset of the - * beginning of each line. - */ - -static int -next_char(void) +_nc_comp_scan_leaks(void) { - if (!yyin) { - /* - * An string with an embedded null will truncate the input. This is - * intentional (we don't read binary files here). - */ - if (*bufptr == '\0') - return (EOF); - if (*bufptr == '\n') { - _nc_curr_line++; - _nc_curr_col = 0; - } - } else if (!bufptr || !*bufptr) { - /* - * In theory this could be recoded to do its I/O one character at a - * time, saving the buffer space. In practice, this turns out to be - * quite hard to get completely right. Try it and see. If you - * succeed, don't forget to hack push_back() correspondingly. - */ - static char *result; - static size_t allocated; - size_t used; - size_t len; - - do { - bufstart = 0; - used = 0; - do { - if (used + (LEXBUFSIZ / 4) >= allocated) { - allocated += (allocated + LEXBUFSIZ); - result = _nc_doalloc(result, allocated); - if (result == 0) - return (EOF); - } - if (used == 0) - _nc_curr_file_pos = ftell(yyin); - - if (fgets(result + used, allocated - used, yyin) != NULL) { - bufstart = result; - if (used == 0) { - _nc_curr_line++; - _nc_curr_col = 0; - } - } else { - if (used != 0) - strlcat(result, "\n", allocated); - } - if ((bufptr = bufstart) != 0) { - used = strlen(bufptr); - while (iswhite(*bufptr)) - bufptr++; - - /* - * Treat a trailing <cr><lf> the same as a <newline> so we - * can read files on OS/2, etc. - */ - if ((len = strlen(bufptr)) > 1) { - if (bufptr[len - 1] == '\n' - && bufptr[len - 2] == '\r') { - len--; - bufptr[len - 1] = '\n'; - bufptr[len] = '\0'; - } - } - } else { - return (EOF); - } - } while (bufptr[len - 1] != '\n'); /* complete a line */ - } while (result[0] == '#'); /* ignore comments */ + if (pushname != 0) { + FreeAndNull(pushname); } - - first_column = (bufptr == bufstart); - - _nc_curr_col++; - return (*bufptr++); -} - -static void -push_back(char c) -/* push a character back onto the input stream */ -{ - if (bufptr == bufstart) - _nc_syserr_abort("Can't backspace off beginning of line"); - *--bufptr = c; -} - -static long -stream_pos(void) -/* return our current character position in the input stream */ -{ - return (yyin ? ftell(yyin) : (bufptr ? bufptr - bufstart : 0)); -} - -static bool -end_of_stream(void) -/* are we at end of input? */ -{ - return ((yyin ? feof(yyin) : (bufptr && *bufptr == '\0')) - ? TRUE : FALSE); } +#endif diff --git a/lib/libcurses/tinfo/db_iterator.c b/lib/libcurses/tinfo/db_iterator.c new file mode 100644 index 00000000000..84418492672 --- /dev/null +++ b/lib/libcurses/tinfo/db_iterator.c @@ -0,0 +1,227 @@ +/* $OpenBSD: db_iterator.c,v 1.1 2010/01/12 23:22:06 nicm Exp $ */ + +/**************************************************************************** + * Copyright (c) 2006,2007 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey * + ****************************************************************************/ + +/* + * Iterators for terminal databases. + */ + +#include <curses.priv.h> + +#include <tic.h> + +MODULE_ID("$Id: db_iterator.c,v 1.1 2010/01/12 23:22:06 nicm Exp $") + +#define HaveTicDirectory _nc_globals.have_tic_directory +#define KeepTicDirectory _nc_globals.keep_tic_directory +#define TicDirectory _nc_globals.tic_directory + +/* + * Record the "official" location of the terminfo directory, according to + * the place where we're writing to, or the normal default, if not. + */ +NCURSES_EXPORT(const char *) +_nc_tic_dir(const char *path) +{ + if (!KeepTicDirectory) { + if (path != 0) { + TicDirectory = path; + HaveTicDirectory = TRUE; + } else if (!HaveTicDirectory && use_terminfo_vars()) { + char *envp; + if ((envp = getenv("TERMINFO")) != 0) + return _nc_tic_dir(envp); + } + } + return TicDirectory; +} + +/* + * Special fix to prevent the terminfo directory from being moved after tic + * has chdir'd to it. If we let it be changed, then if $TERMINFO has a + * relative path, we'll lose track of the actual directory. + */ +NCURSES_EXPORT(void) +_nc_keep_tic_dir(const char *path) +{ + _nc_tic_dir(path); + KeepTicDirectory = TRUE; +} + +/* + * Process the list of :-separated directories, looking for the terminal type. + * We don't use strtok because it does not show us empty tokens. + */ +#define ThisDbList _nc_globals.dbi_list +#define ThisDbSize _nc_globals.dbi_size + +/* + * Cleanup. + */ +NCURSES_EXPORT(void) +_nc_last_db(void) +{ + if (ThisDbList != 0) { + FreeAndNull(ThisDbList); + } + ThisDbSize = 0; +} + +/* The TERMINFO_DIRS value, if defined by the configure script, begins with a + * ":", which will be interpreted as TERMINFO. + */ +static const char * +next_list_item(const char *source, int *offset) +{ + if (source != 0) { + FreeIfNeeded(ThisDbList); + ThisDbList = strdup(source); + ThisDbSize = strlen(source); + } + + if (ThisDbList != 0 && ThisDbSize && *offset < ThisDbSize) { + static char system_db[] = TERMINFO; + char *result = ThisDbList + *offset; + char *marker = strchr(result, NCURSES_PATHSEP); + + /* + * Put a null on the marker if a separator was found. Set the offset + * to the next position after the marker so we can call this function + * again, using the data at the offset. + */ + if (marker == 0) { + *offset += strlen(result) + 1; + marker = result + *offset; + } else { + *marker++ = 0; + *offset = marker - ThisDbList; + } + if (*result == 0 && result != (ThisDbList + ThisDbSize)) + result = system_db; + return result; + } + return 0; +} + +#define NEXT_DBD(var, offset) next_list_item((*offset == 0) ? var : 0, offset) + +/* + * This is a simple iterator which allows the caller to step through the + * possible locations for a terminfo directory. ncurses uses this to find + * terminfo files to read. + */ +NCURSES_EXPORT(const char *) +_nc_next_db(DBDIRS * state, int *offset) +{ + const char *result; + char *envp; + + while (*state < dbdLAST) { + DBDIRS next = (DBDIRS) ((int) (*state) + 1); + + result = 0; + + switch (*state) { + case dbdTIC: + if (HaveTicDirectory) + result = _nc_tic_dir(0); + break; +#if USE_DATABASE + case dbdEnvOnce: + if (use_terminfo_vars()) { + if ((envp = getenv("TERMINFO")) != 0) + result = _nc_tic_dir(envp); + } + break; + case dbdHome: + if (use_terminfo_vars()) { + result = _nc_home_terminfo(); + } + break; + case dbdEnvList: + if (use_terminfo_vars()) { + if ((result = NEXT_DBD(getenv("TERMINFO_DIRS"), offset)) != 0) + next = *state; + } + break; + case dbdCfgList: +#ifdef TERMINFO_DIRS + if ((result = NEXT_DBD(TERMINFO_DIRS, offset)) != 0) + next = *state; +#endif + break; + case dbdCfgOnce: +#ifndef TERMINFO_DIRS + result = TERMINFO; +#endif + break; +#endif /* USE_DATABASE */ +#if USE_TERMCAP + case dbdEnvOnce2: + if (use_terminfo_vars()) { + if ((envp = getenv("TERMCAP")) != 0) + result = _nc_tic_dir(envp); + } + break; + case dbdEnvList2: + if (use_terminfo_vars()) { + if ((result = NEXT_DBD(getenv("TERMPATH"), offset)) != 0) + next = *state; + } + break; + case dbdCfgList2: + if ((result = NEXT_DBD(TERMPATH, offset)) != 0) + next = *state; + break; +#endif /* USE_TERMCAP */ + case dbdLAST: + break; + } + if (*state != next) { + *state = next; + *offset = 0; + _nc_last_db(); + } + if (result != 0) { + return result; + } + } + return 0; +} + +NCURSES_EXPORT(void) +_nc_first_db(DBDIRS * state, int *offset) +{ + *state = dbdTIC; + *offset = 0; +} diff --git a/lib/libcurses/tinfo/doalloc.c b/lib/libcurses/tinfo/doalloc.c index 54659f55888..a28a5cbdffb 100644 --- a/lib/libcurses/tinfo/doalloc.c +++ b/lib/libcurses/tinfo/doalloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: doalloc.c,v 1.6 2003/03/18 16:55:54 millert Exp $ */ +/* $OpenBSD: doalloc.c,v 1.7 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** * Copyright (c) 1998,2000 Free Software Foundation, Inc. * @@ -41,7 +41,7 @@ #include <curses.priv.h> -MODULE_ID("$From: doalloc.c,v 1.7 2000/12/10 02:55:07 tom Exp $") +MODULE_ID("$Id: doalloc.c,v 1.7 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(void *) _nc_doalloc(void *oldp, size_t amount) @@ -54,7 +54,7 @@ _nc_doalloc(void *oldp, size_t amount) errno = ENOMEM; /* just in case 'free' reset */ } } else { - newp = typeMalloc(char, amount); + newp = malloc(amount); } return newp; } @@ -67,7 +67,7 @@ _nc_strdup(const char *src) size_t dsize; if (src != 0) { dsize = strlen(src) + 1; - dst = typeMalloc(char, dsize); + dst = typeMalloc(char, strlen(src) + 1); if (dst != 0) { (void) strlcpy(dst, src, dsize); } diff --git a/lib/libcurses/tinfo/entries.c b/lib/libcurses/tinfo/entries.c new file mode 100644 index 00000000000..ad76fadfb83 --- /dev/null +++ b/lib/libcurses/tinfo/entries.c @@ -0,0 +1,147 @@ +/* $OpenBSD: entries.c,v 1.1 2010/01/12 23:22:06 nicm Exp $ */ + +/**************************************************************************** + * Copyright (c) 2006-2007,2008 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey * + ****************************************************************************/ + +#include <curses.priv.h> + +#include <ctype.h> + +#include <tic.h> +#include <term_entry.h> + +MODULE_ID("$Id: entries.c,v 1.1 2010/01/12 23:22:06 nicm Exp $") + +/**************************************************************************** + * + * Entry queue handling + * + ****************************************************************************/ +/* + * The entry list is a doubly linked list with NULLs terminating the lists: + * + * --------- --------- --------- + * | | | | | | offset + * |-------| |-------| |-------| + * | ----+-->| ----+-->| NULL | next + * |-------| |-------| |-------| + * | NULL |<--+---- |<--+---- | last + * --------- --------- --------- + * ^ ^ + * | | + * | | + * _nc_head _nc_tail + */ + +NCURSES_EXPORT_VAR(ENTRY *) _nc_head = 0; +NCURSES_EXPORT_VAR(ENTRY *) _nc_tail = 0; + +NCURSES_EXPORT(void) +_nc_free_entry(ENTRY * headp, TERMTYPE *tterm) +/* free the allocated storage consumed by the given list entry */ +{ + ENTRY *ep; + + if ((ep = _nc_delink_entry(headp, tterm)) != 0) { + free(ep); + } +} + +NCURSES_EXPORT(void) +_nc_free_entries(ENTRY * headp) +/* free the allocated storage consumed by list entries */ +{ + (void) headp; /* unused - _nc_head is altered here! */ + + while (_nc_head != 0) { + _nc_free_termtype(&(_nc_head->tterm)); + } +} + +NCURSES_EXPORT(ENTRY *) +_nc_delink_entry(ENTRY * headp, TERMTYPE *tterm) +/* delink the allocated storage for the given list entry */ +{ + ENTRY *ep, *last; + + for (last = 0, ep = headp; ep != 0; last = ep, ep = ep->next) { + if (&(ep->tterm) == tterm) { + if (last != 0) { + last->next = ep->next; + } + if (ep == _nc_head) { + _nc_head = ep->next; + } + if (ep == _nc_tail) { + _nc_tail = last; + } + break; + } + } + return ep; +} + +NCURSES_EXPORT(void) +_nc_leaks_tinfo(void) +{ +#if NO_LEAKS + char *s; +#endif + + T((T_CALLED("_nc_free_tinfo()"))); +#if NO_LEAKS + _nc_free_tparm(); + _nc_tgetent_leaks(); + _nc_free_entries(_nc_head); + _nc_get_type(0); + _nc_first_name(0); + _nc_keyname_leaks(); +#if BROKEN_LINKER || USE_REENTRANT + _nc_names_leaks(); + _nc_codes_leaks(); + FreeIfNeeded(_nc_prescreen.real_acs_map); +#endif + + if ((s = _nc_home_terminfo()) != 0) + free(s); +#endif /* NO_LEAKS */ + returnVoid; +} + +#if NO_LEAKS +NCURSES_EXPORT(void) +_nc_free_tinfo(int code) +{ + _nc_leaks_tinfo(); + exit(code); +} +#endif diff --git a/lib/libcurses/tinfo/free_ttype.c b/lib/libcurses/tinfo/free_ttype.c index 3fac7bc6122..a506df3eadf 100644 --- a/lib/libcurses/tinfo/free_ttype.c +++ b/lib/libcurses/tinfo/free_ttype.c @@ -1,7 +1,7 @@ -/* $OpenBSD: free_ttype.c,v 1.6 2007/04/16 11:53:38 otto Exp $ */ +/* $OpenBSD: free_ttype.c,v 1.7 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1999-2005,2006 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,7 +29,7 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey <dickey@clark.net> 1999 * + * Author: Thomas E. Dickey 1999-on * ****************************************************************************/ /* @@ -45,11 +45,13 @@ #include <tic.h> #include <term_entry.h> -MODULE_ID("$From: free_ttype.c,v 1.7 2000/12/10 02:55:07 tom Exp $") +MODULE_ID("$Id: free_ttype.c,v 1.7 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(void) -_nc_free_termtype(TERMTYPE * ptr) +_nc_free_termtype(TERMTYPE *ptr) { + T(("_nc_free_termtype(%s)", ptr->term_names)); + FreeIfNeeded(ptr->str_table); FreeIfNeeded(ptr->Booleans); FreeIfNeeded(ptr->Numbers); @@ -59,6 +61,7 @@ _nc_free_termtype(TERMTYPE * ptr) FreeIfNeeded(ptr->ext_Names); #endif memset(ptr, 0, sizeof(TERMTYPE)); + _nc_free_entry(_nc_head, ptr); } #if NCURSES_XNAMES @@ -68,7 +71,9 @@ NCURSES_EXPORT(int) use_extended_names(bool flag) { int oldflag = _nc_user_definable; + + T((T_CALLED("use_extended_names(%d)"), flag)); _nc_user_definable = flag; - return oldflag; + returnBool(oldflag); } #endif diff --git a/lib/libcurses/tinfo/getenv_num.c b/lib/libcurses/tinfo/getenv_num.c index 80723dbedf8..b4c91796ca5 100644 --- a/lib/libcurses/tinfo/getenv_num.c +++ b/lib/libcurses/tinfo/getenv_num.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getenv_num.c,v 1.2 2001/01/22 18:01:51 millert Exp $ */ +/* $OpenBSD: getenv_num.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** * Copyright (c) 1998,2000 Free Software Foundation, Inc. * @@ -38,7 +38,7 @@ #include <curses.priv.h> -MODULE_ID("$From: getenv_num.c,v 1.3 2000/12/10 02:55:07 tom Exp $") +MODULE_ID("$Id: getenv_num.c,v 1.3 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(int) _nc_getenv_num(const char *name) diff --git a/lib/libcurses/tinfo/hashed_db.c b/lib/libcurses/tinfo/hashed_db.c new file mode 100644 index 00000000000..2ce463a707f --- /dev/null +++ b/lib/libcurses/tinfo/hashed_db.c @@ -0,0 +1,262 @@ +/* $OpenBSD: hashed_db.c,v 1.1 2010/01/12 23:22:06 nicm Exp $ */ + +/**************************************************************************** + * Copyright (c) 2006 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey 2006 * + ****************************************************************************/ + +#include <curses.priv.h> +#include <tic.h> +#include <hashed_db.h> + +#if USE_HASHED_DB + +MODULE_ID("$Id: hashed_db.c,v 1.1 2010/01/12 23:22:06 nicm Exp $") + +#if HASHED_DB_API >= 2 +static DBC *cursor; +#endif + +/* + * Open the database. + */ +NCURSES_EXPORT(DB *) +_nc_db_open(const char *path, bool modify) +{ + DB *result = 0; + +#if HASHED_DB_API >= 4 + db_create(&result, NULL, 0); + result->open(result, + NULL, + path, + NULL, + DB_HASH, + modify ? DB_CREATE : DB_RDONLY, + 0644); +#elif HASHED_DB_API >= 3 + db_create(&result, NULL, 0); + result->open(result, + path, + NULL, + DB_HASH, + modify ? DB_CREATE : DB_RDONLY, + 0644); +#elif HASHED_DB_API >= 2 + int code; + + if ((code = db_open(path, + DB_HASH, + modify ? DB_CREATE : DB_RDONLY, + 0644, + (DB_ENV *) 0, + (DB_INFO *) 0, + &result)) != 0) { + T(("cannot open %s: %s", path, strerror(code))); + result = 0; + } else { + T(("opened %s", path)); + } +#else + result = dbopen(path, + modify ? (O_CREAT | O_RDWR) : O_RDONLY, + 0644, + DB_HASH, + NULL); + if (result != 0) { + T(("opened %s", path)); + } +#endif + return result; +} + +/* + * Close the database. Do not attempt to use the 'db' handle after this call. + */ +NCURSES_EXPORT(int) +_nc_db_close(DB * db) +{ + int result; + +#if HASHED_DB_API >= 2 + result = db->close(db, 0); +#else + result = db->close(db); +#endif + return result; +} + +/* + * Write a record to the database. + * + * Returns 0 on success. + * + * FIXME: the FreeBSD cap_mkdb program assumes the database could have + * duplicates. There appears to be no good reason for that (review/fix). + */ +NCURSES_EXPORT(int) +_nc_db_put(DB * db, DBT * key, DBT * data) +{ + int result; +#if HASHED_DB_API >= 2 + /* remove any pre-existing value, since we do not want duplicates */ + (void) db->del(db, NULL, key, 0); + result = db->put(db, NULL, key, data, DB_NOOVERWRITE); +#else + result = db->put(db, key, data, R_NOOVERWRITE); +#endif + return result; +} + +/* + * Read a record from the database. + * + * Returns 0 on success. + */ +NCURSES_EXPORT(int) +_nc_db_get(DB * db, DBT * key, DBT * data) +{ + int result; + + memset(data, 0, sizeof(*data)); +#if HASHED_DB_API >= 2 + result = db->get(db, NULL, key, data, 0); +#else + result = db->get(db, key, data, 0); +#endif + return result; +} + +/* + * Read the first record from the database, ignoring order. + * + * Returns 0 on success. + */ +NCURSES_EXPORT(int) +_nc_db_first(DB * db, DBT * key, DBT * data) +{ + int result; + + memset(key, 0, sizeof(*key)); + memset(data, 0, sizeof(*data)); +#if HASHED_DB_API >= 2 + if ((result = db->cursor(db, NULL, &cursor, 0)) == 0) { + result = cursor->c_get(cursor, key, data, DB_FIRST); + } +#else + result = db->seq(db, key, data, 0); +#endif + return result; +} + +/* + * Read the next record from the database, ignoring order. + * + * Returns 0 on success. + */ +NCURSES_EXPORT(int) +_nc_db_next(DB * db, DBT * key, DBT * data) +{ + int result; + +#if HASHED_DB_API >= 2 + (void) db; + if (cursor != 0) { + result = cursor->c_get(cursor, key, data, DB_NEXT); + } else { + result = -1; + } +#else + result = db->seq(db, key, data, 0); +#endif + return result; +} + +/* + * Check if a record is a terminfo index record. Index records are those that + * contain only an alias pointing to a list of aliases. + */ +NCURSES_EXPORT(bool) +_nc_db_have_index(DBT * key, DBT * data, char **buffer, int *size) +{ + bool result = FALSE; + int used = data->size - 1; + char *have = (char *) data->data; + + (void) key; + if (*have++ == 2) { + result = TRUE; + } + /* + * Update params in any case for consistency with _nc_db_have_data(). + */ + *buffer = have; + *size = used; + return result; +} + +/* + * Check if a record is the terminfo data record. Ignore index records, e.g., + * those that contain only an alias pointing to a list of aliases. + */ +NCURSES_EXPORT(bool) +_nc_db_have_data(DBT * key, DBT * data, char **buffer, int *size) +{ + bool result = FALSE; + int used = data->size - 1; + char *have = (char *) data->data; + + if (*have++ == 0) { + if (data->size > key->size + && IS_TIC_MAGIC(have)) { + result = TRUE; + } + } + /* + * Update params in any case to make it simple to follow a index record + * to the data record. + */ + *buffer = have; + *size = used; + return result; +} + +#else + +extern +NCURSES_EXPORT(void) +_nc_hashed_db(void); + +NCURSES_EXPORT(void) +_nc_hashed_db(void) +{ +} + +#endif /* USE_HASHED_DB */ diff --git a/lib/libcurses/tinfo/home_terminfo.c b/lib/libcurses/tinfo/home_terminfo.c index 955955484fc..a33924aa46a 100644 --- a/lib/libcurses/tinfo/home_terminfo.c +++ b/lib/libcurses/tinfo/home_terminfo.c @@ -1,7 +1,7 @@ -/* $OpenBSD: home_terminfo.c,v 1.8 2003/03/17 19:16:59 millert Exp $ */ +/* $OpenBSD: home_terminfo.c,v 1.9 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,7 +29,7 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey <dickey@clark.net> 1998,2000 * + * Author: Thomas E. Dickey * ****************************************************************************/ /* @@ -39,29 +39,31 @@ #include <curses.priv.h> #include <tic.h> -MODULE_ID("$From: home_terminfo.c,v 1.6 2000/12/10 02:55:07 tom Exp $") - -#define my_length (strlen(home) + sizeof(PRIVATE_INFO)) +MODULE_ID("$Id: home_terminfo.c,v 1.9 2010/01/12 23:22:06 nicm Exp $") /* ncurses extension...fall back on user's private directory */ +#define MyBuffer _nc_globals.home_terminfo + NCURSES_EXPORT(char *) _nc_home_terminfo(void) { + char *result = 0; +#if USE_HOME_TERMINFO char *home; - static char *temp = 0; if (use_terminfo_vars()) { - if (temp == 0) { - if ((home = getenv("HOME")) != 0 && *home != '\0' - && my_length <= PATH_MAX) { - temp = typeMalloc(char, my_length); - if (temp == 0) - _nc_err_abort("Out of memory"); - (void) snprintf(temp, my_length, PRIVATE_INFO, home); + if (MyBuffer == 0) { + if ((home = getenv("HOME")) != 0 && *home != '\0') { + size_t want = (strlen(home) + sizeof(PRIVATE_INFO)); + MyBuffer = typeMalloc(char, want); + if (MyBuffer == 0) + _nc_err_abort(MSG_NO_MEMORY); + (void) snprintf(MyBuffer, want, PRIVATE_INFO, home); } } - return temp; + result = MyBuffer; } - return 0; +#endif + return result; } diff --git a/lib/libcurses/tinfo/init_keytry.c b/lib/libcurses/tinfo/init_keytry.c index 083861d2690..05bc1b62343 100644 --- a/lib/libcurses/tinfo/init_keytry.c +++ b/lib/libcurses/tinfo/init_keytry.c @@ -1,7 +1,7 @@ -/* $OpenBSD: init_keytry.c,v 1.5 2001/01/22 18:01:51 millert Exp $ */ +/* $OpenBSD: init_keytry.c,v 1.6 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1999-2006,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -30,11 +30,15 @@ #include <curses.priv.h> -#include <term.h> /* keypad_xmit, keypad_local, meta_on, meta_off */ - /* cursor_visible,cursor_normal,cursor_invisible */ +#include <term.h> +/* keypad_xmit, keypad_local, meta_on, meta_off */ +/* cursor_visible,cursor_normal,cursor_invisible */ + #include <tic.h> /* struct tinfo_fkeys */ -MODULE_ID("$From: init_keytry.c,v 1.5 2000/12/10 02:55:07 tom Exp $") +#include <term_entry.h> + +MODULE_ID("$Id: init_keytry.c,v 1.6 2010/01/12 23:22:06 nicm Exp $") /* ** _nc_init_keytry() @@ -43,6 +47,13 @@ MODULE_ID("$From: init_keytry.c,v 1.5 2000/12/10 02:55:07 tom Exp $") ** */ +/* + * Internal entrypoints use SCREEN* parameter to obtain capabilities rather + * than cur_term. + */ +#undef CUR +#define CUR (sp->_term)->type. + #if BROKEN_LINKER #undef _nc_tinfo_fkeys #endif @@ -54,7 +65,7 @@ MODULE_ID("$From: init_keytry.c,v 1.5 2000/12/10 02:55:07 tom Exp $") #endif*/ #if BROKEN_LINKER -struct tinfo_fkeys * +const struct tinfo_fkeys * _nc_tinfo_fkeysf(void) { return _nc_tinfo_fkeys; @@ -62,21 +73,47 @@ _nc_tinfo_fkeysf(void) #endif NCURSES_EXPORT(void) -_nc_init_keytry(void) +_nc_init_keytry(SCREEN *sp) { size_t n; - /* The SP->_keytry value is initialized in newterm(), where the SP + /* The sp->_keytry value is initialized in newterm(), where the sp * structure is created, because we can not tell where keypad() or * mouse_activate() (which will call keyok()) are first called. */ - for (n = 0; _nc_tinfo_fkeys[n].code; n++) - if (_nc_tinfo_fkeys[n].offset < STRCOUNT) - _nc_add_to_try(&(SP->_keytry), - CUR Strings[_nc_tinfo_fkeys[n].offset], - _nc_tinfo_fkeys[n].code); + if (sp != 0) { + for (n = 0; _nc_tinfo_fkeys[n].code; n++) { + if (_nc_tinfo_fkeys[n].offset < STRCOUNT) { + (void) _nc_add_to_try(&(sp->_keytry), + CUR Strings[_nc_tinfo_fkeys[n].offset], + _nc_tinfo_fkeys[n].code); + } + } +#if NCURSES_XNAMES + /* + * Add any of the extended strings to the tries if their name begins + * with 'k', i.e., they follow the convention of other terminfo key + * names. + */ + { + TERMTYPE *tp = &(sp->_term->type); + for (n = STRCOUNT; n < NUM_STRINGS(tp); ++n) { + const char *name = ExtStrname(tp, n, strnames); + char *value = tp->Strings[n]; + if (name != 0 + && *name == 'k' + && value != 0 + && key_defined(value) == 0) { + (void) _nc_add_to_try(&(sp->_keytry), + value, + n - STRCOUNT + KEY_MAX); + } + } + } +#endif #ifdef TRACE - _nc_trace_tries(SP->_keytry); + _nc_trace_tries(sp->_keytry); #endif + } } diff --git a/lib/libcurses/tinfo/keys.list b/lib/libcurses/tinfo/keys.list deleted file mode 100644 index 078c4747aa5..00000000000 --- a/lib/libcurses/tinfo/keys.list +++ /dev/null @@ -1,159 +0,0 @@ -# $OpenBSD: keys.list,v 1.1 1999/01/18 19:10:15 millert Exp $ -# $From: keys.list,v 1.5 1997/10/25 21:05:24 tom Exp $ -# The first column is the #define symbol that is in curses.h -# The second column is the term.h symbol, for terminfo -# Not all keycodes have corresponding terminfo capabilities. -KEY_A1 key_a1 -KEY_A3 key_a3 -KEY_B2 key_b2 -KEY_BACKSPACE key_backspace -KEY_BEG key_beg -KEY_BREAK -KEY_BTAB key_btab -KEY_C1 key_c1 -KEY_C3 key_c3 -KEY_CANCEL key_cancel -KEY_CATAB key_catab -KEY_CLEAR key_clear -KEY_CLOSE key_close -KEY_COMMAND key_command -KEY_COPY key_copy -KEY_CREATE key_create -KEY_CTAB key_ctab -KEY_DC key_dc -KEY_DL key_dl -KEY_DOWN key_down -KEY_EIC key_eic -KEY_END key_end -KEY_ENTER key_enter -KEY_EOL key_eol -KEY_EOS key_eos -KEY_EXIT key_exit -KEY_F(0) key_f0 -KEY_F(1) key_f1 -KEY_F(10) key_f10 -KEY_F(11) key_f11 -KEY_F(12) key_f12 -KEY_F(13) key_f13 -KEY_F(14) key_f14 -KEY_F(15) key_f15 -KEY_F(16) key_f16 -KEY_F(17) key_f17 -KEY_F(18) key_f18 -KEY_F(19) key_f19 -KEY_F(2) key_f2 -KEY_F(20) key_f20 -KEY_F(21) key_f21 -KEY_F(22) key_f22 -KEY_F(23) key_f23 -KEY_F(24) key_f24 -KEY_F(25) key_f25 -KEY_F(26) key_f26 -KEY_F(27) key_f27 -KEY_F(28) key_f28 -KEY_F(29) key_f29 -KEY_F(3) key_f3 -KEY_F(30) key_f30 -KEY_F(31) key_f31 -KEY_F(32) key_f32 -KEY_F(33) key_f33 -KEY_F(34) key_f34 -KEY_F(35) key_f35 -KEY_F(36) key_f36 -KEY_F(37) key_f37 -KEY_F(38) key_f38 -KEY_F(39) key_f39 -KEY_F(4) key_f4 -KEY_F(40) key_f40 -KEY_F(41) key_f41 -KEY_F(42) key_f42 -KEY_F(43) key_f43 -KEY_F(44) key_f44 -KEY_F(45) key_f45 -KEY_F(46) key_f46 -KEY_F(47) key_f47 -KEY_F(48) key_f48 -KEY_F(49) key_f49 -KEY_F(5) key_f5 -KEY_F(50) key_f50 -KEY_F(51) key_f51 -KEY_F(52) key_f52 -KEY_F(53) key_f53 -KEY_F(54) key_f54 -KEY_F(55) key_f55 -KEY_F(56) key_f56 -KEY_F(57) key_f57 -KEY_F(58) key_f58 -KEY_F(59) key_f59 -KEY_F(6) key_f6 -KEY_F(60) key_f60 -KEY_F(61) key_f61 -KEY_F(62) key_f62 -KEY_F(63) key_f63 -KEY_F(7) key_f7 -KEY_F(8) key_f8 -KEY_F(9) key_f9 -KEY_FIND key_find -KEY_HELP key_help -KEY_HOME key_home -KEY_IC key_ic -KEY_IL key_il -KEY_LEFT key_left -KEY_LL key_ll -KEY_MARK key_mark -KEY_MESSAGE key_message -KEY_MOUSE key_mouse -KEY_MOVE key_move -KEY_NEXT key_next -KEY_NPAGE key_npage -KEY_OPEN key_open -KEY_OPTIONS key_options -KEY_PPAGE key_ppage -KEY_PREVIOUS key_previous -KEY_PRINT key_print -KEY_REDO key_redo -KEY_REFERENCE key_reference -KEY_REFRESH key_refresh -KEY_REPLACE key_replace -KEY_RESET -KEY_RESIZE -KEY_RESTART key_restart -KEY_RESUME key_resume -KEY_RIGHT key_right -KEY_SAVE key_save -KEY_SBEG key_sbeg -KEY_SCANCEL key_scancel -KEY_SCOMMAND key_scommand -KEY_SCOPY key_scopy -KEY_SCREATE key_screate -KEY_SDC key_sdc -KEY_SDL key_sdl -KEY_SELECT key_select -KEY_SEND key_send -KEY_SEOL key_seol -KEY_SEXIT key_sexit -KEY_SF key_sf -KEY_SFIND key_sfind -KEY_SHELP key_shelp -KEY_SHOME key_shome -KEY_SIC key_sic -KEY_SLEFT key_sleft -KEY_SMESSAGE key_smessage -KEY_SMOVE key_smove -KEY_SNEXT key_snext -KEY_SOPTIONS key_soptions -KEY_SPREVIOUS key_sprevious -KEY_SPRINT key_sprint -KEY_SR key_sr -KEY_SREDO key_sredo -KEY_SREPLACE key_sreplace -KEY_SRESET -KEY_SRIGHT key_sright -KEY_SRSUME key_srsume -KEY_SSAVE key_ssave -KEY_SSUSPEND key_ssuspend -KEY_STAB key_stab -KEY_SUNDO key_sundo -KEY_SUSPEND key_suspend -KEY_UNDO key_undo -KEY_UP key_up diff --git a/lib/libcurses/tinfo/lib_acs.c b/lib/libcurses/tinfo/lib_acs.c index 9e406cf4d18..b5a5c12a4be 100644 --- a/lib/libcurses/tinfo/lib_acs.c +++ b/lib/libcurses/tinfo/lib_acs.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_acs.c,v 1.4 2001/01/22 18:01:52 millert Exp $ */ +/* $OpenBSD: lib_acs.c,v 1.5 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,128 +31,158 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ #include <curses.priv.h> #include <term.h> /* ena_acs, acs_chars */ -MODULE_ID("$From: lib_acs.c,v 1.18 2000/12/10 02:55:07 tom Exp $") +MODULE_ID("$Id: lib_acs.c,v 1.5 2010/01/12 23:22:06 nicm Exp $") +#if BROKEN_LINKER || USE_REENTRANT +#define MyBuffer _nc_prescreen.real_acs_map +NCURSES_EXPORT_VAR(chtype *) +_nc_acs_map(void) +{ + if (MyBuffer == 0) + MyBuffer = typeCalloc(chtype, ACS_LEN); + return MyBuffer; +} +#undef MyBuffer +#else NCURSES_EXPORT_VAR(chtype) acs_map[ACS_LEN] = { 0 }; +#endif NCURSES_EXPORT(void) _nc_init_acs(void) { + chtype *fake_map = acs_map; + chtype *real_map = SP != 0 ? SP->_acs_map : fake_map; + int j; + T(("initializing ACS map")); /* + * If we're using this from curses (rather than terminfo), we are storing + * the mapping information in the SCREEN struct so we can decide how to + * render it. + */ + if (real_map != fake_map) { + for (j = 1; j < ACS_LEN; ++j) { + real_map[j] = 0; + fake_map[j] = A_ALTCHARSET | j; + if (SP) + SP->_screen_acs_map[j] = FALSE; + } + } else { + for (j = 1; j < ACS_LEN; ++j) { + real_map[j] = 0; + } + } + + /* * Initializations for a UNIX-like multi-terminal environment. Use * ASCII chars and count on the terminfo description to do better. */ - ACS_ULCORNER = '+'; /* should be upper left corner */ - ACS_LLCORNER = '+'; /* should be lower left corner */ - ACS_URCORNER = '+'; /* should be upper right corner */ - ACS_LRCORNER = '+'; /* should be lower right corner */ - ACS_RTEE = '+'; /* should be tee pointing left */ - ACS_LTEE = '+'; /* should be tee pointing right */ - ACS_BTEE = '+'; /* should be tee pointing up */ - ACS_TTEE = '+'; /* should be tee pointing down */ - ACS_HLINE = '-'; /* should be horizontal line */ - ACS_VLINE = '|'; /* should be vertical line */ - ACS_PLUS = '+'; /* should be large plus or crossover */ - ACS_S1 = '~'; /* should be scan line 1 */ - ACS_S9 = '_'; /* should be scan line 9 */ - ACS_DIAMOND = '+'; /* should be diamond */ - ACS_CKBOARD = ':'; /* should be checker board (stipple) */ - ACS_DEGREE = '\''; /* should be degree symbol */ - ACS_PLMINUS = '#'; /* should be plus/minus */ - ACS_BULLET = 'o'; /* should be bullet */ - ACS_LARROW = '<'; /* should be arrow pointing left */ - ACS_RARROW = '>'; /* should be arrow pointing right */ - ACS_DARROW = 'v'; /* should be arrow pointing down */ - ACS_UARROW = '^'; /* should be arrow pointing up */ - ACS_BOARD = '#'; /* should be board of squares */ - ACS_LANTERN = '#'; /* should be lantern symbol */ - ACS_BLOCK = '#'; /* should be solid square block */ + real_map['l'] = '+'; /* should be upper left corner */ + real_map['m'] = '+'; /* should be lower left corner */ + real_map['k'] = '+'; /* should be upper right corner */ + real_map['j'] = '+'; /* should be lower right corner */ + real_map['u'] = '+'; /* should be tee pointing left */ + real_map['t'] = '+'; /* should be tee pointing right */ + real_map['v'] = '+'; /* should be tee pointing up */ + real_map['w'] = '+'; /* should be tee pointing down */ + real_map['q'] = '-'; /* should be horizontal line */ + real_map['x'] = '|'; /* should be vertical line */ + real_map['n'] = '+'; /* should be large plus or crossover */ + real_map['o'] = '~'; /* should be scan line 1 */ + real_map['s'] = '_'; /* should be scan line 9 */ + real_map['`'] = '+'; /* should be diamond */ + real_map['a'] = ':'; /* should be checker board (stipple) */ + real_map['f'] = '\''; /* should be degree symbol */ + real_map['g'] = '#'; /* should be plus/minus */ + real_map['~'] = 'o'; /* should be bullet */ + real_map[','] = '<'; /* should be arrow pointing left */ + real_map['+'] = '>'; /* should be arrow pointing right */ + real_map['.'] = 'v'; /* should be arrow pointing down */ + real_map['-'] = '^'; /* should be arrow pointing up */ + real_map['h'] = '#'; /* should be board of squares */ + real_map['i'] = '#'; /* should be lantern symbol */ + real_map['0'] = '#'; /* should be solid square block */ /* these defaults were invented for ncurses */ - ACS_S3 = '-'; /* should be scan line 3 */ - ACS_S7 = '-'; /* should be scan line 7 */ - ACS_LEQUAL = '<'; /* should be less-than-or-equal-to */ - ACS_GEQUAL = '>'; /* should be greater-than-or-equal-to */ - ACS_PI = '*'; /* should be greek pi */ - ACS_NEQUAL = '!'; /* should be not-equal */ - ACS_STERLING = 'f'; /* should be pound-sterling symbol */ + real_map['p'] = '-'; /* should be scan line 3 */ + real_map['r'] = '-'; /* should be scan line 7 */ + real_map['y'] = '<'; /* should be less-than-or-equal-to */ + real_map['z'] = '>'; /* should be greater-than-or-equal-to */ + real_map['{'] = '*'; /* should be greek pi */ + real_map['|'] = '!'; /* should be not-equal */ + real_map['}'] = 'f'; /* should be pound-sterling symbol */ if (ena_acs != NULL) { TPUTS_TRACE("ena_acs"); putp(ena_acs); } -#define ALTCHAR(c) ((chtype)(((unsigned char)(c)) | A_ALTCHARSET)) +#if NCURSES_EXT_FUNCS + /* + * Linux console "supports" the "PC ROM" character set by the coincidence + * that smpch/rmpch and smacs/rmacs have the same values. ncurses has + * no codepage support (see SCO Merge for an example). Outside of the + * values defined in acsc, there are no definitions for the "PC ROM" + * character set (assumed by some applications to be codepage 437), but we + * allow those applications to use those codepoints. + * + * test/blue.c uses this feature. + */ +#define PCH_KLUDGE(a,b) (a != 0 && b != 0 && !strcmp(a,b)) + if (PCH_KLUDGE(enter_pc_charset_mode, enter_alt_charset_mode) && + PCH_KLUDGE(exit_pc_charset_mode, exit_alt_charset_mode)) { + size_t i; + for (i = 1; i < ACS_LEN; ++i) { + if (real_map[i] == 0) { + real_map[i] = i; + if (real_map != fake_map) { + if (SP != 0) + SP->_screen_acs_map[i] = TRUE; + } + } + } + } +#endif if (acs_chars != NULL) { size_t i = 0; size_t length = strlen(acs_chars); - while (i < length) - switch (acs_chars[i]) { - case 'l': - case 'm': - case 'k': - case 'j': - case 'u': - case 't': - case 'v': - case 'w': - case 'q': - case 'x': - case 'n': - case 'o': - case 's': - case '`': - case 'a': - case 'f': - case 'g': - case '~': - case ',': - case '+': - case '.': - case '-': - case 'h': - case 'i': - case '0': - case 'p': - case 'r': - case 'y': - case 'z': - case '{': - case '|': - case '}': - acs_map[(unsigned int) acs_chars[i]] = - ALTCHAR(acs_chars[i + 1]); - i++; - /* FALLTHRU */ - default: - i++; - break; + while (i + 1 < length) { + if (acs_chars[i] != 0 && UChar(acs_chars[i]) < ACS_LEN) { + real_map[UChar(acs_chars[i])] = UChar(acs_chars[i + 1]) | A_ALTCHARSET; + if (SP != 0) + SP->_screen_acs_map[UChar(acs_chars[i])] = TRUE; } + i += 2; + } } #ifdef TRACE /* Show the equivalent mapping, noting if it does not match the * given attribute, whether by re-ordering or duplication. */ - if (_nc_tracing & TRACE_CALLS) { + if (USE_TRACEF(TRACE_CALLS)) { size_t n, m; - char show[SIZEOF(acs_map) + 1]; - for (n = 1, m = 0; n < SIZEOF(acs_map); n++) { - if (acs_map[n] != 0) { + char show[ACS_LEN * 2 + 1]; + for (n = 1, m = 0; n < ACS_LEN; n++) { + if (real_map[n] != 0) { show[m++] = (char) n; - show[m++] = TextOf(acs_map[n]); + show[m++] = (char) ChCharOf(real_map[n]); } } show[m] = 0; + if (acs_chars == NULL || strcmp(acs_chars, show)) + _tracef("%s acs_chars %s", + (acs_chars == NULL) ? "NULL" : "READ", + _nc_visbuf(acs_chars)); _tracef("%s acs_chars %s", (acs_chars == NULL) ? "NULL" @@ -160,6 +190,7 @@ _nc_init_acs(void) ? "DIFF" : "SAME"), _nc_visbuf(show)); + _nc_unlock_global(tracef); } #endif /* TRACE */ } diff --git a/lib/libcurses/tinfo/lib_baudrate.c b/lib/libcurses/tinfo/lib_baudrate.c index 39342dcb9ab..a171993945a 100644 --- a/lib/libcurses/tinfo/lib_baudrate.c +++ b/lib/libcurses/tinfo/lib_baudrate.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_baudrate.c,v 1.4 2001/01/22 18:01:52 millert Exp $ */ +/* $OpenBSD: lib_baudrate.c,v 1.5 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -41,8 +42,47 @@ #include <curses.priv.h> #include <term.h> /* cur_term, pad_char */ #include <termcap.h> /* ospeed */ +#if defined(__FreeBSD__) +#include <sys/param.h> +#endif + +/* + * These systems use similar header files, which define B1200 as 1200, etc., + * but can be overridden by defining USE_OLD_TTY so B1200 is 9, which makes all + * of the indices up to B115200 fit nicely in a 'short', allowing us to retain + * ospeed's type for compatibility. + */ +#if (defined(__FreeBSD__) && (__FreeBSD_version < 700000)) || defined(__NetBSD__) || defined(__OpenBSD__) +#undef B0 +#undef B50 +#undef B75 +#undef B110 +#undef B134 +#undef B150 +#undef B200 +#undef B300 +#undef B600 +#undef B1200 +#undef B1800 +#undef B2400 +#undef B4800 +#undef B9600 +#undef B19200 +#undef EXTA +#undef B38400 +#undef EXTB +#undef B57600 +#undef B115200 +#undef B230400 +#undef B460800 +#undef B921600 +#define USE_OLD_TTY +#include <sys/ttydev.h> +#else +#undef USE_OLD_TTY +#endif /* USE_OLD_TTY */ -MODULE_ID("$From: lib_baudrate.c,v 1.19 2000/12/10 02:55:07 tom Exp $") +MODULE_ID("$Id: lib_baudrate.c,v 1.5 2010/01/12 23:22:06 nicm Exp $") /* * int @@ -99,21 +139,28 @@ static struct speed const speeds[] = #ifdef B460800 {B460800, 460800}, #endif +#ifdef B921600 + {B921600, 921600}, +#endif }; NCURSES_EXPORT(int) _nc_baudrate(int OSpeed) { +#if !USE_REENTRANT static int last_OSpeed; static int last_baudrate; +#endif - int result; + int result = ERR; unsigned i; +#if !USE_REENTRANT if (OSpeed == last_OSpeed) { result = last_baudrate; - } else { - result = ERR; + } +#endif + if (result == ERR) { if (OSpeed >= 0) { for (i = 0; i < SIZEOF(speeds); i++) { if (speeds[i].s == OSpeed) { @@ -122,7 +169,12 @@ _nc_baudrate(int OSpeed) } } } - last_baudrate = result; +#if !USE_REENTRANT + if (OSpeed == last_OSpeed) { + last_OSpeed = OSpeed; + last_baudrate = result; + } +#endif } return (result); } @@ -157,24 +209,32 @@ baudrate(void) * that take into account costs that depend on baudrate. */ #ifdef TRACE - if (SP && !isatty(fileno(SP->_ofp)) + if (!isatty(fileno(SP ? SP->_ofp : stdout)) && getenv("BAUDRATE") != 0) { int ret; if ((ret = _nc_getenv_num("BAUDRATE")) <= 0) ret = 9600; ospeed = _nc_ospeed(ret); returnCode(ret); - } else + } #endif + if (cur_term != 0) { +#ifdef USE_OLD_TTY + result = cfgetospeed(&cur_term->Nttyb); + ospeed = _nc_ospeed(result); +#else /* !USE_OLD_TTY */ #ifdef TERMIOS ospeed = cfgetospeed(&cur_term->Nttyb); #else ospeed = cur_term->Nttyb.sg_ospeed; #endif - result = _nc_baudrate(ospeed); - if (cur_term != 0) + result = _nc_baudrate(ospeed); +#endif cur_term->_baudrate = result; + } else { + result = ERR; + } returnCode(result); } diff --git a/lib/libcurses/tinfo/lib_cur_term.c b/lib/libcurses/tinfo/lib_cur_term.c index 3fcf4abe47c..68bb567f793 100644 --- a/lib/libcurses/tinfo/lib_cur_term.c +++ b/lib/libcurses/tinfo/lib_cur_term.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_cur_term.c,v 1.5 2001/01/22 18:01:52 millert Exp $ */ +/* $OpenBSD: lib_cur_term.c,v 1.6 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2003,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -42,33 +42,66 @@ #include <term_entry.h> /* TTY, cur_term */ #include <termcap.h> /* ospeed */ -MODULE_ID("$From: lib_cur_term.c,v 1.11 2000/12/10 02:55:07 tom Exp $") +MODULE_ID("$Id: lib_cur_term.c,v 1.6 2010/01/12 23:22:06 nicm Exp $") +#undef CUR +#define CUR termp->type. + +#if BROKEN_LINKER || USE_REENTRANT +NCURSES_EXPORT(TERMINAL *) +NCURSES_PUBLIC_VAR(cur_term) (void) +{ + return (SP != 0 && SP->_term != 0) ? SP->_term : _nc_prescreen._cur_term; +} +#else NCURSES_EXPORT_VAR(TERMINAL *) cur_term = 0; +#endif NCURSES_EXPORT(TERMINAL *) set_curterm(TERMINAL * termp) { - TERMINAL *oldterm = cur_term; + TERMINAL *oldterm; + + T((T_CALLED("set_curterm(%p)"), termp)); - if ((cur_term = termp) != 0) { - ospeed = _nc_ospeed(cur_term->_baudrate); - PC = (pad_char != NULL) ? pad_char[0] : 0; + _nc_lock_global(curses); + oldterm = cur_term; + if (SP) + SP->_term = termp; +#if BROKEN_LINKER || USE_REENTRANT + _nc_prescreen._cur_term = termp; +#else + cur_term = termp; +#endif + if (termp != 0) { + ospeed = _nc_ospeed(termp->_baudrate); + if (termp->type.Strings) { + PC = (char) ((pad_char != NULL) ? pad_char[0] : 0); + } } - return oldterm; + _nc_unlock_global(curses); + + T((T_RETURN("%p"), oldterm)); + return (oldterm); } NCURSES_EXPORT(int) del_curterm(TERMINAL * termp) { + int rc = ERR; + T((T_CALLED("del_curterm(%p)"), termp)); + _nc_lock_global(curses); if (termp != 0) { _nc_free_termtype(&(termp->type)); + FreeIfNeeded(termp->_termname); free(termp); if (termp == cur_term) - cur_term = 0; - returnCode(OK); + set_curterm(0); + rc = OK; } - returnCode(ERR); + _nc_unlock_global(curses); + + returnCode(rc); } diff --git a/lib/libcurses/tinfo/lib_data.c b/lib/libcurses/tinfo/lib_data.c index cdc8044ab18..57e8d7e9a06 100644 --- a/lib/libcurses/tinfo/lib_data.c +++ b/lib/libcurses/tinfo/lib_data.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_data.c,v 1.3 2001/01/22 18:01:52 millert Exp $ */ +/* $OpenBSD: lib_data.c,v 1.4 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -42,18 +43,33 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_data.c,v 1.16 2000/12/10 02:55:07 tom Exp $") +MODULE_ID("$Id: lib_data.c,v 1.4 2010/01/12 23:22:06 nicm Exp $") /* * OS/2's native linker complains if we don't initialize public data when * constructing a dll (reported by J.J.G.Ripoll). */ -NCURSES_EXPORT_VAR(WINDOW *) -stdscr = 0; -NCURSES_EXPORT_VAR(WINDOW *) -curscr = 0; -NCURSES_EXPORT_VAR(WINDOW *) -newscr = 0; +#if USE_REENTRANT +NCURSES_EXPORT(WINDOW *) +NCURSES_PUBLIC_VAR(stdscr) (void) +{ + return SP ? SP->_stdscr : 0; +} +NCURSES_EXPORT(WINDOW *) +NCURSES_PUBLIC_VAR(curscr) (void) +{ + return SP ? SP->_curscr : 0; +} +NCURSES_EXPORT(WINDOW *) +NCURSES_PUBLIC_VAR(newscr) (void) +{ + return SP ? SP->_newscr : 0; +} +#else +NCURSES_EXPORT_VAR(WINDOW *) stdscr = 0; +NCURSES_EXPORT_VAR(WINDOW *) curscr = 0; +NCURSES_EXPORT_VAR(WINDOW *) newscr = 0; +#endif NCURSES_EXPORT_VAR(SCREEN *) _nc_screen_chain = 0; @@ -68,7 +84,7 @@ NCURSES_EXPORT_VAR(SCREEN *) _nc_screen_chain = 0; * module coupling that increases the size of the executable. */ #if BROKEN_LINKER - static SCREEN *my_screen; +static SCREEN *my_screen; NCURSES_EXPORT(SCREEN *) _nc_screen(void) @@ -83,11 +99,236 @@ _nc_alloc_screen(void) } NCURSES_EXPORT(void) -_nc_set_screen(SCREEN * sp) +_nc_set_screen(SCREEN *sp) { my_screen = sp; } #else -NCURSES_EXPORT_VAR(SCREEN *) SP = NULL; /* Some linkers require initialized data... */ +NCURSES_EXPORT_VAR(SCREEN *) SP = NULL; /* Some linkers require initialized data... */ +#endif +/* *INDENT-OFF* */ +#define CHARS_0s { '\0' } + +#define TGETENT_0 { 0L, FALSE, NULL, NULL, NULL } +#define TGETENT_0s { TGETENT_0, TGETENT_0, TGETENT_0, TGETENT_0 } + +NCURSES_EXPORT_VAR(NCURSES_GLOBALS) _nc_globals = { + 0, /* have_sigwinch */ + 0, /* cleanup_nested */ + + FALSE, /* init_signals */ + FALSE, /* init_screen */ + + NULL, /* comp_sourcename */ + NULL, /* comp_termtype */ + + FALSE, /* have_tic_directory */ + FALSE, /* keep_tic_directory */ + TERMINFO, /* tic_directory */ + + NULL, /* dbi_list */ + 0, /* dbi_size */ + + NULL, /* first_name */ + NULL, /* keyname_table */ + + 0, /* slk_format */ + + NULL, /* safeprint_buf */ + 0, /* safeprint_used */ + + TGETENT_0s, /* tgetent_cache */ + 0, /* tgetent_index */ + 0, /* tgetent_sequence */ + + 0, /* _nc_windowlist */ + +#if USE_HOME_TERMINFO + NULL, /* home_terminfo */ +#endif + +#if !USE_SAFE_SPRINTF + 0, /* safeprint_cols */ + 0, /* safeprint_rows */ +#endif + +#ifdef TRACE + FALSE, /* init_trace */ + CHARS_0s, /* trace_fname */ + 0, /* trace_level */ + NULL, /* trace_fp */ + + NULL, /* tracearg_buf */ + 0, /* tracearg_used */ + + NULL, /* tracebuf_ptr */ + 0, /* tracebuf_used */ + + CHARS_0s, /* tracechr_buf */ + + NULL, /* tracedmp_buf */ + 0, /* tracedmp_used */ + + NULL, /* tracetry_buf */ + 0, /* tracetry_used */ + + { CHARS_0s, CHARS_0s }, /* traceatr_color_buf */ + 0, /* traceatr_color_sel */ + -1, /* traceatr_color_last */ + +#endif /* TRACE */ +#ifdef USE_PTHREADS + PTHREAD_MUTEX_INITIALIZER, /* mutex_curses */ + PTHREAD_MUTEX_INITIALIZER, /* mutex_tst_tracef */ + PTHREAD_MUTEX_INITIALIZER, /* mutex_tracef */ + 0, /* nested_tracef */ + 0, /* use_pthreads */ +#endif +}; + +#define STACK_FRAME_0 { { 0 }, 0 } +#define STACK_FRAME_0s { STACK_FRAME_0 } +#define NUM_VARS_0s { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } + +#define RIPOFF_0 { 0,0,0 } +#define RIPOFF_0s { RIPOFF_0 } + +NCURSES_EXPORT_VAR(NCURSES_PRESCREEN) _nc_prescreen = { + TRUE, /* use_env */ + FALSE, /* filter_mode */ + A_NORMAL, /* previous_attr */ + RIPOFF_0s, /* ripoff */ + NULL, /* rsp */ + { /* tparm_state */ +#ifdef TRACE + NULL, /* tname */ +#endif + NULL, /* tparam_base */ + + STACK_FRAME_0s, /* stack */ + 0, /* stack_ptr */ + + NULL, /* out_buff */ + 0, /* out_size */ + 0, /* out_used */ + + NULL, /* fmt_buff */ + 0, /* fmt_size */ + + NUM_VARS_0s, /* dynamic_var */ + NUM_VARS_0s, /* static_vars */ + }, + NULL, /* saved_tty */ +#if NCURSES_NO_PADDING + FALSE, /* flag to set if padding disabled */ +#endif +#if BROKEN_LINKER || USE_REENTRANT + NULL, /* real_acs_map */ + 0, /* LINES */ + 0, /* COLS */ + 0, /* cur_term */ +#ifdef TRACE + 0L, /* _outchars */ + NULL, /* _tputs_trace */ +#endif +#endif +}; +/* *INDENT-ON* */ + +/******************************************************************************/ +#ifdef USE_PTHREADS +static void +init_global_mutexes(void) +{ + static bool initialized = FALSE; + + if (!initialized) { + initialized = TRUE; + _nc_mutex_init(&_nc_globals.mutex_curses); + _nc_mutex_init(&_nc_globals.mutex_tst_tracef); + _nc_mutex_init(&_nc_globals.mutex_tracef); + } +} + +NCURSES_EXPORT(void) +_nc_init_pthreads(void) +{ + if (_nc_use_pthreads) + return; +# if USE_WEAK_SYMBOLS + if ((pthread_mutex_init) == 0) + return; + if ((pthread_mutex_lock) == 0) + return; + if ((pthread_mutex_unlock) == 0) + return; + if ((pthread_mutex_trylock) == 0) + return; + if ((pthread_mutexattr_settype) == 0) + return; +# endif + _nc_use_pthreads = 1; + init_global_mutexes(); +} + +/* + * Use recursive mutexes if we have them - they're part of Unix98. + * For the cases where we do not, _nc_mutex_trylock() is used to avoid a + * deadlock, at the expense of memory leaks and unexpected failures that + * may not be handled by typical clients. + * + * FIXME - need configure check for PTHREAD_MUTEX_RECURSIVE, define it to + * PTHREAD_MUTEX_NORMAL if not supported. + */ +NCURSES_EXPORT(void) +_nc_mutex_init(pthread_mutex_t * obj) +{ + pthread_mutexattr_t recattr; + + if (_nc_use_pthreads) { + pthread_mutexattr_init(&recattr); + pthread_mutexattr_settype(&recattr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init(obj, &recattr); + } +} + +NCURSES_EXPORT(int) +_nc_mutex_lock(pthread_mutex_t * obj) +{ + if (_nc_use_pthreads == 0) + return 0; + return pthread_mutex_lock(obj); +} + +NCURSES_EXPORT(int) +_nc_mutex_trylock(pthread_mutex_t * obj) +{ + if (_nc_use_pthreads == 0) + return 0; + return pthread_mutex_trylock(obj); +} + +NCURSES_EXPORT(int) +_nc_mutex_unlock(pthread_mutex_t * obj) +{ + if (_nc_use_pthreads == 0) + return 0; + return pthread_mutex_unlock(obj); +} + +#if USE_WEAK_SYMBOLS +/* + * NB: sigprocmask(2) is global but pthread_sigmask(3p) + * only for the calling thread. + */ +NCURSES_EXPORT(int) +_nc_sigprocmask(int how, const sigset_t * newmask, sigset_t * oldmask) +{ + if ((pthread_sigmask)) + return pthread_sigmask(how, newmask, oldmask); + else + return sigprocmask(how, newmask, oldmask); +} #endif +#endif /* USE_PTHREADS */ diff --git a/lib/libcurses/tinfo/lib_has_cap.c b/lib/libcurses/tinfo/lib_has_cap.c index d95e3f908c7..6be944be979 100644 --- a/lib/libcurses/tinfo/lib_has_cap.c +++ b/lib/libcurses/tinfo/lib_has_cap.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_has_cap.c,v 1.2 2001/01/22 18:01:52 millert Exp $ */ +/* $OpenBSD: lib_has_cap.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2000,2003 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-2003 * ****************************************************************************/ /* @@ -44,7 +45,7 @@ #include <term.h> -MODULE_ID("$From: lib_has_cap.c,v 1.3 2000/12/10 02:55:07 tom Exp $") +MODULE_ID("$Id: lib_has_cap.c,v 1.3 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(bool) has_ic(void) diff --git a/lib/libcurses/tinfo/lib_kernel.c b/lib/libcurses/tinfo/lib_kernel.c index 730ba1551fd..024227fdc03 100644 --- a/lib/libcurses/tinfo/lib_kernel.c +++ b/lib/libcurses/tinfo/lib_kernel.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_kernel.c,v 1.2 2001/01/22 18:01:52 millert Exp $ */ +/* $OpenBSD: lib_kernel.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2003,2004 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 2002 * ****************************************************************************/ /* @@ -49,7 +50,28 @@ #include <curses.priv.h> #include <term.h> /* cur_term */ -MODULE_ID("$From: lib_kernel.c,v 1.21 2000/12/10 02:55:07 tom Exp $") +MODULE_ID("$Id: lib_kernel.c,v 1.3 2010/01/12 23:22:06 nicm Exp $") + +static int +_nc_vdisable(void) +{ + int value = -1; +#if defined(_POSIX_VDISABLE) && HAVE_UNISTD_H + value = _POSIX_VDISABLE; +#endif +#if defined(_PC_VDISABLE) + if (value == -1) { + value = fpathconf(0, _PC_VDISABLE); + if (value == -1) { + value = 0377; + } + } +#elif defined(VDISABLE) + if (value == -1) + value = VDISABLE; +#endif + return value; +} /* * erasechar() @@ -61,16 +83,19 @@ MODULE_ID("$From: lib_kernel.c,v 1.21 2000/12/10 02:55:07 tom Exp $") NCURSES_EXPORT(char) erasechar(void) { + int result = ERR; T((T_CALLED("erasechar()"))); if (cur_term != 0) { #ifdef TERMIOS - returnCode(cur_term->Ottyb.c_cc[VERASE]); + result = cur_term->Ottyb.c_cc[VERASE]; + if (result == _nc_vdisable()) + result = ERR; #else - returnCode(cur_term->Ottyb.sg_erase); + result = cur_term->Ottyb.sg_erase; #endif } - returnCode(ERR); + returnCode(result); } /* @@ -83,16 +108,19 @@ erasechar(void) NCURSES_EXPORT(char) killchar(void) { + int result = ERR; T((T_CALLED("killchar()"))); if (cur_term != 0) { #ifdef TERMIOS - returnCode(cur_term->Ottyb.c_cc[VKILL]); + result = cur_term->Ottyb.c_cc[VKILL]; + if (result == _nc_vdisable()) + result = ERR; #else - returnCode(cur_term->Ottyb.sg_kill); + result = cur_term->Ottyb.sg_kill; #endif } - returnCode(ERR); + returnCode(result); } /* diff --git a/lib/libcurses/tinfo/lib_longname.c b/lib/libcurses/tinfo/lib_longname.c index 9cbbf5fcbf5..74616fa7bc7 100644 --- a/lib/libcurses/tinfo/lib_longname.c +++ b/lib/libcurses/tinfo/lib_longname.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_longname.c,v 1.2 2001/01/22 18:01:52 millert Exp $ */ +/* $OpenBSD: lib_longname.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** * Copyright (c) 1998,2000 Free Software Foundation, Inc. * @@ -42,7 +42,7 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_longname.c,v 1.9 2000/12/10 02:55:07 tom Exp $") +MODULE_ID("$Id: lib_longname.c,v 1.3 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(char *) longname(void) diff --git a/lib/libcurses/tinfo/lib_napms.c b/lib/libcurses/tinfo/lib_napms.c index bf29ef488f5..b92431d9701 100644 --- a/lib/libcurses/tinfo/lib_napms.c +++ b/lib/libcurses/tinfo/lib_napms.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_napms.c,v 1.7 2001/01/22 18:01:53 millert Exp $ */ +/* $OpenBSD: lib_napms.c,v 1.8 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2005,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -38,6 +38,8 @@ * * The routine napms. * + * (This file was originally written by Eric Raymond; however except for + * comments, none of the original code remains - T.Dickey). */ #include <curses.priv.h> @@ -47,20 +49,9 @@ #if HAVE_SYS_TIME_H #include <sys/time.h> /* needed for MacOS X DP3 */ #endif -#elif USE_FUNC_POLL -#if HAVE_SYS_TIME_H -#include <sys/time.h> -#endif -#elif HAVE_SELECT -#if HAVE_SYS_TIME_H && HAVE_SYS_TIME_SELECT -#include <sys/time.h> -#endif -#if HAVE_SYS_SELECT_H -#include <sys/select.h> -#endif #endif -MODULE_ID("$From: lib_napms.c,v 1.11 2000/12/10 02:55:07 tom Exp $") +MODULE_ID("$Id: lib_napms.c,v 1.8 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(int) napms(int ms) @@ -69,23 +60,17 @@ napms(int ms) #if HAVE_NANOSLEEP { - struct timespec ts; - ts.tv_sec = ms / 1000; - ts.tv_nsec = (ms % 1000) * 1000000; - nanosleep(&ts, NULL); - } -#elif USE_FUNC_POLL - { - struct pollfd fds[1]; - poll(fds, 0, ms); - } -#elif HAVE_SELECT - { - struct timeval tval; - tval.tv_sec = ms / 1000; - tval.tv_usec = (ms % 1000) * 1000; - select(0, NULL, NULL, NULL, &tval); + struct timespec request, remaining; + request.tv_sec = ms / 1000; + request.tv_nsec = (ms % 1000) * 1000000; + while (nanosleep(&request, &remaining) == -1 + && errno == EINTR) { + request = remaining; + } } +#else + _nc_timed_wait(0, 0, ms, (int *) 0 EVENTLIST_2nd(0)); #endif + returnCode(OK); } diff --git a/lib/libcurses/tinfo/lib_options.c b/lib/libcurses/tinfo/lib_options.c index ca96bc3d7db..00e079fce5b 100644 --- a/lib/libcurses/tinfo/lib_options.c +++ b/lib/libcurses/tinfo/lib_options.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_options.c,v 1.9 2001/01/22 18:01:53 millert Exp $ */ +/* $OpenBSD: lib_options.c,v 1.10 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2006,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -44,7 +45,10 @@ #include <term.h> -MODULE_ID("$From: lib_options.c,v 1.42 2000/12/10 02:55:07 tom Exp $") +MODULE_ID("$Id: lib_options.c,v 1.10 2010/01/12 23:22:06 nicm Exp $") + +static int _nc_curs_set(SCREEN *, int); +static int _nc_meta(SCREEN *, bool); NCURSES_EXPORT(int) idlok(WINDOW *win, bool flag) @@ -74,7 +78,7 @@ halfdelay(int t) { T((T_CALLED("halfdelay(%d)"), t)); - if (t < 1 || t > 255) + if (t < 1 || t > 255 || SP == 0) returnCode(ERR); cbreak(); @@ -100,7 +104,7 @@ nodelay(WINDOW *win, bool flag) NCURSES_EXPORT(int) notimeout(WINDOW *win, bool f) { - T((T_CALLED("notimout(%p,%d)"), win, f)); + T((T_CALLED("notimeout(%p,%d)"), win, f)); if (win) { win->_notimeout = f; @@ -117,6 +121,7 @@ wtimeout(WINDOW *win, int delay) if (win) { win->_delay = delay; } + returnVoid; } NCURSES_EXPORT(int) @@ -126,7 +131,7 @@ keypad(WINDOW *win, bool flag) if (win) { win->_use_keypad = flag; - returnCode(_nc_keypad(flag)); + returnCode(_nc_keypad(SP, flag)); } else returnCode(ERR); } @@ -134,19 +139,12 @@ keypad(WINDOW *win, bool flag) NCURSES_EXPORT(int) meta(WINDOW *win GCC_UNUSED, bool flag) { + int result; + /* Ok, we stay relaxed and don't signal an error if win is NULL */ T((T_CALLED("meta(%p,%d)"), win, flag)); - - SP->_use_meta = flag; - - if (flag && meta_on) { - TPUTS_TRACE("meta_on"); - putp(meta_on); - } else if (!flag && meta_off) { - TPUTS_TRACE("meta_off"); - putp(meta_off); - } - returnCode(OK); + result = _nc_meta(SP, flag); + returnCode(result); } /* curs_set() moved here to narrow the kernel interface */ @@ -154,51 +152,23 @@ meta(WINDOW *win GCC_UNUSED, bool flag) NCURSES_EXPORT(int) curs_set(int vis) { - int cursor = SP->_cursor; + int result; T((T_CALLED("curs_set(%d)"), vis)); - - if (vis < 0 || vis > 2) - returnCode(ERR); - - if (vis == cursor) - returnCode(cursor); - - switch (vis) { - case 2: - if (cursor_visible) { - TPUTS_TRACE("cursor_visible"); - putp(cursor_visible); - } else - returnCode(ERR); - break; - case 1: - if (cursor_normal) { - TPUTS_TRACE("cursor_normal"); - putp(cursor_normal); - } else - returnCode(ERR); - break; - case 0: - if (cursor_invisible) { - TPUTS_TRACE("cursor_invisible"); - putp(cursor_invisible); - } else - returnCode(ERR); - break; - } - SP->_cursor = vis; - _nc_flush(); - - returnCode(cursor == -1 ? 1 : cursor); + result = _nc_curs_set(SP, vis); + returnCode(result); } NCURSES_EXPORT(int) typeahead(int fd) { T((T_CALLED("typeahead(%d)"), fd)); - SP->_checkfd = fd; - returnCode(OK); + if (SP != 0) { + SP->_checkfd = fd; + returnCode(OK); + } else { + returnCode(ERR); + } } /* @@ -210,7 +180,7 @@ typeahead(int fd) #if NCURSES_EXT_FUNCS static int -has_key_internal(int keycode, struct tries *tp) +has_key_internal(int keycode, TRIES * tp) { if (tp == 0) return (FALSE); @@ -225,10 +195,39 @@ NCURSES_EXPORT(int) has_key(int keycode) { T((T_CALLED("has_key(%d)"), keycode)); - returnCode(has_key_internal(keycode, SP->_keytry)); + returnCode(SP != 0 ? has_key_internal(keycode, SP->_keytry) : FALSE); } #endif /* NCURSES_EXT_FUNCS */ +/* + * Internal entrypoints use SCREEN* parameter to obtain capabilities rather + * than cur_term. + */ +#undef CUR +#define CUR (sp->_term)->type. + +static int +_nc_putp(const char *name GCC_UNUSED, const char *value) +{ + int rc = ERR; + + if (value) { + TPUTS_TRACE(name); + rc = putp(value); + } + return rc; +} + +static int +_nc_putp_flush(const char *name, const char *value) +{ + int rc = _nc_putp(name, value); + if (rc != ERR) { + _nc_flush(); + } + return rc; +} + /* Turn the keypad on/off * * Note: we flush the output because changing this mode causes some terminals @@ -237,21 +236,94 @@ has_key(int keycode) * the terminal state _before_ switching modes. */ NCURSES_EXPORT(int) -_nc_keypad(bool flag) +_nc_keypad(SCREEN *sp, bool flag) { - if (flag && keypad_xmit) { - TPUTS_TRACE("keypad_xmit"); - putp(keypad_xmit); - _nc_flush(); - } else if (!flag && keypad_local) { - TPUTS_TRACE("keypad_local"); - putp(keypad_local); - _nc_flush(); + int rc = ERR; + + if (sp != 0) { +#ifdef USE_PTHREADS + /* + * We might have this situation in a multithreaded application that + * has wgetch() reading in more than one thread. putp() and below + * may use SP explicitly. + */ + if (_nc_use_pthreads && sp != SP) { + SCREEN *save_sp; + + /* cannot use use_screen(), since that is not in tinfo library */ + _nc_lock_global(curses); + save_sp = SP; + _nc_set_screen(sp); + rc = _nc_keypad(sp, flag); + _nc_set_screen(save_sp); + _nc_unlock_global(curses); + } else +#endif + { + if (flag) { + (void) _nc_putp_flush("keypad_xmit", keypad_xmit); + } else if (!flag && keypad_local) { + (void) _nc_putp_flush("keypad_local", keypad_local); + } + + if (flag && !sp->_tried) { + _nc_init_keytry(sp); + sp->_tried = TRUE; + } + sp->_keypad_on = flag; + rc = OK; + } + } + return (rc); +} + +static int +_nc_curs_set(SCREEN *sp, int vis) +{ + int result = ERR; + + T((T_CALLED("curs_set(%d)"), vis)); + if (sp != 0 && vis >= 0 && vis <= 2) { + int cursor = sp->_cursor; + + if (vis == cursor) { + result = cursor; + } else { + switch (vis) { + case 2: + result = _nc_putp_flush("cursor_visible", cursor_visible); + break; + case 1: + result = _nc_putp_flush("cursor_normal", cursor_normal); + break; + case 0: + result = _nc_putp_flush("cursor_invisible", cursor_invisible); + break; + } + if (result != ERR) + result = (cursor == -1 ? 1 : cursor); + sp->_cursor = vis; + } } + returnCode(result); +} + +static int +_nc_meta(SCREEN *sp, bool flag) +{ + int result = ERR; + + /* Ok, we stay relaxed and don't signal an error if win is NULL */ + + if (SP != 0) { + SP->_use_meta = flag; - if (flag && !SP->_tried) { - _nc_init_keytry(); - SP->_tried = TRUE; + if (flag) { + _nc_putp("meta_on", meta_on); + } else { + _nc_putp("meta_off", meta_off); + } + result = OK; } - return (OK); + return result; } diff --git a/lib/libcurses/tinfo/lib_print.c b/lib/libcurses/tinfo/lib_print.c index 9a5b3157e07..5043c551004 100644 --- a/lib/libcurses/tinfo/lib_print.c +++ b/lib/libcurses/tinfo/lib_print.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_print.c,v 1.4 2003/03/18 16:55:54 millert Exp $ */ +/* $OpenBSD: lib_print.c,v 1.5 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2002,2006 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -37,7 +37,7 @@ #include <term.h> -MODULE_ID("$From: lib_print.c,v 1.13 2000/12/10 02:55:07 tom Exp $") +MODULE_ID("$Id: lib_print.c,v 1.5 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(int) mcprint(char *data, int len) @@ -53,7 +53,7 @@ mcprint(char *data, int len) } if (prtr_non) { - switchon = tparm(prtr_non, len); + switchon = TPARM_1(prtr_non, len); onsize = strlen(switchon); offsize = 0; } else { @@ -63,13 +63,13 @@ mcprint(char *data, int len) } res = onsize + len + offsize + 1; - if ((mybuf = typeMalloc(char, res)) == (char *) 0) { + if (switchon == 0 || (mybuf = typeMalloc(char, res)) == 0) { errno = ENOMEM; return (ERR); } (void) strlcpy(mybuf, switchon, res); - memcpy(mybuf + onsize, data, len); + memcpy(mybuf + onsize, data, (unsigned) len); if (offsize) (void) strlcpy(mybuf + onsize + len, prtr_off, res - onsize - len); diff --git a/lib/libcurses/tinfo/lib_raw.c b/lib/libcurses/tinfo/lib_raw.c index eb10b64e30b..724ba92a4a2 100644 --- a/lib/libcurses/tinfo/lib_raw.c +++ b/lib/libcurses/tinfo/lib_raw.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_raw.c,v 1.7 2001/01/22 18:01:53 millert Exp $ */ +/* $OpenBSD: lib_raw.c,v 1.8 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2002,2007 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1998 on * ****************************************************************************/ /* @@ -50,7 +51,7 @@ #include <curses.priv.h> #include <term.h> /* cur_term */ -MODULE_ID("$From: lib_raw.c,v 1.10 2000/12/10 02:55:07 tom Exp $") +MODULE_ID("$Id: lib_raw.c,v 1.8 2010/01/12 23:22:06 nicm Exp $") #if SVR4_TERMIO && !defined(_POSIX_SOURCE) #define _POSIX_SOURCE @@ -62,13 +63,16 @@ MODULE_ID("$From: lib_raw.c,v 1.10 2000/12/10 02:55:07 tom Exp $") #ifdef __EMX__ #include <io.h> +#define _nc_setmode(mode) setmode(SP->_ifd, mode) +#else +#define _nc_setmode(mode) /* nothing */ #endif #define COOKED_INPUT (IXON|BRKINT|PARMRK) #ifdef TRACE -#define BEFORE(N) if (_nc_tracing&TRACE_BITS) _tracef("%s before bits: %s", N, _nc_tracebits()) -#define AFTER(N) if (_nc_tracing&TRACE_BITS) _tracef("%s after bits: %s", N, _nc_tracebits()) +#define BEFORE(N) if (USE_TRACEF(TRACE_BITS)) _nc_locked_tracef("%s before bits: %s", N, _nc_tracebits()) +#define AFTER(N) if (USE_TRACEF(TRACE_BITS)) _nc_locked_tracef("%s after bits: %s", N, _nc_tracebits()) #else #define BEFORE(s) #define AFTER(s) @@ -77,162 +81,218 @@ MODULE_ID("$From: lib_raw.c,v 1.10 2000/12/10 02:55:07 tom Exp $") NCURSES_EXPORT(int) raw(void) { + int result = ERR; + T((T_CALLED("raw()"))); - if (SP != 0 && cur_term != 0) { - SP->_raw = TRUE; - SP->_cbreak = 1; + if (SP != 0 && cur_term != 0) { + TTY buf; -#ifdef __EMX__ - setmode(SP->_ifd, O_BINARY); -#endif + BEFORE("raw"); + _nc_setmode(O_BINARY); + buf = cur_term->Nttyb; #ifdef TERMIOS - BEFORE("raw"); - cur_term->Nttyb.c_lflag &= ~(ICANON | ISIG | IEXTEN); - cur_term->Nttyb.c_iflag &= ~(COOKED_INPUT); - cur_term->Nttyb.c_cc[VMIN] = 1; - cur_term->Nttyb.c_cc[VTIME] = 0; - AFTER("raw"); + buf.c_lflag &= ~(ICANON | ISIG | IEXTEN); + buf.c_iflag &= ~(COOKED_INPUT); + buf.c_cc[VMIN] = 1; + buf.c_cc[VTIME] = 0; #else - cur_term->Nttyb.sg_flags |= RAW; + buf.sg_flags |= RAW; #endif - returnCode(_nc_set_tty_mode(&cur_term->Nttyb)); + if ((result = _nc_set_tty_mode(&buf)) == OK) { + SP->_raw = TRUE; + SP->_cbreak = 1; + cur_term->Nttyb = buf; + } + AFTER("raw"); } - returnCode(ERR); + returnCode(result); } NCURSES_EXPORT(int) cbreak(void) { + int result = ERR; + T((T_CALLED("cbreak()"))); - SP->_cbreak = 1; + if (SP != 0 && cur_term != 0) { + TTY buf; -#ifdef __EMX__ - setmode(SP->_ifd, O_BINARY); -#endif + BEFORE("cbreak"); + _nc_setmode(O_BINARY); + buf = cur_term->Nttyb; #ifdef TERMIOS - BEFORE("cbreak"); - cur_term->Nttyb.c_lflag &= ~ICANON; - cur_term->Nttyb.c_iflag &= ~ICRNL; - cur_term->Nttyb.c_lflag |= ISIG; - cur_term->Nttyb.c_cc[VMIN] = 1; - cur_term->Nttyb.c_cc[VTIME] = 0; - AFTER("cbreak"); + buf.c_lflag &= ~ICANON; + buf.c_iflag &= ~ICRNL; + buf.c_lflag |= ISIG; + buf.c_cc[VMIN] = 1; + buf.c_cc[VTIME] = 0; #else - cur_term->Nttyb.sg_flags |= CBREAK; + buf.sg_flags |= CBREAK; #endif - returnCode(_nc_set_tty_mode(&cur_term->Nttyb)); + if ((result = _nc_set_tty_mode(&buf)) == OK) { + SP->_cbreak = 1; + cur_term->Nttyb = buf; + } + AFTER("cbreak"); + } + returnCode(result); } +/* + * Note: + * this implementation may be wrong. See the comment under intrflush(). + */ NCURSES_EXPORT(void) qiflush(void) { + int result = ERR; + T((T_CALLED("qiflush()"))); - /* - * Note: this implementation may be wrong. See the comment under - * intrflush(). - */ + if (cur_term != 0) { + TTY buf; + BEFORE("qiflush"); + buf = cur_term->Nttyb; #ifdef TERMIOS - BEFORE("qiflush"); - cur_term->Nttyb.c_lflag &= ~(NOFLSH); - AFTER("qiflush"); - (void) _nc_set_tty_mode(&cur_term->Nttyb); - returnVoid; + buf.c_lflag &= ~(NOFLSH); + result = _nc_set_tty_mode(&buf); +#else + /* FIXME */ #endif + if (result == OK) + cur_term->Nttyb = buf; + AFTER("qiflush"); + } + returnVoid; } NCURSES_EXPORT(int) noraw(void) { + int result = ERR; + T((T_CALLED("noraw()"))); - SP->_raw = FALSE; - SP->_cbreak = 0; + if (SP != 0 && cur_term != 0) { + TTY buf; -#ifdef __EMX__ - setmode(SP->_ifd, O_TEXT); -#endif + BEFORE("noraw"); + _nc_setmode(O_TEXT); + buf = cur_term->Nttyb; #ifdef TERMIOS - BEFORE("noraw"); - cur_term->Nttyb.c_lflag |= ISIG | ICANON | - (cur_term->Ottyb.c_lflag & IEXTEN); - cur_term->Nttyb.c_iflag |= COOKED_INPUT; - AFTER("noraw"); + buf.c_lflag |= ISIG | ICANON | + (cur_term->Ottyb.c_lflag & IEXTEN); + buf.c_iflag |= COOKED_INPUT; #else - cur_term->Nttyb.sg_flags &= ~(RAW | CBREAK); + buf.sg_flags &= ~(RAW | CBREAK); #endif - returnCode(_nc_set_tty_mode(&cur_term->Nttyb)); + if ((result = _nc_set_tty_mode(&buf)) == OK) { + SP->_raw = FALSE; + SP->_cbreak = 0; + cur_term->Nttyb = buf; + } + AFTER("noraw"); + } + returnCode(result); } NCURSES_EXPORT(int) nocbreak(void) { + int result = ERR; + T((T_CALLED("nocbreak()"))); - SP->_cbreak = 0; + if (SP != 0 && cur_term != 0) { + TTY buf; -#ifdef __EMX__ - setmode(SP->_ifd, O_TEXT); -#endif + BEFORE("nocbreak"); + _nc_setmode(O_TEXT); + buf = cur_term->Nttyb; #ifdef TERMIOS - BEFORE("nocbreak"); - cur_term->Nttyb.c_lflag |= ICANON; - cur_term->Nttyb.c_iflag |= ICRNL; - AFTER("nocbreak"); + buf.c_lflag |= ICANON; + buf.c_iflag |= ICRNL; #else - cur_term->Nttyb.sg_flags &= ~CBREAK; + buf.sg_flags &= ~CBREAK; #endif - returnCode(_nc_set_tty_mode(&cur_term->Nttyb)); + if ((result = _nc_set_tty_mode(&buf)) == OK) { + SP->_cbreak = 0; + cur_term->Nttyb = buf; + } + AFTER("nocbreak"); + } + returnCode(result); } +/* + * Note: + * this implementation may be wrong. See the comment under intrflush(). + */ NCURSES_EXPORT(void) noqiflush(void) { + int result = ERR; + T((T_CALLED("noqiflush()"))); - /* - * Note: this implementation may be wrong. See the comment under - * intrflush(). - */ + if (cur_term != 0) { + TTY buf; + BEFORE("noqiflush"); + buf = cur_term->Nttyb; #ifdef TERMIOS - BEFORE("noqiflush"); - cur_term->Nttyb.c_lflag |= NOFLSH; - AFTER("noqiflush"); - (void) _nc_set_tty_mode(&cur_term->Nttyb); - returnVoid; + buf.c_lflag |= NOFLSH; + result = _nc_set_tty_mode(&buf); +#else + /* FIXME */ #endif + if (result == OK) { + cur_term->Nttyb = buf; + } + AFTER("noqiflush"); + } + returnVoid; } +/* + * This call does the same thing as the qiflush()/noqiflush() pair. We know + * for certain that SVr3 intrflush() tweaks the NOFLSH bit; on the other hand, + * the match (in the SVr4 man pages) between the language describing NOFLSH in + * termio(7) and the language describing qiflush()/noqiflush() in + * curs_inopts(3x) is too exact to be coincidence. + */ NCURSES_EXPORT(int) intrflush(WINDOW *win GCC_UNUSED, bool flag) { + int result = ERR; + T((T_CALLED("intrflush(%d)"), flag)); - /* - * This call does the same thing as the qiflush()/noqiflush() pair. We - * know for certain that SVr3 intrflush() tweaks the NOFLSH bit; on the - * other hand, the match (in the SVr4 man pages) between the language - * describing NOFLSH in termio(7) and the language describing - * qiflush()/noqiflush() in curs_inopts(3x) is too exact to be coincidence. - */ + if (cur_term != 0) { + TTY buf; + BEFORE("intrflush"); + buf = cur_term->Nttyb; #ifdef TERMIOS - BEFORE("intrflush"); - if (flag) - cur_term->Nttyb.c_lflag &= ~(NOFLSH); - else - cur_term->Nttyb.c_lflag |= (NOFLSH); - AFTER("intrflush"); - returnCode(_nc_set_tty_mode(&cur_term->Nttyb)); + if (flag) + buf.c_lflag &= ~(NOFLSH); + else + buf.c_lflag |= (NOFLSH); + result = _nc_set_tty_mode(&buf); #else - returnCode(ERR); + /* FIXME */ #endif + if (result == OK) { + cur_term->Nttyb = buf; + } + AFTER("intrflush"); + } + returnCode(result); } diff --git a/lib/libcurses/tinfo/lib_setup.c b/lib/libcurses/tinfo/lib_setup.c index 1db8a06bc1b..63643848a29 100644 --- a/lib/libcurses/tinfo/lib_setup.c +++ b/lib/libcurses/tinfo/lib_setup.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_setup.c,v 1.11 2001/01/22 18:01:53 millert Exp $ */ +/* $OpenBSD: lib_setup.c,v 1.12 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -48,9 +49,13 @@ #define _POSIX_SOURCE #endif +#if HAVE_LOCALE_H +#include <locale.h> +#endif + #include <term.h> /* lines, columns, cur_term */ -MODULE_ID("$From: lib_setup.c,v 1.64 2000/12/10 02:55:07 tom Exp $") +MODULE_ID("$Id: lib_setup.c,v 1.12 2010/01/12 23:22:06 nicm Exp $") /**************************************************************************** * @@ -74,6 +79,10 @@ MODULE_ID("$From: lib_setup.c,v 1.64 2000/12/10 02:55:07 tom Exp $") # include <sys/ptem.h> #endif +#if HAVE_LANGINFO_CODESET +#include <langinfo.h> +#endif + /* * SCO defines TIOCGSIZE and the corresponding struct. Other systems (SunOS, * Solaris, IRIX) define TIOCGWINSZ and struct winsize. @@ -92,31 +101,113 @@ MODULE_ID("$From: lib_setup.c,v 1.64 2000/12/10 02:55:07 tom Exp $") # endif #endif -static int _use_env = TRUE; +/* + * Reduce explicit use of "cur_term" global variable. + */ +#undef CUR +#define CUR termp->type. + +/* + * Wrap global variables in this module. + */ +#if USE_REENTRANT +NCURSES_EXPORT(char *) +NCURSES_PUBLIC_VAR(ttytype) (void) +{ + static char empty[] = ""; + return cur_term ? cur_term->type.term_names : empty; +} +NCURSES_EXPORT(int *) +_nc_ptr_Lines(void) +{ + return ptrLines(); +} +NCURSES_EXPORT(int) +NCURSES_PUBLIC_VAR(LINES) (void) +{ + return *_nc_ptr_Lines(); +} +NCURSES_EXPORT(int *) +_nc_ptr_Cols(void) +{ + return ptrCols(); +} +NCURSES_EXPORT(int) +NCURSES_PUBLIC_VAR(COLS) (void) +{ + return *_nc_ptr_Cols(); +} +NCURSES_EXPORT(int) +NCURSES_PUBLIC_VAR(TABSIZE) (void) +{ + return SP ? SP->_TABSIZE : 8; +} +#else +NCURSES_EXPORT_VAR(char) ttytype[NAMESIZE] = ""; +NCURSES_EXPORT_VAR(int) LINES = 0; +NCURSES_EXPORT_VAR(int) COLS = 0; +NCURSES_EXPORT_VAR(int) TABSIZE = 0; +#endif + +#if NCURSES_EXT_FUNCS +NCURSES_EXPORT(int) +set_tabsize(int value) +{ + int code = OK; +#if USE_REENTRANT + if (SP) { + SP->_TABSIZE = value; + } else { + code = ERR; + } +#else + TABSIZE = value; +#endif + return code; +} +#endif + +#if USE_SIGWINCH +/* + * If we have a pending SIGWINCH, set the flag in each screen. + */ +NCURSES_EXPORT(int) +_nc_handle_sigwinch(SCREEN *sp) +{ + SCREEN *scan; -static void do_prototype(void); + if (_nc_globals.have_sigwinch) { + _nc_globals.have_sigwinch = 0; + + for (each_screen(scan)) { + scan->_sig_winch = TRUE; + } + } + + return (sp ? sp->_sig_winch : 0); +} + +#endif NCURSES_EXPORT(void) use_env(bool f) { - _use_env = f; + T((T_CALLED("use_env()"))); + _nc_prescreen.use_env = f; + returnVoid; } -NCURSES_EXPORT_VAR(int) -LINES = 0; -NCURSES_EXPORT_VAR(int) -COLS = 0; -NCURSES_EXPORT_VAR(int) -TABSIZE = 0; - - static void - _nc_get_screensize(int *linep, int *colp) +NCURSES_EXPORT(void) +_nc_get_screensize(SCREEN *sp, int *linep, int *colp) /* Obtain lines/columns values from the environment and/or terminfo entry */ { + TERMINAL *termp = cur_term; + int my_tabsize; + /* figure out the size of the screen */ T(("screen size: terminfo lines = %d columns = %d", lines, columns)); - if (!_use_env) { + if (!_nc_prescreen.use_env) { *linep = (int) lines; *colp = (int) columns; } else { /* usually want to query LINES and COLUMNS from environment */ @@ -162,7 +253,7 @@ TABSIZE = 0; * environment variable. */ if (*linep <= 0) - *linep = WINSIZE_ROWS(size); + *linep = (sp != 0 && sp->_filtered) ? 1 : WINSIZE_ROWS(size); if (*colp <= 0) *colp = WINSIZE_COLS(size); } @@ -180,8 +271,10 @@ TABSIZE = 0; } /* the ultimate fallback, assume fixed 24x80 size */ - if (*linep <= 0 || *colp <= 0) { + if (*linep <= 0) { *linep = 24; + } + if (*colp <= 0) { *colp = 80; } @@ -196,22 +289,42 @@ TABSIZE = 0; T(("screen size is %dx%d", *linep, *colp)); if (VALID_NUMERIC(init_tabs)) - TABSIZE = (int) init_tabs; + my_tabsize = (int) init_tabs; else - TABSIZE = 8; - T(("TABSIZE = %d", TABSIZE)); + my_tabsize = 8; +#if USE_REENTRANT + if (sp != 0) + sp->_TABSIZE = my_tabsize; +#else + TABSIZE = my_tabsize; +#endif + T(("TABSIZE = %d", TABSIZE)); } #if USE_SIZECHANGE NCURSES_EXPORT(void) -_nc_update_screensize(void) +_nc_update_screensize(SCREEN *sp) { - int my_lines, my_cols; + TERMINAL *termp = cur_term; + int old_lines = lines; + int new_lines; + int old_cols = columns; + int new_cols; - _nc_get_screensize(&my_lines, &my_cols); - if (SP != 0 && SP->_resize != 0) - SP->_resize(my_lines, my_cols); + _nc_get_screensize(sp, &new_lines, &new_cols); + + /* + * See is_term_resized() and resizeterm(). + * We're doing it this way because those functions belong to the upper + * ncurses library, while this resides in the lower terminfo library. + */ + if (sp != 0 + && sp->_resize != 0) { + if ((new_lines != old_lines) || (new_cols != old_cols)) + sp->_resize(new_lines, new_cols); + sp->_sig_winch = FALSE; + } } #endif @@ -237,33 +350,16 @@ _nc_update_screensize(void) exit(EXIT_FAILURE);\ } -#if USE_DATABASE +#if USE_DATABASE || USE_TERMCAP +/* + * Return 1 if entry found, 0 if not found, -1 if database not accessible, + * just like tgetent(). + */ static int -grab_entry(const char *const tn, TERMTYPE * const tp) -/* return 1 if entry found, 0 if not found, -1 if database not accessible */ +grab_entry(const char *const tn, TERMTYPE *const tp) { char filename[PATH_MAX]; - int status; - - /* - * $TERM shouldn't contain pathname delimiters. - */ - if (strchr(tn, '/')) - return 0; - - if ((status = _nc_read_entry(tn, filename, tp)) != 1) { - -#if !PURE_TERMINFO - /* - * Try falling back on the termcap file. - * Note: allowing this call links the entire terminfo/termcap - * compiler into the startup code. It's preferable to build a - * real terminfo database and use that. - */ - status = _nc_read_termcap_entry(tn, tp); -#endif /* PURE_TERMINFO */ - - } + int status = _nc_read_entry(tn, filename, tp); /* * If we have an entry, force all of the cancelled strings to null @@ -271,8 +367,8 @@ grab_entry(const char *const tn, TERMTYPE * const tp) * (The terminfo compiler bypasses this logic, since it must know if * a string is cancelled, for merging entries). */ - if (status == 1) { - int n; + if (status == TGETENT_YES) { + unsigned n; for_each_boolean(n, tp) { if (!VALID_BOOLEAN(tp->Booleans[n])) tp->Booleans[n] = FALSE; @@ -286,139 +382,252 @@ grab_entry(const char *const tn, TERMTYPE * const tp) } #endif -NCURSES_EXPORT_VAR(char) ttytype[NAMESIZE] = ""; +/* +** do_prototype() +** +** Take the real command character out of the CC environment variable +** and substitute it in for the prototype given in 'command_character'. +*/ +static void +do_prototype(TERMINAL * termp) +{ + unsigned i; + char CC; + char proto; + char *tmp; + + if ((tmp = getenv("CC")) != 0) { + if ((CC = *tmp) != 0) { + proto = *command_character; + + for_each_string(i, &(termp->type)) { + for (tmp = termp->type.Strings[i]; *tmp; tmp++) { + if (*tmp == proto) + *tmp = CC; + } + } + } + } +} /* - * setupterm(termname, Filedes, errret) - * - * Find and read the appropriate object file for the terminal - * Make cur_term point to the structure. - * + * Find the locale which is in effect. + */ +NCURSES_EXPORT(char *) +_nc_get_locale(void) +{ + char *env; +#if HAVE_LOCALE_H + /* + * This is preferable to using getenv() since it ensures that we are using + * the locale which was actually initialized by the application. + */ + env = setlocale(LC_CTYPE, 0); +#else + if (((env = getenv("LC_ALL")) != 0 && *env != '\0') + || ((env = getenv("LC_CTYPE")) != 0 && *env != '\0') + || ((env = getenv("LANG")) != 0 && *env != '\0')) { + ; + } +#endif + T(("_nc_get_locale %s", _nc_visbuf(env))); + return env; +} + +/* + * Check if we are running in a UTF-8 locale. + */ +NCURSES_EXPORT(int) +_nc_unicode_locale(void) +{ + int result = 0; +#if HAVE_LANGINFO_CODESET + char *env = nl_langinfo(CODESET); + result = !strcmp(env, "UTF-8"); + T(("_nc_unicode_locale(%s) ->%d", env, result)); +#else + char *env = _nc_get_locale(); + if (env != 0) { + if (strstr(env, ".UTF-8") != 0) { + result = 1; + T(("_nc_unicode_locale(%s) ->%d", env, result)); + } + } +#endif + return result; +} + +#define CONTROL_N(s) ((s) != 0 && strstr(s, "\016") != 0) +#define CONTROL_O(s) ((s) != 0 && strstr(s, "\017") != 0) + +/* + * Check for known broken cases where a UTF-8 locale breaks the alternate + * character set. */ +NCURSES_EXPORT(int) +_nc_locale_breaks_acs(TERMINAL * termp) +{ + char *env; + + if ((env = getenv("NCURSES_NO_UTF8_ACS")) != 0) { + return atoi(env); + } else if ((env = getenv("TERM")) != 0) { + if (strstr(env, "linux")) + return 1; /* always broken */ + if (strstr(env, "screen") != 0 + && ((env = getenv("TERMCAP")) != 0 + && strstr(env, "screen") != 0) + && strstr(env, "hhII00") != 0) { + if (CONTROL_N(enter_alt_charset_mode) || + CONTROL_O(enter_alt_charset_mode) || + CONTROL_N(set_attributes) || + CONTROL_O(set_attributes)) + return 1; + } + } + return 0; +} +/* + * This entrypoint is called from tgetent() to allow a special case of reusing + * the same TERMINAL data (see comment). + */ NCURSES_EXPORT(int) -setupterm -(NCURSES_CONST char *tname, int Filedes, int *errret) +_nc_setupterm(NCURSES_CONST char *tname, int Filedes, int *errret, bool reuse) { - struct term *term_ptr; + TERMINAL *termp; int status; + START_TRACE(); T((T_CALLED("setupterm(%s,%d,%p)"), _nc_visbuf(tname), Filedes, errret)); if (tname == 0) { tname = getenv("TERM"); if (tname == 0 || *tname == '\0') { - ret_error0(-1, "TERM environment variable not set.\n"); + ret_error0(TGETENT_ERR, "TERM environment variable not set.\n"); } } + if (strlen(tname) > MAX_NAME_SIZE) { - ret_error(-1, "TERM environment must be <= %d characters.\n", + ret_error(TGETENT_ERR, + "TERM environment must be <= %d characters.\n", MAX_NAME_SIZE); } T(("your terminal name is %s", tname)); - term_ptr = typeCalloc(TERMINAL, 1); + /* + * Allow output redirection. This is what SVr3 does. If stdout is + * directed to a file, screen updates go to standard error. + */ + if (Filedes == STDOUT_FILENO && !isatty(Filedes)) + Filedes = STDERR_FILENO; - if (term_ptr == 0) { - ret_error0(-1, "Not enough memory to create terminal structure.\n"); - } -#if USE_DATABASE - status = grab_entry(tname, &term_ptr->type); + /* + * Check if we have already initialized to use this terminal. If so, we + * do not need to re-read the terminfo entry, or obtain TTY settings. + * + * This is an improvement on SVr4 curses. If an application mixes curses + * and termcap calls, it may call both initscr and tgetent. This is not + * really a good thing to do, but can happen if someone tries using ncurses + * with the readline library. The problem we are fixing is that when + * tgetent calls setupterm, the resulting Ottyb struct in cur_term is + * zeroed. A subsequent call to endwin uses the zeroed terminal settings + * rather than the ones saved in initscr. So we check if cur_term appears + * to contain terminal settings for the same output file as our current + * call - and copy those terminal settings. (SVr4 curses does not do this, + * however applications that are working around the problem will still work + * properly with this feature). + */ + if (reuse + && (termp = cur_term) != 0 + && termp->Filedes == Filedes + && termp->_termname != 0 + && !strcmp(termp->_termname, tname) + && _nc_name_match(termp->type.term_names, tname, "|")) { + T(("reusing existing terminal information and mode-settings")); + } else { + + termp = typeCalloc(TERMINAL, 1); + + if (termp == 0) { + ret_error0(TGETENT_ERR, + "Not enough memory to create terminal structure.\n"); + } +#if USE_DATABASE || USE_TERMCAP + status = grab_entry(tname, &termp->type); #else - status = 0; + status = TGETENT_NO; #endif - /* try fallback list if entry on disk */ - if (status != 1) { - const TERMTYPE *fallback = _nc_fallback(tname); + /* try fallback list if entry on disk */ + if (status != TGETENT_YES) { + const TERMTYPE *fallback = _nc_fallback(tname); - if (fallback) { - term_ptr->type = *fallback; - status = 1; + if (fallback) { + termp->type = *fallback; + status = TGETENT_YES; + } } - } - if (status == -1) { - ret_error0(-1, "terminals database is inaccessible\n"); - } else if (status == 0) { - ret_error(0, "'%s': unknown terminal type.\n", tname); - } + if (status != TGETENT_YES) { + del_curterm(termp); + if (status == TGETENT_ERR) { + ret_error0(status, "terminals database is inaccessible\n"); + } else if (status == TGETENT_NO) { + ret_error(status, "'%s': unknown terminal type.\n", tname); + } + } +#if !USE_REENTRANT + strncpy(ttytype, termp->type.term_names, NAMESIZE - 1); + ttytype[NAMESIZE - 1] = '\0'; +#endif - /* - * Improve on SVr4 curses. If an application mixes curses and termcap - * calls, it may call both initscr and tgetent. This is not really a - * good thing to do, but can happen if someone tries using ncurses with - * the readline library. The problem we are fixing is that when - * tgetent calls setupterm, the resulting Ottyb struct in cur_term is - * zeroed. A subsequent call to endwin uses the zeroed terminal - * settings rather than the ones saved in initscr. So we check if - * cur_term appears to contain terminal settings for the same output - * file as our current call - and copy those terminal settings. (SVr4 - * curses does not do this, however applications that are working - * around the problem will still work properly with this feature). - */ - if (cur_term != 0) { - if (cur_term->Filedes == Filedes) - term_ptr->Ottyb = cur_term->Ottyb; - } + termp->Filedes = Filedes; + termp->_termname = strdup(tname); - set_curterm(term_ptr); + set_curterm(termp); - if (command_character && getenv("CC")) - do_prototype(); + if (command_character && getenv("CC")) + do_prototype(termp); - strlcpy(ttytype, cur_term->type.term_names, NAMESIZE); + /* + * If an application calls setupterm() rather than initscr() or + * newterm(), we will not have the def_prog_mode() call in + * _nc_setupscreen(). Do it now anyway, so we can initialize the + * baudrate. + */ + if (isatty(Filedes)) { + def_prog_mode(); + baudrate(); + } + } /* - * Allow output redirection. This is what SVr3 does. - * If stdout is directed to a file, screen updates go - * to standard error. + * We should always check the screensize, just in case. */ - if (Filedes == STDOUT_FILENO && !isatty(Filedes)) - Filedes = STDERR_FILENO; - cur_term->Filedes = Filedes; - - _nc_get_screensize(&LINES, &COLS); + _nc_get_screensize(SP, ptrLines(), ptrCols()); if (errret) - *errret = 1; - - T((T_CREATE("screen %s %dx%d"), tname, LINES, COLS)); + *errret = TGETENT_YES; if (generic_type) { - ret_error(0, "'%s': I need something more specific.\n", tname); + ret_error(TGETENT_NO, "'%s': I need something more specific.\n", tname); } if (hard_copy) { - ret_error(1, "'%s': I can't handle hardcopy terminals.\n", tname); + ret_error(TGETENT_YES, "'%s': I can't handle hardcopy terminals.\n", tname); } returnCode(OK); } /* -** do_prototype() -** -** Take the real command character out of the CC environment variable -** and substitute it in for the prototype given in 'command_character'. -** -*/ - -static void -do_prototype(void) + * setupterm(termname, Filedes, errret) + * + * Find and read the appropriate object file for the terminal + * Make cur_term point to the structure. + */ +NCURSES_EXPORT(int) +setupterm(NCURSES_CONST char *tname, int Filedes, int *errret) { - int i; - char CC; - char proto; - char *tmp; - - tmp = getenv("CC"); - CC = *tmp; - proto = *command_character; - - for_each_string(i, &(cur_term->type)) { - for (tmp = cur_term->type.Strings[i]; *tmp; tmp++) { - if (*tmp == proto) - *tmp = CC; - } - } + return _nc_setupterm(tname, Filedes, errret, FALSE); } diff --git a/lib/libcurses/tinfo/lib_termcap.c b/lib/libcurses/tinfo/lib_termcap.c index b307aac5754..66ccb8cf63d 100644 --- a/lib/libcurses/tinfo/lib_termcap.c +++ b/lib/libcurses/tinfo/lib_termcap.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_termcap.c,v 1.9 2003/03/18 16:55:54 millert Exp $ */ +/* $OpenBSD: lib_termcap.c,v 1.10 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,27 +31,36 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * + * * + * some of the code in here was contributed by: * + * Magnus Bengtsson, d6mbeng@dtek.chalmers.se (Nov'93) * + * (but it has changed a lot) * ****************************************************************************/ +#define __INTERNAL_CAPS_VISIBLE #include <curses.priv.h> #include <termcap.h> #include <tic.h> +#include <ctype.h> -#define __INTERNAL_CAPS_VISIBLE #include <term_entry.h> -MODULE_ID("$From: lib_termcap.c,v 1.39 2000/12/10 02:56:30 tom Exp $") +MODULE_ID("$Id: lib_termcap.c,v 1.10 2010/01/12 23:22:06 nicm Exp $") -/* - some of the code in here was contributed by: - Magnus Bengtsson, d6mbeng@dtek.chalmers.se -*/ +NCURSES_EXPORT_VAR(char *) UP = 0; +NCURSES_EXPORT_VAR(char *) BC = 0; -NCURSES_EXPORT_VAR(char *) -UP = 0; -NCURSES_EXPORT_VAR(char *) -BC = 0; +#define MyCache _nc_globals.tgetent_cache +#define CacheInx _nc_globals.tgetent_index +#define CacheSeq _nc_globals.tgetent_sequence + +#define FIX_SGR0 MyCache[CacheInx].fix_sgr0 +#define LAST_TRM MyCache[CacheInx].last_term +#define LAST_BUF MyCache[CacheInx].last_bufp +#define LAST_USE MyCache[CacheInx].last_used +#define LAST_SEQ MyCache[CacheInx].sequence /*************************************************************************** * @@ -69,19 +78,73 @@ BC = 0; ***************************************************************************/ NCURSES_EXPORT(int) -tgetent -(char *bufp GCC_UNUSED, const char *name) +tgetent(char *bufp, const char *name) { int errcode; + int n; + bool found_cache = FALSE; + START_TRACE(); T((T_CALLED("tgetent()"))); - setupterm((NCURSES_CONST char *) name, STDOUT_FILENO, &errcode); + _nc_setupterm((NCURSES_CONST char *) name, STDOUT_FILENO, &errcode, TRUE); + + /* + * In general we cannot tell if the fixed sgr0 is still used by the + * caller, but if tgetent() is called with the same buffer, that is + * good enough, since the previous data would be invalidated by the + * current call. + * + * bufp may be a null pointer, e.g., GNU termcap. That allocates data, + * which is good until the next tgetent() call. The conventional termcap + * is inconvenient because of the fixed buffer size, but because it uses + * caller-supplied buffers, can have multiple terminal descriptions in + * use at a given time. + */ + for (n = 0; n < TGETENT_MAX; ++n) { + bool same_result = (MyCache[n].last_used && MyCache[n].last_bufp == bufp); + if (same_result) { + CacheInx = n; + if (FIX_SGR0 != 0) { + FreeAndNull(FIX_SGR0); + } + /* + * Also free the terminfo data that we loaded (much bigger leak). + */ + if (LAST_TRM != 0 && LAST_TRM != cur_term) { + TERMINAL *trm = LAST_TRM; + del_curterm(LAST_TRM); + for (CacheInx = 0; CacheInx < TGETENT_MAX; ++CacheInx) + if (LAST_TRM == trm) + LAST_TRM = 0; + CacheInx = n; + } + found_cache = TRUE; + break; + } + } + if (!found_cache) { + int best = 0; + + for (CacheInx = 0; CacheInx < TGETENT_MAX; ++CacheInx) { + if (LAST_SEQ < MyCache[best].sequence) { + best = CacheInx; + } + } + CacheInx = best; + } + LAST_TRM = cur_term; + LAST_SEQ = ++CacheSeq; + + PC = 0; + UP = 0; + BC = 0; + FIX_SGR0 = 0; /* don't free it - application may still use */ if (errcode == 1) { if (cursor_left) - if ((backspaces_with_bs = !strcmp(cursor_left, "\b")) == 0) + if ((backspaces_with_bs = (char) !strcmp(cursor_left, "\b")) == 0) backspace_if_not_bs = cursor_left; /* we're required to export these */ @@ -92,6 +155,18 @@ tgetent if (backspace_if_not_bs != NULL) BC = backspace_if_not_bs; + if ((FIX_SGR0 = _nc_trim_sgr0(&(cur_term->type))) != 0) { + if (!strcmp(FIX_SGR0, exit_attribute_mode)) { + if (FIX_SGR0 != exit_attribute_mode) { + free(FIX_SGR0); + } + FIX_SGR0 = 0; + } + } + LAST_BUF = bufp; + LAST_USE = TRUE; + + SetNoPadding(SP); (void) baudrate(); /* sets ospeed as a side-effect */ /* LINT_PREPRO @@ -116,7 +191,7 @@ tgetent NCURSES_EXPORT(int) tgetflag(NCURSES_CONST char *id) { - int i; + unsigned i; T((T_CALLED("tgetflag(%s)"), id)); if (cur_term != 0) { @@ -144,7 +219,7 @@ tgetflag(NCURSES_CONST char *id) NCURSES_EXPORT(int) tgetnum(NCURSES_CONST char *id) { - int i; + unsigned i; T((T_CALLED("tgetnum(%s)"), id)); if (cur_term != 0) { @@ -171,28 +246,49 @@ tgetnum(NCURSES_CONST char *id) ***************************************************************************/ NCURSES_EXPORT(char *) -tgetstr -(NCURSES_CONST char *id, char **area) +tgetstr(NCURSES_CONST char *id, char **area) { - int i; + unsigned i; + char *result = NULL, *base; + if (area != 0 && *area != 0) + base = *area; T((T_CALLED("tgetstr(%s,%p)"), id, area)); if (cur_term != 0) { TERMTYPE *tp = &(cur_term->type); for_each_string(i, tp) { const char *capname = ExtStrname(tp, i, strcodes); if (!strncmp(id, capname, 2)) { - TR(TRACE_DATABASE, ("found match : %s", _nc_visbuf(tp->Strings[i]))); + result = tp->Strings[i]; + TR(TRACE_DATABASE, ("found match : %s", _nc_visbuf(result))); /* setupterm forces canceled strings to null */ - if (area != 0 - && *area != 0 - && VALID_STRING(tp->Strings[i])) { - (void) strlcpy(*area, tp->Strings[i], 1024); - *area += strlen(*area) + 1; + if (VALID_STRING(result)) { + if (result == exit_attribute_mode + && FIX_SGR0 != 0) { + result = FIX_SGR0; + TR(TRACE_DATABASE, ("altered to : %s", _nc_visbuf(result))); + } + if (area != 0 && *area != 0) { + (void) strlcpy(*area, result, 1024 - (*area - base)); + result = *area; + *area += strlen(*area) + 1; + } } - returnPtr(tp->Strings[i]); + break; } } } - returnPtr(NULL); + returnPtr(result); +} + +#if NO_LEAKS +NCURSES_EXPORT(void) +_nc_tgetent_leaks(void) +{ + for (CacheInx = 0; CacheInx < TGETENT_MAX; ++CacheInx) { + FreeIfNeeded(FIX_SGR0); + if (LAST_TRM != 0) + del_curterm(LAST_TRM); + } } +#endif diff --git a/lib/libcurses/tinfo/lib_termname.c b/lib/libcurses/tinfo/lib_termname.c index 8e744f1ed31..f4ddf8b334b 100644 --- a/lib/libcurses/tinfo/lib_termname.c +++ b/lib/libcurses/tinfo/lib_termname.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_termname.c,v 1.4 2003/03/18 16:55:54 millert Exp $ */ +/* $OpenBSD: lib_termname.c,v 1.5 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2001,2003 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,21 +29,18 @@ ****************************************************************************/ #include <curses.priv.h> -#include <tic.h> /* for MAX_ALIAS */ -MODULE_ID("$From: lib_termname.c,v 1.6 2000/12/10 02:55:08 tom Exp $") +MODULE_ID("$Id: lib_termname.c,v 1.5 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(char *) termname(void) { - char *name = getenv("TERM"); - static char ret[MAX_ALIAS + 1]; + char *name = 0; - T(("termname() called")); + T((T_CALLED("termname()"))); - if (name != 0) { - (void) strlcpy(ret, name, sizeof(ret)); - name = ret; - } - return name; + if (cur_term != 0) + name = cur_term->_termname; + + returnPtr(name); } diff --git a/lib/libcurses/tinfo/lib_tgoto.c b/lib/libcurses/tinfo/lib_tgoto.c index bb7fb9c2670..536771fd17e 100644 --- a/lib/libcurses/tinfo/lib_tgoto.c +++ b/lib/libcurses/tinfo/lib_tgoto.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_tgoto.c,v 1.4 2003/03/18 16:55:54 millert Exp $ */ +/* $OpenBSD: lib_tgoto.c,v 1.5 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 2000 Free Software Foundation, Inc. * + * Copyright (c) 2000-2006,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -37,7 +37,7 @@ #include <ctype.h> #include <termcap.h> -MODULE_ID("$From: lib_tgoto.c,v 1.5 2000/12/10 01:33:16 tom Exp $") +MODULE_ID("$Id: lib_tgoto.c,v 1.5 2010/01/12 23:22:06 nicm Exp $") #if !PURE_TERMINFO static bool @@ -91,13 +91,13 @@ tgoto_internal(const char *string, int x, int y) while (*string != 0) { if ((used + need) > length) { length += (used + need); - if ((result = _nc_doalloc(result, length)) == 0) { + if ((result = typeRealloc(char, length, result)) == 0) { length = 0; break; } } if (*string == '%') { - char *fmt = 0; + const char *fmt = 0; switch (*++string) { case '\0': @@ -115,7 +115,7 @@ tgoto_internal(const char *string, int x, int y) *value %= 1000; break; case '+': - *value += CharOf(*++string); + *value += UChar(*++string); /* FALLTHRU */ case '.': /* @@ -131,7 +131,7 @@ tgoto_internal(const char *string, int x, int y) *value = 0200; /* tputs will treat this as \0 */ } } - result[used++] = *value++; + result[used++] = (char) *value++; break; case '%': result[used++] = *string; @@ -158,7 +158,7 @@ tgoto_internal(const char *string, int x, int y) *value = 16 * (*value / 10) + (*value % 10); break; case 'D': /* Reverse coding (Delta Data) */ - *value -= 2 * (*value / 16); + *value -= 2 * (*value % 16); break; } if (fmt != 0) { @@ -175,14 +175,14 @@ tgoto_internal(const char *string, int x, int y) } string++; } - if (need_BC) { + if (result != 0) { copied = strlcpy(result + used, BC, length - used); if (copied < length - used) used += copied; else used += length - used - 1; + result[used] = '\0'; } - result[used] = '\0'; return result; } #endif @@ -192,8 +192,7 @@ tgoto_internal(const char *string, int x, int y) * the last two arguments when invoking tparm(). */ NCURSES_EXPORT(char *) -tgoto -(const char *string, int x, int y) +tgoto(const char *string, int x, int y) { char *result; @@ -203,6 +202,6 @@ tgoto result = tgoto_internal(string, x, y); else #endif - result = tparm((NCURSES_CONST char *) string, y, x); + result = TPARM_2((NCURSES_CONST char *) string, y, x); returnPtr(result); } diff --git a/lib/libcurses/tinfo/lib_ti.c b/lib/libcurses/tinfo/lib_ti.c index 3c1595aef0c..9416c56cca9 100644 --- a/lib/libcurses/tinfo/lib_ti.c +++ b/lib/libcurses/tinfo/lib_ti.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_ti.c,v 1.6 2001/01/22 18:01:54 millert Exp $ */ +/* $OpenBSD: lib_ti.c,v 1.7 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2000,2003 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -38,12 +38,12 @@ #include <term_entry.h> #include <tic.h> -MODULE_ID("$From: lib_ti.c,v 1.22 2000/12/10 02:55:08 tom Exp $") +MODULE_ID("$Id: lib_ti.c,v 1.7 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(int) tigetflag(NCURSES_CONST char *str) { - int i; + unsigned i; T((T_CALLED("tigetflag(%s)"), str)); @@ -64,7 +64,7 @@ tigetflag(NCURSES_CONST char *str) NCURSES_EXPORT(int) tigetnum(NCURSES_CONST char *str) { - int i; + unsigned i; T((T_CALLED("tigetnum(%s)"), str)); @@ -86,7 +86,7 @@ tigetnum(NCURSES_CONST char *str) NCURSES_EXPORT(char *) tigetstr(NCURSES_CONST char *str) { - int i; + unsigned i; T((T_CALLED("tigetstr(%s)"), str)); diff --git a/lib/libcurses/tinfo/lib_tparm.c b/lib/libcurses/tinfo/lib_tparm.c index 3cdd7b915fc..45c07f01e06 100644 --- a/lib/libcurses/tinfo/lib_tparm.c +++ b/lib/libcurses/tinfo/lib_tparm.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_tparm.c,v 1.8 2003/03/17 19:16:59 millert Exp $ */ +/* $OpenBSD: lib_tparm.c,v 1.9 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey, 1996 on * ****************************************************************************/ /* @@ -44,7 +45,7 @@ #include <term.h> #include <tic.h> -MODULE_ID("$From: lib_tparm.c,v 1.51 2000/12/10 02:55:08 tom Exp $") +MODULE_ID("$Id: lib_tparm.c,v 1.9 2010/01/12 23:22:06 nicm Exp $") /* * char * @@ -106,57 +107,37 @@ MODULE_ID("$From: lib_tparm.c,v 1.51 2000/12/10 02:55:08 tom Exp $") * resulting in x mod y, not the reverse. */ -#define STACKSIZE 20 +NCURSES_EXPORT_VAR(int) _nc_tparm_err = 0; -typedef struct { - union { - unsigned int num; - char *str; - } data; - bool num_type; -} stack_frame; - -static stack_frame stack[STACKSIZE]; -static int stack_ptr; - -#ifdef TRACE -static const char *tname; -#endif /* TRACE */ - -static char *out_buff; -static size_t out_size; -static size_t out_used; +#define TPS(var) _nc_prescreen.tparm_state.var #if NO_LEAKS NCURSES_EXPORT(void) _nc_free_tparm(void) { - if (out_buff != 0) { - FreeAndNull(out_buff); - out_size = 0; - out_used = 0; + if (TPS(out_buff) != 0) { + FreeAndNull(TPS(out_buff)); + TPS(out_size) = 0; + TPS(out_used) = 0; + FreeAndNull(TPS(fmt_buff)); + TPS(fmt_size) = 0; } } #endif -static void -really_get_space(size_t need) -{ - out_size = need * 2; - out_buff = typeRealloc(char, out_size, out_buff); - if (out_buff == 0) - _nc_err_abort("Out of memory"); -} - -static inline void +static NCURSES_INLINE void get_space(size_t need) { - need += out_used; - if (need > out_size) - really_get_space(need); + need += TPS(out_used); + if (need > TPS(out_size)) { + TPS(out_size) = need * 2; + TPS(out_buff) = typeRealloc(char, TPS(out_size), TPS(out_buff)); + if (TPS(out_buff) == 0) + _nc_err_abort(MSG_NO_MEMORY); + } } -static inline void +static NCURSES_INLINE void save_text(const char *fmt, const char *s, int len) { size_t s_len = strlen(s); @@ -165,222 +146,223 @@ save_text(const char *fmt, const char *s, int len) get_space(s_len + 1); - (void) snprintf(out_buff + out_used, out_size - out_used, fmt, s); - out_used += strlen(out_buff + out_used); + (void) snprintf(TPS(out_buff) + TPS(out_used), TPS(out_size) - TPS(out_used), fmt, s); + TPS(out_used) += strlen(TPS(out_buff) + TPS(out_used)); } -static inline void +static NCURSES_INLINE void save_number(const char *fmt, int number, int len) { if (len < 30) len = 30; /* actually log10(MAX_INT)+1 */ - get_space(len + 1); + get_space((unsigned) len + 1); - (void) snprintf(out_buff + out_used, out_size - out_used, fmt, number); - out_used += strlen(out_buff + out_used); + (void) snprintf(TPS(out_buff) + TPS(out_used), TPS(out_size) - TPS(out_used), fmt, number); + TPS(out_used) += strlen(TPS(out_buff) + TPS(out_used)); } -static inline void +static NCURSES_INLINE void save_char(int c) { if (c == 0) c = 0200; get_space(1); - out_buff[out_used++] = c; + TPS(out_buff)[TPS(out_used)++] = (char) c; } -static inline void +static NCURSES_INLINE void npush(int x) { - if (stack_ptr < STACKSIZE) { - stack[stack_ptr].num_type = TRUE; - stack[stack_ptr].data.num = x; - stack_ptr++; + if (TPS(stack_ptr) < STACKSIZE) { + TPS(stack)[TPS(stack_ptr)].num_type = TRUE; + TPS(stack)[TPS(stack_ptr)].data.num = x; + TPS(stack_ptr)++; + } else { + DEBUG(2, ("npush: stack overflow: %s", _nc_visbuf(TPS(tparam_base)))); + _nc_tparm_err++; } } -static inline int +static NCURSES_INLINE int npop(void) { int result = 0; - if (stack_ptr > 0) { - stack_ptr--; - if (stack[stack_ptr].num_type) - result = stack[stack_ptr].data.num; + if (TPS(stack_ptr) > 0) { + TPS(stack_ptr)--; + if (TPS(stack)[TPS(stack_ptr)].num_type) + result = TPS(stack)[TPS(stack_ptr)].data.num; + } else { + DEBUG(2, ("npop: stack underflow: %s", _nc_visbuf(TPS(tparam_base)))); + _nc_tparm_err++; } return result; } -static inline void +static NCURSES_INLINE void spush(char *x) { - if (stack_ptr < STACKSIZE) { - stack[stack_ptr].num_type = FALSE; - stack[stack_ptr].data.str = x; - stack_ptr++; + if (TPS(stack_ptr) < STACKSIZE) { + TPS(stack)[TPS(stack_ptr)].num_type = FALSE; + TPS(stack)[TPS(stack_ptr)].data.str = x; + TPS(stack_ptr)++; + } else { + DEBUG(2, ("spush: stack overflow: %s", _nc_visbuf(TPS(tparam_base)))); + _nc_tparm_err++; } } -static inline char * +static NCURSES_INLINE char * spop(void) { static char dummy[] = ""; /* avoid const-cast */ char *result = dummy; - if (stack_ptr > 0) { - stack_ptr--; - if (!stack[stack_ptr].num_type && stack[stack_ptr].data.str != 0) - result = stack[stack_ptr].data.str; + if (TPS(stack_ptr) > 0) { + TPS(stack_ptr)--; + if (!TPS(stack)[TPS(stack_ptr)].num_type + && TPS(stack)[TPS(stack_ptr)].data.str != 0) + result = TPS(stack)[TPS(stack_ptr)].data.str; + } else { + DEBUG(2, ("spop: stack underflow: %s", _nc_visbuf(TPS(tparam_base)))); + _nc_tparm_err++; } return result; } -static inline const char * +static NCURSES_INLINE const char * parse_format(const char *s, char *format, int *len) { - bool done = FALSE; - bool allowminus = FALSE; - bool dot = FALSE; - bool err = FALSE; - char *fmt = format; - int prec = 0; - int width = 0; - int value = 0; - *len = 0; - *format++ = '%'; - while (*s != '\0' && !done) { - switch (*s) { - case 'c': /* FALLTHRU */ - case 'd': /* FALLTHRU */ - case 'o': /* FALLTHRU */ - case 'x': /* FALLTHRU */ - case 'X': /* FALLTHRU */ - case 's': - *format++ = *s; - done = TRUE; - break; - case '.': - *format++ = *s++; - if (dot) { - err = TRUE; - } else { - dot = TRUE; - prec = value; - } - value = 0; - break; - case '#': - *format++ = *s++; - break; - case ' ': - *format++ = *s++; - break; - case ':': - s++; - allowminus = TRUE; - break; - case '-': - if (allowminus) { - *format++ = *s++; - } else { + if (format != 0) { + bool done = FALSE; + bool allowminus = FALSE; + bool dot = FALSE; + bool err = FALSE; + char *fmt = format; + int my_width = 0; + int my_prec = 0; + int value = 0; + + *len = 0; + *format++ = '%'; + while (*s != '\0' && !done) { + switch (*s) { + case 'c': /* FALLTHRU */ + case 'd': /* FALLTHRU */ + case 'o': /* FALLTHRU */ + case 'x': /* FALLTHRU */ + case 'X': /* FALLTHRU */ + case 's': + *format++ = *s; done = TRUE; - } - break; - default: - if (isdigit(CharOf(*s))) { - value = (value * 10) + (*s - '0'); - if (value > 10000) + break; + case '.': + *format++ = *s++; + if (dot) { err = TRUE; + } else { /* value before '.' is the width */ + dot = TRUE; + my_width = value; + } + value = 0; + break; + case '#': *format++ = *s++; - } else { - done = TRUE; + break; + case ' ': + *format++ = *s++; + break; + case ':': + s++; + allowminus = TRUE; + break; + case '-': + if (allowminus) { + *format++ = *s++; + } else { + done = TRUE; + } + break; + default: + if (isdigit(UChar(*s))) { + value = (value * 10) + (*s - '0'); + if (value > 10000) + err = TRUE; + *format++ = *s++; + } else { + done = TRUE; + } } } - } - - /* - * If we found an error, ignore (and remove) the flags. - */ - if (err) { - prec = width = value = 0; - format = fmt; - *format++ = '%'; - *format++ = *s; - } - if (dot) - width = value; - else - prec = value; + /* + * If we found an error, ignore (and remove) the flags. + */ + if (err) { + my_width = my_prec = value = 0; + format = fmt; + *format++ = '%'; + *format++ = *s; + } - *format = '\0'; - /* return maximum string length in print */ - *len = (prec > width) ? prec : width; + /* + * Any value after '.' is the precision. If we did not see '.', then + * the value is the width. + */ + if (dot) + my_prec = value; + else + my_width = value; + + *format = '\0'; + /* return maximum string length in print */ + *len = (my_width > my_prec) ? my_width : my_prec; + } return s; } #define isUPPER(c) ((c) >= 'A' && (c) <= 'Z') #define isLOWER(c) ((c) >= 'a' && (c) <= 'z') -static inline char * -tparam_internal(const char *string, va_list ap) +/* + * Analyze the string to see how many parameters we need from the varargs list, + * and what their types are. We will only accept string parameters if they + * appear as a %l or %s format following an explicit parameter reference (e.g., + * %p2%s). All other parameters are numbers. + * + * 'number' counts coarsely the number of pop's we see in the string, and + * 'popcount' shows the highest parameter number in the string. We would like + * to simply use the latter count, but if we are reading termcap strings, there + * may be cases that we cannot see the explicit parameter numbers. + */ +NCURSES_EXPORT(int) +_nc_tparm_analyze(const char *string, char *p_is_s[NUM_PARM], int *popcount) { -#define NUM_VARS 26 - char *p_is_s[9]; - int param[9]; - int lastpop; - int popcount; - int number; - int len; - int level; - int x, y; - int i; size_t len2; - register const char *cp; - static size_t len_fmt; + int i; + int lastpop = -1; + int len; + int number = 0; + const char *cp = string; static char dummy[] = ""; - static char *format; - static int dynamic_var[NUM_VARS]; - static int static_vars[NUM_VARS]; - out_used = 0; - if (string == NULL) - return NULL; + if (cp == 0) + return 0; - if ((len2 = strlen(string)) > len_fmt) { - len_fmt = len2 + len_fmt + 2; - if ((format = typeRealloc(char, len_fmt, format)) == 0) - return 0; + if ((len2 = strlen(cp)) > TPS(fmt_size)) { + TPS(fmt_size) = len2 + TPS(fmt_size) + 2; + TPS(fmt_buff) = typeRealloc(char, TPS(fmt_size), TPS(fmt_buff)); + if (TPS(fmt_buff) == 0) + return 0; } - /* - * Find the highest parameter-number referred to in the format string. - * Use this value to limit the number of arguments copied from the - * variable-length argument list. - */ - - number = 0; - lastpop = -1; - popcount = 0; - memset(p_is_s, 0, sizeof(p_is_s)); + memset(p_is_s, 0, sizeof(p_is_s[0]) * NUM_PARM); + *popcount = 0; - /* - * Analyze the string to see how many parameters we need from the varargs - * list, and what their types are. We will only accept string parameters - * if they appear as a %l or %s format following an explicit parameter - * reference (e.g., %p2%s). All other parameters are numbers. - * - * 'number' counts coarsely the number of pop's we see in the string, and - * 'popcount' shows the highest parameter number in the string. We would - * like to simply use the latter count, but if we are reading termcap - * strings, there may be cases that we cannot see the explicit parameter - * numbers. - */ - for (cp = string; (cp - string) < (int) len2;) { + while ((cp - string) < (int) len2) { if (*cp == '%') { cp++; - cp = parse_format(cp, format, &len); + cp = parse_format(cp, TPS(fmt_buff), &len); switch (*cp) { default: break; @@ -390,7 +372,8 @@ tparam_internal(const char *string, va_list ap) case 'x': /* FALLTHRU */ case 'X': /* FALLTHRU */ case 'c': /* FALLTHRU */ - number++; + if (lastpop <= 0) + number++; lastpop = -1; break; @@ -403,15 +386,19 @@ tparam_internal(const char *string, va_list ap) case 'p': cp++; - i = (*cp - '0'); - if (i >= 0 && i <= 9) { + i = (UChar(*cp) - '0'); + if (i >= 0 && i <= NUM_PARM) { lastpop = i; - if (lastpop > popcount) - popcount = lastpop; + if (lastpop > *popcount) + *popcount = lastpop; } break; case 'P': + ++number; + ++cp; + break; + case 'g': cp++; break; @@ -423,7 +410,7 @@ tparam_internal(const char *string, va_list ap) case L_BRACE: cp++; - while (*cp >= '0' && *cp <= '9') { + while (isdigit(UChar(*cp))) { cp++; } break; @@ -441,16 +428,18 @@ tparam_internal(const char *string, va_list ap) case '=': case '<': case '>': + lastpop = -1; + number += 2; + break; + case '!': case '~': lastpop = -1; - number += 2; + ++number; break; case 'i': - lastpop = -1; - if (popcount < 2) - popcount = 2; + /* will add 1 to first (usually two) parameters */ break; } } @@ -458,18 +447,52 @@ tparam_internal(const char *string, va_list ap) cp++; } - if (number > 9) - number = 9; + if (number > NUM_PARM) + number = NUM_PARM; + return number; +} + +static NCURSES_INLINE char * +tparam_internal(const char *string, va_list ap) +{ + char *p_is_s[NUM_PARM]; + TPARM_ARG param[NUM_PARM]; + int popcount; + int number; + int len; + int level; + int x, y; + int i; + const char *cp = string; + size_t len2; + + if (cp == NULL) + return NULL; + + TPS(out_used) = 0; + len2 = strlen(cp); + + /* + * Find the highest parameter-number referred to in the format string. + * Use this value to limit the number of arguments copied from the + * variable-length argument list. + */ + number = _nc_tparm_analyze(cp, p_is_s, &popcount); + if (TPS(fmt_buff) == 0) + return NULL; + for (i = 0; i < max(popcount, number); i++) { /* * A few caps (such as plab_norm) have string-valued parms. * We'll have to assume that the caller knows the difference, since - * a char* and an int may not be the same size on the stack. + * a char* and an int may not be the same size on the stack. The + * normal prototype for this uses 9 long's, which is consistent with + * our va_arg() usage. */ if (p_is_s[i] != 0) { p_is_s[i] = va_arg(ap, char *); } else { - param[i] = va_arg(ap, int); + param[i] = va_arg(ap, TPARM_ARG); } } @@ -480,32 +503,37 @@ tparam_internal(const char *string, va_list ap) * the expansion of (for example) \E[%d;%dH work correctly in termcap * style, which means tparam() will expand termcap strings OK. */ - stack_ptr = 0; + TPS(stack_ptr) = 0; if (popcount == 0) { popcount = number; - for (i = number - 1; i >= 0; i--) - npush(param[i]); + for (i = number - 1; i >= 0; i--) { + if (p_is_s[i]) + spush(p_is_s[i]); + else + npush(param[i]); + } } #ifdef TRACE - if (_nc_tracing & TRACE_CALLS) { + if (USE_TRACEF(TRACE_CALLS)) { for (i = 0; i < popcount; i++) { if (p_is_s[i] != 0) save_text(", %s", _nc_visbuf(p_is_s[i]), 0); else save_number(", %d", param[i], 0); } - _tracef(T_CALLED("%s(%s%s)"), tname, _nc_visbuf(string), out_buff); - out_used = 0; + _tracef(T_CALLED("%s(%s%s)"), TPS(tname), _nc_visbuf(cp), TPS(out_buff)); + TPS(out_used) = 0; + _nc_unlock_global(tracef); } #endif /* TRACE */ - while (*string) { - if (*string != '%') { - save_char(*string); + while ((cp - string) < (int) len2) { + if (*cp != '%') { + save_char(UChar(*cp)); } else { - string++; - string = parse_format(string, format, &len); - switch (*string) { + TPS(tparam_base) = cp++; + cp = parse_format(cp, TPS(fmt_buff), &len); + switch (*cp) { default: break; case '%': @@ -516,22 +544,25 @@ tparam_internal(const char *string, va_list ap) case 'o': /* FALLTHRU */ case 'x': /* FALLTHRU */ case 'X': /* FALLTHRU */ + save_number(TPS(fmt_buff), npop(), len); + break; + case 'c': /* FALLTHRU */ - save_number(format, npop(), len); + save_char(npop()); break; case 'l': - save_number("%d", strlen(spop()), 0); + save_number("%d", (int) strlen(spop()), 0); break; case 's': - save_text(format, spop(), len); + save_text(TPS(fmt_buff), spop(), len); break; case 'p': - string++; - i = (*string - '1'); - if (i >= 0 && i < 9) { + cp++; + i = (UChar(*cp) - '1'); + if (i >= 0 && i < NUM_PARM) { if (p_is_s[i]) spush(p_is_s[i]); else @@ -540,39 +571,39 @@ tparam_internal(const char *string, va_list ap) break; case 'P': - string++; - if (isUPPER(*string)) { - i = (*string - 'A'); - static_vars[i] = npop(); - } else if (isLOWER(*string)) { - i = (*string - 'a'); - dynamic_var[i] = npop(); + cp++; + if (isUPPER(*cp)) { + i = (UChar(*cp) - 'A'); + TPS(static_vars)[i] = npop(); + } else if (isLOWER(*cp)) { + i = (UChar(*cp) - 'a'); + TPS(dynamic_var)[i] = npop(); } break; case 'g': - string++; - if (isUPPER(*string)) { - i = (*string - 'A'); - npush(static_vars[i]); - } else if (isLOWER(*string)) { - i = (*string - 'a'); - npush(dynamic_var[i]); + cp++; + if (isUPPER(*cp)) { + i = (UChar(*cp) - 'A'); + npush(TPS(static_vars)[i]); + } else if (isLOWER(*cp)) { + i = (UChar(*cp) - 'a'); + npush(TPS(dynamic_var)[i]); } break; case S_QUOTE: - string++; - npush(*string); - string++; + cp++; + npush(UChar(*cp)); + cp++; break; case L_BRACE: number = 0; - string++; - while (*string >= '0' && *string <= '9') { - number = number * 10 + *string - '0'; - string++; + cp++; + while (isdigit(UChar(*cp))) { + number = (number * 10) + (UChar(*cp) - '0'); + cp++; } npush(number); break; @@ -663,38 +694,38 @@ tparam_internal(const char *string, va_list ap) x = npop(); if (!x) { /* scan forward for %e or %; at level zero */ - string++; + cp++; level = 0; - while (*string) { - if (*string == '%') { - string++; - if (*string == '?') + while (*cp) { + if (*cp == '%') { + cp++; + if (*cp == '?') level++; - else if (*string == ';') { + else if (*cp == ';') { if (level > 0) level--; else break; - } else if (*string == 'e' && level == 0) + } else if (*cp == 'e' && level == 0) break; } - if (*string) - string++; + if (*cp) + cp++; } } break; case 'e': /* scan forward for a %; at level zero */ - string++; + cp++; level = 0; - while (*string) { - if (*string == '%') { - string++; - if (*string == '?') + while (*cp) { + if (*cp == '%') { + cp++; + if (*cp == '?') level++; - else if (*string == ';') { + else if (*cp == ';') { if (level > 0) level--; else @@ -702,42 +733,65 @@ tparam_internal(const char *string, va_list ap) } } - if (*string) - string++; + if (*cp) + cp++; } break; case ';': break; - } /* endswitch (*string) */ - } /* endelse (*string == '%') */ + } /* endswitch (*cp) */ + } /* endelse (*cp == '%') */ - if (*string == '\0') + if (*cp == '\0') break; - string++; - } /* endwhile (*string) */ + cp++; + } /* endwhile (*cp) */ get_space(1); - out_buff[out_used] = '\0'; + TPS(out_buff)[TPS(out_used)] = '\0'; - T((T_RETURN("%s"), _nc_visbuf(out_buff))); - return (out_buff); + T((T_RETURN("%s"), _nc_visbuf(TPS(out_buff)))); + return (TPS(out_buff)); } +#if NCURSES_TPARM_VARARGS +#define tparm_varargs tparm +#else +#define tparm_proto tparm +#endif + NCURSES_EXPORT(char *) -tparm -(NCURSES_CONST char *string,...) +tparm_varargs(NCURSES_CONST char *string,...) { va_list ap; char *result; + _nc_tparm_err = 0; va_start(ap, string); #ifdef TRACE - tname = "tparm"; + TPS(tname) = "tparm"; #endif /* TRACE */ result = tparam_internal(string, ap); va_end(ap); return result; } + +#if !NCURSES_TPARM_VARARGS +NCURSES_EXPORT(char *) +tparm_proto(NCURSES_CONST char *string, + TPARM_ARG a1, + TPARM_ARG a2, + TPARM_ARG a3, + TPARM_ARG a4, + TPARM_ARG a5, + TPARM_ARG a6, + TPARM_ARG a7, + TPARM_ARG a8, + TPARM_ARG a9) +{ + return tparm_varargs(string, a1, a2, a3, a4, a5, a6, a7, a8, a9); +} +#endif /* NCURSES_TPARM_VARARGS */ diff --git a/lib/libcurses/tinfo/lib_tputs.c b/lib/libcurses/tinfo/lib_tputs.c index 634d0317114..c085ecfb77f 100644 --- a/lib/libcurses/tinfo/lib_tputs.c +++ b/lib/libcurses/tinfo/lib_tputs.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_tputs.c,v 1.11 2003/03/18 16:55:54 millert Exp $ */ +/* $OpenBSD: lib_tputs.c,v 1.12 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -47,16 +48,30 @@ #include <termcap.h> /* ospeed */ #include <tic.h> -MODULE_ID("$From: lib_tputs.c,v 1.55 2000/12/10 02:55:08 tom Exp $"); +MODULE_ID("$Id: lib_tputs.c,v 1.12 2010/01/12 23:22:06 nicm Exp $") -NCURSES_EXPORT_VAR(char) -PC = 0; /* used by termcap library */ -NCURSES_EXPORT_VAR(NCURSES_OSPEED) ospeed = 0; /* used by termcap library */ +NCURSES_EXPORT_VAR(char) PC = 0; /* used by termcap library */ +NCURSES_EXPORT_VAR(NCURSES_OSPEED) ospeed = 0; /* used by termcap library */ -NCURSES_EXPORT_VAR(int) -_nc_nulls_sent = 0; /* used by 'tack' program */ +NCURSES_EXPORT_VAR(int) _nc_nulls_sent = 0; /* used by 'tack' program */ - static int (*my_outch) (int c) = _nc_outch; +#if NCURSES_NO_PADDING +NCURSES_EXPORT(void) +_nc_set_no_padding(SCREEN *sp) +{ + bool no_padding = (getenv("NCURSES_NO_PADDING") != 0); + + if (sp) + sp->_no_padding = no_padding; + else + _nc_prescreen._no_padding = no_padding; + + TR(TRACE_CHARPUT | TRACE_MOVE, ("padding will%s be used", + GetNoPadding(sp) ? " not" : "")); +} +#endif + +static int (*my_outch) (int c) = _nc_outch; NCURSES_EXPORT(int) delay_output(int ms) @@ -69,7 +84,7 @@ delay_output(int ms) } else { register int nullcount; - nullcount = (ms * _nc_baudrate(ospeed)) / 10000; + nullcount = (ms * _nc_baudrate(ospeed)) / (BAUDBYTE * 1000); for (_nc_nulls_sent += nullcount; nullcount > 0; nullcount--) my_outch(PC); if (my_outch == _nc_outch) @@ -88,9 +103,7 @@ _nc_flush(void) NCURSES_EXPORT(int) _nc_outch(int ch) { -#ifdef TRACE - _nc_outchars++; -#endif /* TRACE */ + COUNT_OUTCHARS(1); if (SP != 0 && SP->_cleanup) { @@ -106,72 +119,6 @@ _nc_outch(int ch) return OK; } -#if USE_WIDEC_SUPPORT -/* - * Reference: The Unicode Standard 2.0 - * - * No surrogates supported (we're storing only one 16-bit Unicode value per - * cell). - */ -NCURSES_EXPORT(int) -_nc_utf8_outch(int ch) -{ - static const unsigned byteMask = 0xBF; - static const unsigned otherMark = 0x80; - static const unsigned firstMark[] = - {0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC}; - - int result[7], *ptr; - int count = 0; - - if ((unsigned int) ch < 0x80) - count = 1; - else if ((unsigned int) ch < 0x800) - count = 2; - else if ((unsigned int) ch < 0x10000) - count = 3; - else if ((unsigned int) ch < 0x200000) - count = 4; - else if ((unsigned int) ch < 0x4000000) - count = 5; - else if ((unsigned int) ch <= 0x7FFFFFFF) - count = 6; - else { - count = 3; - ch = 0xFFFD; - } - ptr = result + count; - switch (count) { - case 6: - *--ptr = (ch | otherMark) & byteMask; - ch >>= 6; - /* FALLTHRU */ - case 5: - *--ptr = (ch | otherMark) & byteMask; - ch >>= 6; - /* FALLTHRU */ - case 4: - *--ptr = (ch | otherMark) & byteMask; - ch >>= 6; - /* FALLTHRU */ - case 3: - *--ptr = (ch | otherMark) & byteMask; - ch >>= 6; - /* FALLTHRU */ - case 2: - *--ptr = (ch | otherMark) & byteMask; - ch >>= 6; - /* FALLTHRU */ - case 1: - *--ptr = (ch | firstMark[count]); - break; - } - while (count--) - _nc_outch(*ptr++); - return OK; -} -#endif - NCURSES_EXPORT(int) putp(const char *string) { @@ -179,8 +126,7 @@ putp(const char *string) } NCURSES_EXPORT(int) -tputs -(const char *string, int affcnt, int (*outc) (int)) +tputs(const char *string, int affcnt, int (*outc) (int)) { bool always_delay; bool normal_delay; @@ -192,7 +138,7 @@ tputs #ifdef TRACE char addrbuf[32]; - if (_nc_tracing & TRACE_TPUTS) { + if (USE_TRACEF(TRACE_TPUTS)) { if (outc == _nc_outch) (void) strlcpy(addrbuf, "_nc_outch", sizeof(addrbuf)); else @@ -203,7 +149,8 @@ tputs } else { _tracef("tputs(%s, %d, %s) called", _nc_visbuf(string), affcnt, addrbuf); } - _nc_tputs_trace = (char *) NULL; + TPUTS_TRACE(NULL); + _nc_unlock_global(tracef); } #endif /* TRACE */ @@ -219,7 +166,7 @@ tputs !xon_xoff && padding_baud_rate #if NCURSES_NO_PADDING - && (SP == 0 || !(SP->_no_padding)) + && !GetNoPadding(SP) #endif && (_nc_baudrate(ospeed) >= padding_baud_rate); } @@ -230,19 +177,19 @@ tputs * (like nethack) actually do the likes of tputs("50") to get delays. */ trailpad = 0; - if (isdigit(*string)) { - while (isdigit(*string)) { + if (isdigit(UChar(*string))) { + while (isdigit(UChar(*string))) { trailpad = trailpad * 10 + (*string - '0'); string++; } trailpad *= 10; if (*string == '.') { string++; - if (isdigit(*string)) { + if (isdigit(UChar(*string))) { trailpad += (*string - '0'); string++; } - while (isdigit(*string)) + while (isdigit(UChar(*string))) string++; } @@ -267,7 +214,7 @@ tputs bool mandatory; string++; - if ((!isdigit(CharOf(*string)) && *string != '.') + if ((!isdigit(UChar(*string)) && *string != '.') || !strchr(string, '>')) { (*outc) ('$'); (*outc) ('<'); @@ -275,18 +222,18 @@ tputs } number = 0; - while (isdigit(CharOf(*string))) { + while (isdigit(UChar(*string))) { number = number * 10 + (*string - '0'); string++; } number *= 10; if (*string == '.') { string++; - if (isdigit(CharOf(*string))) { + if (isdigit(UChar(*string))) { number += (*string - '0'); string++; } - while (isdigit(CharOf(*string))) + while (isdigit(UChar(*string))) string++; } diff --git a/lib/libcurses/tinfo/lib_ttyflags.c b/lib/libcurses/tinfo/lib_ttyflags.c index 615e0092564..ec604dcaa53 100644 --- a/lib/libcurses/tinfo/lib_ttyflags.c +++ b/lib/libcurses/tinfo/lib_ttyflags.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_ttyflags.c,v 1.4 2001/01/22 18:01:54 millert Exp $ */ +/* $OpenBSD: lib_ttyflags.c,v 1.5 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -40,79 +40,114 @@ #include <curses.priv.h> #include <term.h> /* cur_term */ -MODULE_ID("$From: lib_ttyflags.c,v 1.5 2000/12/10 02:55:08 tom Exp $") - -#undef tabs - -#ifdef TAB3 -# define tabs TAB3 -#else -# ifdef XTABS -# define tabs XTABS -# else -# ifdef OXTABS -# define tabs OXTABS -# else -# define tabs 0 -# endif -# endif -#endif +MODULE_ID("$Id: lib_ttyflags.c,v 1.5 2010/01/12 23:22:06 nicm Exp $") NCURSES_EXPORT(int) _nc_get_tty_mode(TTY * buf) { - if (cur_term == 0 - || GET_TTY(cur_term->Filedes, buf) != 0) - return (ERR); - TR(TRACE_BITS, ("_nc_get_tty_mode: %s", _nc_tracebits())); - return (OK); + int result = OK; + + if (buf == 0) { + result = ERR; + } else { + if (cur_term == 0) { + result = ERR; + } else { + for (;;) { + if (GET_TTY(cur_term->Filedes, buf) != 0) { + if (errno == EINTR) + continue; + result = ERR; + } + break; + } + } + + if (result == ERR) + memset(buf, 0, sizeof(*buf)); + + TR(TRACE_BITS, ("_nc_get_tty_mode(%d): %s", + cur_term ? cur_term->Filedes : -1, + _nc_trace_ttymode(buf))); + } + return (result); } NCURSES_EXPORT(int) _nc_set_tty_mode(TTY * buf) { - if (cur_term == 0 - || SET_TTY(cur_term->Filedes, buf) != 0) - return (ERR); - TR(TRACE_BITS, ("_nc_set_tty_mode: %s", _nc_tracebits())); - return (OK); + int result = OK; + + if (buf == 0) { + result = ERR; + } else { + if (cur_term == 0) { + result = ERR; + } else { + for (;;) { + if (SET_TTY(cur_term->Filedes, buf) != 0) { + if (errno == EINTR) + continue; + if ((errno == ENOTTY) && (SP != 0)) + SP->_notty = TRUE; + result = ERR; + } + break; + } + } + TR(TRACE_BITS, ("_nc_set_tty_mode(%d): %s", + cur_term ? cur_term->Filedes : -1, + _nc_trace_ttymode(buf))); + } + return (result); } NCURSES_EXPORT(int) def_shell_mode(void) { - T((T_CALLED("def_shell_mode()"))); + int rc = ERR; - /* - * Turn off the XTABS bit in the tty structure if it was on. If XTABS - * was on, remove the tab and backtab capabilities. - */ + T((T_CALLED("def_shell_mode()"))); - if (_nc_get_tty_mode(&cur_term->Ottyb) != OK) - returnCode(ERR); + if (cur_term != 0) { + /* + * If XTABS was on, remove the tab and backtab capabilities. + */ + if (_nc_get_tty_mode(&cur_term->Ottyb) == OK) { #ifdef TERMIOS - if (cur_term->Ottyb.c_oflag & tabs) - tab = back_tab = NULL; + if (cur_term->Ottyb.c_oflag & OFLAGS_TABS) + tab = back_tab = NULL; #else - if (cur_term->Ottyb.sg_flags & XTABS) - tab = back_tab = NULL; + if (cur_term->Ottyb.sg_flags & XTABS) + tab = back_tab = NULL; #endif - returnCode(OK); + rc = OK; + } + } + returnCode(rc); } NCURSES_EXPORT(int) def_prog_mode(void) { + int rc = ERR; + T((T_CALLED("def_prog_mode()"))); - if (_nc_get_tty_mode(&cur_term->Nttyb) != OK) - returnCode(ERR); + if (cur_term != 0) { + /* + * Turn off the XTABS bit in the tty structure if it was on. + */ + if (_nc_get_tty_mode(&cur_term->Nttyb) == OK) { #ifdef TERMIOS - cur_term->Nttyb.c_oflag &= ~tabs; + cur_term->Nttyb.c_oflag &= ~OFLAGS_TABS; #else - cur_term->Nttyb.sg_flags &= ~XTABS; + cur_term->Nttyb.sg_flags &= ~XTABS; #endif - returnCode(OK); + rc = OK; + } + } + returnCode(rc); } NCURSES_EXPORT(int) @@ -121,13 +156,14 @@ reset_prog_mode(void) T((T_CALLED("reset_prog_mode()"))); if (cur_term != 0) { - _nc_set_tty_mode(&cur_term->Nttyb); - if (SP) { - if (stdscr && stdscr->_use_keypad) - _nc_keypad(TRUE); - NC_BUFFERED(TRUE); + if (_nc_set_tty_mode(&cur_term->Nttyb) == OK) { + if (SP) { + if (SP->_keypad_on) + _nc_keypad(SP, TRUE); + NC_BUFFERED(TRUE); + } + returnCode(OK); } - returnCode(OK); } returnCode(ERR); } @@ -139,7 +175,7 @@ reset_shell_mode(void) if (cur_term != 0) { if (SP) { - _nc_keypad(FALSE); + _nc_keypad(SP, FALSE); _nc_flush(); NC_BUFFERED(FALSE); } @@ -148,19 +184,33 @@ reset_shell_mode(void) returnCode(ERR); } +static TTY * +saved_tty(void) +{ + TTY *result = 0; + + if (SP != 0) { + result = &(SP->_saved_tty); + } else { + if (_nc_prescreen.saved_tty == 0) { + _nc_prescreen.saved_tty = typeCalloc(TTY, 1); + } + result = _nc_prescreen.saved_tty; + } + return result; +} + /* ** savetty() and resetty() ** */ -static TTY buf; - NCURSES_EXPORT(int) savetty(void) { T((T_CALLED("savetty()"))); - returnCode(_nc_get_tty_mode(&buf)); + returnCode(_nc_get_tty_mode(saved_tty())); } NCURSES_EXPORT(int) @@ -168,5 +218,5 @@ resetty(void) { T((T_CALLED("resetty()"))); - returnCode(_nc_set_tty_mode(&buf)); + returnCode(_nc_set_tty_mode(saved_tty())); } diff --git a/lib/libcurses/tinfo/make_keys.c b/lib/libcurses/tinfo/make_keys.c index 0b6697d0319..caec31c9ffc 100644 --- a/lib/libcurses/tinfo/make_keys.c +++ b/lib/libcurses/tinfo/make_keys.c @@ -1,7 +1,7 @@ -/* $OpenBSD: make_keys.c,v 1.8 2006/10/10 21:38:16 cloder Exp $ */ +/* $OpenBSD: make_keys.c,v 1.9 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,7 +29,7 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey <dickey@clark.net> 1997 * + * Author: Thomas E. Dickey 1997-on * ****************************************************************************/ /* @@ -37,9 +37,11 @@ * making the output show the indices into the TERMTYPE Strings array. Doing * it that way lets us cut down on the size of the init_keytry() function. */ + +#define USE_TERMLIB 1 #include <curses.priv.h> -MODULE_ID("$From: make_keys.c,v 1.10 2000/12/10 02:55:08 tom Exp $") +MODULE_ID("$Id: make_keys.c,v 1.9 2010/01/12 23:22:06 nicm Exp $") #include <names.c> @@ -68,17 +70,23 @@ lookup(const char *name) } static void -make_keys(FILE * ifp, FILE * ofp) +make_keys(FILE *ifp, FILE *ofp) { char buffer[BUFSIZ]; - char from[BUFSIZ]; - char to[BUFSIZ]; + char from[256]; + char to[256]; int maxlen = 16; + int scanned; while (fgets(buffer, sizeof(buffer), ifp) != NULL) { if (*buffer == '#') continue; - if (sscanf(buffer, "%s %s", to, from) == 2) { + + to[sizeof(to) - 1] = '\0'; + from[sizeof(from) - 1] = '\0'; + + scanned = sscanf(buffer, "%255s %255s", to, from); + if (scanned == 2) { int code = lookup(from); if (code == UNKNOWN) continue; @@ -94,7 +102,7 @@ make_keys(FILE * ifp, FILE * ofp) } static void -write_list(FILE * ofp, const char **list) +write_list(FILE *ofp, const char **list) { while (*list != 0) fprintf(ofp, "%s\n", *list++); @@ -113,7 +121,7 @@ main(int argc, char *argv[]) "#if BROKEN_LINKER", "static", "#endif", - "struct tinfo_fkeys _nc_tinfo_fkeys[] = {", + "const struct tinfo_fkeys _nc_tinfo_fkeys[] = {", 0 }; static const char *suffix[] = diff --git a/lib/libcurses/tinfo/name_match.c b/lib/libcurses/tinfo/name_match.c index 6db7ac7057f..1162430ee2f 100644 --- a/lib/libcurses/tinfo/name_match.c +++ b/lib/libcurses/tinfo/name_match.c @@ -1,7 +1,7 @@ -/* $OpenBSD: name_match.c,v 1.3 2001/01/22 18:01:55 millert Exp $ */ +/* $OpenBSD: name_match.c,v 1.4 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1999-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,35 +29,48 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey <dickey@clark.net> 1999 * + * Author: Thomas E. Dickey 1999-on * ****************************************************************************/ #include <curses.priv.h> #include <term.h> #include <tic.h> -MODULE_ID("$From: name_match.c,v 1.10 2000/12/10 02:55:08 tom Exp $") +MODULE_ID("$Id: name_match.c,v 1.4 2010/01/12 23:22:06 nicm Exp $") /* * _nc_first_name(char *names) * * Extract the primary name from a compiled entry. */ +#define FirstName _nc_globals.first_name NCURSES_EXPORT(char *) _nc_first_name(const char *const sp) /* get the first name from the given name list */ { - static char buf[MAX_NAME_SIZE + 1]; - register unsigned n; + unsigned n; - for (n = 0; n < sizeof(buf) - 1; n++) { - if ((buf[n] = sp[n]) == '\0' - || (buf[n] == '|')) - break; +#if NO_LEAKS + if (sp == 0) { + if (FirstName != 0) + FreeAndNull(FirstName); + } else +#endif + { + if (FirstName == 0) + FirstName = typeMalloc(char, MAX_NAME_SIZE + 1); + + if (FirstName != 0) { + for (n = 0; n < MAX_NAME_SIZE; n++) { + if ((FirstName[n] = sp[n]) == '\0' + || (FirstName[n] == '|')) + break; + } + FirstName[n] = '\0'; + } } - buf[n] = '\0'; - return (buf); + return (FirstName); } /* @@ -67,8 +80,7 @@ _nc_first_name(const char *const sp) */ NCURSES_EXPORT(int) -_nc_name_match -(const char *const namelst, const char *const name, const char *const delim) +_nc_name_match(const char *const namelst, const char *const name, const char *const delim) { const char *s, *d, *t; int code, found; diff --git a/lib/libcurses/tinfo/parse_entry.c b/lib/libcurses/tinfo/parse_entry.c index 4a42654d670..2270ad90c07 100644 --- a/lib/libcurses/tinfo/parse_entry.c +++ b/lib/libcurses/tinfo/parse_entry.c @@ -1,7 +1,7 @@ -/* $OpenBSD: parse_entry.c,v 1.12 2003/03/17 19:16:59 millert Exp $ */ +/* $OpenBSD: parse_entry.c,v 1.13 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -42,14 +43,14 @@ * from the input stream. */ +#define __INTERNAL_CAPS_VISIBLE #include <curses.priv.h> #include <ctype.h> #include <tic.h> -#define __INTERNAL_CAPS_VISIBLE #include <term_entry.h> -MODULE_ID("$From: parse_entry.c,v 1.52 2001/01/13 22:44:29 tom Exp $") +MODULE_ID("$Id: parse_entry.c,v 1.13 2010/01/12 23:22:06 nicm Exp $") #ifdef LINT static short const parametrized[] = @@ -143,7 +144,7 @@ _nc_extend_names(ENTRY * entryp, char *name, int token_type) case BOOLEAN: tp->ext_Booleans += 1; tp->num_Booleans += 1; - tp->Booleans = typeRealloc(char, tp->num_Booleans, tp->Booleans); + tp->Booleans = typeRealloc(NCURSES_SBOOL, tp->num_Booleans, tp->Booleans); for (last = tp->num_Booleans - 1; last > tindex; last--) tp->Booleans[last] = tp->Booleans[last - 1]; break; @@ -197,13 +198,17 @@ _nc_extend_names(ENTRY * entryp, char *name, int token_type) * push back token */ +#define BAD_TC_USAGE if (!bad_tc_usage) \ + { bad_tc_usage = TRUE; \ + _nc_warning("Legacy termcap allows only a trailing tc= clause"); } + NCURSES_EXPORT(int) -_nc_parse_entry -(struct entry *entryp, int literal, bool silent) +_nc_parse_entry(struct entry *entryp, int literal, bool silent) { int token_type; struct name_table_entry const *entry_ptr; char *ptr, *base; + bool bad_tc_usage = FALSE; token_type = _nc_get_token(silent); @@ -219,15 +224,32 @@ _nc_parse_entry entryp->startline = _nc_start_line; DEBUG(2, ("Comment range is %ld to %ld", entryp->cstart, entryp->cend)); - /* junk the 2-character termcap name, if present */ + /* + * Strip off the 2-character termcap name, if present. Originally termcap + * used that as an indexing aid. We can retain 2-character terminfo names, + * but note that they would be lost if we translate to/from termcap. This + * feature is supposedly obsolete since "newer" BSD implementations do not + * use it; however our reference for this feature is SunOS 4.x, which + * implemented it. Note that the resulting terminal type was never the + * 2-character name, but was instead the first alias after that. + */ ptr = _nc_curr_token.tk_name; - if (ptr[2] == '|') { - ptr = _nc_curr_token.tk_name + 3; - _nc_curr_token.tk_name[2] = '\0'; + if (_nc_syntax == SYN_TERMCAP +#if NCURSES_XNAMES + && !_nc_user_definable +#endif + ) { + if (ptr[2] == '|') { + ptr += 3; + _nc_curr_token.tk_name[2] = '\0'; + } } entryp->tterm.str_table = entryp->tterm.term_names = _nc_save_str(ptr); + if (entryp->tterm.str_table == 0) + return (ERR); + DEBUG(1, ("Starting '%s'", ptr)); /* @@ -245,7 +267,7 @@ _nc_parse_entry (base == entryp->tterm.term_names) ? "primary name" : "alias", - ptr - base, base); + (int) (ptr - base), base); } } @@ -254,15 +276,19 @@ _nc_parse_entry for (token_type = _nc_get_token(silent); token_type != EOF && token_type != NAMES; token_type = _nc_get_token(silent)) { - if (strcmp(_nc_curr_token.tk_name, "use") == 0 - || strcmp(_nc_curr_token.tk_name, "tc") == 0) { + bool is_use = (strcmp(_nc_curr_token.tk_name, "use") == 0); + bool is_tc = !is_use && (strcmp(_nc_curr_token.tk_name, "tc") == 0); + if (is_use || is_tc) { entryp->uses[entryp->nuses].name = _nc_save_str(_nc_curr_token.tk_valstring); entryp->uses[entryp->nuses].line = _nc_curr_line; entryp->nuses++; + if (entryp->nuses > 1 && is_tc) { + BAD_TC_USAGE + } } else { /* normal token lookup */ entry_ptr = _nc_find_entry(_nc_curr_token.tk_name, - _nc_syntax ? _nc_cap_hash_table : _nc_info_hash_table); + _nc_get_hash_table(_nc_syntax)); /* * Our kluge to handle aliasing. The reason it's done @@ -276,7 +302,10 @@ _nc_parse_entry const struct alias *ap; if (_nc_syntax == SYN_TERMCAP) { - for (ap = _nc_capalias_table; ap->from; ap++) + if (entryp->nuses != 0) { + BAD_TC_USAGE + } + for (ap = _nc_get_alias_table(TRUE); ap->from; ap++) if (strcmp(ap->from, _nc_curr_token.tk_name) == 0) { if (ap->to == (char *) 0) { _nc_warning("%s (%s termcap extension) ignored", @@ -284,14 +313,15 @@ _nc_parse_entry goto nexttok; } - entry_ptr = _nc_find_entry(ap->to, _nc_cap_hash_table); + entry_ptr = _nc_find_entry(ap->to, + _nc_get_hash_table(TRUE)); if (entry_ptr && !silent) _nc_warning("%s (%s termcap extension) aliased to %s", ap->from, ap->source, ap->to); break; } } else { /* if (_nc_syntax == SYN_TERMINFO) */ - for (ap = _nc_infoalias_table; ap->from; ap++) + for (ap = _nc_get_alias_table(FALSE); ap->from; ap++) if (strcmp(ap->from, _nc_curr_token.tk_name) == 0) { if (ap->to == (char *) 0) { _nc_warning("%s (%s terminfo extension) ignored", @@ -299,7 +329,8 @@ _nc_parse_entry goto nexttok; } - entry_ptr = _nc_find_entry(ap->to, _nc_info_hash_table); + entry_ptr = _nc_find_entry(ap->to, + _nc_get_hash_table(FALSE)); if (entry_ptr && !silent) _nc_warning("%s (%s terminfo extension) aliased to %s", ap->from, ap->source, ap->to); @@ -346,23 +377,28 @@ _nc_parse_entry * type, this will do the job. */ - /* tell max_attributes from arrow_key_map */ - if (token_type == NUMBER && !strcmp("ma", _nc_curr_token.tk_name)) + if (token_type == NUMBER + && !strcmp("ma", _nc_curr_token.tk_name)) { + /* tell max_attributes from arrow_key_map */ entry_ptr = _nc_find_type_entry("ma", NUMBER, _nc_get_table(_nc_syntax != 0)); + assert(entry_ptr != 0); - /* map terminfo's string MT to MT */ - else if (token_type == STRING && !strcmp("MT", _nc_curr_token.tk_name)) + } else if (token_type == STRING + && !strcmp("MT", _nc_curr_token.tk_name)) { + /* map terminfo's string MT to MT */ entry_ptr = _nc_find_type_entry("MT", STRING, _nc_get_table(_nc_syntax != 0)); + assert(entry_ptr != 0); - /* treat strings without following "=" as empty strings */ - else if (token_type == BOOLEAN && entry_ptr->nte_type == STRING) + } else if (token_type == BOOLEAN + && entry_ptr->nte_type == STRING) { + /* treat strings without following "=" as empty strings */ token_type = STRING; - /* we couldn't recover; skip this token */ - else { + } else { + /* we couldn't recover; skip this token */ if (!silent) { const char *type_name; switch (entry_ptr->nte_type) { @@ -425,7 +461,7 @@ _nc_parse_entry default: if (!silent) _nc_warning("unknown token type"); - _nc_panic_mode((_nc_syntax == SYN_TERMCAP) ? ':' : ','); + _nc_panic_mode((char) ((_nc_syntax == SYN_TERMCAP) ? ':' : ',')); continue; } } /* end else cur_token.name != "use" */ @@ -445,7 +481,7 @@ _nc_parse_entry if (!literal) { if (_nc_syntax == SYN_TERMCAP) { bool has_base_entry = FALSE; - int i; + unsigned i; /* * Don't insert defaults if this is a `+' entry meant only @@ -484,7 +520,7 @@ _nc_capcmp(const char *s, const char *t) for (;;) { if (s[0] == '$' && s[1] == '<') { for (s += 2;; s++) - if (!(isdigit(CharOf(*s)) + if (!(isdigit(UChar(*s)) || *s == '.' || *s == '*' || *s == '/' @@ -494,7 +530,7 @@ _nc_capcmp(const char *s, const char *t) if (t[0] == '$' && t[1] == '<') { for (t += 2;; t++) - if (!(isdigit(CharOf(*t)) + if (!(isdigit(UChar(*t)) || *t == '.' || *t == '*' || *t == '/' @@ -520,8 +556,8 @@ append_acs0(string_desc * dst, int code, int src) { if (src != 0) { char temp[3]; - temp[0] = code; - temp[1] = src; + temp[0] = (char) code; + temp[1] = (char) src; temp[2] = 0; _nc_safe_strcat(dst, temp); } @@ -596,7 +632,7 @@ static const char C_HT[] = "\t"; #define CUR tp-> static void -postprocess_termcap(TERMTYPE * tp, bool has_base) +postprocess_termcap(TERMTYPE *tp, bool has_base) { char buf[MAX_LINE * 2 + 2]; string_desc result; @@ -619,7 +655,7 @@ postprocess_termcap(TERMTYPE * tp, bool has_base) if (WANTED(carriage_return)) { if (carriage_return_delay > 0) { - snprintf(buf, sizeof(buf), "%s$<%d>", C_CR, carriage_return_delay); + snprintf(buf, sizeof(buf), "%s$<%d>", C_CR, carriage_return_delay); carriage_return = _nc_save_str(buf); } else carriage_return = _nc_save_str(C_CR); @@ -756,11 +792,12 @@ postprocess_termcap(TERMTYPE * tp, bool has_base) base = cp + 1) { size_t len = cp - base; - for (ap = ko_xlate; ap->from; ap++) + for (ap = ko_xlate; ap->from; ap++) { if (len == strlen(ap->from) && strncmp(ap->from, base, len) == 0) break; - if (!ap->to) { + } + if (!(ap->from && ap->to)) { _nc_warning("unknown capability `%.*s' in ko string", (int) len, base); continue; @@ -769,8 +806,8 @@ postprocess_termcap(TERMTYPE * tp, bool has_base) /* now we know we found a match in ko_table, so... */ - from_ptr = _nc_find_entry(ap->from, _nc_cap_hash_table); - to_ptr = _nc_find_entry(ap->to, _nc_info_hash_table); + from_ptr = _nc_find_entry(ap->from, _nc_get_hash_table(TRUE)); + to_ptr = _nc_find_entry(ap->to, _nc_get_hash_table(FALSE)); if (!from_ptr || !to_ptr) /* should never happen! */ _nc_err_abort("ko translation table is invalid, I give up"); @@ -871,13 +908,12 @@ postprocess_termcap(TERMTYPE * tp, bool has_base) } else if (acs_chars == 0 && enter_alt_charset_mode != 0 && exit_alt_charset_mode != 0) { - acs_chars = - _nc_save_str("``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~"); + acs_chars = _nc_save_str(VT_ACSC); } } static void -postprocess_terminfo(TERMTYPE * tp) +postprocess_terminfo(TERMTYPE *tp) { /* * TERMINFO-TO-TERMINFO MAPPINGS FOR SOURCE TRANSLATION diff --git a/lib/libcurses/tinfo/read_bsd_terminfo.c b/lib/libcurses/tinfo/read_bsd_terminfo.c index dae8298ec69..9c34da830f1 100644 --- a/lib/libcurses/tinfo/read_bsd_terminfo.c +++ b/lib/libcurses/tinfo/read_bsd_terminfo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: read_bsd_terminfo.c,v 1.17 2009/10/28 23:22:45 schwarze Exp $ */ +/* $OpenBSD: read_bsd_terminfo.c,v 1.18 2010/01/12 23:22:06 nicm Exp $ */ /* * Copyright (c) 1998, 1999, 2000 Todd C. Miller <Todd.Miller@courtesan.com> @@ -245,13 +245,10 @@ _nc_lookup_bsd_terminfo_entry(tn, filename, tp) goto done; } - /* - * Save term entry and prevent _nc_free_entries() from freeing - * up the string table (since we use it in tp). - */ - *tp = _nc_head->tterm; - _nc_head->tterm.str_table = NULL; - _nc_free_entries(_nc_head); + /* Save term entry and free from _nc_head list. */ + *tp = _nc_head->tterm; + _nc_free_entry(_nc_head, tp); + _nc_head = _nc_tail = NULL; } done: diff --git a/lib/libcurses/tinfo/read_entry.c b/lib/libcurses/tinfo/read_entry.c index 7bbf35a3a3a..f1b3179705d 100644 --- a/lib/libcurses/tinfo/read_entry.c +++ b/lib/libcurses/tinfo/read_entry.c @@ -1,7 +1,7 @@ -/* $OpenBSD: read_entry.c,v 1.15 2008/01/29 13:02:31 krw Exp $ */ +/* $OpenBSD: read_entry.c,v 1.16 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,77 +31,24 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* * read_entry.c -- Routine for reading in a compiled terminfo file - * */ #include <curses.priv.h> +#include <hashed_db.h> #include <tic.h> #include <term_entry.h> -MODULE_ID("$From: read_entry.c,v 1.72 2000/12/10 02:55:08 tom Exp $") - -#if !HAVE_TELL -#define tell(fd) 0 /* lseek() is POSIX, but not tell() - odd... */ -#endif - -/* - * int - * _nc_read_file_entry(filename, ptr) - * - * Read the compiled terminfo entry in the given file into the - * structure pointed to by ptr, allocating space for the string - * table. - */ - -#undef BYTE -#define BYTE(p,n) (unsigned char)((p)[n]) +MODULE_ID("$Id: read_entry.c,v 1.16 2010/01/12 23:22:06 nicm Exp $") -#define IS_NEG1(p) ((BYTE(p,0) == 0377) && (BYTE(p,1) == 0377)) -#define IS_NEG2(p) ((BYTE(p,0) == 0376) && (BYTE(p,1) == 0377)) -#define LOW_MSB(p) (BYTE(p,0) + 256*BYTE(p,1)) - -static bool have_tic_directory = FALSE; -static bool keep_tic_directory = FALSE; - -/* - * Record the "official" location of the terminfo directory, according to - * the place where we're writing to, or the normal default, if not. - */ -NCURSES_EXPORT(const char *) -_nc_tic_dir(const char *path) -{ - static const char *result = TERMINFO; - - if (!keep_tic_directory) { - if (path != 0) { - result = path; - have_tic_directory = TRUE; - } else if (!have_tic_directory && use_terminfo_vars()) { - char *envp; - if ((envp = getenv("TERMINFO")) != 0) - return _nc_tic_dir(envp); - } - } - return result; -} - -/* - * Special fix to prevent the terminfo directory from being moved after tic - * has chdir'd to it. If we let it be changed, then if $TERMINFO has a - * relative path, we'll lose track of the actual directory. - */ -NCURSES_EXPORT(void) -_nc_keep_tic_dir(const char *path) -{ - _nc_tic_dir(path); - keep_tic_directory = TRUE; -} +#define TYPE_CALLOC(type,elts) typeCalloc(type, (unsigned)(elts)) +#if USE_DATABASE static void convert_shorts(char *buf, short *Numbers, int count) { @@ -128,7 +75,7 @@ convert_strings(char *buf, char **Strings, int count, int size, char *table) Strings[i] = ABSENT_STRING; } else if (IS_NEG2(buf + 2 * i)) { Strings[i] = CANCELLED_STRING; - } else if (LOW_MSB(buf + 2 * i) > size) { + } else if ((int) LOW_MSB(buf + 2 * i) > size) { Strings[i] = ABSENT_STRING; } else { Strings[i] = (LOW_MSB(buf + 2 * i) + table); @@ -147,31 +94,51 @@ convert_strings(char *buf, char **Strings, int count, int size, char *table) } } -#define read_shorts(fd, buf, count) (read(fd, buf, (count)*2) == (count)*2) +static int +fake_read(char *src, int *offset, int limit, char *dst, unsigned want) +{ + int have = (limit - *offset); + + if (have > 0) { + if ((int) want > have) + want = have; + memcpy(dst, src + *offset, want); + *offset += want; + } else { + want = 0; + } + return (int) want; +} + +#define Read(buf, count) fake_read(buffer, &offset, limit, buf, count) + +#define read_shorts(buf, count) \ + (Read(buf, (unsigned) (count)*2) == (int) (count)*2) #define even_boundary(value) \ - if ((value) % 2 != 0) read(fd, buf, 1) + if ((value) % 2 != 0) Read(buf, 1) -static int -read_termtype(int fd, TERMTYPE * ptr) +NCURSES_EXPORT(int) +_nc_read_termtype(TERMTYPE *ptr, char *buffer, int limit) /* return 1 if read, 0 if not found or garbled */ { + int offset = 0; int name_size, bool_count, num_count, str_count, str_size; int i; - size_t bsize; - char buf[MAX_ENTRY_SIZE]; + char buf[MAX_ENTRY_SIZE + 1]; + char *string_table; + unsigned want, have; - TR(TRACE_DATABASE, ("READ termtype header @%d", tell(fd))); + TR(TRACE_DATABASE, ("READ termtype header @%d", offset)); memset(ptr, 0, sizeof(*ptr)); /* grab the header */ - if (!read_shorts(fd, buf, 6) - || LOW_MSB(buf) != MAGIC) { - return (0); + if (!read_shorts(buf, 6) + || !IS_TIC_MAGIC(buf)) { + return (TGETENT_NO); } - _nc_free_termtype(ptr); name_size = LOW_MSB(buf + 2); bool_count = LOW_MSB(buf + 4); num_count = LOW_MSB(buf + 6); @@ -187,35 +154,41 @@ read_termtype(int fd, TERMTYPE * ptr) || num_count < 0 || str_count < 0 || str_size < 0) { - return (0); + return (TGETENT_NO); } + want = str_size + name_size + 1; if (str_size) { /* try to allocate space for the string table */ if (str_count * 2 >= (int) sizeof(buf) - || (ptr->str_table = typeMalloc(char, (unsigned) str_size)) == 0) { - return (0); + || (string_table = typeMalloc(char, want)) == 0) { + return (TGETENT_NO); } } else { str_count = 0; + if ((string_table = typeMalloc(char, want)) == 0) { + return (TGETENT_NO); + } } - /* grab the name (a null-terminate string) */ - read(fd, buf, min(MAX_NAME_SIZE, (unsigned) name_size)); - buf[MAX_NAME_SIZE] = '\0'; - bsize = strlen(buf) + 1; - ptr->term_names = typeCalloc(char, bsize); - if (ptr->term_names == NULL) { - return (0); + /* grab the name (a null-terminated string) */ + want = min(MAX_NAME_SIZE, (unsigned) name_size); + ptr->str_table = string_table; + ptr->term_names = string_table; + if ((have = Read(ptr->term_names, want)) != want) { + memset(ptr->term_names + have, 0, want - have); } - (void) strlcpy(ptr->term_names, buf, bsize); - if (name_size > MAX_NAME_SIZE) - lseek(fd, (off_t) (name_size - MAX_NAME_SIZE), 1); + ptr->term_names[want] = '\0'; + string_table += (want + 1); + + if (have > MAX_NAME_SIZE) + offset = (have - MAX_NAME_SIZE); /* grab the booleans */ - if ((ptr->Booleans = typeCalloc(char, max(BOOLCOUNT, bool_count))) == 0 - || read(fd, ptr->Booleans, (unsigned) bool_count) != bool_count) { - return (0); + if ((ptr->Booleans = TYPE_CALLOC(NCURSES_SBOOL, + max(BOOLCOUNT, bool_count))) == 0 + || Read(ptr->Booleans, (unsigned) bool_count) < bool_count) { + return (TGETENT_NO); } /* @@ -227,24 +200,24 @@ read_termtype(int fd, TERMTYPE * ptr) even_boundary(name_size + bool_count); /* grab the numbers */ - if ((ptr->Numbers = typeCalloc(short, max(NUMCOUNT, num_count))) == 0 - || !read_shorts(fd, buf, num_count)) { - return (0); + if ((ptr->Numbers = TYPE_CALLOC(short, max(NUMCOUNT, num_count))) == 0 + || !read_shorts(buf, num_count)) { + return (TGETENT_NO); } convert_shorts(buf, ptr->Numbers, num_count); - if ((ptr->Strings = typeCalloc(char *, max(STRCOUNT, str_count))) == 0) - return (0); + if ((ptr->Strings = TYPE_CALLOC(char *, max(STRCOUNT, str_count))) == 0) + return (TGETENT_NO); if (str_count) { /* grab the string offsets */ - if (!read_shorts(fd, buf, str_count)) { - return (0); + if (!read_shorts(buf, str_count)) { + return (TGETENT_NO); } /* finally, grab the string table itself */ - if (read(fd, ptr->str_table, (unsigned) str_size) != str_size) - return (0); - convert_strings(buf, ptr->Strings, str_count, str_size, ptr->str_table); + if (Read(string_table, (unsigned) str_size) != str_size) + return (TGETENT_NO); + convert_strings(buf, ptr->Strings, str_count, str_size, string_table); } #if NCURSES_XNAMES @@ -256,17 +229,17 @@ read_termtype(int fd, TERMTYPE * ptr) * Read extended entries, if any, after the normal end of terminfo data. */ even_boundary(str_size); - TR(TRACE_DATABASE, ("READ extended_header @%d", tell(fd))); - if (_nc_user_definable && read_shorts(fd, buf, 5)) { + TR(TRACE_DATABASE, ("READ extended_header @%d", offset)); + if (_nc_user_definable && read_shorts(buf, 5)) { int ext_bool_count = LOW_MSB(buf + 0); int ext_num_count = LOW_MSB(buf + 2); int ext_str_count = LOW_MSB(buf + 4); int ext_str_size = LOW_MSB(buf + 6); int ext_str_limit = LOW_MSB(buf + 8); - int need = (ext_bool_count + ext_num_count + ext_str_count); + unsigned need = (ext_bool_count + ext_num_count + ext_str_count); int base = 0; - if (need >= (int) sizeof(buf) + if (need >= sizeof(buf) || ext_str_size >= (int) sizeof(buf) || ext_str_limit >= (int) sizeof(buf) || ext_bool_count < 0 @@ -274,13 +247,13 @@ read_termtype(int fd, TERMTYPE * ptr) || ext_str_count < 0 || ext_str_size < 0 || ext_str_limit < 0) - return (0); + return (TGETENT_NO); ptr->num_Booleans = BOOLCOUNT + ext_bool_count; ptr->num_Numbers = NUMCOUNT + ext_num_count; ptr->num_Strings = STRCOUNT + ext_str_count; - ptr->Booleans = typeRealloc(char, ptr->num_Booleans, ptr->Booleans); + ptr->Booleans = typeRealloc(NCURSES_SBOOL, ptr->num_Booleans, ptr->Booleans); ptr->Numbers = typeRealloc(short, ptr->num_Numbers, ptr->Numbers); ptr->Strings = typeRealloc(char *, ptr->num_Strings, ptr->Strings); @@ -289,36 +262,36 @@ read_termtype(int fd, TERMTYPE * ptr) ext_str_size, ext_str_limit)); TR(TRACE_DATABASE, ("READ %d extended-booleans @%d", - ext_bool_count, tell(fd))); + ext_bool_count, offset)); if ((ptr->ext_Booleans = ext_bool_count) != 0) { - if (read(fd, ptr->Booleans + BOOLCOUNT, (unsigned) + if (Read(ptr->Booleans + BOOLCOUNT, (unsigned) ext_bool_count) != ext_bool_count) - return (0); + return (TGETENT_NO); } even_boundary(ext_bool_count); TR(TRACE_DATABASE, ("READ %d extended-numbers @%d", - ext_num_count, tell(fd))); + ext_num_count, offset)); if ((ptr->ext_Numbers = ext_num_count) != 0) { - if (!read_shorts(fd, buf, ext_num_count)) - return (0); + if (!read_shorts(buf, ext_num_count)) + return (TGETENT_NO); TR(TRACE_DATABASE, ("Before converting extended-numbers")); convert_shorts(buf, ptr->Numbers + NUMCOUNT, ext_num_count); } - TR(TRACE_DATABASE, ("READ extended-offsets @%d", tell(fd))); + TR(TRACE_DATABASE, ("READ extended-offsets @%d", offset)); if ((ext_str_count || need) - && !read_shorts(fd, buf, ext_str_count + need)) - return (0); + && !read_shorts(buf, ext_str_count + need)) + return (TGETENT_NO); TR(TRACE_DATABASE, ("READ %d bytes of extended-strings @%d", - ext_str_limit, tell(fd))); + ext_str_limit, offset)); if (ext_str_limit) { if ((ptr->ext_str_table = typeMalloc(char, ext_str_limit)) == 0) - return (0); - if (read(fd, ptr->ext_str_table, ext_str_limit) != ext_str_limit) - return (0); + return (TGETENT_NO); + if (Read(ptr->ext_str_table, (unsigned) ext_str_limit) != ext_str_limit) + return (TGETENT_NO); TR(TRACE_DATABASE, ("first extended-string is %s", _nc_visbuf(ptr->ext_str_table))); } @@ -342,12 +315,16 @@ read_termtype(int fd, TERMTYPE * ptr) } if (need) { - if ((ptr->ext_Names = typeCalloc(char *, need)) == 0) - return (0); + if (ext_str_count >= (MAX_ENTRY_SIZE * 2)) + return (TGETENT_NO); + if ((ptr->ext_Names = TYPE_CALLOC(char *, need)) == 0) + return (TGETENT_NO); TR(TRACE_DATABASE, ("ext_NAMES starting @%d in extended_strings, first = %s", base, _nc_visbuf(ptr->ext_str_table + base))); - convert_strings(buf + (2 * ext_str_count), ptr->ext_Names, need, + convert_strings(buf + (2 * ext_str_count), + ptr->ext_Names, + (int) need, ext_str_limit, ptr->ext_str_table + base); } @@ -374,15 +351,24 @@ read_termtype(int fd, TERMTYPE * ptr) for (i = str_count; i < STRCOUNT; i++) ptr->Strings[i] = ABSENT_STRING; - return (1); + return (TGETENT_YES); } +/* + * int + * _nc_read_file_entry(filename, ptr) + * + * Read the compiled terminfo entry in the given file into the + * structure pointed to by ptr, allocating space for the string + * table. + */ NCURSES_EXPORT(int) -_nc_read_file_entry -(const char *const filename, TERMTYPE * ptr) +_nc_read_file_entry(const char *const filename, TERMTYPE *ptr) /* return 1 if read, 0 if not found or garbled */ { int code, fd = -1; + int limit; + char buffer[MAX_ENTRY_SIZE + 1]; #ifdef __OpenBSD__ if (_nc_read_bsd_terminfo_file(filename, ptr) == 1) @@ -392,73 +378,137 @@ _nc_read_file_entry if (_nc_access(filename, R_OK) < 0 || (fd = open(filename, O_RDONLY | O_BINARY)) < 0) { T(("cannot open terminfo %s (errno=%d)", filename, errno)); - return (0); - } + code = TGETENT_NO; + } else { + if ((limit = read(fd, buffer, sizeof(buffer))) > 0) { - T(("read terminfo %s", filename)); - if ((code = read_termtype(fd, ptr)) == 0) - _nc_free_termtype(ptr); - close(fd); + T(("read terminfo %s", filename)); + if ((code = _nc_read_termtype(ptr, buffer, limit)) == TGETENT_NO) { + _nc_free_termtype(ptr); + } + } else { + code = TGETENT_NO; + } + close(fd); + } return (code); } /* - * Build a terminfo pathname and try to read the data. Returns 1 on success, - * 0 on failure. + * Build a terminfo pathname and try to read the data. Returns TGETENT_YES on + * success, TGETENT_NO on failure. */ static int -_nc_read_tic_entry(char *const filename, - const char *const dir, const char *ttn, TERMTYPE * const tp) +_nc_read_tic_entry(char *filename, + unsigned limit, + const char *const path, + const char *name, + TERMTYPE *const tp) { -/* maximum safe length of terminfo root directory name */ -#define MAX_TPATH (PATH_MAX - MAX_ALIAS - 6) + int result = TGETENT_NO; - if (strlen(dir) > MAX_TPATH) - return 0; - (void) snprintf(filename, MAX_TPATH + 1, "%s/%s", dir, ttn); - return _nc_read_file_entry(filename, tp); -} + /* + * If we are looking in a directory, assume the entry is a file under that, + * according to the normal rules. + * + * FIXME - add caseless-filename fixup. + */ + unsigned need = 4 + strlen(path) + strlen(name); + if (need <= limit) { + (void) snprintf(filename, limit, "%s/" LEAF_FMT "/%s", path, *name, name); + if (_nc_is_dir_path(path)) + result = _nc_read_file_entry(filename, tp); + } -/* - * Process the list of :-separated directories, looking for the terminal type. - * We don't use strtok because it does not show us empty tokens. - */ -static int -_nc_read_terminfo_dirs(const char *dirs, char *const filename, const char *const - ttn, TERMTYPE * const tp) -{ - char *list, *a; - const char *b; - int code = 0; - - /* we'll modify the argument, so we must copy */ - if ((b = a = list = strdup(dirs)) == NULL) - return (0); - - for (;;) { - int c = *a; - if (c == 0 || c == NCURSES_PATHSEP) { - *a = 0; - if ((b + 1) >= a) - b = TERMINFO; - if (_nc_read_tic_entry(filename, b, ttn, tp) == 1) { - code = 1; - break; +#if USE_HASHED_DB + else { + static const char suffix[] = DBM_SUFFIX; + DB *capdbp; + unsigned lens = sizeof(suffix) - 1; + unsigned size = strlen(path); + unsigned need = lens + size; + + if (need <= limit) { + if (size >= lens + && !strcmp(path + size - lens, suffix)) + (void) strlcpy(filename, path, limit); + else + (void) snprintf(filename, limit, "%s%s", path, suffix); + + /* + * It would be nice to optimize the dbopen/close activity, as + * done in the cgetent implementation for tc= clauses. However, + * since we support multiple database locations, we cannot do + * that. + */ + if ((capdbp = _nc_db_open(filename, FALSE)) != 0) { + DBT key, data; + int reccnt = 0; + char *save = strdup(name); + + memset(&key, 0, sizeof(key)); + key.data = save; + key.size = strlen(save); + + /* + * This lookup could return termcap data, which we do not want. + * We are looking for compiled (binary) terminfo data. + * + * cgetent uses a two-level lookup. On the first it uses the + * given name to return a record containing only the aliases + * for an entry. On the second (using that list of aliases as + * a key), it returns the content of the terminal description. + * We expect second lookup to return data beginning with the + * same set of aliases. + * + * For compiled terminfo, the list of aliases in the second + * case will be null-terminated. A termcap entry will not be, + * and will run on into the description. So we can easily + * distinguish between the two (source/binary) by checking the + * lengths. + */ + while (_nc_db_get(capdbp, &key, &data) == 0) { + int used = data.size - 1; + char *have = (char *) data.data; + + if (*have++ == 0) { + if (data.size > key.size + && IS_TIC_MAGIC(have)) { + result = _nc_read_termtype(tp, have, used); + if (result == TGETENT_NO) { + _nc_free_termtype(tp); + } + } + break; + } + + /* + * Just in case we have a corrupt database, do not waste + * time with it. + */ + if (++reccnt >= 3) + break; + + /* + * Prepare for the second level. + */ + key.data = have; + key.size = used; + } + + _nc_db_close(capdbp); + free(save); } - b = a + 1; - if (c == 0) - break; } - a++; } - - free(list); - return (code); +#endif + return result; } +#endif /* USE_DATABASE */ /* - * _nc_read_entry(char *tn, char *filename, TERMTYPE *tp) + * _nc_read_entry(char *name, char *filename, TERMTYPE *tp) * * Find and read the compiled entry for a given terminal type, * if it exists. We take pains here to make sure no combination @@ -467,52 +517,43 @@ _nc_read_terminfo_dirs(const char *dirs, char *const filename, const char *const */ NCURSES_EXPORT(int) -_nc_read_entry -(const char *const tn, char *const filename, TERMTYPE * const tp) +_nc_read_entry(const char *const name, char *const filename, TERMTYPE *const tp) { - char *envp; - char ttn[MAX_ALIAS + 3]; + int code = TGETENT_NO; #ifdef __OpenBSD__ /* First check the BSD terminfo.db file */ - if (_nc_read_bsd_terminfo_entry(tn, filename, tp) == 1) + if (_nc_read_bsd_terminfo_entry(name, filename, tp) == 1) return (1); #endif /* __OpenBSD__ */ - /* truncate the terminal name to prevent dangerous buffer airline */ - (void) snprintf(ttn, sizeof(ttn), "%c/%.*s", *tn, MAX_ALIAS, tn); - - /* This is System V behavior, in conjunction with our requirements for - * writing terminfo entries. - */ - if (have_tic_directory - && _nc_read_tic_entry(filename, _nc_tic_dir(0), ttn, tp) == 1) - return 1; - - if (use_terminfo_vars()) { - if ((envp = getenv("TERMINFO")) != 0 - && _nc_read_tic_entry(filename, _nc_tic_dir(envp), ttn, tp) == 1) - return 1; - - /* this is an ncurses extension */ - if ((envp = _nc_home_terminfo()) != 0) { - if (_nc_read_tic_entry(filename, envp, ttn, tp) == 1) { - return (1); + snprintf(filename, PATH_MAX, "%s", name); + if (strlen(name) == 0 + || strcmp(name, ".") == 0 + || strcmp(name, "..") == 0 + || _nc_pathlast(name) != 0 + || strchr(name, NCURSES_PATHSEP) != 0) { + T(("illegal or missing entry name '%s'", name)); + } else { +#if USE_DATABASE + DBDIRS state = dbdTIC; + int offset = 0; + const char *path; + + while ((path = _nc_next_db(&state, &offset)) != 0) { + code = _nc_read_tic_entry(filename, PATH_MAX, path, name, tp); + if (code == TGETENT_YES) { + _nc_last_db(); + break; } } - - /* this is an ncurses extension */ - if ((envp = getenv("TERMINFO_DIRS")) != 0) - return _nc_read_terminfo_dirs(envp, filename, ttn, tp); - } - - /* Try the system directory. Note that the TERMINFO_DIRS value, if - * defined by the configure script, begins with a ":", which will be - * interpreted as TERMINFO. - */ -#ifdef TERMINFO_DIRS - return _nc_read_terminfo_dirs(TERMINFO_DIRS, filename, ttn, tp); -#else - return _nc_read_tic_entry(filename, TERMINFO, ttn, tp); #endif +#if USE_TERMCAP + if (code != TGETENT_YES) { + code = _nc_read_termcap_entry(name, tp); + snprintf(filename, PATH_MAX, "%s", _nc_get_source()); + } +#endif + } + return code; } diff --git a/lib/libcurses/tinfo/read_termcap.c b/lib/libcurses/tinfo/read_termcap.c index 65dc97fd04a..9968879f235 100644 --- a/lib/libcurses/tinfo/read_termcap.c +++ b/lib/libcurses/tinfo/read_termcap.c @@ -1,5 +1,7 @@ +/* $OpenBSD: read_termcap.c,v 1.22 2010/01/12 23:22:06 nicm Exp $ */ + /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -52,25 +55,31 @@ #include <curses.priv.h> #include <ctype.h> +#include <sys/types.h> +#include <sys/stat.h> #include <tic.h> #include <term_entry.h> -MODULE_ID("$From: read_termcap.c,v 1.55 2000/12/10 02:55:08 tom Exp $") +MODULE_ID("$Id: read_termcap.c,v 1.22 2010/01/12 23:22:06 nicm Exp $") #if !PURE_TERMINFO -#ifdef __EMX__ -#define is_pathname(s) ((((s) != 0) && ((s)[0] == '/')) \ - || (((s)[0] != 0) && ((s)[1] == ':'))) -#else -#define is_pathname(s) ((s) != 0 && (s)[0] == '/') -#endif - #define TC_SUCCESS 0 -#define TC_UNRESOLVED -1 -#define TC_NOT_FOUND -2 -#define TC_SYS_ERR -3 -#define TC_REF_LOOP -4 +#define TC_NOT_FOUND -1 +#define TC_SYS_ERR -2 +#define TC_REF_LOOP -3 +#define TC_UNRESOLVED -4 /* this is not returned by BSD cgetent */ + +static NCURSES_CONST char * +get_termpath(void) +{ + NCURSES_CONST char *result; + + if (!use_terminfo_vars() || (result = getenv("TERMPATH")) == 0) + result = TERMPATH; + T(("TERMPATH is %s", result)); + return result; +} #if USE_GETCAP @@ -119,13 +128,7 @@ static int _nc_nfcmp(const char *, char *); #define BFRAG 1024 #define BSIZE 1024 -#define ESC ('[' & 037) /* ASCII ESC */ #define MAX_RECURSION 32 /* maximum getent recursion */ -#define SFRAG 100 /* cgetstr mallocs in SFRAG chunks */ - -#define RECOK (char)0 -#define TCERR (char)1 -#define SHADOW (char)2 static size_t topreclen; /* toprec length */ static char *toprec; /* Additional record specified by cgetset() */ @@ -218,10 +221,10 @@ _nc_cgetcap(char *buf, const char *cap, int type) * Returns: * * positive # on success (i.e., the index in db_array) - * TC_UNRESOLVED if we had too many recurrences to resolve * TC_NOT_FOUND if the requested record couldn't be found * TC_SYS_ERR if a system error was encountered (e.g.,couldn't open a file) * TC_REF_LOOP if a potential reference loop is detected + * TC_UNRESOLVED if we had too many recurrences to resolve */ static int _nc_cgetent(char **buf, int *oline, char **db_array, const char *name) @@ -284,7 +287,7 @@ _nc_getent( errno = ENOMEM; return (TC_SYS_ERR); } - (void) strlcpy(record, toprec, topreclen + BFRAG); + (void) strlcpy(record, toprec, topreclen + BFRAG); rp = record + topreclen + 1; r_end = rp + BFRAG; current = in_array; @@ -659,7 +662,11 @@ _nc_nfcmp(const char *nf, char *rec) * 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 + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgment: + * 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. * @@ -701,7 +708,7 @@ get_tc_token(char **srcp, int *endp) if (*s == '\0') { break; } else if (*s++ == '\n') { - while (isspace(*s)) + while (isspace(UChar(*s))) s++; } else { found = TRUE; @@ -715,7 +722,7 @@ get_tc_token(char **srcp, int *endp) break; } base = s; - } else if (isgraph(ch)) { + } else if (isgraph(UChar(ch))) { found = TRUE; } } @@ -735,7 +742,7 @@ copy_tc_token(char *dst, const char *src, size_t len) while ((ch = *src++) != '\0') { if (ch == '\\' && *src == '\n') { - while (isspace(*src)) + while (isspace(UChar(*src))) src++; continue; } @@ -755,7 +762,6 @@ static int _nc_tgetent(char *bp, char **sourcename, int *lineno, const char *name) { static char *the_source; - register char *p; register char *cp; char *dummy = NULL; @@ -765,7 +771,7 @@ _nc_tgetent(char *bp, char **sourcename, int *lineno, const char *name) char pathbuf[PBUFSIZ]; /* holds raw path of filenames */ char *pathvec[PVECSIZ]; /* to point to names in pathbuf */ char **pvec; /* holds usable tail of path vector */ - char *termpath; + NCURSES_CONST char *termpath; string_desc desc; fname = pathvec; @@ -785,23 +791,23 @@ _nc_tgetent(char *bp, char **sourcename, int *lineno, const char *name) */ _nc_str_init(&desc, pathbuf, sizeof(pathbuf)); if (cp == NULL) { - _nc_safe_strcpy(&desc, "/usr/share/misc/termcap /etc/termcap"); - } else if (!is_pathname(cp)) { /* TERMCAP holds an entry */ - if ((termpath = getenv("TERMPATH")) != 0) { + _nc_safe_strcpy(&desc, get_termpath()); + } else if (!_nc_is_abs_path(cp)) { /* TERMCAP holds an entry */ + if ((termpath = get_termpath()) != 0) { _nc_safe_strcat(&desc, termpath); } else { char temp[PBUFSIZ]; - size_t len; temp[0] = 0; if ((home = getenv("HOME")) != 0 && *home != '\0' - && strchr(home, ' ') == 0) { /* setup path */ - len = snprintf(temp, sizeof(temp), "%s/.termcap", home); - if (len < sizeof(temp)) { - _nc_safe_strcat(&desc, temp); - } + && strchr(home, ' ') == 0 + && strlen(home) < sizeof(temp) - 10) { /* setup path */ + snprintf(temp, sizeof(temp), "%s/", home); /* $HOME first */ } - _nc_safe_strcat(&desc, " /usr/share/misc/termcap"); - _nc_safe_strcat(&desc, " /etc/termcap"); + /* if no $HOME look in current directory */ + strlcat(temp, ".termcap", sizeof temp); + _nc_safe_strcat(&desc, temp); + _nc_safe_strcat(&desc, " "); + _nc_safe_strcat(&desc, get_termpath()); } } else { /* user-defined name in TERMCAP */ _nc_safe_strcat(&desc, cp); /* still can be tokenized */ @@ -824,7 +830,7 @@ _nc_tgetent(char *bp, char **sourcename, int *lineno, const char *name) } } *fname = 0; /* mark end of vector */ - if (is_pathname(cp)) { + if (_nc_is_abs_path(cp)) { if (_nc_cgetset(cp) < 0) { return (TC_SYS_ERR); } @@ -877,8 +883,21 @@ _nc_tgetent(char *bp, char **sourcename, int *lineno, const char *name) * cgetent, then it is the actual filename). */ if (i >= 0) { +#if HAVE_BSD_CGETENT + char temp[PATH_MAX]; + + _nc_str_init(&desc, temp, sizeof(temp)); + _nc_safe_strcpy(&desc, pathvec[i]); + _nc_safe_strcat(&desc, ".db"); + if (_nc_access(temp, R_OK) == 0) { + _nc_safe_strcpy(&desc, pathvec[i]); + } + if ((the_source = strdup(temp)) != 0) + *sourcename = the_source; +#else if ((the_source = strdup(pathvec[i])) != 0) *sourcename = the_source; +#endif } return (i); @@ -896,20 +915,26 @@ _nc_tgetent(char *bp, char **sourcename, int *lineno, const char *name) static int add_tc(char *termpaths[], char *path, int count) { + char *save = strchr(path, NCURSES_PATHSEP); + if (save != 0) + *save = '\0'; if (count < MAXPATHS - && _nc_access(path, R_OK) == 0) + && _nc_access(path, R_OK) == 0) { termpaths[count++] = path; + T(("Adding termpath %s", path)); + } termpaths[count] = 0; + if (save != 0) + *save = NCURSES_PATHSEP; return count; } #define ADD_TC(path, count) filecount = add_tc(termpaths, path, count) #endif /* !USE_GETCAP */ NCURSES_EXPORT(int) -_nc_read_termcap_entry -(const char *const tn, TERMTYPE * const tp) +_nc_read_termcap_entry(const char *const tn, TERMTYPE *const tp) { - int found = FALSE; + int found = TGETENT_NO; ENTRY *ep; #if USE_GETCAP_CACHE char cwd_buf[PATH_MAX]; @@ -920,20 +945,31 @@ _nc_read_termcap_entry static char *source; static int lineno; + T(("read termcap entry for %s", tn)); + + if (strlen(tn) == 0 + || strcmp(tn, ".") == 0 + || strcmp(tn, "..") == 0 + || _nc_pathlast(tn) != 0) { + T(("illegal or missing entry name '%s'", tn)); + return TGETENT_NO; + } + if (use_terminfo_vars() && (p = getenv("TERMCAP")) != 0 - && !is_pathname(p) && _nc_name_match(p, tn, "|:")) { + && !_nc_is_abs_path(p) && _nc_name_match(p, tn, "|:")) { /* TERMCAP holds a termcap entry */ - strlcpy(tc, p, sizeof(tc)); + strncpy(tc, p, sizeof(tc) - 1); + tc[sizeof(tc) - 1] = '\0'; _nc_set_source("TERMCAP"); } else { /* we're using getcap(3) */ if ((status = _nc_tgetent(tc, &source, &lineno, tn)) < 0) - return (status == -1 ? 0 : -1); + return (status == TC_NOT_FOUND ? TGETENT_NO : TGETENT_ERR); _nc_curr_line = lineno; _nc_set_source(source); } - _nc_read_entry_source((FILE *) 0, tc, FALSE, TRUE, NULLHOOK); + _nc_read_entry_source((FILE *) 0, tc, FALSE, FALSE, NULLHOOK); #else /* * Here is what the 4.4BSD termcap(3) page prescribes: @@ -964,65 +1000,98 @@ _nc_read_termcap_entry FILE *fp; char *tc, *termpaths[MAXPATHS]; int filecount = 0; + int j, k; bool use_buffer = FALSE; + bool normal = TRUE; char tc_buf[1024]; char pathbuf[PATH_MAX]; + char *copied = 0; + char *cp; + struct stat test_stat[MAXPATHS]; termpaths[filecount] = 0; if (use_terminfo_vars() && (tc = getenv("TERMCAP")) != 0) { - if (is_pathname(tc)) { /* interpret as a filename */ + if (_nc_is_abs_path(tc)) { /* interpret as a filename */ ADD_TC(tc, 0); + normal = FALSE; } else if (_nc_name_match(tc, tn, "|:")) { /* treat as a capability file */ use_buffer = TRUE; - (void) snprintf(tc_buf, sizeof(tc_buf), "%.*s\n", - (int) sizeof(tc_buf) - 2, tc); - } else if ((tc = getenv("TERMPATH")) != 0) { - char *cp; - - for (cp = tc; *cp; cp++) { - if (*cp == NCURSES_PATHSEP) - *cp = '\0'; - else if (cp == tc || cp[-1] == '\0') { - ADD_TC(cp, filecount); - } - } + (void) snprintf(tc_buf, sizeof(tc_buf), "%.*s\n", (int) sizeof(tc_buf) - 2, tc); + normal = FALSE; } - } else { /* normal case */ - char envhome[PATH_MAX], *h; + } - filecount = 0; + if (normal) { /* normal case */ + char envhome[PATH_MAX], *h; - /* - * Probably /etc/termcap is a symlink to /usr/share/misc/termcap. - * Avoid reading the same file twice. - */ - if (_nc_access("/etc/termcap", F_OK) == 0) - ADD_TC("/etc/termcap", filecount); - else - ADD_TC("/usr/share/misc/termcap", filecount); + copied = strdup(get_termpath()); + for (cp = copied; *cp; cp++) { + if (*cp == NCURSES_PATHSEP) + *cp = '\0'; + else if (cp == copied || cp[-1] == '\0') { + ADD_TC(cp, filecount); + } + } #define PRIVATE_CAP "%s/.termcap" if (use_terminfo_vars() && (h = getenv("HOME")) != NULL && *h != '\0' && (strlen(h) + sizeof(PRIVATE_CAP)) < PATH_MAX) { /* user's .termcap, if any, should override it */ - (void) strlcpy(envhome, h, sizeof(envhome)); + (void) strlcpy(envhome, h, sizeof(envhome); (void) snprintf(pathbuf, sizeof(pathbuf), PRIVATE_CAP, envhome); ADD_TC(pathbuf, filecount); } } + /* + * Probably /etc/termcap is a symlink to /usr/share/misc/termcap. + * Avoid reading the same file twice. + */ +#if HAVE_LINK + for (j = 0; j < filecount; j++) { + bool omit = FALSE; + if (stat(termpaths[j], &test_stat[j]) != 0 + || (test_stat[j].st_mode & S_IFMT) != S_IFREG) { + omit = TRUE; + } else { + for (k = 0; k < j; k++) { + if (test_stat[k].st_dev == test_stat[j].st_dev + && test_stat[k].st_ino == test_stat[j].st_ino) { + omit = TRUE; + break; + } + } + } + if (omit) { + T(("Path %s is a duplicate", termpaths[j])); + for (k = j + 1; k < filecount; k++) { + termpaths[k - 1] = termpaths[k]; + test_stat[k - 1] = test_stat[k]; + } + --filecount; + --j; + } + } +#endif + /* parse the sources */ if (use_buffer) { _nc_set_source("TERMCAP"); - _nc_read_entry_source((FILE *) 0, tc_buf, FALSE, TRUE, NULLHOOK); + + /* + * We don't suppress warning messages here. The presumption is + * that since it's just a single entry, they won't be a pain. + */ + _nc_read_entry_source((FILE *) 0, tc_buf, FALSE, FALSE, NULLHOOK); } else { int i; for (i = 0; i < filecount; i++) { T(("Looking for %s in %s", tn, termpaths[i])); - if ((fp = fopen(termpaths[i], "r")) != (FILE *) 0) { + if (_nc_access(termpaths[i], R_OK) == 0 + && (fp = fopen(termpaths[i], "r")) != (FILE *) 0) { _nc_set_source(termpaths[i]); /* @@ -1036,13 +1105,15 @@ _nc_read_termcap_entry } } } + if (copied != 0) + free(copied); #endif /* USE_GETCAP */ if (_nc_head == 0) - return (ERR); + return (TGETENT_ERR); /* resolve all use references */ - _nc_resolve_uses(TRUE); + _nc_resolve_uses2(TRUE, FALSE); /* find a terminal matching tn, if we can */ #if USE_GETCAP_CACHE @@ -1052,13 +1123,12 @@ _nc_read_termcap_entry for_entry_list(ep) { if (_nc_name_match(ep->tterm.term_names, tn, "|:")) { /* - * Make a local copy of the terminal capabilities. Free all - * entry storage except the string table for the loaded type - * (which we disconnected from the list by NULLing out - * ep->tterm.str_table above). + * Make a local copy of the terminal capabilities, delinked + * from the list. */ *tp = ep->tterm; - ep->tterm.str_table = (char *) 0; + _nc_delink_entry(_nc_head, &(ep->tterm)); + free(ep); /* * OK, now try to write the type to user's terminfo directory. @@ -1075,7 +1145,7 @@ _nc_read_termcap_entry #if USE_GETCAP_CACHE (void) _nc_write_entry(tp); #endif - found = TRUE; + found = TGETENT_YES; break; } } @@ -1084,7 +1154,6 @@ _nc_read_termcap_entry } #endif - _nc_free_entries(_nc_head); return (found); } #else diff --git a/lib/libcurses/tinfo/setbuf.c b/lib/libcurses/tinfo/setbuf.c index cfe3771b036..a569f45cc52 100644 --- a/lib/libcurses/tinfo/setbuf.c +++ b/lib/libcurses/tinfo/setbuf.c @@ -1,7 +1,7 @@ -/* $OpenBSD: setbuf.c,v 1.4 2001/01/22 18:01:57 millert Exp $ */ +/* $OpenBSD: setbuf.c,v 1.5 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2003,2007 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -42,7 +42,7 @@ #include <curses.priv.h> -MODULE_ID("$From: setbuf.c,v 1.7 2000/12/10 02:55:08 tom Exp $") +MODULE_ID("$Id: setbuf.c,v 1.5 2010/01/12 23:22:06 nicm Exp $") /* * If the output file descriptor is connected to a tty (the typical case) it @@ -100,47 +100,53 @@ MODULE_ID("$From: setbuf.c,v 1.7 2000/12/10 02:55:08 tom Exp $") * buffer. So we disable this by default (there may yet be a workaround). */ NCURSES_EXPORT(void) -_nc_set_buffer(FILE * ofp, bool buffered) +_nc_set_buffer(FILE *ofp, bool buffered) { /* optional optimization hack -- do before any output to ofp */ #if HAVE_SETVBUF || HAVE_SETBUFFER - unsigned buf_len; - char *buf_ptr; + if (SP->_buffered != buffered) { + unsigned buf_len; + char *buf_ptr; - if (getenv("NCURSES_NO_SETBUF") != 0) - return; + if (getenv("NCURSES_NO_SETBUF") != 0) + return; - fflush(ofp); - if ((SP->_buffered = buffered) != 0) { - buf_len = min(LINES * (COLS + 6), 2800); - if ((buf_ptr = SP->_setbuf) == 0) { - if ((buf_ptr = typeMalloc(char, buf_len)) == NULL) - return; - SP->_setbuf = buf_ptr; - /* Don't try to free this! */ - } + fflush(ofp); +#ifdef __DJGPP__ + setmode(ofp, O_BINARY); +#endif + if (buffered != 0) { + buf_len = min(LINES * (COLS + 6), 2800); + if ((buf_ptr = SP->_setbuf) == 0) { + if ((buf_ptr = typeMalloc(char, buf_len)) == NULL) + return; + SP->_setbuf = buf_ptr; + /* Don't try to free this! */ + } #if !USE_SETBUF_0 - else - return; + else + return; #endif - } else { + } else { #if !USE_SETBUF_0 - return; + return; #else - buf_len = 0; - buf_ptr = 0; + buf_len = 0; + buf_ptr = 0; #endif - } + } #if HAVE_SETVBUF #ifdef SETVBUF_REVERSED /* pre-svr3? */ - (void) setvbuf(ofp, buf_ptr, buf_len, buf_len ? _IOFBF : _IOLBF); + (void) setvbuf(ofp, buf_ptr, buf_len, buf_len ? _IOFBF : _IOLBF); #else - (void) setvbuf(ofp, buf_ptr, buf_len ? _IOFBF : _IOLBF, buf_len); + (void) setvbuf(ofp, buf_ptr, buf_len ? _IOFBF : _IOLBF, buf_len); #endif #elif HAVE_SETBUFFER - (void) setbuffer(ofp, buf_ptr, (int) buf_len); + (void) setbuffer(ofp, buf_ptr, (int) buf_len); #endif + SP->_buffered = buffered; + } #endif /* HAVE_SETVBUF || HAVE_SETBUFFER */ } diff --git a/lib/libcurses/tinfo/strings.c b/lib/libcurses/tinfo/strings.c index fd5d7f314b8..b0f06598466 100644 --- a/lib/libcurses/tinfo/strings.c +++ b/lib/libcurses/tinfo/strings.c @@ -1,7 +1,7 @@ -/* $OpenBSD: strings.c,v 1.3 2003/03/18 16:55:54 millert Exp $ */ +/* $OpenBSD: strings.c,v 1.4 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 2000 Free Software Foundation, Inc. * + * Copyright (c) 2000-2003,2007 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -38,7 +38,7 @@ #include <curses.priv.h> -MODULE_ID("$From: strings.c,v 1.3 2000/12/10 02:55:08 tom Exp $") +MODULE_ID("$Id: strings.c,v 1.4 2010/01/12 23:22:06 nicm Exp $") /**************************************************************************** * Useful string functions (especially for mvcur) @@ -46,8 +46,7 @@ MODULE_ID("$From: strings.c,v 1.3 2000/12/10 02:55:08 tom Exp $") #if !HAVE_STRSTR NCURSES_EXPORT(char *) -_nc_strstr -(const char *haystack, const char *needle) +_nc_strstr(const char *haystack, const char *needle) { size_t len1 = strlen(haystack); size_t len2 = strlen(needle); @@ -55,7 +54,7 @@ _nc_strstr while ((len1 != 0) && (len1-- >= len2)) { if (!strncmp(haystack, needle, len2)) { - result = haystack; + result = (char *) haystack; break; } haystack++; @@ -65,16 +64,18 @@ _nc_strstr #endif /* - * Initialize the descriptor so we can append to it. + * Initialize the descriptor so we can append to it. Note that 'src' may + * be a null pointer (see _nc_str_null), so the corresponding strcat and + * strcpy calls have to allow for this. */ NCURSES_EXPORT(string_desc *) -_nc_str_init -(string_desc * dst, char *src, size_t len) +_nc_str_init(string_desc * dst, char *src, size_t len) { if (dst != 0) { dst->s_head = src; dst->s_tail = src; dst->s_size = len - 1; + dst->s_init = dst->s_size; if (src != 0) *src = 0; } @@ -85,8 +86,7 @@ _nc_str_init * Initialize the descriptor for only tracking the amount of memory used. */ NCURSES_EXPORT(string_desc *) -_nc_str_null -(string_desc * dst, size_t len) +_nc_str_null(string_desc * dst, size_t len) { return _nc_str_init(dst, 0, len); } @@ -95,8 +95,7 @@ _nc_str_null * Copy a descriptor */ NCURSES_EXPORT(string_desc *) -_nc_str_copy -(string_desc * dst, string_desc * src) +_nc_str_copy(string_desc * dst, string_desc * src) { *dst = *src; return dst; @@ -137,7 +136,7 @@ _nc_safe_strcpy(string_desc * dst, const char *src) strlcpy(dst->s_head, src, dst->s_size); dst->s_tail = dst->s_head + len; } - dst->s_size -= len; + dst->s_size = dst->s_init - len; return TRUE; } } diff --git a/lib/libcurses/tinfo/trim_sgr0.c b/lib/libcurses/tinfo/trim_sgr0.c new file mode 100644 index 00000000000..017d715bd01 --- /dev/null +++ b/lib/libcurses/tinfo/trim_sgr0.c @@ -0,0 +1,328 @@ +/* $OpenBSD: trim_sgr0.c,v 1.1 2010/01/12 23:22:06 nicm Exp $ */ + +/**************************************************************************** + * Copyright (c) 2005-2006,2007 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas Dickey * + ****************************************************************************/ + +#include <curses.priv.h> + +#include <ctype.h> + +#include <tic.h> +#include <term_entry.h> + +MODULE_ID("$Id: trim_sgr0.c,v 1.1 2010/01/12 23:22:06 nicm Exp $") + +#undef CUR +#define CUR tp-> + +#define CSI 233 +#define ESC 033 /* ^[ */ +#define L_BRACK '[' + +static char * +set_attribute_9(TERMTYPE *tp, int flag) +{ + const char *result; + + if ((result = tparm(set_attributes, 0, 0, 0, 0, 0, 0, 0, 0, flag)) == 0) + result = ""; + return strdup(result); +} + +static int +is_csi(const char *s) +{ + if (UChar(s[0]) == CSI) + return 1; + else if (s[0] == ESC && s[1] == L_BRACK) + return 2; + return 0; +} + +static char * +skip_zero(char *s) +{ + if (s[0] == '0') { + if (s[1] == ';') + s += 2; + else if (isalpha(UChar(s[1]))) + s += 1; + } + return s; +} + +static const char * +skip_delay(const char *s) +{ + if (s[0] == '$' && s[1] == '<') { + s += 2; + while (isdigit(UChar(*s)) || *s == '/') + ++s; + if (*s == '>') + ++s; + } + return s; +} + +/* + * Improve similar_sgr a little by moving the attr-string from the beginning + * to the end of the s-string. + */ +static bool +rewrite_sgr(char *s, char *attr) +{ + if (PRESENT(s)) { + if (PRESENT(attr)) { + unsigned len_s = strlen(s); + unsigned len_a = strlen(attr); + + if (len_s > len_a && !strncmp(attr, s, len_a)) { + unsigned n; + TR(TRACE_DATABASE, ("rewrite:\n\t%s", s)); + for (n = 0; n < len_s - len_a; ++n) { + s[n] = s[n + len_a]; + } + strlcpy(s + n, attr, len_s - n); + TR(TRACE_DATABASE, ("to:\n\t%s", s)); + } + } + return TRUE; + } + return FALSE; /* oops */ +} + +static bool +similar_sgr(char *a, char *b) +{ + bool result = FALSE; + int csi_a = is_csi(a); + int csi_b = is_csi(b); + unsigned len_a; + unsigned len_b; + + TR(TRACE_DATABASE, ("similar_sgr:\n\t%s\n\t%s", + _nc_visbuf2(1, a), + _nc_visbuf2(2, b))); + if (csi_a != 0 && csi_b != 0 && csi_a == csi_b) { + a += csi_a; + b += csi_b; + if (*a != *b) { + a = skip_zero(a); + b = skip_zero(b); + } + } + len_a = strlen(a); + len_b = strlen(b); + if (len_a && len_b) { + if (len_a > len_b) + result = (strncmp(a, b, len_b) == 0); + else + result = (strncmp(a, b, len_a) == 0); + } + TR(TRACE_DATABASE, ("...similar_sgr: %d\n\t%s\n\t%s", result, + _nc_visbuf2(1, a), + _nc_visbuf2(2, b))); + return result; +} + +static unsigned +chop_out(char *string, unsigned i, unsigned j) +{ + TR(TRACE_DATABASE, ("chop_out %d..%d from %s", i, j, _nc_visbuf(string))); + while (string[j] != '\0') { + string[i++] = string[j++]; + } + string[i] = '\0'; + return i; +} + +/* + * Compare, ignoring delays. Some of the delay values are inconsistent, and + * we do not want to be stopped by that. + * + * Returns the number of chars from 'full' that we matched. If any mismatch + * occurs, return zero. + */ +static int +compare_part(const char *part, const char *full) +{ + const char *next_part; + const char *next_full; + int used_full = 0; + int used_delay = 0; + + while (*part != 0) { + if (*part != *full) { + used_full = 0; + break; + } + + /* + * Adjust the return-value to allow the rare case of + * string<delay>string + * to remove the whole piece. The most common case is a delay at the + * end of the string. The adjusted string will retain the delay, which + * is conservative. + */ + if (used_delay != 0) { + used_full += used_delay; + used_delay = 0; + } + if (*part == '$' && *full == '$') { + next_part = skip_delay(part); + next_full = skip_delay(full); + if (next_part != part && next_full != full) { + used_delay += (next_full - full); + full = next_full; + part = next_part; + continue; + } + } + ++used_full; + ++part; + ++full; + } + return used_full; +} + +/* + * While 'sgr0' is the "same" as termcap 'me', there is a compatibility issue. + * The sgr/sgr0 capabilities include setting/clearing alternate character set + * mode. A termcap application cannot use sgr, so sgr0 strings that reset + * alternate character set mode will be misinterpreted. Here, we remove those + * from the more common ISO/ANSI/VT100 entries, which have sgr0 agreeing with + * sgr. + * + * This function returns the modified sgr0 if it can be modified, a null if + * an error occurs, or the original sgr0 if no change is needed. + */ +NCURSES_EXPORT(char *) +_nc_trim_sgr0(TERMTYPE *tp) +{ + char *result = exit_attribute_mode; + + T((T_CALLED("_nc_trim_sgr0()"))); + + if (PRESENT(exit_attribute_mode) + && PRESENT(set_attributes)) { + bool found = FALSE; + char *on = set_attribute_9(tp, 1); + char *off = set_attribute_9(tp, 0); + char *end = strdup(exit_attribute_mode); + char *tmp; + size_t i, j, k; + + TR(TRACE_DATABASE, ("checking if we can trim sgr0 based on sgr")); + TR(TRACE_DATABASE, ("sgr0 %s", _nc_visbuf(end))); + TR(TRACE_DATABASE, ("sgr(9:off) %s", _nc_visbuf(off))); + TR(TRACE_DATABASE, ("sgr(9:on) %s", _nc_visbuf(on))); + + if (!rewrite_sgr(on, enter_alt_charset_mode) + || !rewrite_sgr(off, exit_alt_charset_mode) + || !rewrite_sgr(end, exit_alt_charset_mode)) { + FreeIfNeeded(off); + } else if (similar_sgr(off, end) + && !similar_sgr(off, on)) { + TR(TRACE_DATABASE, ("adjusting sgr(9:off) : %s", _nc_visbuf(off))); + result = off; + /* + * If rmacs is a substring of sgr(0), remove that chunk. + */ + if (exit_alt_charset_mode != 0) { + TR(TRACE_DATABASE, ("scan for rmacs %s", _nc_visbuf(exit_alt_charset_mode))); + j = strlen(off); + k = strlen(exit_alt_charset_mode); + if (j > k) { + for (i = 0; i <= (j - k); ++i) { + int k2 = compare_part(exit_alt_charset_mode, off + i); + if (k2 != 0) { + found = TRUE; + chop_out(off, i, i + k2); + break; + } + } + } + } + /* + * SGR 10 would reset to normal font. + */ + if (!found) { + if ((i = is_csi(off)) != 0 + && off[strlen(off) - 1] == 'm') { + TR(TRACE_DATABASE, ("looking for SGR 10 in %s", + _nc_visbuf(off))); + tmp = skip_zero(off + i); + if (tmp[0] == '1' + && skip_zero(tmp + 1) != tmp + 1) { + i = tmp - off; + if (off[i - 1] == ';') + i--; + j = skip_zero(tmp + 1) - off; + i = chop_out(off, i, j); + found = TRUE; + } + } + } + if (!found + && (tmp = strstr(end, off)) != 0 + && strcmp(end, off) != 0) { + i = tmp - end; + j = strlen(off); + tmp = strdup(end); + chop_out(tmp, i, j); + free(off); + result = tmp; + } + TR(TRACE_DATABASE, ("...adjusted sgr0 : %s", _nc_visbuf(result))); + if (!strcmp(result, exit_attribute_mode)) { + TR(TRACE_DATABASE, ("...same result, discard")); + free(result); + result = exit_attribute_mode; + } + } else { + /* + * Either the sgr does not reference alternate character set, + * or it is incorrect. That's too hard to decide right now. + */ + free(off); + } + FreeIfNeeded(end); + FreeIfNeeded(on); + } else { + /* + * Possibly some applications are confused if sgr0 contains rmacs, + * but that would be a different bug report -TD + */ + } + + returnPtr(result); +} diff --git a/lib/libcurses/tinfo/use_screen.c b/lib/libcurses/tinfo/use_screen.c new file mode 100644 index 00000000000..2d79e734601 --- /dev/null +++ b/lib/libcurses/tinfo/use_screen.c @@ -0,0 +1,60 @@ +/* $OpenBSD: use_screen.c,v 1.1 2010/01/12 23:22:06 nicm Exp $ */ + +/**************************************************************************** + * Copyright (c) 2007,2008 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey 2007 * + ****************************************************************************/ + +#include <curses.priv.h> + +MODULE_ID("$Id: use_screen.c,v 1.1 2010/01/12 23:22:06 nicm Exp $") + +NCURSES_EXPORT(int) +use_screen(SCREEN *screen, NCURSES_SCREEN_CB func, void *data) +{ + SCREEN *save_SP; + int code = OK; + + T((T_CALLED("use_screen(%p,%p,%p)"), screen, func, data)); + + /* + * FIXME - add a flag so a given thread can check if _it_ has already + * recurred through this point, return an error if so. + */ + _nc_lock_global(curses); + save_SP = SP; + set_term(screen); + + code = func(screen, data); + + set_term(save_SP); + _nc_unlock_global(curses); + returnCode(code); +} diff --git a/lib/libcurses/tinfo/write_entry.c b/lib/libcurses/tinfo/write_entry.c index 9aff48b5ef0..4f28313b905 100644 --- a/lib/libcurses/tinfo/write_entry.c +++ b/lib/libcurses/tinfo/write_entry.c @@ -1,7 +1,7 @@ -/* $OpenBSD: write_entry.c,v 1.12 2003/03/18 16:55:54 millert Exp $ */ +/* $OpenBSD: write_entry.c,v 1.13 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -38,6 +39,7 @@ */ #include <curses.priv.h> +#include <hashed_db.h> #include <sys/stat.h> @@ -48,21 +50,27 @@ #define S_ISDIR(mode) ((mode & S_IFMT) == S_IFDIR) #endif -#if 0 +#if 1 #define TRACE_OUT(p) DEBUG(2, p) #else #define TRACE_OUT(p) /*nothing */ #endif -MODULE_ID("$From: write_entry.c,v 1.56 2000/12/10 02:55:08 tom Exp $") +MODULE_ID("$Id: write_entry.c,v 1.13 2010/01/12 23:22:06 nicm Exp $") static int total_written; -static int write_object(FILE *, TERMTYPE *); +static int make_db_root(const char *); +static int write_object(TERMTYPE *, char *, unsigned *, unsigned); +#if !USE_HASHED_DB static void -write_file(char *filename, TERMTYPE * tp) +write_file(char *filename, TERMTYPE *tp) { + char buffer[MAX_ENTRY_SIZE]; + unsigned limit = sizeof(buffer); + unsigned offset = 0; + FILE *fp = (_nc_access(filename, W_OK) == 0) ? fopen(filename, "wb") : 0; if (fp == 0) { perror(filename); @@ -70,49 +78,117 @@ write_file(char *filename, TERMTYPE * tp) } DEBUG(1, ("Created %s", filename)); - if (write_object(fp, tp) == ERR) { + if (write_object(tp, buffer, &offset, limit) == ERR + || fwrite(buffer, sizeof(char), offset, fp) != offset) { _nc_syserr_abort("error writing %s/%s", _nc_tic_dir(0), filename); } + fclose(fp); } /* - * make_directory(char *path) + * Check for access rights to destination directories + * Create any directories which don't exist. * - * Make a directory if it doesn't exist. + * Note: there's no reason to return the result of make_db_root(), since + * this function is called only in instances where that has to succeed. */ +static void +check_writeable(int code) +{ + static const char dirnames[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + static bool verified[sizeof(dirnames)]; + + char dir[sizeof(LEAF_FMT)]; + char *s = 0; + + if (code == 0 || (s = strchr(dirnames, code)) == 0) + _nc_err_abort("Illegal terminfo subdirectory \"" LEAF_FMT "\"", code); + + if (verified[s - dirnames]) + return; + + snprintf(dir, sizeof(dir), LEAF_FMT, code); + if (make_db_root(dir) < 0) { + _nc_err_abort("%s/%s: permission denied", _nc_tic_dir(0), dir); + } + + verified[s - dirnames] = TRUE; +} +#endif /* !USE_HASHED_DB */ + static int -make_directory(const char *path) +make_db_path(char *dst, const char *src, unsigned limit) { - int rc; - struct stat statbuf; - char fullpath[PATH_MAX]; - const char *destination = _nc_tic_dir(0); + int rc = -1; + const char *top = _nc_tic_dir(0); - if (path == destination || *path == '/') { - if (strlcpy(fullpath, path, sizeof(fullpath)) >= sizeof(fullpath)) - return (-1); + if (src == top || _nc_is_abs_path(src)) { + if (strlen(src) + 1 <= limit) { + (void) strlcpy(dst, src, limit); + rc = 0; + } } else { - if (strlen(destination) + strlen(path) + 2 > sizeof(fullpath)) - return (-1); - (void) snprintf(fullpath, sizeof(fullpath), "%s/%s", destination, path); + if (strlen(top) + strlen(src) + 2 <= limit) { + (void) snprintf(dst, limit, "%s/%s", top, src); + rc = 0; + } + } +#if USE_HASHED_DB + if (rc == 0) { + if (_nc_is_dir_path(dst)) { + rc = -1; + } else { + unsigned have = strlen(dst); + if (have > 3 && strcmp(dst + have - 3, DBM_SUFFIX)) { + if (have + 3 <= limit) + strlcat(dst, DBM_SUFFIX, limit); + else + rc = -1; + } + } } +#endif + return rc; +} - if ((rc = stat(path, &statbuf)) < 0) { - rc = mkdir(path, 0777); - } else { - if (_nc_access(path, R_OK | W_OK | X_OK) < 0) { +/* + * Make a database-root if it doesn't exist. + */ +static int +make_db_root(const char *path) +{ + int rc; + char fullpath[PATH_MAX]; + + if ((rc = make_db_path(fullpath, path, sizeof(fullpath))) == 0) { +#if USE_HASHED_DB + DB *capdbp; + + if ((capdbp = _nc_db_open(fullpath, TRUE)) == NULL) + rc = -1; + else if (_nc_db_close(capdbp) < 0) + rc = -1; +#else + struct stat statbuf; + + if ((rc = stat(path, &statbuf)) < 0) { + rc = mkdir(path, 0777); + } else if (_nc_access(path, R_OK | W_OK | X_OK) < 0) { rc = -1; /* permission denied */ } else if (!(S_ISDIR(statbuf.st_mode))) { rc = -1; /* not a directory */ } +#endif } return rc; } +/* + * Set the write directory for compiled entries. + */ NCURSES_EXPORT(void) _nc_set_writedir(char *dir) -/* set the write directory for compiled entries */ { const char *destination; char actual[PATH_MAX]; @@ -125,12 +201,12 @@ _nc_set_writedir(char *dir) (void) _nc_tic_dir(dir); destination = _nc_tic_dir(0); - if (make_directory(destination) < 0) { + if (make_db_root(destination) < 0) { char *home = _nc_home_terminfo(); if (home != 0) { destination = home; - if (make_directory(destination) < 0) + if (make_db_root(destination) < 0) _nc_err_abort("%s: permission denied (errno %d)", destination, errno); } @@ -140,51 +216,17 @@ _nc_set_writedir(char *dir) * Note: because of this code, this logic should be exercised * *once only* per run. */ +#if USE_HASHED_DB + make_db_path(actual, destination, sizeof(actual)); +#else if (chdir(_nc_tic_dir(destination)) < 0 || getcwd(actual, sizeof(actual)) == 0) _nc_err_abort("%s: not a directory", destination); +#endif _nc_keep_tic_dir(strdup(actual)); } /* - * check_writeable(char code) - * - * Miscellaneous initialisations - * - * Check for access rights to destination directories - * Create any directories which don't exist. - * Note: there's no reason to return the result of make_directory(), since - * this function is called only in instances where that has to succeed. - * - */ - -static void -check_writeable(int code) -{ - static const char dirnames[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - static bool verified[sizeof(dirnames)]; - - char dir[2]; - char *s = 0; - - if (code == 0 || (s = strchr(dirnames, code)) == 0) - _nc_err_abort("Illegal terminfo subdirectory \"%c\"", code); - - if (verified[s - dirnames]) - return; - - dir[0] = code; - dir[1] = '\0'; - if (make_directory(dir) < 0) { - _nc_err_abort("%s/%s: permission denied", _nc_tic_dir(0), dir); - } - - verified[s - dirnames] = TRUE; -} - -/* - * _nc_write_entry() - * * Save the compiled version of a description in the filesystem. * * make a copy of the name-list @@ -204,24 +246,39 @@ check_writeable(int code) * _nc_curr_line is properly set before the write_entry() call. */ -void -_nc_write_entry(TERMTYPE * const tp) +NCURSES_EXPORT(void) +_nc_write_entry(TERMTYPE *const tp) { +#if USE_HASHED_DB + + char buffer[MAX_ENTRY_SIZE + 1]; + unsigned limit = sizeof(buffer); + unsigned offset = 0; + +#else /* !USE_HASHED_DB */ + struct stat statbuf; - char name_list[MAX_TERMINFO_LENGTH]; - char *first_name, *other_names; - char *ptr; char filename[PATH_MAX]; char linkname[PATH_MAX]; #if USE_SYMLINKS char symlinkname[PATH_MAX]; +#if !HAVE_LINK +#undef HAVE_LINK +#define HAVE_LINK 1 +#endif #endif /* USE_SYMLINKS */ + static int call_count; static time_t start_time; /* time at start of writes */ - if (call_count++ == 0) { - start_time = 0; - } +#endif /* USE_HASHED_DB */ + + char name_list[MAX_TERMINFO_LENGTH]; + char *first_name, *other_names; + char *ptr; + + assert(strlen(tp->term_names) != 0); + assert(strlen(tp->term_names) < sizeof(name_list)); (void) strlcpy(name_list, tp->term_names, sizeof(name_list)); DEBUG(7, ("Name list = '%s'", name_list)); @@ -253,10 +310,59 @@ _nc_write_entry(TERMTYPE * const tp) _nc_set_type(first_name); - if (strlen(first_name) > sizeof(filename) - 3) +#if USE_HASHED_DB + if (write_object(tp, buffer + 1, &offset, limit - 1) != ERR) { + DB *capdb = _nc_db_open(_nc_tic_dir(0), TRUE); + DBT key, data; + + if (capdb != 0) { + buffer[0] = 0; + + memset(&key, 0, sizeof(key)); + key.data = tp->term_names; + key.size = strlen(tp->term_names); + + memset(&data, 0, sizeof(data)); + data.data = buffer; + data.size = offset + 1; + + _nc_db_put(capdb, &key, &data); + + buffer[0] = 2; + + key.data = name_list; + key.size = strlen(name_list); + + strlcpy(buffer + 1, tp->term_names, sizeof(buffer) - 1); + data.size = strlen(tp->term_names) + 1; + + _nc_db_put(capdb, &key, &data); + + while (*other_names != '\0') { + ptr = other_names++; + while (*other_names != '|' && *other_names != '\0') + other_names++; + + if (*other_names != '\0') + *(other_names++) = '\0'; + + key.data = ptr; + key.size = strlen(ptr); + + _nc_db_put(capdb, &key, &data); + } + _nc_db_close(capdb); + } + } +#else /* !USE_HASHED_DB */ + if (call_count++ == 0) { + start_time = 0; + } + + if (strlen(first_name) >= sizeof(filename) - 3) _nc_warning("terminal name too long."); - snprintf(filename, sizeof(filename), "%c/%s", first_name[0], first_name); + snprintf(filename, sizeof(filename), LEAF_FMT "/%s", first_name[0], first_name); /* * Has this primary name been written since the first call to @@ -281,6 +387,7 @@ _nc_write_entry(TERMTYPE * const tp) } while (*other_names != '\0') { ptr = other_names++; + assert(ptr < buffer + sizeof(buffer) - 1); while (*other_names != '|' && *other_names != '\0') other_names++; @@ -297,7 +404,7 @@ _nc_write_entry(TERMTYPE * const tp) } check_writeable(ptr[0]); - snprintf(linkname, sizeof(linkname), "%c/%s", ptr[0], ptr); + snprintf(linkname, sizeof(linkname), LEAF_FMT "/%s", ptr[0], ptr); if (strcmp(filename, linkname) == 0) { _nc_warning("self-synonym ignored"); @@ -309,8 +416,8 @@ _nc_write_entry(TERMTYPE * const tp) { int code; #if USE_SYMLINKS - strlcpy(symlinkname, "../", sizeof(symlinkname)); - strlcat(symlinkname, filename, sizeof(symlinkname)); + strlcpy(symlinkname, "../", sizeof(symlinkname)); + strlcat(symlinkname, filename, sizeof(symlinkname)); #endif /* USE_SYMLINKS */ #if HAVE_REMOVE code = remove(linkname); @@ -351,20 +458,45 @@ _nc_write_entry(TERMTYPE * const tp) write_file(linkname, tp); #endif /* HAVE_LINK */ } +#endif /* USE_HASHED_DB */ } +static unsigned +fake_write(char *dst, + unsigned *offset, + unsigned limit, + char *src, + unsigned want, + unsigned size) +{ + int have = (limit - *offset); + + want *= size; + if (have > 0) { + if ((int) want > have) + want = have; + memcpy(dst + *offset, src, want); + *offset += want; + } else { + want = 0; + } + return (int) (want / size); +} + +#define Write(buf, size, count) fake_write(buffer, offset, limit, (char *) buf, count, size) + #undef LITTLE_ENDIAN /* BSD/OS defines this as a feature macro */ #define HI(x) ((x) / 256) #define LO(x) ((x) % 256) #define LITTLE_ENDIAN(p, x) (p)[0] = LO(x), (p)[1] = HI(x) -#define WRITE_STRING(str) (fwrite(str, sizeof(char), strlen(str) + 1, fp) == strlen(str) + 1) +#define WRITE_STRING(str) (Write(str, sizeof(char), strlen(str) + 1) == strlen(str) + 1) static int -compute_offsets(char **Strings, int strmax, short *offsets) +compute_offsets(char **Strings, unsigned strmax, short *offsets) { size_t nextfree = 0; - int i; + unsigned i; for (i = 0; i < strmax; i++) { if (Strings[i] == ABSENT_STRING) { @@ -374,16 +506,17 @@ compute_offsets(char **Strings, int strmax, short *offsets) } else { offsets[i] = nextfree; nextfree += strlen(Strings[i]) + 1; - TRACE_OUT(("put Strings[%d]=%s(%d)", i, _nc_visbuf(Strings[i]), nextfree)); + TRACE_OUT(("put Strings[%d]=%s(%d)", (int) i, + _nc_visbuf(Strings[i]), (int) nextfree)); } } return nextfree; } static void -convert_shorts(unsigned char *buf, short *Numbers, int count) +convert_shorts(unsigned char *buf, short *Numbers, unsigned count) { - int i; + unsigned i; for (i = 0; i < count; i++) { if (Numbers[i] == ABSENT_NUMERIC) { /* HI/LO won't work */ buf[2 * i] = buf[2 * i + 1] = 0377; @@ -398,10 +531,68 @@ convert_shorts(unsigned char *buf, short *Numbers, int count) } #define even_boundary(value) \ - ((value) % 2 != 0 && fwrite(&zero, sizeof(char), 1, fp) != 1) + ((value) % 2 != 0 && Write(&zero, sizeof(char), 1) != 1) + +#if NCURSES_XNAMES +static unsigned +extended_Booleans(TERMTYPE *tp) +{ + unsigned short result = 0; + unsigned short i; + + for (i = 0; i < tp->ext_Booleans; ++i) { + if (tp->Booleans[BOOLCOUNT + i] == TRUE) + result = (i + 1); + } + return result; +} + +static unsigned +extended_Numbers(TERMTYPE *tp) +{ + unsigned short result = 0; + unsigned short i; + + for (i = 0; i < tp->ext_Numbers; ++i) { + if (tp->Numbers[NUMCOUNT + i] != ABSENT_NUMERIC) + result = (i + 1); + } + return result; +} + +static unsigned +extended_Strings(TERMTYPE *tp) +{ + unsigned short result = 0; + unsigned short i; + + for (i = 0; i < tp->ext_Strings; ++i) { + if (tp->Strings[STRCOUNT + i] != ABSENT_STRING) + result = (i + 1); + } + return result; +} + +/* + * _nc_align_termtype() will extend entries that are referenced in a use= + * clause - discard the unneeded data. + */ +static bool +extended_object(TERMTYPE *tp) +{ + bool result = FALSE; + + if (_nc_user_definable) { + result = ((extended_Booleans(tp) + + extended_Numbers(tp) + + extended_Strings(tp)) != 0); + } + return result; +} +#endif static int -write_object(FILE * fp, TERMTYPE * tp) +write_object(TERMTYPE *tp, char *buffer, unsigned *offset, unsigned limit) { char *namelist; size_t namelen, boolmax, nummax, strmax; @@ -460,9 +651,9 @@ write_object(FILE * fp, TERMTYPE * tp) LITTLE_ENDIAN(buf + 10, nextfree); /* write out the header */ - TRACE_OUT(("Header of %s @%ld", namelist, ftell(fp))); - if (fwrite(buf, 12, 1, fp) != 1 - || fwrite(namelist, sizeof(char), namelen, fp) != namelen) + TRACE_OUT(("Header of %s @%d", namelist, *offset)); + if (Write(buf, 12, 1) != 1 + || Write(namelist, sizeof(char), namelen) != namelen) return (ERR); for (i = 0; i < boolmax; i++) @@ -470,27 +661,27 @@ write_object(FILE * fp, TERMTYPE * tp) buf[i] = TRUE; else buf[i] = FALSE; - if (fwrite(buf, sizeof(char), boolmax, fp) != boolmax) + if (Write(buf, sizeof(char), boolmax) != boolmax) return (ERR); if (even_boundary(namelen + boolmax)) return (ERR); - TRACE_OUT(("Numerics begin at %04lx", ftell(fp))); + TRACE_OUT(("Numerics begin at %04x", *offset)); /* the numerics */ convert_shorts(buf, tp->Numbers, nummax); - if (fwrite(buf, 2, nummax, fp) != nummax) + if (Write(buf, 2, nummax) != nummax) return (ERR); - TRACE_OUT(("String offsets begin at %04lx", ftell(fp))); + TRACE_OUT(("String offsets begin at %04x", *offset)); /* the string offsets */ convert_shorts(buf, offsets, strmax); - if (fwrite(buf, 2, strmax, fp) != strmax) + if (Write(buf, 2, strmax) != strmax) return (ERR); - TRACE_OUT(("String table begins at %04lx", ftell(fp))); + TRACE_OUT(("String table begins at %04x", *offset)); /* the strings */ for (i = 0; i < strmax; i++) @@ -499,15 +690,23 @@ write_object(FILE * fp, TERMTYPE * tp) return (ERR); #if NCURSES_XNAMES - if (NUM_EXT_NAMES(tp)) { + if (extended_object(tp)) { unsigned extcnt = NUM_EXT_NAMES(tp); if (even_boundary(nextfree)) return (ERR); - nextfree = compute_offsets(tp->Strings + STRCOUNT, tp->ext_Strings, offsets); + nextfree = compute_offsets(tp->Strings + STRCOUNT, + tp->ext_Strings, + offsets); TRACE_OUT(("after extended string capabilities, nextfree=%d", nextfree)); - nextfree += compute_offsets(tp->ext_Names, extcnt, offsets + tp->ext_Strings); + + if (tp->ext_Strings >= SIZEOF(offsets)) + return (ERR); + + nextfree += compute_offsets(tp->ext_Names, + extcnt, + offsets + tp->ext_Strings); TRACE_OUT(("after extended capnames, nextfree=%d", nextfree)); strmax = tp->ext_Strings + extcnt; @@ -519,23 +718,23 @@ write_object(FILE * fp, TERMTYPE * tp) LITTLE_ENDIAN(buf + 4, tp->ext_Strings); LITTLE_ENDIAN(buf + 6, strmax); LITTLE_ENDIAN(buf + 8, nextfree); - TRACE_OUT(("WRITE extended-header @%ld", ftell(fp))); - if (fwrite(buf, 10, 1, fp) != 1) + TRACE_OUT(("WRITE extended-header @%d", *offset)); + if (Write(buf, 10, 1) != 1) return (ERR); - TRACE_OUT(("WRITE %d booleans @%ld", tp->ext_Booleans, ftell(fp))); + TRACE_OUT(("WRITE %d booleans @%d", tp->ext_Booleans, *offset)); if (tp->ext_Booleans - && fwrite(tp->Booleans + BOOLCOUNT, sizeof(char), - tp->ext_Booleans, fp) != tp->ext_Booleans) + && Write(tp->Booleans + BOOLCOUNT, sizeof(char), + tp->ext_Booleans) != tp->ext_Booleans) return (ERR); if (even_boundary(tp->ext_Booleans)) return (ERR); - TRACE_OUT(("WRITE %d numbers @%ld", tp->ext_Numbers, ftell(fp))); + TRACE_OUT(("WRITE %d numbers @%d", tp->ext_Numbers, *offset)); if (tp->ext_Numbers) { convert_shorts(buf, tp->Numbers + NUMCOUNT, tp->ext_Numbers); - if (fwrite(buf, 2, tp->ext_Numbers, fp) != tp->ext_Numbers) + if (Write(buf, 2, tp->ext_Numbers) != tp->ext_Numbers) return (ERR); } @@ -544,8 +743,8 @@ write_object(FILE * fp, TERMTYPE * tp) * in that order. */ convert_shorts(buf, offsets, strmax); - TRACE_OUT(("WRITE offsets @%ld", ftell(fp))); - if (fwrite(buf, 2, strmax, fp) != strmax) + TRACE_OUT(("WRITE offsets @%d", *offset)); + if (Write(buf, 2, strmax) != strmax) return (ERR); /* @@ -554,7 +753,7 @@ write_object(FILE * fp, TERMTYPE * tp) */ for (i = 0; i < tp->ext_Strings; i++) { if (VALID_STRING(tp->Strings[i + STRCOUNT])) { - TRACE_OUT(("WRITE ext_Strings[%d]=%s", i, + TRACE_OUT(("WRITE ext_Strings[%d]=%s", (int) i, _nc_visbuf(tp->Strings[i + STRCOUNT]))); if (!WRITE_STRING(tp->Strings[i + STRCOUNT])) return (ERR); @@ -565,7 +764,7 @@ write_object(FILE * fp, TERMTYPE * tp) * Write the extended names */ for (i = 0; i < extcnt; i++) { - TRACE_OUT(("WRITE ext_Names[%d]=%s", i, tp->ext_Names[i])); + TRACE_OUT(("WRITE ext_Names[%d]=%s", (int) i, tp->ext_Names[i])); if (!WRITE_STRING(tp->ext_Names[i])) return (ERR); } diff --git a/lib/libcurses/trace/lib_trace.c b/lib/libcurses/trace/lib_trace.c index 2089f0e4977..ed8d45dd9e7 100644 --- a/lib/libcurses/trace/lib_trace.c +++ b/lib/libcurses/trace/lib_trace.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_trace.c,v 1.7 2003/03/17 19:16:59 millert Exp $ */ +/* $OpenBSD: lib_trace.c,v 1.8 2010/01/12 23:22:06 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,10 +31,16 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* * lib_trace.c - Tracing/Debugging routines + * + * The _tracef() function is originally from pcurses (by Pavel Curtis) in 1982. + * pcurses allowed one to enable/disable tracing using traceon() and traceoff() + * functions. ncurses provides a trace() function which allows one to + * selectively enable or disable several tracing features. */ #include <curses.priv.h> @@ -42,32 +48,73 @@ #include <ctype.h> -MODULE_ID("$From: lib_trace.c,v 1.38 2000/12/10 03:02:45 tom Exp $") +MODULE_ID("$Id: lib_trace.c,v 1.8 2010/01/12 23:22:06 nicm Exp $") -NCURSES_EXPORT_VAR(unsigned) -_nc_tracing = 0; /* always define this */ +NCURSES_EXPORT_VAR(unsigned) _nc_tracing = 0; /* always define this */ #ifdef TRACE -NCURSES_EXPORT_VAR(const char *) -_nc_tputs_trace = ""; -NCURSES_EXPORT_VAR(long) -_nc_outchars = 0; - static FILE *tracefp; /* default to writing to stderr */ +#if USE_REENTRANT +NCURSES_EXPORT(const char *) +NCURSES_PUBLIC_VAR(_nc_tputs_trace) (void) +{ + return SP ? SP->_tputs_trace : _nc_prescreen._tputs_trace; +} +NCURSES_EXPORT(long) +NCURSES_PUBLIC_VAR(_nc_outchars) (void) +{ + return SP ? SP->_outchars : _nc_prescreen._outchars; +} +NCURSES_EXPORT(void) +_nc_set_tputs_trace(const char *s) +{ + if (SP) + SP->_tputs_trace = s; + else + _nc_prescreen._tputs_trace = s; +} +NCURSES_EXPORT(void) +_nc_count_outchars(long increment) +{ + if (SP) + SP->_outchars += increment; + else + _nc_prescreen._outchars += increment; +} +#else +NCURSES_EXPORT_VAR(const char *) _nc_tputs_trace = ""; +NCURSES_EXPORT_VAR(long) _nc_outchars = 0; +#endif + +#define TraceFP _nc_globals.trace_fp +#define TracePath _nc_globals.trace_fname +#define TraceLevel _nc_globals.trace_level NCURSES_EXPORT(void) -trace(const unsigned int tracelevel GCC_UNUSED) +trace(const unsigned int tracelevel) { - static bool been_here = FALSE; - static char my_name[] = "trace"; + if ((TraceFP == 0) && tracelevel) { + const char *mode = _nc_globals.init_trace ? "ab" : "wb"; - _nc_tracing = tracelevel; - if (!been_here && tracelevel) { - been_here = TRUE; + if (TracePath[0] == '\0') { + int size = sizeof(TracePath) - 12; + if (getcwd(TracePath, size) == 0) { + perror("curses: Can't get working directory"); + exit(EXIT_FAILURE); + } + TracePath[size] = '\0'; + assert(strlen(TracePath) <= size); + strlcat(TracePath, "/trace", sizeof(TracePath)); + if (_nc_is_dir_path(TracePath)) { + strlcat(TracePath, ".log", sizeof(TracePath)); + } + } - if (_nc_access(my_name, W_OK) < 0 - || (tracefp = fopen(my_name, "wb")) == 0) { - perror("curses: Can't open 'trace' file: "); + _nc_globals.init_trace = TRUE; + _nc_tracing = tracelevel; + if (_nc_access(TracePath, W_OK) < 0 + || (TraceFP = fopen(TracePath, mode)) == 0) { + perror("curses: Can't open 'trace' file"); exit(EXIT_FAILURE); } /* Try to set line-buffered mode, or (failing that) unbuffered, @@ -75,100 +122,46 @@ trace(const unsigned int tracelevel GCC_UNUSED) * end of each line. This is useful in case the program dies. */ #if HAVE_SETVBUF /* ANSI */ - (void) setvbuf(tracefp, (char *) 0, _IOLBF, 0); + (void) setvbuf(TraceFP, (char *) 0, _IOLBF, 0); #elif HAVE_SETBUF /* POSIX */ - (void) setbuffer(tracefp, (char *) 0); -#endif - _tracef("TRACING NCURSES version %s", curses_version()); - } -} -#endif - -NCURSES_EXPORT(const char *) -_nc_visbuf2(int bufnum, const char *buf) -/* visibilize a given string */ -{ - size_t vbsize; - char *vbuf; - char *tp; - int c; - - if (buf == 0) - return ("(null)"); - if (buf == CANCELLED_STRING) - return ("(cancelled)"); - - vbsize = (strlen(buf) * 4) + 5; -#ifdef TRACE - tp = vbuf = _nc_trace_buf(bufnum, vbsize); -#else - { - static char *mybuf[2]; - mybuf[bufnum] = _nc_doalloc(mybuf[bufnum], vbsize); - tp = vbuf = mybuf[bufnum]; - } + (void) setbuffer(TraceFP, (char *) 0); #endif - *tp++ = '"'; - while ((c = *buf++) != '\0') { - if (c == '"') { - *tp++ = '\\'; - *tp++ = '"'; - } else if (is7bits(c) && (isgraph(c) || c == ' ')) { - *tp++ = c; - } else if (c == '\n') { - *tp++ = '\\'; - *tp++ = 'n'; - } else if (c == '\r') { - *tp++ = '\\'; - *tp++ = 'r'; - } else if (c == '\b') { - *tp++ = '\\'; - *tp++ = 'b'; - } else if (c == '\033') { - *tp++ = '\\'; - *tp++ = 'e'; - } else if (is7bits(c) && iscntrl(c)) { - *tp++ = '\\'; - *tp++ = '^'; - *tp++ = '@' + c; - } else { - snprintf(tp, vbsize - (tp - vbuf), "\\%03o", CharOf(c)); - tp += strlen(tp); + _tracef("TRACING NCURSES version %s.%d (tracelevel=%#x)", + NCURSES_VERSION, + NCURSES_VERSION_PATCH, + tracelevel); + } else if (tracelevel == 0) { + if (TraceFP != 0) { + fclose(TraceFP); + TraceFP = 0; } + _nc_tracing = tracelevel; + } else if (_nc_tracing != tracelevel) { + _nc_tracing = tracelevel; + _tracef("tracelevel=%#x", tracelevel); } - *tp++ = '"'; - *tp++ = '\0'; - return (vbuf); -} - -NCURSES_EXPORT(const char *) -_nc_visbuf(const char *buf) -{ - return _nc_visbuf2(0, buf); } -#ifdef TRACE -NCURSES_EXPORT(void) -_tracef(const char *fmt,...) +static void +_nc_va_tracef(const char *fmt, va_list ap) { static const char Called[] = T_CALLED(""); static const char Return[] = T_RETURN(""); - static int level; - va_list ap; + bool before = FALSE; bool after = FALSE; - int doit = _nc_tracing; + unsigned doit = _nc_tracing; int save_err = errno; if (strlen(fmt) >= sizeof(Called) - 1) { if (!strncmp(fmt, Called, sizeof(Called) - 1)) { before = TRUE; - level++; + TraceLevel++; } else if (!strncmp(fmt, Return, sizeof(Return) - 1)) { after = TRUE; } if (before || after) { - if ((level <= 1) + if ((TraceLevel <= 1) || (doit & TRACE_ICALLS) != 0) doit &= (TRACE_CALLS | TRACE_CCALLS); else @@ -177,25 +170,57 @@ _tracef(const char *fmt,...) } if (doit != 0) { - if (tracefp == 0) - tracefp = stderr; + if (TraceFP == 0) + TraceFP = stderr; +#ifdef USE_PTHREADS + /* + * TRACE_ICALLS is "really" needed to show normal use with threaded + * applications, since anything can be running during a napms(), + * making it appear in the hierarchical trace as it other functions + * are being called. + * + * Rather than add the complication of a per-thread stack, just + * show the thread-id in each line of the trace. + */ +# if USE_WEAK_SYMBOLS + if ((pthread_self)) +# endif + fprintf(TraceFP, "%#lx:", (long) (void *) pthread_self()); +#endif if (before || after) { int n; - for (n = 1; n < level; n++) - fputs("+ ", tracefp); + for (n = 1; n < TraceLevel; n++) + fputs("+ ", TraceFP); } - va_start(ap, fmt); - vfprintf(tracefp, fmt, ap); - fputc('\n', tracefp); - va_end(ap); - fflush(tracefp); + vfprintf(TraceFP, fmt, ap); + fputc('\n', TraceFP); + fflush(TraceFP); } - if (after && level) - level--; + if (after && TraceLevel) + TraceLevel--; + errno = save_err; } +NCURSES_EXPORT(void) +_tracef(const char *fmt,...) +{ + va_list ap; + + va_start(ap, fmt); + _nc_va_tracef(fmt, ap); + va_end(ap); +} + +/* Trace 'bool' return-values */ +NCURSES_EXPORT(NCURSES_BOOL) +_nc_retrace_bool(NCURSES_BOOL code) +{ + T((T_RETURN("%s"), code ? "TRUE" : "FALSE")); + return code; +} + /* Trace 'int' return-values */ NCURSES_EXPORT(int) _nc_retrace_int(int code) @@ -204,6 +229,14 @@ _nc_retrace_int(int code) return code; } +/* Trace 'unsigned' return-values */ +NCURSES_EXPORT(unsigned) +_nc_retrace_unsigned(unsigned code) +{ + T((T_RETURN("%#x"), code)); + return code; +} + /* Trace 'char*' return-values */ NCURSES_EXPORT(char *) _nc_retrace_ptr(char *code) @@ -212,6 +245,38 @@ _nc_retrace_ptr(char *code) return code; } +/* Trace 'const char*' return-values */ +NCURSES_EXPORT(const char *) +_nc_retrace_cptr(const char *code) +{ + T((T_RETURN("%s"), _nc_visbuf(code))); + return code; +} + +/* Trace 'NCURSES_CONST void*' return-values */ +NCURSES_EXPORT(NCURSES_CONST void *) +_nc_retrace_cvoid_ptr(NCURSES_CONST void *code) +{ + T((T_RETURN("%p"), code)); + return code; +} + +/* Trace 'void*' return-values */ +NCURSES_EXPORT(void *) +_nc_retrace_void_ptr(void *code) +{ + T((T_RETURN("%p"), code)); + return code; +} + +/* Trace 'SCREEN *' return-values */ +NCURSES_EXPORT(SCREEN *) +_nc_retrace_sp(SCREEN *code) +{ + T((T_RETURN("%p"), code)); + return code; +} + /* Trace 'WINDOW *' return-values */ NCURSES_EXPORT(WINDOW *) _nc_retrace_win(WINDOW *code) @@ -219,4 +284,53 @@ _nc_retrace_win(WINDOW *code) T((T_RETURN("%p"), code)); return code; } + +#if USE_REENTRANT +/* + * Check if the given trace-mask is enabled. + * + * This function may be called from within one of the functions that fills + * in parameters for _tracef(), but in that case we do not want to lock the + * mutex, since it is already locked. + */ +NCURSES_EXPORT(int) +_nc_use_tracef(unsigned mask) +{ + bool result = FALSE; + + _nc_lock_global(tst_tracef); + if (!_nc_globals.nested_tracef++) { + if ((result = (_nc_tracing & (mask))) != 0 + && _nc_try_global(tracef) == 0) { + /* we will call _nc_locked_tracef(), no nesting so far */ + } else { + /* we will not call _nc_locked_tracef() */ + _nc_globals.nested_tracef = 0; + } + } else { + /* we may call _nc_locked_tracef(), but with nested_tracef > 0 */ + result = (_nc_tracing & (mask)); + } + _nc_unlock_global(tst_tracef); + return result; +} + +/* + * We call this if _nc_use_tracef() returns true, which means we must unlock + * the tracef mutex. + */ +NCURSES_EXPORT(void) +_nc_locked_tracef(const char *fmt,...) +{ + va_list ap; + + va_start(ap, fmt); + _nc_va_tracef(fmt, ap); + va_end(ap); + + if (--(_nc_globals.nested_tracef) == 0) + _nc_unlock_global(tracef); +} +#endif /* USE_REENTRANT */ + #endif /* TRACE */ diff --git a/lib/libcurses/trace/lib_traceatr.c b/lib/libcurses/trace/lib_traceatr.c index e1b813bc3d9..34b65f3d7eb 100644 --- a/lib/libcurses/trace/lib_traceatr.c +++ b/lib/libcurses/trace/lib_traceatr.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_traceatr.c,v 1.5 2003/03/18 16:55:54 millert Exp $ */ +/* $OpenBSD: lib_traceatr.c,v 1.6 2010/01/12 23:22:07 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,7 +29,8 @@ ****************************************************************************/ /**************************************************************************** - * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * Author: Thomas Dickey 1996-on * + * and: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * ****************************************************************************/ @@ -40,16 +41,42 @@ #include <curses.priv.h> #include <term.h> /* acs_chars */ -MODULE_ID("$From: lib_traceatr.c,v 1.32 2000/12/10 03:02:45 tom Exp $") +MODULE_ID("$Id: lib_traceatr.c,v 1.6 2010/01/12 23:22:07 nicm Exp $") -#define COLOR_OF(c) (c < 0 || c > 7 ? "default" : colors[c].name) +#define COLOR_OF(c) ((c < 0) ? "default" : (c > 7 ? color_of(c) : colors[c].name)) #ifdef TRACE + +static const char l_brace[] = StringOf(L_BRACE); +static const char r_brace[] = StringOf(R_BRACE); + +#ifndef USE_TERMLIB + +#define my_buffer _nc_globals.traceatr_color_buf +#define my_select _nc_globals.traceatr_color_sel +#define my_cached _nc_globals.traceatr_color_last + +static char * +color_of(int c) +{ + if (c != my_cached) { + my_cached = c; + my_select = !my_select; + if (c == COLOR_DEFAULT) + strlcpy(my_buffer[my_select], "default", _nc_globals_traceatr_color_buf_size); + else + snprintf(my_buffer[my_select], _nc_globals_traceatr_color_buf_size, "color%d", c); + } + return my_buffer[my_select]; +} + +#undef my_buffer +#undef my_select +#endif /* !USE_TERMLIB */ + NCURSES_EXPORT(char *) -_traceattr2(int bufnum, attr_t newmode) +_traceattr2(int bufnum, chtype newmode) { - char *buf = _nc_trace_buf(bufnum, BUFSIZ); - char *tmp = buf; static const struct { unsigned int val; const char *name; @@ -70,7 +97,9 @@ _traceattr2(int bufnum, attr_t newmode) { A_COLOR, "A_COLOR" }, /* *INDENT-ON* */ - }, + } +#ifndef USE_TERMLIB + , colors[] = { /* *INDENT-OFF* */ @@ -84,46 +113,58 @@ _traceattr2(int bufnum, attr_t newmode) { COLOR_WHITE, "COLOR_WHITE" }, /* *INDENT-ON* */ - }; + } +#endif /* !USE_TERMLIB */ + ; size_t n; - unsigned save_nc_tracing = _nc_tracing; - _nc_tracing = 0; - - *tmp++ = '{'; - *tmp = '\0'; - - for (n = 0; n < SIZEOF(names); n++) { - if ((newmode & names[n].val) != 0) { - if (buf[1] != '\0') - strlcat(tmp, "|", BUFSIZ - (tmp - buf)); - strlcat(tmp, names[n].name, BUFSIZ - (tmp - buf)); - tmp += strlen(tmp); - - if (names[n].val == A_COLOR) { - short pairnum = PAIR_NUMBER(newmode); - short fg, bg; - - if (pair_content(pairnum, &fg, &bg) == OK) - (void) snprintf(tmp, BUFSIZ - (tmp - buf), - "{%d = {%s, %s}}", - pairnum, - COLOR_OF(fg), - COLOR_OF(bg) - ); - else - (void) snprintf(tmp, BUFSIZ - (tmp - buf), "{%d}", pairnum); + char temp[80]; + char *result = _nc_trace_buf(bufnum, BUFSIZ); + + if (result != 0) { + unsigned save_nc_tracing = _nc_tracing; + + _nc_tracing = 0; + + strlcpy(result, l_brace, BUFSIZ); + + for (n = 0; n < SIZEOF(names); n++) { + if ((newmode & names[n].val) != 0) { + if (result[1] != '\0') + result = _nc_trace_bufcat(bufnum, "|"); + result = _nc_trace_bufcat(bufnum, names[n].name); + + if (names[n].val == A_COLOR) { + short pairnum = PAIR_NUMBER(newmode); +#ifdef USE_TERMLIB + /* pair_content lives in libncurses */ + (void) snprintf(temp, sizeof(temp), "{%d}", pairnum); +#else + short fg, bg; + + if (pair_content(pairnum, &fg, &bg) == OK) { + (void) snprintf(temp, sizeof(temp), + "{%d = {%s, %s}}", + pairnum, + COLOR_OF(fg), + COLOR_OF(bg)); + } else { + (void) snprintf(temp, sizeof(temp), "{%d}", pairnum); + } +#endif + result = _nc_trace_bufcat(bufnum, temp); + } } } - } - if (AttrOf(newmode) == A_NORMAL) { - if (buf[1] != '\0') - strlcat(tmp, "|", BUFSIZ - (tmp - buf)); - strlcat(tmp, "A_NORMAL", BUFSIZ - (tmp - buf)); - } + if (ChAttrOf(newmode) == A_NORMAL) { + if (result != 0 && result[1] != '\0') + (void) _nc_trace_bufcat(bufnum, "|"); + (void) _nc_trace_bufcat(bufnum, "A_NORMAL"); + } - _nc_tracing = save_nc_tracing; - strlcat(buf, "}", BUFSIZ); - return (buf); + _nc_tracing = save_nc_tracing; + result = _nc_trace_bufcat(bufnum, r_brace); + } + return result; } NCURSES_EXPORT(char *) @@ -140,105 +181,180 @@ _nc_retrace_attr_t(attr_t code) return code; } -NCURSES_EXPORT(char *) -_tracechtype2(int bufnum, chtype ch) +const char * +_nc_altcharset_name(attr_t attr, chtype ch) { - char *buf = _nc_trace_buf(bufnum, BUFSIZ); - char *found = 0; + typedef struct { + unsigned int val; + const char *name; + } ALT_NAMES; + static const ALT_NAMES names[] = + { + {'l', "ACS_ULCORNER"}, /* upper left corner */ + {'m', "ACS_LLCORNER"}, /* lower left corner */ + {'k', "ACS_URCORNER"}, /* upper right corner */ + {'j', "ACS_LRCORNER"}, /* lower right corner */ + {'t', "ACS_LTEE"}, /* tee pointing right */ + {'u', "ACS_RTEE"}, /* tee pointing left */ + {'v', "ACS_BTEE"}, /* tee pointing up */ + {'w', "ACS_TTEE"}, /* tee pointing down */ + {'q', "ACS_HLINE"}, /* horizontal line */ + {'x', "ACS_VLINE"}, /* vertical line */ + {'n', "ACS_PLUS"}, /* large plus or crossover */ + {'o', "ACS_S1"}, /* scan line 1 */ + {'s', "ACS_S9"}, /* scan line 9 */ + {'`', "ACS_DIAMOND"}, /* diamond */ + {'a', "ACS_CKBOARD"}, /* checker board (stipple) */ + {'f', "ACS_DEGREE"}, /* degree symbol */ + {'g', "ACS_PLMINUS"}, /* plus/minus */ + {'~', "ACS_BULLET"}, /* bullet */ + {',', "ACS_LARROW"}, /* arrow pointing left */ + {'+', "ACS_RARROW"}, /* arrow pointing right */ + {'.', "ACS_DARROW"}, /* arrow pointing down */ + {'-', "ACS_UARROW"}, /* arrow pointing up */ + {'h', "ACS_BOARD"}, /* board of squares */ + {'i', "ACS_LANTERN"}, /* lantern symbol */ + {'0', "ACS_BLOCK"}, /* solid square block */ + {'p', "ACS_S3"}, /* scan line 3 */ + {'r', "ACS_S7"}, /* scan line 7 */ + {'y', "ACS_LEQUAL"}, /* less/equal */ + {'z', "ACS_GEQUAL"}, /* greater/equal */ + {'{', "ACS_PI"}, /* Pi */ + {'|', "ACS_NEQUAL"}, /* not equal */ + {'}', "ACS_STERLING"}, /* UK pound sign */ + {'\0', (char *) 0} + }; - buf[0] = '{'; - buf[1] = '\0'; - if (ch & A_ALTCHARSET) { + const char *result = 0; + + if ((attr & A_ALTCHARSET) && (acs_chars != 0)) { char *cp; - static const struct { - unsigned int val; - const char *name; - } names[] = - { - /* *INDENT-OFF* */ - { 'l', "ACS_ULCORNER" }, /* upper left corner */ - { 'm', "ACS_LLCORNER" }, /* lower left corner */ - { 'k', "ACS_URCORNER" }, /* upper right corner */ - { 'j', "ACS_LRCORNER" }, /* lower right corner */ - { 't', "ACS_LTEE" }, /* tee pointing right */ - { 'u', "ACS_RTEE" }, /* tee pointing left */ - { 'v', "ACS_BTEE" }, /* tee pointing up */ - { 'w', "ACS_TTEE" }, /* tee pointing down */ - { 'q', "ACS_HLINE" }, /* horizontal line */ - { 'x', "ACS_VLINE" }, /* vertical line */ - { 'n', "ACS_PLUS" }, /* large plus or crossover */ - { 'o', "ACS_S1" }, /* scan line 1 */ - { 's', "ACS_S9" }, /* scan line 9 */ - { '`', "ACS_DIAMOND" }, /* diamond */ - { 'a', "ACS_CKBOARD" }, /* checker board (stipple) */ - { 'f', "ACS_DEGREE" }, /* degree symbol */ - { 'g', "ACS_PLMINUS" }, /* plus/minus */ - { '~', "ACS_BULLET" }, /* bullet */ - { ',', "ACS_LARROW" }, /* arrow pointing left */ - { '+', "ACS_RARROW" }, /* arrow pointing right */ - { '.', "ACS_DARROW" }, /* arrow pointing down */ - { '-', "ACS_UARROW" }, /* arrow pointing up */ - { 'h', "ACS_BOARD" }, /* board of squares */ - { 'i', "ACS_LANTERN" }, /* lantern symbol */ - { '0', "ACS_BLOCK" }, /* solid square block */ - { 'p', "ACS_S3" }, /* scan line 3 */ - { 'r', "ACS_S7" }, /* scan line 7 */ - { 'y', "ACS_LEQUAL" }, /* less/equal */ - { 'z', "ACS_GEQUAL" }, /* greater/equal */ - { '{', "ACS_PI" }, /* Pi */ - { '|', "ACS_NEQUAL" }, /* not equal */ - { '}', "ACS_STERLING" }, /* UK pound sign */ - { '\0', (char *) 0 } - /* *INDENT-OFF* */ - }, - *sp; + char *found = 0; + const ALT_NAMES *sp; for (cp = acs_chars; cp[0] && cp[1]; cp += 2) { - if (TextOf(cp[1]) == TextOf(ch)) { + if (ChCharOf(cp[1]) == ChCharOf(ch)) { found = cp; /* don't exit from loop - there may be redefinitions */ } } if (found != 0) { - ch = TextOf(*found); + ch = ChCharOf(*found); for (sp = names; sp->val; sp++) if (sp->val == ch) { - (void) strlcat(buf, sp->name, BUFSIZ); - ch &= ~A_ALTCHARSET; + result = sp->name; break; } } } + return result; +} + +NCURSES_EXPORT(char *) +_tracechtype2(int bufnum, chtype ch) +{ + const char *found; + char *result = _nc_trace_buf(bufnum, BUFSIZ); - if (found == 0) - (void) strlcat(buf, _tracechar(TextOf(ch)), BUFSIZ); + if (result != 0) { + strlcpy(result, l_brace, BUFSIZ); + if ((found = _nc_altcharset_name(ChAttrOf(ch), ch)) != 0) { + (void) _nc_trace_bufcat(bufnum, found); + } else + (void) _nc_trace_bufcat(bufnum, _nc_tracechar(SP, (int) ChCharOf(ch))); - if (AttrOf(ch) != A_NORMAL) - (void) snprintf(buf + strlen(buf), BUFSIZ - strlen(buf), " | %s", - _traceattr2(bufnum + 20, AttrOf(ch))); + if (ChAttrOf(ch) != A_NORMAL) { + (void) _nc_trace_bufcat(bufnum, " | "); + (void) _nc_trace_bufcat(bufnum, + _traceattr2(bufnum + 20, ChAttrOf(ch))); + } - strlcat(buf, "}", BUFSIZ); - return (buf); + result = _nc_trace_bufcat(bufnum, r_brace); + } + return result; } NCURSES_EXPORT(char *) -_tracechtype (chtype ch) +_tracechtype(chtype ch) { return _tracechtype2(0, ch); } /* Trace 'chtype' return-values */ -NCURSES_EXPORT(attr_t) -_nc_retrace_chtype (attr_t code) +NCURSES_EXPORT(chtype) +_nc_retrace_chtype(chtype code) { T((T_RETURN("%s"), _tracechtype(code))); return code; } -#else -extern NCURSES_EXPORT(void) _nc_lib_traceatr (void); -NCURSES_EXPORT(void) _nc_lib_traceatr (void) +#if USE_WIDEC_SUPPORT +NCURSES_EXPORT(char *) +_tracecchar_t2(int bufnum, const cchar_t *ch) { + char *result = _nc_trace_buf(bufnum, BUFSIZ); + attr_t attr; + const char *found; + + if (result != 0) { + strlcpy(result, l_brace, BUFSIZ); + if (ch != 0) { + attr = AttrOfD(ch); + if ((found = _nc_altcharset_name(attr, (chtype) CharOfD(ch))) != 0) { + (void) _nc_trace_bufcat(bufnum, found); + attr &= ~A_ALTCHARSET; + } else if (isWidecExt(CHDEREF(ch))) { + (void) _nc_trace_bufcat(bufnum, "{NAC}"); + attr &= ~A_CHARTEXT; + } else { + PUTC_DATA; + int n; + + PUTC_INIT; + (void) _nc_trace_bufcat(bufnum, "{ "); + for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) { + PUTC_ch = ch->chars[PUTC_i]; + if (PUTC_ch == L'\0') + break; + PUTC_n = wcrtomb(PUTC_buf, ch->chars[PUTC_i], &PUT_st); + if (PUTC_n <= 0) { + if (PUTC_ch != L'\0') { + /* it could not be a multibyte sequence */ + (void) _nc_trace_bufcat(bufnum, + _nc_tracechar(SP, + UChar(ch->chars[PUTC_i]))); + } + break; + } + for (n = 0; n < PUTC_n; n++) { + if (n) + (void) _nc_trace_bufcat(bufnum, ", "); + (void) _nc_trace_bufcat(bufnum, + _nc_tracechar(SP, + UChar(PUTC_buf[n]))); + } + } + (void) _nc_trace_bufcat(bufnum, " }"); + } + if (attr != A_NORMAL) { + (void) _nc_trace_bufcat(bufnum, " | "); + (void) _nc_trace_bufcat(bufnum, _traceattr2(bufnum + 20, attr)); + } + } + + result = _nc_trace_bufcat(bufnum, r_brace); + } + return result; } + +NCURSES_EXPORT(char *) +_tracecchar_t(const cchar_t *ch) +{ + return _tracecchar_t2(0, ch); +} +#endif + +#else +EMPTY_MODULE(_nc_lib_traceatr) #endif /* TRACE */ diff --git a/lib/libcurses/trace/lib_tracebits.c b/lib/libcurses/trace/lib_tracebits.c index b1ad17da12c..4905807f11f 100644 --- a/lib/libcurses/trace/lib_tracebits.c +++ b/lib/libcurses/trace/lib_tracebits.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_tracebits.c,v 1.9 2003/03/18 16:55:54 millert Exp $ */ +/* $OpenBSD: lib_tracebits.c,v 1.10 2010/01/12 23:22:07 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,12 +31,13 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ #include <curses.priv.h> #include <term.h> /* cur_term */ -MODULE_ID("$From: lib_tracebits.c,v 1.9 2000/12/10 03:02:45 tom Exp $") +MODULE_ID("$Id: lib_tracebits.c,v 1.10 2010/01/12 23:22:07 nicm Exp $") #if SVR4_TERMIO && !defined(_POSIX_SOURCE) #define _POSIX_SOURCE @@ -54,10 +55,27 @@ MODULE_ID("$From: lib_tracebits.c,v 1.9 2000/12/10 03:02:45 tom Exp $") #ifndef TOSTOP #define TOSTOP 0 #endif + #ifndef IEXTEN #define IEXTEN 0 #endif +#ifndef ONLCR +#define ONLCR 0 +#endif + +#ifndef OCRNL +#define OCRNL 0 +#endif + +#ifndef ONOCR +#define ONOCR 0 +#endif + +#ifndef ONLRET +#define ONLRET 0 +#endif + #ifdef TRACE typedef struct { @@ -84,7 +102,7 @@ lookup_bits(char *buf, size_t bufsize, const BITNAMES * table, const char *label } NCURSES_EXPORT(char *) -_nc_tracebits(void) +_nc_trace_ttymode(TTY * tty) /* describe the state of the terminal control bits exactly */ { char *buf; @@ -109,8 +127,13 @@ _nc_tracebits(void) }, oflags[] = { {OPOST, "OPOST"}, + {OFLAGS_TABS, "XTABS"}, + {ONLCR, "ONLCR"}, + {OCRNL, "OCRNL"}, + {ONOCR, "ONOCR"}, + {ONLRET, "ONLRET"}, {0, NULL} -#define ALLOUT (OPOST) +#define ALLOUT (OPOST|OFLAGS_TABS|ONLCR|OCRNL|ONOCR|ONLRET) }, cflags[] = { {CLOCAL, "CLOCAL"}, @@ -140,60 +163,55 @@ _nc_tracebits(void) }; bufsize = 8 + sizeof(iflags) + 8 + sizeof(oflags) + 8 + sizeof(cflags) + - 8 + sizeof(lflags) + 8; + 8 + sizeof(lflags) + 8; buf = _nc_trace_buf(0, bufsize); - if (cur_term->Nttyb.c_iflag & ALLIN) - lookup_bits(buf, bufsize, iflags, "iflags", cur_term->Nttyb.c_iflag); + if (buf != 0) { + + if (tty->c_iflag & ALLIN) + lookup_bits(buf, bufsize, iflags, "iflags", tty->c_iflag); - if (cur_term->Nttyb.c_oflag & ALLOUT) - lookup_bits(buf, bufsize, oflags, "oflags", cur_term->Nttyb.c_oflag); + if (tty->c_oflag & ALLOUT) + lookup_bits(buf, bufsize, oflags, "oflags", tty->c_oflag); - if (cur_term->Nttyb.c_cflag & ALLCTRL) - lookup_bits(buf, bufsize, cflags, "cflags", cur_term->Nttyb.c_cflag); + if (tty->c_cflag & ALLCTRL) + lookup_bits(buf, bufsize, cflags, "cflags", tty->c_cflag); #if defined(CS5) && defined(CS8) - { - static struct { - char *name; - int value; - } csizes[] = { - { - "CS5 ", CS5 - }, + { + static struct { + int value; + const char *name; + } csizes[] = { +#define CS_DATA(name) { name, #name " " } + CS_DATA(CS5), #ifdef CS6 - { - "CS6 ", CS6 - }, + CS_DATA(CS6), #endif #ifdef CS7 - { - "CS7 ", CS7 - }, -#endif - { - "CS8 ", CS8 - }, - }; - char *result = "CSIZE? "; - int value = (cur_term->Nttyb.c_cflag & CSIZE); - unsigned n; - - if (value != 0) { - for (n = 0; n < SIZEOF(csizes); n++) { - if (csizes[n].value == value) { - result = csizes[n].name; - break; + CS_DATA(CS7), +#endif + CS_DATA(CS8), + }; + const char *result = "CSIZE? "; + int value = (tty->c_cflag & CSIZE); + unsigned n; + + if (value != 0) { + for (n = 0; n < SIZEOF(csizes); n++) { + if (csizes[n].value == value) { + result = csizes[n].name; + break; + } } } + strlcat(buf, result, bufsize); } - strlcat(buf, result, bufsize); - } #endif - if (cur_term->Nttyb.c_lflag & ALLLOCAL) - lookup_bits(buf, bufsize, lflags, "lflags", cur_term->Nttyb.c_lflag); - + if (tty->c_lflag & ALLLOCAL) + lookup_bits(buf, bufsize, lflags, "lflags", tty->c_lflag); + } #else /* reference: ttcompat(4M) on SunOS 4.1 */ #ifndef EVENP @@ -230,18 +248,24 @@ _nc_tracebits(void) buf = _nc_trace_buf(0, 8 + sizeof(cflags)); - - if (cur_term->Nttyb.sg_flags & ALLCTRL) { - lookup_bits(buf, bufsize, cflags, "cflags", cur_term->Nttyb.sg_flags); + if (buf != 0) { + if (tty->sg_flags & ALLCTRL) { + lookup_bits(buf, cflags, "cflags", tty->sg_flags); + } } #endif return (buf); } + +NCURSES_EXPORT(char *) +_nc_tracebits(void) +{ + return _nc_trace_ttymode(&(cur_term->Nttyb)); +} #else NCURSES_EXPORT(char *) _nc_tracebits(void) { - static char tmp[] = ""; - return tmp; + return NULL; } #endif /* TRACE */ diff --git a/lib/libcurses/trace/lib_tracechr.c b/lib/libcurses/trace/lib_tracechr.c index f69a9c59a1f..e909ab79262 100644 --- a/lib/libcurses/trace/lib_tracechr.c +++ b/lib/libcurses/trace/lib_tracechr.c @@ -1,5 +1,7 @@ +/* $OpenBSD: lib_tracechr.c,v 1.5 2010/01/12 23:22:07 nicm Exp $ */ + /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -36,23 +39,49 @@ */ #include <curses.priv.h> -MODULE_ID("$From: lib_tracechr.c,v 1.4 2000/12/10 03:02:45 tom Exp $") +#include <ctype.h> + +MODULE_ID("$Id: lib_tracechr.c,v 1.5 2010/01/12 23:22:07 nicm Exp $") #ifdef TRACE + NCURSES_EXPORT(char *) -_tracechar(const unsigned char ch) +_nc_tracechar(SCREEN *sp, int ch) { - static char crep[20]; - (void) snprintf(crep, sizeof(crep), "'%s' = 0x%02x", unctrl(ch), - (unsigned) ch); - return (crep); + NCURSES_CONST char *name; + char *MyBuffer = ((sp != 0) + ? sp->tracechr_buf + : _nc_globals.tracechr_buf); + size_t len = ((sp != 0) + ? _nc_screen_tracechr_buf_size + : _nc_globals_traceatr_color_buf_size); + + if (ch > KEY_MIN || ch < 0) { + name = _nc_keyname(sp, ch); + if (name == 0 || *name == '\0') + name = "NULL"; + (void) snprintf(MyBuffer, len, "'%.30s' = %#03o", name, ch); + } else if (!is8bits(ch) || !isprint(UChar(ch))) { + /* + * workaround for glibc bug: + * sprintf changes the result from unctrl() to an empty string if it + * does not correspond to a valid multibyte sequence. + */ + (void) snprintf(MyBuffer, len, "%#03o", ch); + } else { + name = _nc_unctrl(sp, (chtype) ch); + if (name == 0 || *name == 0) + name = "null"; /* shouldn't happen */ + (void) snprintf(MyBuffer, len, "'%.30s' = %#03o", name, ch); + } + return (MyBuffer); } -#else -extern -NCURSES_EXPORT(void) -_nc_lib_tracechr(void); -NCURSES_EXPORT(void) -_nc_lib_tracechr(void) + +NCURSES_EXPORT(char *) +_tracechar(int ch) { + return _nc_tracechar(SP, ch); } +#else +EMPTY_MODULE(_nc_lib_tracechr) #endif diff --git a/lib/libcurses/trace/lib_tracedmp.c b/lib/libcurses/trace/lib_tracedmp.c index 4e557d65974..71759dc21db 100644 --- a/lib/libcurses/trace/lib_tracedmp.c +++ b/lib/libcurses/trace/lib_tracedmp.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_tracedmp.c,v 1.3 2003/03/17 19:16:59 millert Exp $ */ +/* $OpenBSD: lib_tracedmp.c,v 1.4 2010/01/12 23:22:07 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,7 +29,8 @@ ****************************************************************************/ /**************************************************************************** - * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * Author: Thomas E. Dickey 1996-on * + * and: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * ****************************************************************************/ @@ -38,94 +39,148 @@ */ #include <curses.priv.h> +#include <ctype.h> -MODULE_ID("$From: lib_tracedmp.c,v 1.16 2000/12/10 03:02:45 tom Exp $") +MODULE_ID("$Id: lib_tracedmp.c,v 1.4 2010/01/12 23:22:07 nicm Exp $") #ifdef TRACE + +#define my_buffer _nc_globals.tracedmp_buf +#define my_length _nc_globals.tracedmp_used + NCURSES_EXPORT(void) _tracedump(const char *name, WINDOW *win) { int i, j, n, width; /* compute narrowest possible display width */ - for (width = i = 0; i <= win->_maxy; i++) { + for (width = i = 0; i <= win->_maxy; ++i) { n = 0; - for (j = 0; j <= win->_maxx; j++) - if (win->_line[i].text[j] != ' ') + for (j = 0; j <= win->_maxx; ++j) { + if (CharOf(win->_line[i].text[j]) != L(' ') + || AttrOf(win->_line[i].text[j]) != A_NORMAL + || GetPair(win->_line[i].text[j]) != 0) { n = j; + } + } if (n > width) width = n; } if (width < win->_maxx) ++width; + if (++width + 1 > (int) my_length) { + my_length = 2 * (width + 1); + my_buffer = typeRealloc(char, my_length, my_buffer); + } - for (n = 0; n <= win->_maxy; n++) { - char buf[BUFSIZ], *ep; + for (n = 0; n <= win->_maxy; ++n) { + char *ep = my_buffer; bool haveattrs, havecolors; - /* dump A_CHARTEXT part */ - (void) snprintf(buf, sizeof(buf), "%s[%2d] %3d%3d ='", - name, n, - win->_line[n].firstchar, - win->_line[n].lastchar); - ep = buf + strlen(buf); - for (j = 0; j <= width; j++) { - ep[j] = TextOf(win->_line[n].text[j]); - if (ep[j] == 0) - ep[j] = '.'; + /* + * Dump A_CHARTEXT part. It is more important to make the grid line up + * in the trace file than to represent control- and wide-characters, so + * we map those to '.' and '?' respectively. + */ + for (j = 0; j < width; ++j) { + chtype test = CharOf(win->_line[n].text[j]); + ep[j] = (char) ((UChar(test) == test +#if USE_WIDEC_SUPPORT + && (win->_line[n].text[j].chars[1] == 0) +#endif + ) + ? (iscntrl(UChar(test)) + ? '.' + : UChar(test)) + : '?'); } - ep[j] = '\''; - ep[j + 1] = '\0'; - _tracef("%s", buf); + ep[j] = '\0'; + _tracef("%s[%2d] %3ld%3ld ='%s'", + name, n, + (long) win->_line[n].firstchar, + (long) win->_line[n].lastchar, + ep); + + /* if there are multi-column characters on the line, print them now */ + if_WIDEC({ + bool multicolumn = FALSE; + for (j = 0; j < width; ++j) + if (WidecExt(win->_line[n].text[j]) != 0) { + multicolumn = TRUE; + break; + } + if (multicolumn) { + ep = my_buffer; + for (j = 0; j < width; ++j) { + int test = WidecExt(win->_line[n].text[j]); + if (test) { + ep[j] = (char) (test + '0'); + } else { + ep[j] = ' '; + } + } + ep[j] = '\0'; + _tracef("%*s[%2d]%*s='%s'", (int) strlen(name), + "widec", n, 8, " ", my_buffer); + } + }); /* dump A_COLOR part, will screw up if there are more than 96 */ havecolors = FALSE; - for (j = 0; j <= width; j++) - if (win->_line[n].text[j] & A_COLOR) { + for (j = 0; j < width; ++j) + if (GetPair(win->_line[n].text[j]) != 0) { havecolors = TRUE; break; } if (havecolors) { - (void) snprintf(buf, sizeof(buf), "%*s[%2d]%*s='", - (int) strlen(name), "colors", n, 8, " "); - ep = buf + strlen(buf); - for (j = 0; j <= width; j++) - ep[j] = CharOf(win->_line[n].text[j] >> 8) + ' '; - ep[j] = '\''; - ep[j + 1] = '\0'; - _tracef("%s", buf); + ep = my_buffer; + for (j = 0; j < width; ++j) { + int pair = GetPair(win->_line[n].text[j]); + if (pair >= 52) + ep[j] = '?'; + else if (pair >= 36) + ep[j] = (char) (pair + 'A'); + else if (pair >= 10) + ep[j] = (char) (pair + 'a'); + else if (pair >= 1) + ep[j] = (char) (pair + '0'); + else + ep[j] = ' '; + } + ep[j] = '\0'; + _tracef("%*s[%2d]%*s='%s'", (int) strlen(name), + "colors", n, 8, " ", my_buffer); } - for (i = 0; i < 4; i++) { + for (i = 0; i < 4; ++i) { const char *hex = " 123456789ABCDEF"; - chtype mask = (0xf << ((i + 4) * 4)); + attr_t mask = (0xf << ((i + 4) * 4)); haveattrs = FALSE; - for (j = 0; j <= width; j++) - if (win->_line[n].text[j] & mask) { + for (j = 0; j < width; ++j) + if (AttrOf(win->_line[n].text[j]) & mask) { haveattrs = TRUE; break; } if (haveattrs) { - (void) snprintf(buf, sizeof(buf), "%*s%d[%2d]%*s='", - (int) strlen(name) - 1, "attrs", i, n, 8, " "); - ep = buf + strlen(buf); - for (j = 0; j <= width; j++) - ep[j] = hex[(win->_line[n].text[j] & mask) >> ((i + 4) * 4)]; - ep[j] = '\''; - ep[j + 1] = '\0'; - _tracef("%s", buf); + ep = my_buffer; + for (j = 0; j < width; ++j) + ep[j] = hex[(AttrOf(win->_line[n].text[j]) & mask) >> + ((i + 4) * 4)]; + ep[j] = '\0'; + _tracef("%*s%d[%2d]%*s='%s'", (int) strlen(name) - + 1, "attrs", i, n, 8, " ", my_buffer); } } } +#if NO_LEAKS + free(my_buffer); + my_buffer = 0; + my_length = 0; +#endif } + #else -extern -NCURSES_EXPORT(void) -_nc_lib_tracedmp(void); -NCURSES_EXPORT(void) -_nc_lib_tracedmp(void) -{ -} +EMPTY_MODULE(_nc_lib_tracedmp) #endif /* TRACE */ diff --git a/lib/libcurses/trace/lib_tracemse.c b/lib/libcurses/trace/lib_tracemse.c index 3346d87e224..798aae9f563 100644 --- a/lib/libcurses/trace/lib_tracemse.c +++ b/lib/libcurses/trace/lib_tracemse.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_tracemse.c,v 1.4 2003/03/18 16:55:54 millert Exp $ */ +/* $OpenBSD: lib_tracemse.c,v 1.5 2010/01/12 23:22:07 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -39,62 +40,92 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_tracemse.c,v 1.8 2000/12/10 03:02:45 tom Exp $") +MODULE_ID("$Id: lib_tracemse.c,v 1.5 2010/01/12 23:22:07 nicm Exp $") #ifdef TRACE +#define my_buffer sp->tracemse_buf + NCURSES_EXPORT(char *) -_tracemouse(MEVENT const *ep) +_nc_tracemouse(SCREEN *sp, MEVENT const *ep) { - static char buf[80]; - - (void) snprintf(buf, sizeof(buf), "id %2d at (%2d, %2d, %2d) state %4lx = {", - ep->id, ep->x, ep->y, ep->z, ep->bstate); - -#define SHOW(m, s) if ((ep->bstate & m)==m) {strlcat(buf,s,sizeof(buf)); strlcat(buf, ", ",sizeof(buf));} - SHOW(BUTTON1_RELEASED, "release-1") - SHOW(BUTTON1_PRESSED, "press-1") - SHOW(BUTTON1_CLICKED, "click-1") - SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1") - SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1") - SHOW(BUTTON1_RESERVED_EVENT, "reserved-1") - SHOW(BUTTON2_RELEASED, "release-2") - SHOW(BUTTON2_PRESSED, "press-2") - SHOW(BUTTON2_CLICKED, "click-2") - SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2") - SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2") - SHOW(BUTTON2_RESERVED_EVENT, "reserved-2") - SHOW(BUTTON3_RELEASED, "release-3") - SHOW(BUTTON3_PRESSED, "press-3") - SHOW(BUTTON3_CLICKED, "click-3") - SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3") - SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3") - SHOW(BUTTON3_RESERVED_EVENT, "reserved-3") - SHOW(BUTTON4_RELEASED, "release-4") - SHOW(BUTTON4_PRESSED, "press-4") - SHOW(BUTTON4_CLICKED, "click-4") - SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4") - SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4") - SHOW(BUTTON4_RESERVED_EVENT, "reserved-4") - SHOW(BUTTON_CTRL, "ctrl") - SHOW(BUTTON_SHIFT, "shift") - SHOW(BUTTON_ALT, "alt") - SHOW(ALL_MOUSE_EVENTS, "all-events") - SHOW(REPORT_MOUSE_POSITION, "position") + (void) snprintf(my_buffer, TRACEMSE_MAX, TRACEMSE_FMT, + ep->id, + ep->x, + ep->y, + ep->z, + (unsigned long) ep->bstate); + +#define SHOW(m, s) \ + if ((ep->bstate & m) == m) { \ + strlcat(my_buffer, s, TRACEMSE_MAX); \ + strlcat(my_buffer, ", ", TRACEMSE_MAX); \ +} + + SHOW(BUTTON1_RELEASED, "release-1"); + SHOW(BUTTON1_PRESSED, "press-1"); + SHOW(BUTTON1_CLICKED, "click-1"); + SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1"); + SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1"); +#if NCURSES_MOUSE_VERSION == 1 + SHOW(BUTTON1_RESERVED_EVENT, "reserved-1"); +#endif + + SHOW(BUTTON2_RELEASED, "release-2"); + SHOW(BUTTON2_PRESSED, "press-2"); + SHOW(BUTTON2_CLICKED, "click-2"); + SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2"); + SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2"); +#if NCURSES_MOUSE_VERSION == 1 + SHOW(BUTTON2_RESERVED_EVENT, "reserved-2"); +#endif + + SHOW(BUTTON3_RELEASED, "release-3"); + SHOW(BUTTON3_PRESSED, "press-3"); + SHOW(BUTTON3_CLICKED, "click-3"); + SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3"); + SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3"); +#if NCURSES_MOUSE_VERSION == 1 + SHOW(BUTTON3_RESERVED_EVENT, "reserved-3"); +#endif + + SHOW(BUTTON4_RELEASED, "release-4"); + SHOW(BUTTON4_PRESSED, "press-4"); + SHOW(BUTTON4_CLICKED, "click-4"); + SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4"); + SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4"); +#if NCURSES_MOUSE_VERSION == 1 + SHOW(BUTTON4_RESERVED_EVENT, "reserved-4"); +#endif + +#if NCURSES_MOUSE_VERSION == 2 + SHOW(BUTTON5_RELEASED, "release-5"); + SHOW(BUTTON5_PRESSED, "press-5"); + SHOW(BUTTON5_CLICKED, "click-5"); + SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5"); + SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5"); +#endif + + SHOW(BUTTON_CTRL, "ctrl"); + SHOW(BUTTON_SHIFT, "shift"); + SHOW(BUTTON_ALT, "alt"); + SHOW(ALL_MOUSE_EVENTS, "all-events"); + SHOW(REPORT_MOUSE_POSITION, "position"); + #undef SHOW - if (buf[strlen(buf) - 1] == ' ') - buf[strlen(buf) - 2] = '\0'; - (void) strlcat(buf, "}", sizeof(buf)); - return (buf); + if (my_buffer[strlen(my_buffer) - 1] == ' ') + my_buffer[strlen(my_buffer) - 2] = '\0'; + (void) strlcat(my_buffer, "}", TRACEMSE_MAX); + return (my_buffer); } -#else /* !TRACE */ -/* don't make empty module */ -NCURSES_EXPORT(void) -_nc_lib_tracemouse(void); -NCURSES_EXPORT(void) -_nc_lib_tracemouse(void) +NCURSES_EXPORT(char *) +_tracemouse(MEVENT const *ep) { + return _nc_tracemouse(SP, ep); } + +#else /* !TRACE */ +EMPTY_MODULE(_nc_lib_tracemouse) #endif diff --git a/lib/libcurses/trace/trace_buf.c b/lib/libcurses/trace/trace_buf.c index 060ef5e686d..2b57ef77a3f 100644 --- a/lib/libcurses/trace/trace_buf.c +++ b/lib/libcurses/trace/trace_buf.c @@ -1,7 +1,7 @@ -/* $OpenBSD: trace_buf.c,v 1.3 2001/01/22 18:01:58 millert Exp $ */ +/* $OpenBSD: trace_buf.c,v 1.4 2010/01/12 23:22:07 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,7 +29,7 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey <dickey@clark.net> 1997 * + * Author: Thomas E. Dickey 1997-on * ****************************************************************************/ /* * trace_buf.c - Tracing/Debugging buffers (attributes) @@ -37,47 +37,85 @@ #include <curses.priv.h> -MODULE_ID("$From: trace_buf.c,v 1.9 2000/12/10 03:02:45 tom Exp $") +MODULE_ID("$Id: trace_buf.c,v 1.4 2010/01/12 23:22:07 nicm Exp $") -typedef struct { - char *text; - size_t size; -} LIST; +#define MyList _nc_globals.tracebuf_ptr +#define MySize _nc_globals.tracebuf_used -NCURSES_EXPORT(char *) -_nc_trace_buf(int bufnum, size_t want) +static char * +_nc_trace_alloc(int bufnum, size_t want) { - static LIST *list; - static size_t have; +#ifdef TRACE + char *result = 0; + + if (bufnum >= 0) { + if ((size_t) (bufnum + 1) > MySize) { + size_t need = (bufnum + 1) * 2; + if ((MyList = typeRealloc(TRACEBUF, need, MyList)) != 0) { + while (need > MySize) + MyList[MySize++].text = 0; + } + } + if (MyList != 0) { + if (MyList[bufnum].text == 0 + || want > MyList[bufnum].size) { + MyList[bufnum].text = typeRealloc(char, want, MyList[bufnum].text); + if (MyList[bufnum].text != 0) + MyList[bufnum].size = want; + } + result = MyList[bufnum].text; + } + } #if NO_LEAKS - if (bufnum < 0) { - if (have) { - while (have--) { - free(list[have].text); + else { + if (MySize) { + if (MyList) { + while (MySize--) { + if (MyList[MySize].text != 0) { + free(MyList[MySize].text); + } + } + free(MyList); + MyList = 0; } - free(list); + MySize = 0; } - return 0; } #endif + return result; +#else + return NULL; +#endif +} - if ((size_t) (bufnum + 1) > have) { - size_t need = (bufnum + 1) * 2; - if ((list = typeRealloc(LIST, need, list)) == 0) - return (0); - while (need > have) - list[have++].text = 0; - } +/* + * (re)Allocate a buffer big enough for the caller's wants. + */ +NCURSES_EXPORT(char *) +_nc_trace_buf(int bufnum, size_t want) +{ + char *result = _nc_trace_alloc(bufnum, want); + if (result != 0) + *result = '\0'; + return result; +} - if (list[bufnum].text == 0 - || want > list[bufnum].size) { - if ((list[bufnum].text = typeRealloc(char, want, list[bufnum].text)) - != 0) - list[bufnum].size = want; - } +/* + * Append a new string to an existing buffer. + */ +NCURSES_EXPORT(char *) +_nc_trace_bufcat(int bufnum, const char *value) +{ + char *buffer = _nc_trace_alloc(bufnum, 0); + if (buffer != 0) { + size_t have = strlen(buffer), length; + + length = 1 + have + strlen(value); + buffer = _nc_trace_alloc(bufnum, length); + if (buffer != 0) + (void) strlcpy(buffer + have, value, length); - if (list[bufnum].text != 0) - *(list[bufnum].text) = '\0'; - return list[bufnum].text; + } + return buffer; } diff --git a/lib/libcurses/trace/trace_tries.c b/lib/libcurses/trace/trace_tries.c index d0dd538d9be..0a138b48cab 100644 --- a/lib/libcurses/trace/trace_tries.c +++ b/lib/libcurses/trace/trace_tries.c @@ -1,7 +1,7 @@ -/* $OpenBSD: trace_tries.c,v 1.4 2001/01/22 18:01:59 millert Exp $ */ +/* $OpenBSD: trace_tries.c,v 1.5 2010/01/12 23:22:07 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1999-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -37,25 +37,27 @@ #include <curses.priv.h> -MODULE_ID("$From: trace_tries.c,v 1.8 2000/12/10 03:03:51 tom Exp $") +MODULE_ID("$Id: trace_tries.c,v 1.5 2010/01/12 23:22:07 nicm Exp $") #ifdef TRACE -static unsigned char *buffer; -static unsigned len; +#define my_buffer _nc_globals.tracetry_buf +#define my_length _nc_globals.tracetry_used static void -recur_tries(struct tries *tree, unsigned level) +recur_tries(TRIES * tree, unsigned level) { - if (level > len) - buffer = (unsigned char *) realloc(buffer, len = (level + 1) * 4); + if (level > my_length) { + my_length = (level + 1) * 4; + my_buffer = (unsigned char *) realloc(my_buffer, my_length); + } while (tree != 0) { - if ((buffer[level] = tree->ch) == 0) - buffer[level] = 128; - buffer[level + 1] = 0; + if ((my_buffer[level] = tree->ch) == 0) + my_buffer[level] = 128; + my_buffer[level + 1] = 0; if (tree->value != 0) { _tracef("%5d: %s (%s)", tree->value, - _nc_visbuf((char *) buffer), keyname(tree->value)); + _nc_visbuf((char *) my_buffer), keyname(tree->value)); } if (tree->child) recur_tries(tree->child, level + 1); @@ -64,18 +66,18 @@ recur_tries(struct tries *tree, unsigned level) } NCURSES_EXPORT(void) -_nc_trace_tries(struct tries *tree) +_nc_trace_tries(TRIES * tree) { - buffer = typeMalloc(unsigned char, len = 80); + my_buffer = typeMalloc(unsigned char, my_length = 80); _tracef("BEGIN tries %p", tree); recur_tries(tree, 0); _tracef(". . . tries %p", tree); - free(buffer); + free(my_buffer); } #else NCURSES_EXPORT(void) -_nc_trace_tries(struct tries *tree GCC_UNUSED) +_nc_trace_tries(TRIES * tree) { } #endif diff --git a/lib/libcurses/trace/trace_xnames.c b/lib/libcurses/trace/trace_xnames.c index 22dc761419f..2c5b0ff74dd 100644 --- a/lib/libcurses/trace/trace_xnames.c +++ b/lib/libcurses/trace/trace_xnames.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trace_xnames.c,v 1.3 2001/01/22 18:01:59 millert Exp $ */ +/* $OpenBSD: trace_xnames.c,v 1.4 2010/01/12 23:22:07 nicm Exp $ */ /**************************************************************************** * Copyright (c) 1999,2000 Free Software Foundation, Inc. * @@ -38,7 +38,7 @@ #include <curses.priv.h> #include <term_entry.h> -MODULE_ID("$From: trace_xnames.c,v 1.5 2000/12/10 03:02:45 tom Exp $") +MODULE_ID("$Id: trace_xnames.c,v 1.4 2010/01/12 23:22:07 nicm Exp $") NCURSES_EXPORT(void) _nc_trace_xnames(TERMTYPE * tp GCC_UNUSED) diff --git a/lib/libcurses/trace/varargs.c b/lib/libcurses/trace/varargs.c new file mode 100644 index 00000000000..0a1d5cfa161 --- /dev/null +++ b/lib/libcurses/trace/varargs.c @@ -0,0 +1,186 @@ +/* $OpenBSD: varargs.c,v 1.1 2010/01/12 23:22:07 nicm Exp $ */ + +/**************************************************************************** + * Copyright (c) 2001-2007,2008 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey 2001 * + ****************************************************************************/ + +#include <curses.priv.h> + +#include <ctype.h> + +MODULE_ID("$Id: varargs.c,v 1.1 2010/01/12 23:22:07 nicm Exp $") + +#ifdef TRACE + +#define MAX_PARMS 10 + +typedef enum { + atUnknown = 0, atInteger, atFloat, atPoint, atString +} ARGTYPE; + +#define VA_INT(type) ival = va_arg(ap, type) +#define VA_FLT(type) fval = va_arg(ap, type) +#define VA_PTR(type) pval = (char *)va_arg(ap, type) +#define VA_STR(type) sval = va_arg(ap, type) + +#define MyBuffer _nc_globals.tracearg_buf +#define MyLength _nc_globals.tracearg_used + +/* + * Returns a string that represents the parameter list of a printf-style call. + */ +NCURSES_EXPORT(char *) +_nc_varargs(const char *fmt, va_list ap) +{ + static char dummy[] = ""; + + char buffer[BUFSIZ]; + const char *param; + int n; + + if (fmt == 0 || *fmt == '\0') + return dummy; + if (MyLength == 0) + MyBuffer = typeMalloc(char, MyLength = BUFSIZ); + if (MyBuffer == 0) + return dummy; + *MyBuffer = '\0'; + + while (*fmt != '\0') { + if (*fmt == '%') { + char *pval = 0; /* avoid const-cast */ + const char *sval = ""; + double fval = 0.0; + int done = FALSE; + int ival = 0; + int type = 0; + ARGTYPE parm[MAX_PARMS]; + int parms = 0; + ARGTYPE used = atUnknown; + + while (*++fmt != '\0' && !done) { + + if (*fmt == '*') { + VA_INT(int); + if (parms < MAX_PARMS) + parm[parms++] = atInteger; + } else if (isalpha(UChar(*fmt))) { + done = TRUE; + switch (*fmt) { + case 'Z': /* FALLTHRU */ + case 'h': /* FALLTHRU */ + case 'l': /* FALLTHRU */ + done = FALSE; + type = *fmt; + break; + case 'i': /* FALLTHRU */ + case 'd': /* FALLTHRU */ + case 'u': /* FALLTHRU */ + case 'x': /* FALLTHRU */ + case 'X': /* FALLTHRU */ + if (type == 'l') + VA_INT(long); + else if (type == 'Z') + VA_INT(size_t); + else + VA_INT(int); + used = atInteger; + break; + case 'f': /* FALLTHRU */ + case 'e': /* FALLTHRU */ + case 'E': /* FALLTHRU */ + case 'g': /* FALLTHRU */ + case 'G': /* FALLTHRU */ + VA_FLT(double); + used = atFloat; + break; + case 'c': + VA_INT(int); + used = atInteger; + break; + case 's': + VA_STR(const char *); + used = atString; + break; + case 'p': + VA_PTR(void *); + used = atPoint; + break; + case 'n': + VA_PTR(int *); + used = atPoint; + break; + default: + break; + } + } else if (*fmt == '%') { + done = TRUE; + } + if (used != atUnknown && parms < MAX_PARMS) { + parm[parms++] = used; + for (n = 0; n < parms; ++n) { + used = parm[n]; + param = buffer; + switch (used) { + case atInteger: + snprintf(buffer, sizeof(buffer), "%d", ival); + break; + case atFloat: + snprintf(buffer, sizeof(buffer), "%f", fval); + break; + case atPoint: + snprintf(buffer, sizeof(buffer), "%p", pval); + break; + case atString: + param = _nc_visbuf2(1, sval); + break; + case atUnknown: + default: + strlcpy(buffer, "?", sizeof(buffer)); + break; + } + MyLength += strlen(param) + 2; + MyBuffer = typeRealloc(char, MyLength, MyBuffer); + snprintf(MyBuffer + strlen(MyBuffer), MyLength - strlen(MyBuffer), ", %s", param); + } + } + used = atUnknown; + } + } else { + fmt++; + } + } + + return (MyBuffer); +} +#else +EMPTY_MODULE(_nc_varargs) +#endif diff --git a/lib/libcurses/trace/visbuf.c b/lib/libcurses/trace/visbuf.c new file mode 100644 index 00000000000..47efca5e22c --- /dev/null +++ b/lib/libcurses/trace/visbuf.c @@ -0,0 +1,333 @@ +/* $OpenBSD: visbuf.c,v 1.1 2010/01/12 23:22:07 nicm Exp $ */ + +/**************************************************************************** + * Copyright (c) 2001-2007,2008 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey 1996-on * + * and: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * + * and: Eric S. Raymond <esr@snark.thyrsus.com> * + ****************************************************************************/ + +/* + * visbuf.c - Tracing/Debugging support routines + */ + +#define NEED_NCURSES_CH_T +#include <curses.priv.h> + +#include <tic.h> +#include <ctype.h> + +MODULE_ID("$Id: visbuf.c,v 1.1 2010/01/12 23:22:07 nicm Exp $") + +#define NormalLen(len) (size_t) (((size_t)(len) + 1) * 4) +#define WideLen(len) (size_t) (((size_t)(len) + 1) * 4 * MB_CUR_MAX) + +#ifdef TRACE +static const char d_quote[] = StringOf(D_QUOTE); +static const char l_brace[] = StringOf(L_BRACE); +static const char r_brace[] = StringOf(R_BRACE); +#endif + +static char * +_nc_vischar(char *tp, size_t tl, unsigned c) +{ + if (c == '"' || c == '\\') { + *tp++ = '\\'; + *tp++ = (char) c; + } else if (is7bits(c) && (isgraph(c) || c == ' ')) { + *tp++ = (char) c; + } else if (c == '\n') { + *tp++ = '\\'; + *tp++ = 'n'; + } else if (c == '\r') { + *tp++ = '\\'; + *tp++ = 'r'; + } else if (c == '\b') { + *tp++ = '\\'; + *tp++ = 'b'; + } else if (c == '\033') { + *tp++ = '\\'; + *tp++ = 'e'; + } else if (UChar(c) == 0x7f) { + *tp++ = '\\'; + *tp++ = '^'; + *tp++ = '?'; + } else if (is7bits(c) && iscntrl(UChar(c))) { + *tp++ = '\\'; + *tp++ = '^'; + *tp++ = (char) ('@' + c); + } else { + snprintf(tp, tl, "\\%03lo", (unsigned long) ChCharOf(c)); + tp += strlen(tp); + } + *tp = 0; + return tp; +} + +static const char * +_nc_visbuf2n(int bufnum, const char *buf, int len) +{ + const char *vbuf; + char *tp; + int c; + + if (buf == 0) + return ("(null)"); + if (buf == CANCELLED_STRING) + return ("(cancelled)"); + + if (len < 0) + len = (int) strlen(buf); + +#ifdef TRACE + vbuf = tp = _nc_trace_buf(bufnum, NormalLen(len)); +#else + { + static char *mybuf[4]; + mybuf[bufnum] = typeRealloc(char, NormalLen(len), mybuf[bufnum]); + vbuf = tp = mybuf[bufnum]; + } +#endif + if (tp != 0) { + *tp++ = D_QUOTE; + while ((--len >= 0) && (c = *buf++) != '\0') { + tp = _nc_vischar(tp, NormalLen(len) - (tp - vbuf), UChar(c)); + } + *tp++ = D_QUOTE; + *tp++ = '\0'; + } else { + vbuf = ("(_nc_visbuf2n failed)"); + } + return (vbuf); +} + +NCURSES_EXPORT(const char *) +_nc_visbuf2(int bufnum, const char *buf) +{ + return _nc_visbuf2n(bufnum, buf, -1); +} + +NCURSES_EXPORT(const char *) +_nc_visbuf(const char *buf) +{ + return _nc_visbuf2(0, buf); +} + +NCURSES_EXPORT(const char *) +_nc_visbufn(const char *buf, int len) +{ + return _nc_visbuf2n(0, buf, len); +} + +#ifdef TRACE +#if USE_WIDEC_SUPPORT + +#if defined(USE_TERMLIB) +#define _nc_wchstrlen _my_wchstrlen +static int +_nc_wchstrlen(const cchar_t *s) +{ + int result = 0; + while (CharOf(s[result]) != L'\0') { + result++; + } + return result; +} +#endif + +static const char * +_nc_viswbuf2n(int bufnum, const wchar_t *buf, int len) +{ + const char *vbuf; + char *tp; + wchar_t c; + + if (buf == 0) + return ("(null)"); + + if (len < 0) + len = (int) wcslen(buf); + +#ifdef TRACE + vbuf = tp = _nc_trace_buf(bufnum, WideLen(len)); +#else + { + static char *mybuf[2]; + mybuf[bufnum] = typeRealloc(char, WideLen(len), mybuf[bufnum]); + vbuf = tp = mybuf[bufnum]; + } +#endif + if (tp != 0) { + *tp++ = D_QUOTE; + while ((--len >= 0) && (c = *buf++) != '\0') { + char temp[CCHARW_MAX + 80]; + int j = wctomb(temp, c), k; + if (j <= 0) { + snprintf(temp, sizeof temp, "\\u%08X", (unsigned) c); + j = (int) strlen(temp); + } + for (k = 0; k < j; ++k) { + tp = _nc_vischar(tp, WideLen(len) - (tp - vbuf), UChar(temp[k])); + } + } + *tp++ = D_QUOTE; + *tp++ = '\0'; + } else { + vbuf = ("(_nc_viswbuf2n failed)"); + } + return (vbuf); +} + +NCURSES_EXPORT(const char *) +_nc_viswbuf2(int bufnum, const wchar_t *buf) +{ + return _nc_viswbuf2n(bufnum, buf, -1); +} + +NCURSES_EXPORT(const char *) +_nc_viswbuf(const wchar_t *buf) +{ + return _nc_viswbuf2(0, buf); +} + +NCURSES_EXPORT(const char *) +_nc_viswbufn(const wchar_t *buf, int len) +{ + return _nc_viswbuf2n(0, buf, len); +} + +/* this special case is used for wget_wstr() */ +NCURSES_EXPORT(const char *) +_nc_viswibuf(const wint_t *buf) +{ + static wchar_t *mybuf; + static unsigned mylen; + unsigned n; + + for (n = 0; buf[n] != 0; ++n) ; + if (mylen < ++n) { + mylen = n + 80; + if (mybuf != 0) + mybuf = typeRealloc(wchar_t, mylen, mybuf); + else + mybuf = typeMalloc(wchar_t, mylen); + } + for (n = 0; buf[n] != 0; ++n) + mybuf[n] = (wchar_t) buf[n]; + + return _nc_viswbuf2(0, mybuf); +} +#endif /* USE_WIDEC_SUPPORT */ + +/* use these functions for displaying parts of a line within a window */ +NCURSES_EXPORT(const char *) +_nc_viscbuf2(int bufnum, const NCURSES_CH_T * buf, int len) +{ + char *result = _nc_trace_buf(bufnum, BUFSIZ); + int first; + const char *found; + + if (result != 0) { +#if USE_WIDEC_SUPPORT + if (len < 0) + len = _nc_wchstrlen(buf); +#endif /* USE_WIDEC_SUPPORT */ + + /* + * Display one or more strings followed by attributes. + */ + first = 0; + while (first < len) { + attr_t attr = AttrOf(buf[first]); + int last = len - 1; + int j; + + for (j = first + 1; j < len; ++j) { + if (!SameAttrOf(buf[j], buf[first])) { + last = j - 1; + break; + } + } + + result = _nc_trace_bufcat(bufnum, l_brace); + result = _nc_trace_bufcat(bufnum, d_quote); + for (j = first; j <= last; ++j) { + found = _nc_altcharset_name(attr, (chtype) CharOf(buf[j])); + if (found != 0) { + result = _nc_trace_bufcat(bufnum, found); + attr &= ~A_ALTCHARSET; + } else +#if USE_WIDEC_SUPPORT + if (!isWidecExt(buf[j])) { + PUTC_DATA; + + PUTC_INIT; + for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) { + int k; + + PUTC_ch = buf[j].chars[PUTC_i]; + if (PUTC_ch == L'\0') + break; + PUTC_n = (int) wcrtomb(PUTC_buf, buf[j].chars[PUTC_i], &PUT_st); + if (PUTC_n <= 0) + break; + for (k = 0; k < PUTC_n; k++) { + char temp[80]; + _nc_vischar(temp, sizeof(temp), UChar(PUTC_buf[k])); + result = _nc_trace_bufcat(bufnum, temp); + } + } + } +#else + { + char temp[80]; + _nc_vischar(temp, sizeof(temp), UChar(buf[j])); + result = _nc_trace_bufcat(bufnum, temp); + } +#endif /* USE_WIDEC_SUPPORT */ + } + result = _nc_trace_bufcat(bufnum, d_quote); + if (attr != A_NORMAL) { + result = _nc_trace_bufcat(bufnum, " | "); + result = _nc_trace_bufcat(bufnum, _traceattr2(bufnum + 20, attr)); + } + result = _nc_trace_bufcat(bufnum, r_brace); + first = last + 1; + } + } + return result; +} + +NCURSES_EXPORT(const char *) +_nc_viscbuf(const NCURSES_CH_T * buf, int len) +{ + return _nc_viscbuf2(0, buf, len); +} +#endif /* TRACE */ diff --git a/lib/libcurses/tty/MKexpanded.sh b/lib/libcurses/tty/MKexpanded.sh index c9de5292ec3..bc6902b5bb7 100644 --- a/lib/libcurses/tty/MKexpanded.sh +++ b/lib/libcurses/tty/MKexpanded.sh @@ -1,6 +1,7 @@ #! /bin/sh +# $OpenBSD: MKexpanded.sh,v 1.4 2010/01/12 23:22:07 nicm Exp $ ############################################################################## -# Copyright (c) 1998,2000 Free Software Foundation, Inc. # +# Copyright (c) 1998-2000,2005 Free Software Foundation, Inc. # # # # Permission is hereby granted, free of charge, to any person obtaining a # # copy of this software and associated documentation files (the "Software"), # @@ -29,8 +30,7 @@ # # Author: Thomas E. Dickey <dickey@clark.net> 1997 # -# $OpenBSD: MKexpanded.sh,v 1.3 2001/01/22 18:01:59 millert Exp $ -# $From: MKexpanded.sh,v 1.10 2000/12/10 00:24:33 tom Exp $ +# $Id: MKexpanded.sh,v 1.4 2010/01/12 23:22:07 nicm Exp $ # # Script to generate 'expanded.c', a dummy source that contains functions # corresponding to complex macros used in this library. By making functions, @@ -85,7 +85,7 @@ NCURSES_EXPORT(int) _nc_InsCharCost (int count) { return InsCharCost(count); } -NCURSES_EXPORT(void) _nc_UpdateAttrs (chtype c) +NCURSES_EXPORT(void) _nc_UpdateAttrs (NCURSES_CH_T c) { UpdateAttrs(c); } diff --git a/lib/libcurses/tty/hardscroll.c b/lib/libcurses/tty/hardscroll.c index 2633ce851e9..35cb745db31 100644 --- a/lib/libcurses/tty/hardscroll.c +++ b/lib/libcurses/tty/hardscroll.c @@ -1,7 +1,7 @@ -/* $OpenBSD: hardscroll.c,v 1.6 2003/03/18 16:55:54 millert Exp $ */ +/* $OpenBSD: hardscroll.c,v 1.7 2010/01/12 23:22:07 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,8 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * + * and: Alexander V Lukyanov 1997-1998 * ****************************************************************************/ /****************************************************************************** @@ -147,7 +149,7 @@ AUTHOR #include <curses.priv.h> -MODULE_ID("$From: hardscroll.c,v 1.36 2001/01/14 00:17:28 tom Exp $") +MODULE_ID("$Id: hardscroll.c,v 1.7 2010/01/12 23:22:07 nicm Exp $") #if defined(SCROLLDEBUG) || defined(HASHDEBUG) @@ -160,22 +162,25 @@ oldnums[MAXLINES]; # undef TR # define TR(n, a) if (_nc_tracing & (n)) { _tracef a ; putchar('\n'); } +extern NCURSES_EXPORT_VAR(unsigned) _nc_tracing; + #else /* no debug */ /* OLDNUM(n) indicates which line will be shifted to the position n. if OLDNUM(n) == _NEWINDEX, then the line n in new, not shifted from somewhere. */ NCURSES_EXPORT_VAR(int *) -_nc_oldnums = 0; +_nc_oldnums = 0; /* obsolete: keep for ABI compat */ # if USE_HASHMAP - static int oldnums_allocated = 0; -# define oldnums _nc_oldnums +# define oldnums SP->_oldnum_list # define OLDNUM(n) oldnums[n] # else /* !USE_HASHMAP */ # define OLDNUM(n) newscr->_line[n].oldindex # endif /* !USE_HASHMAP */ +#define OLDNUM_SIZE SP->_oldnum_size + #endif /* defined(SCROLLDEBUG) || defined(HASHDEBUG) */ NCURSES_EXPORT(void) @@ -185,17 +190,17 @@ _nc_scroll_optimize(void) int i; int start, end, shift; - TR(TRACE_ICALLS, ("_nc_scroll_optimize() begins")); + TR(TRACE_ICALLS, (T_CALLED("_nc_scroll_optimize"))); #if !defined(SCROLLDEBUG) && !defined(HASHDEBUG) #if USE_HASHMAP /* get enough storage */ - if (oldnums_allocated < screen_lines) { + if (OLDNUM_SIZE < screen_lines) { int *new_oldnums = typeRealloc(int, screen_lines, oldnums); if (!new_oldnums) return; oldnums = new_oldnums; - oldnums_allocated = screen_lines; + OLDNUM_SIZE = screen_lines; } /* calculate the indices */ _nc_hash_map(); @@ -203,8 +208,10 @@ _nc_scroll_optimize(void) #endif /* !defined(SCROLLDEBUG) && !defined(HASHDEBUG) */ #ifdef TRACE - if (_nc_tracing & (TRACE_UPDATE | TRACE_MOVE)) + if (USE_TRACEF(TRACE_UPDATE | TRACE_MOVE)) { _nc_linedump(); + _nc_unlock_global(tracef); + } #endif /* TRACE */ /* pass 1 - from top to bottom scrolling up */ @@ -255,6 +262,7 @@ _nc_scroll_optimize(void) } #endif /* !defined(SCROLLDEBUG) && !defined(HASHDEBUG) */ } + TR(TRACE_ICALLS, (T_RETURN(""))); } #if defined(TRACE) || defined(SCROLLDEBUG) || defined(HASHDEBUG) @@ -262,24 +270,18 @@ NCURSES_EXPORT(void) _nc_linedump(void) /* dump the state of the real and virtual oldnum fields */ { - static size_t have; - static char *buf; - int n; + char *buf = 0; size_t want = (screen_lines + 1) * 4; - if (have < want) - buf = typeMalloc(char, have = want); - - (void) strlcpy(buf, "virt", have); - for (n = 0; n < screen_lines; n++) - (void) snprintf(buf + strlen(buf), have - strlen(buf), " %02d", - OLDNUM(n)); - TR(TRACE_UPDATE | TRACE_MOVE, (buf)); -#if NO_LEAKS - free(buf); - have = 0; -#endif + if ((buf = typeMalloc(char, want)) != 0) { + + (void) strlcpy(buf, "virt", want); + for (n = 0; n < screen_lines; n++) + (void) snprintf(buf + strlen(buf), want - strlen(buf), " %02d", OLDNUM(n)); + TR(TRACE_UPDATE | TRACE_MOVE, (buf)); + free(buf); + } } #endif /* defined(TRACE) || defined(SCROLLDEBUG) */ diff --git a/lib/libcurses/tty/hashmap.c b/lib/libcurses/tty/hashmap.c index bf57cefdbe2..14739fa35a3 100644 --- a/lib/libcurses/tty/hashmap.c +++ b/lib/libcurses/tty/hashmap.c @@ -1,7 +1,7 @@ -/* $OpenBSD: hashmap.c,v 1.7 2002/06/22 18:13:05 deraadt Exp $ */ +/* $OpenBSD: hashmap.c,v 1.8 2010/01/12 23:22:07 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -72,7 +72,7 @@ AUTHOR #include <curses.priv.h> #include <term.h> /* for back_color_erase */ -MODULE_ID("$From: hashmap.c,v 1.36 2000/12/10 03:04:30 tom Exp $") +MODULE_ID("$Id: hashmap.c,v 1.8 2010/01/12 23:22:07 nicm Exp $") #ifdef HASHDEBUG @@ -83,7 +83,8 @@ MODULE_ID("$From: hashmap.c,v 1.36 2000/12/10 03:04:30 tom Exp $") # define screen_lines MAXLINES # define TEXTWIDTH 1 int oldnums[MAXLINES], reallines[MAXLINES]; -static chtype oldtext[MAXLINES][TEXTWIDTH], newtext[MAXLINES][TEXTWIDTH]; +static NCURSES_CH_T oldtext[MAXLINES][TEXTWIDTH]; +static NCURSES_CH_T newtext[MAXLINES][TEXTWIDTH]; # define OLDNUM(n) oldnums[n] # define OLDTEXT(n) oldtext[n] # define NEWTEXT(m) newtext[m] @@ -91,7 +92,7 @@ static chtype oldtext[MAXLINES][TEXTWIDTH], newtext[MAXLINES][TEXTWIDTH]; #else /* !HASHDEBUG */ -# define OLDNUM(n) _nc_oldnums[n] +# define OLDNUM(n) SP->_oldnum_list[n] # define OLDTEXT(n) curscr->_line[n].text # define NEWTEXT(m) newscr->_line[m].text # define TEXTWIDTH (curscr->_maxx+1) @@ -99,47 +100,58 @@ static chtype oldtext[MAXLINES][TEXTWIDTH], newtext[MAXLINES][TEXTWIDTH]; #endif /* !HASHDEBUG */ -#define oldhash (SP->oldhash) -#define newhash (SP->newhash) +#define oldhash (SP->oldhash) +#define newhash (SP->newhash) +#define hashtab (SP->hashtab) +#define lines_alloc (SP->hashtab_len) -static inline unsigned long -hash(chtype * text) +#if USE_WIDEC_SUPPORT +#define HASH_VAL(ch) (ch.chars[0]) +#else +#define HASH_VAL(ch) (ch) +#endif + +static const NCURSES_CH_T blankchar = NewChar(BLANK_TEXT); + +static NCURSES_INLINE unsigned long +hash(NCURSES_CH_T * text) { int i; - chtype ch; + NCURSES_CH_T ch; unsigned long result = 0; for (i = TEXTWIDTH; i > 0; i--) { ch = *text++; - result += (result << 5) + ch; + result += (result << 5) + HASH_VAL(ch); } return result; } /* approximate update cost */ static int -update_cost(chtype * from, chtype * to) +update_cost(NCURSES_CH_T * from, NCURSES_CH_T * to) { int cost = 0; int i; - for (i = TEXTWIDTH; i > 0; i--) - if (*from++ != *to++) + for (i = TEXTWIDTH; i > 0; i--, from++, to++) + if (!(CharEq(*from, *to))) cost++; return cost; } + static int -update_cost_from_blank(chtype * to) +update_cost_from_blank(NCURSES_CH_T * to) { int cost = 0; int i; - chtype blank = BLANK; + NCURSES_CH_T blank = blankchar; if (back_color_erase) - blank |= (stdscr->_bkgd & A_COLOR); + SetPair(blank, GetPair(stdscr->_nc_bkgd)); - for (i = TEXTWIDTH; i > 0; i--) - if (blank != *to++) + for (i = TEXTWIDTH; i > 0; i--, to++) + if (!(CharEq(blank, *to))) cost++; return cost; @@ -149,7 +161,7 @@ update_cost_from_blank(chtype * to) * Returns true when moving line 'from' to line 'to' seems to be cost * effective. 'blank' indicates whether the line 'to' would become blank. */ -static inline bool +static NCURSES_INLINE bool cost_effective(const int from, const int to, const bool blank) { int new_from; @@ -173,15 +185,6 @@ cost_effective(const int from, const int to, const bool blank) + update_cost(OLDTEXT(from), NEWTEXT(to)))) ? TRUE : FALSE; } -typedef struct { - unsigned long hashval; - int oldcount, newcount; - int oldindex, newindex; -} sym; - -static sym *hashtab = 0; -static int lines_alloc = 0; - static void grow_hunks(void) { @@ -269,14 +272,14 @@ grow_hunks(void) NCURSES_EXPORT(void) _nc_hash_map(void) { - sym *sp; + HASHMAP *sp; register int i; int start, shift, size; if (screen_lines > lines_alloc) { if (hashtab) free(hashtab); - hashtab = typeMalloc(sym, (screen_lines + 1) * 2); + hashtab = typeMalloc(HASHMAP, (screen_lines + 1) * 2); if (!hashtab) { if (oldhash) { FreeAndNull(oldhash); @@ -296,9 +299,9 @@ _nc_hash_map(void) } else { /* re-hash all */ if (oldhash == 0) - oldhash = typeCalloc(unsigned long, screen_lines); + oldhash = typeCalloc(unsigned long, (unsigned) screen_lines); if (newhash == 0) - newhash = typeCalloc(unsigned long, screen_lines); + newhash = typeCalloc(unsigned long, (unsigned) screen_lines); if (!oldhash || !newhash) return; /* malloc failure */ for (i = 0; i < screen_lines; i++) { @@ -389,11 +392,6 @@ _nc_hash_map(void) /* After clearing invalid hunks, try grow the rest. */ grow_hunks(); - -#if NO_LEAKS - FreeAndNull(hashtab); - lines_alloc = 0; -#endif } NCURSES_EXPORT(void) @@ -406,7 +404,7 @@ _nc_make_oldhash(int i) NCURSES_EXPORT(void) _nc_scroll_oldhash(int n, int top, int bot) { - int size; + size_t size; int i; if (!oldhash) @@ -451,11 +449,14 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) char line[BUFSIZ], *st, *last; int n; - SP = typeCalloc(SCREEN, 1); + if (setupterm(NULL, fileno(stdout), (int *) 0) == ERR) + return EXIT_FAILURE; + (void) _nc_alloc_screen(); + for (n = 0; n < screen_lines; n++) { reallines[n] = n; oldnums[n] = _NEWINDEX; - oldtext[n][0] = newtext[n][0] = '.'; + CharOf(oldtext[n][0]) = CharOf(newtext[n][0]) = '.'; } if (isatty(fileno(stdin))) @@ -467,7 +468,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) for (;;) { /* grab a test command */ if (fgets(line, sizeof(line), stdin) == (char *) NULL) - exit(EXIT_SUCCESS); + break; switch (line[0]) { case '#': /* comment */ @@ -489,22 +490,22 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) case 'n': /* use following letters as text of new lines */ for (n = 0; n < screen_lines; n++) - newtext[n][0] = '.'; + CharOf(newtext[n][0]) = '.'; for (n = 0; n < screen_lines; n++) if (line[n + 1] == '\n') break; else - newtext[n][0] = line[n + 1]; + CharOf(newtext[n][0]) = line[n + 1]; break; case 'o': /* use following letters as text of old lines */ for (n = 0; n < screen_lines; n++) - oldtext[n][0] = '.'; + CharOf(oldtext[n][0]) = '.'; for (n = 0; n < screen_lines; n++) if (line[n + 1] == '\n') break; else - oldtext[n][0] = line[n + 1]; + CharOf(oldtext[n][0]) = line[n + 1]; break; case 'd': /* dump state of test arrays */ @@ -513,12 +514,12 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) #endif (void) fputs("Old lines: [", stdout); for (n = 0; n < screen_lines; n++) - putchar(oldtext[n][0]); + putchar(CharOf(oldtext[n][0])); putchar(']'); putchar('\n'); (void) fputs("New lines: [", stdout); for (n = 0; n < screen_lines; n++) - putchar(newtext[n][0]); + putchar(CharOf(newtext[n][0])); putchar(']'); putchar('\n'); break; @@ -532,12 +533,17 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) _nc_scroll_optimize(); (void) fputs("Done.\n", stderr); break; + default: case '?': usage(); break; } } +#if NO_LEAKS + _nc_free_and_exit(EXIT_SUCCESS); +#else return EXIT_SUCCESS; +#endif } #endif /* HASHDEBUG */ diff --git a/lib/libcurses/tty/lib_mvcur.c b/lib/libcurses/tty/lib_mvcur.c index df0a3080ade..bd0b4334345 100644 --- a/lib/libcurses/tty/lib_mvcur.c +++ b/lib/libcurses/tty/lib_mvcur.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_mvcur.c,v 1.12 2007/05/17 04:34:50 ray Exp $ */ +/* $OpenBSD: lib_mvcur.c,v 1.13 2010/01/12 23:22:07 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -110,7 +111,9 @@ * LONG_DIST and (b) further inward from the right or left edge than LONG_DIST, * we'll consider nonlocal. */ -#define NOT_LOCAL(fy, fx, ty, tx) ((tx > LONG_DIST) && (tx < screen_lines - 1 - LONG_DIST) && (abs(ty-fy) + abs(tx-fx) > LONG_DIST)) +#define NOT_LOCAL(fy, fx, ty, tx) ((tx > LONG_DIST) \ + && (tx < screen_columns - 1 - LONG_DIST) \ + && (abs(ty-fy) + abs(tx-fx) > LONG_DIST)) /**************************************************************************** * @@ -154,12 +157,8 @@ #include <term.h> #include <ctype.h> -MODULE_ID("$From: lib_mvcur.c,v 1.77 2000/12/10 03:04:30 tom Exp $") +MODULE_ID("$Id: lib_mvcur.c,v 1.13 2010/01/12 23:22:07 nicm Exp $") -#define CURRENT_ROW SP->_cursrow /* phys cursor row */ -#define CURRENT_COLUMN SP->_curscol /* phys cursor column */ -#define CURRENT_ATTR SP->_current_attr /* current phys attribute */ -#define REAL_ATTR SP->_current_attr /* phys current attribute */ #define WANT_CHAR(y, x) SP->_newscr->_line[y].text[x] /* desired state */ #define BAUDRATE cur_term->_baudrate /* bits per second */ @@ -209,8 +208,7 @@ trace_normalized_cost(const char *capname, const char *cap, int affcnt) #endif NCURSES_EXPORT(int) -_nc_msec_cost -(const char *const cap, int affcnt) +_nc_msec_cost(const char *const cap, int affcnt) /* compute the cost of a given operation */ { if (cap == 0) @@ -225,16 +223,16 @@ _nc_msec_cost float number = 0.0; for (cp += 2; *cp != '>'; cp++) { - if (isdigit(CharOf(*cp))) + if (isdigit(UChar(*cp))) number = number * 10 + (*cp - '0'); else if (*cp == '*') number *= affcnt; - else if (*cp == '.' && (*++cp != '>') && isdigit(CharOf(*cp))) + else if (*cp == '.' && (*++cp != '>') && isdigit(UChar(*cp))) number += (*cp - '0') / 10.0; } #if NCURSES_NO_PADDING - if (!(SP->_no_padding)) + if (!GetNoPadding(SP)) #endif cum_cost += number * 10; } else @@ -261,7 +259,7 @@ reset_scroll_region(void) { if (change_scroll_region) { TPUTS_TRACE("change_scroll_region"); - putp(tparm(change_scroll_region, 0, screen_lines - 1)); + putp(TPARM_2(change_scroll_region, 0, screen_lines - 1)); } } @@ -299,10 +297,11 @@ NCURSES_EXPORT(void) _nc_mvcur_init(void) /* initialize the cost structure */ { - /* - * 9 = 7 bits + 1 parity + 1 stop. - */ - SP->_char_padding = (9 * 1000 * 10) / (BAUDRATE > 0 ? BAUDRATE : 9600); + if (isatty(fileno(SP->_ofp))) + SP->_char_padding = ((BAUDBYTE * 1000 * 10) + / (BAUDRATE > 0 ? BAUDRATE : 9600)); + else + SP->_char_padding = 1; /* must be nonzero */ if (SP->_char_padding <= 0) SP->_char_padding = 1; /* must be nonzero */ TR(TRACE_CHARPUT | TRACE_MOVE, ("char_padding %d msecs", SP->_char_padding)); @@ -312,8 +311,13 @@ _nc_mvcur_init(void) SP->_home_cost = CostOf(cursor_home, 0); SP->_ll_cost = CostOf(cursor_to_ll, 0); #if USE_HARD_TABS - SP->_ht_cost = CostOf(tab, 0); - SP->_cbt_cost = CostOf(back_tab, 0); + if (getenv("NCURSES_NO_HARD_TABS") == 0) { + SP->_ht_cost = CostOf(tab, 0); + SP->_cbt_cost = CostOf(back_tab, 0); + } else { + SP->_ht_cost = INFINITY; + SP->_cbt_cost = INFINITY; + } #endif /* USE_HARD_TABS */ SP->_cub1_cost = CostOf(cursor_left, 0); SP->_cuf1_cost = CostOf(cursor_right, 0); @@ -359,13 +363,13 @@ _nc_mvcur_init(void) * All these averages depend on the assumption that all parameter values * are equally probable. */ - SP->_cup_cost = CostOf(tparm(SP->_address_cursor, 23, 23), 1); - SP->_cub_cost = CostOf(tparm(parm_left_cursor, 23), 1); - SP->_cuf_cost = CostOf(tparm(parm_right_cursor, 23), 1); - SP->_cud_cost = CostOf(tparm(parm_down_cursor, 23), 1); - SP->_cuu_cost = CostOf(tparm(parm_up_cursor, 23), 1); - SP->_hpa_cost = CostOf(tparm(column_address, 23), 1); - SP->_vpa_cost = CostOf(tparm(row_address, 23), 1); + SP->_cup_cost = CostOf(TPARM_2(SP->_address_cursor, 23, 23), 1); + SP->_cub_cost = CostOf(TPARM_1(parm_left_cursor, 23), 1); + SP->_cuf_cost = CostOf(TPARM_1(parm_right_cursor, 23), 1); + SP->_cud_cost = CostOf(TPARM_1(parm_down_cursor, 23), 1); + SP->_cuu_cost = CostOf(TPARM_1(parm_up_cursor, 23), 1); + SP->_hpa_cost = CostOf(TPARM_1(column_address, 23), 1); + SP->_vpa_cost = CostOf(TPARM_1(row_address, 23), 1); /* non-parameterized screen-update strings */ SP->_ed_cost = NormalizedCost(clr_eos, 1); @@ -374,15 +378,22 @@ _nc_mvcur_init(void) SP->_dch1_cost = NormalizedCost(delete_character, 1); SP->_ich1_cost = NormalizedCost(insert_character, 1); + /* + * If this is a bce-terminal, we want to bias the choice so we use clr_eol + * rather than spaces at the end of a line. + */ + if (back_color_erase) + SP->_el_cost = 0; + /* parameterized screen-update strings */ - SP->_dch_cost = NormalizedCost(tparm(parm_dch, 23), 1); - SP->_ich_cost = NormalizedCost(tparm(parm_ich, 23), 1); - SP->_ech_cost = NormalizedCost(tparm(erase_chars, 23), 1); - SP->_rep_cost = NormalizedCost(tparm(repeat_char, ' ', 23), 1); - - SP->_cup_ch_cost = NormalizedCost(tparm(SP->_address_cursor, 23, 23), 1); - SP->_hpa_ch_cost = NormalizedCost(tparm(column_address, 23), 1); - SP->_cuf_ch_cost = NormalizedCost(tparm(parm_right_cursor, 23), 1); + SP->_dch_cost = NormalizedCost(TPARM_1(parm_dch, 23), 1); + SP->_ich_cost = NormalizedCost(TPARM_1(parm_ich, 23), 1); + SP->_ech_cost = NormalizedCost(TPARM_1(erase_chars, 23), 1); + SP->_rep_cost = NormalizedCost(TPARM_2(repeat_char, ' ', 23), 1); + + SP->_cup_ch_cost = NormalizedCost(TPARM_2(SP->_address_cursor, 23, 23), 1); + SP->_hpa_ch_cost = NormalizedCost(TPARM_1(column_address, 23), 1); + SP->_cuf_ch_cost = NormalizedCost(TPARM_1(parm_right_cursor, 23), 1); SP->_inline_cost = min(SP->_cup_ch_cost, min(SP->_hpa_ch_cost, SP->_cuf_ch_cost)); @@ -417,8 +428,11 @@ _nc_mvcur_wrap(void) mvcur(-1, -1, screen_lines - 1, 0); /* set cursor to normal mode */ - if (SP->_cursor != -1) + if (SP->_cursor != -1) { + int cursor = SP->_cursor; curs_set(1); + SP->_cursor = cursor; + } if (exit_ca_mode) { TPUTS_TRACE("exit_ca_mode"); @@ -444,7 +458,7 @@ _nc_mvcur_wrap(void) /* * Perform repeated-append, returning cost */ -static inline int +static NCURSES_INLINE int repeated_append(string_desc * target, int total, int num, int repeat, const char *src) { size_t need = repeat * strlen(src); @@ -487,7 +501,7 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int vcost = INFINITY; if (row_address != 0 - && _nc_safe_strcat(target, tparm(row_address, to_y))) { + && _nc_safe_strcat(target, TPARM_1(row_address, to_y))) { vcost = SP->_vpa_cost; } @@ -497,11 +511,13 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int if (parm_down_cursor && SP->_cud_cost < vcost && _nc_safe_strcat(_nc_str_copy(target, &save), - tparm(parm_down_cursor, n))) { + TPARM_1(parm_down_cursor, n))) { vcost = SP->_cud_cost; } - if (cursor_down && (n * SP->_cud1_cost < vcost)) { + if (cursor_down + && (*cursor_down != '\n' || SP->_nl) + && (n * SP->_cud1_cost < vcost)) { vcost = repeated_append(_nc_str_copy(target, &save), 0, SP->_cud1_cost, n, cursor_down); } @@ -509,10 +525,10 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int n = (from_y - to_y); if (parm_up_cursor - && SP->_cup_cost < vcost + && SP->_cuu_cost < vcost && _nc_safe_strcat(_nc_str_copy(target, &save), - tparm(parm_up_cursor, n))) { - vcost = SP->_cup_cost; + TPARM_1(parm_up_cursor, n))) { + vcost = SP->_cuu_cost; } if (cursor_up && (n * SP->_cuu1_cost < vcost)) { @@ -535,7 +551,7 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int if (column_address && _nc_safe_strcat(_nc_str_copy(target, &save), - tparm(column_address, to_x))) { + TPARM_1(column_address, to_x))) { hcost = SP->_hpa_cost; } @@ -545,7 +561,7 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int if (parm_right_cursor && SP->_cuf_cost < hcost && _nc_safe_strcat(_nc_str_copy(target, &save), - tparm(parm_right_cursor, n))) { + TPARM_1(parm_right_cursor, n))) { hcost = SP->_cuf_cost; } @@ -571,7 +587,6 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int } #endif /* USE_HARD_TABS */ -#if defined(REAL_ATTR) && defined(WANT_CHAR) if (n <= 0 || n >= (int) check.s_size) ovw = FALSE; #if BSD_TPUTS @@ -585,9 +600,11 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int && n > 0 && n < (int) check.s_size && vcost == 0 - && str[0] == '\0' - && isdigit(TextOf(WANT_CHAR(to_y, from_x)))) - ovw = FALSE; + && str[0] == '\0') { + int wanted = CharOf(WANT_CHAR(to_y, from_x)); + if (is8bits(wanted) && isdigit(wanted)) + ovw = FALSE; + } #endif /* * If we have no attribute changes, overwrite is cheaper. @@ -600,23 +617,28 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int if (ovw) { int i; - for (i = 0; i < n; i++) - if ((WANT_CHAR(to_y, from_x + i) & A_ATTRIBUTES) != CURRENT_ATTR) { + for (i = 0; i < n; i++) { + NCURSES_CH_T ch = WANT_CHAR(to_y, from_x + i); + if (!SameAttrOf(ch, SCREEN_ATTRS(SP)) +#if USE_WIDEC_SUPPORT + || !Charable(ch) +#endif + ) { ovw = FALSE; break; } + } } if (ovw) { int i; for (i = 0; i < n; i++) - *check.s_tail++ = WANT_CHAR(to_y, from_x + i); + *check.s_tail++ = (char) CharOf(WANT_CHAR(to_y, + from_x + i)); *check.s_tail = '\0'; check.s_size -= n; lhcost += n * SP->_char_padding; - } else -#endif /* defined(REAL_ATTR) && defined(WANT_CHAR) */ - { + } else { lhcost = repeated_append(&check, lhcost, SP->_cuf1_cost, n, cursor_right); } @@ -632,7 +654,7 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int if (parm_left_cursor && SP->_cub_cost < hcost && _nc_safe_strcat(_nc_str_copy(target, &save), - tparm(parm_left_cursor, n))) { + TPARM_1(parm_left_cursor, n))) { hcost = SP->_cub_cost; } @@ -684,7 +706,7 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int * the simpler method below. */ -static inline int +static NCURSES_INLINE int onscreen_mvcur(int yold, int xold, int ynew, int xnew, bool ovw) /* onscreen move from (yold, xold) to (ynew, xnew) */ { @@ -703,7 +725,7 @@ onscreen_mvcur(int yold, int xold, int ynew, int xnew, bool ovw) #define InitResult _nc_str_init(&result, buffer, sizeof(buffer)) /* tactic #0: use direct cursor addressing */ - if (_nc_safe_strcpy(InitResult, tparm(SP->_address_cursor, ynew, xnew))) { + if (_nc_safe_strcpy(InitResult, TPARM_2(SP->_address_cursor, ynew, xnew))) { tactic = 0; usecost = SP->_cup_cost; @@ -812,78 +834,122 @@ onscreen_mvcur(int yold, int xold, int ynew, int xnew, bool ovw) } #endif /* !NO_OPTIMIZE */ + nonlocal: #if defined(MAIN) || defined(NCURSES_TEST) gettimeofday(&after, NULL); diff = after.tv_usec - before.tv_usec + (after.tv_sec - before.tv_sec) * 1000000; if (!profiling) (void) fprintf(stderr, - "onscreen: %d msec, %f 28.8Kbps char-equivalents\n", + "onscreen: %d microsec, %f 28.8Kbps char-equivalents\n", (int) diff, diff / 288); #endif /* MAIN */ - nonlocal: if (usecost != INFINITY) { TPUTS_TRACE("mvcur"); tputs(buffer, 1, _nc_outch); + SP->_cursrow = ynew; + SP->_curscol = xnew; return (OK); } else return (ERR); } NCURSES_EXPORT(int) -mvcur -(int yold, int xold, int ynew, int xnew) +mvcur(int yold, int xold, int ynew, int xnew) /* optimized cursor move from (yold, xold) to (ynew, xnew) */ { - TR(TRACE_MOVE, ("mvcur(%d,%d,%d,%d) called", yold, xold, ynew, xnew)); + NCURSES_CH_T oldattr; + int code; - if (yold == ynew && xold == xnew) - return (OK); + TR(TRACE_CALLS | TRACE_MOVE, (T_CALLED("mvcur(%d,%d,%d,%d)"), + yold, xold, ynew, xnew)); - /* - * 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 ynew on the screen. - */ + if (SP == 0) { + code = ERR; + } else if (yold == ynew && xold == xnew) { + code = OK; + } else { - if (xnew >= screen_columns) { - ynew += xnew / screen_columns; - xnew %= screen_columns; - } - if (xold >= screen_columns) { - int l; - - l = (xold + 1) / screen_columns; - yold += l; - if (yold >= screen_lines) - l -= (yold - screen_lines - 1); - - while (l > 0) { - if (newline) { - TPUTS_TRACE("newline"); - tputs(newline, 0, _nc_outch); - } else - putchar('\n'); - l--; - if (xold > 0) { - if (carriage_return) { - TPUTS_TRACE("carriage_return"); - tputs(carriage_return, 0, _nc_outch); - } else - putchar('\r'); - xold = 0; + /* + * 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 ynew on the screen. + */ + if (xnew >= screen_columns) { + ynew += xnew / screen_columns; + xnew %= screen_columns; + } + + /* + * Force restore even if msgr is on when we're in an alternate + * character set -- these have a strong tendency to screw up the CR & + * LF used for local character motions! + */ + oldattr = SCREEN_ATTRS(SP); + if ((AttrOf(oldattr) & A_ALTCHARSET) + || (AttrOf(oldattr) && !move_standout_mode)) { + TR(TRACE_CHARPUT, ("turning off (%#lx) %s before move", + (unsigned long) AttrOf(oldattr), + _traceattr(AttrOf(oldattr)))); + (void) VIDATTR(A_NORMAL, 0); + } + + if (xold >= screen_columns) { + int l; + + if (SP->_nl) { + l = (xold + 1) / screen_columns; + yold += l; + if (yold >= screen_lines) + l -= (yold - screen_lines - 1); + + if (l > 0) { + if (carriage_return) { + TPUTS_TRACE("carriage_return"); + putp(carriage_return); + } else + _nc_outch('\r'); + xold = 0; + + while (l > 0) { + if (newline) { + TPUTS_TRACE("newline"); + putp(newline); + } else + _nc_outch('\n'); + l--; + } + } + } else { + /* + * If caller set nonl(), we cannot really use newlines to + * position to the next row. + */ + xold = -1; + yold = -1; } } - } - if (yold > screen_lines - 1) - yold = screen_lines - 1; - if (ynew > screen_lines - 1) - ynew = screen_lines - 1; + if (yold > screen_lines - 1) + yold = screen_lines - 1; + if (ynew > screen_lines - 1) + ynew = screen_lines - 1; - /* destination location is on screen now */ - return (onscreen_mvcur(yold, xold, ynew, xnew, TRUE)); + /* destination location is on screen now */ + code = onscreen_mvcur(yold, xold, ynew, xnew, TRUE); + + /* + * Restore attributes if we disabled them before moving. + */ + if (!SameAttrOf(oldattr, SCREEN_ATTRS(SP))) { + TR(TRACE_CHARPUT, ("turning on (%#lx) %s after move", + (unsigned long) AttrOf(oldattr), + _traceattr(AttrOf(oldattr)))); + (void) VIDATTR(AttrOf(oldattr), GetPair(oldattr)); + } + } + returnCode(code); } #if defined(TRACE) || defined(NCURSES_TEST) @@ -899,16 +965,15 @@ NCURSES_EXPORT_VAR(int) _nc_optimize_enable = OPTIMIZE_ALL; #include <tic.h> #include <dump_entry.h> +#include <time.h> -NCURSES_EXPORT_VAR(const char *) -_nc_progname = "mvcur"; +NCURSES_EXPORT_VAR(const char *) _nc_progname = "mvcur"; - static unsigned long xmits; +static unsigned long xmits; /* these override lib_tputs.c */ NCURSES_EXPORT(int) -tputs -(const char *string, int affcnt GCC_UNUSED, int (*outc) (int) GCC_UNUSED) +tputs(const char *string, int affcnt GCC_UNUSED, int (*outc) (int) GCC_UNUSED) /* stub tputs() that dumps sequences in a visible form */ { if (profiling) @@ -931,18 +996,13 @@ _nc_outch(int ch) return OK; } -NCURSES_EXPORT_VAR(char) PC = 0; /* used by termcap library */ -NCURSES_EXPORT_VAR(NCURSES_OSPEED) ospeed = 0; /* used by termcap library */ -NCURSES_EXPORT_VAR(int) -_nc_nulls_sent = 0; /* used by 'tack' program */ - NCURSES_EXPORT(int) delay_output(int ms GCC_UNUSED) { return OK; } -static char tname[MAX_ALIAS]; +static char tname[PATH_MAX]; static void load_term(void) @@ -964,9 +1024,9 @@ roll(int n) int main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) { - (void) strlcpy(tname, termname(), sizeof(tname)); + strlcpy(tname, sizeof(tname), getenv("TERM")); load_term(); - _nc_setupscreen(lines, columns, stdout); + _nc_setupscreen(lines, columns, stdout, FALSE, 0); baudrate(); _nc_mvcur_init(); @@ -983,9 +1043,9 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) (void) fputs("> ", stdout); if (fgets(buf, sizeof(buf), stdin) == NULL) { - if (ferror(stdin)) - fputs("ferror on stdin", stderr); - break; + if (ferror(stdin)) + fputs("ferror on stdin", stderr); + break; } if (buf[0] == '?') { @@ -1033,13 +1093,13 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) before.tv_sec) * 1000000)); } else if (buf[0] == 'r') { - (void) strlcpy(tname, termname(), sizeof(tname)); + (void) strlcpy(tname, sizeof(tname), termname()); load_term(); } else if (sscanf(buf, "l %s", tname) == 1) { load_term(); } else if (sscanf(buf, "d %s", capname) == 1) { struct name_table_entry const *np = _nc_find_entry(capname, - _nc_info_hash_table); + _nc_get_hash_table(FALSE)); if (np == NULL) (void) printf("No such capability as \"%s\"\n", capname); @@ -1067,7 +1127,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) } } else if (buf[0] == 'i') { dump_init((char *) NULL, F_TERMINFO, S_TERMINFO, 70, 0, FALSE); - dump_entry(&cur_term->type, FALSE, TRUE, 0); + dump_entry(&cur_term->type, FALSE, TRUE, 0, 0); putchar('\n'); } else if (buf[0] == 'o') { if (_nc_optimize_enable & OPTIMIZE_MVCUR) { diff --git a/lib/libcurses/tty/lib_tstp.c b/lib/libcurses/tty/lib_tstp.c index 0e862bbcde5..a6126846461 100644 --- a/lib/libcurses/tty/lib_tstp.c +++ b/lib/libcurses/tty/lib_tstp.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_tstp.c,v 1.9 2001/12/06 04:26:00 deraadt Exp $ */ +/* $OpenBSD: lib_tstp.c,v 1.10 2010/01/12 23:22:07 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1995-on * ****************************************************************************/ /* @@ -39,17 +40,15 @@ ** The routine _nc_signal_handler(). ** */ - #include <curses.priv.h> -#include <signal.h> #include <SigAction.h> #if SVR4_ACTION && !defined(_POSIX_SOURCE) #define _POSIX_SOURCE #endif -MODULE_ID("$From: lib_tstp.c,v 1.24 2000/12/10 03:04:30 tom Exp $") +MODULE_ID("$Id: lib_tstp.c,v 1.10 2010/01/12 23:22:07 nicm Exp $") #if defined(SIGTSTP) && (HAVE_SIGACTION || HAVE_SIGVEC) #define USE_SIGTSTP 1 @@ -57,6 +56,41 @@ MODULE_ID("$From: lib_tstp.c,v 1.24 2000/12/10 03:04:30 tom Exp $") #define USE_SIGTSTP 0 #endif +#ifdef TRACE +static const char * +signal_name(int sig) +{ + switch (sig) { + case SIGALRM: + return "SIGALRM"; +#ifdef SIGCONT + case SIGCONT: + return "SIGCONT"; +#endif + case SIGINT: + return "SIGINT"; + case SIGQUIT: + return "SIGQUIT"; + case SIGTERM: + return "SIGTERM"; +#ifdef SIGTSTP + case SIGTSTP: + return "SIGTSTP"; +#endif +#ifdef SIGTTOU + case SIGTTOU: + return "SIGTTOU"; +#endif +#ifdef SIGWINCH + case SIGWINCH: + return "SIGWINCH"; +#endif + default: + return "unknown signal"; + } +} +#endif + /* * Note: This code is fragile! Its problem is that different OSs * handle restart of system calls interrupted by signals differently. @@ -202,16 +236,14 @@ tstp(int dummy GCC_UNUSED) static void cleanup(int sig) { - static int nested; - /* - * XXX signal race. The kind of comment is completely ingenius! + * XXX signal race. This kind of comment is completely ingenious! * * Actually, doing any sort of I/O from within an signal handler is * "unsafe". But we'll _try_ to clean up the screen and terminal * settings on the way out. */ - if (!nested++ + if (!_nc_globals.cleanup_nested++ && (sig == SIGINT || sig == SIGQUIT)) { #if HAVE_SIGACTION || HAVE_SIGVEC @@ -219,24 +251,22 @@ cleanup(int sig) sigemptyset(&act.sa_mask); act.sa_flags = 0; act.sa_handler = SIG_IGN; - if (sigaction(sig, &act, (sigaction_t *) 0) == 0) + if (sigaction(sig, &act, NULL) == 0) #else if (signal(sig, SIG_IGN) != SIG_ERR) #endif { - SCREEN *scan = _nc_screen_chain; - while (scan) { - if (SP != 0 - && SP->_ofp != 0 - && isatty(fileno(SP->_ofp))) { - SP->_cleanup = TRUE; - SP->_outch = _nc_outch; + SCREEN *scan; + for (each_screen(scan)) { + if (scan->_ofp != 0 + && isatty(fileno(scan->_ofp))) { + scan->_cleanup = TRUE; + scan->_outch = _nc_outch; } set_term(scan); endwin(); if (SP) SP->_endwin = FALSE; /* in case we have an atexit! */ - scan = scan->_next_screen; } } } @@ -247,11 +277,7 @@ cleanup(int sig) static void sigwinch(int sig GCC_UNUSED) { - SCREEN *scan = _nc_screen_chain; - while (scan) { - scan->_sig_winch = TRUE; - scan = scan->_next_screen; - } + _nc_globals.have_sigwinch = 1; } #endif /* USE_SIGWINCH */ @@ -259,43 +285,57 @@ sigwinch(int sig GCC_UNUSED) * If the given signal is still in its default state, set it to the given * handler. */ -#if HAVE_SIGACTION || HAVE_SIGVEC static int -CatchIfDefault(int sig, sigaction_t * act) +CatchIfDefault(int sig, RETSIGTYPE (*handler) (int)) { + int result; +#if HAVE_SIGACTION || HAVE_SIGVEC sigaction_t old_act; + sigaction_t new_act; + + memset(&new_act, 0, sizeof(new_act)); + sigemptyset(&new_act.sa_mask); +#ifdef SA_RESTART +#ifdef SIGWINCH + if (sig != SIGWINCH) +#endif + new_act.sa_flags |= SA_RESTART; +#endif /* SA_RESTART */ + new_act.sa_handler = handler; - if (sigaction(sig, (sigaction_t *) 0, &old_act) == 0 + if (sigaction(sig, NULL, &old_act) == 0 && (old_act.sa_handler == SIG_DFL + || old_act.sa_handler == handler #if USE_SIGWINCH || (sig == SIGWINCH && old_act.sa_handler == SIG_IGN) #endif )) { - (void) sigaction(sig, act, (sigaction_t *) 0); - return TRUE; + (void) sigaction(sig, &new_act, NULL); + result = TRUE; + } else { + result = FALSE; } - return FALSE; -} -#else -static int -CatchIfDefault(int sig, RETSIGTYPE(*handler) (int)) -{ - void (*ohandler) (int); +#else /* !HAVE_SIGACTION */ + RETSIGTYPE (*ohandler) (int); ohandler = signal(sig, SIG_IGN); if (ohandler == SIG_DFL + || ohandler == handler #if USE_SIGWINCH || (sig == SIGWINCH && ohandler == SIG_IGN) #endif ) { signal(sig, handler); - return TRUE; + result = TRUE; } else { signal(sig, ohandler); - return FALSE; + result = FALSE; } -} #endif + T(("CatchIfDefault - will %scatch %s", + result ? "" : "not ", signal_name(sig))); + return result; +} /* * This is invoked once at the beginning (e.g., from 'initscr()'), to @@ -311,60 +351,43 @@ CatchIfDefault(int sig, RETSIGTYPE(*handler) (int)) NCURSES_EXPORT(void) _nc_signal_handler(bool enable) { + T((T_CALLED("_nc_signal_handler(%d)"), enable)); #if USE_SIGTSTP /* Xenix 2.x doesn't have SIGTSTP, for example */ - static sigaction_t act, oact; - static int ignore; - - if (!ignore) { - if (!enable) { - act.sa_handler = SIG_IGN; - sigaction(SIGTSTP, &act, &oact); - } else if (act.sa_handler) { - sigaction(SIGTSTP, &oact, NULL); - } else { /*initialize */ - sigemptyset(&act.sa_mask); - act.sa_flags = 0; -#if USE_SIGWINCH - act.sa_handler = sigwinch; - CatchIfDefault(SIGWINCH, &act); -#endif - + { + static bool ignore_tstp = FALSE; + + if (!ignore_tstp) { + static sigaction_t new_sigaction, old_sigaction; + + if (!enable) { + new_sigaction.sa_handler = SIG_IGN; + sigaction(SIGTSTP, &new_sigaction, &old_sigaction); + } else if (new_sigaction.sa_handler != SIG_DFL) { + sigaction(SIGTSTP, &old_sigaction, NULL); + } else if (sigaction(SIGTSTP, NULL, &old_sigaction) == 0 + && (old_sigaction.sa_handler == SIG_DFL)) { + sigemptyset(&new_sigaction.sa_mask); #ifdef SA_RESTART - act.sa_flags |= SA_RESTART; + new_sigaction.sa_flags |= SA_RESTART; #endif /* SA_RESTART */ - act.sa_handler = cleanup; - CatchIfDefault(SIGINT, &act); - CatchIfDefault(SIGTERM, &act); - - act.sa_handler = tstp; - if (!CatchIfDefault(SIGTSTP, &act)) - ignore = TRUE; + new_sigaction.sa_handler = tstp; + (void) sigaction(SIGTSTP, &new_sigaction, NULL); + } else { + ignore_tstp = TRUE; + } } } -#else /* !USE_SIGTSTP */ - if (enable) { -#if HAVE_SIGACTION || HAVE_SIGVEC - static sigaction_t act; - sigemptyset(&act.sa_mask); -#if USE_SIGWINCH - act.sa_handler = sigwinch; - CatchIfDefault(SIGWINCH, &act); -#endif -#ifdef SA_RESTART - act.sa_flags |= SA_RESTART; -#endif /* SA_RESTART */ - act.sa_handler = cleanup; - CatchIfDefault(SIGINT, &act); - CatchIfDefault(SIGTERM, &act); - -#else /* !(HAVE_SIGACTION || HAVE_SIGVEC) */ +#endif /* !USE_SIGTSTP */ - CatchIfDefault(SIGINT, cleanup); - CatchIfDefault(SIGTERM, cleanup); + if (!_nc_globals.init_signals) { + if (enable) { + CatchIfDefault(SIGINT, cleanup); + CatchIfDefault(SIGTERM, cleanup); #if USE_SIGWINCH - CatchIfDefault(SIGWINCH, sigwinch); + CatchIfDefault(SIGWINCH, sigwinch); #endif -#endif /* !(HAVE_SIGACTION || HAVE_SIGVEC) */ + _nc_globals.init_signals = TRUE; + } } -#endif /* !USE_SIGTSTP */ + returnVoid; } diff --git a/lib/libcurses/tty/lib_twait.c b/lib/libcurses/tty/lib_twait.c index 0b7c4d2949b..fcbc3cfdf47 100644 --- a/lib/libcurses/tty/lib_twait.c +++ b/lib/libcurses/tty/lib_twait.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_twait.c,v 1.8 2001/01/22 18:02:00 millert Exp $ */ +/* $OpenBSD: lib_twait.c,v 1.9 2010/01/12 23:22:07 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -42,12 +43,18 @@ ** comments, none of the original code remains - T.Dickey). */ +#include <curses.priv.h> + +#if defined __HAIKU__ && defined __BEOS__ +#undef __BEOS__ +#endif + #ifdef __BEOS__ +#undef false +#undef true #include <OS.h> #endif -#include <curses.priv.h> - #if USE_FUNC_POLL # if HAVE_SYS_TIME_H # include <sys/time.h> @@ -61,36 +68,64 @@ # endif #endif -MODULE_ID("$From: lib_twait.c,v 1.41 2000/12/10 03:04:30 tom Exp $") +#undef CUR + +MODULE_ID("$Id: lib_twait.c,v 1.9 2010/01/12 23:22:07 nicm Exp $") static long -_nc_gettime(bool first) +_nc_gettime(TimeType * t0, bool first) { long res; -#if HAVE_GETTIMEOFDAY -# define PRECISE_GETTIME 1 - static struct timeval t0; - struct timeval t1; +#if PRECISE_GETTIME + TimeType t1; gettimeofday(&t1, (struct timezone *) 0); if (first) { - t0 = t1; + *t0 = t1; + res = 0; + } else { + /* .tv_sec and .tv_usec are unsigned, be careful when subtracting */ + if (t0->tv_usec > t1.tv_usec) { + t1.tv_usec += 1000000; /* Convert 1s in 1e6 microsecs */ + t1.tv_sec--; + } + res = (t1.tv_sec - t0->tv_sec) * 1000 + + (t1.tv_usec - t0->tv_usec) / 1000; } - res = (t1.tv_sec - t0.tv_sec) * 1000 - + (t1.tv_usec - t0.tv_usec) / 1000; #else -# define PRECISE_GETTIME 0 - static time_t t0; time_t t1 = time((time_t *) 0); if (first) { - t0 = t1; + *t0 = t1; } - res = (t1 - t0) * 1000; + res = (t1 - *t0) * 1000; #endif - T(("%s time: %ld msec", first ? "get" : "elapsed", res)); + TR(TRACE_IEVENT, ("%s time: %ld msec", first ? "get" : "elapsed", res)); return res; } +#ifdef NCURSES_WGETCH_EVENTS +NCURSES_EXPORT(int) +_nc_eventlist_timeout(_nc_eventlist * evl) +{ + int event_delay = -1; + int n; + + if (evl != 0) { + + for (n = 0; n < evl->count; ++n) { + _nc_event *ev = evl->events[n]; + + if (ev->type == _NC_EVENT_TIMEOUT_MSEC) { + event_delay = ev->data.timeout_msec; + if (event_delay < 0) + event_delay = INT_MAX; /* FIXME Is this defined? */ + } + } + } + return event_delay; +} +#endif /* NCURSES_WGETCH_EVENTS */ + /* * Wait a specified number of milliseconds, returning nonzero if the timer * didn't expire before there is activity on the specified file descriptors. @@ -99,55 +134,137 @@ _nc_gettime(bool first) * 1 - ncurses' normal input-descriptor * 2 - mouse descriptor, if any * 3 - either input or mouse. + * + * Experimental: if NCURSES_WGETCH_EVENTS is defined, (mode & 4) determines + * whether to pay attention to evl argument. If set, the smallest of + * millisecond and of timeout of evl is taken. + * * We return a mask that corresponds to the mode (e.g., 2 for mouse activity). * * If the milliseconds given are -1, the wait blocks until activity on the * descriptors. */ NCURSES_EXPORT(int) -_nc_timed_wait -(int mode, int milliseconds, int *timeleft) +_nc_timed_wait(SCREEN *sp, + int mode, + int milliseconds, + int *timeleft + EVENTLIST_2nd(_nc_eventlist * evl)) { int fd; int count; + int result = 0; + TimeType t0; - int result; +#ifdef NCURSES_WGETCH_EVENTS + int timeout_is_event = 0; + int n; +#endif #if USE_FUNC_POLL - struct pollfd fds[2]; +#define MIN_FDS 2 + struct pollfd fd_list[MIN_FDS]; + struct pollfd *fds = fd_list; #elif defined(__BEOS__) #elif HAVE_SELECT - static fd_set *set; - static size_t setsize; - size_t nsetsize; - int readfd; + fd_set set; #endif long starttime, returntime; - T(("start twait: %d milliseconds, mode: %d", milliseconds, mode)); + TR(TRACE_IEVENT, ("start twait: %d milliseconds, mode: %d", + milliseconds, mode)); -#if PRECISE_GETTIME +#ifdef NCURSES_WGETCH_EVENTS + if (mode & 4) { + int event_delay = _nc_eventlist_timeout(evl); + + if (event_delay >= 0 + && (milliseconds >= event_delay || milliseconds < 0)) { + milliseconds = event_delay; + timeout_is_event = 1; + } + } +#endif + +#if PRECISE_GETTIME && HAVE_NANOSLEEP retry: #endif - starttime = _nc_gettime(TRUE); + starttime = _nc_gettime(&t0, TRUE); count = 0; +#ifdef NCURSES_WGETCH_EVENTS + if ((mode & 4) && evl) + evl->result_flags = 0; +#endif + #if USE_FUNC_POLL - memset(fds, 0, sizeof(fds)); + memset(fd_list, 0, sizeof(fd_list)); + +#ifdef NCURSES_WGETCH_EVENTS + if ((mode & 4) && evl) + fds = typeMalloc(struct pollfd, MIN_FDS + evl->count); +#endif + if (mode & 1) { - fds[count].fd = SP->_ifd; + fds[count].fd = sp->_ifd; fds[count].events = POLLIN; count++; } if ((mode & 2) - && (fd = SP->_mouse_fd) >= 0) { + && (fd = sp->_mouse_fd) >= 0) { fds[count].fd = fd; fds[count].events = POLLIN; count++; } - result = poll(fds, count, milliseconds); +#ifdef NCURSES_WGETCH_EVENTS + if ((mode & 4) && evl) { + for (n = 0; n < evl->count; ++n) { + _nc_event *ev = evl->events[n]; + + if (ev->type == _NC_EVENT_FILE + && (ev->data.fev.flags & _NC_EVENT_FILE_READABLE)) { + fds[count].fd = ev->data.fev.fd; + fds[count].events = POLLIN; + count++; + } + } + } +#endif + + result = poll(fds, (unsigned) count, milliseconds); + +#ifdef NCURSES_WGETCH_EVENTS + if ((mode & 4) && evl) { + int c; + + if (!result) + count = 0; + + for (n = 0; n < evl->count; ++n) { + _nc_event *ev = evl->events[n]; + + if (ev->type == _NC_EVENT_FILE + && (ev->data.fev.flags & _NC_EVENT_FILE_READABLE)) { + ev->data.fev.result = 0; + for (c = 0; c < count; c++) + if (fds[c].fd == ev->data.fev.fd + && fds[c].revents & POLLIN) { + ev->data.fev.result |= _NC_EVENT_FILE_READABLE; + evl->result_flags |= _NC_EVENT_FILE_READABLE; + } + } else if (ev->type == _NC_EVENT_TIMEOUT_MSEC + && !result && timeout_is_event) { + evl->result_flags |= _NC_EVENT_TIMEOUT_MSEC; + } + } + } + + if (fds != fd_list) + free((char *) fds); + +#endif #elif defined(__BEOS__) /* @@ -158,73 +275,124 @@ _nc_timed_wait * * FIXME: the return values from the ioctl aren't very clear if we get * interrupted. + * + * FIXME: this assumes mode&1 if milliseconds < 0 (see lib_getch.c). */ result = 0; if (mode & 1) { + int step = (milliseconds < 0) ? 0 : 5000; bigtime_t d; bigtime_t useconds = milliseconds * 1000; int n, howmany; - if (useconds == 0) /* we're here to go _through_ the loop */ + if (useconds <= 0) /* we're here to go _through_ the loop */ useconds = 1; - for (d = 0; d < useconds; d += 5000) { + for (d = 0; d < useconds; d += step) { n = 0; howmany = ioctl(0, 'ichr', &n); if (howmany >= 0 && n > 0) { result = 1; break; } - if (useconds > 1) - snooze(5000); - milliseconds -= 5; + if (useconds > 1 && step > 0) { + snooze(step); + milliseconds -= (step / 1000); + if (milliseconds <= 0) { + milliseconds = 0; + break; + } + } } } else if (milliseconds > 0) { snooze(milliseconds * 1000); milliseconds = 0; } #elif HAVE_SELECT + /* + * select() modifies the fd_set arguments; do this in the + * loop. + */ + FD_ZERO(&set); + if (mode & 1) { - count = SP->_ifd; - readfd = SP->_ifd; + FD_SET(sp->_ifd, &set); + count = sp->_ifd + 1; } - if ((mode & 2) && (fd = SP->_mouse_fd) >= 0) { - count = max(fd, count); - readfd = fd; + if ((mode & 2) + && (fd = sp->_mouse_fd) >= 0) { + FD_SET(fd, &set); + count = max(fd, count) + 1; } +#ifdef NCURSES_WGETCH_EVENTS + if ((mode & 4) && evl) { + for (n = 0; n < evl->count; ++n) { + _nc_event *ev = evl->events[n]; - /* - * grow set as needed. - */ - nsetsize = howmany(count, NFDBITS) * sizeof(fd_mask); - if (setsize == 0 || setsize < nsetsize) { - setsize = nsetsize; - set = _nc_doalloc(set, setsize); + if (ev->type == _NC_EVENT_FILE + && (ev->data.fev.flags & _NC_EVENT_FILE_READABLE)) { + FD_SET(ev->data.fev.fd, &set); + count = max(ev->data.fev.fd + 1, count); + } + } } - - /* - * select() modifies the fd_set arguments; do this in the - * loop. - */ - memset(set, 0, setsize); - FD_SET(readfd, set); +#endif if (milliseconds >= 0) { struct timeval ntimeout; ntimeout.tv_sec = milliseconds / 1000; ntimeout.tv_usec = (milliseconds % 1000) * 1000; - result = select(count + 1, set, NULL, NULL, &ntimeout); + result = select(count, &set, NULL, NULL, &ntimeout); } else { - result = select(count + 1, set, NULL, NULL, NULL); + result = select(count, &set, NULL, NULL, NULL); + } + +#ifdef NCURSES_WGETCH_EVENTS + if ((mode & 4) && evl) { + evl->result_flags = 0; + for (n = 0; n < evl->count; ++n) { + _nc_event *ev = evl->events[n]; + + if (ev->type == _NC_EVENT_FILE + && (ev->data.fev.flags & _NC_EVENT_FILE_READABLE)) { + ev->data.fev.result = 0; + if (FD_ISSET(ev->data.fev.fd, &set)) { + ev->data.fev.result |= _NC_EVENT_FILE_READABLE; + evl->result_flags |= _NC_EVENT_FILE_READABLE; + } + } else if (ev->type == _NC_EVENT_TIMEOUT_MSEC + && !result && timeout_is_event) + evl->result_flags |= _NC_EVENT_TIMEOUT_MSEC; + } } #endif - returntime = _nc_gettime(FALSE); +#endif /* USE_FUNC_POLL, etc */ + + returntime = _nc_gettime(&t0, FALSE); if (milliseconds >= 0) milliseconds -= (returntime - starttime); -#if PRECISE_GETTIME +#ifdef NCURSES_WGETCH_EVENTS + if (evl) { + evl->result_flags = 0; + for (n = 0; n < evl->count; ++n) { + _nc_event *ev = evl->events[n]; + + if (ev->type == _NC_EVENT_TIMEOUT_MSEC) { + long diff = (returntime - starttime); + if (ev->data.timeout_msec <= diff) + ev->data.timeout_msec = 0; + else + ev->data.timeout_msec -= diff; + } + + } + } +#endif + +#if PRECISE_GETTIME && HAVE_NANOSLEEP /* * If the timeout hasn't expired, and we've gotten no data, * this is probably a system where 'select()' needs to be left @@ -232,7 +400,7 @@ _nc_timed_wait * then come back for more. */ if (result == 0 && milliseconds > 100) { - napms(100); + napms(100); /* FIXME: this won't be right if I recur! */ milliseconds -= 100; goto retry; } @@ -242,8 +410,8 @@ _nc_timed_wait if (timeleft) *timeleft = milliseconds; - T(("end twait: returned %d (%d), remaining time %d msec", - result, errno, milliseconds)); + TR(TRACE_IEVENT, ("end twait: returned %d (%d), remaining time %d msec", + result, errno, milliseconds)); /* * Both 'poll()' and 'select()' return the number of file descriptors @@ -255,7 +423,7 @@ _nc_timed_wait if (result > 0) { result = 0; #if USE_FUNC_POLL - for (count = 0; count < 2; count++) { + for (count = 0; count < MIN_FDS; count++) { if ((mode & (1 << count)) && (fds[count].revents & POLLIN)) { result |= (1 << count); @@ -265,16 +433,20 @@ _nc_timed_wait result = 1; /* redundant, but simple */ #elif HAVE_SELECT if ((mode & 2) - && (fd = SP->_mouse_fd) >= 0 - && FD_ISSET(fd, set)) + && (fd = sp->_mouse_fd) >= 0 + && FD_ISSET(fd, &set)) result |= 2; if ((mode & 1) - && FD_ISSET(SP->_ifd, set)) + && FD_ISSET(sp->_ifd, &set)) result |= 1; #endif } else result = 0; } +#ifdef NCURSES_WGETCH_EVENTS + if ((mode & 4) && evl && evl->result_flags) + result |= 4; +#endif return (result); } diff --git a/lib/libcurses/tty/lib_vidattr.c b/lib/libcurses/tty/lib_vidattr.c index 4a5c9354b72..5553a348ead 100644 --- a/lib/libcurses/tty/lib_vidattr.c +++ b/lib/libcurses/tty/lib_vidattr.c @@ -1,7 +1,7 @@ -/* $OpenBSD: lib_vidattr.c,v 1.8 2001/01/22 18:02:00 millert Exp $ */ +/* $OpenBSD: lib_vidattr.c,v 1.9 2010/01/12 23:22:07 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996 on * ****************************************************************************/ /* @@ -66,7 +67,7 @@ #include <curses.priv.h> #include <term.h> -MODULE_ID("$From: lib_vidattr.c,v 1.36 2000/12/10 03:05:48 tom Exp $") +MODULE_ID("$Id: lib_vidattr.c,v 1.9 2010/01/12 23:22:07 nicm Exp $") #define doPut(mode) TPUTS_TRACE(#mode); tputs(mode, 1, outc) @@ -88,15 +89,14 @@ MODULE_ID("$From: lib_vidattr.c,v 1.36 2000/12/10 03:05:48 tom Exp $") } \ } +#define PreviousAttr _nc_prescreen.previous_attr + NCURSES_EXPORT(int) -vidputs -(attr_t newmode, int (*outc) (int)) +vidputs(chtype newmode, int (*outc) (int)) { - static attr_t previous_attr = A_NORMAL; attr_t turn_on, turn_off; int pair; bool reverse = FALSE; - bool used_ncv = FALSE; bool can_color = (SP == 0 || SP->_coloron); #if NCURSES_EXT_FUNCS bool fix_pair0 = (SP != 0 && SP->_coloron && !SP->_default_color); @@ -104,19 +104,56 @@ vidputs #define fix_pair0 FALSE #endif + newmode &= A_ATTRIBUTES; T((T_CALLED("vidputs(%s)"), _traceattr(newmode))); /* this allows us to go on whether or not newterm() has been called */ if (SP) - previous_attr = SP->_current_attr; + PreviousAttr = AttrOf(SCREEN_ATTRS(SP)); - TR(TRACE_ATTRS, ("previous attribute was %s", _traceattr(previous_attr))); + TR(TRACE_ATTRS, ("previous attribute was %s", _traceattr(PreviousAttr))); -#if !USE_XMC_SUPPORT if ((SP != 0) - && (magic_cookie_glitch > 0)) + && (magic_cookie_glitch > 0)) { +#if USE_XMC_SUPPORT + static const chtype table[] = + { + A_STANDOUT, + A_UNDERLINE, + A_REVERSE, + A_BLINK, + A_DIM, + A_BOLD, + A_INVIS, + A_PROTECT, + }; + unsigned n; + int used = 0; + int limit = (max_attributes <= 0) ? 1 : max_attributes; + chtype retain = 0; + + /* + * Limit the number of attribute bits set in the newmode according to + * the terminfo max_attributes value. + */ + for (n = 0; n < SIZEOF(table); ++n) { + if ((table[n] & SP->_ok_attributes) == 0) { + newmode &= ~table[n]; + } else if ((table[n] & newmode) != 0) { + if (used++ >= limit) { + newmode &= ~table[n]; + if (newmode == retain) + break; + } else { + retain = newmode; + } + } + } +#else newmode &= ~(SP->_xmc_suppress); #endif + TR(TRACE_ATTRS, ("suppressed attribute is %s", _traceattr(newmode))); + } /* * If we have a terminal that cannot combine color with video @@ -150,7 +187,7 @@ vidputs newmode &= ~mask; } - if (newmode == previous_attr) + if (newmode == PreviousAttr) returnCode(OK); pair = PAIR_NUMBER(newmode); @@ -159,17 +196,17 @@ vidputs newmode &= ~A_REVERSE; } - turn_off = (~newmode & previous_attr) & ALL_BUT_COLOR; - turn_on = (newmode & ~previous_attr) & ALL_BUT_COLOR; + turn_off = (~newmode & PreviousAttr) & ALL_BUT_COLOR; + turn_on = (newmode & ~PreviousAttr) & ALL_BUT_COLOR; - SetColorsIf(((pair == 0) && !fix_pair0), previous_attr); + SetColorsIf(((pair == 0) && !fix_pair0), PreviousAttr); if (newmode == A_NORMAL) { - if ((previous_attr & A_ALTCHARSET) && exit_alt_charset_mode) { + if ((PreviousAttr & A_ALTCHARSET) && exit_alt_charset_mode) { doPut(exit_alt_charset_mode); - previous_attr &= ~A_ALTCHARSET; + PreviousAttr &= ~A_ALTCHARSET; } - if (previous_attr) { + if (PreviousAttr) { if (exit_attribute_mode) { doPut(exit_attribute_mode); } else { @@ -180,11 +217,11 @@ vidputs TurnOff(A_STANDOUT, exit_standout_mode); } } - previous_attr &= ~A_COLOR; + PreviousAttr &= ALL_BUT_COLOR; } - SetColorsIf((pair != 0) || fix_pair0, previous_attr); - } else if (set_attributes && !used_ncv) { + SetColorsIf((pair != 0) || fix_pair0, PreviousAttr); + } else if (set_attributes) { if (turn_on || turn_off) { TPUTS_TRACE("set_attributes"); tputs(tparm(set_attributes, @@ -197,9 +234,9 @@ vidputs (newmode & A_INVIS) != 0, (newmode & A_PROTECT) != 0, (newmode & A_ALTCHARSET) != 0), 1, outc); - previous_attr &= ~A_COLOR; + PreviousAttr &= ALL_BUT_COLOR; } - SetColorsIf((pair != 0) || fix_pair0, previous_attr); + SetColorsIf((pair != 0) || fix_pair0, PreviousAttr); } else { TR(TRACE_ATTRS, ("turning %s off", _traceattr(turn_off))); @@ -216,10 +253,10 @@ vidputs if (turn_off && exit_attribute_mode) { doPut(exit_attribute_mode); - turn_on |= (newmode & (chtype) (~A_COLOR)); - previous_attr &= ~A_COLOR; + turn_on |= (newmode & ALL_BUT_COLOR); + PreviousAttr &= ALL_BUT_COLOR; } - SetColorsIf((pair != 0) || fix_pair0, previous_attr); + SetColorsIf((pair != 0) || fix_pair0, PreviousAttr); TR(TRACE_ATTRS, ("turning %s on", _traceattr(turn_on))); /* *INDENT-OFF* */ @@ -232,12 +269,14 @@ vidputs TurnOn(A_PROTECT, enter_protected_mode); TurnOn(A_INVIS, enter_secure_mode); TurnOn(A_UNDERLINE, enter_underline_mode); +#if USE_WIDEC_SUPPORT TurnOn(A_HORIZONTAL, enter_horizontal_hl_mode); TurnOn(A_LEFT, enter_left_hl_mode); TurnOn(A_LOW, enter_low_hl_mode); TurnOn(A_RIGHT, enter_right_hl_mode); TurnOn(A_TOP, enter_top_hl_mode); TurnOn(A_VERTICAL, enter_vertical_hl_mode); +#endif /* *INDENT-ON* */ } @@ -246,15 +285,15 @@ vidputs newmode |= A_REVERSE; if (SP) - SP->_current_attr = newmode; + SetAttr(SCREEN_ATTRS(SP), newmode); else - previous_attr = newmode; + PreviousAttr = newmode; returnCode(OK); } NCURSES_EXPORT(int) -vidattr(attr_t newmode) +vidattr(chtype newmode) { T((T_CALLED("vidattr(%s)"), _traceattr(newmode))); diff --git a/lib/libcurses/tty/tty_display.h b/lib/libcurses/tty/tty_display.h index f1e0f47e1d1..f62abe2891a 100644 --- a/lib/libcurses/tty/tty_display.h +++ b/lib/libcurses/tty/tty_display.h @@ -1,7 +1,7 @@ -/* $OpenBSD: tty_display.h,v 1.3 2001/01/22 18:02:00 millert Exp $ */ +/* $OpenBSD: tty_display.h,v 1.4 2010/01/12 23:22:07 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2003,2004 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,6 +31,9 @@ #ifndef TTY_DISPLAY_H #define TTY_DISPLAY_H 1 +/* + * $Id: tty_display.h,v 1.4 2010/01/12 23:22:07 nicm Exp $ + */ extern NCURSES_EXPORT(bool) _nc_tty_beep (void); extern NCURSES_EXPORT(bool) _nc_tty_check_resize (void); extern NCURSES_EXPORT(bool) _nc_tty_cursor (int); @@ -113,11 +116,11 @@ struct tty_display_data { : ((enter_insert_mode && exit_insert_mode) \ ? D->_smir_cost + D->_rmir_cost + (D->_ip_cost * count) \ : ((insert_character != 0) \ - ? (D->_ich1_cost * count) \ + ? ((D->_ich1_cost + D->_ip_cost) * count) \ : INFINITY))) #if USE_XMC_SUPPORT -#define UpdateAttrs(c) if (D->_current_attr != AttrOf(c)) { \ +#define UpdateAttrs(c) if (!SameAttrOf(D->_current_attr, AttrOf(c))) { \ attr_t chg = D->_current_attr; \ vidattr(AttrOf(c)); \ if (magic_cookie_glitch > 0 \ @@ -130,7 +133,7 @@ struct tty_display_data { } \ } #else -#define UpdateAttrs(c) if (D->_current_attr != AttrOf(c)) \ +#define UpdateAttrs(c) if (!SameAttrOf(D->_current_attr, AttrOf(c))) \ vidattr(AttrOf(c)); #endif diff --git a/lib/libcurses/tty/tty_input.h b/lib/libcurses/tty/tty_input.h index 21f551a49a2..cff0bb54e4b 100644 --- a/lib/libcurses/tty/tty_input.h +++ b/lib/libcurses/tty/tty_input.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tty_input.h,v 1.2 2001/01/22 18:02:00 millert Exp $ */ +/* $OpenBSD: tty_input.h,v 1.3 2010/01/12 23:22:07 nicm Exp $ */ /**************************************************************************** * Copyright (c) 1998,2000 Free Software Foundation, Inc. * @@ -29,7 +29,7 @@ ****************************************************************************/ /* - * $From: tty_input.h,v 1.2 2000/12/10 02:26:51 tom Exp $ + * $Id: tty_input.h,v 1.3 2010/01/12 23:22:07 nicm Exp $ */ #ifndef TTY_INPUT_H diff --git a/lib/libcurses/tty/tty_update.c b/lib/libcurses/tty/tty_update.c index 28b6b99927e..bd2f088adf6 100644 --- a/lib/libcurses/tty/tty_update.c +++ b/lib/libcurses/tty/tty_update.c @@ -1,7 +1,7 @@ -/* $OpenBSD: tty_update.c,v 1.15 2001/02/22 04:16:35 millert Exp $ */ +/* $OpenBSD: tty_update.c,v 1.16 2010/01/12 23:22:07 nicm Exp $ */ /**************************************************************************** - * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -31,24 +31,31 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * * and: Eric S. Raymond <esr@snark.thyrsus.com> * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /*----------------------------------------------------------------- * * lib_doupdate.c * - * The routine doupdate() and its dependents. Also _nc_outstr(), - * so all physical output is concentrated here (except _nc_outch() - * in lib_tputs.c). + * The routine doupdate() and its dependents. + * All physical output is concentrated here (except _nc_outch() + * in lib_tputs.c). * *-----------------------------------------------------------------*/ +#include <curses.priv.h> + +#if defined __HAIKU__ && defined __BEOS__ +#undef __BEOS__ +#endif + #ifdef __BEOS__ +#undef false +#undef true #include <OS.h> #endif -#include <curses.priv.h> - #if defined(TRACE) && HAVE_SYS_TIMES_H && HAVE_TIMES #define USE_TRACE_TIMES 1 #else @@ -70,9 +77,10 @@ #endif #endif +#include <ctype.h> #include <term.h> -MODULE_ID("$From: tty_update.c,v 1.151 2001/02/03 23:41:55 tom Exp $") +MODULE_ID("$Id: tty_update.c,v 1.16 2010/01/12 23:22:07 nicm Exp $") /* * This define controls the line-breakout optimization. Every once in a @@ -87,6 +95,9 @@ MODULE_ID("$From: tty_update.c,v 1.151 2001/02/03 23:41:55 tom Exp $") #define FILL_BCE() (SP->_coloron && !SP->_default_color && !back_color_erase) +static const NCURSES_CH_T blankchar = NewChar(BLANK_TEXT); +static NCURSES_CH_T normal = NewChar(BLANK_TEXT); + /* * Enable checking to see if doupdate and friends are tracking the true * cursor position correctly. NOTE: this is a debugging hack which will @@ -94,12 +105,12 @@ MODULE_ID("$From: tty_update.c,v 1.151 2001/02/03 23:41:55 tom Exp $") */ /* #define POSITION_DEBUG */ -static inline chtype ClrBlank(WINDOW *win); +static NCURSES_INLINE NCURSES_CH_T ClrBlank(WINDOW *win); static int ClrBottom(int total); -static void ClearScreen(chtype blank); +static void ClearScreen(NCURSES_CH_T blank); static void ClrUpdate(void); static void DelChar(int count); -static void InsStr(chtype * line, int count); +static void InsStr(NCURSES_CH_T * line, int count); static void TransformLine(int const lineno); #ifdef POSITION_DEBUG @@ -162,56 +173,131 @@ position_check(int expected_y, int expected_x, char *legend) * ****************************************************************************/ -static inline void +static NCURSES_INLINE void GoTo(int const row, int const col) { - chtype oldattr = SP->_current_attr; - TR(TRACE_MOVE, ("GoTo(%d, %d) from (%d, %d)", row, col, SP->_cursrow, SP->_curscol)); position_check(SP->_cursrow, SP->_curscol, "GoTo"); - /* - * Force restore even if msgr is on when we're in an alternate - * character set -- these have a strong tendency to screw up the - * CR & LF used for local character motions! - */ - if ((oldattr & A_ALTCHARSET) - || (oldattr && !move_standout_mode)) { - TR(TRACE_CHARPUT, ("turning off (%#lx) %s before move", - oldattr, _traceattr(oldattr))); - vidattr(A_NORMAL); - } - mvcur(SP->_cursrow, SP->_curscol, row, col); - SP->_cursrow = row; - SP->_curscol = col; position_check(SP->_cursrow, SP->_curscol, "GoTo2"); } -static inline void -PutAttrChar(chtype ch) +static NCURSES_INLINE void +PutAttrChar(CARG_CH_T ch) { - int data; - - if (tilde_glitch && (TextOf(ch) == '~')) - ch = ('`' | AttrOf(ch)); + int chlen = 1; + NCURSES_CH_T my_ch; + PUTC_DATA; + NCURSES_CH_T tilde; + NCURSES_CH_T attr = CHDEREF(ch); TR(TRACE_CHARPUT, ("PutAttrChar(%s) at (%d, %d)", - _tracechtype(ch), + _tracech_t(ch), SP->_cursrow, SP->_curscol)); - UpdateAttrs(ch); - data = TextOf(ch); +#if USE_WIDEC_SUPPORT + /* + * If this is not a valid character, there is nothing more to do. + */ + if (isWidecExt(CHDEREF(ch))) { + TR(TRACE_CHARPUT, ("...skip")); + return; + } + /* + * Determine the number of character cells which the 'ch' value will use + * on the screen. It should be at least one. + */ + if ((chlen = wcwidth(CharOf(CHDEREF(ch)))) <= 0) { + static const NCURSES_CH_T blank = NewChar(BLANK_TEXT); + + /* + * If the character falls into any of these special cases, do + * not force the result to a blank: + * + * a) it is printable (this works around a bug in wcwidth()). + * b) use_legacy_coding() has been called to modify the treatment + * of codes 128-255. + * c) the acs_map[] has been initialized to allow codes 0-31 + * to be rendered. This supports Linux console's "PC" + * characters. Codes 128-255 are allowed though this is + * not checked. + */ + if (is8bits(CharOf(CHDEREF(ch))) + && (isprint(CharOf(CHDEREF(ch))) + || (SP->_legacy_coding > 0 && CharOf(CHDEREF(ch)) >= 160) + || (SP->_legacy_coding > 1 && CharOf(CHDEREF(ch)) >= 128) + || (AttrOf(attr) & A_ALTCHARSET + && ((CharOfD(ch) < ACS_LEN + && SP->_acs_map != 0 + && SP->_acs_map[CharOfD(ch)] != 0) + || (CharOfD(ch) >= 128))))) { + ; + } else { + ch = CHREF(blank); + TR(TRACE_CHARPUT, ("forced to blank")); + } + chlen = 1; + } +#endif + + if ((AttrOf(attr) & A_ALTCHARSET) + && SP->_acs_map != 0 + && CharOfD(ch) < ACS_LEN) { + my_ch = CHDEREF(ch); /* work around const param */ +#if USE_WIDEC_SUPPORT + /* + * This is crude & ugly, but works most of the time. It checks if the + * acs_chars string specified that we have a mapping for this + * character, and uses the wide-character mapping when we expect the + * normal one to be broken (by mis-design ;-). + */ + if (SP->_screen_acs_fix + && SP->_screen_acs_map[CharOf(my_ch)]) { + RemAttr(attr, A_ALTCHARSET); + my_ch = _nc_wacs[CharOf(my_ch)]; + } +#endif + /* + * If we (still) have alternate character set, it is the normal 8bit + * flavor. The _screen_acs_map[] array tells if the character was + * really in acs_chars, needed because of the way wide/normal line + * drawing flavors are integrated. + */ + if (AttrOf(attr) & A_ALTCHARSET) { + int j = CharOfD(ch); + chtype temp = UChar(SP->_acs_map[j]); + + if (!(SP->_screen_acs_map[j])) { + RemAttr(attr, A_ALTCHARSET); + if (temp == 0) + temp = ' '; + } + if (temp != 0) + SetChar(my_ch, temp, AttrOf(attr)); + } + ch = CHREF(my_ch); + } + if (tilde_glitch && (CharOfD(ch) == L('~'))) { + SetChar(tilde, L('`'), AttrOf(attr)); + ch = CHREF(tilde); + } + + UpdateAttrs(attr); +#if !USE_WIDEC_SUPPORT + /* FIXME - we do this special case for signal handling, should see how to + * make it work for wide characters. + */ if (SP->_outch != 0) { - SP->_outch(data); - } else { - putc(data, SP->_ofp); /* macro's fastest... */ -#ifdef TRACE - _nc_outchars++; -#endif /* TRACE */ + SP->_outch(UChar(ch)); + } else +#endif + { + PUTC(CHDEREF(ch), SP->_ofp); /* macro's fastest... */ + COUNT_OUTCHARS(1); } - SP->_curscol++; + SP->_curscol += chlen; if (char_padding) { TPUTS_TRACE("char_padding"); putp(char_padding); @@ -256,19 +342,16 @@ check_pending(void) have_pending = TRUE; } #elif HAVE_SELECT - fd_set *fdset; + fd_set fdset; struct timeval ktimeout; ktimeout.tv_sec = ktimeout.tv_usec = 0; - fdset = calloc(howmany(SP->_checkfd + 1, NFDBITS), sizeof(fd_mask)); - if (fdset != NULL) { - FD_SET(SP->_checkfd, fdset); - if (select(SP->_checkfd + 1, fdset, NULL, NULL, &ktimeout) != 0) { - have_pending = TRUE; - } - free(fdset); + FD_ZERO(&fdset); + FD_SET(SP->_checkfd, &fdset); + if (select(SP->_checkfd + 1, &fdset, NULL, NULL, &ktimeout) != 0) { + have_pending = TRUE; } #endif } @@ -281,7 +364,7 @@ check_pending(void) /* put char at lower right corner */ static void -PutCharLR(chtype const ch) +PutCharLR(const ARG_CH_T ch) { if (!auto_right_margin) { /* we can put the char directly */ @@ -306,39 +389,49 @@ PutCharLR(chtype const ch) } } +/* + * Wrap the cursor position, i.e., advance to the beginning of the next line. + */ static void wrap_cursor(void) { if (eat_newline_glitch) { /* - * xenl can manifest two different ways. The vt100 - * way is that, when you'd expect the cursor to wrap, - * it stays hung at the right margin (on top of the - * character just emitted) and doesn't wrap until the - * *next* graphic char is emitted. The c100 way is - * to ignore LF received just after an am wrap. + * xenl can manifest two different ways. The vt100 way is that, when + * you'd expect the cursor to wrap, it stays hung at the right margin + * (on top of the character just emitted) and doesn't wrap until the + * *next* graphic char is emitted. The c100 way is to ignore LF + * received just after an am wrap. * - * An aggressive way to handle this would be to - * emit CR/LF after the char and then assume the wrap - * is done, you're on the first position of the next - * line, and the terminal out of its weird state. - * Here it's safe to just tell the code that the - * cursor is in hyperspace and let the next mvcur() - * call straighten things out. + * An aggressive way to handle this would be to emit CR/LF after the + * char and then assume the wrap is done, you're on the first position + * of the next line, and the terminal out of its weird state. Here + * it's safe to just tell the code that the cursor is in hyperspace and + * let the next mvcur() call straighten things out. */ SP->_curscol = -1; SP->_cursrow = -1; } else if (auto_right_margin) { SP->_curscol = 0; SP->_cursrow++; + /* + * We've actually moved - but may have to work around problems with + * video attributes not working. + */ + if (!move_standout_mode && AttrOf(SCREEN_ATTRS(SP))) { + TR(TRACE_CHARPUT, ("turning off (%#lx) %s before wrapping", + (unsigned long) AttrOf(SCREEN_ATTRS(SP)), + _traceattr(AttrOf(SCREEN_ATTRS(SP))))); + (void) VIDATTR(A_NORMAL, 0); + } } else { SP->_curscol--; } position_check(SP->_cursrow, SP->_curscol, "wrap_cursor"); } -static inline void -PutChar(chtype const ch) +static NCURSES_INLINE void +PutChar(const ARG_CH_T ch) /* insert character, handling automargin stuff */ { if (SP->_cursrow == screen_lines - 1 && SP->_curscol == screen_columns - 1) @@ -358,20 +451,30 @@ PutChar(chtype const ch) * as A_REVERSE. All attribute flags which don't affect appearance of a space * or can be output by clearing (A_COLOR in case of bce-terminal) are excluded. */ -static inline bool -can_clear_with(chtype ch) +static NCURSES_INLINE bool +can_clear_with(ARG_CH_T ch) { if (!back_color_erase && SP->_coloron) { - if (ch & A_COLOR) - return FALSE; #if NCURSES_EXT_FUNCS + int pair; + if (!SP->_default_color) return FALSE; if (SP->_default_fg != C_MASK || SP->_default_bg != C_MASK) return FALSE; + if ((pair = GetPair(CHDEREF(ch))) != 0) { + short fg, bg; + pair_content(pair, &fg, &bg); + if (fg != C_MASK || bg != C_MASK) + return FALSE; + } +#else + if (AttrOfD(ch) & A_COLOR) + return FALSE; #endif } - return ((ch & ~(NONBLANK_ATTR | A_COLOR)) == BLANK); + return (ISBLANK(CHDEREF(ch)) && + (AttrOfD(ch) & ~(NONBLANK_ATTR | A_COLOR)) == BLANK_ATTR); } /* @@ -387,28 +490,30 @@ can_clear_with(chtype ch) * This code is optimized using ech and rep. */ static int -EmitRange(const chtype * ntext, int num) +EmitRange(const NCURSES_CH_T * ntext, int num) { int i; + TR(TRACE_CHARPUT, ("EmitRange %d:%s", num, _nc_viscbuf(ntext, num))); + if (erase_chars || repeat_char) { while (num > 0) { int runcount; - chtype ntext0; + NCURSES_CH_T ntext0; - while (num > 1 && ntext[0] != ntext[1]) { - PutChar(ntext[0]); + while (num > 1 && !CharEq(ntext[0], ntext[1])) { + PutChar(CHREF(ntext[0])); ntext++; num--; } ntext0 = ntext[0]; if (num == 1) { - PutChar(ntext0); + PutChar(CHREF(ntext0)); return 0; } runcount = 2; - while (runcount < num && ntext[runcount] == ntext0) + while (runcount < num && CharEq(ntext[runcount], ntext0)) runcount++; /* @@ -421,9 +526,9 @@ EmitRange(const chtype * ntext, int num) */ if (erase_chars && runcount > SP->_ech_cost + SP->_cup_ch_cost - && can_clear_with(ntext0)) { + && can_clear_with(CHREF(ntext0))) { UpdateAttrs(ntext0); - putp(tparm(erase_chars, runcount)); + putp(TPARM_1(erase_chars, runcount)); /* * If this is the last part of the given interval, @@ -443,14 +548,15 @@ EmitRange(const chtype * ntext, int num) rep_count--; UpdateAttrs(ntext0); - putp(tparm(repeat_char, TextOf(ntext0), rep_count)); + tputs(TPARM_2(repeat_char, CharOf(ntext0), rep_count), + rep_count, _nc_outch); SP->_curscol += rep_count; if (wrap_possible) - PutChar(ntext0); + PutChar(CHREF(ntext0)); } else { for (i = 0; i < runcount; i++) - PutChar(ntext[i]); + PutChar(CHREF(ntext[i])); } ntext += runcount; num -= runcount; @@ -459,7 +565,7 @@ EmitRange(const chtype * ntext, int num) } for (i = 0; i < num; i++) - PutChar(ntext[i]); + PutChar(CHREF(ntext[i])); return 0; } @@ -472,31 +578,37 @@ EmitRange(const chtype * ntext, int num) * Returns: same as EmitRange */ static int -PutRange( - const chtype * otext, - const chtype * ntext, - int row, - int first, int last) +PutRange(const NCURSES_CH_T * otext, + const NCURSES_CH_T * ntext, + int row, + int first, int last) { - int j, run; + int i, j, same; TR(TRACE_CHARPUT, ("PutRange(%p, %p, %d, %d, %d)", otext, ntext, row, first, last)); if (otext != ntext && (last - first + 1) > SP->_inline_cost) { - for (j = first, run = 0; j <= last; j++) { - if (otext[j] == ntext[j]) { - run++; + for (j = first, same = 0; j <= last; j++) { + if (!same && isWidecExt(otext[j])) + continue; + if (CharEq(otext[j], ntext[j])) { + same++; } else { - if (run > SP->_inline_cost) { - int before_run = (j - run); - EmitRange(ntext + first, before_run - first); + if (same > SP->_inline_cost) { + EmitRange(ntext + first, j - same - first); GoTo(row, first = j); } - run = 0; + same = 0; } } + i = EmitRange(ntext + first, j - same - first); + /* + * Always return 1 for the next GoTo() after a PutRange() if we found + * identical characters at end of interval + */ + return (same == 0 ? i : 1); } return EmitRange(ntext + first, last - first + 1); } @@ -518,13 +630,18 @@ doupdate(void) T((T_CALLED("doupdate()"))); + if (curscr == 0 + || newscr == 0) + returnCode(ERR); + #ifdef TRACE - if (_nc_tracing & TRACE_UPDATE) { + if (USE_TRACEF(TRACE_UPDATE)) { if (curscr->_clear) _tracef("curscr is clear"); else _tracedump("curscr", curscr); _tracedump("newscr", newscr); + _nc_unlock_global(tracef); } #endif /* TRACE */ @@ -534,7 +651,7 @@ doupdate(void) SP->_fifohold--; #if USE_SIZECHANGE - if (SP->_endwin || SP->_sig_winch) { + if (SP->_endwin || _nc_handle_sigwinch(SP)) { /* * This is a transparent extension: XSI does not address it, * and applications need not know that ncurses can do it. @@ -543,7 +660,7 @@ doupdate(void) * (this can happen in an xterm, for example), and resize the * ncurses data structures accordingly. */ - _nc_update_screensize(); + _nc_update_screensize(SP); } #endif @@ -560,22 +677,20 @@ doupdate(void) } #if USE_TRACE_TIMES /* zero the metering machinery */ - _nc_outchars = 0; + RESET_OUTCHARS(); (void) times(&before); #endif /* USE_TRACE_TIMES */ /* - * This is the support for magic-cookie terminals. The - * theory: we scan the virtual screen looking for attribute - * turnons. Where we find one, check to make sure it's - * realizable by seeing if the required number of - * un-attributed blanks are present before and after the - * attributed range; try to shift the range boundaries over - * blanks (not changing the screen display) so this becomes - * true. If it is, shift the beginning attribute change - * appropriately (the end one, if we've gotten this far, is - * guaranteed room for its cookie). If not, nuke the added - * attributes out of the span. + * This is the support for magic-cookie terminals. The theory: we scan + * the virtual screen looking for attribute turnons. Where we find one, + * check to make sure it's realizable by seeing if the required number of + * un-attributed blanks are present before and after the attributed range; + * try to shift the range boundaries over blanks (not changing the screen + * display) so this becomes true. If it is, shift the beginning attribute + * change appropriately (the end one, if we've gotten this far, is + * guaranteed room for its cookie). If not, nuke the added attributes out + * of the span. */ #if USE_XMC_SUPPORT if (magic_cookie_glitch > 0) { @@ -585,11 +700,13 @@ doupdate(void) for (i = 0; i < screen_lines; i++) { for (j = 0; j < screen_columns; j++) { bool failed = FALSE; - chtype turnon = AttrOf(newscr->_line[i].text[j]) & ~rattr; + NCURSES_CH_T *thisline = newscr->_line[i].text; + attr_t thisattr = AttrOf(thisline[j]) & SP->_xmc_triggers; + attr_t turnon = thisattr & ~rattr; /* is an attribute turned on here? */ if (turnon == 0) { - rattr = AttrOf(newscr->_line[i].text[j]); + rattr = thisattr; continue; } @@ -597,23 +714,33 @@ doupdate(void) TR(TRACE_ATTRS, ("...to %s", _traceattr(turnon))); /* - * If the attribute change location is a blank with a - * "safe" attribute, undo the attribute turnon. This may - * ensure there's enough room to set the attribute before - * the first non-blank in the run. + * If the attribute change location is a blank with a "safe" + * attribute, undo the attribute turnon. This may ensure + * there's enough room to set the attribute before the first + * non-blank in the run. */ -#define SAFE(a) (!((a) & (chtype)~NONBLANK_ATTR)) - if (TextOf(newscr->_line[i].text[j]) == ' ' && SAFE(turnon)) { - newscr->_line[i].text[j] &= ~turnon; +#define SAFE(a) (!((a) & SP->_xmc_triggers)) + if (ISBLANK(thisline[j]) && SAFE(turnon)) { + RemAttr(thisline[j], turnon); continue; } /* check that there's enough room at start of span */ for (k = 1; k <= magic_cookie_glitch; k++) { if (j - k < 0 - || TextOf(newscr->_line[i].text[j - k]) != ' ' - || !SAFE(AttrOf(newscr->_line[i].text[j - k]))) + || !ISBLANK(thisline[j - k]) + || !SAFE(AttrOf(thisline[j - k]))) { failed = TRUE; + TR(TRACE_ATTRS, ("No room at start in %d,%d%s%s", + i, j - k, + (ISBLANK(thisline[j - k]) + ? "" + : ":nonblank"), + (SAFE(AttrOf(thisline[j - k])) + ? "" + : ":unsafe"))); + break; + } } if (!failed) { bool end_onscreen = FALSE; @@ -622,7 +749,8 @@ doupdate(void) /* find end of span, if it's onscreen */ for (m = i; m < screen_lines; m++) { for (; n < screen_columns; n++) { - if (AttrOf(newscr->_line[m].text[n]) == rattr) { + attr_t testattr = AttrOf(newscr->_line[m].text[n]); + if ((testattr & SP->_xmc_triggers) == rattr) { end_onscreen = TRUE; TR(TRACE_ATTRS, ("Range attributed with %s ends at (%d, %d)", @@ -638,25 +766,37 @@ doupdate(void) foundit:; if (end_onscreen) { - chtype *lastline = newscr->_line[m].text; + NCURSES_CH_T *lastline = newscr->_line[m].text; /* - * If there are safely-attributed blanks at the - * end of the range, shorten the range. This will - * help ensure that there is enough room at end - * of span. + * If there are safely-attributed blanks at the end of + * the range, shorten the range. This will help ensure + * that there is enough room at end of span. */ while (n >= 0 - && TextOf(lastline[n]) == ' ' - && SAFE(AttrOf(lastline[n]))) - lastline[n--] &= ~turnon; + && ISBLANK(lastline[n]) + && SAFE(AttrOf(lastline[n]))) { + RemAttr(lastline[n--], turnon); + } /* check that there's enough room at end of span */ - for (k = 1; k <= magic_cookie_glitch; k++) + for (k = 1; k <= magic_cookie_glitch; k++) { if (n + k >= screen_columns - || TextOf(lastline[n + k]) != ' ' - || !SAFE(AttrOf(lastline[n + k]))) + || !ISBLANK(lastline[n + k]) + || !SAFE(AttrOf(lastline[n + k]))) { failed = TRUE; + TR(TRACE_ATTRS, + ("No room at end in %d,%d%s%s", + i, j - k, + (ISBLANK(lastline[n + k]) + ? "" + : ":nonblank"), + (SAFE(AttrOf(lastline[n + k])) + ? "" + : ":unsafe"))); + break; + } + } } } @@ -670,9 +810,10 @@ doupdate(void) /* turn off new attributes over span */ for (p = i; p < screen_lines; p++) { for (; q < screen_columns; q++) { - if (AttrOf(newscr->_line[p].text[q]) == rattr) + attr_t testattr = AttrOf(newscr->_line[p].text[q]); + if ((testattr & SP->_xmc_triggers) == rattr) goto foundend; - newscr->_line[p].text[q] &= ~turnon; + RemAttr(newscr->_line[p].text[q], turnon); } q = 0; } @@ -683,22 +824,23 @@ doupdate(void) _traceattr(turnon), i, j)); /* - * back up the start of range so there's room - * for cookies before the first nonblank character + * Back up the start of range so there's room for cookies + * before the first nonblank character. */ for (k = 1; k <= magic_cookie_glitch; k++) - newscr->_line[i].text[j - k] |= turnon; + AddAttr(thisline[j - k], turnon); } - rattr = AttrOf(newscr->_line[i].text[j]); + rattr = thisattr; } } #ifdef TRACE /* show altered highlights after magic-cookie check */ - if (_nc_tracing & TRACE_UPDATE) { + if (USE_TRACEF(TRACE_UPDATE)) { _tracef("After magic-cookie check..."); _tracedump("newscr", newscr); + _nc_unlock_global(tracef); } #endif /* TRACE */ } @@ -706,7 +848,6 @@ doupdate(void) nonempty = 0; if (curscr->_clear || newscr->_clear) { /* force refresh ? */ - TR(TRACE_UPDATE, ("clearing and updating from scratch")); ClrUpdate(); curscr->_clear = FALSE; /* reset flag */ newscr->_clear = FALSE; /* reset flag */ @@ -774,21 +915,26 @@ doupdate(void) cleanup: /* - * Keep the physical screen in normal mode in case we get other - * processes writing to the screen. + * We would like to keep the physical screen in normal mode in case we get + * other processes writing to the screen. This goal cannot be met for + * magic cookies since it interferes with attributes that may propagate + * past the current position. */ - UpdateAttrs(A_NORMAL); +#if USE_XMC_SUPPORT + if (magic_cookie_glitch != 0) +#endif + UpdateAttrs(normal); _nc_flush(); - curscr->_attrs = newscr->_attrs; + WINDOW_ATTRS(curscr) = WINDOW_ATTRS(newscr); #if USE_TRACE_TIMES (void) times(&after); TR(TRACE_TIMES, ("Update cost: %ld chars, %ld clocks system time, %ld clocks user time", _nc_outchars, - after.tms_stime - before.tms_stime, - after.tms_utime - before.tms_utime)); + (long) (after.tms_stime - before.tms_stime), + (long) (after.tms_utime - before.tms_utime))); #endif /* USE_TRACE_TIMES */ _nc_signal_handler(TRUE); @@ -807,14 +953,14 @@ doupdate(void) * in the wbkgd() call. Assume 'stdscr' for this case. */ #define BCE_ATTRS (A_NORMAL|A_COLOR) -#define BCE_BKGD(win) (((win) == curscr ? stdscr : (win))->_bkgd) +#define BCE_BKGD(win) (((win) == curscr ? stdscr : (win))->_nc_bkgd) -static inline chtype +static NCURSES_INLINE NCURSES_CH_T ClrBlank(WINDOW *win) { - chtype blank = BLANK; + NCURSES_CH_T blank = blankchar; if (back_color_erase) - blank |= (BCE_BKGD(win) & BCE_ATTRS); + AddAttr(blank, (AttrOf(BCE_BKGD(win)) & BCE_ATTRS)); return blank; } @@ -829,10 +975,10 @@ static void ClrUpdate(void) { int i; - chtype blank = ClrBlank(stdscr); + NCURSES_CH_T blank = ClrBlank(stdscr); int nonempty = min(screen_lines, newscr->_maxy + 1); - TR(TRACE_UPDATE, ("ClrUpdate() called")); + TR(TRACE_UPDATE, (T_CALLED("ClrUpdate"))); ClearScreen(blank); @@ -842,6 +988,8 @@ ClrUpdate(void) for (i = 0; i < nonempty; i++) TransformLine(i); + + TR(TRACE_UPDATE, (T_RETURN(""))); } /* @@ -851,7 +999,7 @@ ClrUpdate(void) */ static void -ClrToEOL(chtype blank, bool needclear) +ClrToEOL(NCURSES_CH_T blank, bool needclear) { int j; @@ -859,9 +1007,9 @@ ClrToEOL(chtype blank, bool needclear) && SP->_cursrow >= 0) { for (j = SP->_curscol; j < screen_columns; j++) { if (j >= 0) { - chtype *cp = &(curscr->_line[SP->_cursrow].text[j]); + NCURSES_CH_T *cp = &(curscr->_line[SP->_cursrow].text[j]); - if (*cp != blank) { + if (!CharEq(*cp, blank)) { *cp = blank; needclear = TRUE; } @@ -874,12 +1022,12 @@ ClrToEOL(chtype blank, bool needclear) if (needclear) { UpdateAttrs(blank); TPUTS_TRACE("clr_eol"); - if (SP->_el_cost > (screen_columns - SP->_curscol)) { + if (clr_eol && SP->_el_cost <= (screen_columns - SP->_curscol)) { + putp(clr_eol); + } else { int count = (screen_columns - SP->_curscol); while (count-- > 0) - PutChar(blank); - } else { - putp(clr_eol); + PutChar(CHREF(blank)); } } } @@ -891,7 +1039,7 @@ ClrToEOL(chtype blank, bool needclear) */ static void -ClrToEOS(chtype blank) +ClrToEOS(NCURSES_CH_T blank) { int row, col; @@ -925,39 +1073,51 @@ ClrBottom(int total) int col; int top = total; int last = min(screen_columns, newscr->_maxx + 1); - chtype blank = ClrBlank(stdscr); + NCURSES_CH_T blank = newscr->_line[total - 1].text[last - 1]; bool ok; - if (clr_eos && can_clear_with(blank)) { + if (clr_eos && can_clear_with(CHREF(blank))) { for (row = total - 1; row >= 0; row--) { for (col = 0, ok = TRUE; ok && col < last; col++) { - ok = (newscr->_line[row].text[col] == blank); + ok = (CharEq(newscr->_line[row].text[col], blank)); } if (!ok) break; for (col = 0; ok && col < last; col++) { - ok = (curscr->_line[row].text[col] == blank); + ok = (CharEq(curscr->_line[row].text[col], blank)); } if (!ok) top = row; } /* don't use clr_eos for just one line if clr_eol available */ - if (top < total - 1 || (top < total && !clr_eol && !clr_bol)) { + if (top < total) { GoTo(top, 0); ClrToEOS(blank); - total = top; if (SP->oldhash && SP->newhash) { for (row = top; row < screen_lines; row++) SP->oldhash[row] = SP->newhash[row]; } } } - return total; + return top; } +#if USE_XMC_SUPPORT +#if USE_WIDEC_SUPPORT +#define check_xmc_transition(a, b) \ + ((((a)->attr ^ (b)->attr) & ~((a)->attr) & SP->_xmc_triggers) != 0) +#define xmc_turn_on(a,b) check_xmc_transition(&(a), &(b)) +#else +#define xmc_turn_on(a,b) ((((a)^(b)) & ~(a) & SP->_xmc_triggers) != 0) +#endif + +#define xmc_new(r,c) newscr->_line[r].text[c] +#define xmc_turn_off(a,b) xmc_turn_on(b,a) +#endif /* USE_XMC_SUPPORT */ + /* ** TransformLine(lineno) ** @@ -980,19 +1140,17 @@ static void TransformLine(int const lineno) { int firstChar, oLastChar, nLastChar; - chtype *newLine = newscr->_line[lineno].text; - chtype *oldLine = curscr->_line[lineno].text; + NCURSES_CH_T *newLine = newscr->_line[lineno].text; + NCURSES_CH_T *oldLine = curscr->_line[lineno].text; int n; bool attrchanged = FALSE; - TR(TRACE_UPDATE, ("TransformLine(%d) called", lineno)); + TR(TRACE_UPDATE, (T_CALLED("TransformLine(%d)"), lineno)); /* copy new hash value to old one */ if (SP->oldhash && SP->newhash) SP->oldhash[lineno] = SP->newhash[lineno]; -#define ColorOf(n) ((n) & A_COLOR) -#define unColor(n) ((n) & ALL_BUT_COLOR) /* * If we have colors, there is the possibility of having two color pairs * that display as the same colors. For instance, Lynx does this. Check @@ -1000,24 +1158,19 @@ TransformLine(int const lineno) * they are equivalent. */ if (SP->_coloron) { - chtype oldColor; - chtype newColor; int oldPair; int newPair; for (n = 0; n < screen_columns; n++) { - if (newLine[n] != oldLine[n]) { - oldColor = ColorOf(oldLine[n]); - newColor = ColorOf(newLine[n]); - if (oldColor != newColor + if (!CharEq(newLine[n], oldLine[n])) { + oldPair = GetPair(oldLine[n]); + newPair = GetPair(newLine[n]); + if (oldPair != newPair && unColor(oldLine[n]) == unColor(newLine[n])) { - oldPair = PAIR_NUMBER(oldColor); - newPair = PAIR_NUMBER(newColor); if (oldPair < COLOR_PAIRS && newPair < COLOR_PAIRS && SP->_color_pairs[oldPair] == SP->_color_pairs[newPair]) { - oldLine[n] &= ~A_COLOR; - oldLine[n] |= ColorOf(newLine[n]); + SetPair(oldLine[n], GetPair(newLine[n])); } } } @@ -1027,8 +1180,10 @@ TransformLine(int const lineno) if (ceol_standout_glitch && clr_eol) { firstChar = 0; while (firstChar < screen_columns) { - if (AttrOf(newLine[firstChar]) != AttrOf(oldLine[firstChar])) + if (!SameAttrOf(newLine[firstChar], oldLine[firstChar])) { attrchanged = TRUE; + break; + } firstChar++; } } @@ -1041,10 +1196,6 @@ TransformLine(int const lineno) PutRange(oldLine, newLine, lineno, 0, (screen_columns - 1)); #if USE_XMC_SUPPORT -#define NEW(r,c) newscr->_line[r].text[c] -#define xmc_turn_on(a,b) ((((a)^(b)) & ~(a) & SP->_xmc_triggers) != 0) -#define xmc_turn_off(a,b) xmc_turn_on(b,a) - /* * This is a very simple loop to paint characters which may have the * magic cookie glitch embedded. It doesn't know much about video @@ -1065,86 +1216,96 @@ TransformLine(int const lineno) * If we are writing an attributed blank, where the * previous cell is not attributed. */ - if (TextOf(newLine[n]) == ' ' + if (ISBLANK(newLine[n]) && ((n > 0 && xmc_turn_on(newLine[n - 1], newLine[n])) || (n == 0 && lineno > 0 - && xmc_turn_on(NEW(lineno - 1, screen_columns - 1), + && xmc_turn_on(xmc_new(lineno - 1, screen_columns - 1), newLine[n])))) { n = m; } - PutChar(newLine[n]); + PutChar(CHREF(newLine[n])); /* check for turn-off: * If we are writing an attributed non-blank, where the * next cell is blank, and not attributed. */ - if (TextOf(newLine[n]) != ' ' + if (!ISBLANK(newLine[n]) && ((n + 1 < screen_columns && xmc_turn_off(newLine[n], newLine[n + 1])) || (n + 1 >= screen_columns && lineno + 1 < screen_lines - && xmc_turn_off(newLine[n], NEW(lineno + 1, 0))))) { + && xmc_turn_off(newLine[n], xmc_new(lineno + 1, 0))))) { n = m; } } -#undef NEW #endif } else { - chtype blank; - - /* find the first differing character */ - while (firstChar < screen_columns && - newLine[firstChar] == oldLine[firstChar]) - firstChar++; - - /* if there wasn't one, we're done */ - if (firstChar >= screen_columns) - return; + NCURSES_CH_T blank; /* it may be cheap to clear leading whitespace with clr_bol */ - if (clr_bol && can_clear_with(blank = newLine[0])) { + blank = newLine[0]; + if (clr_bol && can_clear_with(CHREF(blank))) { int oFirstChar, nFirstChar; for (oFirstChar = 0; oFirstChar < screen_columns; oFirstChar++) - if (oldLine[oFirstChar] != blank) + if (!CharEq(oldLine[oFirstChar], blank)) break; for (nFirstChar = 0; nFirstChar < screen_columns; nFirstChar++) - if (newLine[nFirstChar] != blank) + if (!CharEq(newLine[nFirstChar], blank)) break; - if (nFirstChar > oFirstChar + SP->_el1_cost) { - if (nFirstChar >= screen_columns && SP->_el_cost <= SP->_el1_cost) { - GoTo(lineno, 0); - UpdateAttrs(blank); - TPUTS_TRACE("clr_eol"); - putp(clr_eol); - } else { - GoTo(lineno, nFirstChar - 1); - UpdateAttrs(blank); - TPUTS_TRACE("clr_bol"); - putp(clr_bol); - } - - while (firstChar < nFirstChar) - oldLine[firstChar++] = blank; + if (nFirstChar == oFirstChar) { + firstChar = nFirstChar; + /* find the first differing character */ + while (firstChar < screen_columns + && CharEq(newLine[firstChar], oldLine[firstChar])) + firstChar++; + } else if (oFirstChar > nFirstChar) { + firstChar = nFirstChar; + } else { /* oFirstChar < nFirstChar */ + firstChar = oFirstChar; + if (SP->_el1_cost < nFirstChar - oFirstChar) { + if (nFirstChar >= screen_columns + && SP->_el_cost <= SP->_el1_cost) { + GoTo(lineno, 0); + UpdateAttrs(blank); + TPUTS_TRACE("clr_eol"); + putp(clr_eol); + } else { + GoTo(lineno, nFirstChar - 1); + UpdateAttrs(blank); + TPUTS_TRACE("clr_bol"); + putp(clr_bol); + } - if (firstChar >= screen_columns) - return; + while (firstChar < nFirstChar) + oldLine[firstChar++] = blank; + } } + } else { + /* find the first differing character */ + while (firstChar < screen_columns + && CharEq(newLine[firstChar], oldLine[firstChar])) + firstChar++; + } + /* if there wasn't one, we're done */ + if (firstChar >= screen_columns) { + TR(TRACE_UPDATE, (T_RETURN(""))); + return; } blank = newLine[screen_columns - 1]; - if (!can_clear_with(blank)) { + if (!can_clear_with(CHREF(blank))) { /* find the last differing character */ nLastChar = screen_columns - 1; while (nLastChar > firstChar - && newLine[nLastChar] == oldLine[nLastChar]) + && CharEq(newLine[nLastChar], oldLine[nLastChar])) nLastChar--; if (nLastChar >= firstChar) { @@ -1152,29 +1313,30 @@ TransformLine(int const lineno) PutRange(oldLine, newLine, lineno, firstChar, nLastChar); memcpy(oldLine + firstChar, newLine + firstChar, - (nLastChar - firstChar + 1) * sizeof(chtype)); + (nLastChar - firstChar + 1) * sizeof(NCURSES_CH_T)); } + TR(TRACE_UPDATE, (T_RETURN(""))); return; } /* find last non-blank character on old line */ oLastChar = screen_columns - 1; - while (oLastChar > firstChar && oldLine[oLastChar] == blank) + while (oLastChar > firstChar && CharEq(oldLine[oLastChar], blank)) oLastChar--; /* find last non-blank character on new line */ nLastChar = screen_columns - 1; - while (nLastChar > firstChar && newLine[nLastChar] == blank) + while (nLastChar > firstChar && CharEq(newLine[nLastChar], blank)) nLastChar--; if ((nLastChar == firstChar) && (SP->_el_cost < (oLastChar - nLastChar))) { GoTo(lineno, firstChar); - if (newLine[firstChar] != blank) - PutChar(newLine[firstChar]); + if (!CharEq(newLine[firstChar], blank)) + PutChar(CHREF(newLine[firstChar])); ClrToEOL(blank, FALSE); } else if ((nLastChar != oLastChar) - && (newLine[nLastChar] != oldLine[oLastChar] + && (!CharEq(newLine[nLastChar], oldLine[oLastChar]) || !(_nc_idcok && has_ic()))) { GoTo(lineno, firstChar); if ((oLastChar - nLastChar) > SP->_el_cost) { @@ -1190,14 +1352,16 @@ TransformLine(int const lineno) int oLastNonblank = oLastChar; /* find the last characters that really differ */ - while (newLine[nLastChar] == oldLine[oLastChar]) { - if (nLastChar != 0 - && oLastChar != 0) { - nLastChar--; - oLastChar--; - } else { + /* can be -1 if no characters differ */ + while (CharEq(newLine[nLastChar], oldLine[oLastChar])) { + /* don't split a wide char */ + if (isWidecExt(newLine[nLastChar]) && + !CharEq(newLine[nLastChar - 1], oldLine[oLastChar - 1])) + break; + nLastChar--; + oLastChar--; + if (nLastChar == -1 || oLastChar == -1) break; - } } n = min(oLastChar, nLastChar); @@ -1208,9 +1372,15 @@ TransformLine(int const lineno) if (oLastChar < nLastChar) { int m = max(nLastNonblank, oLastNonblank); +#if USE_WIDEC_SUPPORT + while (isWidecExt(newLine[n + 1]) && n) { + --n; + --oLastChar; + } +#endif GoTo(lineno, n + 1); - if (InsCharCost(nLastChar - oLastChar) - > (m - n)) { + if ((nLastChar < nLastNonblank) + || InsCharCost(nLastChar - oLastChar) > (m - n)) { PutRange(oldLine, newLine, lineno, n + 1, m); } else { InsStr(&newLine[n + 1], nLastChar - oLastChar); @@ -1243,7 +1413,9 @@ TransformLine(int const lineno) if (screen_columns > firstChar) memcpy(oldLine + firstChar, newLine + firstChar, - (screen_columns - firstChar) * sizeof(chtype)); + (screen_columns - firstChar) * sizeof(NCURSES_CH_T)); + TR(TRACE_UPDATE, (T_RETURN(""))); + return; } /* @@ -1254,7 +1426,7 @@ TransformLine(int const lineno) */ static void -ClearScreen(chtype blank) +ClearScreen(NCURSES_CH_T blank) { int i, j; bool fast_clear = (clear_screen || clr_eos || clr_eol); @@ -1264,7 +1436,7 @@ ClearScreen(chtype blank) #if NCURSES_EXT_FUNCS if (SP->_coloron && !SP->_default_color) { - _nc_do_color((int) COLOR_PAIR(SP->_current_attr), 0, FALSE, _nc_outch); + _nc_do_color(GET_SCREEN_PAIR(SP), 0, FALSE, _nc_outch); if (!back_color_erase) { fast_clear = FALSE; } @@ -1284,7 +1456,7 @@ ClearScreen(chtype blank) UpdateAttrs(blank); TPUTS_TRACE("clr_eos"); - putp(clr_eos); + tputs(clr_eos, screen_lines, _nc_outch); } else if (clr_eol) { SP->_cursrow = SP->_curscol = -1; @@ -1301,7 +1473,7 @@ ClearScreen(chtype blank) for (i = 0; i < screen_lines; i++) { GoTo(i, 0); for (j = 0; j < screen_columns; j++) - PutChar(blank); + PutChar(CHREF(blank)); } GoTo(0, 0); } @@ -1322,7 +1494,7 @@ ClearScreen(chtype blank) */ static void -InsStr(chtype * line, int count) +InsStr(NCURSES_CH_T * line, int count) { TR(TRACE_UPDATE, ("InsStr(%p,%d) called", line, count)); @@ -1331,9 +1503,9 @@ InsStr(chtype * line, int count) /* The order must match that of InsCharCost. */ if (parm_ich) { TPUTS_TRACE("parm_ich"); - tputs(tparm(parm_ich, count), count, _nc_outch); + tputs(TPARM_1(parm_ich, count), count, _nc_outch); while (count) { - PutAttrChar(*line); + PutAttrChar(CHREF(*line)); line++; count--; } @@ -1341,7 +1513,7 @@ InsStr(chtype * line, int count) TPUTS_TRACE("enter_insert_mode"); putp(enter_insert_mode); while (count) { - PutAttrChar(*line); + PutAttrChar(CHREF(*line)); if (insert_padding) { TPUTS_TRACE("insert_padding"); putp(insert_padding); @@ -1355,7 +1527,7 @@ InsStr(chtype * line, int count) while (count) { TPUTS_TRACE("insert_character"); putp(insert_character); - PutAttrChar(*line); + PutAttrChar(CHREF(*line)); if (insert_padding) { TPUTS_TRACE("insert_padding"); putp(insert_padding); @@ -1379,12 +1551,14 @@ DelChar(int count) { int n; - TR(TRACE_UPDATE, ("DelChar(%d) called, position = (%d,%d)", count, - newscr->_cury, newscr->_curx)); + TR(TRACE_UPDATE, ("DelChar(%d) called, position = (%ld,%ld)", + count, + (long) newscr->_cury, + (long) newscr->_curx)); if (parm_dch) { TPUTS_TRACE("parm_dch"); - tputs(tparm(parm_dch, count), count, _nc_outch); + tputs(TPARM_1(parm_dch, count), count, _nc_outch); } else { for (n = 0; n < count; n++) { TPUTS_TRACE("delete_character"); @@ -1394,19 +1568,6 @@ DelChar(int count) } /* -** _nc_outstr(char *str) -** -** Emit a string without waiting for update. -*/ - -NCURSES_EXPORT(void) -_nc_outstr(const char *str) -{ - (void) putp(str); - _nc_flush(); -} - -/* * Physical-scrolling support * * This code was adapted from Keith Bostic's hardware scrolling @@ -1440,53 +1601,54 @@ _nc_outstr(const char *str) /* Try to scroll up assuming given csr (miny, maxy). Returns ERR on failure */ static int -scroll_csr_forward(int n, int top, int bot, int miny, int maxy, chtype blank) +scroll_csr_forward(int n, int top, int bot, int miny, int maxy, NCURSES_CH_T blank) { - int i, j; + int i; if (n == 1 && scroll_forward && top == miny && bot == maxy) { GoTo(bot, 0); UpdateAttrs(blank); TPUTS_TRACE("scroll_forward"); - tputs(scroll_forward, 0, _nc_outch); + putp(scroll_forward); } else if (n == 1 && delete_line && bot == maxy) { GoTo(top, 0); UpdateAttrs(blank); TPUTS_TRACE("delete_line"); - tputs(delete_line, 0, _nc_outch); + putp(delete_line); } else if (parm_index && top == miny && bot == maxy) { GoTo(bot, 0); UpdateAttrs(blank); TPUTS_TRACE("parm_index"); - tputs(tparm(parm_index, n, 0), n, _nc_outch); + tputs(TPARM_2(parm_index, n, 0), n, _nc_outch); } else if (parm_delete_line && bot == maxy) { GoTo(top, 0); UpdateAttrs(blank); TPUTS_TRACE("parm_delete_line"); - tputs(tparm(parm_delete_line, n, 0), n, _nc_outch); + tputs(TPARM_2(parm_delete_line, n, 0), n, _nc_outch); } else if (scroll_forward && top == miny && bot == maxy) { GoTo(bot, 0); UpdateAttrs(blank); for (i = 0; i < n; i++) { TPUTS_TRACE("scroll_forward"); - tputs(scroll_forward, 0, _nc_outch); + putp(scroll_forward); } } else if (delete_line && bot == maxy) { GoTo(top, 0); UpdateAttrs(blank); for (i = 0; i < n; i++) { TPUTS_TRACE("delete_line"); - tputs(delete_line, 0, _nc_outch); + putp(delete_line); } } else return ERR; #if NCURSES_EXT_FUNCS if (FILL_BCE()) { + int j; for (i = 0; i < n; i++) { GoTo(bot - i, 0); for (j = 0; j < screen_columns; j++) - PutChar(blank); + PutChar(CHREF(blank)); } } #endif @@ -1496,53 +1658,55 @@ scroll_csr_forward(int n, int top, int bot, int miny, int maxy, chtype blank) /* Try to scroll down assuming given csr (miny, maxy). Returns ERR on failure */ /* n > 0 */ static int -scroll_csr_backward(int n, int top, int bot, int miny, int maxy, chtype blank) +scroll_csr_backward(int n, int top, int bot, int miny, int maxy, + NCURSES_CH_T blank) { - int i, j; + int i; if (n == 1 && scroll_reverse && top == miny && bot == maxy) { GoTo(top, 0); UpdateAttrs(blank); TPUTS_TRACE("scroll_reverse"); - tputs(scroll_reverse, 0, _nc_outch); + putp(scroll_reverse); } else if (n == 1 && insert_line && bot == maxy) { GoTo(top, 0); UpdateAttrs(blank); TPUTS_TRACE("insert_line"); - tputs(insert_line, 0, _nc_outch); + putp(insert_line); } else if (parm_rindex && top == miny && bot == maxy) { GoTo(top, 0); UpdateAttrs(blank); TPUTS_TRACE("parm_rindex"); - tputs(tparm(parm_rindex, n, 0), n, _nc_outch); + tputs(TPARM_2(parm_rindex, n, 0), n, _nc_outch); } else if (parm_insert_line && bot == maxy) { GoTo(top, 0); UpdateAttrs(blank); TPUTS_TRACE("parm_insert_line"); - tputs(tparm(parm_insert_line, n, 0), n, _nc_outch); + tputs(TPARM_2(parm_insert_line, n, 0), n, _nc_outch); } else if (scroll_reverse && top == miny && bot == maxy) { GoTo(top, 0); UpdateAttrs(blank); for (i = 0; i < n; i++) { TPUTS_TRACE("scroll_reverse"); - tputs(scroll_reverse, 0, _nc_outch); + putp(scroll_reverse); } } else if (insert_line && bot == maxy) { GoTo(top, 0); UpdateAttrs(blank); for (i = 0; i < n; i++) { TPUTS_TRACE("insert_line"); - tputs(insert_line, 0, _nc_outch); + putp(insert_line); } } else return ERR; #if NCURSES_EXT_FUNCS if (FILL_BCE()) { + int j; for (i = 0; i < n; i++) { GoTo(top + i, 0); for (j = 0; j < screen_columns; j++) - PutChar(blank); + PutChar(CHREF(blank)); } } #endif @@ -1552,7 +1716,7 @@ scroll_csr_backward(int n, int top, int bot, int miny, int maxy, chtype blank) /* scroll by using delete_line at del and insert_line at ins */ /* n > 0 */ static int -scroll_idl(int n, int del, int ins, chtype blank) +scroll_idl(int n, int del, int ins, NCURSES_CH_T blank) { int i; @@ -1563,14 +1727,14 @@ scroll_idl(int n, int del, int ins, chtype blank) UpdateAttrs(blank); if (n == 1 && delete_line) { TPUTS_TRACE("delete_line"); - tputs(delete_line, 0, _nc_outch); + putp(delete_line); } else if (parm_delete_line) { TPUTS_TRACE("parm_delete_line"); - tputs(tparm(parm_delete_line, n, 0), n, _nc_outch); + tputs(TPARM_2(parm_delete_line, n, 0), n, _nc_outch); } else { /* if (delete_line) */ for (i = 0; i < n; i++) { TPUTS_TRACE("delete_line"); - tputs(delete_line, 0, _nc_outch); + putp(delete_line); } } @@ -1578,26 +1742,33 @@ scroll_idl(int n, int del, int ins, chtype blank) UpdateAttrs(blank); if (n == 1 && insert_line) { TPUTS_TRACE("insert_line"); - tputs(insert_line, 0, _nc_outch); + putp(insert_line); } else if (parm_insert_line) { TPUTS_TRACE("parm_insert_line"); - tputs(tparm(parm_insert_line, n, 0), n, _nc_outch); + tputs(TPARM_2(parm_insert_line, n, 0), n, _nc_outch); } else { /* if (insert_line) */ for (i = 0; i < n; i++) { TPUTS_TRACE("insert_line"); - tputs(insert_line, 0, _nc_outch); + putp(insert_line); } } return OK; } +/* + * Note: some terminals require the cursor to be within the scrolling margins + * before setting them. Generally, the cursor must be at the appropriate end + * of the scrolling margins when issuing an indexing operation (it is not + * apparent whether it must also be at the left margin; we do this just to be + * safe). To make the related cursor movement a little faster, we use the + * save/restore cursor capabilities if the terminal has them. + */ NCURSES_EXPORT(int) -_nc_scrolln -(int n, int top, int bot, int maxy) +_nc_scrolln(int n, int top, int bot, int maxy) /* scroll region from top to bot by n lines */ { - chtype blank = ClrBlank(stdscr); + NCURSES_CH_T blank = ClrBlank(stdscr); int i; bool cursor_saved = FALSE; int res; @@ -1626,13 +1797,13 @@ _nc_scrolln && save_cursor && restore_cursor) { cursor_saved = TRUE; TPUTS_TRACE("save_cursor"); - tputs(save_cursor, 0, _nc_outch); + putp(save_cursor); } TPUTS_TRACE("change_scroll_region"); - tputs(tparm(change_scroll_region, top, bot), 0, _nc_outch); + putp(TPARM_2(change_scroll_region, top, bot)); if (cursor_saved) { TPUTS_TRACE("restore_cursor"); - tputs(restore_cursor, 0, _nc_outch); + putp(restore_cursor); } else { SP->_cursrow = SP->_curscol = -1; } @@ -1640,7 +1811,7 @@ _nc_scrolln res = scroll_csr_forward(n, top, bot, top, bot, blank); TPUTS_TRACE("change_scroll_region"); - tputs(tparm(change_scroll_region, 0, maxy), 0, _nc_outch); + putp(TPARM_2(change_scroll_region, 0, maxy)); SP->_cursrow = SP->_curscol = -1; } @@ -1652,13 +1823,14 @@ _nc_scrolln */ if (res != ERR && (non_dest_scroll_region || (memory_below && bot == maxy))) { + static const NCURSES_CH_T blank2 = NewChar(BLANK_TEXT); if (bot == maxy && clr_eos) { - GoTo(bot - n, 0); - ClrToEOS(BLANK); + GoTo(bot - n + 1, 0); + ClrToEOS(blank2); } else { for (i = 0; i < n; i++) { GoTo(bot - i, 0); - ClrToEOL(BLANK, FALSE); + ClrToEOL(blank2, FALSE); } } } @@ -1671,13 +1843,13 @@ _nc_scrolln && save_cursor && restore_cursor) { cursor_saved = TRUE; TPUTS_TRACE("save_cursor"); - tputs(save_cursor, 0, _nc_outch); + putp(save_cursor); } TPUTS_TRACE("change_scroll_region"); - tputs(tparm(change_scroll_region, top, bot), 0, _nc_outch); + putp(TPARM_2(change_scroll_region, top, bot)); if (cursor_saved) { TPUTS_TRACE("restore_cursor"); - tputs(restore_cursor, 0, _nc_outch); + putp(restore_cursor); } else { SP->_cursrow = SP->_curscol = -1; } @@ -1685,7 +1857,7 @@ _nc_scrolln res = scroll_csr_backward(-n, top, bot, top, bot, blank); TPUTS_TRACE("change_scroll_region"); - tputs(tparm(change_scroll_region, 0, maxy), 0, _nc_outch); + putp(TPARM_2(change_scroll_region, 0, maxy)); SP->_cursrow = SP->_curscol = -1; } @@ -1697,9 +1869,10 @@ _nc_scrolln */ if (res != ERR && (non_dest_scroll_region || (memory_above && top == 0))) { + static const NCURSES_CH_T blank2 = NewChar(BLANK_TEXT); for (i = 0; i < -n; i++) { GoTo(i + top, 0); - ClrToEOL(BLANK, FALSE); + ClrToEOL(blank2, FALSE); } } } @@ -1719,11 +1892,27 @@ NCURSES_EXPORT(void) _nc_screen_resume(void) { /* make sure terminal is in a sane known state */ - SP->_current_attr = A_NORMAL; + SetAttr(SCREEN_ATTRS(SP), A_NORMAL); newscr->_clear = TRUE; - if (SP->_coloron == TRUE && orig_pair) - putp(orig_pair); + /* reset color pairs and definitions */ + if (SP->_coloron || SP->_color_defs) + _nc_reset_colors(); + + /* restore user-defined colors, if any */ + if (SP->_color_defs < 0) { + int n; + SP->_color_defs = -(SP->_color_defs); + for (n = 0; n < SP->_color_defs; ++n) { + if (SP->_color_table[n].init) { + init_color(n, + SP->_color_table[n].r, + SP->_color_table[n].g, + SP->_color_table[n].b); + } + } + } + if (exit_attribute_mode) putp(exit_attribute_mode); else { @@ -1751,28 +1940,30 @@ _nc_screen_init(void) NCURSES_EXPORT(void) _nc_screen_wrap(void) { - UpdateAttrs(A_NORMAL); + UpdateAttrs(normal); #if NCURSES_EXT_FUNCS if (SP->_coloron && !SP->_default_color) { + static const NCURSES_CH_T blank = NewChar(BLANK_TEXT); SP->_default_color = TRUE; _nc_do_color(-1, 0, FALSE, _nc_outch); SP->_default_color = FALSE; mvcur(SP->_cursrow, SP->_curscol, screen_lines - 1, 0); - SP->_cursrow = screen_lines - 1; - SP->_curscol = 0; - ClrToEOL(BLANK, TRUE); + ClrToEOL(blank, TRUE); } #endif + if (SP->_color_defs) { + _nc_reset_colors(); + } } #if USE_XMC_SUPPORT NCURSES_EXPORT(void) _nc_do_xmc_glitch(attr_t previous) { - attr_t chg = XMC_CHANGES(previous ^ SP->_current_attr); + attr_t chg = XMC_CHANGES(previous ^ AttrOf(SCREEN_ATTRS(SP))); while (chg != 0) { if (chg & 1) { diff --git a/lib/libcurses/unctrl.h b/lib/libcurses/unctrl.h index 211540418b9..eb9f9ce16a0 100644 --- a/lib/libcurses/unctrl.h +++ b/lib/libcurses/unctrl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: unctrl.h,v 1.8 2001/01/22 18:01:35 millert Exp $ */ +/* $OpenBSD: unctrl.h,v 1.9 2010/01/12 23:21:59 nicm Exp $ */ /**************************************************************************** * Copyright (c) 1998,2000 Free Software Foundation, Inc. * @@ -41,13 +41,13 @@ * as ^?. Printable characters are displayed as is. */ -/* $From: unctrl.h.in,v 1.9 2000/12/10 02:02:15 tom Exp $ */ +/* $Id: unctrl.h,v 1.9 2010/01/12 23:21:59 nicm Exp $ */ -#ifndef _UNCTRL_H -#define _UNCTRL_H 1 +#ifndef NCURSES_UNCTRL_H_incl +#define NCURSES_UNCTRL_H_incl 1 #undef NCURSES_VERSION -#define NCURSES_VERSION "5.2" +#define NCURSES_VERSION "5.7" #ifdef __cplusplus extern "C" { @@ -62,4 +62,4 @@ NCURSES_EXPORT(NCURSES_CONST char *) unctrl (chtype); } #endif -#endif /* _UNCTRL_H */ +#endif /* NCURSES_UNCTRL_H_incl */ diff --git a/lib/libcurses/wresize.3 b/lib/libcurses/wresize.3 index 5d718031ee7..8e6b09eefb9 100644 --- a/lib/libcurses/wresize.3 +++ b/lib/libcurses/wresize.3 @@ -1,7 +1,7 @@ -.\" $OpenBSD: wresize.3,v 1.6 1998/09/13 19:16:31 millert Exp $ +.\" $OpenBSD: wresize.3,v 1.7 2010/01/12 23:21:59 nicm Exp $ .\" .\"*************************************************************************** -.\" Copyright (c) 1998 Free Software Foundation, Inc. * +.\" Copyright (c) 1998-2003,2006 Free Software Foundation, Inc. * .\" * .\" Permission is hereby granted, free of charge, to any person obtaining a * .\" copy of this software and associated documentation files (the * @@ -28,40 +28,34 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" Author: Thomas E. Dickey <dickey@clark.net> 1996 +.\" Author: Thomas E. Dickey 1996 .\" -.\" $From: wresize.3x,v 1.5 1998/03/14 23:42:44 tom Exp $ +.\" $Id: wresize.3,v 1.7 2010/01/12 23:21:59 nicm Exp $ .TH wresize 3 "" .SH NAME \fBwresize\fR - resize a curses window -.. .SH SYNOPSIS \fB#include <curses.h>\fR - +.sp \fBint wresize(WINDOW *win, int lines, int columns);\fR -.. .SH DESCRIPTION -The \fBwresize\fR function reallocates storage for a \fBcurses\fR +The \fBwresize\fR function reallocates storage for an \fBncurses\fR window to adjust its dimensions to the specified values. If either dimension is larger than the current values, the window's data is filled with blanks that have the current background rendition (as set by \fBwbkgndset\fR) merged into them. -.. .SH RETURN VALUE The function returns the integer \fBERR\fR upon failure and \fBOK\fR on success. It will fail if either of the dimensions less than or equal to zero, or if an error occurs while (re)allocating memory for the window. -.. .SH NOTES The only restriction placed on the dimensions is that they be greater than zero. The dimensions are not compared to \fBcurses\fR screen dimensions to simplify the logic of \fBresizeterm\fR. The caller must ensure that the window's dimensions fit within the actual screen dimensions. -.. .SH SEE ALSO \fBresizeterm\fR(3). -.. .SH AUTHOR Thomas Dickey (from an equivalent function written in 1988 for BSD curses). .\"# |