sync code with last improvements from OpenBSD

This commit is contained in:
purplerain 2023-11-11 01:29:48 +00:00
parent 5903cbe575
commit 62d64fa864
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
841 changed files with 83929 additions and 40755 deletions

View file

@ -1,7 +1,8 @@
# $OpenBSD: Caps,v 1.6 2010/01/12 23:21:58 nicm Exp $
# $OpenBSD: Caps,v 1.7 2023/10/17 09:52:08 nicm Exp $
##############################################################################
# Copyright (c) 1998-2002,2006 Free Software Foundation, Inc. #
# Copyright 2019-2020,2021 Thomas E. Dickey #
# Copyright 1998-2015,2016 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"), #
@ -31,12 +32,12 @@
# Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995
# and: Eric S. Raymond <esr@snark.thyrsus.com>
#
# $Id: Caps,v 1.6 2010/01/12 23:21:58 nicm Exp $
# $Id: Caps,v 1.7 2023/10/17 09:52:08 nicm Exp $
#
# This is the master termcap/terminfo capability table.
#
# This table is used to generate initializers for tables that drive tic,
# infocmp, and the library compilation code used to support the termcap
# infocmp, and the library compilation code used to support the termcap
# compatibility hack. It is also used to generate the tabular portion of the
# terminfo(5) man page; lines beginning with `#%' are passed through to become
# the terminfo table.
@ -59,7 +60,7 @@
#
# 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
# proper; rather, it is there to help the terminfo maintainer avoid emitting
# termcap entry translations that are more than 1023 bytes long (and tank a
# lot of old termcap-using programs). The codes read as follows:
# B = mentioned in the BSD man page for 4.4BSD curses
@ -99,8 +100,8 @@
# 3. List it in the standard table. You almost certainly do *not* want
# to do this -- the capabilities in that one, and their order, have been
# carefully chosen to be SVr4-binary-compatible when they're written out
# as a terminfo object, and breaking this would be bad. It's up the ncurses
# library what to do with the terminfo data after it's read in.
# as a terminfo object, and breaking this would be bad. It is up to the ncurses
# library what to do with the terminfo data after it is read in.
#
# 4. List it in the aliases table with an IGNORE target field. If you
# do this, the capability will be ignored on input (though the user will
@ -109,7 +110,7 @@
# 5. List it in the extensions table. If you do this, the compiler will
# silently accept the capability, but the curses library proper will never
# see it (because it won't be written out as part of the terminfo object
# format). It's up to you what you have the compiler do with it.
# format). It is up to you what you have the compiler do with it.
#
# There are two opposite reasons to choose option 5. One is when you want
# to eat the capability silently and discard it when doing translations
@ -121,14 +122,14 @@
# You'll need to write custom code, probably in postprocess_termcap() or
# postprocess_terminfo(), to handle the translation.
#
# CONTROLLING ENTRY LENGTH
# CONTROLLING ENTRY LENGTH
#
# Notes on specific elisions made to fit translations within 1023 bytes:
#
# Machines with IBM PC-like keyboards want to be able to define the following
# keys: key_npage, key_ppage, key_home, key_ll (which is used for in termcap-
# only environments for End or Home-Down), key_dc, and key_ic. This is also
# the set of keys the `joe' editor will be upset if it can't see. So don't
# the set of keys the `joe' editor will be upset if it can't see. So don't
# trim those out of the set to be translated to termcap, or various users of
# the termcap file will become irate.
#
@ -149,7 +150,7 @@
#
# It would be nice to keep f11 and f12 for Emacs use, but a couple of termcap
# translations go back over critical if we do this. As 4.4BSD curses fades
# into history and GNU termcap's application base shrinks towards being GNU
# into history and GNU termcap's application base shrinks towards being GNU
# Emacs only, we'll probably elide out some BSD-only capabilities in order
# to buy space for non-essentials Emacs is still using. Capabilities high
# on that hit list: rc, sc, uc.
@ -168,7 +169,7 @@
#%The \fBcapname\fR is the short name used in the text of the database,
#%and is used by a person updating the database.
#%Whenever possible, capnames are chosen to be the same as or similar to
#%the ANSI X3.64-1979 standard (now superseded by ECMA-48, which uses
#%the ANSI X3.64-1979 standard (now superseded by ECMA-48, which uses
#%identical or very similar names). Semantics are also intended to match
#%those of the specification.
#%
@ -190,8 +191,12 @@
#%indicates that padding may be specified
#%.TP
#%#[1-9]
#%in the description field indicates that the string is passed through tparm with
#%parms as given (#\fIi\fP).
#%in the description field indicates that the string is passed
#%through \fBtparm\fP(3X) with parameters as given (#\fIi\fP).
#%.IP
#%If no parameters are listed in the description,
#%passing the string through \fBtparm\fP(3X) may give unexpected results,
#%e.g., if it contains percent (%%) signs.
#%.TP
#%(P*)
#%indicates that padding may vary in proportion to the number of
@ -229,7 +234,7 @@ 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)
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
@ -273,7 +278,7 @@ 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
maximum_windows wnum num MW - - ----- maximum number of definable 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
@ -598,7 +603,7 @@ 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_left_margin smgl str ML - - ----- set left soft margin at current column. (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
@ -721,7 +726,7 @@ 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
define_bit_image_region defbi str Yx - - ----- Define rectangular 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
@ -740,11 +745,13 @@ alt_scancode_esc scesa str S8 - - ----- Alternate escape for scancode emulatio
#%.ad
#%
#%.in .8i
#%The XSI Curses standard added these. They are some post-4.1
#%versions of System V curses, e.g., Solaris 2.5 and IRIX 6.x.
#%The \fBncurses\fR termcap names for them are invented; according to the
#%XSI Curses standard, they have no termcap names. If your compiled terminfo
#%entries use these, they may not be binary-compatible with System V terminfo
#%The XSI Curses standard added these hardcopy capabilities.
#%They were used in some post-4.1 versions of System V curses,
#%e.g., Solaris 2.5 and IRIX 6.x.
#%Except for \fBYI\fP, the \fBncurses\fR termcap names for them are invented.
#%According to the XSI Curses standard, they have no termcap names.
#%If your compiled terminfo entries use these,
#%they may not be binary-compatible with System V terminfo
#%entries after SVr4.1; beware!
#%
#%.na
@ -762,7 +769,7 @@ 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
set_pglen_inch slength str YI - - ----- Set page length to #1 hundredth of an inch (some implementations use sL for termcap).
#%.TE
#%.ad
#
@ -826,7 +833,7 @@ gnu_has_meta_key OTMT bool MT - - ----E has meta key
# 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
@ -843,9 +850,9 @@ gnu_has_meta_key OTMT bool MT - - ----E has meta key
# comma-separated list of capabilities for which there are corresponding keys.
# The `kn' code is accepted but ignored.
#
# The `ma' capability seems to have been designed to map between the rogue(2)
# motion keys (including jkhl) and characters emitted by arrow keys on some
# primitive pre-ANSI terminals. It's so obsolete it's fossilized...
# The `ma' capability was a 4.0BSD feature used by vi version 2.
# It consists of pairs of characters corresponding to kl, kr, ku, kd, and kh.
# Besides being obsolete, that interpretation conflicts with max_attributes.
#
# Here is a description of memory_lock_above and memory_unlock:
# "You can 'freeze' data on the screen by turning on Memory Lock in a line of
@ -871,14 +878,14 @@ 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
arrow_key_map OTma str ma - - YBC-- map motion-keys for vi version 2
# 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
# mytinfo described this as a termcap capability, but it is 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.
#
@ -887,7 +894,7 @@ return_does_clr_eol OTxr bool xr - - YB--- return clears the 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.
# 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 (?)
@ -936,7 +943,7 @@ return_does_clr_eol OTxr bool xr - - YB--- return clears the line
# Gv 186 \272 M-: double vertical line
#
# The compiler will translate the single-line caps and discard the others
# (via IGNORE aliases further down). We don't want to do normal pad
# (via IGNORE aliases further down). We don't want to do normal pad
# translation on these, they're often single-character printable ASCII
# strings that happen to be numerics. There's awk code in parametrized.sh
# that detects the acs_ prefix and uses it to suppress pad translation.
@ -958,309 +965,9 @@ acs_plus OTGC str GC - - ----- single intersection
#
# TERMINFO EXTENSION CAPABILITIES
#
# This section is almost all comments. What it's mainly for is to describe
# what capabilities need to be squeezed out to get down to the XSI Curses
# standard set. They are flagged with K.
#
# HP extensions
#
# These extensions follow ptr_non (replacing everything after it) in HP
# terminfo files. Except for memory_lock and memory_unlock, they are
# functionally identical to SVr4 extensions, but they make the binary format
# different. Grrr....
# (see Caps-ncurses for the complete set of comments)
#
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
#
# These extensions follow ptr_non (replacing everything after it) in IBM
# terminfo files.
#
# The places in the box[12] capabilities correspond to acsc characters, here is
# the mapping:
#
# box1[0] = ACS_ULCORNER
# box1[1] = ACS_HLINE
# box1[2] = ACS_URCORNER
# box1[3] = ACS_VLINE
# box1[4] = ACS_LRCORNER
# box1[5] = ACS_LLCORNER
# box1[6] = ACS_TTEE
# box1[7] = ACS_RTEE
# box1[8] = ACS_BTEE
# box1[9] = ACS_LTEE
# box1[10] = ACS_PLUS
#
# 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
# 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
# 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
# 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
# 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
#
#############################################################################
#
# ALIAS DECLARATIONS
#
# Here we set up aliases for translating extensions into standard terminfo.
#
#---------------------------------- Termcap aliases -------------------------
#
# BSD aliases:
#
# This is a common error in many termcap files. We'll get notified during
# translation when this (or any other alias) fires.
#
capalias sb sr BSD scroll text down
#
# AT&T extensions:
#
# The old AT&T 5410, 5420, 5425, pc6300plus, 610, and s4 entries used a set of
# nonstandard capabilities. Its signature is the KM capability, used to name
# some sort of keymap file. EE, BO, CI, CV, XS, DS, FL and FE are in this
# set. Comments in the original, and a little cross-checking with other AT&T
# documentation, seem to establish the following mappings:
#
capalias BO mr AT&T enter_reverse_mode
capalias CI vi AT&T cursor_invisible
capalias CV ve AT&T cursor_normal
capalias DS mh AT&T enter_dim_mode
#capalias EE me AT&T exit_attribute_mode
capalias FE LF AT&T label_on
capalias FL LO AT&T label_off
capalias XS mk AT&T enter_secure_mode
#
# We comment out EE because the conflicting XENIX EE is more common in
# old entries.
#
# XENIX extensions:
#
# These are the ones we know how to translate directly:
#
capalias EE mh XENIX exit_attribute_mode
capalias GE ae XENIX exit_alt_charset_mode
capalias GS as XENIX enter_alt_charset_mode
capalias CF vi XENIX cursor_invis
capalias CO ve XENIX cursor_normal
capalias EN @7 XENIX key_end
capalias HM kh XENIX key_home
capalias LD kL XENIX key_dl
capalias PD kN XENIX key_npage
capalias PN po XENIX prtr_off
capalias PS pf XENIX prtr_on
capalias PU kP XENIX key_ppage
capalias RT @8 XENIX kent
capalias UP ku XENIX kcuu1
capalias G6 IGNORE XENIX double-ACS_ULCORNER
capalias G7 IGNORE XENIX double-ACS_LLCORNER
capalias G5 IGNORE XENIX double-ACS_URCORNER
capalias G8 IGNORE XENIX double-ACS_LRCORNER
capalias Gr IGNORE XENIX double-ACS_LTEE
capalias Gr IGNORE XENIX double-ACS_RTEE
capalias Gu IGNORE XENIX double-ACS_BTEE
capalias Gd IGNORE XENIX double ACS_TTEE
capalias Gh IGNORE XENIX double-ACS_HLINE
capalias Gv IGNORE XENIX double-ACS_VLINE
capalias Gc IGNORE XENIX double-ACS_PLUS
capalias GG IGNORE XENIX acs-glitch
#
# IBM extensions:
#
capalias kq %1 IBM key_help
#
# Iris extensions:
#
capalias HS mh IRIS enter_dim_mode
#
# Tektronix extensions:
#
capalias KA k; Tek key_f10
capalias KB F1 Tek key_f11
capalias KC F2 Tek key_f12
capalias KD F3 Tek key_f13
capalias KE F4 Tek key_f14
capalias KF F5 Tek key_f15
capalias BC Sb Tek set_background
capalias FC Sf Tek set_foreground
#
# There are also the following:
#
# XENIX XENIX variable name name clash with terminfo?
# ----- ------------------- -------------------------
# CL key_char_left
# CR key_char_right
# CW key_change_window
# HP ??
# LF key_linefeed label_off
# NU key_next_unlocked_cell
# PL ??
# PR ??
# RC key_recalc remove_clock
# RF key_toggle_ref req_for_input
# WL key_word_left
# WR key_word_right
#
# If you know what any of the question-marked ones mean, please tell us.
#
#--------------------------------- Terminfo aliases ------------------------
#
# IBM extensions:
#
infoalias font0 s0ds IBM set0_des_seq
infoalias font1 s1ds IBM set1_des_seq
infoalias font2 s2ds IBM set2_des_seq
infoalias font3 s3ds IBM set3_des_seq
infoalias kbtab kcbt IBM key_backtab
infoalias ksel kslt IBM key_select
#
# Some others are identical to SVr4/XPG4 capabilities, in particular:
# kcmd, kend, khlp, and kf11...kf63.
#
#############################################################################
#
# The following sets edit modes for GNU EMACS
# Local Variables:
# case-fold-search:nil
# truncate-lines:t
# End:

476
lib/libcurses/Caps-ncurses Normal file
View file

@ -0,0 +1,476 @@
##############################################################################
# Copyright 2019-2022,2023 Thomas E. Dickey #
# #
# 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
#
# $Id: Caps-ncurses,v 1.1 2023/10/17 09:52:08 nicm Exp $
#
#############################################################################
#
# TERMINFO EXTENSION CAPABILITIES
#
# This section is all comments (selected lines are copied/uncommented into
# specific "Caps" files). The section describes what capabilities need to be
# squeezed out to get down to the XSI Curses standard set. They are flagged
# with K.
#
# HP extensions
#
# These extensions follow ptr_non (replacing everything after it) in HP
# terminfo files. Except for memory_lock and memory_unlock, they are
# functionally identical to SVr4 extensions, but they make the binary format
# different. Grrr....
#
#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
#
# These extensions follow ptr_non (replacing everything after it) in IBM
# terminfo files.
#
# The places in the box[12] capabilities correspond to acsc characters, here is
# the mapping:
#
# box1[0] = ACS_ULCORNER
# box1[1] = ACS_HLINE
# box1[2] = ACS_URCORNER
# box1[3] = ACS_VLINE
# box1[4] = ACS_LRCORNER
# box1[5] = ACS_LLCORNER
# box1[6] = ACS_TTEE
# box1[7] = ACS_RTEE
# box1[8] = ACS_BTEE
# box1[9] = ACS_LTEE
# box1[10] = ACS_PLUS
#
# 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
# 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
# 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
# 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
# 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
#
#############################################################################
#
# ALIAS DECLARATIONS
#
# Here we set up aliases for translating extensions into standard terminfo.
#
#---------------------------------- Termcap aliases -------------------------
#
# BSD aliases:
#
# This is a common error in many termcap files. We'll get notified during
# translation when this (or any other alias) fires.
#
capalias sb sr BSD scroll text down
#
# AT&T extensions:
#
# The old AT&T 5410, 5420, 5425, pc6300plus, 610, and s4 entries used a set of
# nonstandard capabilities. Its signature is the KM capability, used to name
# some sort of keymap file. EE, BO, CI, CV, XS, DS, FL and FE are in this
# set. Comments in the original, and a little cross-checking with other AT&T
# documentation, seem to establish the following mappings:
#
capalias BO mr AT&T enter_reverse_mode
capalias CI vi AT&T cursor_invisible
capalias CV ve AT&T cursor_normal
capalias DS mh AT&T enter_dim_mode
#capalias EE me AT&T exit_attribute_mode
capalias FE LF AT&T label_on
capalias FL LO AT&T label_off
capalias XS mk AT&T enter_secure_mode
#
# We comment out EE because the conflicting XENIX EE is more common in
# old entries.
#
# XENIX extensions:
#
# These are the ones we know how to translate directly:
#
capalias EE mh XENIX exit_attribute_mode
capalias GE ae XENIX exit_alt_charset_mode
capalias GS as XENIX enter_alt_charset_mode
capalias CF vi XENIX cursor_invis
capalias CO ve XENIX cursor_normal
capalias EN @7 XENIX key_end
capalias HM kh XENIX key_home
capalias LD kL XENIX key_dl
capalias PD kN XENIX key_npage
capalias PN po XENIX prtr_off
capalias PS pf XENIX prtr_on
capalias PU kP XENIX key_ppage
capalias RT @8 XENIX kent
capalias UP ku XENIX kcuu1
capalias G6 IGNORE XENIX double-ACS_ULCORNER
capalias G7 IGNORE XENIX double-ACS_LLCORNER
capalias G5 IGNORE XENIX double-ACS_URCORNER
capalias G8 IGNORE XENIX double-ACS_LRCORNER
capalias Gr IGNORE XENIX double-ACS_LTEE
capalias Gr IGNORE XENIX double-ACS_RTEE
capalias Gu IGNORE XENIX double-ACS_BTEE
capalias Gd IGNORE XENIX double ACS_TTEE
capalias Gh IGNORE XENIX double-ACS_HLINE
capalias Gv IGNORE XENIX double-ACS_VLINE
capalias Gc IGNORE XENIX double-ACS_PLUS
capalias GG IGNORE XENIX acs-glitch
#
# IBM extensions:
#
capalias kq %1 IBM key_help
#
# Iris extensions:
#
capalias HS mh IRIS enter_dim_mode
#
# Tektronix extensions:
#
capalias KA k; Tek key_f10
capalias KB F1 Tek key_f11
capalias KC F2 Tek key_f12
capalias KD F3 Tek key_f13
capalias KE F4 Tek key_f14
capalias KF F5 Tek key_f15
capalias BC Sb Tek set_background
capalias FC Sf Tek set_foreground
#
# There are also the following:
#
# XENIX XENIX variable name name clash with terminfo?
# ----- ------------------- -------------------------
# CL key_char_left
# CR key_char_right
# CW key_change_window
# HP ??
# LF key_linefeed label_off
# NU key_next_unlocked_cell
# PL ??
# PR ??
# RC key_recalc remove_clock
# RF key_toggle_ref req_for_input
# WL key_word_left
# WR key_word_right
#
# If you know what any of the question-marked ones mean, please tell us.
#
#--------------------------------- Terminfo aliases ------------------------
#
# IBM extensions:
#
infoalias font0 s0ds IBM set0_des_seq
infoalias font1 s1ds IBM set1_des_seq
infoalias font2 s2ds IBM set2_des_seq
infoalias font3 s3ds IBM set3_des_seq
infoalias kbtab kcbt IBM key_backtab
infoalias ksel kslt IBM key_select
#
# Some others are identical to SVr4/XPG4 capabilities, in particular:
# kcmd, kend, khlp, and kf11...kf63.
#
#############################################################################
# This is a table of ncurses user-definable capabilities which applications
# developers may have used. ncurses may use the table to check consistency of
# types/parameters. Applications may have defined others (such as screen's
# LP and NF), but where a standard capability is available, those alternatives
# are not listed here.
#
used_by ncurses
userdef CO num n number of indexed colors overlaying RGB space
userdef E3 str - clears the terminal's scrollback buffer.
userdef NQ bool - terminal does not support query/response
userdef RGB bool - use direct colors with 1/3 of color-pair bits per color.
userdef RGB num n use direct colors with given number of bits per color.
userdef RGB str - use direct colors with given bit-layout.
userdef TS str - like "tsl", but uses no parameter.
userdef U8 num n terminal does/does not support VT100 SI/SO when processing UTF-8 encoding.
userdef XM str n initialize alternate xterm mouse mode
userdef grbom str - disable real bold (not intensity bright) mode.
userdef gsbom str - enable real bold (not intensity bright) mode.
userdef xm str - mouse response, no parameters
userdef xm str n mouse response, p1 = y-ordinate
userdef xm str nn mouse response, p2 = x-ordinate
userdef xm str nnn mouse response, p3 = button
userdef xm str nnns mouse response, p4 = state, e.g., pressed or released
userdef xm str nnnsn mouse response, p5 = y-ordinate starting region
userdef xm str nnnsnn mouse response, p6 = x-ordinate starting region
userdef xm str nnnsnnn mouse response, p7 = y-ordinate ending region
userdef xm str nnnsnnnn mouse response, p8 = x-ordinate ending region
#
used_by mintty
userdef Rmol str - remove overline-mode
userdef Smol str - set overline-mode
userdef blink2 str - turn on rapid blinking
userdef norm str - turn off bold and half-bright mode
userdef opaq str - turn off blank mode
userdef setal str n set underline-color
userdef smul2 str - begin double underline mode
#
used_by screen
userdef AN bool - turn on autonuke.
userdef AX bool - understands ANSI set default fg/bg color (\E[39m / \E[49m).
userdef C0 str - use the string as a conversion table for font '0', like acsc.
userdef C8 bool - terminal shows bold as high-intensity colors.
userdef CE str - switch cursor-keys back to normal mode.
userdef CS str - switch cursor-keys to application mode.
userdef E0 str - switch charset 'G0' back to standard charset. Default is '\E(B'.
userdef G0 bool - terminal can deal with ISO 2022 font selection sequences.
userdef KJ str s set the encoding of the terminal.
userdef OL num n set the screen program's output buffer limit.
userdef S0 str s switch charset 'G0' to the specified charset. Default is '\E(%.'.
userdef TF bool - add missing capabilities to screen's termcap/info entry. (Set by default).
userdef WS str nn resize display. This capability has the desired width and height as arguments. SunView(tm) example: '\E[8;%d;%dt'.
userdef XC str s describe a translation of characters to strings depending on the current font.
userdef XT bool - terminal understands special xterm sequences (OSC, mouse tracking).
userdef Z0 str - change width to 132 columns.
userdef Z1 str - change width to 80 columns.
#
used_by tmux
userdef Cr str - restore the default cursor color.
userdef Cs str s set the cursor color.
userdef Csr str n change the cursor style, overriding Ss.
userdef Ms str ss store the current buffer in the host terminal's selection (clipboard).
userdef Se str - reset the cursor style to the terminal initial state.
userdef Smulx str n modify the appearance of underlines in VTE.
userdef Ss str n change the cursor style.
userdef rmxx str - reset ECMA-48 strikeout/crossed-out attributes.
userdef smxx str - set ECMA-48 strikeout/crossed-out attributes.
#
used_by vim
userdef BD str - disables bracketed paste
userdef BE str - enables bracketed paste
userdef PE str - is sent after pasted text
userdef PS str - is sent before pasted text
userdef RV str - report terminal secondary device attributes
userdef XR str - report terminal version as a free-format string.
userdef XF bool - terminal supports xterm focus in/out
userdef rv str - response to RV, regular expression
userdef xr str - response to XR, regular expression
#
used_by xterm
userdef csl str - clear status line
userdef kDC3 str - alt delete-character
userdef kDC4 str - shift+alt delete-character
userdef kDC5 str - control delete-character
userdef kDC6 str - shift+control delete-character
userdef kDC7 str - alt+control delete-character
userdef kDN str - shift down-cursor
userdef kDN3 str - alt down-cursor
userdef kDN4 str - shift+alt down-cursor
userdef kDN5 str - control down-cursor
userdef kDN6 str - shift+control down-cursor
userdef kDN7 str - alt+control down-cursor
userdef kEND3 str - alt end
userdef kEND4 str - shift+alt end
userdef kEND5 str - control end
userdef kEND6 str - shift+control end
userdef kEND7 str - alt+control end
userdef kHOM3 str - alt home
userdef kHOM4 str - shift+alt home
userdef kHOM5 str - control home
userdef kHOM6 str - shift+control home
userdef kHOM7 str - alt+control home
userdef kIC3 str - alt insert-character
userdef kIC4 str - shift+alt insert-character
userdef kIC5 str - control insert-character
userdef kIC6 str - shift+control insert-character
userdef kIC7 str - alt+control insert-character
userdef kLFT3 str - alt left-cursor
userdef kLFT4 str - shift+alt left-cursor
userdef kLFT5 str - control left-cursor
userdef kLFT6 str - shift+control left-cursor
userdef kLFT7 str - alt+control left-cursor
userdef kNXT3 str - alt next
userdef kNXT4 str - shift+alt next
userdef kNXT5 str - control next
userdef kNXT6 str - shift+control next
userdef kNXT7 str - alt+control next
userdef kPRV3 str - alt previous
userdef kPRV4 str - shift+alt previous
userdef kPRV5 str - control previous
userdef kPRV6 str - shift+control previous
userdef kPRV7 str - alt+control previous
userdef kRIT3 str - alt right-cursor
userdef kRIT4 str - shift+alt right-cursor
userdef kRIT5 str - control right-cursor
userdef kRIT6 str - shift+control right-cursor
userdef kRIT7 str - alt+control right-cursor
userdef kUP str - shift up-cursor
userdef kUP3 str - alt up-cursor
userdef kUP4 str - shift+alt up-cursor
userdef kUP5 str - control up-cursor
userdef kUP6 str - shift+control up-cursor
userdef kUP7 str - alt+control up-cursor
userdef ka2 str - vt220-keypad extensions
userdef kb1 str - vt220-keypad extensions
userdef kb3 str - vt220-keypad extensions
userdef kc2 str - vt220-keypad extensions
userdef kxIN str - mouse response on focus-in
userdef kxOUT str - mouse response on focus-out
#############################################################################

121
lib/libcurses/MKterminfo.sh Normal file
View file

@ -0,0 +1,121 @@
#!/bin/sh
# $Id: MKterminfo.sh,v 1.1 2023/10/17 09:52:08 nicm Exp $
#
# MKterminfo.sh -- generate terminfo.5 from Caps tabular data
#
#***************************************************************************
# Copyright 2018-2020,2022 Thomas E. Dickey *
# Copyright 1998-2003,2017 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. *
#***************************************************************************
#
# This script takes terminfo.head and terminfo.tail and splices in between
# them a table derived from the Caps data file. Besides avoiding having
# the docs fall out of sync with the table, this also lets us set up tbl
# commands for better formatting of the table.
#
# NOTE: The s in this script really are control characters. It translates
#  to \n because I couldn't get used to inserting linefeeds directly. There
# had better be no s in the table source text.
#
# keep the order 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
#
head="$1"
shift 1
caps=
while test $# -gt 1
do
caps="$caps $1"
shift 1
done
tail="$1"
cat <<EOF
'\\" t
.\\" DO NOT EDIT THIS FILE BY HAND!
.\\" It is generated from terminfo.head, $caps, and terminfo.tail.
.\\"
.\\" Note: this must be run through tbl before nroff.
.\\" The magic cookie on the first line triggers this under some man programs.
EOF
cat "$head"
temp=temp$$
sorted=sorted$$
unsorted=unsorted$$
trap 'code=$?; rm -f $sorted $temp $unsorted; exit $code' EXIT HUP INT QUIT TERM
rm -f $sorted $temp $unsorted
cat $caps | sed -n "\
/%%-STOP-HERE-%%/q
/^#%center/s, expand,,
/^#%lw25/s, lw6 , lw7 ,
/^#%/s/#%//p
/^#/d
s/[ ][ ]*/ /g
s/$/T}/
s/ [A-Z0-9_()\-][A-Z0-9_()\-]* [0-9\-][0-9\-]* [Y\-][B\-][C\-][G\-][EK\-]\** / T{/
s/ bool / /p
s/ num / /p
s/ str / /p
" |sed -e 's/^$/../' | tr "\134" "\006" >$unsorted
rm -f $sorted
rm -f $temp
saved=no
while true
do
data=
read data
test -z "$data" && break
case "$data" in #(vi
**) #(vi
echo "$data" >>$temp
saved=yes
;;
*)
if test $saved = yes ; then
saved=no
sort $temp >>$sorted
rm -f $temp
fi
echo "$data" >>$sorted
;;
esac
done <$unsorted
test $saved = yes && sort $temp >>$sorted
sed -e 's/^\.\.$//' $sorted | tr "\005\006" "\012\134"
sed -e '/^center expand;/s, expand,,' \
-e '/^\.TS/,/^\\/s, lw[1-9][0-9]*\., l.,' \
"$tail"

View file

@ -1,7 +1,6 @@
# $OpenBSD: Makefile,v 1.74 2019/02/13 15:10:40 nicm Exp $
# $OpenBSD: Makefile,v 1.75 2023/10/17 09:52:08 nicm Exp $
# Uncomment this to enable tracing in libcurses
#CURSESTRACE=-DTRACE
LIB= curses
# This is used to compile terminal info directly into the library
FALLBACK_LIST=
@ -12,89 +11,72 @@ AWK?= /usr/bin/awk
# Search in subdirs
.PATH: ${.CURDIR}/base ${.CURDIR}/tinfo ${.CURDIR}/trace ${.CURDIR}/tty \
${.CURDIR}/widechar
LIB= curses
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 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 \
lib_scanw.c lib_screen.c lib_scroll.c lib_scrollok.c \
lib_scrreg.c lib_set_term.c lib_slk.c lib_slkatr_set.c \
lib_slkatrof.c lib_slkatron.c lib_slkatrset.c lib_slkattr.c \
lib_slkclear.c lib_slkcolor.c lib_slkinit.c lib_slklab.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 \
tries.c use_window.c version.c vsscanf.c wresize.c
# tinfo
SRCS= codes.c comp_captab.c comp_userdefs.c expanded.c fallback.c \
lib_gen.c lib_keyname.c names.c unctrl.c
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 \
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_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 \
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
# widechar
SRCS+= charable.c lib_add_wch.c lib_box_set.c lib_cchar.c lib_erasewchar.c \
lib_get_wch.c lib_get_wstr.c lib_hline_set.c lib_in_wch.c \
lib_in_wchnstr.c lib_ins_wch.c lib_inwstr.c lib_key_name.c \
lib_pecho_wchar.c lib_slk_wset.c lib_unget_wch.c lib_vid_attr.c \
lib_vline_set.c lib_wacs.c lib_wunctrl.c
charable.c comp_error.c comp_expand.c comp_hash.c comp_parse.c \
comp_scan.c db_iterator.c define_key.c doalloc.c entries.c \
free_ttype.c getenv_num.c hardscroll.c hashed_db.c hashmap.c \
home_terminfo.c init_keytry.c key_defined.c keybound.c keyok.c \
legacy_coding.c lib_acs.c lib_add_wch.c lib_addch.c lib_addstr.c \
lib_baudrate.c lib_beep.c lib_bkgd.c lib_box.c lib_box_set.c \
lib_cchar.c lib_chgat.c lib_clear.c lib_clearok.c lib_clrbot.c \
lib_clreol.c lib_color.c lib_colorset.c lib_cur_term.c lib_data.c \
lib_delch.c lib_delwin.c lib_dft_fgbg.c lib_echo.c lib_endwin.c \
lib_erase.c lib_erasewchar.c lib_flash.c lib_freeall.c lib_get_wch.c \
lib_get_wstr.c lib_getch.c lib_getstr.c lib_has_cap.c lib_hline.c \
lib_hline_set.c lib_immedok.c lib_in_wch.c lib_in_wchnstr.c \
lib_inchstr.c lib_initscr.c lib_ins_wch.c lib_insch.c lib_insdel.c \
lib_insnstr.c lib_instr.c lib_inwstr.c lib_isendwin.c lib_kernel.c \
lib_key_name.c lib_leaveok.c lib_longname.c lib_mouse.c lib_move.c \
lib_mvcur.c lib_mvwin.c lib_napms.c lib_newterm.c lib_newwin.c \
lib_nl.c lib_options.c lib_overlay.c lib_pad.c lib_pecho_wchar.c \
lib_print.c lib_printw.c lib_raw.c lib_redrawln.c lib_refresh.c \
lib_restart.c lib_scanw.c lib_screen.c lib_scroll.c lib_scrollok.c \
lib_scrreg.c lib_set_term.c lib_setup.c lib_slk.c lib_slk_wset.c \
lib_slkatr_set.c lib_slkatrof.c lib_slkatron.c lib_slkatrset.c \
lib_slkattr.c lib_slkclear.c lib_slkcolor.c lib_slkinit.c \
lib_slklab.c lib_slkrefr.c lib_slkset.c lib_slktouch.c lib_termcap.c \
lib_termname.c lib_tgoto.c lib_ti.c lib_touch.c lib_tparm.c \
lib_tputs.c lib_trace.c lib_tstp.c lib_ttyflags.c lib_twait.c \
lib_unget_wch.c lib_ungetch.c lib_vid_attr.c lib_vidattr.c \
lib_vline.c lib_vline_set.c lib_wacs.c lib_wattroff.c lib_wattron.c \
lib_winch.c lib_window.c lib_wunctrl.c name_match.c nc_panel.c \
new_pair.c obsolete.c parse_entry.c read_entry.c read_termcap.c \
resizeterm.c safe_sprintf.c strings.c tries.c trim_sgr0.c \
tty_update.c use_screen.c use_window.c version.c visbuf.c vsscanf.c \
wresize.c write_entry.c
HOSTCFLAGS?= ${CFLAGS}
HOSTLDFLAGS?= ${LDFLAGS}
HOSTCFLAGS+= -I. -I${.CURDIR} ${CURSESTRACE}
CFLAGS+= -I. -I${.CURDIR} ${CURSESTRACE}
HOSTCFLAGS+= -I. -I${.CURDIR}
CFLAGS+= -I. -I${.CURDIR} -D_XOPEN_SOURCE_EXTENDED -DNDEBUG
MAN= curs_addch.3 curs_addchstr.3 curs_addstr.3 curs_attr.3 \
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.3 curs_getstr.3 curs_getyx.3 \
MAN= curs_add_wch.3 curs_add_wchstr.3 curs_addch.3 curs_addchstr.3 \
curs_addstr.3 curs_addwstr.3 curs_attr.3 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_get_wch.3 curs_get_wstr.3 curs_getcchar.3 curs_getch.3 \
curs_getstr.3 curs_getyx.3 curs_in_wch.3 curs_in_wchstr.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_legacy.3 \
curs_mouse.3 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 \
curs_add_wch.3 curs_add_wchstr.3 curs_addwstr.3 curs_get_wch.3 \
curs_get_wstr.3 curs_in_wch.3 curs_in_wchstr.3 curs_ins_wch.3 \
curs_ins_wstr.3 curs_inwstr.3 \
default_colors.3 define_key.3 \
key_defined.3 keybound.3 keyok.3 legacy_coding.3 \
curses.3 \
resizeterm.3 \
term.5 term.7 termcap.3 terminfo.3 terminfo.5 \
curs_ins_wch.3 curs_ins_wstr.3 curs_insch.3 curs_insstr.3 \
curs_instr.3 curs_inwstr.3 curs_kernel.3 curs_legacy.3 \
curs_memleaks.3 curs_mouse.3 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_sp_funcs.3 curs_termattrs.3 curs_threads.3 curs_touch.3 \
curs_util.3 curs_variables.3 curs_window.3 curses.3 \
default_colors.3 define_key.3 key_defined.3 keybound.3 keyok.3 \
legacy_coding.3 new_pair.3 resizeterm.3 scr_dump.5 term.5 term.7 \
term_variables.3 termcap.3 terminfo.3 terminfo.5 user_caps.5 \
wresize.3
GENERATED= codes.c comp_captab.c comp_userdefs.c expanded.c fallback.c \
init_keytry.h keys.list lib_gen.c lib_keyname.c make_hash make_keys \
names.c
CAPLIST = ${.CURDIR}/Caps
USE_BIG_STRINGS = 1
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}
BUILDFIRST = ${GENERATED}
@ -103,7 +85,7 @@ includes:
@cmp -s ${DESTDIR}/usr/include/ncurses.h ${.CURDIR}/curses.h || \
${INSTALL} ${INSTALL_COPY} -m 444 -o $(BINOWN) -g $(BINGRP) \
${.CURDIR}/curses.h ${DESTDIR}/usr/include/ncurses.h
@cd ${.CURDIR}; for i in unctrl.h term.h termcap.h; do \
@cd ${.CURDIR}; for i in ncurses_dll.h unctrl.h term.h termcap.h; do \
cmp -s $$i ${DESTDIR}/usr/include/$$i || \
${INSTALL} ${INSTALL_COPY} -m 444 -o $(BINOWN) -g $(BINGRP) $$i \
${DESTDIR}/usr/include; done
@ -112,7 +94,7 @@ keys.list: ${.CURDIR}/tinfo/MKkeys_list.sh
sh ${.CURDIR}/tinfo/MKkeys_list.sh ${.CURDIR}/Caps | sort > ${.TARGET}
fallback.c: ${.CURDIR}/tinfo/MKfallback.sh
sh ${.CURDIR}/tinfo/MKfallback.sh $(FALLBACK_LIST) > ${.TARGET}
sh ${.CURDIR}/tinfo/MKfallback.sh /usr/share/terminfo ${.CURDIR}/../../share/termtypes/termtypes.master $(FALLBACK_LIST) > ${.TARGET}
lib_gen.c: ${.CURDIR}/base/MKlib_gen.sh
sh ${.CURDIR}/base/MKlib_gen.sh "${CC} -E -P -I${.CURDIR}" \
@ -124,30 +106,39 @@ init_keytry.h: make_keys keys.list
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}/curses.priv.h \
make_hash: ${.CURDIR}/tinfo/make_hash.c \
${.CURDIR}/curses.priv.h \
${.CURDIR}/hashsize.h
${HOSTCC} ${LDSTATIC} ${HOSTCFLAGS} -DMAIN_PROGRAM ${HOSTLDFLAGS} \
-o ${.TARGET} ${.CURDIR}/tinfo/comp_hash.c ${LDADD}
-o ${.TARGET} ${.CURDIR}/tinfo/make_hash.c ${LDADD}
CAPLIST += ${.CURDIR}/Caps-ncurses
comp_userdefs.c: make_hash \
${.CURDIR}/hashsize.h \
${.CURDIR}/tinfo/MKuserdefs.sh
sh ${.CURDIR}/tinfo/MKuserdefs.sh ${AWK} ${USE_BIG_STRINGS} ${CAPLIST} > ${.TARGET}
expanded.c: ${.CURDIR}/term.h ${.CURDIR}/curses.priv.h \
${.CURDIR}/ncurses_cfg.h ${.CURDIR}/tty/MKexpanded.sh
sh ${.CURDIR}/tty/MKexpanded.sh "${CC} -E -P" ${CPPFLAGS} > ${.TARGET}
comp_captab.c: make_hash
sh ${.CURDIR}/tinfo/MKcaptab.sh ${AWK} 1 \
${.CURDIR}/tinfo/MKcaptab.awk ${.CURDIR}/Caps > ${.TARGET}
sh ${.CURDIR}/tinfo/MKcaptab.sh ${AWK} ${USE_BIG_STRINGS} \
${.CURDIR}/tinfo/MKcaptab.awk ${CAPLIST} > ${.TARGET}
lib_keyname.c: keys.list ${.CURDIR}/base/MKkeyname.awk
${AWK} -f ${.CURDIR}/base/MKkeyname.awk bigstrings=1 \
${AWK} -f ${.CURDIR}/base/MKkeyname.awk \
bigstrings=${USE_BIG_STRINGS} \
keys.list > ${.TARGET}
names.c: ${.CURDIR}/tinfo/MKnames.awk
${AWK} -f ${.CURDIR}/tinfo/MKnames.awk \
${.CURDIR}/Caps > names.c
bigstrings=${USE_BIG_STRINGS} \
${CAPLIST} > ${.TARGET}
codes.c: ${.CURDIR}/tinfo/MKcodes.awk
${AWK} -f ${.CURDIR}/tinfo/MKcodes.awk \
bigstrings=1 ${.CURDIR}/Caps > codes.c
bigstrings=${USE_BIG_STRINGS} \
${CAPLIST} > ${.TARGET}
unctrl.c: ${.CURDIR}/base/MKunctrl.awk
echo | ${AWK} -f ${.CURDIR}/base/MKunctrl.awk bigstrings=1 > ${.TARGET}

View file

@ -1,7 +1,8 @@
/* $OpenBSD: SigAction.h,v 1.4 2010/01/12 23:21:58 nicm Exp $ */
/* $OpenBSD: SigAction.h,v 1.5 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998,2000 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 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 *
@ -34,7 +35,7 @@
****************************************************************************/
/*
* $Id: SigAction.h,v 1.4 2010/01/12 23:21:58 nicm Exp $
* $Id: SigAction.h,v 1.5 2023/10/17 09:52:08 nicm Exp $
*
* This file exists to handle non-POSIX systems which don't have <unistd.h>,
* and usually no sigaction() nor <termios.h>

View file

@ -1,7 +1,8 @@
# $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 $
# $OpenBSD: MKkeyname.awk,v 1.6 2023/10/17 09:52:08 nicm Exp $
# $Id: MKkeyname.awk,v 1.6 2023/10/17 09:52:08 nicm Exp $
##############################################################################
# Copyright (c) 1999-2007,2008 Free Software Foundation, Inc. #
# Copyright 2020 Thomas E. Dickey #
# Copyright 1998-2016,2017 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"), #
@ -32,7 +33,6 @@ BEGIN {
print ""
print "#include <curses.priv.h>"
print "#include <tic.h>"
print "#include <term_entry.h>"
print ""
first = 1;
}
@ -67,18 +67,18 @@ END {
print ""
print "#define SIZEOF_TABLE 256"
print "#define MyTable _nc_globals.keyname_table"
print "#define MyInit _nc_globals.init_keyname"
print ""
print "NCURSES_EXPORT(NCURSES_CONST char *) _nc_keyname (SCREEN *sp, int c)"
print "NCURSES_EXPORT(NCURSES_CONST char *)"
print "safe_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 {"
print " int i;"
if (bigstrings) {
print " for (i = 0; _nc_key_names[i].offset != -1; i++) {"
print " if (_nc_key_names[i].code == c) {"
@ -98,36 +98,49 @@ END {
print " if (result == 0 && (c >= 0 && c < SIZEOF_TABLE)) {"
print " if (MyTable == 0)"
print " MyTable = typeCalloc(char *, SIZEOF_TABLE);"
print ""
print " if (MyTable != 0) {"
print " int m_prefix = (sp == 0 || sp->_use_meta);"
print ""
print " /* if sense of meta() changed, discard cached data */"
print " if (MyInit != (m_prefix + 1)) {"
print " MyInit = m_prefix + 1;"
print " for (i = 0; i < SIZEOF_TABLE; ++i) {"
print " if (MyTable[i]) {"
print " FreeAndNull(MyTable[i]);"
print " }"
print " }"
print " }"
print ""
print " /* create and cache result as needed */"
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 " char *p = name;"
print "#define P_LIMIT (sizeof(name) - (size_t) (p - name))"
print " if (cc >= 128 && m_prefix) {"
print " _nc_STRCPY(p, \"M-\", P_LIMIT);"
print " p += 2;"
print " psize -= 2;"
print " cc -= 128;"
print " }"
print " if (cc < 32)"
print " snprintf(p, psize, \"^%c\", cc + '@');"
print " _nc_SPRINTF(p, _nc_SLIMIT(P_LIMIT) \"^%c\", cc + '@');"
print " else if (cc == 127)"
print " strlcpy(p, \"^?\", psize);"
print " _nc_STRCPY(p, \"^?\", P_LIMIT);"
print " else"
print " snprintf(p, psize, \"%c\", cc);"
print " _nc_SPRINTF(p, _nc_SLIMIT(P_LIMIT) \"%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 " } else if (result == 0 && HasTerminal(sp)) {"
print " int j, k;"
print " char * bound;"
print " TERMTYPE *tp = &(cur_term->type);"
print " int save_trace = _nc_tracing;"
print " TERMTYPE2 *tp = &TerminalType(TerminalOf(sp));"
print " unsigned 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 (j = 0; (bound = NCURSES_SP_NAME(keybound)(NCURSES_SP_ARGx 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);"
@ -145,16 +158,17 @@ END {
print " return result;"
print "}"
print ""
print "NCURSES_EXPORT(NCURSES_CONST char *) keyname (int c)"
print "NCURSES_EXPORT(NCURSES_CONST char *)"
print "keyname (int c)"
print "{"
print "\treturn _nc_keyname(SP, c);"
print " return safe_keyname (CURRENT_SCREEN, c);"
print "}"
print ""
print "#if NO_LEAKS"
print "void _nc_keyname_leaks(void)"
print "{"
print " int j;"
print " if (MyTable != 0) {"
print " int j;"
print " for (j = 0; j < SIZEOF_TABLE; ++j) {"
print " FreeIfNeeded(MyTable[j]);"
print " }"

View file

@ -1,12 +1,13 @@
# $OpenBSD: MKlib_gen.sh,v 1.5 2023/10/17 09:52:08 nicm Exp $
#!/bin/sh
#
# MKlib_gen.sh -- generate sources from curses.h macro definitions
#
# $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 $)
# ($Id: MKlib_gen.sh,v 1.5 2023/10/17 09:52:08 nicm Exp $)
#
##############################################################################
# Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. #
# Copyright 2018-2021,2022 Thomas E. Dickey #
# Copyright 1998-2016,2017 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"), #
@ -52,7 +53,7 @@
# them.
# 5. cpp: macro-expand the file so the macro calls turn into C calls
# 6. awk: strip the expansion junk off the front and add the new header
# 7. sed: squeeze spaces, strip off gen_ prefix, create needed #undef
# 7. sed: squeeze spaces, strip off gen_ prefix.
#
# keep the editing independent of locale:
@ -63,10 +64,36 @@ 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"
preprocessor="$1 -DNCURSES_WATTR_MACROS -DNCURSES_INTERNALS -I../include"
AWK="$2"
USE="$3"
# A patch discussed here:
# https://gcc.gnu.org/ml/gcc-patches/2014-06/msg02185.html
#
# introduces spurious #line markers into the preprocessor output. The result
# appears in gcc 5.0 and (with modification) in 5.1, making it necessary to
# determine if we are using gcc, and if so, what version because the proposed
# solution uses a nonstandard option.
#
# As illustrated in
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60723
#
# gcc developers chose to ignore the problems with this, and summarized those
# as "intriguing problems" in
# https://gcc.gnu.org/gcc-5/porting_to.html
PRG=`echo "$1" | "$AWK" '{ sub(/^[ ]*/,""); sub(/[ ].*$/, ""); print; }' || exit 0`
FSF=`("$PRG" --version 2>/dev/null || exit 0) | ${FGREP-grep -F} "Free Software Foundation" | head -n 1`
ALL=`"$PRG" -dumpversion 2>/dev/null || exit 0`
ONE=`echo "$ALL" | sed -e 's/[^0-9].*$//'`
if test -n "$FSF" && test -n "$ALL" && test -n "$ONE" ; then
if test "$ONE" -ge 5 ; then
echo ".. adding -P option to work around $PRG $ALL" >&2
preprocessor="$preprocessor -P"
fi
fi
PID=$$
ED1=sed1_${PID}.sed
ED2=sed2_${PID}.sed
@ -75,13 +102,16 @@ 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
trap "rm -f $ED1 $ED2 $ED3 $ED4 $AW1 $AW2 $TMP; exit 1" 1 2 3 15
trap "rm -f $ED1 $ED2 $ED3 $ED4 $AW1 $AW2 $TMP" 0
ALL=$USE
if test "$USE" = implemented ; then
CALL="call_"
cat >$ED1 <<EOF1
/^extern.*implemented/{
h
s/GCC_DEPRECATED([^)]*)//
s/NCURSES_SP_NAME(\([^)]*\))/NCURSES_SP_NAME___\1/
h
s/^.*implemented:\([^ *]*\).*/P_POUNDCif_USE_\1_SUPPORT/p
g
@ -99,7 +129,6 @@ if test "$USE" = implemented ; then
}
EOF1
else
CALL=""
cat >$ED1 <<EOF1
/^extern.*${ALL}/{
h
@ -152,7 +181,6 @@ cat >$ED3 <<EOF3
s/( /(/g
s/ )/)/g
s/ gen_/ /
s/^M_/#undef /
s/^[ ]*@[ ]*@[ ]*/ /
:done
EOF3
@ -160,6 +188,7 @@ EOF3
if test "$USE" = generated ; then
cat >$ED4 <<EOF
s/^\(.*\) \(.*\) (\(.*\))\$/NCURSES_EXPORT(\1) \2 (\3)/
/attr_[sg]et.* z)/s,z),z GCC_UNUSED),
EOF
else
cat >$ED4 <<EOF
@ -170,6 +199,7 @@ cat >$ED4 <<EOF
g
s/^\(.*\) \(.*\) (\(.*\))\$/\1 call_\2 (\3)/
}
s/\([^_]\)NCURSES_SP_NAME___\([a-zA-Z][a-zA-Z_]*\)/\1NCURSES_SP_NAME(\2)/g
EOF
fi
@ -199,18 +229,20 @@ $0 !~ /^P_/ {
}
}
second = first + 1;
returnCast = "";
if ( $first == "chtype" ) {
returnType = "Char";
returnType = "Chtype";
} 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";
returnType = "IntAttr";
returnCast = "(attr_t)";
} else if ( $first == "bool" || $first == "NCURSES_BOOL" ) {
returnType = "Bool";
} else if ( $second == "*" ) {
returnType = "Ptr";
returnType = ($1 == "NCURSES_CONST") ? "CPtr" : "Ptr";
} else {
returnType = "Code";
}
@ -221,8 +253,8 @@ $0 !~ /^P_/ {
break;
}
}
if (using == "generated") {
print "M_" $myfunc
if (using == "implemented") {
printf "#undef %s\n", $myfunc;
}
print $0;
print "{";
@ -248,11 +280,19 @@ $0 !~ /^P_/ {
if ($myfunc ~ /ripoffline/) {
dotrace = 0;
argcount = 2;
if ($myfunc ~ /NCURSES_SP_NAME/) {
argcount = 3;
}
}
if ($myfunc ~ /wunctrl/) {
dotrace = 0;
}
do_getstr = 0;
if ($myfunc ~ /get[n]?str/) {
do_getstr = 1;
}
call = "@@T((T_CALLED(\""
args = ""
comma = ""
@ -263,35 +303,43 @@ $0 !~ /^P_/ {
argtype = ""
for (i = myfunc; i <= NF; i++) {
ch = $i;
if ( ch == "*" )
if ( ch == "*" ) {
pointer = 1;
else if ( ch == "va_list" )
} else if ( ch == "va_list" ) {
va_list = 1;
else if ( ch == "..." )
} else if ( ch == "..." ) {
varargs = 1;
else if ( ch == "char" )
} else if ( ch == "char" ) {
argtype = "char";
else if ( ch == "int" )
} else if ( ch == "int" ) {
argtype = "int";
else if ( ch == "short" )
} else if ( ch == "short" ) {
argtype = "short";
else if ( ch == "chtype" )
} else if ( ch == "chtype" ) {
argtype = "chtype";
else if ( ch == "attr_t" || ch == "NCURSES_ATTR_T" )
} else if ( ch == "attr_t" || ch == "NCURSES_ATTR_T" ) {
argtype = "attr";
}
if ( ch == "," || ch == ")" ) {
argcast = "";
if (va_list) {
call = call "%s"
} else if (varargs) {
call = call "%s"
} else if (pointer) {
if ( argtype == "char" ) {
call = call "%s"
if (do_getstr) {
call = call "%p"
} else {
call = call "%s"
}
comma = comma "_nc_visbuf2(" num ","
pointer = 0;
} else
} else {
call = call "%p"
comma = comma "(const void *)"
}
} else if (argcount != 0) {
if ( argtype == "int" || argtype == "short" ) {
call = call "%d"
@ -299,6 +347,9 @@ $0 !~ /^P_/ {
} else if ( argtype != "" ) {
call = call "%s"
comma = comma "_trace" argtype "2(" num ","
if (argtype == "attr") {
argcast = "(chtype)";
}
} else {
call = call "%#lx"
comma = comma "(long)"
@ -312,7 +363,7 @@ $0 !~ /^P_/ {
} else if ( varargs ) {
args = args comma "\"...\""
} else {
args = args comma "z"
args = args comma argcast "z"
}
}
call = call ch
@ -323,7 +374,7 @@ $0 !~ /^P_/ {
pointer = 0;
argtype = ""
}
if ( i == 2 || ch == "(" )
if ( i == myfunc || ch == "(" )
call = call ch
}
call = call "\")"
@ -332,14 +383,18 @@ $0 !~ /^P_/ {
call = call ")); "
if (dotrace)
printf "%s", call
printf "%s\n\t@@", call
if (match($0, "^void"))
if (match($0, "^void")) {
call = ""
else if (dotrace)
} else if (dotrace) {
call = sprintf("return%s( ", returnType);
else
if (returnCast != "") {
call = call returnCast;
}
} else {
call = "@@return ";
}
call = call $myfunc "(";
for (i = 1; i < argcount; i++) {
@ -354,8 +409,9 @@ $0 !~ /^P_/ {
}
if (!match($0, "^void"))
call = call ") ";
if (dotrace)
if (dotrace) {
call = call ")";
}
print call ";"
if (match($0, "^void"))
@ -366,9 +422,10 @@ EOF1
cat >$AW2 <<EOF1
BEGIN {
printf "/* This file was generated by $0 $USE */\n"
print ""
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"
@ -382,14 +439,55 @@ BEGIN {
}
print " */"
print "#define NCURSES_ATTR_T int"
print "#include <ncurses_cfg.h>"
print ""
print "#undef NCURSES_NOMACROS /* _this_ file uses macros */"
print "#define NCURSES_NOMACROS 1"
print ""
print "#include <curses.priv.h>"
print ""
}
/^DECLARATIONS/ {start = 1; next;}
{if (start) print \$0;}
{
if (start) {
if ( "$USE" == "generated" ) {
print \$0;
} else if ( \$0 ~ /^[{}]?\$/ ) {
print \$0;
} else if ( \$0 ~ /;/ ) {
print \$0;
} else {
calls[start] = \$0;
print \$0;
start++;
}
}
}
END {
if ( "$USE" != "generated" ) {
print "int main(void) { return 0; }"
print "int main(void)"
print "{"
for (n = 1; n < start; ++n) {
value = calls[n];
if ( value !~ /P_POUNDC/ ) {
gsub(/[ \t]+/," ",value);
sub(/^[0-9a-zA-Z_]+ /,"",value);
sub(/^[*][ \t]*/,"",value);
gsub("struct[ \t]*[0-9a-zA-Z_]+[ \t]*[*]","",value);
gsub(/[0-9a-zA-Z_]+[ \t]*[*][ \t]*/,"",value);
gsub(/ (const) /," ",value);
gsub(/ (int|short|attr_t|chtype|wchar_t|NCURSES_BOOL|NCURSES_OUTC|NCURSES_OUTC_sp|va_list) /," ",value);
gsub(/ void /,"",value);
sub(/^/,"call_",value);
gsub(/ (a[0-9]|z) /, " 0 ", value);
gsub(/ int[ \t]*[(][^)]+[)][(][^)]+[)]/, "0", value);
printf "\t%s;\n", value;
} else {
print value;
}
}
print " return 0;"
print "}"
}
}
EOF1
@ -398,6 +496,8 @@ cat >$TMP <<EOF
#include <ncurses_cfg.h>
#undef NCURSES_NOMACROS
#include <curses.h>
#include <term.h>
#include <unctrl.h>
DECLARATIONS
@ -406,7 +506,7 @@ EOF
sed -n -f $ED1 \
| sed -e 's/NCURSES_EXPORT(\(.*\)) \(.*\) (\(.*\))/\1 \2(\3)/' \
| sed -f $ED2 \
| $AWK -f $AW1 using=$USE \
| "$AWK" -f $AW1 using="$USE" \
| sed \
-e 's/ [ ]*$//g' \
-e 's/^\([a-zA-Z_][a-zA-Z_]*[ *]*\)/\1 gen_/' \
@ -418,7 +518,7 @@ $preprocessor $TMP 2>/dev/null \
-e 's/ / /g' \
-e 's/^ //' \
-e 's/_Bool/NCURSES_BOOL/g' \
| $AWK -f $AW2 \
| "$AWK" -f $AW2 \
| sed -f $ED3 \
| sed \
-e 's/^.*T_CALLED.*returnCode( \([a-z].*) \));/ return \1;/' \

View file

@ -1,7 +1,8 @@
# $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 $
# $OpenBSD: MKunctrl.awk,v 1.5 2023/10/17 09:52:08 nicm Exp $
# $Id: MKunctrl.awk,v 1.5 2023/10/17 09:52:08 nicm Exp $
##############################################################################
# Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. #
# Copyright 2020 Thomas E. Dickey #
# Copyright 1998-2012,2017 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"), #
@ -37,19 +38,12 @@ BEGIN {
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 *) _nc_unctrl (SCREEN *sp, chtype ch)"
print "NCURSES_EXPORT(NCURSES_CONST char *) safe_unctrl(SCREEN *sp, chtype ch)"
print "{"
blob=""
offset=0
if (bigstrings) {
@ -148,9 +142,10 @@ END {
} else {
stringname = "unctrl"
}
print "\tint check = ChCharOf(ch);"
print "\tint check = (int) ChCharOf(ch);"
print "\tconst char *result;"
print ""
print "(void) sp;"
print "\tif (check >= 0 && check < (int)SIZEOF(unctrl_table)) {"
print "#if NCURSES_EXT_FUNCS"
print "\t\tif ((sp != 0)"
@ -159,16 +154,6 @@ END {
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)"
@ -177,7 +162,6 @@ END {
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 {"
@ -188,6 +172,6 @@ END {
print ""
print "NCURSES_EXPORT(NCURSES_CONST char *) unctrl (chtype ch)"
print "{"
print "\treturn _nc_unctrl(SP, ch);"
print "\treturn safe_unctrl(CURRENT_SCREEN, ch);"
print "}"
}

View file

@ -1,7 +1,8 @@
/* $OpenBSD: define_key.c,v 1.5 2010/01/12 23:22:05 nicm Exp $ */
/* $OpenBSD: define_key.c,v 1.6 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2009,2014 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,33 +30,40 @@
****************************************************************************/
/****************************************************************************
* Author: Thomas E. Dickey 1997-on *
* Author: Thomas E. Dickey 1997-on *
* and: Juergen Pfeifer 2009 *
****************************************************************************/
#include <curses.priv.h>
MODULE_ID("$Id: define_key.c,v 1.5 2010/01/12 23:22:05 nicm Exp $")
MODULE_ID("$Id: define_key.c,v 1.6 2023/10/17 09:52:08 nicm Exp $")
NCURSES_EXPORT(int)
define_key(const char *str, int keycode)
NCURSES_SP_NAME(define_key) (NCURSES_SP_DCLx const char *str, int keycode)
{
int code = ERR;
T((T_CALLED("define_key(%s,%d)"), _nc_visbuf(str), keycode));
if (SP == 0) {
T((T_CALLED("define_key(%p, %s,%d)"), (void *) SP_PARM, _nc_visbuf(str), keycode));
if (SP_PARM == 0 || !HasTInfoTerminal(SP_PARM)) {
code = ERR;
} else if (keycode > 0) {
unsigned ukey = (unsigned) keycode;
#ifdef USE_TERM_DRIVER
#define CallHasKey(keycode) CallDriver_1(SP_PARM, td_kyExist, keycode)
#else
#define CallHasKey(keycode) NCURSES_SP_NAME(has_key)(NCURSES_SP_ARGx keycode)
#endif
if (str != 0) {
define_key(str, 0);
} else if (has_key(keycode)) {
while (_nc_remove_key(&(SP->_keytry), ukey))
NCURSES_SP_NAME(define_key) (NCURSES_SP_ARGx str, 0);
} else if (CallHasKey(keycode)) {
while (_nc_remove_key(&(SP_PARM->_keytry), ukey))
code = OK;
}
if (str != 0) {
if (key_defined(str) == 0) {
if (_nc_add_to_try(&(SP->_keytry), str, ukey) == OK) {
if (NCURSES_SP_NAME(key_defined) (NCURSES_SP_ARGx str) == 0) {
if (_nc_add_to_try(&(SP_PARM->_keytry), str, ukey) == OK) {
code = OK;
} else {
code = ERR;
@ -65,8 +73,16 @@ define_key(const char *str, int keycode)
}
}
} else {
while (_nc_remove_string(&(SP->_keytry), str))
while (_nc_remove_string(&(SP_PARM->_keytry), str))
code = OK;
}
returnCode(code);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
define_key(const char *str, int keycode)
{
return NCURSES_SP_NAME(define_key) (CURRENT_SCREEN, str, keycode);
}
#endif

View file

@ -1,7 +1,8 @@
/* $OpenBSD: key_defined.c,v 1.1 2010/01/12 23:22:05 nicm Exp $ */
/* $OpenBSD: key_defined.c,v 1.2 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 2003,2006 Free Software Foundation, Inc. *
* Copyright 2020,2023 Thomas E. Dickey *
* Copyright 2003-2006,2009 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 *
@ -33,8 +34,9 @@
****************************************************************************/
#include <curses.priv.h>
#include <tic.h>
MODULE_ID("$Id: key_defined.c,v 1.1 2010/01/12 23:22:05 nicm Exp $")
MODULE_ID("$Id: key_defined.c,v 1.2 2023/10/17 09:52:08 nicm Exp $")
static int
find_definition(TRIES * tree, const char *str)
@ -42,7 +44,7 @@ find_definition(TRIES * tree, const char *str)
TRIES *ptr;
int result = OK;
if (str != 0 && *str != '\0') {
if (VALID_STRING(str) && *str != '\0') {
for (ptr = tree; ptr != 0; ptr = ptr->sibling) {
if (UChar(*str) == UChar(ptr->ch)) {
if (str[1] == '\0' && ptr->child != 0) {
@ -67,14 +69,22 @@ find_definition(TRIES * tree, const char *str)
* Otherwise, return the keycode's value (neither OK/ERR).
*/
NCURSES_EXPORT(int)
key_defined(const char *str)
NCURSES_SP_NAME(key_defined) (NCURSES_SP_DCLx const char *str)
{
int code = ERR;
T((T_CALLED("key_defined(%s)"), _nc_visbuf(str)));
if (SP != 0 && str != 0) {
code = find_definition(SP->_keytry, str);
T((T_CALLED("key_defined(%p, %s)"), (void *) SP_PARM, _nc_visbuf(str)));
if (SP_PARM != 0 && str != 0) {
code = find_definition(SP_PARM->_keytry, str);
}
returnCode(code);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
key_defined(const char *str)
{
return NCURSES_SP_NAME(key_defined) (CURRENT_SCREEN, str);
}
#endif

View file

@ -1,7 +1,8 @@
/* $OpenBSD: keybound.c,v 1.5 2010/01/12 23:22:05 nicm Exp $ */
/* $OpenBSD: keybound.c,v 1.6 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1999-2005,2006 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1999-2009,2011 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,26 +30,37 @@
****************************************************************************/
/****************************************************************************
* Author: Thomas E. Dickey 1999-on *
* Author: Thomas E. Dickey 1999-on *
* and: Juergen Pfeifer 2009 *
****************************************************************************/
#include <curses.priv.h>
#include <limits.h>
MODULE_ID("$Id: keybound.c,v 1.5 2010/01/12 23:22:05 nicm Exp $")
MODULE_ID("$Id: keybound.c,v 1.6 2023/10/17 09:52:08 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)
NCURSES_SP_NAME(keybound) (NCURSES_SP_DCLx int code, int count)
{
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);
T((T_CALLED("keybound(%p, %d,%d)"), (void *) SP_PARM, code, count));
if (SP_PARM != 0 && code >= 0) {
result = _nc_expand_try(SP_PARM->_keytry,
(unsigned) code,
&count,
(size_t) 0);
}
returnPtr(result);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(char *)
keybound(int code, int count)
{
return NCURSES_SP_NAME(keybound) (CURRENT_SCREEN, code, count);
}
#endif

View file

@ -1,7 +1,8 @@
/* $OpenBSD: keyok.c,v 1.5 2010/01/12 23:22:05 nicm Exp $ */
/* $OpenBSD: keyok.c,v 1.6 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2000,2006 Free Software Foundation, Inc. *
* Copyright 2019-2020,2021 Thomas E. Dickey *
* Copyright 1998-2012,2014 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,52 +30,76 @@
****************************************************************************/
/****************************************************************************
* Author: Thomas E. Dickey 1997-on *
* Author: Thomas E. Dickey 1997-on *
* and: Juergen Pfeifer 2009 *
****************************************************************************/
#include <curses.priv.h>
MODULE_ID("$Id: keyok.c,v 1.5 2010/01/12 23:22:05 nicm Exp $")
MODULE_ID("$Id: keyok.c,v 1.6 2023/10/17 09:52:08 nicm Exp $")
/*
* Enable (or disable) ncurses' interpretation of a keycode by adding (or
* removing) the corresponding 'tries' entry.
*
* Do this by storing a second tree of tries, which records the disabled keys.
* Do this by storing a second tree of tries, which records the disabled keys.
* The simplest way to copy is to make a function that returns the string (with
* nulls set to 0200), then use that to reinsert the string into the
* corresponding tree.
*/
NCURSES_EXPORT(int)
keyok(int c, bool flag)
NCURSES_SP_NAME(keyok) (NCURSES_SP_DCLx int c, bool flag)
{
int code = ERR;
int count = 0;
char *s;
T((T_CALLED("keyok(%d,%d)"), c, flag));
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;
if (HasTerminal(SP_PARM)) {
T((T_CALLED("keyok(%p, %d,%d)"), (void *) SP_PARM, c, flag));
#ifdef USE_TERM_DRIVER
code = CallDriver_2(sp, td_kyOk, c, flag);
#else
if (c >= 0) {
int count = 0;
char *s;
unsigned ch = (unsigned) c;
if (flag) {
while ((s = _nc_expand_try(SP_PARM->_key_ok,
ch, &count, (size_t) 0)) != 0) {
if (_nc_remove_key(&(SP_PARM->_key_ok), ch)) {
code = _nc_add_to_try(&(SP_PARM->_keytry), s, ch);
free(s);
count = 0;
if (code != OK)
break;
} else {
free(s);
}
}
} else {
while ((s = _nc_expand_try(SP_PARM->_keytry,
ch, &count, (size_t) 0)) != 0) {
if (_nc_remove_key(&(SP_PARM->_keytry), ch)) {
code = _nc_add_to_try(&(SP_PARM->_key_ok), s, ch);
free(s);
count = 0;
if (code != OK)
break;
} else {
free(s);
}
}
}
}
#endif
}
returnCode(code);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
keyok(int c, bool flag)
{
return NCURSES_SP_NAME(keyok) (CURRENT_SCREEN, c, flag);
}
#endif

View file

@ -1,7 +1,8 @@
/* $OpenBSD: legacy_coding.c,v 1.1 2010/01/12 23:22:05 nicm Exp $ */
/* $OpenBSD: legacy_coding.c,v 1.2 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 2005 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 2005,2009 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,22 +30,31 @@
****************************************************************************/
/****************************************************************************
* Author: Thomas E. Dickey *
* Author: Thomas E. Dickey 2005 *
* Juergen Pfeifer 2009 *
****************************************************************************/
#include <curses.priv.h>
MODULE_ID("$Id: legacy_coding.c,v 1.1 2010/01/12 23:22:05 nicm Exp $")
MODULE_ID("$Id: legacy_coding.c,v 1.2 2023/10/17 09:52:08 nicm Exp $")
NCURSES_EXPORT(int)
use_legacy_coding(int level)
NCURSES_SP_NAME(use_legacy_coding) (NCURSES_SP_DCLx 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;
T((T_CALLED("use_legacy_coding(%p,%d)"), (void *) SP_PARM, level));
if (level >= 0 && level <= 2 && SP_PARM != 0) {
result = SP_PARM->_legacy_coding;
SP_PARM->_legacy_coding = level;
}
returnCode(result);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
use_legacy_coding(int level)
{
return NCURSES_SP_NAME(use_legacy_coding) (CURRENT_SCREEN, level);
}
#endif

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_addch.c,v 1.5 2010/01/12 23:22:05 nicm Exp $ */
/* $OpenBSD: lib_addch.c,v 1.6 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2006,2008 Free Software Foundation, Inc. *
* Copyright 2019-2021,2022 Thomas E. Dickey *
* Copyright 1998-2016,2017 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 +39,7 @@
#include <curses.priv.h>
#include <ctype.h>
MODULE_ID("$Id: lib_addch.c,v 1.5 2010/01/12 23:22:05 nicm Exp $")
MODULE_ID("$Id: lib_addch.c,v 1.6 2023/10/17 09:52:08 nicm Exp $")
static const NCURSES_CH_T blankchar = NewChar(BLANK_TEXT);
@ -53,7 +54,7 @@ static const NCURSES_CH_T blankchar = NewChar(BLANK_TEXT);
*/
/* Return bit mask for clearing color pair number if given ch has color */
#define COLOR_MASK(ch) (~(attr_t)((ch) & A_COLOR ? A_COLOR : 0))
#define COLOR_MASK(ch) (~(attr_t)(((ch) & A_COLOR) ? A_COLOR : 0))
static NCURSES_INLINE NCURSES_CH_T
render_char(WINDOW *win, NCURSES_CH_T ch)
@ -79,12 +80,6 @@ render_char(WINDOW *win, NCURSES_CH_T ch)
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);
}
@ -125,15 +120,19 @@ _nc_render(WINDOW *win, NCURSES_CH_T ch)
#endif
static bool
newline_forces_scroll(WINDOW *win, NCURSES_SIZE_T * ypos)
newline_forces_scroll(WINDOW *win, NCURSES_SIZE_T *ypos)
{
bool result = FALSE;
if (*ypos >= win->_regtop && *ypos == win->_regbottom) {
*ypos = win->_regbottom;
result = TRUE;
} else {
*ypos += 1;
if (*ypos >= win->_regtop && *ypos <= win->_regbottom) {
if (*ypos == win->_regbottom) {
*ypos = win->_regbottom;
result = TRUE;
} else if (*ypos < win->_maxy) {
*ypos = (NCURSES_SIZE_T) (*ypos + 1);
}
} else if (*ypos < win->_maxy) {
*ypos = (NCURSES_SIZE_T) (*ypos + 1);
}
return result;
}
@ -143,7 +142,7 @@ newline_forces_scroll(WINDOW *win, NCURSES_SIZE_T * ypos)
* 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).
* 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).
*/
@ -178,8 +177,8 @@ fill_cells(WINDOW *win, int count)
if (waddch_literal(win, blank) == ERR)
break;
}
win->_curx = save_x;
win->_cury = save_y;
win->_curx = (NCURSES_SIZE_T) save_x;
win->_cury = (NCURSES_SIZE_T) save_y;
}
#endif
@ -211,13 +210,28 @@ _nc_build_wch(WINDOW *win, ARG_CH_T ch)
WINDOW_EXT(win, addch_x) = x;
WINDOW_EXT(win, addch_y) = y;
/*
* If the background character is a wide-character, that may interfere with
* processing multibyte characters in this function.
*/
if (!is8bits(CharOf(CHDEREF(ch)))) {
if (WINDOW_EXT(win, addch_used) != 0) {
/* discard the incomplete multibyte character */
WINDOW_EXT(win, addch_used) = 0;
TR(TRACE_VIRTPUT,
("Alert discarded incomplete multibyte"));
}
return 1;
}
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) {
if ((len = (int) mbrtowc(&result,
buffer,
(size_t) 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);
@ -262,20 +276,37 @@ waddch_literal(WINDOW *win, NCURSES_CH_T ch)
/*
* Build up multibyte characters until we have a wide-character.
*/
#if NCURSES_SP_FUNCS
#define DeriveSP() SCREEN *sp = _nc_screen_of(win);
#else
#define DeriveSP() /*nothing */
#endif
if_WIDEC({
DeriveSP();
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);
attr_t attr = AttrOf(ch);
/* handle EILSEQ (i.e., when len >= -1) */
if (len == -1 && is8bits(CharOf(ch))) {
const char *s = NCURSES_SP_NAME(unctrl)
(NCURSES_SP_ARGx (chtype) CharOf(ch));
if (s[1] != '\0') {
int rc = OK;
while (*s != '\0') {
rc = waddch(win, UChar(*s) | attr);
if (rc != OK)
break;
++s;
}
return rc;
}
}
if (len == -1)
return waddch(win, ' ');
return waddch(win, ' ' | attr);
} else {
return OK;
}
@ -289,23 +320,32 @@ waddch_literal(WINDOW *win, NCURSES_CH_T ch)
* adjustments.
*/
if_WIDEC({
int len = wcwidth(CharOf(ch));
int len = _nc_wacs_width(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);
NCURSES_CH_T *dst;
wchar_t *chars;
if (x > 0 && y >= 0) {
for (j = x - 1; j >= 0; --j) {
if (!isWidecExt(win->_line[y].text[j])) {
win->_curx = (NCURSES_SIZE_T) j;
break;
}
}
dst = &(win->_line[y].text[j]);
} else {
dst = &(win->_line[y - 1].text[win->_maxx]);
}
chars = dst->chars;
for (i = 0; i < CCHARW_MAX; ++i) {
if (chars[i] == 0) {
TR(TRACE_VIRTPUT,
("added non-spacing %d: %x",
x, (int) CharOf(ch)));
("adding non-spacing %s (level %d)",
_tracech_t(CHREF(ch)), i));
chars[i] = CharOf(ch);
break;
}
@ -329,6 +369,8 @@ waddch_literal(WINDOW *win, NCURSES_CH_T ch)
return ERR;
x = win->_curx;
y = win->_cury;
CHECK_POSITION(win, x, y);
line = win->_line + y;
}
/*
* Check for cells which are orphaned by adding this character, set
@ -379,14 +421,14 @@ waddch_literal(WINDOW *win, NCURSES_CH_T ch)
testwrapping:
);
TR(TRACE_VIRTPUT, ("cell (%ld, %ld..%d) = %s",
(long) win->_cury, (long) win->_curx, x - 1,
_tracech_t(CHREF(ch))));
TR(TRACE_VIRTPUT, ("cell (%d, %d..%d) = %s",
win->_cury, win->_curx, x - 1,
_tracech_t(CHREF(line->text[win->_curx]))));
if (x > win->_maxx) {
return wrap_to_next_line(win);
}
win->_curx = x;
win->_curx = (NCURSES_SIZE_T) x;
return OK;
}
@ -395,30 +437,36 @@ waddch_nosync(WINDOW *win, const NCURSES_CH_T ch)
/* the workhorse function -- add a character to the given window */
{
NCURSES_SIZE_T x, y;
chtype t = CharOf(ch);
const char *s = unctrl(t);
chtype t = (chtype) CharOf(ch);
#if USE_WIDEC_SUPPORT || NCURSES_SP_FUNCS || USE_REENTRANT
SCREEN *sp = _nc_screen_of(win);
#endif
const char *s = NCURSES_SP_NAME(unctrl) (NCURSES_SP_ARGx t);
int tabsize = 8;
/*
* 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.
* claims the code is printable (and not also a control character),
* treat it that way.
*/
if ((AttrOf(ch) & A_ALTCHARSET)
|| (
#if USE_WIDEC_SUPPORT
(SP != 0 && SP->_legacy_coding) &&
(sp != 0 && sp->_legacy_coding) &&
#endif
s[1] == 0
)
|| (
isprint(t)
(isprint((int) t) && !iscntrl((int) t))
#if USE_WIDEC_SUPPORT
|| ((SP == 0 || !SP->_legacy_coding) &&
|| ((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
@ -426,11 +474,16 @@ waddch_nosync(WINDOW *win, const NCURSES_CH_T ch)
*/
x = win->_curx;
y = win->_cury;
CHECK_POSITION(win, x, y);
switch (t) {
case '\t':
x += (TABSIZE - (x % TABSIZE));
#if USE_REENTRANT
tabsize = *ptrTabsize(sp);
#else
tabsize = TABSIZE;
#endif
x = (NCURSES_SIZE_T) (x + (tabsize - (x % tabsize)));
/*
* Space-fill the tab on the bottom line so that we'll get the
* "correct" cursor position.
@ -480,7 +533,7 @@ waddch_nosync(WINDOW *win, const NCURSES_CH_T ch)
default:
while (*s) {
NCURSES_CH_T sch;
SetChar(sch, *s++, AttrOf(ch));
SetChar(sch, UChar(*s++), AttrOf(ch));
if_EXT_COLORS(SetPair(sch, GetPair(ch)));
if (waddch_literal(win, sch) == ERR)
return ERR;
@ -516,7 +569,7 @@ waddch(WINDOW *win, const chtype ch)
NCURSES_CH_T wch;
SetChar2(wch, ch);
TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("waddch(%p, %s)"), win,
TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("waddch(%p, %s)"), (void *) win,
_tracechtype(ch)));
if (win && (waddch_nosync(win, wch) != ERR)) {
@ -535,7 +588,8 @@ wechochar(WINDOW *win, const chtype ch)
NCURSES_CH_T wch;
SetChar2(wch, ch);
TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("wechochar(%p, %s)"), win,
TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("wechochar(%p, %s)"),
(void *) win,
_tracechtype(ch)));
if (win && (waddch_nosync(win, wch) != ERR)) {

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_addstr.c,v 1.5 2010/01/12 23:22:05 nicm Exp $ */
/* $OpenBSD: lib_addstr.c,v 1.6 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. *
* Copyright 2019-2020,2022 Thomas E. Dickey *
* Copyright 1998-2016,2017 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 *
@ -46,7 +47,7 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_addstr.c,v 1.5 2010/01/12 23:22:05 nicm Exp $")
MODULE_ID("$Id: lib_addstr.c,v 1.6 2023/10/17 09:52:08 nicm Exp $")
NCURSES_EXPORT(int)
waddnstr(WINDOW *win, const char *astr, int n)
@ -54,17 +55,18 @@ waddnstr(WINDOW *win, const char *astr, int n)
const char *str = astr;
int code = ERR;
T((T_CALLED("waddnstr(%p,%s,%d)"), win, _nc_visbufn(astr, n), n));
T((T_CALLED("waddnstr(%p,%s,%d)"), (void *) win, _nc_visbufn(astr, n), n));
if (win && (str != 0)) {
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 is not null, length = %d",
((n > 0) ? n : (int) strlen(str))));
if (n < 0)
n = INT_MAX;
while ((*str != '\0') && (n-- > 0)) {
NCURSES_CH_T ch;
TR(TRACE_VIRTPUT, ("*str = %#o", UChar(*str)));
SetChar(ch, UChar(*str++), A_NORMAL);
@ -87,9 +89,9 @@ waddchnstr(WINDOW *win, const chtype *astr, int n)
int i;
struct ldat *line;
T((T_CALLED("waddchnstr(%p,%p,%d)"), win, astr, n));
T((T_CALLED("waddchnstr(%p,%p,%d)"), (void *) win, (const void *) astr, n));
if (!win)
if (!win || !astr)
returnCode(ERR);
y = win->_cury;
@ -109,7 +111,7 @@ waddchnstr(WINDOW *win, const chtype *astr, int n)
for (i = 0; i < n && ChCharOf(astr[i]) != '\0'; ++i) {
SetChar2(line->text[i + x], astr[i]);
}
CHANGED_RANGE(line, x, x + n - 1);
CHANGED_RANGE(line, x, (NCURSES_SIZE_T) (x + n - 1));
_nc_synchook(win);
returnCode(code);
@ -121,8 +123,10 @@ NCURSES_EXPORT(int)
_nc_wchstrlen(const cchar_t *s)
{
int result = 0;
while (CharOf(s[result]) != L'\0') {
result++;
if (s != 0) {
while (CharOf(s[result]) != L'\0') {
result++;
}
}
return result;
}
@ -137,7 +141,10 @@ wadd_wchnstr(WINDOW *win, const cchar_t *astr, int n)
struct ldat *line;
int i, j, start, len, end;
T((T_CALLED("wadd_wchnstr(%p,%s,%d)"), win, _nc_viscbuf(astr, n), n));
T((T_CALLED("wadd_wchnstr(%p,%s,%d)"),
(void *) win,
_nc_viscbuf(astr, n),
n));
if (!win)
returnCode(ERR);
@ -180,7 +187,7 @@ wadd_wchnstr(WINDOW *win, const cchar_t *astr, int n)
if (isWidecExt(astr[i]))
continue;
len = wcwidth(CharOf(astr[i]));
len = _nc_wacs_width(CharOf(astr[i]));
if (x + len - 1 <= win->_maxx) {
line->text[x] = _nc_render(win, astr[i]);
@ -191,8 +198,10 @@ wadd_wchnstr(WINDOW *win, const cchar_t *astr, int n)
}
SetWidecExt(line->text[x + j], j);
}
} else {
len = 1;
}
x += len;
x = (NCURSES_SIZE_T) (x + len);
end += len - 1;
} else {
break;
@ -219,17 +228,18 @@ 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));
T((T_CALLED("waddnwstr(%p,%s,%d)"), (void *) 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'))) {
TR(TRACE_VIRTPUT, ("str is not null, length = %d",
((n > 0) ? n : (int) wcslen(str))));
if (n < 0)
n = INT_MAX;
while ((*str != L('\0')) && (n-- > 0)) {
NCURSES_CH_T ch;
TR(TRACE_VIRTPUT, ("*str[0] = %#lx", (unsigned long) *str));
SetChar(ch, *str++, A_NORMAL);

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_beep.c,v 1.4 2010/01/12 23:22:05 nicm Exp $ */
/* $OpenBSD: lib_beep.c,v 1.5 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2000,2005 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2013,2014 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,6 +33,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 *
* and: Juergen Pfeifer 2009 *
****************************************************************************/
/*
@ -42,9 +44,12 @@
*/
#include <curses.priv.h>
#include <term.h> /* beep, flash */
MODULE_ID("$Id: lib_beep.c,v 1.4 2010/01/12 23:22:05 nicm Exp $")
#ifndef CUR
#define CUR SP_TERMTYPE
#endif
MODULE_ID("$Id: lib_beep.c,v 1.5 2023/10/17 09:52:08 nicm Exp $")
/*
* beep()
@ -55,24 +60,34 @@ MODULE_ID("$Id: lib_beep.c,v 1.4 2010/01/12 23:22:05 nicm Exp $")
*/
NCURSES_EXPORT(int)
beep(void)
NCURSES_SP_NAME(beep) (NCURSES_SP_DCL0)
{
int res = ERR;
T((T_CALLED("beep()")));
T((T_CALLED("beep(%p)"), (void *) SP_PARM));
#ifdef USE_TERM_DRIVER
if (SP_PARM != 0)
res = CallDriver_1(SP_PARM, td_doBeepOrFlash, TRUE);
#else
/* FIXME: should make sure that we are not in altchar mode */
if (cur_term == 0) {
res = ERR;
} else if (bell) {
TPUTS_TRACE("bell");
res = putp(bell);
_nc_flush();
res = NCURSES_PUTP2_FLUSH("bell", bell);
} else if (flash_screen) {
TPUTS_TRACE("flash_screen");
res = putp(flash_screen);
res = NCURSES_PUTP2_FLUSH("flash_screen", flash_screen);
_nc_flush();
}
#endif
returnCode(res);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
beep(void)
{
return NCURSES_SP_NAME(beep) (CURRENT_SCREEN);
}
#endif

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_bkgd.c,v 1.3 2010/01/12 23:22:05 nicm Exp $ */
/* $OpenBSD: lib_bkgd.c,v 1.4 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2006,2008 Free Software Foundation, Inc. *
* Copyright 2018-2020,2021 Thomas E. Dickey *
* Copyright 1998-2014,2016 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 +39,9 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_bkgd.c,v 1.3 2010/01/12 23:22:05 nicm Exp $")
MODULE_ID("$Id: lib_bkgd.c,v 1.4 2023/10/17 09:52:08 nicm Exp $")
static const NCURSES_CH_T blank = NewChar(BLANK_TEXT);
/*
* Set the window's background information.
@ -50,7 +53,7 @@ static NCURSES_INLINE void
#endif
wbkgrndset(WINDOW *win, const ARG_CH_T ch)
{
T((T_CALLED("wbkgdset(%p,%s)"), win, _tracech_t(ch)));
T((T_CALLED("wbkgrndset(%p,%s)"), (void *) win, _tracech_t(ch)));
if (win) {
attr_t off = AttrOf(win->_nc_bkgd);
@ -63,7 +66,7 @@ wbkgrndset(WINDOW *win, const ARG_CH_T ch)
{
int pair;
if ((pair = GetPair(win->_nc_bkgd)) != 0)
if (GetPair(win->_nc_bkgd) != 0)
SET_WINDOW_PAIR(win, 0);
if ((pair = GetPair(CHDEREF(ch))) != 0)
SET_WINDOW_PAIR(win, pair);
@ -87,12 +90,13 @@ wbkgrndset(WINDOW *win, const ARG_CH_T ch)
cchar_t wch;
int tmp;
wgetbkgrnd(win, &wch);
memset(&wch, 0, sizeof(wch));
(void) 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)));
| (chtype) ColorPair(GET_WINDOW_PAIR(win)));
}
#endif
}
@ -103,42 +107,147 @@ NCURSES_EXPORT(void)
wbkgdset(WINDOW *win, chtype ch)
{
NCURSES_CH_T wch;
T((T_CALLED("wbkgdset(%p,%s)"), (void *) win, _tracechtype(ch)));
SetChar2(wch, ch);
wbkgrndset(win, CHREF(wch));
returnVoid;
}
/*
* Set the window's background information and apply it to each cell.
*/
#if USE_WIDEC_SUPPORT
NCURSES_EXPORT(int)
#else
static NCURSES_INLINE int
#undef wbkgrnd
#endif
wbkgrnd(WINDOW *win, const ARG_CH_T ch)
_nc_background(WINDOW *win, const ARG_CH_T ch, bool narrow)
{
#undef SP_PARM
#define SP_PARM SP /* to use Charable() */
int code = ERR;
int x, y;
NCURSES_CH_T new_bkgd = CHDEREF(ch);
T((T_CALLED("wbkgd(%p,%s)"), win, _tracech_t(ch)));
#if USE_WIDEC_SUPPORT
T((T_CALLED("%s(%p,%s)"),
narrow ? "wbkgd" : "wbkgrnd",
(void *) win,
_tracecchar_t(ch)));
#define TraceChar(c) _tracecchar_t2(1, &(c))
#else
T((T_CALLED("%s(%p,%s)"),
"wbkgd",
(void *) win,
_tracech_t(ch)));
(void) narrow;
#define TraceChar(c) _tracechar(CharOf(c))
#endif
if (win) {
NCURSES_CH_T old_bkgrnd;
wgetbkgrnd(win, &old_bkgrnd);
if (SP == 0) {
;
} else if (win) {
NCURSES_CH_T new_bkgd = CHDEREF(ch);
NCURSES_CH_T old_bkgd;
int y;
NCURSES_CH_T old_char;
attr_t old_attr;
int old_pair;
NCURSES_CH_T new_char;
attr_t new_attr;
int new_pair;
wbkgrndset(win, CHREF(new_bkgd));
wattrset(win, AttrOf(win->_nc_bkgd));
/* SVr4 trims color info if non-color terminal */
if (!SP->_pair_limit) {
RemAttr(new_bkgd, A_COLOR);
SetPair(new_bkgd, 0);
}
/* avoid setting background-character to a null */
if (CharOf(new_bkgd) == 0) {
NCURSES_CH_T tmp_bkgd = blank;
SetAttr(tmp_bkgd, AttrOf(new_bkgd));
SetPair(tmp_bkgd, GetPair(new_bkgd));
new_bkgd = tmp_bkgd;
}
memset(&old_bkgd, 0, sizeof(old_bkgd));
(void) wgetbkgrnd(win, &old_bkgd);
if (!memcmp(&old_bkgd, &new_bkgd, sizeof(new_bkgd))) {
T(("...unchanged"));
returnCode(OK);
}
old_char = old_bkgd;
RemAttr(old_char, ~A_CHARTEXT);
old_attr = AttrOf(old_bkgd);
old_pair = GetPair(old_bkgd);
if (!(old_attr & A_COLOR)) {
old_pair = 0;
}
T(("... old background char %s, attr %s, pair %d",
TraceChar(old_char), _traceattr(old_attr), old_pair));
new_char = new_bkgd;
RemAttr(new_char, ~A_CHARTEXT);
new_attr = AttrOf(new_bkgd);
new_pair = GetPair(new_bkgd);
/* SVr4 limits background character to printable 7-bits */
if (
#if USE_WIDEC_SUPPORT
narrow &&
#endif
!Charable(new_bkgd)) {
new_char = old_char;
}
if (!(new_attr & A_COLOR)) {
new_pair = 0;
}
T(("... new background char %s, attr %s, pair %d",
TraceChar(new_char), _traceattr(new_attr), new_pair));
(void) wbkgrndset(win, CHREF(new_bkgd));
/* SVr4 updates color pair if old/new match, otherwise just attrs */
if ((new_pair != 0) && (new_pair == old_pair)) {
WINDOW_ATTRS(win) = new_attr;
SET_WINDOW_PAIR(win, new_pair);
} else {
WINDOW_ATTRS(win) = new_attr;
}
for (y = 0; y <= win->_maxy; y++) {
int x;
for (x = 0; x <= win->_maxx; x++) {
if (CharEq(win->_line[y].text[x], old_bkgrnd)) {
win->_line[y].text[x] = win->_nc_bkgd;
NCURSES_CH_T *cp = &(win->_line[y].text[x]);
int tmp_pair = GetPair(*cp);
attr_t tmp_attr = AttrOf(*cp);
if (CharEq(*cp, old_bkgd)) {
#if USE_WIDEC_SUPPORT
if (!narrow) {
if (Charable(new_bkgd)) {
SetChar2(*cp, CharOf(new_char));
} else {
SetChar(*cp, L' ', AttrOf(new_char));
}
memcpy(cp->chars,
new_char.chars,
CCHARW_MAX * sizeof(cp->chars[0]));
} else
#endif
SetChar2(*cp, CharOf(new_char));
}
if (tmp_pair != 0) {
if (tmp_pair == old_pair) {
SetAttr(*cp, (tmp_attr & ~old_attr) | new_attr);
SetPair(*cp, new_pair);
} else {
SetAttr(*cp,
(tmp_attr & (~old_attr | A_COLOR))
| (new_attr & ALL_BUT_COLOR));
}
} 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);
SetAttr(*cp, (tmp_attr & ~old_attr) | new_attr);
SetPair(*cp, new_pair);
}
}
}
@ -149,10 +258,18 @@ wbkgrnd(WINDOW *win, const ARG_CH_T ch)
returnCode(code);
}
#if USE_WIDEC_SUPPORT
NCURSES_EXPORT(int)
wbkgrnd(WINDOW *win, const ARG_CH_T ch)
{
return _nc_background(win, ch, FALSE);
}
#endif
NCURSES_EXPORT(int)
wbkgd(WINDOW *win, chtype ch)
{
NCURSES_CH_T wch;
SetChar2(wch, ch);
return wbkgrnd(win, CHREF(wch));
return _nc_background(win, CHREF(wch), TRUE);
}

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_box.c,v 1.4 2010/01/12 23:22:05 nicm Exp $ */
/* $OpenBSD: lib_box.c,v 1.5 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2002,2005 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2010,2017 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,7 +45,7 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_box.c,v 1.4 2010/01/12 23:22:05 nicm Exp $")
MODULE_ID("$Id: lib_box.c,v 1.5 2023/10/17 09:52:08 nicm Exp $")
#if USE_WIDEC_SUPPORT
static NCURSES_INLINE chtype
@ -53,8 +54,9 @@ _my_render(WINDOW *win, chtype ch)
NCURSES_CH_T wch;
SetChar2(wch, ch);
wch = _nc_render(win, wch);
return CharOf(wch) | AttrOf(wch);
return ((attr_t) 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)
@ -72,7 +74,7 @@ wborder(WINDOW *win,
chtype wls, wrs, wts, wbs, wtl, wtr, wbl, wbr;
T((T_CALLED("wborder(%p,%s,%s,%s,%s,%s,%s,%s,%s)"),
win,
(void *) win,
_tracechtype2(1, ls),
_tracechtype2(2, rs),
_tracechtype2(3, ts),
@ -115,10 +117,20 @@ wborder(WINDOW *win,
win->_line[endy].lastchar = win->_line[0].lastchar = endx;
for (i = 0; i <= endy; i++) {
#if USE_WIDEC_SUPPORT
if (endx > 0 && isWidecExt(win->_line[i].text[endx])) {
SetChar2(win->_line[i].text[endx - 1], ' ');
}
#endif
SetChar2(win->_line[i].text[0], wls);
SetChar2(win->_line[i].text[endx], wrs);
win->_line[i].firstchar = 0;
win->_line[i].lastchar = endx;
#if USE_WIDEC_SUPPORT
if (isWidecExt(win->_line[i].text[1])) {
SetChar2(win->_line[i].text[1], ' ');
}
#endif
}
SetChar2(win->_line[0].text[0], wtl);
SetChar2(win->_line[0].text[endx], wtr);

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_chgat.c,v 1.3 2010/01/12 23:22:05 nicm Exp $ */
/* $OpenBSD: lib_chgat.c,v 1.4 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2016,2017 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,27 +45,38 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_chgat.c,v 1.3 2010/01/12 23:22:05 nicm Exp $")
MODULE_ID("$Id: lib_chgat.c,v 1.4 2023/10/17 09:52:08 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,
NCURSES_PAIRS_T pair_arg,
const void *opts GCC_UNUSED)
{
int i;
int code = ERR;
int color_pair = pair_arg;
T((T_CALLED("wchgat(%p,%d,%s,%d)"), win, n, _traceattr(attr), color));
T((T_CALLED("wchgat(%p,%d,%s,%d)"),
(void *) win,
n,
_traceattr(attr),
color_pair));
set_extended_pair(opts, color_pair);
if (win) {
struct ldat *line = &(win->_line[win->_cury]);
int i;
toggle_attr_on(attr, COLOR_PAIR(color));
toggle_attr_on(attr, ColorPair(color_pair));
for (i = win->_curx; i <= win->_maxx && (n == -1 || (n-- > 0)); i++) {
SetAttr(line->text[i], attr);
SetPair(line->text[i], color);
SetPair(line->text[i], color_pair);
CHANGED_CELL(line, i);
}
returnCode(OK);
} else
returnCode(ERR);
code = OK;
}
returnCode(code);
}

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_clear.c,v 1.3 2010/01/12 23:22:05 nicm Exp $ */
/* $OpenBSD: lib_clear.c,v 1.4 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998,2000 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2000,2009 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,14 +43,14 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_clear.c,v 1.3 2010/01/12 23:22:05 nicm Exp $")
MODULE_ID("$Id: lib_clear.c,v 1.4 2023/10/17 09:52:08 nicm Exp $")
NCURSES_EXPORT(int)
wclear(WINDOW *win)
{
int code = ERR;
T((T_CALLED("wclear(%p)"), win));
T((T_CALLED("wclear(%p)"), (void *) win));
if ((code = werase(win)) != ERR)
win->_clear = TRUE;

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_clearok.c,v 1.3 2010/01/12 23:22:05 nicm Exp $ */
/* $OpenBSD: lib_clearok.c,v 1.4 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998,2000 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2000,2009 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,12 +43,12 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_clearok.c,v 1.3 2010/01/12 23:22:05 nicm Exp $")
MODULE_ID("$Id: lib_clearok.c,v 1.4 2023/10/17 09:52:08 nicm Exp $")
NCURSES_EXPORT(int)
clearok(WINDOW *win, bool flag)
{
T((T_CALLED("clearok(%p,%d)"), win, flag));
T((T_CALLED("clearok(%p,%d)"), (void *) win, flag));
if (win) {
win->_clear = flag;

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_clrbot.c,v 1.4 2010/01/12 23:22:05 nicm Exp $ */
/* $OpenBSD: lib_clrbot.c,v 1.5 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2001,2006 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2006,2009 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,14 +43,14 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_clrbot.c,v 1.4 2010/01/12 23:22:05 nicm Exp $")
MODULE_ID("$Id: lib_clrbot.c,v 1.5 2023/10/17 09:52:08 nicm Exp $")
NCURSES_EXPORT(int)
wclrtobot(WINDOW *win)
{
int code = ERR;
T((T_CALLED("wclrtobot(%p)"), win));
T((T_CALLED("wclrtobot(%p)"), (void *) win));
if (win) {
NCURSES_SIZE_T y;

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_clreol.c,v 1.4 2010/01/12 23:22:05 nicm Exp $ */
/* $OpenBSD: lib_clreol.c,v 1.5 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc. *
* Copyright 2020,2021 Thomas E. Dickey *
* Copyright 1998-2001,2009 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,14 +43,14 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_clreol.c,v 1.4 2010/01/12 23:22:05 nicm Exp $")
MODULE_ID("$Id: lib_clreol.c,v 1.5 2023/10/17 09:52:08 nicm Exp $")
NCURSES_EXPORT(int)
wclrtoeol(WINDOW *win)
{
int code = ERR;
T((T_CALLED("wclrtoeol(%p)"), win));
T((T_CALLED("wclrtoeol(%p)"), (void *) win));
if (win) {
NCURSES_CH_T blank;
@ -62,7 +63,7 @@ wclrtoeol(WINDOW *win)
* If we have just wrapped the cursor, the clear applies to the
* new line, unless we are at the lower right corner.
*/
if ((win->_flags & _WRAPPED) != 0
if (IS_WRAPPED(win) != 0
&& y < win->_maxy) {
win->_flags &= ~_WRAPPED;
}
@ -71,7 +72,7 @@ wclrtoeol(WINDOW *win)
* There's no point in clearing if we're not on a legal
* position, either.
*/
if ((win->_flags & _WRAPPED) != 0
if (IS_WRAPPED(win)
|| y > win->_maxy
|| x > win->_maxx)
returnCode(ERR);

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_colorset.c,v 1.5 2010/01/12 23:22:05 nicm Exp $ */
/* $OpenBSD: lib_colorset.c,v 1.6 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2003,2005 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2014,2017 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,7 +31,7 @@
/****************************************************************************
* Author: Juergen Pfeifer, 1998 *
* and: Thomas E. Dickey, 2005 *
* and: Thomas E. Dickey, 2005-on *
****************************************************************************/
/*
@ -43,20 +44,24 @@
#include <curses.priv.h>
#include <ctype.h>
MODULE_ID("$Id: lib_colorset.c,v 1.5 2010/01/12 23:22:05 nicm Exp $")
MODULE_ID("$Id: lib_colorset.c,v 1.6 2023/10/17 09:52:08 nicm Exp $")
NCURSES_EXPORT(int)
wcolor_set(WINDOW *win, short color_pair_number, void *opts)
wcolor_set(WINDOW *win, NCURSES_PAIRS_T pair_arg, void *opts)
{
T((T_CALLED("wcolor_set(%p,%d)"), win, color_pair_number));
int code = ERR;
int color_pair = pair_arg;
T((T_CALLED("wcolor_set(%p,%d)"), (void *) win, color_pair));
set_extended_pair(opts, color_pair);
if (win
&& !opts
&& (color_pair_number >= 0)
&& (color_pair_number < COLOR_PAIRS)) {
&& (SP != 0)
&& (color_pair >= 0)
&& (color_pair < SP->_pair_limit)) {
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);
SET_WINDOW_PAIR(win, color_pair);
if_EXT_COLORS(win->_color = color_pair);
code = OK;
}
returnCode(code);
}

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_delch.c,v 1.3 2010/01/12 23:22:05 nicm Exp $ */
/* $OpenBSD: lib_delch.c,v 1.4 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2001,2009 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,14 +43,14 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_delch.c,v 1.3 2010/01/12 23:22:05 nicm Exp $")
MODULE_ID("$Id: lib_delch.c,v 1.4 2023/10/17 09:52:08 nicm Exp $")
NCURSES_EXPORT(int)
wdelch(WINDOW *win)
{
int code = ERR;
T((T_CALLED("wdelch(%p)"), win));
T((T_CALLED("wdelch(%p)"), (void *) win));
if (win) {
NCURSES_CH_T blank = win->_nc_bkgd;

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_delwin.c,v 1.3 2010/01/12 23:22:05 nicm Exp $ */
/* $OpenBSD: lib_delwin.c,v 1.4 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
* Copyright 2020,2021 Thomas E. Dickey *
* Copyright 1998-2008,2009 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 +32,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: Juergen Pfeifer 2008 *
****************************************************************************/
/*
@ -42,21 +45,29 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_delwin.c,v 1.3 2010/01/12 23:22:05 nicm Exp $")
MODULE_ID("$Id: lib_delwin.c,v 1.4 2023/10/17 09:52:08 nicm Exp $")
static bool
cannot_delete(WINDOW *win)
{
WINDOWLIST *p;
bool result = TRUE;
for (each_window(p)) {
if (&(p->win) == win) {
result = FALSE;
} else if ((p->win._flags & _SUBWIN) != 0
&& p->win._parent == win) {
result = TRUE;
break;
if (IS_PAD(win)) {
result = FALSE;
} else {
WINDOWLIST *p;
#ifdef USE_SP_WINDOWLIST
SCREEN *sp = _nc_screen_of(win);
#endif
for (each_window(SP_PARM, p)) {
if (&(p->win) == win) {
result = FALSE;
} else if (IS_SUBWIN(&(p->win))
&& p->win._parent == win) {
result = TRUE;
break;
}
}
}
return result;
@ -67,19 +78,24 @@ delwin(WINDOW *win)
{
int result = ERR;
T((T_CALLED("delwin(%p)"), win));
T((T_CALLED("delwin(%p)"), (void *) win));
if (_nc_try_global(curses) == 0) {
if (win == 0
|| cannot_delete(win)) {
result = ERR;
} else if (IS_PAD(win)) {
win->_parent = NULL;
result = _nc_freewin(win);
} else {
if (win->_flags & _SUBWIN)
#if NCURSES_SP_FUNCS
SCREEN *sp = _nc_screen_of(win);
#endif
if (IS_SUBWIN(win)) {
touchwin(win->_parent);
else if (curscr != 0)
touchwin(curscr);
} else if (CurScreen(SP_PARM) != 0) {
touchwin(CurScreen(SP_PARM));
}
result = _nc_freewin(win);
}
_nc_unlock_global(curses);

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_dft_fgbg.c,v 1.8 2010/01/12 23:22:05 nicm Exp $ */
/* $OpenBSD: lib_dft_fgbg.c,v 1.9 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2004,2005 Free Software Foundation, Inc. *
* Copyright 2020,2021 Thomas E. Dickey *
* Copyright 1998-2014,2017 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,49 +30,77 @@
****************************************************************************/
/****************************************************************************
* Author: Thomas E. Dickey *
* Author: Thomas E. Dickey 1998-on *
* Juergen Pfeifer 2009 *
****************************************************************************/
#include <curses.priv.h>
#include <term.h>
MODULE_ID("$Id: lib_dft_fgbg.c,v 1.8 2010/01/12 23:22:05 nicm Exp $")
#ifndef CUR
#define CUR SP_TERMTYPE
#endif
MODULE_ID("$Id: lib_dft_fgbg.c,v 1.9 2023/10/17 09:52:08 nicm Exp $")
/*
* Modify the behavior of color-pair 0 so that the library doesn't assume that
* it is white on black. This is an extension to XSI curses.
*/
NCURSES_EXPORT(int)
NCURSES_SP_NAME(use_default_colors) (NCURSES_SP_DCL0)
{
T((T_CALLED("use_default_colors(%p)"), (void *) SP_PARM));
returnCode(NCURSES_SP_NAME(assume_default_colors) (NCURSES_SP_ARGx -1, -1));
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
use_default_colors(void)
{
T((T_CALLED("use_default_colors()")));
returnCode(assume_default_colors(-1, -1));
return NCURSES_SP_NAME(use_default_colors) (CURRENT_SCREEN);
}
#endif
/*
* Modify the behavior of color-pair 0 so that the library assumes that it
* is something specific, possibly not white on black.
*/
NCURSES_EXPORT(int)
NCURSES_SP_NAME(assume_default_colors) (NCURSES_SP_DCLx int fg, int bg)
{
int code = ERR;
T((T_CALLED("assume_default_colors(%p,%d,%d)"), (void *) SP_PARM, fg, bg));
if (SP_PARM != 0) {
#ifdef USE_TERM_DRIVER
code = CallDriver_2(SP_PARM, td_defaultcolors, fg, bg);
#else
if ((orig_pair || orig_colors) && !initialize_pair) {
SP_PARM->_default_color = isDefaultColor(fg) || isDefaultColor(bg);
SP_PARM->_has_sgr_39_49 = (tigetflag("AX") == TRUE);
SP_PARM->_default_fg = isDefaultColor(fg) ? COLOR_DEFAULT : fg;
SP_PARM->_default_bg = isDefaultColor(bg) ? COLOR_DEFAULT : bg;
if (SP_PARM->_color_pairs != 0) {
bool save = SP_PARM->_default_color;
SP_PARM->_assumed_color = TRUE;
SP_PARM->_default_color = TRUE;
NCURSES_SP_NAME(init_pair) (NCURSES_SP_ARGx 0,
(short)fg,
(short)bg);
SP_PARM->_default_color = save;
}
code = OK;
}
#endif
}
returnCode(code);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
assume_default_colors(int fg, int bg)
{
T((T_CALLED("assume_default_colors(%d,%d)"), fg, bg));
if (!orig_pair && !orig_colors)
returnCode(ERR);
if (initialize_pair) /* don't know how to handle this */
returnCode(ERR);
SP->_default_color = isDefaultColor(fg) || isDefaultColor(bg);
SP->_has_sgr_39_49 = (tigetflag("AX") == TRUE);
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);
return NCURSES_SP_NAME(assume_default_colors) (CURRENT_SCREEN, fg, bg);
}
#endif

View file

@ -0,0 +1,148 @@
/****************************************************************************
* Copyright 2018,2020 Thomas E. Dickey *
* Copyright 2009-2012,2014 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 *
* *
****************************************************************************/
#include <curses.priv.h>
MODULE_ID("$Id: lib_driver.c,v 1.1 2023/10/17 09:52:08 nicm Exp $")
#ifndef EXP_WIN32_DRIVER
typedef struct DriverEntry {
const char *name;
TERM_DRIVER *driver;
} DRIVER_ENTRY;
static DRIVER_ENTRY DriverTable[] =
{
#ifdef _WIN32
{"win32console", &_nc_WIN_DRIVER},
#endif
{"tinfo", &_nc_TINFO_DRIVER} /* must be last */
};
NCURSES_EXPORT(int)
_nc_get_driver(TERMINAL_CONTROL_BLOCK * TCB, const char *name, int *errret)
{
int code = ERR;
size_t i;
TERM_DRIVER *res = (TERM_DRIVER *) 0;
TERM_DRIVER *use = 0;
T((T_CALLED("_nc_get_driver(%p, %s, %p)"),
(void *) TCB, NonNull(name), (void *) errret));
assert(TCB != 0);
for (i = 0; i < SIZEOF(DriverTable); i++) {
res = DriverTable[i].driver;
if (strcmp(DriverTable[i].name, res->td_name(TCB)) == 0) {
if (res->td_CanHandle(TCB, name, errret)) {
use = res;
break;
}
}
}
if (use != 0) {
TCB->drv = use;
code = OK;
}
returnCode(code);
}
#endif /* !EXP_WIN32_DRIVER */
NCURSES_EXPORT(int)
NCURSES_SP_NAME(has_key) (SCREEN *sp, int keycode)
{
T((T_CALLED("has_key(%p, %d)"), (void *) sp, keycode));
returnCode(IsValidTIScreen(sp) ? CallDriver_1(sp, td_kyExist, keycode) : FALSE);
}
NCURSES_EXPORT(int)
has_key(int keycode)
{
return NCURSES_SP_NAME(has_key) (CURRENT_SCREEN, keycode);
}
NCURSES_EXPORT(int)
NCURSES_SP_NAME(_nc_mcprint) (SCREEN *sp, char *data, int len)
{
int code = ERR;
if (0 != TerminalOf(sp))
code = CallDriver_2(sp, td_print, data, len);
return (code);
}
NCURSES_EXPORT(int)
mcprint(char *data, int len)
{
return NCURSES_SP_NAME(_nc_mcprint) (CURRENT_SCREEN, data, len);
}
NCURSES_EXPORT(int)
NCURSES_SP_NAME(doupdate) (SCREEN *sp)
{
int code = ERR;
T((T_CALLED("doupdate(%p)"), (void *) sp));
if (IsValidScreen(sp))
code = CallDriver(sp, td_update);
returnCode(code);
}
NCURSES_EXPORT(int)
doupdate(void)
{
return NCURSES_SP_NAME(doupdate) (CURRENT_SCREEN);
}
NCURSES_EXPORT(int)
NCURSES_SP_NAME(mvcur) (SCREEN *sp, int yold, int xold, int ynew, int xnew)
{
int code = ERR;
TR(TRACE_CALLS | TRACE_MOVE, (T_CALLED("mvcur(%p,%d,%d,%d,%d)"),
(void *) sp, yold, xold, ynew, xnew));
if (HasTerminal(sp)) {
code = CallDriver_4(sp, td_hwcur, yold, xold, ynew, xnew);
}
returnCode(code);
}
NCURSES_EXPORT(int)
mvcur(int yold, int xold, int ynew, int xnew)
/* optimized cursor move from (yold, xold) to (ynew, xnew) */
{
return NCURSES_SP_NAME(mvcur) (CURRENT_SCREEN, yold, xold, ynew, xnew);
}

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_echo.c,v 1.3 2010/01/12 23:22:05 nicm Exp $ */
/* $OpenBSD: lib_echo.c,v 1.4 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998,2000 Free Software Foundation, Inc. *
* Copyright 2020,2023 Thomas E. Dickey *
* Copyright 1998-2000,2009 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 +32,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: Juergen Pfeifer 2009 *
****************************************************************************/
/*
@ -44,20 +47,40 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_echo.c,v 1.3 2010/01/12 23:22:05 nicm Exp $")
MODULE_ID("$Id: lib_echo.c,v 1.4 2023/10/17 09:52:08 nicm Exp $")
NCURSES_EXPORT(int)
NCURSES_SP_NAME(echo) (NCURSES_SP_DCL0)
{
T((T_CALLED("echo(%p)"), (void *) SP_PARM));
if (0 == SP_PARM)
returnCode(ERR);
IsEcho(SP_PARM) = TRUE;
returnCode(OK);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
echo(void)
{
T((T_CALLED("echo()")));
SP->_echo = TRUE;
return NCURSES_SP_NAME(echo) (CURRENT_SCREEN);
}
#endif
NCURSES_EXPORT(int)
NCURSES_SP_NAME(noecho) (NCURSES_SP_DCL0)
{
T((T_CALLED("noecho(%p)"), (void *) SP_PARM));
if (0 == SP_PARM)
returnCode(ERR);
IsEcho(SP_PARM) = FALSE;
returnCode(OK);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
noecho(void)
{
T((T_CALLED("noecho()")));
SP->_echo = FALSE;
returnCode(OK);
return NCURSES_SP_NAME(noecho) (CURRENT_SCREEN);
}
#endif

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_endwin.c,v 1.4 2010/01/12 23:22:05 nicm Exp $ */
/* $OpenBSD: lib_endwin.c,v 1.5 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998,2000 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2014,2017 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 +32,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: Juergen Pfeifer 2009 *
****************************************************************************/
/*
@ -41,22 +44,39 @@
*/
#include <curses.priv.h>
#include <term.h>
MODULE_ID("$Id: lib_endwin.c,v 1.4 2010/01/12 23:22:05 nicm Exp $")
MODULE_ID("$Id: lib_endwin.c,v 1.5 2023/10/17 09:52:08 nicm Exp $")
NCURSES_EXPORT(int)
NCURSES_SP_NAME(endwin) (NCURSES_SP_DCL0)
{
int code = ERR;
T((T_CALLED("endwin(%p)"), (void *) SP_PARM));
if (SP_PARM) {
#ifdef USE_TERM_DRIVER
TERMINAL_CONTROL_BLOCK *TCB = TCBOf(SP_PARM);
SP_PARM->_endwin = ewSuspend;
if (TCB && TCB->drv && TCB->drv->td_scexit)
TCB->drv->td_scexit(SP_PARM);
#else
SP_PARM->_endwin = ewSuspend;
SP_PARM->_mouse_wrap(SP_PARM);
_nc_screen_wrap();
_nc_mvcur_wrap(); /* wrap up cursor addressing */
#endif
code = NCURSES_SP_NAME(reset_shell_mode) (NCURSES_SP_ARG);
}
returnCode(code);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
endwin(void)
{
T((T_CALLED("endwin()")));
if (SP) {
SP->_endwin = TRUE;
SP->_mouse_wrap(SP);
_nc_screen_wrap();
_nc_mvcur_wrap(); /* wrap up cursor addressing */
returnCode(reset_shell_mode());
}
returnCode(ERR);
return NCURSES_SP_NAME(endwin) (CURRENT_SCREEN);
}
#endif

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_erase.c,v 1.3 2010/01/12 23:22:05 nicm Exp $ */
/* $OpenBSD: lib_erase.c,v 1.4 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. *
* Copyright 2020,2022 Thomas E. Dickey *
* Copyright 1998-2009,2016 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,21 +44,25 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_erase.c,v 1.3 2010/01/12 23:22:05 nicm Exp $")
MODULE_ID("$Id: lib_erase.c,v 1.4 2023/10/17 09:52:08 nicm Exp $")
NCURSES_EXPORT(int)
werase(WINDOW *win)
{
int code = ERR;
int y;
NCURSES_CH_T blank;
NCURSES_CH_T *sp, *end, *start;
NCURSES_CH_T *start;
T((T_CALLED("werase(%p)"), win));
T((T_CALLED("werase(%p)"), (void *) win));
if (win) {
NCURSES_CH_T blank;
NCURSES_CH_T *sp;
int y;
blank = win->_nc_bkgd;
for (y = 0; y <= win->_maxy; y++) {
NCURSES_CH_T *end;
start = win->_line[y].text;
end = &start[win->_maxx];

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_flash.c,v 1.4 2010/01/12 23:22:05 nicm Exp $ */
/* $OpenBSD: lib_flash.c,v 1.5 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998,2000 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2013,2014 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 +32,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: Juergen Pfeifer 2009 *
****************************************************************************/
/*
@ -41,9 +44,12 @@
*/
#include <curses.priv.h>
#include <term.h> /* beep, flash */
MODULE_ID("$Id: lib_flash.c,v 1.4 2010/01/12 23:22:05 nicm Exp $")
#ifndef CUR
#define CUR SP_TERMTYPE
#endif
MODULE_ID("$Id: lib_flash.c,v 1.5 2023/10/17 09:52:08 nicm Exp $")
/*
* flash()
@ -54,22 +60,31 @@ MODULE_ID("$Id: lib_flash.c,v 1.4 2010/01/12 23:22:05 nicm Exp $")
*/
NCURSES_EXPORT(int)
flash(void)
NCURSES_SP_NAME(flash) (NCURSES_SP_DCL0)
{
int res = ERR;
T((T_CALLED("flash()")));
/* FIXME: should make sure that we are not in altchar mode */
if (flash_screen) {
TPUTS_TRACE("flash_screen");
res = putp(flash_screen);
_nc_flush();
} else if (bell) {
TPUTS_TRACE("bell");
res = putp(bell);
_nc_flush();
T((T_CALLED("flash(%p)"), (void *) SP_PARM));
#ifdef USE_TERM_DRIVER
if (SP_PARM != 0)
res = CallDriver_1(SP_PARM, td_doBeepOrFlash, FALSE);
#else
if (HasTerminal(SP_PARM)) {
/* FIXME: should make sure that we are not in altchar mode */
if (flash_screen) {
res = NCURSES_PUTP2_FLUSH("flash_screen", flash_screen);
} else if (bell) {
res = NCURSES_PUTP2_FLUSH("bell", bell);
}
}
#endif
returnCode(res);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
flash(void)
{
return NCURSES_SP_NAME(flash) (CURRENT_SCREEN);
}
#endif

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_freeall.c,v 1.5 2010/01/12 23:22:05 nicm Exp $ */
/* $OpenBSD: lib_freeall.c,v 1.6 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
* Copyright 2018-2020,2021 Thomas E. Dickey *
* Copyright 1998-2016,2017 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 *
@ -33,7 +34,6 @@
****************************************************************************/
#include <curses.priv.h>
#include <term_entry.h>
#include <tic.h>
#if HAVE_NC_FREEALL
@ -42,50 +42,70 @@
extern int malloc_errfd; /* FIXME */
#endif
MODULE_ID("$Id: lib_freeall.c,v 1.5 2010/01/12 23:22:05 nicm Exp $")
MODULE_ID("$Id: lib_freeall.c,v 1.6 2023/10/17 09:52:08 nicm Exp $")
/*
* Free all ncurses data. This is used for testing only (there's no practical
* use for it as an extension).
*/
NCURSES_EXPORT(void)
_nc_freeall(void)
NCURSES_SP_NAME(_nc_freeall) (NCURSES_SP_DCL0)
{
WINDOWLIST *p, *q;
static va_list empty_va;
T((T_CALLED("_nc_freeall()")));
#if NO_LEAKS
if (SP != 0) {
if (SP->_oldnum_list != 0) {
FreeAndNull(SP->_oldnum_list);
_nc_globals.leak_checking = TRUE;
if (SP_PARM != 0) {
if (SP_PARM->_oldnum_list != 0) {
FreeAndNull(SP_PARM->_oldnum_list);
}
if (SP->_panelHook.destroy != 0) {
SP->_panelHook.destroy(SP->_panelHook.stdscr_pseudo_panel);
if (SP_PARM->_panelHook.destroy != 0) {
SP_PARM->_panelHook.destroy(SP_PARM->_panelHook.stdscr_pseudo_panel);
}
#if NCURSES_EXT_COLORS
_nc_new_pair_leaks(SP_PARM);
#endif
}
#endif
if (SP != 0) {
if (SP_PARM != 0) {
_nc_lock_global(curses);
while (_nc_windows != 0) {
while (WindowList(SP_PARM) != 0) {
WINDOWLIST *p, *q;
bool deleted = FALSE;
/* Delete only windows that're not a parent */
for (each_window(p)) {
for (each_window(SP_PARM, p)) {
WINDOW *p_win = &(p->win);
bool found = FALSE;
for (each_window(q)) {
if (IS_PAD(p_win))
continue;
#ifndef USE_SP_WINDOWLIST
if (p->screen != SP_PARM)
continue;
#endif
for (each_window(SP_PARM, q)) {
WINDOW *q_win = &(q->win);
#ifndef USE_SP_WINDOWLIST
if (q->screen != SP_PARM)
continue;
#endif
if ((p != q)
&& (q->win._flags & _SUBWIN)
&& (&(p->win) == q->win._parent)) {
&& IS_SUBWIN(q_win)
&& (p_win == q_win->_parent)) {
found = TRUE;
break;
}
}
if (!found) {
if (delwin(&(p->win)) != ERR)
if (delwin(p_win) != ERR)
deleted = TRUE;
break;
}
@ -97,15 +117,13 @@ _nc_freeall(void)
if (!deleted)
break;
}
delscreen(SP);
delscreen(SP_PARM);
_nc_unlock_global(curses);
}
if (cur_term != 0)
del_curterm(cur_term);
(void) _nc_printf_string(0, empty_va);
#ifdef TRACE
(void) _nc_trace_buf(-1, 0);
(void) _nc_trace_buf(-1, (size_t) 0);
#endif
#if USE_WIDEC_SUPPORT
FreeIfNeeded(_nc_wacs);
@ -123,37 +141,63 @@ _nc_freeall(void)
returnVoid;
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(void)
_nc_free_and_exit(int code)
_nc_freeall(void)
{
char *last_setbuf = (SP != 0) ? SP->_setbuf : 0;
NCURSES_SP_NAME(_nc_freeall) (CURRENT_SCREEN);
}
#endif
_nc_freeall();
NCURSES_EXPORT(void)
NCURSES_SP_NAME(_nc_free_and_exit) (NCURSES_SP_DCLx int code)
{
T((T_CALLED("_nc_free_and_exit(%d)"), code));
NCURSES_SP_NAME(_nc_flush) (NCURSES_SP_ARG);
NCURSES_SP_NAME(_nc_freeall) (NCURSES_SP_ARG);
#ifdef TRACE
trace(0); /* close trace file, freeing its setbuf */
curses_trace(0); /* close trace file, freeing its setbuf */
{
static va_list fake;
free(_nc_varargs("?", fake));
}
#endif
fclose(stdout);
FreeIfNeeded(last_setbuf);
exit(code);
}
#else
#else /* !HAVE_NC_FREEALL */
NCURSES_EXPORT(void)
_nc_freeall(void)
{
}
NCURSES_EXPORT(void)
_nc_free_and_exit(int code)
NCURSES_SP_NAME(_nc_free_and_exit) (NCURSES_SP_DCLx int code)
{
if (SP)
delscreen(SP);
if (cur_term != 0)
del_curterm(cur_term);
if (SP_PARM) {
delscreen(SP_PARM);
}
exit(code);
}
#endif /* HAVE_NC_FREEALL */
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(void)
_nc_free_and_exit(int code)
{
NCURSES_SP_NAME(_nc_free_and_exit) (CURRENT_SCREEN, code);
}
#endif
NCURSES_EXPORT(void)
exit_curses(int code)
{
#if NO_LEAKS
#if NCURSES_SP_FUNCS
NCURSES_SP_NAME(_nc_free_and_exit) (CURRENT_SCREEN, code);
#else
_nc_free_and_exit(code); /* deprecated... */
#endif
#endif
exit(code);
}

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_getch.c,v 1.11 2010/01/12 23:22:05 nicm Exp $ */
/* $OpenBSD: lib_getch.c,v 1.12 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
* Copyright 2018-2022,2023 Thomas E. Dickey *
* Copyright 1998-2015,2016 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,6 +33,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 *
* and: Juergen Pfeifer 2009 *
****************************************************************************/
/*
@ -41,42 +43,91 @@
**
*/
#define NEED_KEY_EVENT
#include <curses.priv.h>
MODULE_ID("$Id: lib_getch.c,v 1.11 2010/01/12 23:22:05 nicm Exp $")
MODULE_ID("$Id: lib_getch.c,v 1.12 2023/10/17 09:52:08 nicm Exp $")
#include <fifo_defs.h>
#if USE_REENTRANT
#define GetEscdelay(sp) (sp)->_ESCDELAY
#define GetEscdelay(sp) *_nc_ptr_Escdelay(sp)
NCURSES_EXPORT(int)
NCURSES_PUBLIC_VAR(ESCDELAY) (void)
{
return SP ? GetEscdelay(SP) : 1000;
return *(_nc_ptr_Escdelay(CURRENT_SCREEN));
}
NCURSES_EXPORT(int *)
_nc_ptr_Escdelay(SCREEN *sp)
{
return ptrEscdelay(sp);
}
#else
#define GetEscdelay(sp) ESCDELAY
NCURSES_EXPORT_VAR(int)
ESCDELAY = 1000; /* max interval betw. chars in funkeys, in millisecs */
NCURSES_EXPORT_VAR(int) ESCDELAY = 1000;
#endif
#if NCURSES_EXT_FUNCS
NCURSES_EXPORT(int)
set_escdelay(int value)
NCURSES_SP_NAME(set_escdelay) (NCURSES_SP_DCLx int value)
{
int code = OK;
#if USE_REENTRANT
if (SP) {
SP->_ESCDELAY = value;
} else {
if (value < 0) {
code = ERR;
}
} else {
#if USE_REENTRANT
if (SP_PARM) {
SET_ESCDELAY(value);
} else {
code = ERR;
}
#else
ESCDELAY = value;
(void) SP_PARM;
ESCDELAY = value;
#endif
}
return code;
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
set_escdelay(int value)
{
int code;
if (value < 0) {
code = ERR;
} else {
#if USE_REENTRANT
code = NCURSES_SP_NAME(set_escdelay) (CURRENT_SCREEN, value);
#else
ESCDELAY = value;
code = OK;
#endif
}
return code;
}
#endif
#endif /* NCURSES_EXT_FUNCS */
#if NCURSES_EXT_FUNCS
NCURSES_EXPORT(int)
NCURSES_SP_NAME(get_escdelay) (NCURSES_SP_DCL0)
{
#if !USE_REENTRANT
(void) SP_PARM;
#endif
return GetEscdelay(SP_PARM);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
get_escdelay(void)
{
return NCURSES_SP_NAME(get_escdelay) (CURRENT_SCREEN);
}
#endif
#endif /* NCURSES_EXT_FUNCS */
static int
_nc_use_meta(WINDOW *win)
@ -85,10 +136,15 @@ _nc_use_meta(WINDOW *win)
return (sp ? sp->_use_meta : 0);
}
#ifdef NCURSES_WGETCH_EVENTS
#define TWAIT_MASK 7
#else
#define TWAIT_MASK 3
#ifdef USE_TERM_DRIVER
# if defined(_NC_WINDOWS) && !defined(EXP_WIN32_DRIVER)
static HANDLE
_nc_get_handle(int fd)
{
intptr_t value = _get_osfhandle(fd);
return (HANDLE) value;
}
# endif
#endif
/*
@ -99,28 +155,61 @@ check_mouse_activity(SCREEN *sp, int delay EVENTLIST_2nd(_nc_eventlist * evl))
{
int rc;
#if USE_SYSMOUSE
#ifdef USE_TERM_DRIVER
TERMINAL_CONTROL_BLOCK *TCB = TCBOf(sp);
rc = TCBOf(sp)->drv->td_testmouse(TCBOf(sp), delay EVENTLIST_2nd(evl));
# if defined(EXP_WIN32_DRIVER)
/* if we emulate terminfo on console, we have to use the console routine */
if (IsTermInfoOnConsole(sp)) {
rc = _nc_console_testmouse(sp,
_nc_console_handle(sp->_ifd),
delay EVENTLIST_2nd(evl));
} else
# elif defined(_NC_WINDOWS)
/* if we emulate terminfo on console, we have to use the console routine */
if (IsTermInfoOnConsole(sp)) {
HANDLE fd = _nc_get_handle(sp->_ifd);
rc = _nc_mingw_testmouse(sp, fd, delay EVENTLIST_2nd(evl));
} else
# endif
rc = TCB->drv->td_testmouse(TCB, delay EVENTLIST_2nd(evl));
#else /* !USE_TERM_DRIVER */
# if USE_SYSMOUSE
if ((sp->_mouse_type == M_SYSMOUSE)
&& (sp->_sysmouse_head < sp->_sysmouse_tail)) {
return 2;
rc = TW_MOUSE;
} else
# endif
{
# if defined(EXP_WIN32_DRIVER)
rc = _nc_console_testmouse(sp,
_nc_console_handle(sp->_ifd),
delay
EVENTLIST_2nd(evl));
# else
rc = _nc_timed_wait(sp,
TWAIT_MASK,
delay,
(int *) 0
EVENTLIST_2nd(evl));
# endif
# if USE_SYSMOUSE
if ((sp->_mouse_type == M_SYSMOUSE)
&& (sp->_sysmouse_head < sp->_sysmouse_tail)
&& (rc == 0)
&& (errno == EINTR)) {
rc |= TW_MOUSE;
}
# endif
}
#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
#endif /* USE_TERM_DRIVER */
return rc;
}
static NCURSES_INLINE int
fifo_peek(SCREEN *sp)
{
int ch = sp->_fifo[peek];
int ch = (peek >= 0) ? sp->_fifo[peek] : ERR;
TR(TRACE_IEVENT, ("peeking at %d", peek));
p_inc();
@ -130,15 +219,16 @@ fifo_peek(SCREEN *sp)
static NCURSES_INLINE int
fifo_pull(SCREEN *sp)
{
int ch;
ch = sp->_fifo[head];
int ch = (head >= 0) ? sp->_fifo[head] : ERR;
TR(TRACE_IEVENT, ("pulling %s from %d", _nc_tracechar(sp, ch), head));
if (peek == head) {
h_inc();
peek = head;
} else
} else {
h_inc();
}
#ifdef TRACE
if (USE_TRACEF(TRACE_IEVENT)) {
@ -157,14 +247,9 @@ fifo_push(SCREEN *sp EVENTLIST_2nd(_nc_eventlist * evl))
int mask = 0;
(void) mask;
if (tail == -1)
if (tail < 0)
return ERR;
#ifdef HIDE_EINTR
again:
errno = 0;
#endif
#ifdef NCURSES_WGETCH_EVENTS
if (evl
#if USE_GPM_SUPPORT || USE_EMX_MOUSE || USE_SYSMOUSE
@ -175,9 +260,9 @@ fifo_push(SCREEN *sp EVENTLIST_2nd(_nc_eventlist * evl))
} else
mask = 0;
if (mask & 4) {
if (mask & TW_EVENT) {
T(("fifo_push: ungetch KEY_EVENT"));
_nc_ungetch(sp, KEY_EVENT);
safe_ungetch(sp, KEY_EVENT);
return KEY_EVENT;
}
#elif USE_GPM_SUPPORT || USE_EMX_MOUSE || USE_SYSMOUSE
@ -187,7 +272,7 @@ fifo_push(SCREEN *sp EVENTLIST_2nd(_nc_eventlist * evl))
#endif
#if USE_GPM_SUPPORT || USE_EMX_MOUSE
if ((sp->_mouse_fd >= 0) && (mask & 2)) {
if ((sp->_mouse_fd >= 0) && (mask & TW_MOUSE)) {
sp->_mouse_event(sp);
ch = KEY_MOUSE;
n = 1;
@ -206,25 +291,60 @@ fifo_push(SCREEN *sp EVENTLIST_2nd(_nc_eventlist * evl))
n = 1;
} else
#endif
{ /* Can block... */
unsigned char c2 = 0;
n = read(sp->_ifd, &c2, 1);
ch = c2;
}
#ifdef HIDE_EINTR
/*
* Under System V curses with non-restarting signals, getch() returns
* with value ERR when a handled signal keeps it from completing.
* If signals restart system calls, OTOH, the signal is invisible
* except to its handler.
*
* We don't want this difference to show. This piece of code
* tries to make it look like we always have restarting signals.
*/
if (n <= 0 && errno == EINTR)
goto again;
#ifdef USE_TERM_DRIVER
if ((sp->_mouse_type == M_TERM_DRIVER)
&& (sp->_drv_mouse_head < sp->_drv_mouse_tail)) {
sp->_mouse_event(sp);
ch = KEY_MOUSE;
n = 1;
} else
#endif
#if USE_KLIBC_KBD
if (NC_ISATTY(sp->_ifd) && IsCbreak(sp)) {
ch = _read_kbd(0, 1, !IsRaw(sp));
n = (ch == -1) ? -1 : 1;
sp->_extended_key = (ch == 0);
} else
#endif
{ /* Can block... */
#if defined(USE_TERM_DRIVER)
int buf;
# if defined(EXP_WIN32_DRIVER)
if (NC_ISATTY(sp->_ifd) && IsTermInfoOnConsole(sp) && IsCbreak(sp)) {
_nc_set_read_thread(TRUE);
n = _nc_console_read(sp,
_nc_console_handle(sp->_ifd),
&buf);
_nc_set_read_thread(FALSE);
} else
# elif defined(_NC_WINDOWS)
if (NC_ISATTY(sp->_ifd) && IsTermInfoOnConsole(sp) && IsCbreak(sp))
n = _nc_mingw_console_read(sp,
_nc_get_handle(sp->_ifd),
&buf);
else
# endif /* EXP_WIN32_DRIVER */
n = CallDriver_1(sp, td_read, &buf);
ch = buf;
#else /* !USE_TERM_DRIVER */
#if defined(EXP_WIN32_DRIVER)
int buf;
#endif
unsigned char c2 = 0;
_nc_set_read_thread(TRUE);
#if defined(EXP_WIN32_DRIVER)
n = _nc_console_read(sp,
_nc_console_handle(sp->_ifd),
&buf);
c2 = buf;
#else
n = (int) read(sp->_ifd, &c2, (size_t) 1);
#endif
_nc_set_read_thread(FALSE);
ch = c2;
#endif /* USE_TERM_DRIVER */
}
if ((n == -1) || (n == 0)) {
TR(TRACE_IEVENT, ("read(%d,&ch,1)=%d, errno=%d", sp->_ifd, n, errno));
@ -255,19 +375,29 @@ fifo_clear(SCREEN *sp)
tail = peek = 0;
}
static int kgetch(SCREEN *EVENTLIST_2nd(_nc_eventlist * evl));
static int kgetch(SCREEN *, bool EVENTLIST_2nd(_nc_eventlist *));
static void
recur_wrefresh(WINDOW *win)
{
#ifdef USE_PTHREADS
SCREEN *sp = _nc_screen_of(win);
if (_nc_use_pthreads && sp != SP) {
bool same_sp;
if (_nc_use_pthreads) {
_nc_lock_global(curses);
same_sp = (sp == CURRENT_SCREEN);
_nc_unlock_global(curses);
} else {
same_sp = (sp == CURRENT_SCREEN);
}
if (_nc_use_pthreads && !same_sp) {
SCREEN *save_SP;
/* temporarily switch to the window's screen to check/refresh */
_nc_lock_global(curses);
save_SP = SP;
save_SP = CURRENT_SCREEN;
_nc_set_screen(sp);
recur_wrefresh(win);
_nc_set_screen(save_SP);
@ -275,7 +405,7 @@ recur_wrefresh(WINDOW *win)
} else
#endif
if ((is_wintouched(win) || (win->_flags & _HASMOVED))
&& !(win->_flags & _ISPAD)) {
&& !IS_PAD(win)) {
wrefresh(win);
}
}
@ -288,12 +418,12 @@ recur_wgetnstr(WINDOW *win, char *buf)
if (sp != 0) {
#ifdef USE_PTHREADS
if (_nc_use_pthreads && sp != SP) {
if (_nc_use_pthreads && sp != CURRENT_SCREEN) {
SCREEN *save_SP;
/* temporarily switch to the window's screen to get cooked input */
_nc_lock_global(curses);
save_SP = SP;
save_SP = CURRENT_SCREEN;
_nc_set_screen(sp);
rc = recur_wgetnstr(win, buf);
_nc_set_screen(save_SP);
@ -313,17 +443,18 @@ recur_wgetnstr(WINDOW *win, char *buf)
NCURSES_EXPORT(int)
_nc_wgetch(WINDOW *win,
unsigned long *result,
int *result,
int use_meta
EVENTLIST_2nd(_nc_eventlist * evl))
{
SCREEN *sp;
int ch;
int rc = 0;
#ifdef NCURSES_WGETCH_EVENTS
long event_delay = -1;
int event_delay = -1;
#endif
T((T_CALLED("_nc_wgetch(%p)"), win));
T((T_CALLED("_nc_wgetch(%p)"), (void *) win));
*result = 0;
@ -350,23 +481,24 @@ _nc_wgetch(WINDOW *win,
*/
if (head == -1 &&
!sp->_notty &&
!sp->_raw &&
!sp->_cbreak &&
!IsRaw(sp) &&
!IsCbreak(sp) &&
!sp->_called_wgetch) {
char buf[MAXCOLUMNS], *bufp;
int rc;
TR(TRACE_IEVENT, ("filling queue in cooked mode"));
rc = recur_wgetnstr(win, buf);
/* ungetch in reverse order */
#ifdef NCURSES_WGETCH_EVENTS
if (rc != KEY_EVENT)
rc = recur_wgetnstr(win, buf);
if (rc != KEY_EVENT && rc != ERR)
safe_ungetch(sp, '\n');
#else
if (recur_wgetnstr(win, buf) != ERR)
safe_ungetch(sp, '\n');
#endif
_nc_ungetch(sp, '\n');
for (bufp = buf + strlen(buf); bufp > buf; bufp--)
_nc_ungetch(sp, bufp[-1]);
safe_ungetch(sp, bufp[-1]);
#ifdef NCURSES_WGETCH_EVENTS
/* Return it first */
@ -383,14 +515,13 @@ _nc_wgetch(WINDOW *win,
recur_wrefresh(win);
if (win->_notimeout || (win->_delay >= 0) || (sp->_cbreak > 1)) {
if (win->_notimeout || (win->_delay >= 0) || (IsCbreak(sp) > 1)) {
if (head == -1) { /* fifo is empty */
int delay;
int rc;
TR(TRACE_IEVENT, ("timed delay in wgetch()"));
if (sp->_cbreak > 1)
delay = (sp->_cbreak - 1) * 100;
if (IsCbreak(sp) > 1)
delay = (IsCbreak(sp) - 1) * 100;
else
delay = win->_delay;
@ -404,13 +535,13 @@ _nc_wgetch(WINDOW *win,
rc = check_mouse_activity(sp, delay EVENTLIST_2nd(evl));
#ifdef NCURSES_WGETCH_EVENTS
if (rc & 4) {
if (rc & TW_EVENT) {
*result = KEY_EVENT;
returnCode(KEY_CODE_YES);
}
#endif
if (!rc) {
returnCode(ERR);
goto check_sigwinch;
}
}
/* else go on to read data available */
@ -421,7 +552,7 @@ _nc_wgetch(WINDOW *win,
* This is tricky. We only want to get special-key
* events one at a time. But we want to accumulate
* mouse events until either (a) the mouse logic tells
* us it's picked up a complete gesture, or (b)
* us it has picked up a complete gesture, or (b)
* there's a detectable time lapse after one.
*
* Note: if the mouse code starts failing to compose
@ -429,10 +560,9 @@ _nc_wgetch(WINDOW *win,
* increase the wait with mouseinterval().
*/
int runcount = 0;
int rc;
do {
ch = kgetch(sp EVENTLIST_2nd(evl));
ch = kgetch(sp, win->_notimeout EVENTLIST_2nd(evl));
if (ch == KEY_MOUSE) {
++runcount;
if (sp->_mouse_inline(sp))
@ -444,11 +574,11 @@ _nc_wgetch(WINDOW *win,
(ch == KEY_MOUSE
&& (((rc = check_mouse_activity(sp, sp->_maxclick
EVENTLIST_2nd(evl))) != 0
&& !(rc & 4))
&& !(rc & TW_EVENT))
|| !sp->_mouse_parse(sp, runcount)));
#ifdef NCURSES_WGETCH_EVENTS
if ((rc & 4) && !ch == KEY_EVENT) {
_nc_ungetch(sp, ch);
if ((rc & TW_EVENT) && !(ch == KEY_EVENT)) {
safe_ungetch(sp, ch);
ch = KEY_EVENT;
}
#endif
@ -456,12 +586,12 @@ _nc_wgetch(WINDOW *win,
#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... */
safe_ungetch(sp, KEY_MOUSE); /* FIXME This interrupts a gesture... */
} else
#endif
{
/* mouse event sequence ended by keystroke, store keystroke */
_nc_ungetch(sp, ch);
safe_ungetch(sp, ch);
ch = KEY_MOUSE;
}
}
@ -472,12 +602,19 @@ _nc_wgetch(WINDOW *win,
}
if (ch == ERR) {
check_sigwinch:
#if USE_SIZECHANGE
if (_nc_handle_sigwinch(sp)) {
_nc_update_screensize(sp);
/* resizeterm can push KEY_RESIZE */
if (cooked_key_in_fifo()) {
*result = fifo_pull(sp);
/*
* Get the ERR from queue -- it is from WINCH,
* so we should take it out, the "error" is handled.
*/
if (fifo_peek(sp) == -1)
fifo_pull(sp);
returnCode(*result >= KEY_MIN ? KEY_CODE_YES : OK);
}
}
@ -492,7 +629,7 @@ _nc_wgetch(WINDOW *win,
*
* If carriage return is defined as a function key in the
* terminfo, e.g., kent, then Solaris may return either ^J (or ^M
* if nonl() is set) or KEY_ENTER depending on the echo() mode.
* if nonl() is set) or KEY_ENTER depending on the echo() mode.
* We echo before translating carriage return based on nonl(),
* since the visual result simply moves the cursor to column 0.
*
@ -503,8 +640,8 @@ _nc_wgetch(WINDOW *win,
* However, we provide the same visual result as Solaris, moving the
* cursor to the left.
*/
if (sp->_echo && !(win->_flags & _ISPAD)) {
chtype backup = (ch == KEY_BACKSPACE) ? '\b' : ch;
if (IsEcho(sp) && !IS_PAD(win)) {
chtype backup = (chtype) ((ch == KEY_BACKSPACE) ? '\b' : ch);
if (backup < KEY_MIN)
wechochar(win, backup);
}
@ -512,7 +649,7 @@ _nc_wgetch(WINDOW *win,
/*
* Simulate ICRNL mode
*/
if ((ch == '\r') && sp->_nl)
if ((ch == '\r') && IsNl(sp))
ch = '\n';
/* Strip 8th-bit if so desired. We do this only for characters that
@ -535,9 +672,9 @@ NCURSES_EXPORT(int)
wgetch_events(WINDOW *win, _nc_eventlist * evl)
{
int code;
unsigned long value;
int value;
T((T_CALLED("wgetch_events(%p,%p)"), win, evl));
T((T_CALLED("wgetch_events(%p,%p)"), (void *) win, (void *) evl));
code = _nc_wgetch(win,
&value,
_nc_use_meta(win)
@ -552,9 +689,9 @@ NCURSES_EXPORT(int)
wgetch(WINDOW *win)
{
int code;
unsigned long value;
int value;
T((T_CALLED("wgetch(%p)"), win));
T((T_CALLED("wgetch(%p)"), (void *) win));
code = _nc_wgetch(win,
&value,
_nc_use_meta(win)
@ -580,11 +717,11 @@ wgetch(WINDOW *win)
*/
static int
kgetch(SCREEN *sp EVENTLIST_2nd(_nc_eventlist * evl))
kgetch(SCREEN *sp, bool forever EVENTLIST_2nd(_nc_eventlist * evl))
{
TRIES *ptr;
int ch = 0;
int timeleft = GetEscdelay(sp);
int timeleft = forever ? 9999999 : GetEscdelay(sp);
TR(TRACE_IEVENT, ("kgetch() called"));
@ -628,14 +765,15 @@ kgetch(SCREEN *sp EVENTLIST_2nd(_nc_eventlist * evl))
break;
}
TR(TRACE_IEVENT, ("ptr=%p, ch=%d, value=%d",
ptr, ptr->ch, ptr->value));
(void *) ptr, ptr->ch, ptr->value));
if (ptr->value != 0) { /* sequence terminated */
TR(TRACE_IEVENT, ("end of sequence"));
if (peek == tail)
if (peek == tail) {
fifo_clear(sp);
else
} else {
head = peek;
}
return (ptr->value);
}
@ -647,7 +785,7 @@ kgetch(SCREEN *sp EVENTLIST_2nd(_nc_eventlist * evl))
TR(TRACE_IEVENT, ("waiting for rest of sequence"));
rc = check_mouse_activity(sp, timeleft EVENTLIST_2nd(evl));
#ifdef NCURSES_WGETCH_EVENTS
if (rc & 4) {
if (rc & TW_EVENT) {
TR(TRACE_IEVENT, ("interrupted by a user event"));
/* FIXME Should have preserved remainder timeleft for reuse... */
peek = head; /* Restart interpreting later */

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_getstr.c,v 1.3 2010/01/12 23:22:05 nicm Exp $ */
/* $OpenBSD: lib_getstr.c,v 1.4 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2006,2008 Free Software Foundation, Inc. *
* Copyright 2018-2021,2023 Thomas E. Dickey *
* Copyright 1998-2011,2017 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,17 +41,17 @@
**
*/
#define NEED_KEY_EVENT
#include <curses.priv.h>
#include <term.h>
MODULE_ID("$Id: lib_getstr.c,v 1.3 2010/01/12 23:22:05 nicm Exp $")
MODULE_ID("$Id: lib_getstr.c,v 1.4 2023/10/17 09:52:08 nicm Exp $")
/*
* This wipes out the last character, no matter whether it was a tab, control
* or other character, and handles reverse wraparound.
*/
static char *
WipeOut(WINDOW *win, int y, int x, char *first, char *last, bool echoed)
WipeOut(WINDOW *win, int y, int x, char *first, char *last, int echoed)
{
if (last > first) {
*--last = '\0';
@ -79,31 +80,30 @@ wgetnstr_events(WINDOW *win,
{
SCREEN *sp = _nc_screen_of(win);
TTY buf;
bool oldnl, oldecho, oldraw, oldcbreak;
TTY_FLAGS save_flags;
char erasec;
char killc;
char *oldstr;
int ch;
int y, x;
T((T_CALLED("wgetnstr(%p,%p, %d)"), win, str, maxlen));
T((T_CALLED("wgetnstr(%p,%p,%d)"), (void *) win, (void *) str, maxlen));
if (!win)
if (!win || !str)
returnCode(ERR);
_nc_get_tty_mode(&buf);
maxlen = _nc_getstr_limit(maxlen);
oldnl = sp->_nl;
oldecho = sp->_echo;
oldraw = sp->_raw;
oldcbreak = sp->_cbreak;
nl();
noecho();
noraw();
cbreak();
NCURSES_SP_NAME(_nc_get_tty_mode) (NCURSES_SP_ARGx &buf);
erasec = erasechar();
killc = killchar();
save_flags = sp->_tty_flags;
NCURSES_SP_NAME(nl) (NCURSES_SP_ARG);
NCURSES_SP_NAME(noecho) (NCURSES_SP_ARG);
if (!save_flags._raw)
NCURSES_SP_NAME(cbreak) (NCURSES_SP_ARG);
erasec = NCURSES_SP_NAME(erasechar) (NCURSES_SP_ARG);
killc = NCURSES_SP_NAME(killchar) (NCURSES_SP_ARG);
oldstr = str;
getyx(win, y, x);
@ -114,7 +114,7 @@ wgetnstr_events(WINDOW *win,
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
* a \n from the down-arrow key. With this logic, it is the
* user's choice whether to set kcud=\n for wgetch();
* terminating *getstr() with \n should work either way.
*/
@ -122,7 +122,7 @@ wgetnstr_events(WINDOW *win,
|| ch == '\r'
|| ch == KEY_DOWN
|| ch == KEY_ENTER) {
if (oldecho == TRUE
if (save_flags._echo == TRUE
&& win->_cury == win->_maxy
&& win->_scroll)
wechochar(win, (chtype) '\n');
@ -138,18 +138,18 @@ wgetnstr_events(WINDOW *win,
#endif
if (ch == erasec || ch == KEY_LEFT || ch == KEY_BACKSPACE) {
if (str > oldstr) {
str = WipeOut(win, y, x, oldstr, str, oldecho);
str = WipeOut(win, y, x, oldstr, str, save_flags._echo);
}
} else if (ch == killc) {
while (str > oldstr) {
str = WipeOut(win, y, x, oldstr, str, oldecho);
str = WipeOut(win, y, x, oldstr, str, save_flags._echo);
}
} else if (ch >= KEY_MIN
|| (maxlen >= 0 && str - oldstr >= maxlen)) {
beep();
|| (str - oldstr >= maxlen)) {
NCURSES_SP_NAME(beep) (NCURSES_SP_ARG);
} else {
*str++ = (char) ch;
if (oldecho == TRUE) {
if (save_flags._echo == TRUE) {
int oldy = win->_cury;
if (waddch(win, (chtype) ch) == ERR) {
/*
@ -159,9 +159,9 @@ wgetnstr_events(WINDOW *win,
*/
win->_flags &= ~_WRAPPED;
waddch(win, (chtype) ' ');
str = WipeOut(win, y, x, oldstr, str, oldecho);
str = WipeOut(win, y, x, oldstr, str, save_flags._echo);
continue;
} else if (win->_flags & _WRAPPED) {
} else if (IS_WRAPPED(win)) {
/*
* If the last waddch forced a wrap &
* scroll, adjust our reference point
@ -190,12 +190,8 @@ wgetnstr_events(WINDOW *win,
/* 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;
_nc_set_tty_mode(&buf);
sp->_tty_flags = save_flags;
NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
*str = '\0';
if (ch == ERR)

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_hline.c,v 1.5 2010/01/12 23:22:05 nicm Exp $ */
/* $OpenBSD: lib_hline.c,v 1.6 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2001,2006 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2016,2017 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 +32,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,23 +45,21 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_hline.c,v 1.5 2010/01/12 23:22:05 nicm Exp $")
MODULE_ID("$Id: lib_hline.c,v 1.6 2023/10/17 09:52:08 nicm Exp $")
NCURSES_EXPORT(int)
whline(WINDOW *win, chtype ch, int n)
{
int code = ERR;
NCURSES_SIZE_T start;
NCURSES_SIZE_T end;
T((T_CALLED("whline(%p,%s,%d)"), win, _tracechtype(ch), n));
T((T_CALLED("whline(%p,%s,%d)"), (void *) win, _tracechtype(ch), n));
if (win) {
struct ldat *line = &(win->_line[win->_cury]);
NCURSES_CH_T wch;
int start = win->_curx;
int end = start + n - 1;
start = win->_curx;
end = start + n - 1;
if (end > win->_maxx)
end = win->_maxx;
@ -70,6 +71,14 @@ whline(WINDOW *win, chtype ch, int n)
SetChar2(wch, ch);
wch = _nc_render(win, wch);
#if USE_WIDEC_SUPPORT
if (start > 0 && isWidecExt(line->text[start])) {
SetChar2(line->text[start - 1], ' ');
}
if (end < win->_maxx && isWidecExt(line->text[end + 1])) {
SetChar2(line->text[end + 1], ' ');
}
#endif
while (end >= start) {
line->text[end] = wch;
end--;

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_immedok.c,v 1.3 2010/01/12 23:22:05 nicm Exp $ */
/* $OpenBSD: lib_immedok.c,v 1.4 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998,2000 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2000,2009 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,12 +43,12 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_immedok.c,v 1.3 2010/01/12 23:22:05 nicm Exp $")
MODULE_ID("$Id: lib_immedok.c,v 1.4 2023/10/17 09:52:08 nicm Exp $")
NCURSES_EXPORT(void)
immedok(WINDOW *win, bool flag)
{
T((T_CALLED("immedok(%p,%d)"), win, flag));
T((T_CALLED("immedok(%p,%d)"), (void *) win, flag));
if (win)
win->_immed = flag;

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_inchstr.c,v 1.3 2010/01/12 23:22:05 nicm Exp $ */
/* $OpenBSD: lib_inchstr.c,v 1.4 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2010,2017 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 +32,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,25 +44,28 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_inchstr.c,v 1.3 2010/01/12 23:22:05 nicm Exp $")
MODULE_ID("$Id: lib_inchstr.c,v 1.4 2023/10/17 09:52:08 nicm Exp $")
NCURSES_EXPORT(int)
winchnstr(WINDOW *win, chtype * str, int n)
winchnstr(WINDOW *win, chtype *str, int n)
{
int i = 0;
T((T_CALLED("winchnstr(%p,%p,%d)"), win, str, n));
T((T_CALLED("winchnstr(%p,%p,%d)"), (void *) win, (void *) str, n));
if (!str)
returnCode(0);
if (!win || !str) {
i = ERR;
} else {
int row = win->_cury;
int col = win->_curx;
NCURSES_CH_T *text = win->_line[row].text;
if (win) {
for (; (n < 0 || (i < n)) && (win->_curx + i <= win->_maxx); i++)
str[i] =
CharOf(win->_line[win->_cury].text[win->_curx + i]) |
AttrOf(win->_line[win->_cury].text[win->_curx + i]);
for (; (n < 0 || (i < n)) && (col + i <= win->_maxx); i++) {
str[i] = (((chtype) CharOf(text[col + i]) & A_CHARTEXT) |
AttrOf(text[col + i]));
}
str[i] = (chtype) 0;
}
str[i] = (chtype) 0;
returnCode(i);
}

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_initscr.c,v 1.3 2010/01/12 23:22:05 nicm Exp $ */
/* $OpenBSD: lib_initscr.c,v 1.4 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
* Copyright 2019,2020 Thomas E. Dickey *
* Copyright 1998-2016,2017 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 +32,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 *
* and: Thomas E. Dickey 1996-on *
****************************************************************************/
/*
@ -47,15 +48,13 @@
#include <sys/termio.h> /* needed for ISC */
#endif
MODULE_ID("$Id: lib_initscr.c,v 1.3 2010/01/12 23:22:05 nicm Exp $")
MODULE_ID("$Id: lib_initscr.c,v 1.4 2023/10/17 09:52:08 nicm Exp $")
NCURSES_EXPORT(WINDOW *)
initscr(void)
{
WINDOW *result;
NCURSES_CONST char *name;
START_TRACE();
T((T_CALLED("initscr()")));
@ -64,11 +63,18 @@ initscr(void)
/* Portable applications must not call initscr() more than once */
if (!_nc_globals.init_screen) {
const char *env;
char *name;
_nc_globals.init_screen = TRUE;
if ((name = getenv("TERM")) == 0
|| *name == '\0')
name = "unknown";
env = getenv("TERM");
(void) VALID_TERM_ENV(env, "unknown");
if ((name = strdup(env)) == NULL) {
fprintf(stderr, "Error opening allocating $TERM.\n");
ExitProgram(EXIT_FAILURE);
}
#ifdef __CYGWIN__
/*
* 2002/9/21
@ -77,9 +83,9 @@ initscr(void)
* core when attempting to write to stdout. Opening /dev/tty
* explicitly seems to fix the problem.
*/
if (isatty(fileno(stdout))) {
if (NC_ISATTY(fileno(stdout))) {
FILE *fp = fopen("/dev/tty", "w");
if (fp != 0 && isatty(fileno(fp))) {
if (fp != 0 && NC_ISATTY(fileno(fp))) {
fclose(stdout);
dup2(fileno(fp), STDOUT_FILENO);
stdout = fdopen(STDOUT_FILENO, "w");
@ -88,11 +94,16 @@ initscr(void)
#endif
if (newterm(name, stdout, stdin) == 0) {
fprintf(stderr, "Error opening terminal: %s.\n", name);
exit(EXIT_FAILURE);
ExitProgram(EXIT_FAILURE);
}
/* def_shell_mode - done in newterm/_nc_setupscreen */
#if NCURSES_SP_FUNCS
NCURSES_SP_NAME(def_prog_mode) (CURRENT_SCREEN);
#else
def_prog_mode();
#endif
free(name);
}
result = stdscr;
_nc_unlock_global(curses);

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_insch.c,v 1.3 2010/01/12 23:22:05 nicm Exp $ */
/* $OpenBSD: lib_insch.c,v 1.4 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2005,2008 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2013,2016 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 *
@ -45,24 +46,31 @@
#include <curses.priv.h>
#include <ctype.h>
MODULE_ID("$Id: lib_insch.c,v 1.3 2010/01/12 23:22:05 nicm Exp $")
MODULE_ID("$Id: lib_insch.c,v 1.4 2023/10/17 09:52:08 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)
_nc_insert_ch(SCREEN *sp, WINDOW *win, chtype ch)
{
int code = OK;
int ch8 = (int) ChCharOf(ch);
NCURSES_CH_T wch;
int count;
NCURSES_CONST char *s;
int tabsize = (
#if USE_REENTRANT
sp->_TABSIZE
#else
TABSIZE
#endif
);
switch (ch) {
case '\t':
for (count = (TABSIZE - (win->_curx % TABSIZE)); count > 0; count--) {
if ((code = _nc_insert_ch(win, ' ')) != OK)
for (count = (tabsize - (win->_curx % tabsize)); count > 0; count--) {
if ((code = _nc_insert_ch(sp, win, ' ')) != OK)
break;
}
break;
@ -77,8 +85,9 @@ _nc_insert_ch(WINDOW *win, chtype ch)
#if USE_WIDEC_SUPPORT
WINDOW_EXT(win, addch_used) == 0 &&
#endif
is8bits(ChCharOf(ch)) &&
isprint(ChCharOf(ch))) {
(isprint(ch8) ||
(ChAttrOf(ch) & A_ALTCHARSET) ||
(sp != 0 && sp->_legacy_coding && !iscntrl(ch8)))) {
if (win->_curx <= win->_maxx) {
struct ldat *line = &(win->_line[win->_cury]);
NCURSES_CH_T *end = &(line->text[win->_curx]);
@ -94,10 +103,11 @@ _nc_insert_ch(WINDOW *win, chtype ch)
*temp1 = _nc_render(win, wch);
win->_curx++;
}
} else if (is8bits(ChCharOf(ch)) && iscntrl(ChCharOf(ch))) {
s = unctrl(ChCharOf(ch));
} else if (iscntrl(ch8)) {
NCURSES_CONST char *s;
s = NCURSES_SP_NAME(unctrl) (NCURSES_SP_ARGx (chtype) ch8);
while (*s != '\0') {
code = _nc_insert_ch(win, ChAttrOf(ch) | UChar(*s));
code = _nc_insert_ch(sp, win, ChAttrOf(ch) | UChar(*s));
if (code != OK)
break;
++s;
@ -112,13 +122,15 @@ _nc_insert_ch(WINDOW *win, chtype ch)
wch = _nc_render(win, wch);
count = _nc_build_wch(win, &wch);
if (count > 0) {
code = wins_wch(win, &wch);
code = _nc_insert_wch(win, &wch);
} else if (count == -1) {
NCURSES_CONST char *s;
/* handle EILSEQ */
if (is8bits(ch)) {
s = unctrl(ChCharOf(ch));
s = NCURSES_SP_NAME(unctrl) (NCURSES_SP_ARGx (chtype) ch8);
if (strlen(s) > 1) {
while (*s != '\0') {
code = _nc_insert_ch(win, ChAttrOf(ch) | UChar(*s));
code = _nc_insert_ch(sp, win,
ChAttrOf(ch) | UChar(*s));
if (code != OK)
break;
++s;
@ -137,17 +149,15 @@ _nc_insert_ch(WINDOW *win, chtype ch)
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)));
T((T_CALLED("winsch(%p, %s)"), (void *) win, _tracechtype(c)));
if (win != 0) {
oy = win->_cury;
ox = win->_curx;
NCURSES_SIZE_T oy = win->_cury;
NCURSES_SIZE_T ox = win->_curx;
code = _nc_insert_ch(win, c);
code = _nc_insert_ch(_nc_screen_of(win), win, c);
win->_curx = ox;
win->_cury = oy;

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_insdel.c,v 1.3 2010/01/12 23:22:05 nicm Exp $ */
/* $OpenBSD: lib_insdel.c,v 1.4 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2001,2003 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2003,2009 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,14 +45,14 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_insdel.c,v 1.3 2010/01/12 23:22:05 nicm Exp $")
MODULE_ID("$Id: lib_insdel.c,v 1.4 2023/10/17 09:52:08 nicm Exp $")
NCURSES_EXPORT(int)
winsdelln(WINDOW *win, int n)
{
int code = ERR;
T((T_CALLED("winsdelln(%p,%d)"), win, n));
T((T_CALLED("winsdelln(%p,%d)"), (void *) win, n));
if (win) {
if (n != 0) {

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_insnstr.c,v 1.1 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_insnstr.c,v 1.2 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 2004 Free Software Foundation, Inc. *
* Copyright 2018-2020,2022 Thomas E. Dickey *
* Copyright 2004-2009,2016 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,29 +43,56 @@
#include <curses.priv.h>
#include <ctype.h>
MODULE_ID("$Id: lib_insnstr.c,v 1.1 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_insnstr.c,v 1.2 2023/10/17 09:52:08 nicm Exp $")
NCURSES_EXPORT(int)
winsnstr(WINDOW *win, const char *s, int n)
{
int code = ERR;
NCURSES_SIZE_T oy;
NCURSES_SIZE_T ox;
const unsigned char *str = (const unsigned char *) s;
const unsigned char *cp;
T((T_CALLED("winsnstr(%p,%s,%d)"), win, _nc_visbufn(s, n), n));
T((T_CALLED("winsnstr(%p,%s,%d)"), (void *) win, _nc_visbufn(s, n), n));
if (win != 0 && str != 0) {
oy = win->_cury;
ox = win->_curx;
for (cp = str; *cp && (n <= 0 || (cp - str) < n); cp++) {
_nc_insert_ch(win, (chtype) UChar(*cp));
SCREEN *sp = _nc_screen_of(win);
#if USE_WIDEC_SUPPORT
/*
* If the output contains "wide" (multibyte) characters, we will not
* really know the width of a character until we get the last byte
* of the character. Since the preceding byte(s) may use more columns
* on the screen than the final character, it is best to route the
* call to the wins_nwstr() function.
*/
if (sp->_screen_unicode) {
size_t nn = (n > 0) ? (size_t) n : strlen(s);
wchar_t *buffer = typeMalloc(wchar_t, nn + 1);
if (buffer != 0) {
mbstate_t state;
size_t n3;
init_mb(state);
n3 = mbstowcs(buffer, s, nn);
if (n3 != (size_t) (-1)) {
buffer[n3] = '\0';
code = wins_nwstr(win, buffer, (int) n3);
}
free(buffer);
}
}
if (code == ERR)
#endif
{
NCURSES_SIZE_T oy = win->_cury;
NCURSES_SIZE_T ox = win->_curx;
const unsigned char *cp;
for (cp = str; (n <= 0 || (cp - str) < n) && *cp; cp++) {
_nc_insert_ch(sp, win, (chtype) UChar(*cp));
}
win->_curx = ox;
win->_cury = oy;
_nc_synchook(win);
code = OK;
}
win->_curx = ox;
win->_cury = oy;
_nc_synchook(win);
code = OK;
}
returnCode(code);
}

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_instr.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_instr.c,v 1.4 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2005,2007 Free Software Foundation, Inc. *
* Copyright 2020-2021,2023 Thomas E. Dickey *
* Copyright 1998-2016,2017 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,56 +44,65 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_instr.c,v 1.3 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_instr.c,v 1.4 2023/10/17 09:52:08 nicm Exp $")
NCURSES_EXPORT(int)
winnstr(WINDOW *win, char *str, int n)
{
int i = 0, row, col;
int i = 0;
T((T_CALLED("winnstr(%p,%p,%d)"), win, str, n));
T((T_CALLED("winnstr(%p,%p,%d)"), (void *) win, str, n));
if (!str)
returnCode(0);
if (win) {
getyx(win, row, col);
if (!win || !str) {
i = ERR;
} else {
int row = win->_cury;
int col = win->_curx;
NCURSES_CH_T *text = win->_line[row].text;
if (n < 0)
n = win->_maxx - win->_curx + 1;
n = win->_maxx - col + 1;
for (; i < n;) {
#if USE_WIDEC_SUPPORT
cchar_t *cell = &(win->_line[row].text[col]);
wchar_t *wch;
cchar_t *cell = &(text[col]);
attr_t attrs;
short pair;
int n2;
bool done = FALSE;
mbstate_t state;
size_t i3, n3;
NCURSES_PAIRS_T pair;
char *tmp;
if (!isWidecExt(*cell)) {
wchar_t *wch;
int n2;
n2 = getcchar(cell, 0, 0, 0, 0);
if (n2 > 0
&& (wch = typeCalloc(wchar_t, (unsigned) n2 + 1)) != 0) {
bool done = FALSE;
if (getcchar(cell, wch, &attrs, &pair, 0) == OK) {
mbstate_t state;
size_t n3;
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);
n3 = wcstombs(0, wch, (size_t) 0);
if (!isEILSEQ(n3) && (n3 != 0) && (n3 <= MB_LEN_MAX)) {
size_t need = n3 + 10 + (size_t) i;
int have = (int) n3 + i;
/* check for loop-done as well as overflow */
if (have > n || (int) need <= 0) {
done = TRUE;
} else if ((tmp = typeCalloc(char, need)) == 0) {
done = TRUE;
} else {
size_t i3;
init_mb(state);
wcstombs(tmp, wch, n3);
for (i3 = 0; i3 < n3; ++i3)
str[i++] = tmp[i3];
free(tmp);
}
}
}
free(wch);
@ -101,14 +111,14 @@ winnstr(WINDOW *win, char *str, int n)
}
}
#else
str[i++] = (char) CharOf(win->_line[row].text[col]);
str[i++] = (char) CharOf(text[col]);
#endif
if (++col > win->_maxx) {
break;
}
}
str[i] = '\0'; /* SVr4 does not seem to count the null */
}
str[i] = '\0'; /* SVr4 does not seem to count the null */
T(("winnstr returns %s", _nc_visbuf(str)));
returnCode(i);
}

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_isendwin.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_isendwin.c,v 1.4 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998,2000 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2009,2017 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 +32,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: Juergen Pfeifer 2009 *
****************************************************************************/
/*
@ -42,12 +45,20 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_isendwin.c,v 1.3 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_isendwin.c,v 1.4 2023/10/17 09:52:08 nicm Exp $")
NCURSES_EXPORT(bool)
NCURSES_SP_NAME(isendwin) (NCURSES_SP_DCL0)
{
if (SP_PARM == NULL)
return FALSE;
return (SP_PARM->_endwin == ewSuspend);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(bool)
isendwin(void)
{
if (SP == NULL)
return FALSE;
return SP->_endwin;
return NCURSES_SP_NAME(isendwin) (CURRENT_SCREEN);
}
#endif

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_leaveok.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_leaveok.c,v 1.4 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998,2000 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2000,2009 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,12 +43,12 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_leaveok.c,v 1.3 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_leaveok.c,v 1.4 2023/10/17 09:52:08 nicm Exp $")
NCURSES_EXPORT(int)
leaveok(WINDOW *win, bool flag)
{
T((T_CALLED("leaveok(%p,%d)"), win, flag));
T((T_CALLED("leaveok(%p,%d)"), (void *) win, flag));
if (win) {
win->_leaveok = flag;

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_move.c,v 1.4 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_move.c,v 1.5 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2000,2004 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2004,2009 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,12 +44,12 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_move.c,v 1.4 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_move.c,v 1.5 2023/10/17 09:52:08 nicm Exp $")
NCURSES_EXPORT(int)
wmove(WINDOW *win, int y, int x)
{
T((T_CALLED("wmove(%p,%d,%d)"), win, y, x));
T((T_CALLED("wmove(%p,%d,%d)"), (void *) win, y, x));
if (LEGALYX(win, y, x)) {
win->_curx = (NCURSES_SIZE_T) x;

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_mvwin.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_mvwin.c,v 1.4 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2001,2006 Free Software Foundation, Inc. *
* Copyright 2020,2021 Thomas E. Dickey *
* Copyright 1998-2009,2010 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 +32,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: Juergen Pfeifer *
****************************************************************************/
/*
@ -42,14 +45,18 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_mvwin.c,v 1.3 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_mvwin.c,v 1.4 2023/10/17 09:52:08 nicm Exp $")
NCURSES_EXPORT(int)
mvwin(WINDOW *win, int by, int bx)
{
T((T_CALLED("mvwin(%p,%d,%d)"), win, by, bx));
#if NCURSES_SP_FUNCS
SCREEN *sp = _nc_screen_of(win);
#endif
if (!win || (win->_flags & _ISPAD))
T((T_CALLED("mvwin(%p,%d,%d)"), (void *) win, by, bx));
if (!win || IS_PAD(win))
returnCode(ERR);
/*
@ -58,7 +65,7 @@ mvwin(WINDOW *win, int by, int bx)
*/
#if 0
/* Copying subwindows is allowed, but it is expensive... */
if (win->_flags & _SUBWIN) {
if (IS_SUBWIN(win)) {
int err = ERR;
WINDOW *parent = win->_parent;
if (parent) { /* Now comes the complicated and costly part, you should really
@ -98,8 +105,8 @@ mvwin(WINDOW *win, int by, int bx)
}
#endif
if (by + win->_maxy > screen_lines - 1
|| bx + win->_maxx > screen_columns - 1
if (by + win->_maxy > screen_lines(SP_PARM) - 1
|| bx + win->_maxx > screen_columns(SP_PARM) - 1
|| by < 0
|| bx < 0)
returnCode(ERR);
@ -110,7 +117,7 @@ mvwin(WINDOW *win, int by, int bx)
* new location. This ensures that if the caller has refreshed another
* window at the same location, that this one will be displayed.
*/
win->_begy = by;
win->_begx = bx;
win->_begy = (NCURSES_SIZE_T) by;
win->_begx = (NCURSES_SIZE_T) bx;
returnCode(touchwin(win));
}

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_newterm.c,v 1.13 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_newterm.c,v 1.14 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
* Copyright 2018-2020,2022 Thomas E. Dickey *
* Copyright 1998-2016,2017 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,6 +33,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 *
* and: Juergen Pfeifer 2009 *
****************************************************************************/
/*
@ -43,14 +45,19 @@
#include <curses.priv.h>
#if SVR4_TERMIO && !defined(_POSIX_SOURCE)
#define _POSIX_SOURCE
#ifndef CUR
#define CUR SP_TERMTYPE
#endif
#include <term.h> /* clear_screen, cup & friends, cur_term */
#include <tic.h>
MODULE_ID("$Id: lib_newterm.c,v 1.13 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_newterm.c,v 1.14 2023/10/17 09:52:08 nicm Exp $")
#ifdef USE_TERM_DRIVER
#define NumLabels InfoOf(SP_PARM).numlabels
#else
#define NumLabels num_labels
#endif
#ifndef ONLCR /* Allows compilation under the QNX 4.2 OS */
#define ONLCR 0
@ -65,29 +72,38 @@ MODULE_ID("$Id: lib_newterm.c,v 1.13 2010/01/12 23:22:06 nicm Exp $")
* is supposed to behave as if it calls newterm, we do it here.
*/
static NCURSES_INLINE int
_nc_initscr(void)
_nc_initscr(NCURSES_SP_DCL0)
{
int result = ERR;
TERMINAL *term = TerminalOf(SP_PARM);
/* for extended XPG4 conformance requires cbreak() at this point */
/* (SVr4 curses does this anyway) */
if (cbreak() == OK) {
T((T_CALLED("_nc_initscr(%p) ->term %p"), (void *) SP_PARM, (void *) term));
if (NCURSES_SP_NAME(cbreak) (NCURSES_SP_ARG) == OK) {
TTY buf;
buf = cur_term->Nttyb;
buf = term->Nttyb;
#ifdef TERMIOS
buf.c_lflag &= ~(ECHO | ECHONL);
buf.c_iflag &= ~(ICRNL | INLCR | IGNCR);
buf.c_oflag &= ~(ONLCR);
buf.c_lflag &= (unsigned) ~(ECHO | ECHONL);
buf.c_iflag &= (unsigned) ~(ICRNL | INLCR | IGNCR);
buf.c_oflag &= (unsigned) ~(ONLCR);
#elif HAVE_SGTTY_H
buf.sg_flags &= ~(ECHO | CRMOD);
#elif defined(EXP_WIN32_DRIVER)
buf.dwFlagIn = CONMODE_IN_DEFAULT;
buf.dwFlagOut = CONMODE_OUT_DEFAULT | VT_FLAG_OUT;
if (WINCONSOLE.isTermInfoConsole) {
buf.dwFlagIn |= VT_FLAG_IN;
}
#else
memset(&buf, 0, sizeof(buf));
#endif
if ((result = _nc_set_tty_mode(&buf)) == OK)
cur_term->Nttyb = buf;
result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
if (result == OK)
term->Nttyb = buf;
}
return result;
returnCode(result);
}
/*
@ -97,13 +113,30 @@ _nc_initscr(void)
* initialized.
*/
NCURSES_EXPORT(void)
NCURSES_SP_NAME(filter) (NCURSES_SP_DCL0)
{
START_TRACE();
T((T_CALLED("filter(%p)"), (void *) SP_PARM));
#if NCURSES_SP_FUNCS
if (IsPreScreen(SP_PARM)) {
SP_PARM->_filtered = TRUE;
}
#else
_nc_prescreen.filter_mode = TRUE;
#endif
returnVoid;
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(void)
filter(void)
{
START_TRACE();
T((T_CALLED("filter")));
T((T_CALLED("filter()")));
_nc_prescreen.filter_mode = TRUE;
returnVoid;
}
#endif
#if NCURSES_EXT_FUNCS
/*
@ -111,62 +144,128 @@ filter(void)
* requiring it to also be filtered.
*/
NCURSES_EXPORT(void)
NCURSES_SP_NAME(nofilter) (NCURSES_SP_DCL0)
{
START_TRACE();
T((T_CALLED("nofilter(%p)"), (void *) SP_PARM));
#if NCURSES_SP_FUNCS
if (IsPreScreen(SP_PARM)) {
SP_PARM->_filtered = FALSE;
}
#else
_nc_prescreen.filter_mode = FALSE;
#endif
returnVoid;
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(void)
nofilter(void)
{
START_TRACE();
T((T_CALLED("nofilter")));
T((T_CALLED("nofilter()")));
_nc_prescreen.filter_mode = FALSE;
returnVoid;
}
#endif
#endif /* NCURSES_EXT_FUNCS */
NCURSES_EXPORT(SCREEN *)
newterm(NCURSES_CONST char *name, FILE *ofp, FILE *ifp)
NCURSES_SP_NAME(newterm) (NCURSES_SP_DCLx
const char *name,
FILE *ofp,
FILE *ifp)
{
int value;
int errret;
SCREEN *current;
SCREEN *result = 0;
SCREEN *current;
TERMINAL *its_term;
FILE *_ofp = ofp ? ofp : stdout;
FILE *_ifp = ifp ? ifp : stdin;
TERMINAL *new_term = 0;
START_TRACE();
T((T_CALLED("newterm(\"%s\",%p,%p)"), name, ofp, ifp));
T((T_CALLED("newterm(%p, \"%s\", %p,%p)"),
(void *) SP_PARM,
(name ? name : ""),
(void *) ofp,
(void *) ifp));
#if NCURSES_SP_FUNCS
assert(SP_PARM != 0);
if (SP_PARM == 0)
returnSP(SP_PARM);
#endif
_nc_init_pthreads();
_nc_lock_global(curses);
current = SP;
its_term = (SP ? SP->_term : 0);
current = CURRENT_SCREEN;
its_term = (current ? current->_term : 0);
#if defined(EXP_WIN32_DRIVER)
_setmode(fileno(_ifp), _O_BINARY);
_setmode(fileno(_ofp), _O_BINARY);
#endif
INIT_TERM_DRIVER();
/* this loads the capability entry, then sets LINES and COLS */
if (setupterm(name, fileno(ofp), &errret) != ERR) {
int slk_format = _nc_globals.slk_format;
if (
TINFO_SETUP_TERM(&new_term, name,
fileno(_ofp), &errret, FALSE) != ERR) {
int slk_format;
int filter_mode;
_nc_set_screen(0);
#ifdef USE_TERM_DRIVER
assert(new_term != 0);
#endif
#if NCURSES_SP_FUNCS
slk_format = SP_PARM->slk_format;
filter_mode = SP_PARM->_filtered;
#else
slk_format = _nc_globals.slk_format;
filter_mode = _nc_prescreen.filter_mode;
#endif
/*
* 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);
}
if (_nc_setupscreen(LINES,
COLS,
ofp,
_nc_prescreen.filter_mode,
slk_format) == ERR) {
if (NCURSES_SP_NAME(_nc_setupscreen) (
#if NCURSES_SP_FUNCS
&SP_PARM,
#endif
*(ptrLines(SP_PARM)),
*(ptrCols(SP_PARM)),
_ofp,
filter_mode,
slk_format) == ERR) {
_nc_set_screen(current);
result = 0;
} else {
assert(SP != 0);
int value;
int cols;
#ifdef USE_TERM_DRIVER
TERMINAL_CONTROL_BLOCK *TCB;
#elif !NCURSES_SP_FUNCS
_nc_set_screen(CURRENT_SCREEN);
#endif
assert(SP_PARM != 0);
cols = *(ptrCols(SP_PARM));
#ifdef USE_TERM_DRIVER
_nc_set_screen(SP_PARM);
TCB = (TERMINAL_CONTROL_BLOCK *) new_term;
TCB->csp = SP_PARM;
#endif
/*
* 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.
* CURRENT_SCREEN. So the "current" screen's terminal pointer was
* overwritten with a different terminal. Later, in
* _nc_setupscreen(), we set CURRENT_SCREEN and the terminal
* pointer in the new screen.
*
* Restore the terminal-pointer for the pre-existing screen, if
* any.
@ -174,37 +273,58 @@ newterm(NCURSES_CONST char *name, FILE *ofp, FILE *ifp)
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));
#ifdef USE_TERM_DRIVER
SP_PARM->_term = new_term;
#else
SP->_use_meta = FALSE;
new_term = SP_PARM->_term;
#endif
SP->_endwin = FALSE;
/* allow user to set maximum escape delay from the environment */
if ((value = _nc_getenv_num("ESCDELAY")) >= 0) {
#if NCURSES_EXT_FUNCS
NCURSES_SP_NAME(set_escdelay) (NCURSES_SP_ARGx value);
#else
ESCDELAY = value;
#endif
}
/* if the terminal type has real soft labels, set those up */
if (slk_format && NumLabels > 0 && SLK_STDFMT(slk_format))
_nc_slk_initialize(StdScreen(SP_PARM), cols);
SP_PARM->_ifd = fileno(_ifp);
NCURSES_SP_NAME(typeahead) (NCURSES_SP_ARGx fileno(_ifp));
#ifdef TERMIOS
SP_PARM->_use_meta = ((new_term->Ottyb.c_cflag & CSIZE) == CS8 &&
!(new_term->Ottyb.c_iflag & ISTRIP)) ||
USE_KLIBC_KBD;
#else
SP_PARM->_use_meta = FALSE;
#endif
SP_PARM->_endwin = ewInitial;
#ifndef USE_TERM_DRIVER
/*
* 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)));
SP_PARM->_scrolling = ((scroll_forward && scroll_reverse) ||
((parm_rindex ||
parm_insert_line ||
insert_line) &&
(parm_index ||
parm_delete_line ||
delete_line)));
#endif
baudrate(); /* sets a field in the SP structure */
NCURSES_SP_NAME(baudrate) (NCURSES_SP_ARG); /* sets a field in the screen structure */
SP->_keytry = 0;
SP_PARM->_keytry = 0;
/* compute movement costs so we can do better move optimization */
#ifdef USE_TERM_DRIVER
TCBOf(SP_PARM)->drv->td_scinit(SP_PARM);
#else /* ! USE_TERM_DRIVER */
/*
* Check for mismatched graphic-rendition capabilities. Most SVr4
* terminfo trees contain entries that have rmul or rmso equated to
@ -215,23 +335,43 @@ newterm(NCURSES_CONST char *name, FILE *ofp, FILE *ifp)
* 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);
SP_PARM->_use_rmso = SGR0_TEST(exit_standout_mode);
SP_PARM->_use_rmul = SGR0_TEST(exit_underline_mode);
#if USE_ITALIC
SP_PARM->_use_ritm = SGR0_TEST(exit_italics_mode);
#endif
/* compute movement costs so we can do better move optimization */
_nc_mvcur_init();
/* initialize terminal to a sane state */
_nc_screen_init();
#endif /* USE_TERM_DRIVER */
/* Initialize the terminal line settings. */
_nc_initscr();
_nc_initscr(NCURSES_SP_ARG);
_nc_signal_handler(TRUE);
result = SP;
result = SP_PARM;
}
}
_nc_unlock_global(curses);
returnSP(result);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(SCREEN *)
newterm(const char *name, FILE *ofp, FILE *ifp)
{
SCREEN *rc;
_nc_init_pthreads();
_nc_lock_global(prescreen);
START_TRACE();
rc = NCURSES_SP_NAME(newterm) (CURRENT_SCREEN_PRE, name, ofp, ifp);
_nc_forget_prescr();
_nc_unlock_global(prescreen);
return rc;
}
#endif

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_newwin.c,v 1.6 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_newwin.c,v 1.7 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
* Copyright 2020,2021 Thomas E. Dickey *
* Copyright 1998-2016,2017 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,6 +33,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 *
* and: Juergen Pfeifer 2009 *
****************************************************************************/
/*
@ -44,7 +46,7 @@
#include <curses.priv.h>
#include <stddef.h>
MODULE_ID("$Id: lib_newwin.c,v 1.6 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_newwin.c,v 1.7 2023/10/17 09:52:08 nicm Exp $")
#define window_is(name) ((sp)->_##name == win)
@ -63,6 +65,17 @@ remove_window_from_screen(WINDOW *win)
{
SCREEN *sp;
#ifdef USE_SP_WINDOWLIST
if ((sp = _nc_screen_of(win)) != 0) {
if (window_is(curscr)) {
remove_window(curscr);
} else if (window_is(stdscr)) {
remove_window(stdscr);
} else if (window_is(newscr)) {
remove_window(newscr);
}
}
#else
for (each_screen(sp)) {
if (window_is(curscr)) {
remove_window(curscr);
@ -75,29 +88,37 @@ remove_window_from_screen(WINDOW *win)
break;
}
}
#endif
}
NCURSES_EXPORT(int)
_nc_freewin(WINDOW *win)
{
WINDOWLIST *p, *q;
int i;
int result = ERR;
#ifdef USE_SP_WINDOWLIST
SCREEN *sp = _nc_screen_of(win); /* pretend this is parameter */
#endif
T((T_CALLED("_nc_freewin(%p)"), win));
T((T_CALLED("_nc_freewin(%p)"), (void *) win));
if (win != 0) {
if (_nc_try_global(curses) == 0) {
if (_nc_nonsp_try_global(curses) == 0) {
WINDOWLIST *p, *q;
q = 0;
for (each_window(p)) {
for (each_window(sp, p)) {
if (&(p->win) == win) {
remove_window_from_screen(win);
if (q == 0)
_nc_windows = p->next;
WindowList(sp) = p->next;
else
q->next = p->next;
if (!(win->_flags & _SUBWIN)) {
if (!IS_SUBWIN(win)) {
int i;
for (i = 0; i <= win->_maxy; i++)
FreeIfNeeded(win->_line[i].text);
}
@ -105,35 +126,43 @@ _nc_freewin(WINDOW *win)
free(p);
result = OK;
T(("...deleted win=%p", win));
T(("...deleted win=%p", (void *) win));
break;
}
q = p;
}
_nc_unlock_global(curses);
_nc_nonsp_unlock_global(curses);
}
}
returnCode(result);
}
NCURSES_EXPORT(WINDOW *)
newwin(int num_lines, int num_columns, int begy, int begx)
NCURSES_SP_NAME(newwin) (NCURSES_SP_DCLx
int num_lines, int num_columns, int begy, int begx)
{
WINDOW *win;
NCURSES_CH_T *ptr;
int i;
T((T_CALLED("newwin(%d,%d,%d,%d)"), num_lines, num_columns, begy, begx));
T((T_CALLED("newwin(%p, %d,%d,%d,%d)"), (void *) SP_PARM, num_lines, num_columns,
begy, begx));
if (begy < 0 || begx < 0 || num_lines < 0 || num_columns < 0)
if (begy < 0
|| begx < 0
|| num_lines < 0
|| num_columns < 0
|| SP_PARM == 0)
returnWin(0);
if (num_lines == 0)
num_lines = SP->_lines_avail - begy;
num_lines = SP_PARM->_lines_avail - begy;
if (num_columns == 0)
num_columns = screen_columns - begx;
num_columns = screen_columns(SP_PARM) - begx;
if ((win = _nc_makenew(num_lines, num_columns, begy, begx, 0)) == 0)
win = NCURSES_SP_NAME(_nc_makenew) (NCURSES_SP_ARGx
num_lines, num_columns, begy, begx, 0);
if (win == 0)
returnWin(0);
for (i = 0; i < num_lines; i++) {
@ -151,14 +180,30 @@ newwin(int num_lines, int num_columns, int begy, int begx)
returnWin(win);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(WINDOW *)
newwin(int num_lines, int num_columns, int begy, int begx)
{
WINDOW *win;
_nc_sp_lock_global(curses);
win = NCURSES_SP_NAME(newwin) (CURRENT_SCREEN,
num_lines, num_columns, begy, begx);
_nc_sp_unlock_global(curses);
return (win);
}
#endif
NCURSES_EXPORT(WINDOW *)
derwin(WINDOW *orig, int num_lines, int num_columns, int begy, int begx)
{
WINDOW *win;
int i;
int flags = _SUBWIN;
#if NCURSES_SP_FUNCS
SCREEN *sp = _nc_screen_of(orig);
#endif
T((T_CALLED("derwin(%p,%d,%d,%d,%d)"), orig, num_lines, num_columns,
T((T_CALLED("derwin(%p,%d,%d,%d,%d)"), (void *) orig, num_lines, num_columns,
begy, begx));
/*
@ -176,11 +221,13 @@ derwin(WINDOW *orig, int num_lines, int num_columns, int begy, int begx)
if (num_columns == 0)
num_columns = orig->_maxx + 1 - begx;
if (orig->_flags & _ISPAD)
if (IS_PAD(orig))
flags |= _ISPAD;
if ((win = _nc_makenew(num_lines, num_columns, orig->_begy + begy,
orig->_begx + begx, flags)) == 0)
win = NCURSES_SP_NAME(_nc_makenew) (NCURSES_SP_ARGx num_lines, num_columns,
orig->_begy + begy,
orig->_begx + begx, flags);
if (win == 0)
returnWin(0);
win->_pary = begy;
@ -199,30 +246,41 @@ derwin(WINDOW *orig, int num_lines, int num_columns, int begy, int begx)
NCURSES_EXPORT(WINDOW *)
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 = %ld, begx = %ld", (long) w->_begy, (long) w->_begx));
WINDOW *result = 0;
returnWin(derwin(w, l, c, y - w->_begy, x - w->_begx));
T((T_CALLED("subwin(%p, %d, %d, %d, %d)"), (void *) w, l, c, y, x));
if (w != 0) {
T(("parent has begy = %ld, begx = %ld", (long) w->_begy, (long) w->_begx));
result = derwin(w, l, c, y - w->_begy, x - w->_begx);
}
returnWin(result);
}
static bool
dimension_limit(int value)
{
NCURSES_SIZE_T test = value;
NCURSES_SIZE_T test = (NCURSES_SIZE_T) value;
return (test == value && value > 0);
}
NCURSES_EXPORT(WINDOW *)
_nc_makenew(int num_lines, int num_columns, int begy, int begx, int flags)
NCURSES_SP_NAME(_nc_makenew) (NCURSES_SP_DCLx
int num_lines,
int num_columns,
int begy,
int begx,
int flags)
{
int i;
WINDOWLIST *wp;
WINDOW *win;
bool is_pad = (flags & _ISPAD);
bool is_padwin = (flags & _ISPAD);
T((T_CALLED("_nc_makenew(%d,%d,%d,%d)"), num_lines, num_columns, begy, begx));
T((T_CALLED("_nc_makenew(%p,%d,%d,%d,%d)"),
(void *) SP_PARM, num_lines, num_columns, begy, begx));
if (SP == 0)
if (SP_PARM == 0)
returnWin(0);
if (!dimension_limit(num_lines) || !dimension_limit(num_columns))
@ -238,22 +296,24 @@ _nc_makenew(int num_lines, int num_columns, int begy, int begx, int flags)
returnWin(0);
}
_nc_lock_global(curses);
_nc_nonsp_lock_global(curses);
win->_curx = 0;
win->_cury = 0;
win->_maxy = num_lines - 1;
win->_maxx = num_columns - 1;
win->_begy = begy;
win->_begx = begx;
win->_yoffset = SP->_topstolen;
win->_maxy = (NCURSES_SIZE_T) (num_lines - 1);
win->_maxx = (NCURSES_SIZE_T) (num_columns - 1);
win->_begy = (NCURSES_SIZE_T) begy;
win->_begx = (NCURSES_SIZE_T) begx;
win->_yoffset = SP_PARM->_topstolen;
win->_flags = flags;
win->_flags = (short) flags;
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);
win->_clear = (is_padwin
? FALSE
: (num_lines == screen_lines(SP_PARM)
&& num_columns == screen_columns(SP_PARM)));
win->_idlok = FALSE;
win->_idcok = TRUE;
win->_scroll = FALSE;
@ -267,7 +327,7 @@ _nc_makenew(int num_lines, int num_columns, int begy, int begx, int flags)
win->_parent = 0;
win->_regtop = 0;
win->_regbottom = num_lines - 1;
win->_regbottom = (NCURSES_SIZE_T) (num_lines - 1);
win->_pad._pad_y = -1;
win->_pad._pad_x = -1;
@ -297,28 +357,28 @@ _nc_makenew(int num_lines, int num_columns, int begy, int begx, int flags)
* So that's how we want ncurses to behave.
*/
win->_line[i].firstchar = 0;
win->_line[i].lastchar = num_columns - 1;
win->_line[i].lastchar = (NCURSES_SIZE_T) (num_columns - 1);
if_USE_SCROLL_HINTS(win->_line[i].oldindex = i);
}
if (!is_pad && (begx + num_columns == screen_columns)) {
if (!is_padwin && (begx + num_columns == screen_columns(SP_PARM))) {
win->_flags |= _ENDLINE;
if (begx == 0 && num_lines == screen_lines && begy == 0)
if (begx == 0 && num_lines == screen_lines(SP_PARM) && begy == 0)
win->_flags |= _FULLWIN;
if (begy + num_lines == screen_lines)
if (begy + num_lines == screen_lines(SP_PARM))
win->_flags |= _SCROLLWIN;
}
wp->next = _nc_windows;
wp->screen = SP;
_nc_windows = wp;
wp->next = WindowList(SP_PARM);
wp->screen = SP_PARM;
WindowList(SP_PARM) = wp;
T((T_CREATE("window %p"), win));
T((T_CREATE("window %p"), (void *) win));
_nc_unlock_global(curses);
_nc_nonsp_unlock_global(curses);
returnWin(win);
}
@ -327,14 +387,22 @@ _nc_makenew(int num_lines, int num_columns, int begy, int begx, int flags)
* 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)
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(WINDOW *)
_nc_curscr_of(SCREEN *sp)
{
SCREEN *sp = 0;
if (win != 0) {
WINDOWLIST *wp = (WINDOWLIST *) win;
sp = wp->screen;
}
return (sp);
return (sp == 0) ? NULL : CurScreen(sp);
}
NCURSES_EXPORT(WINDOW *)
_nc_newscr_of(SCREEN *sp)
{
return (sp == 0) ? NULL : NewScreen(sp);
}
NCURSES_EXPORT(WINDOW *)
_nc_stdscr_of(SCREEN *sp)
{
return (sp == 0) ? NULL : StdScreen(sp);
}
#endif

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_nl.c,v 1.6 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_nl.c,v 1.7 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. *
* Copyright 2020,2023 Thomas E. Dickey *
* Copyright 1998-2000,2009 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 +32,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: Juergen Pfeifer 2009 *
****************************************************************************/
/*
@ -44,38 +47,52 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_nl.c,v 1.6 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_nl.c,v 1.7 2023/10/17 09:52:08 nicm Exp $")
#ifdef __EMX__
#include <io.h>
#endif
NCURSES_EXPORT(int)
nl(void)
NCURSES_SP_NAME(nl) (NCURSES_SP_DCL0)
{
T((T_CALLED("nl()")));
SP->_nl = TRUE;
T((T_CALLED("nl(%p)"), (void *) SP_PARM));
if (0 == SP_PARM)
returnCode(ERR);
IsNl(SP_PARM) = TRUE;
#ifdef __EMX__
_nc_flush();
_fsetmode(NC_OUTPUT, "t");
_fsetmode(NC_OUTPUT(SP_PARM), "t");
#endif
returnCode(OK);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
nl(void)
{
return NCURSES_SP_NAME(nl) (CURRENT_SCREEN);
}
#endif
NCURSES_EXPORT(int)
NCURSES_SP_NAME(nonl) (NCURSES_SP_DCL0)
{
T((T_CALLED("nonl(%p)"), (void *) SP_PARM));
if (0 == SP_PARM)
returnCode(ERR);
IsNl(SP_PARM) = FALSE;
#ifdef __EMX__
_nc_flush();
_fsetmode(NC_OUTPUT(SP_PARM), "b");
#endif
returnCode(OK);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
nonl(void)
{
T((T_CALLED("nonl()")));
SP->_nl = FALSE;
#ifdef __EMX__
_nc_flush();
_fsetmode(NC_OUTPUT, "b");
#endif
returnCode(OK);
return NCURSES_SP_NAME(nonl) (CURRENT_SCREEN);
}
#endif

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_overlay.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_overlay.c,v 1.4 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2013,2016 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,21 +43,19 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_overlay.c,v 1.3 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_overlay.c,v 1.4 2023/10/17 09:52:08 nicm Exp $")
static int
overlap(const WINDOW *const src, WINDOW *const dst, int const 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));
T((T_CALLED("overlap(%p,%p,%d)"), (const void *) src, (void *) dst, flag));
if (src != 0 && dst != 0) {
int sx1, sy1, sx2, sy2;
int dx1, dy1, dx2, dy2;
_nc_lock_global(curses);
T(("src : begy %ld, begx %ld, maxy %ld, maxx %ld",
@ -81,12 +80,12 @@ overlap(const WINDOW *const src, WINDOW *const dst, int const flag)
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;
int sminrow = max(sy1, dy1) - sy1;
int smincol = max(sx1, dx1) - sx1;
int dminrow = max(sy1, dy1) - dy1;
int dmincol = max(sx1, dx1) - dx1;
int dmaxrow = min(sy2, dy2) - dy1;
int dmaxcol = min(sx2, dx2) - dx1;
rc = copywin(src, dst,
sminrow, smincol,
@ -112,7 +111,7 @@ overlap(const WINDOW *const src, WINDOW *const dst, int const flag)
NCURSES_EXPORT(int)
overlay(const WINDOW *win1, WINDOW *win2)
{
T((T_CALLED("overlay(%p,%p)"), win1, win2));
T((T_CALLED("overlay(%p,%p)"), (const void *) win1, (void *) win2));
returnCode(overlap(win1, win2, TRUE));
}
@ -129,7 +128,7 @@ overlay(const WINDOW *win1, WINDOW *win2)
NCURSES_EXPORT(int)
overwrite(const WINDOW *win1, WINDOW *win2)
{
T((T_CALLED("overwrite(%p,%p)"), win1, win2));
T((T_CALLED("overwrite(%p,%p)"), (const void *) win1, (void *) win2));
returnCode(overlap(win1, win2, FALSE));
}
@ -141,15 +140,21 @@ copywin(const WINDOW *src, WINDOW *dst,
int over)
{
int rc = ERR;
int sx, sy, dx, dy;
bool touched;
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));
(const void *) src,
(void *) dst,
sminrow, smincol,
dminrow, dmincol,
dmaxrow, dmaxcol, over));
if (src != 0
&& dst != 0
&& dmaxrow >= dminrow
&& dmaxcol >= dmincol) {
attr_t bk;
attr_t mask;
if (src && dst) {
_nc_lock_global(curses);
bk = AttrOf(dst->_nc_bkgd);
@ -163,17 +168,28 @@ copywin(const WINDOW *src, WINDOW *dst,
/* make sure rectangle fits in destination */
if (dmaxrow <= dst->_maxy && dmaxcol <= dst->_maxx) {
int sx, sy, dx, dy;
bool copied = FALSE;
T(("rectangle fits in destination"));
for (dy = dminrow, sy = sminrow;
dy <= dmaxrow;
sy++, dy++) {
bool touched;
if (dy < 0 || sy < 0)
continue;
touched = FALSE;
for (dx = dmincol, sx = smincol;
dx <= dmaxcol;
sx++, dx++) {
if (dx < 0 || sx < 0)
continue;
copied = TRUE;
if (over) {
if ((CharOf(src->_line[sy].text[sx]) != L(' ')) &&
(!CharEq(dst->_line[dy].text[dx],
@ -199,7 +215,8 @@ copywin(const WINDOW *src, WINDOW *dst,
}
}
T(("finished copywin"));
rc = OK;
if (copied)
rc = OK;
}
}
_nc_unlock_global(curses);

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_pad.c,v 1.5 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_pad.c,v 1.6 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2004,2006 Free Software Foundation, Inc. *
* Copyright 2020,2021 Thomas E. Dickey *
* Copyright 1998-2010,2017 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 +32,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: Juergen Pfeifer 2009 *
****************************************************************************/
/*
@ -42,21 +45,22 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_pad.c,v 1.5 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_pad.c,v 1.6 2023/10/17 09:52:08 nicm Exp $")
NCURSES_EXPORT(WINDOW *)
newpad(int l, int c)
NCURSES_SP_NAME(newpad) (NCURSES_SP_DCLx int l, int c)
{
WINDOW *win;
NCURSES_CH_T *ptr;
int i;
T((T_CALLED("newpad(%d, %d)"), l, c));
T((T_CALLED("newpad(%p,%d, %d)"), (void *) SP_PARM, l, c));
if (l <= 0 || c <= 0)
returnWin(0);
if ((win = _nc_makenew(l, c, 0, 0, _ISPAD)) == NULL)
win = NCURSES_SP_NAME(_nc_makenew) (NCURSES_SP_ARGx l, c, 0, 0, _ISPAD);
if (win == NULL)
returnWin(0);
for (i = 0; i < l; i++) {
@ -72,6 +76,14 @@ newpad(int l, int c)
returnWin(win);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(WINDOW *)
newpad(int l, int c)
{
return NCURSES_SP_NAME(newpad) (CURRENT_SCREEN, l, c);
}
#endif
NCURSES_EXPORT(WINDOW *)
subpad(WINDOW *orig, int l, int c, int begy, int begx)
{
@ -80,7 +92,7 @@ subpad(WINDOW *orig, int l, int c, int begy, int begx)
T((T_CALLED("subpad(%d, %d)"), l, c));
if (orig) {
if (!(orig->_flags & _ISPAD)
if (!IS_PAD(orig)
|| ((win = derwin(orig, l, c, begy, begx)) == NULL))
returnWin(0);
}
@ -96,10 +108,14 @@ prefresh(WINDOW *win,
int smaxrow,
int smaxcol)
{
#if NCURSES_SP_FUNCS
SCREEN *sp = _nc_screen_of(win);
#endif
T((T_CALLED("prefresh()")));
if (pnoutrefresh(win, pminrow, pmincol, sminrow, smincol, smaxrow,
smaxcol) != ERR
&& doupdate() != ERR) {
&& NCURSES_SP_NAME(doupdate) (NCURSES_SP_ARG) != ERR) {
returnCode(OK);
}
returnCode(ERR);
@ -114,10 +130,11 @@ pnoutrefresh(WINDOW *win,
int smaxrow,
int smaxcol)
{
NCURSES_SIZE_T i, j;
NCURSES_SIZE_T m, n;
NCURSES_SIZE_T pmaxrow;
NCURSES_SIZE_T pmaxcol;
int i, j;
int m, n;
int pmaxrow;
int pmaxcol;
SCREEN *sp;
#if USE_SCROLL_HINTS
const int my_len = 2; /* parameterize the threshold for hardscroll */
@ -126,14 +143,16 @@ pnoutrefresh(WINDOW *win,
#endif
T((T_CALLED("pnoutrefresh(%p, %d, %d, %d, %d, %d, %d)"),
win, pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol));
(void *) win, pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol));
if (win == 0)
returnCode(ERR);
if (!(win->_flags & _ISPAD))
if (!IS_PAD(win))
returnCode(ERR);
sp = _nc_screen_of(win);
/* negative values are interpreted as zero */
if (pminrow < 0)
pminrow = 0;
@ -164,14 +183,20 @@ pnoutrefresh(WINDOW *win,
pmaxcol = pmincol + smaxcol - smincol;
}
if (smaxrow >= screen_lines
|| smaxcol >= screen_columns
if (smaxrow >= screen_lines(sp)
|| smaxcol >= screen_columns(sp)
|| sminrow > smaxrow
|| smincol > smaxcol)
returnCode(ERR);
T(("pad being refreshed"));
#ifdef TRACE
if (USE_TRACEF(TRACE_UPDATE)) {
_tracedump("...pad", win);
_nc_unlock_global(tracef);
}
#endif /* TRACE */
#if USE_SCROLL_HINTS
if (win->_pad._pad_y >= 0) {
displaced = pminrow - win->_pad._pad_y
@ -196,13 +221,13 @@ pnoutrefresh(WINDOW *win,
* merely change the costs of various update cases.
*/
#if USE_SCROLL_HINTS
wide = (smincol < my_len && smaxcol > (newscr->_maxx - my_len));
wide = (smincol < my_len && smaxcol > (NewScreen(sp)->_maxx - my_len));
#endif
for (i = pminrow, m = sminrow + win->_yoffset;
i <= pmaxrow && m <= newscr->_maxy;
i <= pmaxrow && m <= NewScreen(sp)->_maxy;
i++, m++) {
register struct ldat *nline = &newscr->_line[m];
register struct ldat *nline = &NewScreen(sp)->_line[m];
register struct ldat *oline = &win->_line[i];
for (j = pmincol, n = smincol; j <= pmaxcol; j++, n++) {
NCURSES_CH_T ch = oline->text[j];
@ -231,9 +256,9 @@ pnoutrefresh(WINDOW *win,
|| nind > smaxrow) {
nind = _NEWINDEX;
} else if (displaced) {
register struct ldat *pline = &curscr->_line[nind];
register struct ldat *pline = &CurScreen(sp)->_line[nind];
for (j = 0; j <= my_len; j++) {
int k = newscr->_maxx - j;
int k = NewScreen(sp)->_maxx - j;
if (pline->text[j] != nline->text[j]
|| pline->text[k] != nline->text[k]) {
nind = _NEWINDEX;
@ -263,27 +288,29 @@ pnoutrefresh(WINDOW *win,
win->_line[i].oldindex = _NEWINDEX;
#endif
win->_begx = smincol;
win->_begy = sminrow;
win->_begx = (NCURSES_SIZE_T) smincol;
win->_begy = (NCURSES_SIZE_T) sminrow;
if (win->_clear) {
win->_clear = FALSE;
newscr->_clear = TRUE;
NewScreen(sp)->_clear = TRUE;
}
/*
* Use the pad's current position, if it will be visible.
* If not, don't do anything; it's not an error.
* If not, don't do anything; it is not an error.
*/
if (win->_leaveok == FALSE
&& win->_cury >= pminrow
&& win->_curx >= pmincol
&& win->_cury <= pmaxrow
&& win->_curx <= pmaxcol) {
newscr->_cury = win->_cury - pminrow + win->_begy + win->_yoffset;
newscr->_curx = win->_curx - pmincol + win->_begx;
NewScreen(sp)->_cury = (NCURSES_SIZE_T) (win->_cury - pminrow
+ win->_begy + win->_yoffset);
NewScreen(sp)->_curx = (NCURSES_SIZE_T) (win->_curx - pmincol
+ win->_begx);
}
newscr->_leaveok = win->_leaveok;
NewScreen(sp)->_leaveok = win->_leaveok;
win->_flags &= ~_HASMOVED;
/*
@ -291,12 +318,12 @@ pnoutrefresh(WINDOW *win,
* We will use this on subsequent calls to this function to derive
* values to stuff into 'oldindex[]' -- for scrolling optimization.
*/
win->_pad._pad_y = pminrow;
win->_pad._pad_x = pmincol;
win->_pad._pad_top = sminrow;
win->_pad._pad_left = smincol;
win->_pad._pad_bottom = smaxrow;
win->_pad._pad_right = smaxcol;
win->_pad._pad_y = (NCURSES_SIZE_T) pminrow;
win->_pad._pad_x = (NCURSES_SIZE_T) pmincol;
win->_pad._pad_top = (NCURSES_SIZE_T) sminrow;
win->_pad._pad_left = (NCURSES_SIZE_T) smincol;
win->_pad._pad_bottom = (NCURSES_SIZE_T) smaxrow;
win->_pad._pad_right = (NCURSES_SIZE_T) smaxcol;
returnCode(OK);
}
@ -304,12 +331,12 @@ pnoutrefresh(WINDOW *win,
NCURSES_EXPORT(int)
pechochar(WINDOW *pad, const chtype ch)
{
T((T_CALLED("pechochar(%p, %s)"), pad, _tracechtype(ch)));
T((T_CALLED("pechochar(%p, %s)"), (void *) pad, _tracechtype(ch)));
if (pad == 0)
returnCode(ERR);
if (!(pad->_flags & _ISPAD))
if (!IS_PAD(pad))
returnCode(wechochar(pad, ch));
waddch(pad, ch);

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_printw.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_printw.c,v 1.4 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2003,2005 Free Software Foundation, Inc. *
* Copyright 2018-2019,2020 Thomas E. Dickey *
* Copyright 1998-2012,2016 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 +30,7 @@
****************************************************************************/
/****************************************************************************
* Author: Thomas E. Dickey <dickey@clark.net> 1997 *
* Author: Thomas E. Dickey 1997-on *
****************************************************************************/
/*
@ -41,85 +42,91 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_printw.c,v 1.3 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_printw.c,v 1.4 2023/10/17 09:52:08 nicm Exp $")
NCURSES_EXPORT(int)
printw(const char *fmt,...)
printw(const char *fmt, ...)
{
va_list argp;
int code;
#ifdef TRACE
va_start(argp, fmt);
va_list argq;
va_start(argq, fmt);
T((T_CALLED("printw(%s%s)"),
_nc_visbuf(fmt), _nc_varargs(fmt, argp)));
va_end(argp);
_nc_visbuf(fmt), _nc_varargs(fmt, argq)));
va_end(argq);
#endif
va_start(argp, fmt);
code = vwprintw(stdscr, fmt, argp);
code = vw_printw(stdscr, fmt, argp);
va_end(argp);
returnCode(code);
}
NCURSES_EXPORT(int)
wprintw(WINDOW *win, const char *fmt,...)
wprintw(WINDOW *win, const char *fmt, ...)
{
va_list argp;
int code;
#ifdef TRACE
va_start(argp, fmt);
va_list argq;
va_start(argq, fmt);
T((T_CALLED("wprintw(%p,%s%s)"),
win, _nc_visbuf(fmt), _nc_varargs(fmt, argp)));
va_end(argp);
(void *) win, _nc_visbuf(fmt), _nc_varargs(fmt, argq)));
va_end(argq);
#endif
va_start(argp, fmt);
code = vwprintw(win, fmt, argp);
code = vw_printw(win, fmt, argp);
va_end(argp);
returnCode(code);
}
NCURSES_EXPORT(int)
mvprintw(int y, int x, const char *fmt,...)
mvprintw(int y, int x, const char *fmt, ...)
{
va_list argp;
int code;
#ifdef TRACE
va_start(argp, fmt);
va_list argq;
va_start(argq, fmt);
T((T_CALLED("mvprintw(%d,%d,%s%s)"),
y, x, _nc_visbuf(fmt), _nc_varargs(fmt, argp)));
va_end(argp);
y, x, _nc_visbuf(fmt), _nc_varargs(fmt, argq)));
va_end(argq);
#endif
if ((code = move(y, x)) != ERR) {
va_list argp;
va_start(argp, fmt);
code = vwprintw(stdscr, fmt, argp);
code = vw_printw(stdscr, fmt, argp);
va_end(argp);
}
returnCode(code);
}
NCURSES_EXPORT(int)
mvwprintw(WINDOW *win, int y, int x, const char *fmt,...)
mvwprintw(WINDOW *win, int y, int x, const char *fmt, ...)
{
va_list argp;
int code;
#ifdef TRACE
va_start(argp, fmt);
va_list argq;
va_start(argq, fmt);
T((T_CALLED("mvwprintw(%d,%d,%p,%s%s)"),
y, x, win, _nc_visbuf(fmt), _nc_varargs(fmt, argp)));
va_end(argp);
y, x, (void *) win, _nc_visbuf(fmt), _nc_varargs(fmt, argq)));
va_end(argq);
#endif
if ((code = wmove(win, y, x)) != ERR) {
va_list argp;
va_start(argp, fmt);
code = vwprintw(win, fmt, argp);
code = vw_printw(win, fmt, argp);
va_end(argp);
}
returnCode(code);
@ -130,10 +137,32 @@ vwprintw(WINDOW *win, const char *fmt, va_list argp)
{
char *buf;
int code = ERR;
#if NCURSES_SP_FUNCS
SCREEN *sp = _nc_screen_of(win);
#endif
T((T_CALLED("vwprintw(%p,%s,va_list)"), win, _nc_visbuf(fmt)));
T((T_CALLED("vwprintw(%p,%s,va_list)"), (void *) win, _nc_visbuf(fmt)));
if ((buf = _nc_printf_string(fmt, argp)) != 0) {
buf = NCURSES_SP_NAME(_nc_printf_string) (NCURSES_SP_ARGx fmt, argp);
if (buf != 0) {
code = waddstr(win, buf);
}
returnCode(code);
}
NCURSES_EXPORT(int)
vw_printw(WINDOW *win, const char *fmt, va_list argp)
{
char *buf;
int code = ERR;
#if NCURSES_SP_FUNCS
SCREEN *sp = _nc_screen_of(win);
#endif
T((T_CALLED("vw_printw(%p,%s,va_list)"), (void *) win, _nc_visbuf(fmt)));
buf = NCURSES_SP_NAME(_nc_printf_string) (NCURSES_SP_ARGx fmt, argp);
if (buf != 0) {
code = waddstr(win, buf);
}
returnCode(code);

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_redrawln.c,v 1.4 2019/11/15 14:45:37 fcambus Exp $ */
/* $OpenBSD: lib_redrawln.c,v 1.5 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2009,2010 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 +42,7 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_redrawln.c,v 1.4 2019/11/15 14:45:37 fcambus Exp $")
MODULE_ID("$Id: lib_redrawln.c,v 1.5 2023/10/17 09:52:08 nicm Exp $")
NCURSES_EXPORT(int)
wredrawln(WINDOW *win, int beg, int num)
@ -49,37 +50,40 @@ wredrawln(WINDOW *win, int beg, int num)
int i;
int end;
size_t len;
SCREEN *sp;
T((T_CALLED("wredrawln(%p,%d,%d)"), win, beg, num));
T((T_CALLED("wredrawln(%p,%d,%d)"), (void *) win, beg, num));
if (win == 0)
returnCode(ERR);
sp = _nc_screen_of(win);
if (beg < 0)
beg = 0;
if (touchline(win, beg, num) == ERR)
returnCode(ERR);
if (touchline(curscr, beg + win->_begy, num) == ERR)
if (touchline(CurScreen(sp), beg + win->_begy, num) == ERR)
returnCode(ERR);
end = beg + num;
if (end > curscr->_maxy + 1 - win->_begy)
end = curscr->_maxy + 1 - win->_begy;
if (end > CurScreen(sp)->_maxy + 1 - win->_begy)
end = CurScreen(sp)->_maxy + 1 - win->_begy;
if (end > win->_maxy + 1)
end = win->_maxy + 1;
len = (win->_maxx + 1);
if (len > (size_t) (curscr->_maxx + 1 - win->_begx))
len = (size_t) (curscr->_maxx + 1 - win->_begx);
len *= sizeof(curscr->_line[0].text[0]);
len = (size_t) (win->_maxx + 1);
if (len > (size_t) (CurScreen(sp)->_maxx + 1 - win->_begx))
len = (size_t) (CurScreen(sp)->_maxx + 1 - win->_begx);
len *= sizeof(CurScreen(sp)->_line[0].text[0]);
for (i = beg; i < end; i++) {
int crow = i + win->_begy;
memset(curscr->_line[crow].text + win->_begx, 0, len);
_nc_make_oldhash(crow);
memset(CurScreen(sp)->_line[crow].text + win->_begx, 0, len);
NCURSES_SP_NAME(_nc_make_oldhash) (NCURSES_SP_ARGx crow);
}
returnCode(OK);

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_refresh.c,v 1.5 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_refresh.c,v 1.6 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. *
* Copyright 2020-2021,2023 Thomas E. Dickey *
* Copyright 1998-2010,2011 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,6 +33,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 *
* and: Juergen Pfeifer *
****************************************************************************/
/*
@ -43,24 +45,27 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_refresh.c,v 1.5 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_refresh.c,v 1.6 2023/10/17 09:52:08 nicm Exp $")
NCURSES_EXPORT(int)
wrefresh(WINDOW *win)
{
int code;
#if NCURSES_SP_FUNCS
SCREEN *SP_PARM = _nc_screen_of(win);
#endif
T((T_CALLED("wrefresh(%p)"), win));
T((T_CALLED("wrefresh(%p)"), (void *) win));
if (win == 0) {
code = ERR;
} else if (win == curscr) {
curscr->_clear = TRUE;
code = doupdate();
} else if (win == CurScreen(SP_PARM)) {
CurScreen(SP_PARM)->_clear = TRUE;
code = NCURSES_SP_NAME(doupdate) (NCURSES_SP_ARG);
} else if ((code = wnoutrefresh(win)) == OK) {
if (win->_clear)
newscr->_clear = TRUE;
code = doupdate();
NewScreen(SP_PARM)->_clear = TRUE;
code = NCURSES_SP_NAME(doupdate) (NCURSES_SP_ARG);
/*
* Reset the clearok() flag in case it was set for the special
* case in hardscroll.c (if we don't reset it here, we'll get 2
@ -75,16 +80,35 @@ wrefresh(WINDOW *win)
NCURSES_EXPORT(int)
wnoutrefresh(WINDOW *win)
{
NCURSES_SIZE_T limit_x;
NCURSES_SIZE_T src_row, src_col;
NCURSES_SIZE_T begx;
NCURSES_SIZE_T begy;
NCURSES_SIZE_T dst_row, dst_col;
int limit_x;
int src_row, src_col;
int begx;
int begy;
int dst_row, dst_col;
#if USE_SCROLL_HINTS
bool wide;
#endif
#if NCURSES_SP_FUNCS
SCREEN *SP_PARM = _nc_screen_of(win);
#endif
T((T_CALLED("wnoutrefresh(%p)"), win));
T((T_CALLED("wnoutrefresh(%p)"), (void *) win));
if (win == NULL)
returnCode(ERR);
/*
* Handle pads as a special case.
*/
if (IS_PAD(win)) {
returnCode(pnoutrefresh(win,
win->_pad._pad_y,
win->_pad._pad_x,
win->_pad._pad_top,
win->_pad._pad_left,
win->_pad._pad_bottom,
win->_pad._pad_right));
}
#ifdef TRACE
if (USE_TRACEF(TRACE_UPDATE)) {
_tracedump("...win", win);
@ -92,19 +116,12 @@ wnoutrefresh(WINDOW *win)
}
#endif /* TRACE */
/*
* This function will break badly if we try to refresh a pad.
*/
if ((win == 0)
|| (win->_flags & _ISPAD))
returnCode(ERR);
/* put them here so "win == 0" won't break our code */
begx = win->_begx;
begy = win->_begy;
newscr->_nc_bkgd = win->_nc_bkgd;
WINDOW_ATTRS(newscr) = WINDOW_ATTRS(win);
NewScreen(SP_PARM)->_nc_bkgd = win->_nc_bkgd;
WINDOW_ATTRS(NewScreen(SP_PARM)) = WINDOW_ATTRS(win);
/* merge in change information from all subwindows of this window */
wsyncdown(win);
@ -124,7 +141,7 @@ wnoutrefresh(WINDOW *win)
* windows). Note that changing this formula will not break any code,
* merely change the costs of various update cases.
*/
wide = (begx <= 1 && win->_maxx >= (newscr->_maxx - 1));
wide = (begx <= 1 && win->_maxx >= (NewScreen(SP_PARM)->_maxx - 1));
#endif
win->_flags &= ~_HASMOVED;
@ -139,14 +156,14 @@ wnoutrefresh(WINDOW *win)
/* limit(dst_col) */
limit_x = win->_maxx;
/* limit(src_col) */
if (limit_x > newscr->_maxx - begx)
limit_x = newscr->_maxx - begx;
if (limit_x > NewScreen(SP_PARM)->_maxx - begx)
limit_x = NewScreen(SP_PARM)->_maxx - begx;
for (src_row = 0, dst_row = begy + win->_yoffset;
src_row <= win->_maxy && dst_row <= newscr->_maxy;
src_row <= win->_maxy && dst_row <= NewScreen(SP_PARM)->_maxy;
src_row++, dst_row++) {
register struct ldat *nline = &newscr->_line[dst_row];
register struct ldat *oline = &win->_line[src_row];
struct ldat *nline = &(NewScreen(SP_PARM)->_line[dst_row]);
struct ldat *oline = &win->_line[src_row];
if (oline->firstchar != _NOCHANGE) {
int last_src = oline->lastchar;
@ -158,7 +175,7 @@ wnoutrefresh(WINDOW *win)
dst_col = src_col + begx;
if_WIDEC({
register int j;
int j;
/*
* Ensure that we will copy complete multi-column characters
@ -193,13 +210,12 @@ wnoutrefresh(WINDOW *win)
});
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;
int j;
/*
* Check for boundary cases where we may overwrite part of a
@ -227,7 +243,8 @@ wnoutrefresh(WINDOW *win)
* this character. Find the end of the character.
*/
++j;
while (j <= newscr->_maxx && isWidecExt(nline->text[j])) {
while (j <= NewScreen(SP_PARM)->_maxx &&
isWidecExt(nline->text[j])) {
fix_right = j++;
}
}
@ -238,6 +255,7 @@ wnoutrefresh(WINDOW *win)
*/
if (fix_left < dst_col || fix_right > last_dst) {
for (j = fix_left; j <= fix_right; ++j) {
static cchar_t blank = BLANK;
nline->text[j] = blank;
CHANGED_CELL(nline, j);
}
@ -271,18 +289,19 @@ wnoutrefresh(WINDOW *win)
if (win->_clear) {
win->_clear = FALSE;
newscr->_clear = TRUE;
NewScreen(SP_PARM)->_clear = TRUE;
}
if (!win->_leaveok) {
newscr->_cury = win->_cury + win->_begy + win->_yoffset;
newscr->_curx = win->_curx + win->_begx;
NewScreen(SP_PARM)->_cury = (NCURSES_SIZE_T) (win->_cury +
win->_begy + win->_yoffset);
NewScreen(SP_PARM)->_curx = (NCURSES_SIZE_T) (win->_curx + win->_begx);
}
newscr->_leaveok = win->_leaveok;
NewScreen(SP_PARM)->_leaveok = win->_leaveok;
#ifdef TRACE
if (USE_TRACEF(TRACE_UPDATE)) {
_tracedump("newscr", newscr);
_tracedump("newscr", NewScreen(SP_PARM));
_nc_unlock_global(tracef);
}
#endif /* TRACE */

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_restart.c,v 1.5 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_restart.c,v 1.6 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
* Copyright 2020,2023 Thomas E. Dickey *
* Copyright 1998-2012,2015 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,6 +33,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 *
* and: Juergen Pfeifer 2008 *
****************************************************************************/
/*
@ -42,53 +44,60 @@
#include <curses.priv.h>
#if SVR4_TERMIO && !defined(_POSIX_SOURCE)
#define _POSIX_SOURCE
#endif
#include <term.h> /* lines, columns, cur_term */
MODULE_ID("$Id: lib_restart.c,v 1.5 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_restart.c,v 1.6 2023/10/17 09:52:09 nicm Exp $")
NCURSES_EXPORT(int)
restartterm(NCURSES_CONST char *termp, int filenum, int *errret)
NCURSES_SP_NAME(restartterm) (NCURSES_SP_DCLx
NCURSES_CONST char *termp,
int filenum,
int *errret)
{
int result;
#ifdef USE_TERM_DRIVER
TERMINAL *new_term = 0;
#endif
T((T_CALLED("restartterm(%s,%d,%p)"), termp, filenum, errret));
START_TRACE();
T((T_CALLED("restartterm(%p,%s,%d,%p)"),
(void *) SP_PARM,
termp,
filenum,
(void *) errret));
if (setupterm(termp, filenum, errret) != OK) {
if (TINFO_SETUP_TERM(&new_term, termp, filenum, errret, FALSE) != OK) {
result = ERR;
} else if (SP != 0) {
int saveecho = SP->_echo;
int savecbreak = SP->_cbreak;
int saveraw = SP->_raw;
int savenl = SP->_nl;
} else if (SP_PARM != 0) {
TTY_FLAGS save_flags = SP_PARM->_tty_flags;
if (saveecho)
echo();
else
noecho();
if (savecbreak) {
cbreak();
noraw();
} else if (saveraw) {
nocbreak();
raw();
#ifdef USE_TERM_DRIVER
SP_PARM->_term = new_term;
#endif
if (save_flags._echo) {
NCURSES_SP_NAME(echo) (NCURSES_SP_ARG);
} else {
nocbreak();
noraw();
NCURSES_SP_NAME(noecho) (NCURSES_SP_ARG);
}
if (savenl)
nl();
else
nonl();
reset_prog_mode();
if (save_flags._cbreak) {
NCURSES_SP_NAME(cbreak) (NCURSES_SP_ARG);
NCURSES_SP_NAME(noraw) (NCURSES_SP_ARG);
} else if (save_flags._raw) {
NCURSES_SP_NAME(nocbreak) (NCURSES_SP_ARG);
NCURSES_SP_NAME(raw) (NCURSES_SP_ARG);
} else {
NCURSES_SP_NAME(nocbreak) (NCURSES_SP_ARG);
NCURSES_SP_NAME(noraw) (NCURSES_SP_ARG);
}
if (save_flags._nl) {
NCURSES_SP_NAME(nl) (NCURSES_SP_ARG);
} else {
NCURSES_SP_NAME(nonl) (NCURSES_SP_ARG);
}
NCURSES_SP_NAME(reset_prog_mode) (NCURSES_SP_ARG);
#if USE_SIZECHANGE
_nc_update_screensize(SP);
_nc_update_screensize(SP_PARM);
#endif
result = OK;
@ -97,3 +106,12 @@ restartterm(NCURSES_CONST char *termp, int filenum, int *errret)
}
returnCode(result);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
restartterm(NCURSES_CONST char *termp, int filenum, int *errret)
{
START_TRACE();
return NCURSES_SP_NAME(restartterm) (CURRENT_SCREEN, termp, filenum, errret);
}
#endif

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_scanw.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_scanw.c,v 1.4 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. *
* Copyright 2018-2019,2020 Thomas E. Dickey *
* Copyright 1998-2009,2011 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,21 +43,40 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_scanw.c,v 1.3 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_scanw.c,v 1.4 2023/10/17 09:52:09 nicm Exp $")
NCURSES_EXPORT(int)
vwscanw(WINDOW *win, NCURSES_CONST char *fmt, va_list argp)
vwscanw(WINDOW *win, const char *fmt, va_list argp)
{
char buf[BUFSIZ];
int code = ERR;
if (wgetnstr(win, buf, sizeof(buf) - 1) == ERR)
return (ERR);
if (wgetnstr(win, buf, (int) sizeof(buf) - 1) != ERR) {
if ((code = vsscanf(buf, fmt, argp)) == EOF) {
code = ERR;
}
}
return (vsscanf(buf, fmt, argp));
return code;
}
NCURSES_EXPORT(int)
scanw(NCURSES_CONST char *fmt,...)
vw_scanw(WINDOW *win, const char *fmt, va_list argp)
{
char buf[BUFSIZ];
int code = ERR;
if (wgetnstr(win, buf, (int) sizeof(buf) - 1) != ERR) {
if ((code = vsscanf(buf, fmt, argp)) == EOF) {
code = ERR;
}
}
return code;
}
NCURSES_EXPORT(int)
scanw(const char *fmt, ...)
{
int code;
va_list ap;
@ -64,45 +84,45 @@ scanw(NCURSES_CONST char *fmt,...)
T(("scanw(\"%s\",...) called", fmt));
va_start(ap, fmt);
code = vwscanw(stdscr, fmt, ap);
code = vw_scanw(stdscr, fmt, ap);
va_end(ap);
return (code);
}
NCURSES_EXPORT(int)
wscanw(WINDOW *win, NCURSES_CONST char *fmt,...)
wscanw(WINDOW *win, const char *fmt, ...)
{
int code;
va_list ap;
T(("wscanw(%p,\"%s\",...) called", win, fmt));
T(("wscanw(%p,\"%s\",...) called", (void *) win, fmt));
va_start(ap, fmt);
code = vwscanw(win, fmt, ap);
code = vw_scanw(win, fmt, ap);
va_end(ap);
return (code);
}
NCURSES_EXPORT(int)
mvscanw(int y, int x, NCURSES_CONST char *fmt,...)
mvscanw(int y, int x, const char *fmt, ...)
{
int code;
va_list ap;
va_start(ap, fmt);
code = (move(y, x) == OK) ? vwscanw(stdscr, fmt, ap) : ERR;
code = (move(y, x) == OK) ? vw_scanw(stdscr, fmt, ap) : ERR;
va_end(ap);
return (code);
}
NCURSES_EXPORT(int)
mvwscanw(WINDOW *win, int y, int x, NCURSES_CONST char *fmt,...)
mvwscanw(WINDOW *win, int y, int x, const char *fmt, ...)
{
int code;
va_list ap;
va_start(ap, fmt);
code = (wmove(win, y, x) == OK) ? vwscanw(win, fmt, ap) : ERR;
code = (wmove(win, y, x) == OK) ? vw_scanw(win, fmt, ap) : ERR;
va_end(ap);
return (code);
}

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_scroll.c,v 1.4 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_scroll.c,v 1.5 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2004,2006 Free Software Foundation, Inc. *
* Copyright 2019,2020 Thomas E. Dickey *
* Copyright 1998-2010,2011 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 *
@ -45,22 +46,22 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_scroll.c,v 1.4 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_scroll.c,v 1.5 2023/10/17 09:52:09 nicm Exp $")
NCURSES_EXPORT(void)
_nc_scroll_window(WINDOW *win,
int const n,
NCURSES_SIZE_T const top,
NCURSES_SIZE_T const bottom,
int const top,
int const bottom,
NCURSES_CH_T blank)
{
int limit;
int line;
int j;
size_t to_copy = (size_t) (sizeof(NCURSES_CH_T) * (win->_maxx + 1));
size_t to_copy = (sizeof(NCURSES_CH_T) * (size_t) (win->_maxx + 1));
TR(TRACE_MOVE, ("_nc_scroll_window(%p, %d, %ld, %ld)",
win, n, (long) top, (long) bottom));
(void *) win, n, (long) top, (long) bottom));
if (top < 0
|| bottom < top
@ -79,11 +80,13 @@ _nc_scroll_window(WINDOW *win,
* setup cost. So there is no point in trying to be excessively
* clever -- esr.
*/
#define BottomLimit(n) ((n) >= 0 && (n) >= top)
#define TopLimit(n) ((n) <= win->_maxy && (n) <= bottom)
/* shift n lines downwards */
if (n < 0) {
limit = top - n;
for (line = bottom; line >= limit && line >= 0; line--) {
for (line = bottom; line >= limit && BottomLimit(line); line--) {
TR(TRACE_MOVE, ("...copying %d to %d", line + n, line));
memcpy(win->_line[line].text,
win->_line[line + n].text,
@ -91,7 +94,7 @@ _nc_scroll_window(WINDOW *win,
if_USE_SCROLL_HINTS(win->_line[line].oldindex =
win->_line[line + n].oldindex);
}
for (line = top; line < limit && line <= win->_maxy; line++) {
for (line = top; line < limit && TopLimit(line); line++) {
TR(TRACE_MOVE, ("...filling %d", line));
for (j = 0; j <= win->_maxx; j++)
win->_line[line].text[j] = blank;
@ -102,14 +105,14 @@ _nc_scroll_window(WINDOW *win,
/* shift n lines upwards */
if (n > 0) {
limit = bottom - n;
for (line = top; line <= limit && line <= win->_maxy; line++) {
for (line = top; line <= limit && TopLimit(line); 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 > limit && line >= 0; line--) {
for (line = bottom; line > limit && BottomLimit(line); line--) {
for (j = 0; j <= win->_maxx; j++)
win->_line[line].text[j] = blank;
if_USE_SCROLL_HINTS(win->_line[line].oldindex = _NEWINDEX);
@ -137,7 +140,7 @@ _nc_scroll_window(WINDOW *win,
NCURSES_EXPORT(int)
wscrl(WINDOW *win, int n)
{
T((T_CALLED("wscrl(%p,%d)"), win, n));
T((T_CALLED("wscrl(%p,%d)"), (void *) win, n));
if (!win || !win->_scroll) {
TR(TRACE_MOVE, ("...scrollok is false"));

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_scrollok.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_scrollok.c,v 1.4 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998,2000 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2000,2009 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,12 +43,12 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_scrollok.c,v 1.3 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_scrollok.c,v 1.4 2023/10/17 09:52:09 nicm Exp $")
NCURSES_EXPORT(int)
scrollok(WINDOW *win, bool flag)
{
T((T_CALLED("scrollok(%p,%d)"), win, flag));
T((T_CALLED("scrollok(%p,%d)"), (void *) win, flag));
if (win) {
win->_scroll = flag;

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_scrreg.c,v 1.4 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_scrreg.c,v 1.5 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998,2000 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2000,2009 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,12 +43,12 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_scrreg.c,v 1.4 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_scrreg.c,v 1.5 2023/10/17 09:52:09 nicm Exp $")
NCURSES_EXPORT(int)
wsetscrreg(WINDOW *win, int top, int bottom)
{
T((T_CALLED("wsetscrreg(%p,%d,%d)"), win, top, bottom));
T((T_CALLED("wsetscrreg(%p,%d,%d)"), (void *) win, top, bottom));
if (win &&
top >= 0 && top <= win->_maxy &&

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_set_term.c,v 1.14 2021/03/10 20:16:08 millert Exp $ */
/* $OpenBSD: lib_set_term.c,v 1.15 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
* Copyright 2018-2021,2022 Thomas E. Dickey *
* Copyright 1998-2016,2017 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,6 +33,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 *
* and: Juergen Pfeifer 2009 *
****************************************************************************/
/*
@ -41,12 +43,31 @@
**
*/
#define NEW_PAIR_INTERNAL 1
#include <curses.priv.h>
#include <term.h> /* cur_term */
#include <tic.h>
#include <new_pair.h>
MODULE_ID("$Id: lib_set_term.c,v 1.14 2021/03/10 20:16:08 millert Exp $")
#if USE_GPM_SUPPORT
#ifdef HAVE_LIBDL
/* use dynamic loader to avoid linkage dependency */
#include <dlfcn.h>
#endif
#endif
#undef CUR
#define CUR SP_TERMTYPE
MODULE_ID("$Id: lib_set_term.c,v 1.15 2023/10/17 09:52:09 nicm Exp $")
#ifdef USE_TERM_DRIVER
#define MaxColors InfoOf(sp).maxcolors
#define NumLabels InfoOf(sp).numlabels
#else
#define MaxColors max_colors
#define NumLabels num_labels
#endif
NCURSES_EXPORT(SCREEN *)
set_term(SCREEN *screenp)
@ -54,25 +75,25 @@ set_term(SCREEN *screenp)
SCREEN *oldSP;
SCREEN *newSP;
T((T_CALLED("set_term(%p)"), screenp));
T((T_CALLED("set_term(%p)"), (void *) screenp));
_nc_lock_global(curses);
oldSP = SP;
oldSP = CURRENT_SCREEN;
_nc_set_screen(screenp);
newSP = SP;
newSP = screenp;
if (newSP != 0) {
set_curterm(newSP->_term);
TINFO_SET_CURTERM(newSP, newSP->_term);
#if !USE_REENTRANT
curscr = newSP->_curscr;
newscr = newSP->_newscr;
stdscr = newSP->_stdscr;
curscr = CurScreen(newSP);
newscr = NewScreen(newSP);
stdscr = StdScreen(newSP);
COLORS = newSP->_color_count;
COLOR_PAIRS = newSP->_pair_count;
#endif
} else {
set_curterm(0);
TINFO_SET_CURTERM(oldSP, 0);
#if !USE_REENTRANT
curscr = 0;
newscr = 0;
@ -84,7 +105,7 @@ set_term(SCREEN *screenp)
_nc_unlock_global(curses);
T((T_RETURN("%p"), oldSP));
T((T_RETURN("%p"), (void *) oldSP));
return (oldSP);
}
@ -108,7 +129,7 @@ delink_screen(SCREEN *sp)
for (each_screen(temp)) {
if (temp == sp) {
if (last)
last = sp->_next_screen;
last->_next_screen = sp->_next_screen;
else
_nc_screen_chain = sp->_next_screen;
result = TRUE;
@ -125,19 +146,41 @@ delink_screen(SCREEN *sp)
NCURSES_EXPORT(void)
delscreen(SCREEN *sp)
{
int i;
T((T_CALLED("delscreen(%p)"), sp));
T((T_CALLED("delscreen(%p)"), (void *) sp));
_nc_lock_global(curses);
if (delink_screen(sp)) {
WINDOWLIST *wl;
bool is_current = (sp == CURRENT_SCREEN);
(void) _nc_freewin(sp->_curscr);
(void) _nc_freewin(sp->_newscr);
(void) _nc_freewin(sp->_stdscr);
#ifdef USE_SP_RIPOFF
if (safe_ripoff_sp && safe_ripoff_sp != safe_ripoff_stack) {
ripoff_t *rop;
for (rop = safe_ripoff_stack;
rop != safe_ripoff_sp && (rop - safe_ripoff_stack) < N_RIPS;
rop++) {
if (rop->win) {
(void) delwin(rop->win);
rop->win = 0;
}
}
}
#endif
/* delete all of the windows in this screen */
rescan:
for (each_window(sp, wl)) {
if (_nc_freewin(&(wl->win)) == OK) {
goto rescan;
}
}
if (sp->_slk != 0) {
if (sp->_slk->ent != 0) {
int i;
for (i = 0; i < sp->_slk->labcnt; ++i) {
FreeIfNeeded(sp->_slk->ent[i].ent_text);
FreeIfNeeded(sp->_slk->ent[i].form_text);
@ -156,9 +199,11 @@ delscreen(SCREEN *sp)
FreeIfNeeded(sp->_current_attr);
_nc_free_ordered_pairs(sp);
FreeIfNeeded(sp->_color_table);
FreeIfNeeded(sp->_color_pairs);
FreeIfNeeded(sp->_oldnum_list);
FreeIfNeeded(sp->oldhash);
FreeIfNeeded(sp->newhash);
FreeIfNeeded(sp->hashtab);
@ -166,19 +211,20 @@ delscreen(SCREEN *sp)
FreeIfNeeded(sp->_acs_map);
FreeIfNeeded(sp->_screen_acs_map);
/*
* 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);
NCURSES_SP_NAME(_nc_flush) (NCURSES_SP_ARG);
NCURSES_SP_NAME(del_curterm) (NCURSES_SP_ARGx sp->_term);
FreeIfNeeded(sp->out_buffer);
if (_nc_find_prescr() == sp) {
_nc_forget_prescr();
}
del_curterm(sp->_term);
#if USE_GPM_SUPPORT
#ifdef HAVE_LIBDL
if (sp->_dlopen_gpm != 0) {
dlclose(sp->_dlopen_gpm);
sp->_dlopen_gpm = 0;
}
#endif
#endif /* USE_GPM_SUPPORT */
free(sp);
/*
@ -186,7 +232,7 @@ delscreen(SCREEN *sp)
* application might try to use (except cur_term, which may have
* multiple references in different screens).
*/
if (sp == SP) {
if (is_current) {
#if !USE_REENTRANT
curscr = 0;
newscr = 0;
@ -195,6 +241,14 @@ delscreen(SCREEN *sp)
COLOR_PAIRS = 0;
#endif
_nc_set_screen(0);
#if USE_WIDEC_SUPPORT
if (SP == 0) {
FreeIfNeeded(_nc_wacs);
_nc_wacs = 0;
}
#endif
} else {
set_term(CURRENT_SCREEN);
}
}
_nc_unlock_global(curses);
@ -231,16 +285,17 @@ no_mouse_wrap(SCREEN *sp GCC_UNUSED)
}
#if NCURSES_EXT_FUNCS && USE_COLORFGBG
static char *
extract_fgbg(char *src, int *result)
static const char *
extract_fgbg(const char *src, int *result)
{
char *dst = 0;
long value = strtol(src, &dst, 0);
const char *dst = 0;
char *tmp = 0;
long value = strtol(src, &tmp, 0);
if (dst == 0) {
if ((dst = tmp) == 0) {
dst = src;
} else if (value >= 0) {
*result = value;
*result = (int) value;
}
while (*dst != 0 && *dst != ';')
dst++;
@ -250,85 +305,155 @@ extract_fgbg(char *src, int *result)
}
#endif
#define ReturnScreenError() do { _nc_set_screen(0); \
returnCode(ERR); } while (0)
/* OS-independent screen initializations */
NCURSES_EXPORT(int)
_nc_setupscreen(int slines GCC_UNUSED,
int scolumns GCC_UNUSED,
FILE *output,
bool filtered,
int slk_format)
NCURSES_SP_NAME(_nc_setupscreen) (
#if NCURSES_SP_FUNCS
SCREEN **spp,
#endif
int slines,
int scolumns,
FILE *output,
int filtered,
int slk_format)
{
#ifndef USE_TERM_DRIVER
static const TTY null_TTY; /* all zeros iff uninitialized */
#endif
char *env;
int bottom_stolen = 0;
SCREEN *sp;
#ifndef USE_TERM_DRIVER
bool support_cookies = USE_XMC_SUPPORT;
ripoff_t *rop;
#endif
T((T_CALLED("_nc_setupscreen(%d, %d, %p, %d, %d)"),
slines, scolumns, output, filtered, slk_format));
slines, scolumns, (void *) output, filtered, slk_format));
assert(SP == 0); /* has been reset in newterm() ! */
assert(CURRENT_SCREEN == 0); /* has been reset in newterm() ! */
#if NCURSES_SP_FUNCS
assert(spp != 0);
sp = *spp;
if (!sp) {
sp = _nc_alloc_screen_sp();
T(("_nc_alloc_screen_sp %p", (void *) sp));
*spp = sp;
}
if (sp == NULL) {
ReturnScreenError();
}
if ((sp->_acs_map = typeCalloc(chtype, ACS_LEN)) == NULL) {
ReturnScreenError();
}
if ((sp->_screen_acs_map = typeCalloc(bool, ACS_LEN)) == NULL) {
free(sp->_acs_map);
ReturnScreenError();
}
T(("created SP %p", (void *) sp));
sp->_next_screen = _nc_screen_chain;
_nc_screen_chain = sp;
if ((sp->_current_attr = typeCalloc(NCURSES_CH_T, 1)) == 0) {
ReturnScreenError();
}
#else
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;
T(("created SP %p", (void *) SP));
if ((SP->_current_attr = typeCalloc(NCURSES_CH_T, 1)) == 0)
sp = SP; /* fixup so SET_LINES and SET_COLS works */
sp->_next_screen = _nc_screen_chain;
_nc_screen_chain = sp;
if ((sp->_current_attr = typeCalloc(NCURSES_CH_T, 1)) == 0) {
returnCode(ERR);
}
#endif
/*
* We should always check the screensize, just in case.
*/
_nc_get_screensize(SP, &slines, &scolumns);
_nc_set_screen(sp);
sp->_term = cur_term;
#ifdef USE_TERM_DRIVER
TCBOf(sp)->csp = sp;
_nc_get_screensize(sp, sp->_term, &slines, &scolumns);
#else
_nc_get_screensize(sp, &slines, &scolumns);
#endif
SET_LINES(slines);
SET_COLS(scolumns);
T((T_CREATE("screen %s %dx%d"), termname(), LINES, COLS));
SP->_filtered = filtered;
T((T_CREATE("screen %s %dx%d"),
NCURSES_SP_NAME(termname) (NCURSES_SP_ARG), slines, scolumns));
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;
#ifdef USE_TERM_DRIVER
CallDriver(sp, td_setfilter);
#else
/* *INDENT-EQLS* */
clear_screen = ABSENT_STRING;
cursor_address = ABSENT_STRING;
cursor_down = ABSENT_STRING;
cursor_up = ABSENT_STRING;
parm_down_cursor = ABSENT_STRING;
parm_up_cursor = ABSENT_STRING;
row_address = ABSENT_STRING;
cursor_home = carriage_return;
cursor_home = carriage_return;
T(("filter screensize %dx%d", LINES, COLS));
if (back_color_erase)
clr_eos = ABSENT_STRING;
#endif
T(("filter screensize %dx%d", slines, scolumns));
}
#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;
SP->_lines_avail = slines;
SP->_columns = scolumns;
SP->_cursrow = -1;
SP->_curscol = -1;
SP->_nl = TRUE;
SP->_raw = FALSE;
SP->_cbreak = 0;
SP->_echo = TRUE;
SP->_fifohead = -1;
SP->_endwin = TRUE;
SP->_ofp = output;
SP->_cursor = -1; /* cannot know real cursor shape */
#if defined(EXP_WIN32_DRIVER)
T(("setting output mode to binary"));
fflush(output);
_setmode(fileno(output), _O_BINARY);
#endif
sp->_lines = (NCURSES_SIZE_T) slines;
sp->_lines_avail = (NCURSES_SIZE_T) slines;
sp->_columns = (NCURSES_SIZE_T) scolumns;
SetNoPadding(SP);
fflush(output);
sp->_ofd = output ? fileno(output) : -1;
sp->_ofp = output;
#if defined(EXP_WIN32_DRIVER)
if (output)
_setmode(fileno(output), _O_BINARY);
#endif
sp->out_limit = (size_t) ((2 + slines) * (6 + scolumns));
if ((sp->out_buffer = malloc(sp->out_limit)) == 0)
sp->out_limit = 0;
sp->out_inuse = 0;
SP_PRE_INIT(sp);
SetNoPadding(sp);
#if NCURSES_EXT_FUNCS
SP->_default_color = FALSE;
SP->_has_sgr_39_49 = FALSE;
sp->_default_color = FALSE;
sp->_has_sgr_39_49 = FALSE;
/*
* Set our assumption of the terminal's default foreground and background
@ -350,11 +475,11 @@ _nc_setupscreen(int slines GCC_UNUSED,
* or black-on-white display under control of the application than not).
*/
#ifdef USE_ASSUMED_COLOR
SP->_default_fg = COLOR_WHITE;
SP->_default_bg = COLOR_BLACK;
sp->_default_fg = COLOR_WHITE;
sp->_default_bg = COLOR_BLACK;
#else
SP->_default_fg = C_MASK;
SP->_default_bg = C_MASK;
sp->_default_fg = COLOR_DEFAULT;
sp->_default_bg = COLOR_DEFAULT;
#endif
/*
@ -366,14 +491,14 @@ _nc_setupscreen(int slines GCC_UNUSED,
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;
sp->_default_fg = ((fg >= 0 && fg < MaxColors) ? fg : COLOR_DEFAULT);
if (count >= 3) {
SP->_default_bg = (bg >= 0 && bg < max_colors) ? bg : C_MASK;
sp->_default_bg = ((bg >= 0 && bg < MaxColors) ? bg : COLOR_DEFAULT);
}
TR(TRACE_CHARPUT | TRACE_MOVE,
("from environment assumed fg=%d, bg=%d",
SP->_default_fg,
SP->_default_bg));
sp->_default_fg,
sp->_default_bg));
}
}
#if USE_COLORFGBG
@ -384,50 +509,53 @@ _nc_setupscreen(int slines GCC_UNUSED,
* decide later if it is worth having default attributes as well.
*/
if (getenv("COLORFGBG") != 0) {
char *p = getenv("COLORFGBG");
const 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));
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));
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) {
sp->_default_fg, sp->_default_bg));
if (sp->_default_fg >= MaxColors) {
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";
set_a_foreground = strdup("\033[3%?%p1%{8}%>%t9%e%p1%d%;m");
} else {
SP->_default_fg %= max_colors;
sp->_default_fg %= MaxColors;
}
}
if (SP->_default_bg >= max_colors) {
if (sp->_default_bg >= MaxColors) {
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";
set_a_background = strdup("\033[4%?%p1%{8}%>%t9%e%p1%d%;m");
} else {
SP->_default_bg %= max_colors;
sp->_default_bg %= MaxColors;
}
}
}
#endif
#endif /* NCURSES_EXT_FUNCS */
SP->_maxclick = DEFAULT_MAXCLICK;
SP->_mouse_event = no_mouse_event;
SP->_mouse_inline = no_mouse_inline;
SP->_mouse_parse = no_mouse_parse;
SP->_mouse_resume = no_mouse_resume;
SP->_mouse_wrap = no_mouse_wrap;
SP->_mouse_fd = -1;
sp->_maxclick = DEFAULT_MAXCLICK;
sp->_mouse_event = no_mouse_event;
sp->_mouse_inline = no_mouse_inline;
sp->_mouse_parse = no_mouse_parse;
sp->_mouse_resume = no_mouse_resume;
sp->_mouse_wrap = no_mouse_wrap;
sp->_mouse_fd = -1;
/*
* 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;
sp->_ok_attributes = NCURSES_SP_NAME(termattrs) (NCURSES_SP_ARG);
if (NCURSES_SP_NAME(has_colors) (NCURSES_SP_ARG)) {
sp->_ok_attributes |= A_COLOR;
}
#ifdef USE_TERM_DRIVER
_nc_cookie_init(sp);
#else
#if USE_XMC_SUPPORT
/*
* If we have no magic-cookie support compiled-in, or if it is suppressed
@ -446,16 +574,7 @@ _nc_setupscreen(int slines GCC_UNUSED,
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_triggers = sp->_ok_attributes & XMC_CONFLICT;
#if 0
/*
* We "should" treat colors as an attribute. The wyse350 (and its
@ -463,12 +582,12 @@ _nc_setupscreen(int slines GCC_UNUSED,
* cookies.
*/
if (has_colors()) {
SP->_xmc_triggers |= A_COLOR;
sp->_xmc_triggers |= A_COLOR;
}
#endif
SP->_xmc_suppress = SP->_xmc_triggers & (chtype) ~(A_BOLD);
sp->_xmc_suppress = sp->_xmc_triggers & (chtype) ~(A_BOLD);
T(("magic cookie attributes %s", _traceattr(SP->_xmc_suppress)));
T(("magic cookie attributes %s", _traceattr(sp->_xmc_suppress)));
/*
* Supporting line-drawing may be possible. But make the regular
* video attributes work first.
@ -508,7 +627,7 @@ _nc_setupscreen(int slines GCC_UNUSED,
/* 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)) {
if (_nc_unicode_locale() && _nc_locale_breaks_acs(sp->_term)) {
acs_chars = NULL;
ena_acs = NULL;
enter_alt_charset_mode = NULL;
@ -516,135 +635,240 @@ _nc_setupscreen(int slines GCC_UNUSED,
set_attributes = NULL;
}
#endif
_nc_init_acs();
#if USE_WIDEC_SUPPORT
_nc_init_wacs();
#endif
SP->_screen_acs_fix = (_nc_unicode_locale()
&& _nc_locale_breaks_acs(cur_term));
NCURSES_SP_NAME(_nc_init_acs) (NCURSES_SP_ARG);
#if USE_WIDEC_SUPPORT
sp->_screen_unicode = _nc_unicode_locale();
if (_nc_wacs == 0) {
_nc_init_wacs();
}
if (_nc_wacs == 0) {
ReturnScreenError();
}
sp->_screen_acs_fix = (sp->_screen_unicode
&& _nc_locale_breaks_acs(sp->_term));
#endif
env = _nc_get_locale();
SP->_legacy_coding = ((env == 0)
sp->_legacy_coding = ((env == 0)
|| !strcmp(env, "C")
|| !strcmp(env, "POSIX"));
T(("legacy-coding %d", SP->_legacy_coding));
T(("legacy-coding %d", sp->_legacy_coding));
_nc_idcok = TRUE;
_nc_idlok = FALSE;
sp->_nc_sp_idcok = TRUE;
sp->_nc_sp_idlok = FALSE;
SP->oldhash = 0;
SP->newhash = 0;
sp->oldhash = 0;
sp->newhash = 0;
T(("creating newscr"));
if ((SP->_newscr = newwin(slines, scolumns, 0, 0)) == 0)
returnCode(ERR);
NewScreen(sp) = NCURSES_SP_NAME(newwin) (NCURSES_SP_ARGx slines, scolumns,
0, 0);
if (NewScreen(sp) == 0) {
ReturnScreenError();
}
T(("creating curscr"));
if ((SP->_curscr = newwin(slines, scolumns, 0, 0)) == 0)
returnCode(ERR);
CurScreen(sp) = NCURSES_SP_NAME(newwin) (NCURSES_SP_ARGx slines, scolumns,
0, 0);
if (CurScreen(sp) == 0) {
ReturnScreenError();
}
#if !USE_REENTRANT
newscr = SP->_newscr;
curscr = SP->_curscr;
newscr = NewScreen(sp);
curscr = CurScreen(sp);
#endif
#if USE_SIZECHANGE
SP->_resize = resizeterm;
SP->_ungetch = _nc_ungetch;
sp->_resize = NCURSES_SP_NAME(resizeterm);
sp->_ungetch = safe_ungetch;
#endif
newscr->_clear = TRUE;
curscr->_clear = FALSE;
NewScreen(sp)->_clear = TRUE;
CurScreen(sp)->_clear = FALSE;
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;
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 {
returnCode(ERR);
}
if (rop->line < 0)
bottom_stolen += count;
else
SP->_topstolen += count;
SP->_lines_avail -= count;
}
/*
* Get the current tty-modes. setupterm() may already have done this,
* unless we use the term-driver.
*/
#ifndef USE_TERM_DRIVER
if (cur_term != 0 &&
!memcmp(&cur_term->Ottyb, &null_TTY, sizeof(TTY)))
#endif
{
NCURSES_SP_NAME(def_shell_mode) (NCURSES_SP_ARG);
NCURSES_SP_NAME(def_prog_mode) (NCURSES_SP_ARG);
}
if (safe_ripoff_sp && safe_ripoff_sp != safe_ripoff_stack) {
ripoff_t *rop;
for (rop = safe_ripoff_stack;
rop != safe_ripoff_sp && (rop - safe_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 (!TerminalOf(sp)) {
continue;
}
if (!(NumLabels <= 0 || !SLK_STDFMT(slk_format))) {
continue;
}
}
if (rop->hook) {
int count;
WINDOW *w;
count = (rop->line < 0) ? -rop->line : rop->line;
T(("ripping off %i lines at %s", count,
((rop->line < 0)
? "bottom"
: "top")));
w = NCURSES_SP_NAME(newwin) (NCURSES_SP_ARGx
count, scolumns,
((rop->line < 0)
? sp->_lines_avail - count
: 0),
0);
if (w) {
rop->win = w;
rop->hook(w, scolumns);
} else {
ReturnScreenError();
}
if (rop->line < 0) {
bottom_stolen += count;
} else {
sp->_topstolen = (NCURSES_SIZE_T) (sp->_topstolen + count);
}
sp->_lines_avail = (NCURSES_SIZE_T) (sp->_lines_avail - count);
}
}
/* reset the stack */
safe_ripoff_sp = safe_ripoff_stack;
}
/* reset the stack */
ripoff_sp = ripoff_stack;
T(("creating stdscr"));
assert((SP->_lines_avail + SP->_topstolen + bottom_stolen) == slines);
if ((SP->_stdscr = newwin(SP->_lines_avail, scolumns, 0, 0)) == 0)
returnCode(ERR);
SET_LINES(SP->_lines_avail);
(void) bottom_stolen;
assert((sp->_lines_avail + sp->_topstolen + bottom_stolen) == slines);
if ((StdScreen(sp) = NCURSES_SP_NAME(newwin) (NCURSES_SP_ARGx
sp->_lines_avail,
scolumns, 0, 0)) == 0) {
ReturnScreenError();
}
SET_LINES(sp->_lines_avail);
#if !USE_REENTRANT
stdscr = SP->_stdscr;
stdscr = StdScreen(sp);
#endif
sp->_prescreen = FALSE;
returnCode(OK);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
_nc_setupscreen(int slines GCC_UNUSED,
int scolumns GCC_UNUSED,
FILE *output,
int filtered,
int slk_format)
{
SCREEN *sp = 0;
int rc = NCURSES_SP_NAME(_nc_setupscreen) (&sp,
slines,
scolumns,
output,
filtered,
slk_format);
if (rc != OK)
_nc_set_screen(0);
return rc;
}
#endif
/*
* 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))
NCURSES_SP_NAME(_nc_ripoffline) (NCURSES_SP_DCLx
int line,
int (*init) (WINDOW *, int))
{
T((T_CALLED("_nc_ripoffline(%d, %p)"), line, init));
int code = ERR;
TR_FUNC_BFR(1);
if (line != 0) {
START_TRACE();
T((T_CALLED("ripoffline(%p,%d,%s)"),
(void *) SP_PARM, line,
TR_FUNC_ARG(0, init)));
if (ripoff_sp == 0)
ripoff_sp = ripoff_stack;
if (ripoff_sp >= ripoff_stack + N_RIPS)
returnCode(ERR);
ripoff_sp->line = line;
ripoff_sp->hook = init;
ripoff_sp++;
#if NCURSES_SP_FUNCS
if (SP_PARM != 0 && SP_PARM->_prescreen)
#endif
{
if (line == 0) {
code = OK;
} else {
if (safe_ripoff_sp == 0) {
safe_ripoff_sp = safe_ripoff_stack;
}
if (safe_ripoff_sp < safe_ripoff_stack + N_RIPS) {
safe_ripoff_sp->line = line;
safe_ripoff_sp->hook = init;
(safe_ripoff_sp)++;
T(("ripped-off %d:%d chunks",
(int) (safe_ripoff_sp - safe_ripoff_stack), N_RIPS));
code = OK;
}
}
}
returnCode(OK);
returnCode(code);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
_nc_ripoffline(int line, int (*init) (WINDOW *, int))
{
int rc;
_nc_init_pthreads();
_nc_lock_global(prescreen);
START_TRACE();
rc = NCURSES_SP_NAME(_nc_ripoffline) (CURRENT_SCREEN_PRE, line, init);
_nc_unlock_global(prescreen);
return rc;
}
#endif
NCURSES_EXPORT(int)
NCURSES_SP_NAME(ripoffline) (NCURSES_SP_DCLx
int line,
int (*init) (WINDOW *, int))
{
START_TRACE();
return NCURSES_SP_NAME(_nc_ripoffline) (NCURSES_SP_ARGx
(line < 0) ? -1 : 1,
init);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
ripoffline(int line, int (*init) (WINDOW *, int))
{
int rc;
_nc_init_pthreads();
_nc_lock_global(prescreen);
START_TRACE();
T((T_CALLED("ripoffline(%d,%p)"), line, init));
rc = NCURSES_SP_NAME(ripoffline) (CURRENT_SCREEN_PRE, line, init);
_nc_unlock_global(prescreen);
if (line == 0)
returnCode(OK);
returnCode(_nc_ripoffline((line < 0) ? -1 : 1, init));
return rc;
}
#endif

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_slk.c,v 1.5 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_slk.c,v 1.6 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2005,2008 Free Software Foundation, Inc. *
* Copyright 2020,2022 Thomas E. Dickey *
* Copyright 1998-2010,2011 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,26 +44,94 @@
*/
#include <curses.priv.h>
#include <ctype.h>
#include <term.h> /* num_labels, label_*, plab_norm */
MODULE_ID("$Id: lib_slk.c,v 1.5 2010/01/12 23:22:06 nicm Exp $")
#ifndef CUR
#define CUR SP_TERMTYPE
#endif
MODULE_ID("$Id: lib_slk.c,v 1.6 2023/10/17 09:52:09 nicm Exp $")
#ifdef USE_TERM_DRIVER
#define NumLabels InfoOf(SP_PARM).numlabels
#define NoColorVideo InfoOf(SP_PARM).nocolorvideo
#define LabelWidth InfoOf(SP_PARM).labelwidth
#define LabelHeight InfoOf(SP_PARM).labelheight
#else
#define NumLabels num_labels
#define NoColorVideo no_color_video
#define LabelWidth label_width
#define LabelHeight label_height
#endif
/*
* Free any memory related to soft labels, return an error.
*/
static int
slk_failed(void)
slk_failed(NCURSES_SP_DCL0)
{
if (SP->_slk) {
FreeIfNeeded(SP->_slk->ent);
free(SP->_slk);
SP->_slk = (SLK *) 0;
if ((0 != SP_PARM) && SP_PARM->_slk) {
FreeIfNeeded(SP_PARM->_slk->ent);
free(SP_PARM->_slk);
SP_PARM->_slk = (SLK *) 0;
}
return ERR;
}
NCURSES_EXPORT(int)
_nc_format_slks(NCURSES_SP_DCLx int cols)
{
int gap, i, x;
int max_length;
if (!SP_PARM || !SP_PARM->_slk)
return ERR;
max_length = SP_PARM->_slk->maxlen;
if (SP_PARM->slk_format >= 3) { /* PC style */
gap = (cols - 3 * (3 + 4 * max_length)) / 2;
if (gap < 1)
gap = 1;
for (i = x = 0; i < SP_PARM->_slk->maxlab; i++) {
SP_PARM->_slk->ent[i].ent_x = x;
x += max_length;
x += (i == 3 || i == 7) ? gap : 1;
}
} else {
if (SP_PARM->slk_format == 2) { /* 4-4 */
gap = cols - (int) (SP_PARM->_slk->maxlab * max_length) - 6;
if (gap < 1)
gap = 1;
for (i = x = 0; i < SP_PARM->_slk->maxlab; i++) {
SP_PARM->_slk->ent[i].ent_x = x;
x += max_length;
x += (i == 3) ? gap : 1;
}
} else {
if (SP_PARM->slk_format == 1) { /* 1 -> 3-2-3 */
gap = (cols - (SP_PARM->_slk->maxlab * max_length) - 5)
/ 2;
if (gap < 1)
gap = 1;
for (i = x = 0; i < SP_PARM->_slk->maxlab; i++) {
SP_PARM->_slk->ent[i].ent_x = x;
x += max_length;
x += (i == 2 || i == 4) ? gap : 1;
}
} else {
return slk_failed(NCURSES_SP_ARG);
}
}
}
SP_PARM->_slk->dirty = TRUE;
return OK;
}
/*
* Initialize soft labels.
* Called from newterm()
@ -70,108 +139,92 @@ slk_failed(void)
NCURSES_EXPORT(int)
_nc_slk_initialize(WINDOW *stwin, int cols)
{
int i, x;
int i;
int res = OK;
unsigned max_length;
size_t max_length;
SCREEN *sp;
int numlab;
T((T_CALLED("_nc_slk_initialize()")));
if (SP->_slk) { /* we did this already, so simply return */
returnCode(OK);
} else if ((SP->_slk = typeCalloc(SLK, 1)) == 0)
assert(stwin);
sp = _nc_screen_of(stwin);
if (0 == sp)
returnCode(ERR);
SP->_slk->ent = NULL;
assert(TerminalOf(SP_PARM));
numlab = NumLabels;
if (SP_PARM->_slk) { /* we did this already, so simply return */
returnCode(OK);
} else if ((SP_PARM->_slk = typeCalloc(SLK, 1)) == 0)
returnCode(ERR);
if (!SP_PARM->slk_format)
SP_PARM->slk_format = _nc_globals.slk_format;
/*
* 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);
if ((NoColorVideo & 1) == 0)
SetAttr(SP_PARM->_slk->attr, A_STANDOUT);
else
SetAttr(SP->_slk->attr, A_REVERSE);
SetAttr(SP_PARM->_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);
SP_PARM->_slk->maxlab = (short) ((numlab > 0)
? numlab
: MAX_SKEY(SP_PARM->slk_format));
SP_PARM->_slk->maxlen = (short) ((numlab > 0)
? LabelWidth * LabelHeight
: MAX_SKEY_LEN(SP_PARM->slk_format));
SP_PARM->_slk->labcnt = (short) ((SP_PARM->_slk->maxlab < MAX_SKEY(SP_PARM->slk_format))
? MAX_SKEY(SP_PARM->slk_format)
: SP_PARM->_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());
if (SP_PARM->_slk->maxlen <= 0
|| SP_PARM->_slk->labcnt <= 0
|| (SP_PARM->_slk->ent = typeCalloc(slk_ent,
(size_t) SP_PARM->_slk->labcnt))
== NULL) {
free(SP_PARM->_slk->ent);
returnCode(slk_failed(NCURSES_SP_ARG));
}
max_length = SP->_slk->maxlen;
for (i = 0; i < SP->_slk->labcnt; i++) {
max_length = (size_t) SP_PARM->_slk->maxlen;
for (i = 0; i < SP_PARM->_slk->labcnt; i++) {
size_t used = max_length + 1;
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);
SP_PARM->_slk->ent[i].ent_text = (char *) _nc_doalloc(0, used);
if (SP_PARM->_slk->ent[i].ent_text == 0)
returnCode(slk_failed(NCURSES_SP_ARG));
memset(SP_PARM->_slk->ent[i].ent_text, 0, used);
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);
SP_PARM->_slk->ent[i].form_text = (char *) _nc_doalloc(0, used);
if (SP_PARM->_slk->ent[i].form_text == 0)
returnCode(slk_failed(NCURSES_SP_ARG));
memset(SP->_slk->ent[i].form_text, ' ', max_length);
SP->_slk->ent[i].visible = (char) (i < SP->_slk->maxlab);
}
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].ent_x = x;
x += max_length;
x += (i == 3 || i == 7) ? gap : 1;
if (used > 1) {
memset(SP_PARM->_slk->ent[i].form_text, ' ', used - 1);
}
} else {
if (_nc_globals.slk_format == 2) { /* 4-4 */
int gap = cols - (SP->_slk->maxlab * max_length) - 6;
SP_PARM->_slk->ent[i].form_text[used - 1] = '\0';
if (gap < 1)
gap = 1;
for (i = x = 0; i < SP->_slk->maxlab; i++) {
SP->_slk->ent[i].ent_x = x;
x += max_length;
x += (i == 3) ? gap : 1;
}
} else {
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].ent_x = x;
x += max_length;
x += (i == 2 || i == 4) ? gap : 1;
}
} else
returnCode(slk_failed());
}
SP_PARM->_slk->ent[i].visible = (char) (i < SP_PARM->_slk->maxlab);
}
SP->_slk->dirty = TRUE;
if ((SP->_slk->win = stwin) == NULL) {
returnCode(slk_failed());
res = _nc_format_slks(NCURSES_SP_ARGx cols);
if ((SP_PARM->_slk->win = stwin) == NULL) {
returnCode(slk_failed(NCURSES_SP_ARG));
}
/* 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_globals.slk_format;
_nc_globals.slk_format = 0;
returnCode(res);
}
@ -180,14 +233,24 @@ _nc_slk_initialize(WINDOW *stwin, int cols)
* Restore the soft labels on the screen.
*/
NCURSES_EXPORT(int)
NCURSES_SP_NAME(slk_restore) (NCURSES_SP_DCL0)
{
T((T_CALLED("slk_restore(%p)"), (void *) SP_PARM));
if (0 == SP_PARM)
returnCode(ERR);
if (SP_PARM->_slk == NULL)
returnCode(ERR);
SP_PARM->_slk->hidden = FALSE;
SP_PARM->_slk->dirty = TRUE;
returnCode(NCURSES_SP_NAME(slk_refresh) (NCURSES_SP_ARG));
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
slk_restore(void)
{
T((T_CALLED("slk_restore()")));
if (SP->_slk == NULL)
return (ERR);
SP->_slk->hidden = FALSE;
SP->_slk->dirty = TRUE;
returnCode(slk_refresh());
return NCURSES_SP_NAME(slk_restore) (CURRENT_SCREEN);
}
#endif

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_slkatr_set.c,v 1.4 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_slkatr_set.c,v 1.5 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2003,2005 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2014,2017 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,7 +31,7 @@
/****************************************************************************
* Author: Juergen Pfeifer, 1998 *
* and: Thomas E. Dickey 2005 *
* and: Thomas E. Dickey 2005-on *
****************************************************************************/
/*
@ -40,22 +41,43 @@
*/
#include <curses.priv.h>
MODULE_ID("$Id: lib_slkatr_set.c,v 1.4 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_slkatr_set.c,v 1.5 2023/10/17 09:52:09 nicm Exp $")
NCURSES_EXPORT(int)
slk_attr_set(const attr_t attr, short color_pair_number, void *opts)
NCURSES_SP_NAME(slk_attr_set) (NCURSES_SP_DCLx
const attr_t attr,
NCURSES_PAIRS_T pair_arg,
void *opts)
{
T((T_CALLED("slk_attr_set(%s,%d)"), _traceattr(attr), color_pair_number));
int code = ERR;
int color_pair = pair_arg;
if (SP != 0 && SP->_slk != 0 && !opts &&
color_pair_number >= 0 && color_pair_number < COLOR_PAIRS) {
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);
T((T_CALLED("slk_attr_set(%p,%s,%d)"),
(void *) SP_PARM,
_traceattr(attr),
color_pair));
set_extended_pair(opts, color_pair);
if (SP_PARM != 0
&& SP_PARM->_slk != 0
&& color_pair >= 0
&& color_pair < SP_PARM->_pair_limit) {
TR(TRACE_ATTRS, ("... current %s", _tracech_t(CHREF(SP_PARM->_slk->attr))));
SetAttr(SP_PARM->_slk->attr, attr);
if (color_pair > 0) {
SetPair(SP_PARM->_slk->attr, color_pair);
}
TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP->_slk->attr))));
returnCode(OK);
} else
returnCode(ERR);
TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP_PARM->_slk->attr))));
code = OK;
}
returnCode(code);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
slk_attr_set(const attr_t attr, NCURSES_COLOR_T pair_arg, void *opts)
{
return NCURSES_SP_NAME(slk_attr_set) (CURRENT_SCREEN, attr,
pair_arg, opts);
}
#endif

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_slkatrof.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_slkatrof.c,v 1.4 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2000,2005 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2005,2009 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,21 +41,29 @@
*/
#include <curses.priv.h>
MODULE_ID("$Id: lib_slkatrof.c,v 1.3 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_slkatrof.c,v 1.4 2023/10/17 09:52:09 nicm Exp $")
NCURSES_EXPORT(int)
slk_attroff(const chtype attr)
NCURSES_SP_NAME(slk_attroff) (NCURSES_SP_DCLx const chtype attr)
{
T((T_CALLED("slk_attroff(%s)"), _traceattr(attr)));
T((T_CALLED("slk_attroff(%p,%s)"), (void *) SP_PARM, _traceattr(attr)));
if (SP != 0 && SP->_slk != 0) {
TR(TRACE_ATTRS, ("... current %s", _tracech_t(CHREF(SP->_slk->attr))));
RemAttr(SP->_slk->attr, attr);
if (SP_PARM != 0 && SP_PARM->_slk != 0) {
TR(TRACE_ATTRS, ("... current %s", _tracech_t(CHREF(SP_PARM->_slk->attr))));
RemAttr(SP_PARM->_slk->attr, attr);
if ((attr & A_COLOR) != 0) {
SetPair(SP->_slk->attr, 0);
SetPair(SP_PARM->_slk->attr, 0);
}
TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP->_slk->attr))));
TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP_PARM->_slk->attr))));
returnCode(OK);
} else
returnCode(ERR);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
slk_attroff(const chtype attr)
{
return NCURSES_SP_NAME(slk_attroff) (CURRENT_SCREEN, attr);
}
#endif

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_slkatron.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_slkatron.c,v 1.4 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2000,2005 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2009,2010 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,21 +41,29 @@
*/
#include <curses.priv.h>
MODULE_ID("$Id: lib_slkatron.c,v 1.3 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_slkatron.c,v 1.4 2023/10/17 09:52:09 nicm Exp $")
NCURSES_EXPORT(int)
slk_attron(const chtype attr)
NCURSES_SP_NAME(slk_attron) (NCURSES_SP_DCLx const chtype attr)
{
T((T_CALLED("slk_attron(%s)"), _traceattr(attr)));
T((T_CALLED("slk_attron(%p,%s)"), (void *) SP_PARM, _traceattr(attr)));
if (SP != 0 && SP->_slk != 0) {
TR(TRACE_ATTRS, ("... current %s", _tracech_t(CHREF(SP->_slk->attr))));
AddAttr(SP->_slk->attr, attr);
if (SP_PARM != 0 && SP_PARM->_slk != 0) {
TR(TRACE_ATTRS, ("... current %s", _tracech_t(CHREF(SP_PARM->_slk->attr))));
AddAttr(SP_PARM->_slk->attr, attr);
if ((attr & A_COLOR) != 0) {
SetPair(SP->_slk->attr, PAIR_NUMBER(attr));
SetPair(SP_PARM->_slk->attr, PairNumber(attr));
}
TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP->_slk->attr))));
TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP_PARM->_slk->attr))));
returnCode(OK);
} else
returnCode(ERR);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
slk_attron(const chtype attr)
{
return NCURSES_SP_NAME(slk_attron) (CURRENT_SCREEN, attr);
}
#endif

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_slkatrset.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_slkatrset.c,v 1.4 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2000,2005 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2005,2009 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,16 +41,24 @@
*/
#include <curses.priv.h>
MODULE_ID("$Id: lib_slkatrset.c,v 1.3 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_slkatrset.c,v 1.4 2023/10/17 09:52:09 nicm Exp $")
NCURSES_EXPORT(int)
slk_attrset(const chtype attr)
NCURSES_SP_NAME(slk_attrset) (NCURSES_SP_DCLx const chtype attr)
{
T((T_CALLED("slk_attrset(%s)"), _traceattr(attr)));
T((T_CALLED("slk_attrset(%p,%s)"), (void *) SP_PARM, _traceattr(attr)));
if (SP != 0 && SP->_slk != 0) {
SetAttr(SP->_slk->attr, attr);
if (SP_PARM != 0 && SP_PARM->_slk != 0) {
SetAttr(SP_PARM->_slk->attr, attr);
returnCode(OK);
} else
returnCode(ERR);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
slk_attrset(const chtype attr)
{
return NCURSES_SP_NAME(slk_attrset) (CURRENT_SCREEN, attr);
}
#endif

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_slkattr.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_slkattr.c,v 1.4 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998,2000 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2009,2010 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,19 +41,27 @@
*/
#include <curses.priv.h>
MODULE_ID("$Id: lib_slkattr.c,v 1.3 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_slkattr.c,v 1.4 2023/10/17 09:52:09 nicm Exp $")
NCURSES_EXPORT(attr_t)
slk_attr(void)
NCURSES_SP_NAME(slk_attr) (NCURSES_SP_DCL0)
{
T((T_CALLED("slk_attr()")));
T((T_CALLED("slk_attr(%p)"), (void *) SP_PARM));
if (SP != 0 && SP->_slk != 0) {
attr_t result = AttrOf(SP->_slk->attr) & ALL_BUT_COLOR;
int pair = GetPair(SP->_slk->attr);
if (SP_PARM != 0 && SP_PARM->_slk != 0) {
attr_t result = AttrOf(SP_PARM->_slk->attr) & ALL_BUT_COLOR;
int pair = GetPair(SP_PARM->_slk->attr);
result |= COLOR_PAIR(pair);
result |= (attr_t) ColorPair(pair);
returnAttr(result);
} else
returnAttr(0);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(attr_t)
slk_attr(void)
{
return NCURSES_SP_NAME(slk_attr) (CURRENT_SCREEN);
}
#endif

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_slkclear.c,v 1.4 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_slkclear.c,v 1.5 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2007,2009 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,27 +43,35 @@
*/
#include <curses.priv.h>
MODULE_ID("$Id: lib_slkclear.c,v 1.4 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_slkclear.c,v 1.5 2023/10/17 09:52:09 nicm Exp $")
NCURSES_EXPORT(int)
slk_clear(void)
NCURSES_SP_NAME(slk_clear) (NCURSES_SP_DCL0)
{
int rc = ERR;
T((T_CALLED("slk_clear()")));
T((T_CALLED("slk_clear(%p)"), (void *) SP_PARM));
if (SP != NULL && SP->_slk != NULL) {
SP->_slk->hidden = TRUE;
if (SP_PARM != 0 && SP_PARM->_slk != 0) {
SP_PARM->_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) {
SP_PARM->_slk->win->_nc_bkgd = StdScreen(SP_PARM)->_nc_bkgd;
WINDOW_ATTRS(SP_PARM->_slk->win) = WINDOW_ATTRS(StdScreen(SP_PARM));
if (SP_PARM->_slk->win == StdScreen(SP_PARM)) {
rc = OK;
} else {
werase(SP->_slk->win);
rc = wrefresh(SP->_slk->win);
werase(SP_PARM->_slk->win);
rc = wrefresh(SP_PARM->_slk->win);
}
}
returnCode(rc);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
slk_clear(void)
{
return NCURSES_SP_NAME(slk_clear) (CURRENT_SCREEN);
}
#endif

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_slkcolor.c,v 1.4 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_slkcolor.c,v 1.5 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2003,2005 Free Software Foundation, Inc. *
* Copyright 2018,2020 Thomas E. Dickey *
* Copyright 1998-2014,2017 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 +30,8 @@
****************************************************************************/
/****************************************************************************
* Author: Juergen Pfeifer, 1998 *
* and: Thomas E. Dickey 2005 *
* Author: Juergen Pfeifer, 1998,2009 *
* and: Thomas E. Dickey 2005-on *
****************************************************************************/
/*
@ -40,19 +41,53 @@
*/
#include <curses.priv.h>
MODULE_ID("$Id: lib_slkcolor.c,v 1.4 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_slkcolor.c,v 1.5 2023/10/17 09:52:09 nicm Exp $")
static int
_nc_slk_color(SCREEN *sp, int pair_arg)
{
int code = ERR;
T((T_CALLED("slk_color(%p,%d)"), (void *) sp, pair_arg));
if (sp != 0
&& sp->_slk != 0
&& pair_arg >= 0
&& pair_arg < sp->_pair_limit) {
TR(TRACE_ATTRS, ("... current is %s", _tracech_t(CHREF(sp->_slk->attr))));
SetPair(sp->_slk->attr, pair_arg);
TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(sp->_slk->attr))));
code = OK;
}
returnCode(code);
}
NCURSES_EXPORT(int)
slk_color(short color_pair_number)
NCURSES_SP_NAME(slk_color) (NCURSES_SP_DCLx NCURSES_PAIRS_T pair_arg)
{
T((T_CALLED("slk_color(%d)"), color_pair_number));
if (SP != 0 && SP->_slk != 0 &&
color_pair_number >= 0 && color_pair_number < COLOR_PAIRS) {
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);
return _nc_slk_color(SP_PARM, pair_arg);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
slk_color(NCURSES_PAIRS_T pair_arg)
{
return NCURSES_SP_NAME(slk_color) (CURRENT_SCREEN, pair_arg);
}
#endif
#if NCURSES_EXT_COLORS
NCURSES_EXPORT(int)
NCURSES_SP_NAME(extended_slk_color) (NCURSES_SP_DCLx int pair_arg)
{
return _nc_slk_color(SP_PARM, pair_arg);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
extended_slk_color(int pair_arg)
{
return NCURSES_SP_NAME(extended_slk_color) (CURRENT_SCREEN, pair_arg);
}
#endif
#endif

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_slkinit.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_slkinit.c,v 1.4 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
* Copyright 2020,2022 Thomas E. Dickey *
* Copyright 1998-2009,2017 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,6 +33,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 *
* and: Juergen Pfeifer 2009 *
****************************************************************************/
/*
@ -41,17 +43,49 @@
*/
#include <curses.priv.h>
MODULE_ID("$Id: lib_slkinit.c,v 1.3 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_slkinit.c,v 1.4 2023/10/17 09:52:09 nicm Exp $")
#ifdef USE_SP_RIPOFF
#define SoftkeyFormat SP_PARM->slk_format
#else
#define SoftkeyFormat _nc_globals.slk_format
#endif
NCURSES_EXPORT(int)
slk_init(int format)
NCURSES_SP_NAME(slk_init) (NCURSES_SP_DCLx int format)
{
int code = ERR;
T((T_CALLED("slk_init(%d)"), format));
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);
START_TRACE();
T((T_CALLED("slk_init(%p,%d)"), (void *) SP_PARM, format));
if (format >= 0
&& format <= 3
#ifdef USE_SP_RIPOFF
&& SP_PARM
&& SP_PARM->_prescreen
#endif
&& !SoftkeyFormat) {
SoftkeyFormat = 1 + format;
code = NCURSES_SP_NAME(_nc_ripoffline) (NCURSES_SP_ARGx
-SLK_LINES(SoftkeyFormat),
_nc_slk_initialize);
}
returnCode(code);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
slk_init(int format)
{
int rc;
_nc_init_pthreads();
_nc_lock_global(prescreen);
START_TRACE();
rc = NCURSES_SP_NAME(slk_init) (CURRENT_SCREEN_PRE, format);
_nc_unlock_global(prescreen);
return rc;
}
#endif

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_slklab.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_slklab.c,v 1.4 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2000,2003 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2003,2009 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 +32,8 @@
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
* and: Juergen Pfeifer, 1998,2009 *
* and: Thomas E. Dickey 1998-on *
****************************************************************************/
/*
@ -40,14 +43,22 @@
*/
#include <curses.priv.h>
MODULE_ID("$Id: lib_slklab.c,v 1.3 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_slklab.c,v 1.4 2023/10/17 09:52:09 nicm Exp $")
NCURSES_EXPORT(char *)
NCURSES_SP_NAME(slk_label) (NCURSES_SP_DCLx int n)
{
T((T_CALLED("slk_label(%p,%d)"), (void *) SP_PARM, n));
if (SP_PARM == 0 || SP_PARM->_slk == 0 || n < 1 || n > SP_PARM->_slk->labcnt)
returnPtr(0);
returnPtr(SP_PARM->_slk->ent[n - 1].ent_text);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(char *)
slk_label(int n)
{
T((T_CALLED("slk_label(%d)"), n));
if (SP == NULL || SP->_slk == NULL || n < 1 || n > SP->_slk->labcnt)
returnPtr(0);
returnPtr(SP->_slk->ent[n - 1].ent_text);
return NCURSES_SP_NAME(slk_label) (CURRENT_SCREEN, n);
}
#endif

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_slkrefr.c,v 1.5 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_slkrefr.c,v 1.6 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2006,2008 Free Software Foundation, Inc. *
* Copyright 2020,2021 Thomas E. Dickey *
* Copyright 1998-2013,2014 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,9 +41,18 @@
* Write SLK window to the (virtual) screen.
*/
#include <curses.priv.h>
#include <term.h> /* num_labels, label_*, plab_norm */
MODULE_ID("$Id: lib_slkrefr.c,v 1.5 2010/01/12 23:22:06 nicm Exp $")
#ifndef CUR
#define CUR SP_TERMTYPE
#endif
MODULE_ID("$Id: lib_slkrefr.c,v 1.6 2023/10/17 09:52:09 nicm Exp $")
#ifdef USE_TERM_DRIVER
#define NumLabels InfoOf(SP_PARM).numlabels
#else
#define NumLabels num_labels
#endif
/*
* Paint the info line for the PC style SLK emulation.
@ -55,7 +65,7 @@ slk_paint_info(WINDOW *win)
if (win && sp && (sp->slk_format == 4)) {
int i;
mvwhline(win, 0, 0, 0, getmaxx(win));
(void) mvwhline(win, 0, 0, 0, getmaxx(win));
wmove(win, 0, 0);
for (i = 0; i < sp->_slk->maxlab; i++) {
@ -68,31 +78,47 @@ slk_paint_info(WINDOW *win)
* Write the soft labels to the soft-key window.
*/
static void
slk_intern_refresh(SLK * slk)
slk_intern_refresh(SCREEN *sp)
{
int i;
int fmt = SP->slk_format;
int fmt;
SLK *slk;
int numlab;
if (sp == 0)
return;
slk = sp->_slk;
fmt = sp->slk_format;
numlab = NumLabels;
if (slk->hidden)
return;
for (i = 0; i < slk->labcnt; i++) {
if (slk->dirty || slk->ent[i].dirty) {
if (slk->ent[i].visible) {
if (num_labels > 0 && SLK_STDFMT(fmt)) {
if (numlab > 0 && SLK_STDFMT(fmt)) {
#ifdef USE_TERM_DRIVER
CallDriver_2(sp, td_hwlabel, i + 1, slk->ent[i].form_text);
#else
if (i < num_labels) {
TPUTS_TRACE("plab_norm");
putp(TPARM_2(plab_norm, i + 1, slk->ent[i].form_text));
NCURSES_PUTP2("plab_norm",
TPARM_2(plab_norm,
i + 1,
slk->ent[i].form_text));
}
#endif
} else {
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));
}
(void) wattrset(slk->win, (int) AttrOf(slk->attr));
waddstr(slk->win, slk->ent[i].form_text);
/* if we simulate SLK's, it's looking much more
/* if we simulate SLK's, it is looking much more
natural to use the current ATTRIBUTE also
for the label window */
wattrset(slk->win, WINDOW_ATTRS(stdscr));
(void) wattrset(slk->win, (int) WINDOW_ATTRS(StdScreen(sp)));
}
}
slk->ent[i].dirty = FALSE;
@ -100,14 +126,16 @@ slk_intern_refresh(SLK * slk)
}
slk->dirty = FALSE;
if (num_labels > 0) {
if (numlab > 0) {
#ifdef USE_TERM_DRIVER
CallDriver_1(sp, td_hwlabelOnOff, slk->hidden ? FALSE : TRUE);
#else
if (slk->hidden) {
TPUTS_TRACE("label_off");
putp(label_off);
NCURSES_PUTP2("label_off", label_off);
} else {
TPUTS_TRACE("label_on");
putp(label_on);
NCURSES_PUTP2("label_on", label_on);
}
#endif
}
}
@ -115,32 +143,48 @@ slk_intern_refresh(SLK * slk)
* Refresh the soft labels.
*/
NCURSES_EXPORT(int)
NCURSES_SP_NAME(slk_noutrefresh) (NCURSES_SP_DCL0)
{
T((T_CALLED("slk_noutrefresh(%p)"), (void *) SP_PARM));
if (SP_PARM == 0 || SP_PARM->_slk == 0)
returnCode(ERR);
if (SP_PARM->_slk->hidden)
returnCode(OK);
slk_intern_refresh(SP_PARM);
returnCode(wnoutrefresh(SP_PARM->_slk->win));
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
slk_noutrefresh(void)
{
T((T_CALLED("slk_noutrefresh()")));
if (SP == NULL || SP->_slk == NULL)
returnCode(ERR);
if (SP->_slk->hidden)
returnCode(OK);
slk_intern_refresh(SP->_slk);
returnCode(wnoutrefresh(SP->_slk->win));
return NCURSES_SP_NAME(slk_noutrefresh) (CURRENT_SCREEN);
}
#endif
/*
* Refresh the soft labels.
*/
NCURSES_EXPORT(int)
NCURSES_SP_NAME(slk_refresh) (NCURSES_SP_DCL0)
{
T((T_CALLED("slk_refresh(%p)"), (void *) SP_PARM));
if (SP_PARM == 0 || SP_PARM->_slk == 0)
returnCode(ERR);
if (SP_PARM->_slk->hidden)
returnCode(OK);
slk_intern_refresh(SP_PARM);
returnCode(wrefresh(SP_PARM->_slk->win));
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
slk_refresh(void)
{
T((T_CALLED("slk_refresh()")));
if (SP == NULL || SP->_slk == NULL)
returnCode(ERR);
if (SP->_slk->hidden)
returnCode(OK);
slk_intern_refresh(SP->_slk);
returnCode(wrefresh(SP->_slk->win));
return NCURSES_SP_NAME(slk_refresh) (CURRENT_SCREEN);
}
#endif

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_slkset.c,v 1.4 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_slkset.c,v 1.5 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2005,2007 Free Software Foundation, Inc. *
* Copyright 2019,2020 Thomas E. Dickey *
* Copyright 1998-2011,2012 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 *
@ -46,33 +47,33 @@
#endif
#endif
MODULE_ID("$Id: lib_slkset.c,v 1.4 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_slkset.c,v 1.5 2023/10/17 09:52:09 nicm Exp $")
NCURSES_EXPORT(int)
slk_set(int i, const char *astr, int format)
NCURSES_SP_NAME(slk_set) (NCURSES_SP_DCLx int i, const char *astr, int format)
{
SLK *slk;
int offset;
int offset = 0;
int numchrs;
int numcols;
int limit;
const char *str = astr;
const char *p;
T((T_CALLED("slk_set(%d, \"%s\", %d)"), i, str, format));
T((T_CALLED("slk_set(%p, %d, \"%s\", %d)"), (void *) SP_PARM, i, str, format));
if (SP == 0
|| (slk = SP->_slk) == 0
if (SP_PARM == 0
|| (slk = SP_PARM->_slk) == 0
|| i < 1
|| i > slk->labcnt
|| format < 0
|| format > 2)
returnCode(ERR);
if (str == NULL)
if (str == 0)
str = "";
--i; /* Adjust numbering of labels */
limit = MAX_SKEY_LEN(SP->slk_format);
limit = MAX_SKEY_LEN(SP_PARM->slk_format);
while (isspace(UChar(*str)))
str++; /* skip over leading spaces */
p = str;
@ -91,17 +92,17 @@ slk_set(int i, const char *astr, int format)
mbrtowc(&wc, p, need, &state);
if (!iswprint((wint_t) wc))
break;
if (wcwidth(wc) + numcols > limit)
if (_nc_wacs_width(wc) + numcols > limit)
break;
numcols += wcwidth(wc);
numcols += _nc_wacs_width(wc);
p += need;
}
numchrs = (p - str);
numchrs = (int) (p - str);
#else
while (isprint(UChar(*p)))
p++; /* The first non-print stops */
numcols = (p - str);
numcols = (int) (p - str);
if (numcols > limit)
numcols = limit;
numchrs = numcols;
@ -113,13 +114,12 @@ slk_set(int i, const char *astr, int format)
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))
(size_t) (limit +
numchrs + 1))
) == 0)
returnCode(ERR);
switch (format) {
default:
case 0: /* left-justified */
offset = 0;
break;
@ -133,19 +133,27 @@ slk_set(int i, const char *astr, int format)
if (offset <= 0)
offset = 0;
else
memset(slk->ent[i].form_text, ' ', (unsigned) offset);
memset(slk->ent[i].form_text, ' ', (size_t) offset);
memcpy(slk->ent[i].form_text + offset,
slk->ent[i].ent_text,
(unsigned) numchrs);
(size_t) numchrs);
if (offset < limit) {
memset(slk->ent[i].form_text + offset + numchrs,
' ',
(unsigned) (limit - (offset + numcols)));
(size_t) (limit - (offset + numcols)));
}
slk->ent[i].form_text[numchrs - numcols + limit] = 0;
slk->ent[i].dirty = TRUE;
returnCode(OK);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
slk_set(int i, const char *astr, int format)
{
return NCURSES_SP_NAME(slk_set) (CURRENT_SCREEN, i, astr, format);
}
#endif

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_slktouch.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_slktouch.c,v 1.4 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998,2000 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2000,2009 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 +30,8 @@
****************************************************************************/
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
* Author: Juergen Pfeifer 1997,2009 *
* and: Thomas E. Dickey 1996-on *
****************************************************************************/
/*
@ -40,16 +41,24 @@
*/
#include <curses.priv.h>
MODULE_ID("$Id: lib_slktouch.c,v 1.3 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_slktouch.c,v 1.4 2023/10/17 09:52:09 nicm Exp $")
NCURSES_EXPORT(int)
slk_touch(void)
NCURSES_SP_NAME(slk_touch) (NCURSES_SP_DCL0)
{
T((T_CALLED("slk_touch()")));
T((T_CALLED("slk_touch(%p)"), (void *) SP_PARM));
if (SP == NULL || SP->_slk == NULL)
if (SP_PARM == 0 || SP_PARM->_slk == 0)
returnCode(ERR);
SP->_slk->dirty = TRUE;
SP_PARM->_slk->dirty = TRUE;
returnCode(OK);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
slk_touch(void)
{
return NCURSES_SP_NAME(slk_touch) (CURRENT_SCREEN);
}
#endif

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_touch.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_touch.c,v 1.4 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998,2000 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2016,2017 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 *
@ -45,16 +46,19 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_touch.c,v 1.3 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_touch.c,v 1.4 2023/10/17 09:52:09 nicm Exp $")
#undef is_linetouched
NCURSES_EXPORT(bool)
is_linetouched(WINDOW *win, int line)
{
T((T_CALLED("is_linetouched(%p,%d)"), win, line));
T((T_CALLED("is_linetouched(%p,%d)"), (void *) win, line));
/* XSI doesn't define any error */
if (!win || (line > win->_maxy) || (line < 0))
returnCode((bool) ERR);
/* XSI doesn't define any error, and gcc ultimately made it impossible */
if (!win || (line > win->_maxy) || (line < 0)) {
returnCode(FALSE);
}
returnCode(win->_line[line].firstchar != _NOCHANGE ? TRUE : FALSE);
}
@ -62,14 +66,15 @@ is_linetouched(WINDOW *win, int line)
NCURSES_EXPORT(bool)
is_wintouched(WINDOW *win)
{
int i;
T((T_CALLED("is_wintouched(%p)"), (void *) win));
T((T_CALLED("is_wintouched(%p)"), win));
if (win) {
int i;
if (win)
for (i = 0; i <= win->_maxy; i++)
if (win->_line[i].firstchar != _NOCHANGE)
returnCode(TRUE);
}
returnCode(FALSE);
}
@ -78,7 +83,7 @@ wtouchln(WINDOW *win, int y, int n, int changed)
{
int i;
T((T_CALLED("wtouchln(%p,%d,%d,%d)"), win, y, n, changed));
T((T_CALLED("wtouchln(%p,%d,%d,%d)"), (void *) win, y, n, changed));
if (!win || (n < 0) || (y < 0) || (y > win->_maxy))
returnCode(ERR);
@ -86,8 +91,10 @@ wtouchln(WINDOW *win, int y, int n, int changed)
for (i = y; i < y + n; i++) {
if (i > win->_maxy)
break;
win->_line[i].firstchar = changed ? 0 : _NOCHANGE;
win->_line[i].lastchar = changed ? win->_maxx : _NOCHANGE;
win->_line[i].firstchar = (NCURSES_SIZE_T) (changed ? 0 : _NOCHANGE);
win->_line[i].lastchar = (NCURSES_SIZE_T) (changed
? win->_maxx
: _NOCHANGE);
}
returnCode(OK);
}

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_ungetch.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_ungetch.c,v 1.4 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2011,2012 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,6 +33,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 *
* and: Juergen Pfeifer 2009 *
****************************************************************************/
/*
@ -43,7 +45,7 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_ungetch.c,v 1.3 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_ungetch.c,v 1.4 2023/10/17 09:52:09 nicm Exp $")
#include <fifo_defs.h>
@ -59,17 +61,20 @@ _nc_fifo_dump(SCREEN *sp)
#endif /* TRACE */
NCURSES_EXPORT(int)
_nc_ungetch(SCREEN *sp, int ch)
safe_ungetch(SCREEN *sp, int ch)
{
int rc = ERR;
if (tail != -1) {
if (head == -1) {
T((T_CALLED("ungetch(%p,%s)"), (void *) sp, _nc_tracechar(sp, ch)));
if (sp != 0 && tail >= 0) {
if (head < 0) {
head = 0;
t_inc();
peek = tail; /* no raw keys */
} else
} else {
h_dec();
}
sp->_fifo[head] = ch;
T(("ungetch %s ok", _nc_tracechar(sp, ch)));
@ -81,12 +86,11 @@ _nc_ungetch(SCREEN *sp, int ch)
#endif
rc = OK;
}
return rc;
returnCode(rc);
}
NCURSES_EXPORT(int)
ungetch(int ch)
{
T((T_CALLED("ungetch(%s)"), _nc_tracechar(SP, ch)));
returnCode(_nc_ungetch(SP, ch));
return safe_ungetch(CURRENT_SCREEN, ch);
}

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_vline.c,v 1.4 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_vline.c,v 1.5 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2001,2006 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2016,2017 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 +32,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,22 +45,21 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_vline.c,v 1.4 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_vline.c,v 1.5 2023/10/17 09:52:09 nicm Exp $")
NCURSES_EXPORT(int)
wvline(WINDOW *win, chtype ch, int n)
{
int code = ERR;
NCURSES_SIZE_T row, col;
NCURSES_SIZE_T end;
T((T_CALLED("wvline(%p,%s,%d)"), win, _tracechtype(ch), n));
T((T_CALLED("wvline(%p,%s,%d)"), (void *) win, _tracechtype(ch), n));
if (win) {
NCURSES_CH_T wch;
row = win->_cury;
col = win->_curx;
end = row + n - 1;
int row = win->_cury;
int col = win->_curx;
int end = row + n - 1;
if (end > win->_maxy)
end = win->_maxy;
@ -69,6 +71,14 @@ wvline(WINDOW *win, chtype ch, int n)
while (end >= row) {
struct ldat *line = &(win->_line[end]);
#if USE_WIDEC_SUPPORT
if (col > 0 && isWidecExt(line->text[col])) {
SetChar2(line->text[col - 1], ' ');
}
if (col < win->_maxx && isWidecExt(line->text[col + 1])) {
SetChar2(line->text[col + 1], ' ');
}
#endif
line->text[col] = wch;
CHANGED_CELL(line, col);
end--;

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_wattroff.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_wattroff.c,v 1.4 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2006,2009 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,12 +45,12 @@
#include <curses.priv.h>
#include <ctype.h>
MODULE_ID("$Id: lib_wattroff.c,v 1.3 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_wattroff.c,v 1.4 2023/10/17 09:52:09 nicm Exp $")
NCURSES_EXPORT(int)
wattr_off(WINDOW *win, attr_t at, void *opts GCC_UNUSED)
{
T((T_CALLED("wattr_off(%p,%s)"), win, _traceattr(at)));
T((T_CALLED("wattr_off(%p,%s)"), (void *) win, _traceattr(at)));
if (win) {
T(("... current %s (%d)",
_traceattr(WINDOW_ATTRS(win)),

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_wattron.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_wattron.c,v 1.4 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. *
* Copyright 2020,2022 Thomas E. Dickey *
* Copyright 1998-2009,2010 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,20 +45,22 @@
#include <curses.priv.h>
#include <ctype.h>
MODULE_ID("$Id: lib_wattron.c,v 1.3 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_wattron.c,v 1.4 2023/10/17 09:52:09 nicm Exp $")
NCURSES_EXPORT(int)
wattr_on(WINDOW *win, attr_t at, void *opts GCC_UNUSED)
{
T((T_CALLED("wattr_on(%p,%s)"), win, _traceattr(at)));
T((T_CALLED("wattr_on(%p,%s)"), (void *) win, _traceattr(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);
if (at & A_COLOR) {
win->_color = PairNumber(at);
set_extended_pair(opts, win->_color);
}
});
toggle_attr_on(WINDOW_ATTRS(win), at);
returnCode(OK);

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_winch.c,v 1.4 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_winch.c,v 1.5 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2009,2010 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,16 +42,16 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_winch.c,v 1.4 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_winch.c,v 1.5 2023/10/17 09:52:09 nicm Exp $")
NCURSES_EXPORT(chtype)
winch(WINDOW *win)
{
T((T_CALLED("winch(%p)"), win));
T((T_CALLED("winch(%p)"), (void *) win));
if (win != 0) {
returnChar(CharOf(win->_line[win->_cury].text[win->_curx]) |
AttrOf(win->_line[win->_cury].text[win->_curx]));
returnChtype((chtype) CharOf(win->_line[win->_cury].text[win->_curx])
| AttrOf(win->_line[win->_cury].text[win->_curx]));
} else {
returnChar(0);
returnChtype(0);
}
}

View file

@ -1,7 +1,8 @@
/* $OpenBSD: lib_window.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: lib_window.c,v 1.4 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
* Copyright 2020,2021 Thomas E. Dickey *
* Copyright 1998-2010,2016 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 +42,7 @@
#include <curses.priv.h>
MODULE_ID("$Id: lib_window.c,v 1.3 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: lib_window.c,v 1.4 2023/10/17 09:52:09 nicm Exp $")
NCURSES_EXPORT(void)
_nc_synchook(WINDOW *win)
@ -58,33 +59,32 @@ mvderwin(WINDOW *win, int y, int x)
/* move a derived window */
{
WINDOW *orig;
int i;
int rc = ERR;
T((T_CALLED("mvderwin(%p,%d,%d)"), win, y, x));
T((T_CALLED("mvderwin(%p,%d,%d)"), (void *) win, y, x));
if (win && (orig = win->_parent)) {
if (win->_parx == x && win->_pary == y)
returnCode(OK);
if (x < 0 || y < 0)
returnCode(ERR);
if ((x + getmaxx(win) > getmaxx(orig)) ||
(y + getmaxy(win) > getmaxy(orig)))
returnCode(ERR);
} else
returnCode(ERR);
wsyncup(win);
win->_parx = x;
win->_pary = y;
for (i = 0; i < getmaxy(win); i++)
win->_line[i].text = &(orig->_line[y++].text[x]);
returnCode(OK);
if (win != 0
&& (orig = win->_parent) != 0
&& (x >= 0 && y >= 0)
&& (x + getmaxx(win) <= getmaxx(orig))
&& (y + getmaxy(win) <= getmaxy(orig))) {
int i;
wsyncup(win);
win->_parx = x;
win->_pary = y;
for (i = 0; i < getmaxy(win); i++)
win->_line[i].text = &(orig->_line[y++].text[x]);
rc = OK;
}
returnCode(rc);
}
NCURSES_EXPORT(int)
syncok(WINDOW *win, bool bf)
/* enable/disable automatic wsyncup() on each change to window */
{
T((T_CALLED("syncok(%p,%d)"), win, bf));
T((T_CALLED("syncok(%p,%d)"), (void *) win, bf));
if (win) {
win->_sync = bf;
@ -100,7 +100,7 @@ wsyncup(WINDOW *win)
{
WINDOW *wp;
T((T_CALLED("wsyncup(%p)"), win));
T((T_CALLED("wsyncup(%p)"), (void *) win));
if (win && win->_parent) {
for (wp = win; wp->_parent; wp = wp->_parent) {
int y;
@ -130,9 +130,9 @@ 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));
T((T_CALLED("wsyncdown(%p)"), (void *) win));
if (win && win->_parent) {
if (win != NULL && win->_parent != NULL) {
WINDOW *pp = win->_parent;
int y;
@ -169,7 +169,7 @@ wcursyncup(WINDOW *win)
{
WINDOW *wp;
T((T_CALLED("wcursyncup(%p)"), win));
T((T_CALLED("wcursyncup(%p)"), (void *) win));
for (wp = win; wp && wp->_parent; wp = wp->_parent) {
wmove(wp->_parent, wp->_pary + wp->_cury, wp->_parx + wp->_curx);
}
@ -181,25 +181,29 @@ dupwin(WINDOW *win)
/* make an exact duplicate of the given window */
{
WINDOW *nwin = 0;
size_t linesize;
int i;
T((T_CALLED("dupwin(%p)"), win));
T((T_CALLED("dupwin(%p)"), (void *) win));
if (win != 0) {
#if NCURSES_SP_FUNCS
SCREEN *sp = _nc_screen_of(win);
#endif
_nc_lock_global(curses);
if (win->_flags & _ISPAD) {
nwin = newpad(win->_maxy + 1,
win->_maxx + 1);
if (IS_PAD(win)) {
nwin = NCURSES_SP_NAME(newpad) (NCURSES_SP_ARGx
win->_maxy + 1,
win->_maxx + 1);
} else {
nwin = newwin(win->_maxy + 1,
win->_maxx + 1,
win->_begy,
win->_begx);
nwin = NCURSES_SP_NAME(newwin) (NCURSES_SP_ARGx
win->_maxy + 1,
win->_maxx + 1,
win->_begy,
win->_begx);
}
if (nwin != 0) {
int i;
size_t linesize;
nwin->_curx = win->_curx;
nwin->_cury = win->_cury;
@ -236,10 +240,10 @@ dupwin(WINDOW *win)
nwin->_regtop = win->_regtop;
nwin->_regbottom = win->_regbottom;
if (win->_flags & _ISPAD)
if (IS_PAD(win))
nwin->_pad = win->_pad;
linesize = (win->_maxx + 1) * sizeof(NCURSES_CH_T);
linesize = (unsigned) (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;

View file

@ -1,7 +1,8 @@
/* $OpenBSD: nc_panel.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: nc_panel.c,v 1.4 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998,2000 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2000,2009 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 *
@ -34,10 +35,22 @@
#include <curses.priv.h>
MODULE_ID("$Id: nc_panel.c,v 1.3 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: nc_panel.c,v 1.4 2023/10/17 09:52:09 nicm Exp $")
NCURSES_EXPORT(struct panelhook *)
NCURSES_SP_NAME(_nc_panelhook) (NCURSES_SP_DCL0)
{
return (SP_PARM
? &(SP_PARM->_panelHook)
: (CURRENT_SCREEN
? &(CURRENT_SCREEN->_panelHook)
: 0));
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(struct panelhook *)
_nc_panelhook(void)
{
return (SP ? &(SP->_panelHook) : NULL);
return NCURSES_SP_NAME(_nc_panelhook) (CURRENT_SCREEN);
}
#endif

View file

@ -0,0 +1,393 @@
/****************************************************************************
* Copyright 2018-2020,2021 Thomas E. Dickey *
* Copyright 2017 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 *
****************************************************************************/
/* new_pair.c
*
* New color-pair functions, alloc_pair and free_pair
*/
#define NEW_PAIR_INTERNAL 1
#include <curses.priv.h>
#ifndef CUR
#define CUR SP_TERMTYPE
#endif
#ifdef USE_TERM_DRIVER
#define MaxColors InfoOf(SP_PARM).maxcolors
#else
#define MaxColors max_colors
#endif
#if NCURSES_EXT_COLORS
/* fix redefinition versys tic.h */
#undef entry
#define entry my_entry
#undef ENTRY
#define ENTRY my_ENTRY
#include <search.h>
#endif
MODULE_ID("$Id: new_pair.c,v 1.1 2023/10/17 09:52:09 nicm Exp $")
#if NCURSES_EXT_COLORS
#ifdef NEW_PAIR_DEBUG
static int
prev_len(SCREEN *sp, int pair)
{
int result = 1;
int base = pair;
colorpair_t *list = sp->_color_pairs;
while (list[pair].prev != base) {
result++;
pair = list[pair].prev;
}
return result;
}
static int
next_len(SCREEN *sp, int pair)
{
int result = 1;
int base = pair;
colorpair_t *list = sp->_color_pairs;
while (list[pair].next != base) {
result++;
pair = list[pair].next;
}
return result;
}
/*
* Trace the contents of LRU color-pairs.
*/
static void
dumpit(SCREEN *sp, int pair, const char *tag)
{
colorpair_t *list = sp->_color_pairs;
char bigbuf[256 * 20];
char *p = bigbuf;
int n;
size_t have = sizeof(bigbuf);
_nc_STRCPY(p, tag, have);
for (n = 0; n < sp->_pair_alloc; ++n) {
if (list[n].mode != cpFREE) {
p += strlen(p);
if ((size_t) (p - bigbuf) + 50 > have)
break;
_nc_SPRINTF(p, _nc_SLIMIT(have - (p - bigbuf))
" %d%c(%d,%d)",
n, n == pair ? '@' : ':', list[n].next, list[n].prev);
}
}
T(("(%d/%d) %ld - %s",
next_len(sp, 0),
prev_len(sp, 0),
strlen(bigbuf), bigbuf));
if (next_len(sp, 0) != prev_len(sp, 0)) {
endwin();
ExitProgram(EXIT_FAILURE);
}
}
#else
#define dumpit(sp, pair, tag) /* nothing */
#endif
static int
compare_data(const void *a, const void *b)
{
const colorpair_t *p = (const colorpair_t *) a;
const colorpair_t *q = (const colorpair_t *) b;
return ((p->fg == q->fg)
? (p->bg - q->bg)
: (p->fg - q->fg));
}
static int
_nc_find_color_pair(SCREEN *sp, int fg, int bg)
{
colorpair_t find;
int result = -1;
find.fg = fg;
find.bg = bg;
if (sp != 0) {
void *pp;
if ((pp = tfind(&find, &sp->_ordered_pairs, compare_data)) != 0) {
colorpair_t *temp = *(colorpair_t **) pp;
result = (int) (temp - sp->_color_pairs);
}
}
return result;
}
static void
delink_color_pair(SCREEN *sp, int pair)
{
colorpair_t *list = sp->_color_pairs;
int prev = list[pair].prev;
int next = list[pair].next;
/* delink this from its current location */
if (list[prev].next == pair &&
list[next].prev == pair) {
list[prev].next = next;
list[next].prev = prev;
dumpit(sp, pair, "delinked");
}
}
/*
* Discard all nodes in the fast-index.
*/
NCURSES_EXPORT(void)
_nc_free_ordered_pairs(SCREEN *sp)
{
if (sp && sp->_ordered_pairs && sp->_pair_alloc) {
int n;
for (n = 0; n < sp->_pair_alloc; ++n) {
tdelete(&sp->_color_pairs[n], &sp->_ordered_pairs, compare_data);
}
}
}
/*
* Use this call to update the fast-index when modifying an entry in the color
* pair table.
*/
NCURSES_EXPORT(void)
_nc_reset_color_pair(SCREEN *sp, int pair, colorpair_t * next)
{
colorpair_t *last;
if (ValidPair(sp, pair)) {
bool used;
ReservePairs(sp, pair);
last = &(sp->_color_pairs[pair]);
delink_color_pair(sp, pair);
if (last->mode > cpFREE &&
(last->fg != next->fg || last->bg != next->bg)) {
/* remove the old entry from fast index */
tdelete(last, &sp->_ordered_pairs, compare_data);
used = FALSE;
} else {
used = (last->mode != cpFREE);
}
if (!used) {
/* create a new entry in fast index */
*last = *next;
tsearch(last, &sp->_ordered_pairs, compare_data);
}
}
}
/*
* Use this call to relink the newest pair to the front of the list, keeping
* "0" first.
*/
NCURSES_EXPORT(void)
_nc_set_color_pair(SCREEN *sp, int pair, int mode)
{
if (ValidPair(sp, pair)) {
colorpair_t *list = sp->_color_pairs;
dumpit(sp, pair, "SET_PAIR");
list[0].mode = cpKEEP;
if (list[pair].mode <= cpFREE)
sp->_pairs_used++;
list[pair].mode = mode;
if (list[0].next != pair) {
/* link it at the front of the list */
list[pair].next = list[0].next;
list[list[pair].next].prev = pair;
list[pair].prev = 0;
list[0].next = pair;
}
dumpit(sp, pair, "...after");
}
}
/*
* If we reallocate the color-pair array, we have to adjust the fast-index.
*/
NCURSES_EXPORT(void)
_nc_copy_pairs(SCREEN *sp, colorpair_t * target, colorpair_t * source, int length)
{
int n;
for (n = 0; n < length; ++n) {
void *find = tfind(source + n, &sp->_ordered_pairs, compare_data);
if (find != 0) {
tdelete(source + n, &sp->_ordered_pairs, compare_data);
tsearch(target + n, &sp->_ordered_pairs, compare_data);
}
}
}
NCURSES_EXPORT(int)
NCURSES_SP_NAME(alloc_pair) (NCURSES_SP_DCLx int fg, int bg)
{
int pair;
T((T_CALLED("alloc_pair(%d,%d)"), fg, bg));
if (SP_PARM == 0) {
pair = -1;
} else if ((pair = _nc_find_color_pair(SP_PARM, fg, bg)) < 0) {
/*
* Check if all of the slots have been used. If not, find one and
* use that.
*/
if (SP_PARM->_pairs_used + 1 < SP_PARM->_pair_limit) {
bool found = FALSE;
int hint = SP_PARM->_recent_pair;
/*
* The linear search is done to allow mixing calls to init_pair()
* and alloc_pair(). The former can make gaps...
*/
for (pair = hint + 1; pair < SP_PARM->_pair_alloc; pair++) {
if (SP_PARM->_color_pairs[pair].mode == cpFREE) {
T(("found gap %d", pair));
found = TRUE;
break;
}
}
if (!found && (SP_PARM->_pair_alloc < SP_PARM->_pair_limit)) {
pair = SP_PARM->_pair_alloc;
ReservePairs(SP_PARM, pair);
if (SP_PARM->_color_pairs == 0) {
pair = -1;
} else {
found = TRUE;
}
}
if (!found && SP_PARM->_color_pairs != NULL) {
for (pair = 1; pair <= hint; pair++) {
if (SP_PARM->_color_pairs[pair].mode == cpFREE) {
T(("found gap %d", pair));
found = TRUE;
break;
}
}
}
if (found) {
SP_PARM->_recent_pair = pair;
} else {
pair = ERR;
}
} else {
/* reuse the oldest one */
pair = SP_PARM->_color_pairs[0].prev;
T(("reusing %d", pair));
}
if (_nc_init_pair(SP_PARM, pair, fg, bg) == ERR)
pair = ERR;
}
returnCode(pair);
}
NCURSES_EXPORT(int)
NCURSES_SP_NAME(find_pair) (NCURSES_SP_DCLx int fg, int bg)
{
int pair;
T((T_CALLED("find_pair(%d,%d)"), fg, bg));
pair = _nc_find_color_pair(SP_PARM, fg, bg);
returnCode(pair);
}
NCURSES_EXPORT(int)
NCURSES_SP_NAME(free_pair) (NCURSES_SP_DCLx int pair)
{
int result = ERR;
T((T_CALLED("free_pair(%d)"), pair));
if (ValidPair(SP_PARM, pair) && pair < SP_PARM->_pair_alloc) {
colorpair_t *cp = &(SP_PARM->_color_pairs[pair]);
if (pair != 0) {
_nc_change_pair(SP_PARM, pair);
delink_color_pair(SP_PARM, pair);
tdelete(cp, &SP_PARM->_ordered_pairs, compare_data);
cp->mode = cpFREE;
result = OK;
SP_PARM->_pairs_used--;
}
}
returnCode(result);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
alloc_pair(int f, int b)
{
return NCURSES_SP_NAME(alloc_pair) (CURRENT_SCREEN, f, b);
}
NCURSES_EXPORT(int)
find_pair(int f, int b)
{
return NCURSES_SP_NAME(find_pair) (CURRENT_SCREEN, f, b);
}
NCURSES_EXPORT(int)
free_pair(int pair)
{
return NCURSES_SP_NAME(free_pair) (CURRENT_SCREEN, pair);
}
#endif
#if NO_LEAKS
NCURSES_EXPORT(void)
_nc_new_pair_leaks(SCREEN *sp)
{
if (sp->_color_pairs) {
while (sp->_color_pairs[0].next) {
free_pair(sp->_color_pairs[0].next);
}
}
}
#endif
#else
void _nc_new_pair(void);
void
_nc_new_pair(void)
{
}
#endif /* NCURSES_EXT_COLORS */

View file

@ -1,7 +1,8 @@
/* $OpenBSD: resizeterm.c,v 1.4 2021/03/10 20:16:08 millert Exp $ */
/* $OpenBSD: resizeterm.c,v 1.5 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
* Copyright 2020,2021 Thomas E. Dickey *
* Copyright 1998-2015,2016 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,6 +31,7 @@
/****************************************************************************
* Author: Thomas E. Dickey *
* and: Juergen Pfeifer *
****************************************************************************/
/*
@ -41,11 +43,12 @@
*/
#include <curses.priv.h>
#include <term.h>
MODULE_ID("$Id: resizeterm.c,v 1.4 2021/03/10 20:16:08 millert Exp $")
#ifndef CUR
#define CUR SP_TERMTYPE
#endif
#define stolen_lines (screen_lines - SP->_lines_avail)
MODULE_ID("$Id: resizeterm.c,v 1.5 2023/10/17 09:52:09 nicm Exp $")
/*
* If we're trying to be reentrant, do not want any local statics.
@ -62,22 +65,33 @@ static int current_cols;
#define EXTRA_DCLS /* nothing */
#endif
#if NCURSES_SP_FUNCS && !defined(USE_SP_WINDOWLIST)
#define UNUSED_SP (void) sp
#else
#define UNUSED_SP /* nothing */
#endif
#ifdef TRACE
static void
show_window_sizes(const char *name)
{
SCREEN *sp;
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);
for (each_screen(sp)) {
_tracef("%s resizing: %p: %2d x %2d (%2d x %2d)", name, (void *) sp,
*(ptrLines(sp)),
*(ptrCols(sp)),
screen_lines(sp), screen_columns(sp));
for (each_window(sp, wp)) {
_tracef(" window %p is %2ld x %2ld at %2ld,%2ld",
(void *) &(wp->win),
(long) wp->win._maxy + 1,
(long) wp->win._maxx + 1,
(long) wp->win._begy,
(long) wp->win._begx);
}
}
_nc_unlock_global(curses);
}
@ -88,15 +102,23 @@ show_window_sizes(const char *name)
* structure's size.
*/
NCURSES_EXPORT(bool)
is_term_resized(int ToLines, int ToCols)
NCURSES_SP_NAME(is_term_resized) (NCURSES_SP_DCLx int ToLines, int ToCols)
{
T((T_CALLED("is_term_resized(%d, %d)"), ToLines, ToCols));
T((T_CALLED("is_term_resized(%p, %d, %d)"), (void *) SP_PARM, ToLines, ToCols));
returnCode(ToLines > 0
&& ToCols > 0
&& (ToLines != screen_lines
|| ToCols != screen_columns));
&& (ToLines != screen_lines(SP_PARM)
|| ToCols != screen_columns(SP_PARM)));
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(bool)
is_term_resized(int ToLines, int ToCols)
{
return NCURSES_SP_NAME(is_term_resized) (CURRENT_SCREEN, ToLines, ToCols);
}
#endif
/*
*/
static ripoff_t *
@ -106,6 +128,9 @@ ripped_window(WINDOW *win)
ripoff_t *rop;
if (win != 0) {
#ifdef USE_SP_RIPOFF
SCREEN *sp = _nc_screen_of(win);
#endif
for (each_ripoff(rop)) {
if (rop->win == win && rop->line != 0) {
result = rop;
@ -124,9 +149,13 @@ static int
ripped_bottom(WINDOW *win)
{
int result = 0;
ripoff_t *rop;
if (win != 0) {
ripoff_t *rop;
#ifdef USE_SP_RIPOFF
SCREEN *sp = _nc_screen_of(win);
#endif
for (each_ripoff(rop)) {
if (rop->line < 0) {
result -= rop->line;
@ -148,9 +177,12 @@ child_depth(WINDOW *cmp)
int depth = 0;
if (cmp != 0) {
#ifdef USE_SP_WINDOWLIST
SCREEN *sp = _nc_screen_of(cmp);
#endif
WINDOWLIST *wp;
for (each_window(wp)) {
for (each_window(sp, wp)) {
WINDOW *tst = &(wp->win);
if (tst->_parent == cmp) {
depth = 1 + child_depth(tst);
@ -180,19 +212,19 @@ parent_depth(WINDOW *cmp)
}
/*
* FIXME: must adjust position so it's within the parent!
* FIXME: must adjust position so it is 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 bottom = CurLines + _nc_screen_of(win)->_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,
(void *) win, ToLines, ToCols,
(rop != 0) ? " (rip)" : "",
parent_depth(win),
child_depth(win),
@ -204,13 +236,19 @@ adjust_window(WINDOW *win, int ToLines, int ToCols, int stolen EXTRA_DCLS)
* 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;
win->_begy = (NCURSES_SIZE_T) (ToLines - ripped_bottom(win) - 0 - win->_yoffset);
if (rop->hook == _nc_slk_initialize)
_nc_format_slks(
#if NCURSES_SP_FUNCS
_nc_screen_of(win),
#endif
ToCols);
} 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);
win->_begy = (NCURSES_SIZE_T) (win->_begy + (ToLines - CurLines));
} else {
if (myLines == (CurLines - stolen)
&& ToLines != CurLines) {
@ -241,22 +279,23 @@ adjust_window(WINDOW *win, int ToLines, int ToCols, int stolen EXTRA_DCLS)
* children, decrease those to fit, then decrease the containing window, etc.
*/
static int
decrease_size(int ToLines, int ToCols, int stolen EXTRA_DCLS)
decrease_size(NCURSES_SP_DCLx int ToLines, int ToCols, int stolen EXTRA_DCLS)
{
bool found;
int depth = 0;
WINDOWLIST *wp;
T((T_CALLED("decrease_size(%d, %d)"), ToLines, ToCols));
T((T_CALLED("decrease_size(%p, %d, %d)"), (void *) SP_PARM, ToLines, ToCols));
UNUSED_SP;
do {
found = FALSE;
TR(TRACE_UPDATE, ("decreasing size of windows to %dx%d, depth=%d",
ToLines, ToCols, depth));
for (each_window(wp)) {
for (each_window(SP_PARM, wp)) {
WINDOW *win = &(wp->win);
if (!(win->_flags & _ISPAD)) {
if (!IS_PAD(win)) {
if (child_depth(win) == depth) {
found = TRUE;
if (adjust_window(win, ToLines, ToCols,
@ -275,22 +314,23 @@ decrease_size(int ToLines, int ToCols, int stolen EXTRA_DCLS)
* parent, increase those to fit, then increase the contained window, etc.
*/
static int
increase_size(int ToLines, int ToCols, int stolen EXTRA_DCLS)
increase_size(NCURSES_SP_DCLx int ToLines, int ToCols, int stolen EXTRA_DCLS)
{
bool found;
int depth = 0;
WINDOWLIST *wp;
T((T_CALLED("increase_size(%d, %d)"), ToLines, ToCols));
T((T_CALLED("increase_size(%p, %d, %d)"), (void *) SP_PARM, ToLines, ToCols));
UNUSED_SP;
do {
found = FALSE;
TR(TRACE_UPDATE, ("increasing size of windows to %dx%d, depth=%d",
ToLines, ToCols, depth));
for (each_window(wp)) {
for (each_window(SP_PARM, wp)) {
WINDOW *win = &(wp->win);
if (!(win->_flags & _ISPAD)) {
if (!IS_PAD(win)) {
if (parent_depth(win) == depth) {
found = TRUE;
if (adjust_window(win, ToLines, ToCols,
@ -309,25 +349,26 @@ increase_size(int ToLines, int ToCols, int stolen EXTRA_DCLS)
* such as ungetch().
*/
NCURSES_EXPORT(int)
resize_term(int ToLines, int ToCols)
NCURSES_SP_NAME(resize_term) (NCURSES_SP_DCLx int ToLines, int ToCols)
{
int result = OK EXTRA_ARGS;
int was_stolen;
T((T_CALLED("resize_term(%d,%d) old(%d,%d)"),
ToLines, ToCols,
screen_lines, screen_columns));
T((T_CALLED("resize_term(%p,%d,%d) old(%d,%d)"),
(void *) SP_PARM, ToLines, ToCols,
(SP_PARM == 0) ? -1 : screen_lines(SP_PARM),
(SP_PARM == 0) ? -1 : screen_columns(SP_PARM)));
if (SP == 0) {
if (SP_PARM == 0 || ToLines <= 0 || ToCols <= 0) {
returnCode(ERR);
}
_nc_lock_global(curses);
_nc_nonsp_lock_global(curses);
was_stolen = (screen_lines - SP->_lines_avail);
if (is_term_resized(ToLines, ToCols)) {
int myLines = CurLines = screen_lines;
int myCols = CurCols = screen_columns;
was_stolen = (screen_lines(SP_PARM) - SP_PARM->_lines_avail);
if (NCURSES_SP_NAME(is_term_resized) (NCURSES_SP_ARGx ToLines, ToCols)) {
int myLines = CurLines = screen_lines(SP_PARM);
int myCols = CurCols = screen_columns(SP_PARM);
#ifdef TRACE
if (USE_TRACEF(TRACE_UPDATE)) {
@ -335,56 +376,90 @@ resize_term(int ToLines, int ToCols)
_nc_unlock_global(tracef);
}
#endif
if (ToLines > screen_lines) {
increase_size(myLines = ToLines, myCols, was_stolen EXTRA_ARGS);
if (ToLines > screen_lines(SP_PARM)) {
result = increase_size(NCURSES_SP_ARGx
myLines = ToLines,
myCols,
was_stolen EXTRA_ARGS);
CurLines = myLines;
CurCols = myCols;
}
if (ToCols > screen_columns) {
increase_size(myLines, myCols = ToCols, was_stolen EXTRA_ARGS);
if ((result == OK)
&& (ToCols > screen_columns(SP_PARM))) {
result = increase_size(NCURSES_SP_ARGx
myLines,
myCols = ToCols,
was_stolen EXTRA_ARGS);
CurLines = myLines;
CurCols = myCols;
}
if (ToLines < myLines ||
ToCols < myCols) {
decrease_size(ToLines, ToCols, was_stolen EXTRA_ARGS);
if ((result == OK)
&& (ToLines < myLines ||
ToCols < myCols)) {
result = decrease_size(NCURSES_SP_ARGx
ToLines,
ToCols,
was_stolen EXTRA_ARGS);
}
screen_lines = lines = ToLines;
screen_columns = columns = ToCols;
if (result == OK) {
screen_lines(SP_PARM) = (NCURSES_SIZE_T) ToLines;
screen_columns(SP_PARM) = (NCURSES_SIZE_T) ToCols;
SP->_lines_avail = lines - was_stolen;
if (SP->oldhash) {
FreeAndNull(SP->oldhash);
}
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);
}
#ifdef USE_TERM_DRIVER
CallDriver_2(SP_PARM, td_setsize, ToLines, ToCols);
#else
lines = (NCURSES_SIZE_T) ToLines;
columns = (NCURSES_SIZE_T) ToCols;
#endif
SP_PARM->_lines_avail = (NCURSES_SIZE_T) (ToLines - was_stolen);
if (SP_PARM->oldhash) {
FreeAndNull(SP_PARM->oldhash);
}
if (SP_PARM->newhash) {
FreeAndNull(SP_PARM->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.
*/
SET_LINES(ToLines - was_stolen);
SET_COLS(ToCols);
if (result == OK) {
/*
* Always update LINES, to allow for call from lib_doupdate.c which
* needs to have the count adjusted by the stolen (ripped off) lines.
*/
SET_LINES(ToLines - was_stolen);
SET_COLS(ToCols);
}
_nc_unlock_global(curses);
_nc_nonsp_unlock_global(curses);
returnCode(result);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
resize_term(int ToLines, int ToCols)
{
int res;
_nc_sp_lock_global(curses);
res = NCURSES_SP_NAME(resize_term) (CURRENT_SCREEN, ToLines, ToCols);
_nc_sp_unlock_global(curses);
return (res);
}
#endif
/*
* This function reallocates NCURSES window structures. It is invoked in
* response to a SIGWINCH interrupt. Other user-defined windows may also need
@ -394,33 +469,34 @@ resize_term(int ToLines, int ToCols)
* invoked directly from the signal handler.
*/
NCURSES_EXPORT(int)
resizeterm(int ToLines, int ToCols)
NCURSES_SP_NAME(resizeterm) (NCURSES_SP_DCLx int ToLines, int ToCols)
{
int result = ERR;
T((T_CALLED("resizeterm(%d,%d) old(%d,%d)"),
ToLines, ToCols,
screen_lines, screen_columns));
T((T_CALLED("resizeterm(%p, %d,%d) old(%d,%d)"),
(void *) SP_PARM, ToLines, ToCols,
(SP_PARM == 0) ? -1 : screen_lines(SP_PARM),
(SP_PARM == 0) ? -1 : screen_columns(SP_PARM)));
if (SP != 0) {
if (SP_PARM != 0 && ToLines > 0 && ToCols > 0) {
result = OK;
SP->_sig_winch = FALSE;
SP_PARM->_sig_winch = FALSE;
if (is_term_resized(ToLines, ToCols)) {
if (NCURSES_SP_NAME(is_term_resized) (NCURSES_SP_ARGx ToLines, ToCols)) {
#if USE_SIGWINCH
ripoff_t *rop;
bool slk_visible = (SP != 0
&& SP->_slk != 0
&& !(SP->_slk->hidden));
bool slk_visible = (SP_PARM != 0
&& SP_PARM->_slk != 0
&& !(SP_PARM->_slk->hidden));
if (slk_visible) {
slk_clear();
}
#endif
result = resize_term(ToLines, ToCols);
result = NCURSES_SP_NAME(resize_term) (NCURSES_SP_ARGx ToLines, ToCols);
#if USE_SIGWINCH
clearok(curscr, TRUE); /* screen contents are unknown */
clearok(CurScreen(SP_PARM), 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.
@ -430,7 +506,7 @@ resizeterm(int ToLines, int ToCols)
* not know which are really on top.
*/
for (each_ripoff(rop)) {
if (rop->win != stdscr
if (rop->win != StdScreen(SP_PARM)
&& rop->win != 0
&& rop->line < 0) {
@ -443,17 +519,24 @@ resizeterm(int ToLines, int ToCols)
/* soft-keys are a special case: we _know_ how to repaint them */
if (slk_visible) {
slk_restore();
slk_touch();
slk_refresh();
NCURSES_SP_NAME(slk_restore) (NCURSES_SP_ARG);
NCURSES_SP_NAME(slk_touch) (NCURSES_SP_ARG);
NCURSES_SP_NAME(slk_refresh) (NCURSES_SP_ARG);
}
#endif
}
#if USE_SIGWINCH
_nc_ungetch(SP, KEY_RESIZE); /* so application can know this */
safe_ungetch(SP_PARM, KEY_RESIZE); /* so application can know this */
#endif
}
returnCode(result);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
resizeterm(int ToLines, int ToCols)
{
return NCURSES_SP_NAME(resizeterm) (CURRENT_SCREEN, ToLines, ToCols);
}
#endif

View file

@ -1,7 +1,8 @@
/* $OpenBSD: safe_sprintf.c,v 1.6 2010/10/18 18:22:35 nicm Exp $ */
/* $OpenBSD: safe_sprintf.c,v 1.7 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2003,2007 Free Software Foundation, Inc. *
* Copyright 2018-2020,2021 Thomas E. Dickey *
* Copyright 1998-2012,2013 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 +30,13 @@
****************************************************************************/
/****************************************************************************
* Author: Thomas E. Dickey <dickey@clark.net> 1997 *
* Author: Thomas E. Dickey 1997-on *
****************************************************************************/
#include <curses.priv.h>
#include <ctype.h>
MODULE_ID("$Id: safe_sprintf.c,v 1.6 2010/10/18 18:22:35 nicm Exp $")
MODULE_ID("$Id: safe_sprintf.c,v 1.7 2023/10/17 09:52:09 nicm Exp $")
#if USE_SAFE_SPRINTF
@ -43,7 +44,7 @@ typedef enum {
Flags, Width, Prec, Type, Format
} PRINTF;
#define VA_INTGR(type) ival = va_arg(ap, type)
#define VA_INTGR(type) ival = (int) va_arg(ap, type)
#define VA_FLOAT(type) fval = va_arg(ap, type)
#define VA_POINT(type) pval = (void *)va_arg(ap, type)
@ -57,7 +58,6 @@ _nc_printf_length(const char *fmt, va_list ap)
size_t length = BUFSIZ;
char *buffer;
char *format;
char *tmp_format;
int len = 0;
size_t fmt_len;
char fmt_arg[BUFSIZ];
@ -112,15 +112,16 @@ _nc_printf_length(const char *fmt, va_list ap)
} else if (state == Prec) {
prec = ival;
}
sprintf(fmt_arg, "%d", ival);
_nc_SPRINTF(fmt_arg,
_nc_SLIMIT(sizeof(fmt_arg))
"%d", ival);
fmt_len += strlen(fmt_arg);
if ((tmp_format = realloc(format, fmt_len)) == 0) {
if ((format = _nc_doalloc(format, fmt_len)) == 0) {
free(buffer);
free(format);
return -1;
}
format = tmp_format;
strcpy(&format[--f], fmt_arg);
--f;
_nc_STRCPY(&format[f], fmt_arg, fmt_len - f);
f = strlen(format);
} else if (isalpha(UChar(*fmt))) {
done = TRUE;
@ -159,9 +160,9 @@ _nc_printf_length(const char *fmt, va_list ap)
case 's':
VA_POINT(char *);
if (prec < 0)
prec = strlen(pval);
prec = (int) strlen(pval);
if (prec > (int) length) {
length = length + prec;
length = length + (size_t) prec;
buffer = typeRealloc(char, length, buffer);
if (buffer == 0) {
free(format);
@ -191,13 +192,13 @@ _nc_printf_length(const char *fmt, va_list ap)
format[f] = '\0';
switch (used) {
case 'i':
sprintf(buffer, format, ival);
_nc_SPRINTF(buffer, _nc_SLIMIT(length) format, ival);
break;
case 'f':
sprintf(buffer, format, fval);
_nc_SPRINTF(buffer, _nc_SLIMIT(length) format, fval);
break;
default:
sprintf(buffer, format, pval);
_nc_SPRINTF(buffer, _nc_SLIMIT(length) format, pval);
break;
}
len += (int) strlen(buffer);
@ -220,19 +221,26 @@ _nc_printf_length(const char *fmt, va_list ap)
* 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)
NCURSES_SP_NAME(_nc_printf_string) (NCURSES_SP_DCLx
const char *fmt,
va_list ap)
{
char *result = 0;
char *result = NULL;
if (fmt != 0) {
if (SP_PARM != NULL && fmt != NULL) {
#if USE_SAFE_SPRINTF
int len = _nc_printf_length(fmt, ap);
va_list ap2;
int len;
begin_va_copy(ap2, ap);
len = _nc_printf_length(fmt, ap2);
end_va_copy(ap2);
if ((int) my_length < len + 1) {
my_length = 2 * (len + 1);
my_length = (size_t) (2 * (len + 1));
my_buffer = typeRealloc(char, my_length, my_buffer);
}
if (my_buffer != 0) {
if (my_buffer != NULL) {
*my_buffer = '\0';
if (len >= 0) {
vsprintf(my_buffer, fmt, ap);
@ -243,28 +251,45 @@ _nc_printf_string(const char *fmt, va_list ap)
#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;
if (screen_lines(SP_PARM) > MyRows || screen_columns(SP_PARM) > MyCols) {
if (screen_lines(SP_PARM) > MyRows)
MyRows = screen_lines(SP_PARM);
if (screen_columns(SP_PARM) > MyCols)
MyCols = screen_columns(SP_PARM);
my_length = (size_t) (MyRows * (MyCols + 1)) + 1;
if (my_length < 80)
my_length = 80;
my_buffer = typeRealloc(char, my_length, my_buffer);
}
if (my_buffer != 0) {
if (my_buffer != NULL) {
# if HAVE_VSNPRINTF
vsnprintf(my_buffer, my_length, fmt, ap); /* GNU extension */
/* SUSv2, 1997 */
int used;
while ((used = vsnprintf(my_buffer, my_length, fmt, ap))
>= (int) my_length) {
my_length = (size_t) ((3 * used) / 2);
my_buffer = typeRealloc(char, my_length, my_buffer);
}
# else
vsprintf(my_buffer, fmt, ap); /* ANSI */
/* ISO/ANSI C, 1989 */
vsprintf(my_buffer, fmt, ap);
# endif
result = my_buffer;
}
#endif
} else if (my_buffer != 0) { /* see _nc_freeall() */
} else if (my_buffer != NULL) { /* see _nc_freeall() */
free(my_buffer);
my_buffer = 0;
my_buffer = NULL;
my_length = 0;
}
return result;
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(char *)
_nc_printf_string(const char *fmt, va_list ap)
{
return NCURSES_SP_NAME(_nc_printf_string) (CURRENT_SCREEN, fmt, ap);
}
#endif

View file

@ -1,7 +1,6 @@
/* $OpenBSD: lib_tracechr.c,v 1.5 2010/01/12 23:22:07 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 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 *
@ -31,57 +30,71 @@
/****************************************************************************
* 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: Thomas E. Dickey 1996-2003 *
****************************************************************************/
/*
* lib_tracechr.c - Tracing/Debugging routines
*/
#include <curses.priv.h>
/* This file provides sigaction() emulation using sigvec() */
/* Use only if this is non POSIX system */
#include <ctype.h>
MODULE_ID("$Id: sigaction.c,v 1.6 2023/10/17 09:52:09 nicm Exp $")
MODULE_ID("$Id: lib_tracechr.c,v 1.5 2010/01/12 23:22:07 nicm Exp $")
#ifdef TRACE
NCURSES_EXPORT(char *)
_nc_tracechar(SCREEN *sp, int ch)
static int
_nc_sigaction(int sig, sigaction_t * sigact, sigaction_t * osigact)
{
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);
return sigvec(sig, sigact, osigact);
}
NCURSES_EXPORT(char *)
_tracechar(int ch)
static int
_nc_sigemptyset(sigset_t * mask)
{
return _nc_tracechar(SP, ch);
*mask = 0;
return 0;
}
static int
_nc_sigprocmask(int mode, sigset_t * mask, sigset_t * omask)
{
sigset_t current = sigsetmask(0);
if (omask)
*omask = current;
if (mode == SIG_BLOCK)
current |= *mask;
else if (mode == SIG_UNBLOCK)
current &= ~*mask;
else if (mode == SIG_SETMASK)
current = *mask;
sigsetmask(current);
return 0;
}
static int
_nc_sigaddset(sigset_t * mask, int sig)
{
*mask |= sigmask(sig);
return 0;
}
/* not used in lib_tstp.c */
#if 0
static int
_nc_sigsuspend(sigset_t * mask)
{
return sigpause(*mask);
}
static int
_nc_sigdelset(sigset_t * mask, int sig)
{
*mask &= ~sigmask(sig);
return 0;
}
static int
_nc_sigismember(sigset_t * mask, int sig)
{
return (*mask & sigmask(sig)) != 0;
}
#else
EMPTY_MODULE(_nc_lib_tracechr)
#endif

View file

@ -1,7 +1,8 @@
/* $OpenBSD: tries.c,v 1.5 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: tries.c,v 1.6 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
* Copyright 2020,2023 Thomas E. Dickey *
* Copyright 1998-2009,2010 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,8 +41,9 @@
*/
#include <curses.priv.h>
#include <tic.h>
MODULE_ID("$Id: tries.c,v 1.5 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: tries.c,v 1.6 2023/10/17 09:52:09 nicm Exp $")
/*
* Expand a keycode into the string that it corresponds to, returning null if
@ -74,7 +76,9 @@ _nc_expand_try(TRIES * tree, unsigned code, int *count, size_t len)
*((unsigned char *) (result + len)) = 128;
#ifdef TRACE
if (len == 0 && USE_TRACEF(TRACE_MAXIMUM)) {
_tracef("expand_key %s %s", _nc_tracechar(SP, code), _nc_visbuf(result));
_tracef("expand_key %s %s",
_nc_tracechar(CURRENT_SCREEN, (int) code),
_nc_visbuf(result));
_nc_unlock_global(tracef);
}
#endif
@ -89,7 +93,7 @@ _nc_expand_try(TRIES * tree, unsigned code, int *count, size_t len)
NCURSES_EXPORT(int)
_nc_remove_key(TRIES ** tree, unsigned code)
{
T((T_CALLED("_nc_remove_key(%p,%d)"), tree, code));
T((T_CALLED("_nc_remove_key(%p,%d)"), (void *) tree, code));
if (code == 0)
returnCode(FALSE);
@ -121,9 +125,9 @@ _nc_remove_key(TRIES ** tree, unsigned code)
NCURSES_EXPORT(int)
_nc_remove_string(TRIES ** tree, const char *string)
{
T((T_CALLED("_nc_remove_string(%p,%s)"), tree, _nc_visbuf(string)));
T((T_CALLED("_nc_remove_string(%p,%s)"), (void *) tree, _nc_visbuf(string)));
if (string == 0 || *string == 0)
if (!VALID_STRING(string) || *string == 0)
returnCode(FALSE);
while (*tree != 0) {

View file

@ -1,7 +1,8 @@
/* $OpenBSD: use_window.c,v 1.1 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: use_window.c,v 1.2 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 2007,2008 Free Software Foundation, Inc. *
* Copyright 2018,2020 Thomas E. Dickey *
* Copyright 2007-2009,2016 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 *
@ -34,14 +35,19 @@
#include <curses.priv.h>
MODULE_ID("$Id: use_window.c,v 1.1 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: use_window.c,v 1.2 2023/10/17 09:52:09 nicm Exp $")
NCURSES_EXPORT(int)
use_window(WINDOW *win, NCURSES_WINDOW_CB func, void *data)
{
int code = OK;
TR_FUNC_BFR(1);
T((T_CALLED("use_window(%p,%s,%p)"),
(void *) win,
TR_FUNC_ARG(0, func),
data));
T((T_CALLED("use_window(%p,%p,%p)"), win, func, data));
_nc_lock_global(curses);
code = func(win, data);
_nc_unlock_global(curses);

View file

@ -1,7 +1,8 @@
/* $OpenBSD: version.c,v 1.5 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: version.c,v 1.6 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1999-2004,2005 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 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 *
@ -34,7 +35,7 @@
#include <curses.priv.h>
MODULE_ID("$Id: version.c,v 1.5 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: version.c,v 1.6 2023/10/17 09:52:09 nicm Exp $")
NCURSES_EXPORT(const char *)
curses_version(void)

View file

@ -1,7 +1,8 @@
/* $OpenBSD: vsscanf.c,v 1.2 2015/09/27 05:25:00 guenther Exp $ */
/* $OpenBSD: vsscanf.c,v 1.3 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2003,2004 Free Software Foundation, Inc. *
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2004,2012 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 +41,7 @@
#if !HAVE_VSSCANF
MODULE_ID("$Id: vsscanf.c,v 1.2 2015/09/27 05:25:00 guenther Exp $")
MODULE_ID("$Id: vsscanf.c,v 1.3 2023/10/17 09:52:09 nicm Exp $")
#if !(HAVE_VFSCANF || HAVE__DOSCAN)
@ -161,6 +162,7 @@ other_ch(int ch)
}
#endif
/*VARARGS2*/
NCURSES_EXPORT(int)
vsscanf(const char *str, const char *format, va_list ap)
{
@ -294,12 +296,12 @@ vsscanf(const char *str, const char *format, va_list ap)
/* add %n, if the format was not that */
if (chunk != cAssigned) {
strlcat(my_fmt, "%n", len_fmt);
_nc_STRCAT(my_fmt, "%n", len_fmt);
}
switch (chunk) {
case cAssigned:
strlcat(my_fmt, "%n", len_fmt);
_nc_STRCAT(my_fmt, "%n", len_fmt);
pointer = &eaten;
break;
case cInt:

View file

@ -1,7 +1,8 @@
/* $OpenBSD: wresize.c,v 1.5 2010/01/12 23:22:06 nicm Exp $ */
/* $OpenBSD: wresize.c,v 1.6 2023/10/17 09:52:09 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
* Copyright 2019-2020,2021 Thomas E. Dickey *
* Copyright 1998-2010,2011 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,18 +30,19 @@
****************************************************************************/
/****************************************************************************
* Author: Thomas E. Dickey 1996-2002 *
* Author: Thomas E. Dickey 1996-on *
* and: Juergen Pfeifer *
****************************************************************************/
#include <curses.priv.h>
MODULE_ID("$Id: wresize.c,v 1.5 2010/01/12 23:22:06 nicm Exp $")
MODULE_ID("$Id: wresize.c,v 1.6 2023/10/17 09:52:09 nicm Exp $")
static int
cleanup_lines(struct ldat *data, int length)
{
while (--length >= 0)
free(data[length].text);
FreeAndNull(data[length].text);
free(data);
return ERR;
}
@ -55,23 +57,40 @@ repair_subwindows(WINDOW *cmp)
WINDOWLIST *wp;
struct ldat *pline = cmp->_line;
int row;
#ifdef USE_SP_WINDOWLIST
SCREEN *sp = _nc_screen_of(cmp);
#endif
_nc_lock_global(curses);
for (each_window(wp)) {
for (each_window(SP_PARM, 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;
#define REPAIR1(field, limit) \
if (tst->field > cmp->limit) \
tst->field = cmp->limit
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;
REPAIR1(_pary, _maxy);
REPAIR1(_parx, _maxx);
#define REPAIR2(field, limit) \
if (tst->limit + tst->field > cmp->limit) \
tst->limit = (NCURSES_SIZE_T) (cmp->limit - tst->field)
REPAIR2(_pary, _maxy);
REPAIR2(_parx, _maxx);
#define REPAIR3(field, limit) \
if (tst->field > tst->limit) \
tst->field = tst->limit
REPAIR3(_cury, _maxy);
REPAIR3(_curx, _maxx);
REPAIR3(_regtop, _maxy);
REPAIR3(_regbottom, _maxy);
for (row = 0; row <= tst->_maxy; ++row) {
tst->_line[row].text = &pline[tst->_pary + row].text[tst->_parx];
@ -95,7 +114,7 @@ wresize(WINDOW *win, int ToLines, int ToCols)
struct ldat *new_lines = 0;
#ifdef TRACE
T((T_CALLED("wresize(%p,%d,%d)"), win, ToLines, ToCols));
T((T_CALLED("wresize(%p,%d,%d)"), (void *) win, ToLines, ToCols));
if (win) {
TR(TRACE_UPDATE, ("...beg (%ld, %ld), max(%ld,%ld), reg(%ld,%ld)",
(long) win->_begy, (long) win->_begx,
@ -118,7 +137,7 @@ wresize(WINDOW *win, int ToLines, int ToCols)
&& ToCols == size_x)
returnCode(OK);
if ((win->_flags & _SUBWIN)) {
if (IS_SUBWIN(win)) {
/*
* Check if the new limits will fit into the parent window's size. If
* not, do not resize. We could adjust the location of the subwindow,
@ -152,13 +171,22 @@ wresize(WINDOW *win, int ToLines, int ToCols)
int end = ToCols;
NCURSES_CH_T *s;
if (!(win->_flags & _SUBWIN)) {
if (!IS_SUBWIN(win)) {
if (row <= size_y) {
if (ToCols != size_x) {
if ((s = typeMalloc(NCURSES_CH_T, ToCols + 1)) == 0)
s = typeMalloc(NCURSES_CH_T, (unsigned) ToCols + 1);
if (s == 0)
returnCode(cleanup_lines(new_lines, row));
for (col = 0; col <= ToCols; ++col) {
s[col] = (col <= size_x
bool valid = (col <= size_x);
if_WIDEC({
if (col == ToCols
&& col < size_x
&& isWidecBase(win->_line[row].text[col])) {
valid = FALSE;
}
});
s[col] = (valid
? win->_line[row].text[col]
: win->_nc_bkgd);
}
@ -166,13 +194,16 @@ wresize(WINDOW *win, int ToLines, int ToCols)
s = win->_line[row].text;
}
} else {
if ((s = typeMalloc(NCURSES_CH_T, ToCols + 1)) == 0)
s = typeMalloc(NCURSES_CH_T, (unsigned) ToCols + 1);
if (s == 0)
returnCode(cleanup_lines(new_lines, row));
for (col = 0; col <= ToCols; ++col)
s[col] = win->_nc_bkgd;
}
} else {
} else if (pline != 0 && pline[win->_pary + row].text != 0) {
s = &pline[win->_pary + row].text[win->_parx];
} else {
s = 0;
}
if_USE_SCROLL_HINTS(new_lines[row].oldindex = row);
@ -183,11 +214,11 @@ wresize(WINDOW *win, int ToLines, int ToCols)
if ((ToCols != size_x) || (row > size_y)) {
if (end >= begin) { /* growing */
if (new_lines[row].firstchar < begin)
new_lines[row].firstchar = begin;
new_lines[row].firstchar = (NCURSES_SIZE_T) begin;
} else { /* shrinking */
new_lines[row].firstchar = 0;
}
new_lines[row].lastchar = ToCols;
new_lines[row].lastchar = (NCURSES_SIZE_T) ToCols;
}
new_lines[row].text = s;
}
@ -198,24 +229,24 @@ wresize(WINDOW *win, int ToLines, int ToCols)
if (!(win->_flags & _SUBWIN)) {
if (ToCols == size_x) {
for (row = ToLines + 1; row <= size_y; row++) {
free(win->_line[row].text);
FreeAndNull(win->_line[row].text);
}
} else {
for (row = 0; row <= size_y; row++) {
free(win->_line[row].text);
FreeAndNull(win->_line[row].text);
}
}
}
free(win->_line);
FreeAndNull(win->_line);
win->_line = new_lines;
/*
* Finally, adjust the parameters showing screen size and cursor
* position:
*/
win->_maxx = ToCols;
win->_maxy = ToLines;
win->_maxx = (NCURSES_SIZE_T) ToCols;
win->_maxy = (NCURSES_SIZE_T) ToLines;
if (win->_regtop > win->_maxy)
win->_regtop = win->_maxy;

View file

@ -1,7 +1,6 @@
/* $OpenBSD: trace_buf.c,v 1.4 2010/01/12 23:22:07 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
* Copyright 2019,2020 Thomas E. Dickey *
* Copyright 2010,2012 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,93 +28,81 @@
****************************************************************************/
/****************************************************************************
* Author: Thomas E. Dickey 1997-on *
* Author: Thomas E. Dickey 2010 *
****************************************************************************/
/*
* trace_buf.c - Tracing/Debugging buffers (attributes)
* $Id: build.priv.h,v 1.1 2023/10/17 09:52:08 nicm Exp $
*
* build.priv.h
*
* This is a reduced version of curses.priv.h, for build-time utilities.
* Because it has fewer dependencies, this simplifies cross-compiling.
*
*/
#include <curses.priv.h>
#ifndef CURSES_PRIV_H
#define CURSES_PRIV_H 1
MODULE_ID("$Id: trace_buf.c,v 1.4 2010/01/12 23:22:07 nicm Exp $")
#include <ncurses_dll.h>
#define MyList _nc_globals.tracebuf_ptr
#define MySize _nc_globals.tracebuf_used
static char *
_nc_trace_alloc(int bufnum, size_t want)
{
#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
else {
if (MySize) {
if (MyList) {
while (MySize--) {
if (MyList[MySize].text != 0) {
free(MyList[MySize].text);
}
}
free(MyList);
MyList = 0;
}
MySize = 0;
}
}
#ifdef __cplusplus
extern "C" {
#endif
return result;
#include <ncurses_cfg.h>
#if USE_RCS_IDS
#define MODULE_ID(id) static const char Ident[] = id;
#else
return NULL;
#define MODULE_ID(id) /*nothing */
#endif
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <assert.h>
#include <stdio.h>
#include <errno.h>
#include <curses.h> /* we'll use -Ipath directive to get the right one! */
/* usually in <unistd.h> */
#ifndef EXIT_SUCCESS
#define EXIT_SUCCESS 0
#endif
#ifndef EXIT_FAILURE
#define EXIT_FAILURE 1
#endif
#define FreeAndNull(p) do { free(p); p = 0; } while (0)
#define UChar(c) ((unsigned char)(c))
#define SIZEOF(v) (sizeof(v) / sizeof(v[0]))
#include <nc_alloc.h>
#include <nc_string.h>
/* declare these, to avoid needing term.h */
#if BROKEN_LINKER || USE_REENTRANT
#define NCURSES_ARRAY(name) \
NCURSES_WRAPPED_VAR(NCURSES_CONST char * const *, name)
NCURSES_ARRAY(boolnames);
NCURSES_ARRAY(boolfnames);
NCURSES_ARRAY(numnames);
NCURSES_ARRAY(numfnames);
NCURSES_ARRAY(strnames);
NCURSES_ARRAY(strfnames);
#endif
#if NO_LEAKS
NCURSES_EXPORT(void) _nc_names_leaks(void);
#endif
#ifdef __cplusplus
}
/*
* (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;
}
/*
* 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);
}
return buffer;
}
#endif
#endif /* CURSES_PRIV_H */

View file

@ -1,7 +1,8 @@
/* $OpenBSD: capdefaults.c,v 1.3 2010/01/12 23:21:58 nicm Exp $ */
/* $OpenBSD: capdefaults.c,v 1.4 2023/10/17 09:52:08 nicm Exp $ */
/****************************************************************************
* Copyright (c) 1998-2000,2008 Free Software Foundation, Inc. *
* Copyright 2020,2021 Thomas E. Dickey *
* Copyright 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 *
@ -34,11 +35,11 @@
* and: Thomas E. Dickey 1996-on *
****************************************************************************/
/* $Id: capdefaults.c,v 1.3 2010/01/12 23:21:58 nicm Exp $ */
/* $Id: capdefaults.c,v 1.4 2023/10/17 09:52:08 nicm Exp $ */
/*
* Compute obsolete capabilities. The reason this is an include file is
* that the two places where it's needed want the macros to generate
* that the two places where it is needed require the macros to generate
* offsets to different structures. See the file Caps for explanations of
* these conversions.
*
@ -46,11 +47,11 @@
* postprocess_termcap().
*/
{
char *sp;
char *strp;
short capval;
#define EXTRACT_DELAY(str) \
(short) (sp = strchr(str, '*'), sp ? atoi(sp+1) : 0)
(short) (strp = strchr(str, '*'), strp ? atoi(strp+1) : 0)
/* current (4.4BSD) capabilities marked obsolete */
if (VALID_STRING(carriage_return)

View file

@ -1,6 +1,8 @@
.\" $OpenBSD: curs_add_wch.3,v 1.1 2010/09/06 17:26:17 nicm Exp $
'\" t
.\" $OpenBSD: curs_add_wch.3,v 1.2 2023/10/17 09:52:08 nicm Exp $
.\"***************************************************************************
.\" Copyright (c) 2001-2002,2006 Free Software Foundation, Inc. *
.\" Copyright 2019-2021,2023 Thomas E. Dickey *
.\" Copyright 2001-2015,2017 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,17 +29,24 @@
.\" authorization. *
.\"***************************************************************************
.\"
.\" $Id: curs_add_wch.3,v 1.1 2010/09/06 17:26:17 nicm Exp $
.TH curs_add_wch 3 ""
.\" $Id: curs_add_wch.3,v 1.2 2023/10/17 09:52:08 nicm Exp $
.TH curs_add_wch 3 2023-08-19 "ncurses 6.4" "Library calls"
.ie \n(.g .ds `` \(lq
.el .ds `` ``
.ie \n(.g .ds '' \(rq
.el .ds '' ''
.de bP
.ie n .IP \(bu 4
.el .IP \(bu 2
..
.SH NAME
\fBadd_wch\fP,
\fBwadd_wch\fP,
\fBmvadd_wch\fP,
\fBmvwadd_wch\fP,
\fBecho_wchar\fP,
\fBwecho_wchar\fP - add a complex character and rendition to a \fBcurses\fR window, then advance the cursor
\fBwecho_wchar\fP \- add a complex character and rendition to a \fBcurses\fP window, then advance the cursor
.SH SYNOPSIS
.PP
\fB#include <curses.h>\fP
.sp
.B "int add_wch( const cchar_t *\fIwch\fB );"
@ -47,13 +56,12 @@
.B "int mvadd_wch( int \fIy\fP, int \fIx\fP, const cchar_t *\fIwch\fB );"
.br
.B "int mvwadd_wch( WINDOW *\fIwin\fP, int \fIy\fP, int \fIx\fP, const cchar_t *\fIwch\fB );"
.br
.sp
.B "int echo_wchar( const cchar_t *\fIwch\fB );"
.br
.B "int wecho_wchar( WINDOW *\fIwin\fP, const cchar_t *\fIwch\fB );"
.br
.SH DESCRIPTION
.PP
.SS add_wch
The
\fBadd_wch\fP,
\fBwadd_wch\fP,
@ -64,32 +72,36 @@ window at its current position,
which is then advanced.
These functions perform
wrapping and special-character processing as follows:
.TP 5
-
.bP
If \fIwch\fP refers to a spacing character,
then any previous character at that location is removed.
A new character specified by \fIwch\fP is
placed at that location with rendition specified by \fIwch\fP.
The cursor then advances to
the next spacing character on the screen.
.TP 5
-
The cursor then advances after this spacing character,
to prepare for writing the next character on the screen.
.IP
The newly added spacing character is the base of the active complex character.
Subsequent non-spacing characters can be combined with this base
until another spacing character is written to the screen,
or the cursor is moved, e.g., using \fBwmove\fP.
.bP
If \fIwch\fP refers to a non-spacing character,
all previous characters at that location are preserved.
The non-spacing characters of \fIwch\fP
are added to the spacing complex character,
and the rendition specified by \fIwch\fP is ignored.
.TP 5
-
it is appended to the active complex character,
retaining the previous characters at that location.
The rendition specified by \fIwch\fP is ignored.
.IP
The cursor is not advanced after adding a non-spacing character.
Subsequent calls to add non-spacing characters will update the same position.
.bP
If the character part of \fIwch\fP is
a tab, newline, backspace or other control character,
the window is updated and the cursor moves as if \fBaddch\fR were called.
.PP
the window is updated and the cursor moves as if \fBaddch\fP were called.
.SS echo_wchar
The \fBecho_wchar\fP
function is functionally equivalent to a call to
\fBadd_wch\fP
followed by a call to
\fBrefresh\fP.
\fBrefresh\fP(3).
Similarly, the
\fBwecho_wchar\fP
is functionally equivalent to a call to
@ -100,11 +112,134 @@ 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 the *\fBecho\fP* functions instead of their equivalents.
.SH RETURN VALUES
.SS Line Graphics
Like \fBaddch\fP(3),
\fBaddch_wch\fP accepts symbols which make it simple to draw lines and other
frequently used special characters.
These symbols correspond to the same VT100 line-drawing set as
\fBaddch\fP(3).
.PP
All routines return the integer \fBERR\fR upon failure and \fBOK\fR on success.
.TS
l l l l l
l l l l l
_ _ _ _ _
lw(1.5i) lw5 lw5 lw5 lw20.
\fBACS\fP \fBUnicode\fP \fBASCII\fP \fBacsc\fP \fBGlyph\fP
\fBName\fP \fBDefault\fP \fBDefault\fP \fBchar\fP \fBName\fP
WACS_BLOCK 0x25ae # 0 solid square block
WACS_BOARD 0x2592 # h board of squares
WACS_BTEE 0x2534 + v bottom tee
WACS_BULLET 0x00b7 o ~ bullet
WACS_CKBOARD 0x2592 : a checker board (stipple)
WACS_DARROW 0x2193 v . arrow pointing down
WACS_DEGREE 0x00b0 ' f degree symbol
WACS_DIAMOND 0x25c6 + ` diamond
WACS_GEQUAL 0x2265 > > greater-than-or-equal-to
WACS_HLINE 0x2500 \- q horizontal line
WACS_LANTERN 0x2603 # i lantern symbol
WACS_LARROW 0x2190 < , arrow pointing left
WACS_LEQUAL 0x2264 < y less-than-or-equal-to
WACS_LLCORNER 0x2514 + m lower left-hand corner
WACS_LRCORNER 0x2518 + j lower right-hand corner
WACS_LTEE 0x2524 + t left tee
WACS_NEQUAL 0x2260 ! | not-equal
WACS_PI 0x03c0 * { greek pi
WACS_PLMINUS 0x00b1 # g plus/minus
WACS_PLUS 0x253c + n plus
WACS_RARROW 0x2192 > + arrow pointing right
WACS_RTEE 0x251c + u right tee
WACS_S1 0x23ba \- o scan line 1
WACS_S3 0x23bb \- p scan line 3
WACS_S7 0x23bc \- r scan line 7
WACS_S9 0x23bd \&_ s scan line 9
WACS_STERLING 0x00a3 f } pound-sterling symbol
WACS_TTEE 0x252c + w top tee
WACS_UARROW 0x2191 ^ \- arrow pointing up
WACS_ULCORNER 0x250c + l upper left-hand corner
WACS_URCORNER 0x2510 + k upper right-hand corner
WACS_VLINE 0x2502 | x vertical line
.TE
.PP
The wide-character configuration of ncurses also defines symbols
for thick lines (\fBacsc\fP \*(``J\*('' to \*(``V\*(''):
.PP
.TS
l l l l l
l l l l l
_ _ _ _ _
lw(1.5i) lw5 lw5 lw5 lw20.
\fBACS\fP \fBUnicode\fP \fBASCII\fP \fBacsc\fP \fBGlyph\fP
\fBName\fP \fBDefault\fP \fBDefault\fP \fBchar\fP \fBName\fP
WACS_T_BTEE 0x253b + V thick tee pointing up
WACS_T_HLINE 0x2501 - Q thick horizontal line
WACS_T_LLCORNER 0x2517 + M thick lower left corner
WACS_T_LRCORNER 0x251b + J thick lower right corner
WACS_T_LTEE 0x252b + T thick tee pointing right
WACS_T_PLUS 0x254b + N thick large plus
WACS_T_RTEE 0x2523 + U thick tee pointing left
WACS_T_TTEE 0x2533 + W thick tee pointing down
WACS_T_ULCORNER 0x250f + L thick upper left corner
WACS_T_URCORNER 0x2513 + K thick upper right corner
WACS_T_VLINE 0x2503 | X thick vertical line
.TE
.PP
and for double-lines (\fBacsc\fP \*(``A\*('' to \*(``I\*(''):
.PP
.TS
l l l l l
l l l l l
_ _ _ _ _
lw(1.5i) lw5 lw5 lw5 lw20.
\fBACS\fP \fBUnicode\fP \fBASCII\fP \fBacsc\fP \fBGlyph\fP
\fBName\fP \fBDefault\fP \fBDefault\fP \fBchar\fP \fBName\fP
WACS_D_BTEE 0x2569 + H double tee pointing up
WACS_D_HLINE 0x2550 - R double horizontal line
WACS_D_LLCORNER 0x255a + D double lower left corner
WACS_D_LRCORNER 0x255d + A double lower right corner
WACS_D_LTEE 0x2560 + F double tee pointing right
WACS_D_PLUS 0x256c + E double large plus
WACS_D_RTEE 0x2563 + G double tee pointing left
WACS_D_TTEE 0x2566 + I double tee pointing down
WACS_D_ULCORNER 0x2554 + C double upper left corner
WACS_D_URCORNER 0x2557 + B double upper right corner
WACS_D_VLINE 0x2551 | Y double vertical line
.TE
.PP
Unicode's descriptions for these characters differs slightly from ncurses,
by introducing the term \*(``light\*('' (along with less important details).
Here are its descriptions for the normal, thick, and double horizontal lines:
.bP
U+2500 BOX DRAWINGS LIGHT HORIZONTAL
.bP
U+2501 BOX DRAWINGS HEAVY HORIZONTAL
.bP
U+2550 BOX DRAWINGS DOUBLE HORIZONTAL
.SH RETURN VALUE
All routines return the integer \fBERR\fP upon failure and \fBOK\fP on success.
.PP
X/Open does not define any error conditions.
This implementation returns an error
.bP
if the window pointer is null or
.bP
if it is not possible to add a complete character in the window.
.PP
The latter may be due to different causes:
.bP
If \fBscrollok\fP(3) is not enabled,
writing a character at the lower right margin succeeds.
However, an error is returned because
it is not possible to wrap to a new line
.bP
If an error is detected when converting a multibyte character to a sequence
of bytes,
or if it is not possible to add all of the resulting bytes in the window,
an error is returned.
.PP
Functions with a \*(``mv\*('' prefix first perform a cursor movement using
\fBwmove\fP, and return an error if the position is outside the window,
or if the window pointer is null.
.SH NOTES
.PP
Note that
\fBadd_wch\fP,
\fBmvadd_wch\fP,
@ -112,25 +247,111 @@ Note that
\fBecho_wchar\fP
may be macros.
.SH PORTABILITY
All of these functions are described in the XSI Curses standard, Issue 4.
The defaults specified for line-drawing characters apply in the POSIX locale.
.SS WACS Symbols
X/Open Curses makes it clear that the WACS_ symbols should be defined as
a pointer to \fBcchar_t\fP data, e.g., in the discussion of \fBborder_set\fP.
A few implementations are problematic:
.bP
NetBSD curses defines the symbols as a \fBwchar_t\fP within a \fBcchar_t\fP.
.bP
HPUX curses equates some of the \fBACS_\fP symbols
to the analogous \fBWACS_\fP symbols as if the \fBACS_\fP symbols were
wide characters.
The misdefined symbols are the arrows
and other symbols which are not used for line-drawing.
.PP
All these functions are described in the XSI Curses standard, Issue 4.
The defaults specified for forms-drawing characters apply in the POSIX locale.
X/Open Curses does not define symbols for thick- or double-lines.
SVr4 curses implementations defined their line-drawing symbols in
terms of intermediate symbols.
This implementation extends those symbols, providing new definitions
which are not in the SVr4 implementations.
.PP
XSI documents constants beginning with \fBWACS_\fP which are used for
line-drawing.
Those are not currently implemented in \fBncurses\fP.
Not all Unicode-capable terminals provide support for VT100-style
alternate character sets (i.e., the \fBacsc\fP capability),
with their corresponding line-drawing characters.
X/Open Curses did not address the aspect of integrating Unicode with
line-drawing characters.
Existing implementations of Unix curses (AIX, HPUX, Solaris)
use only the \fBacsc\fP character-mapping to provide this feature.
As a result, those implementations can only use single-byte line-drawing
characters.
Ncurses 5.3 (2002) provided a table of Unicode values to solve these problems.
NetBSD curses incorporated that table in 2010.
.PP
In this implementation, the Unicode values are used instead of the
terminal description's \fBacsc\fP mapping as discussed in ncurses(3)
for the environment variable \fBNCURSES_NO_UTF8_ACS\fP.
In contrast, for the same cases, the line-drawing characters
described in \fBcurs_addch\fP(3) will use only the ASCII default values.
.PP
Having Unicode available does not solve all of the problems with
line-drawing for curses:
.bP
The closest Unicode equivalents to the
VT100 graphics \fIS1\fP, \fIS3\fP, \fIS7\fP and \fIS9\fP
frequently are not displayed at
the regular intervals which the terminal used.
.bP
The \fIlantern\fP is a special case.
It originated with the AT&T 4410 terminal in the early 1980s.
There is no accessible documentation depicting the lantern symbol
on the AT&T terminal.
.IP
Lacking documentation, most readers assume that a \fIstorm lantern\fP
was intended.
But there are several possibilities, all with problems.
.IP
Unicode 6.0 (2010) does provide two lantern symbols: U+1F383 and U+1F3EE.
Those were not available in 2002, and are irrelevant since
they lie outside the BMP and as a result are not generally available
in terminals.
They are not storm lanterns, in any case.
.IP
Most \fIstorm lanterns\fP have a tapering glass chimney
(to guard against tipping);
some have a wire grid protecting the chimney.
.IP
For the tapering appearance, \[u2603] U+2603 was adequate.
In use on a terminal, no one can tell what the image represents.
Unicode calls it a snowman.
.IP
Others have suggested these alternatives:
\[sc] U+00A7 (section mark),
\[u0398] U+0398 (theta),
\[u03A6] U+03A6 (phi),
\[u03B4] U+03B4 (delta),
\[u2327] U+2327 (x in a rectangle),
\[u256C] U+256C (forms double vertical and horizontal), and
\[u2612] U+2612 (ballot box with x).
.SS Complex Characters
The complex character type \fBcchar_t\fR
can store more than one wide character (\fBwchar_t\fR).
The X/Open Curses description does not mention this possibility,
describing only the cases where \fIwch\fP is a spacing character
or a non-spacing character.
.PP
This implementation assumes that \fIwch\fP is constructed using
\fBsetcchar\fP(3), and in turn that the result
.bP
contains at most one spacing character in the beginning of its list of wide
characters,
and zero or more non-spacing characters
or
.bP
may hold one non-spacing character.
.PP
In the latter case, ncurses adds the non-spacing character to the active
(base) spacing character.
.SH SEE ALSO
.PP
\fBcurses\fR(3),
\fBcurs_addch\fR(3),
\fBcurs_attr\fR(3),
\fBcurs_clear\fR(3),
\fBcurs_outopts\fR(3),
\fBcurs_refresh\fR(3),
\fBputwc\fR(3)
.\"#
.\"# The following sets edit modes for GNU EMACS
.\"# Local Variables:
.\"# mode:nroff
.\"# fill-column:79
.\"# End:
.na
.hy 0
\fBcurses\fP(3),
\fBcurs_addch\fP(3),
\fBcurs_attr\fP(3),
\fBcurs_clear\fP(3),
\fBcurs_getcchar\fP(3),
\fBcurs_outopts\fP(3),
\fBcurs_refresh\fP(3),
\fBputwc\fP(3)

View file

@ -1,6 +1,7 @@
.\" $OpenBSD: curs_add_wchstr.3,v 1.1 2010/09/06 17:26:17 nicm Exp $
.\" $OpenBSD: curs_add_wchstr.3,v 1.2 2023/10/17 09:52:08 nicm Exp $
.\"***************************************************************************
.\" Copyright (c) 2002-2004,2005 Free Software Foundation, Inc. *
.\" Copyright 2019-2021,2022 Thomas E. Dickey *
.\" Copyright 2002-2012,2017 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,72 +28,97 @@
.\" authorization. *
.\"***************************************************************************
.\"
.\" $Id: curs_add_wchstr.3,v 1.1 2010/09/06 17:26:17 nicm Exp $
.TH curs_add_wchstr 3 ""
.\" $Id: curs_add_wchstr.3,v 1.2 2023/10/17 09:52:08 nicm Exp $
.TH curs_add_wchstr 3 2022-02-12 "ncurses 6.4" "Library calls"
.ie \n(.g .ds `` \(lq
.el .ds `` ``
.ie \n(.g .ds '' \(rq
.el .ds '' ''
.de bP
.ie n .IP \(bu 4
.el .IP \(bu 2
..
.na
.hy 0
.SH NAME
\fBadd_wchstr\fR,
\fBadd_wchnstr\fR,
\fBwadd_wchstr\fR,
\fBwadd_wchnstr\fR,
\fBmvadd_wchstr\fR,
\fBmvadd_wchnstr\fR,
\fBmvwadd_wchstr\fR,
\fBmvwadd_wchnstr\fR \- add an array of complex characters (and attributes) to a curses window
\fBadd_wchstr\fP,
\fBadd_wchnstr\fP,
\fBwadd_wchstr\fP,
\fBwadd_wchnstr\fP,
\fBmvadd_wchstr\fP,
\fBmvadd_wchnstr\fP,
\fBmvwadd_wchstr\fP,
\fBmvwadd_wchnstr\fP \- add an array of complex characters (and attributes) to a curses window
.ad
.hy
.SH SYNOPSIS
.B #include <curses.h>
.PP
.nf
\fBint add_wchstr(const cchar_t *\fR\fIwchstr\fR\fB);\fR
\fB#include <curses.h>\fP
.PP
\fBint add_wchstr(const cchar_t *\fIwchstr\fB);\fR
.br
\fBint add_wchnstr(const cchar_t *\fR\fIwchstr\fR\fB, int \fR\fIn\fR\fB);\fR
\fBint add_wchnstr(const cchar_t *\fIwchstr\fB, int \fIn\fB);\fR
.br
\fBint wadd_wchstr(WINDOW *\fR \fIwin\fR\fB, const cchar_t *\fR\fIwchstr\fR\fB);\fR
\fBint wadd_wchstr(WINDOW *\fR \fIwin\fB, const cchar_t *\fIwchstr\fB);\fR
.br
\fBint wadd_wchnstr(WINDOW *\fR \fIwin\fR\fB, const cchar_t *\fR\fIwchstr\fR\fB, int \fR\fIn\fR\fB);\fR
\fBint wadd_wchnstr(WINDOW *\fR \fIwin\fB, const cchar_t *\fIwchstr\fB, int \fIn\fB);\fR
.sp
\fBint mvadd_wchstr(int \fIy\fB, int \fIx\fB, const cchar_t *\fIwchstr\fB);\fR
.br
\fBint mvadd_wchstr(int \fR\fIy\fR\fB, int \fR\fIx\fR\fB, const cchar_t *\fR\fIwchstr\fR\fB);\fR
\fBint mvadd_wchnstr(int \fIy\fB, int \fIx\fB, const cchar_t *\fIwchstr\fB, int \fIn\fB);\fR
.br
\fBint mvadd_wchnstr(int \fR\fIy\fR\fB, int \fR\fIx\fR\fB, const cchar_t *\fR\fIwchstr\fR\fB, int \fR\fIn\fR\fB);\fR
\fBint mvwadd_wchstr(WINDOW *\fIwin\fB, int \fIy\fB, int \fIx\fB, const cchar_t *\fIwchstr\fB);\fR
.br
\fBint mvwadd_wchstr(WINDOW *\fR\fIwin\fR\fB, int \fR\fIy\fR\fB, int \fR\fIx\fR\fB, const cchar_t *\fR\fIwchstr\fR\fB);\fR
.br
\fBint mvwadd_wchnstr(WINDOW *\fR\fIwin\fR\fB, int \fR\fIy\fR\fB, int \fR\fIx\fR\fB, const cchar_t *\fR\fIwchstr\fR\fB, int \fR\fIn\fR\fB);\fR
\fBint mvwadd_wchnstr(WINDOW *\fIwin\fB, int \fIy\fB, int \fIx\fB, const cchar_t *\fIwchstr\fB, int \fIn\fB);\fR
.fi
.SH DESCRIPTION
These routines copy the array of complex characters \fIwchstr\fR
into the window image structure at and after 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 array is copied,
These functions copy the (null-terminated)
array of complex characters \fIwchstr\fP
into the window image structure
starting at the current cursor position.
The four functions with \fIn\fP as the last
argument copy at most \fIn\fP elements,
but no more than will fit on the line.
If \fBn\fP=\fB\-1\fP then the whole array is copied,
to the maximum number of characters that will fit on the line.
.PP
The window cursor is \fInot\fR advanced.
These routines work faster than \fBwaddnstr\fR.
On the other hand, they do not perform checking
The window cursor is \fInot\fP advanced.
These functions work faster than \fBwaddnstr\fP.
On the other hand:
.bP
they do not perform checking
(such as for the newline, backspace, or carriage return characters),
.bP
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,
.bP
they do not expand other control characters to ^-escapes, and
.bP
they truncate the string if it crosses the right margin,
rather than wrapping it around to the new line.
.PP
These routines end successfully
on encountering a null \fIcchar_t\fR, or
These functions end successfully
on encountering a null \fBcchar_t\fP, or
when they have filled the current line.
If a complex character cannot completely fit at the end of the current line,
the remaining columns are filled with the background character and rendition.
.SH RETURN VALUE
All functions return the integer \fBERR\fP upon failure and \fBOK\fP on success.
.PP
X/Open does not define any error conditions.
This implementation returns an error
if the window pointer is null.
.PP
Functions with a \*(``mv\*('' prefix first perform a cursor movement using
\fBwmove\fP, and return an error if the position is outside the window,
or if the window pointer is null.
.SH NOTES
All functions except \fBwadd_wchnstr\fR may be macros.
.SH RETURN VALUES
All routines return the integer \fBERR\fR upon failure and \fBOK\fR on success.
All functions except \fBwadd_wchnstr\fP 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),
\fBcurs_addchstr\fR(3),
\fBcurs_addwstr\fR(3)
.\"#
.\"# The following sets edit modes for GNU EMACS
.\"# Local Variables:
.\"# mode:nroff
.\"# fill-column:79
.\"# End:
\fBcurses\fP(3),
\fBcurs_addwstr\fP(3).
.PP
Comparable functions in the narrow-character (ncurses) library are
described in
\fBcurs_addchstr\fP(3).

View file

@ -1,8 +1,9 @@
'\" t
.\" $OpenBSD: curs_addch.3,v 1.4 2019/02/13 07:18:57 nicm Exp $
.\"
.\" $OpenBSD: curs_addch.3,v 1.5 2023/10/17 09:52:08 nicm Exp $
.\"
.\"***************************************************************************
.\" Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. *
.\" Copyright 2018-2022,2023 Thomas E. Dickey *
.\" Copyright 1998-2015,2017 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,119 +30,211 @@
.\" authorization. *
.\"***************************************************************************
.\"
.\" $Id: curs_addch.3,v 1.4 2019/02/13 07:18:57 nicm Exp $
.TH curs_addch 3 ""
.\" $Id: curs_addch.3,v 1.5 2023/10/17 09:52:08 nicm Exp $
.TH curs_addch 3 2023-08-19 "ncurses 6.4" "Library calls"
.ie \n(.g .ds `` \(lq
.el .ds `` ``
.ie \n(.g .ds '' \(rq
.el .ds '' ''
.de bP
.ie n .IP \(bu 4
.el .IP \(bu 2
..
.SH NAME
\fBaddch\fR, \fBwaddch\fR, \fBmvaddch\fR, \fBmvwaddch\fR,
\fBechochar\fR,
\fBwechochar\fR - add a character (with attributes) to a \fBcurses\fR window, then advance the cursor
\fBaddch\fP,
\fBwaddch\fP,
\fBmvaddch\fP,
\fBmvwaddch\fP,
\fBechochar\fP,
\fBwechochar\fP \- add a character (with attributes) to a \fBcurses\fP window, then advance the cursor
.SH SYNOPSIS
\fB#include <curses.h>\fR
\fB#include <curses.h>\fP
.PP
\fBint addch(const chtype ch);\fR
\fBint addch(const chtype \fIch\fB);\fR
.br
\fBint waddch(WINDOW *win, const chtype ch);\fR
\fBint waddch(WINDOW *\fIwin\fB, const chtype \fIch\fB);\fR
.br
\fBint mvaddch(int y, int x, const chtype ch);\fR
\fBint mvaddch(int \fIy\fB, int \fIx\fB, const chtype \fIch\fB);\fR
.br
\fBint mvwaddch(WINDOW *win, int y, int x, const chtype ch);\fR
\fBint mvwaddch(WINDOW *\fIwin\fB, int \fIy\fB, int \fIx\fB, const chtype \fIch\fB);\fR
.sp
\fBint echochar(const chtype \fIch\fB);\fR
.br
\fBint echochar(const chtype ch);\fR
.br
\fBint wechochar(WINDOW *win, const chtype ch);\fR
\fBint wechochar(WINDOW *\fIwin\fB, const chtype \fIch\fB);\fR
.br
.SH DESCRIPTION
The \fBaddch\fR, \fBwaddch\fR, \fBmvaddch\fR and \fBmvwaddch\fR routines put
the character \fIch\fR into the given window at its current window position,
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.
.SS Adding characters
The \fBaddch\fP, \fBwaddch\fP, \fBmvaddch\fP and \fBmvwaddch\fP routines put
the character \fIch\fP into the given window at its current window position,
which is then advanced.
They are analogous to \fBputchar\fP(3) in \fBstdio\fP(3).
If the advance is at the right margin:
.bP
The cursor automatically wraps to the beginning of the next line.
.bP
At the bottom of the current scrolling region,
and if \fBscrollok\fP(3) is enabled,
the scrolling region is scrolled up one line.
.bP
If \fBscrollok\fP(3) is not enabled,
writing a character at the lower right margin succeeds.
However, an error is returned because
it is not possible to wrap to a new line
.PP
If \fIch\fR is a tab, newline, or backspace,
the cursor is moved appropriately within the window.
If \fIch\fP is a tab, newline, carriage return or backspace,
the cursor is moved appropriately within the window:
.bP
Backspace moves the cursor one character left; at the left
edge of a window it does nothing.
Newline does a \fBclrtoeol\fR,
.bP
Carriage return moves the cursor to the window left margin on the current line.
.bP
Newline does a \fBclrtoeol\fP,
then moves the cursor to the window left margin on the next line,
scrolling the window if on the last line.
.bP
Tabs are considered to be at every eighth column.
The tab interval may be altered by setting the \fBTABSIZE\fR variable.
The tab interval may be altered by setting the \fBTABSIZE\fP 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.
If \fIch\fP is any other nonprintable character,
it is drawn in printable form,
using the same convention as \fBunctrl\fR(3):
.bP
Control characters are displayed in the \fB^\fIX\fR notation.
.bP
Values above 128 are either meta characters
(if the screen has not been initialized,
or if \fBmeta\fP(3) has been called with a \fBTRUE\fP E parameter),
shown in the \fBM\-\fIX\fR notation, or are displayed as themselves.
In the latter case, the values may not be printable;
this follows the X/Open specification.
.PP
Calling \fBwinch\fP after adding a
nonprintable character does not return the character itself,
but instead returns the printable representation of the 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.
\fBaddch\fP 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
using \fBinch\fP(3) and \fBaddch\fP.) See the \fBcurs_attr\fP(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
.SS Echoing characters
The \fBechochar\fP and \fBwechochar\fP routines are equivalent to a call to
\fBaddch\fP followed by a call to \fBrefresh\fP(3), or a call to \fBwaddch\fP
followed by a call to \fBwrefresh\fP.
The knowledge that only a single
character is being output is used and, for non-control characters, a
considerable performance gain may be seen by using these routines instead of
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 does not define a terminal-specific
replacement for it.
screen with routines of the \fBaddch\fP family.
The default character listed
below is used if the \fBacsc\fP capability does not define a terminal-specific
replacement for it,
or if the terminal and locale configuration requires Unicode but the
library is unable to use Unicode.
.PP
The names are taken from VT100 nomenclature.
.PP
.TS
l l l
_ _ _
l l l.
\fIName\fR \fIDefault\fR \fIDescription\fR
ACS_BLOCK # solid square block
ACS_BOARD # board of squares
ACS_BTEE + bottom tee
ACS_BULLET o bullet
ACS_CKBOARD : checker board (stipple)
ACS_DARROW v arrow pointing down
ACS_DEGREE ' degree symbol
ACS_DIAMOND + diamond
ACS_GEQUAL > greater-than-or-equal-to
ACS_HLINE - horizontal line
ACS_LANTERN # lantern symbol
ACS_LARROW < arrow pointing left
ACS_LEQUAL < less-than-or-equal-to
ACS_LLCORNER + lower left-hand corner
ACS_LRCORNER + lower right-hand corner
ACS_LTEE + left tee
ACS_NEQUAL ! not-equal
ACS_PI * greek pi
ACS_PLMINUS # plus/minus
ACS_PLUS + plus
ACS_RARROW > arrow pointing right
ACS_RTEE + right tee
ACS_S1 - scan line 1
ACS_S3 - scan line 3
ACS_S7 - scan line 7
ACS_S9 \&_ scan line 9
ACS_STERLING f pound-sterling symbol
ACS_TTEE + top tee
ACS_UARROW ^ arrow pointing up
ACS_ULCORNER + upper left-hand corner
ACS_URCORNER + upper right-hand corner
ACS_VLINE | vertical line
l l l l
l l l l
_ _ _ _
l l l l.
\fBACS\fP \fBACS\fP \fBacsc\fP \fBGlyph\fP
\fBName\fP \fBDefault\fP \fBchar\fP \fBName\fP
ACS_BLOCK # 0 solid square block
ACS_BOARD # h board of squares
ACS_BTEE + v bottom tee
ACS_BULLET o ~ bullet
ACS_CKBOARD : a checker board (stipple)
ACS_DARROW v . arrow pointing down
ACS_DEGREE ' f degree symbol
ACS_DIAMOND + ` diamond
ACS_GEQUAL > > greater-than-or-equal-to
ACS_HLINE \- q horizontal line
ACS_LANTERN # i lantern symbol
ACS_LARROW < , arrow pointing left
ACS_LEQUAL < y less-than-or-equal-to
ACS_LLCORNER + m lower left-hand corner
ACS_LRCORNER + j lower right-hand corner
ACS_LTEE + t left tee
ACS_NEQUAL ! | not-equal
ACS_PI * { greek pi
ACS_PLMINUS # g plus/minus
ACS_PLUS + n plus
ACS_RARROW > + arrow pointing right
ACS_RTEE + u right tee
ACS_S1 \- o scan line 1
ACS_S3 \- p scan line 3
ACS_S7 \- r scan line 7
ACS_S9 \&_ s scan line 9
ACS_STERLING f } pound-sterling symbol
ACS_TTEE + w top tee
ACS_UARROW ^ \- arrow pointing up
ACS_ULCORNER + l upper left-hand corner
ACS_URCORNER + k upper right-hand corner
ACS_VLINE | x 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
successful completion, unless otherwise noted in the preceding routine
descriptions.
All routines return the integer \fBERR\fP upon failure and \fBOK\fP on success
(the SVr4 manuals specify only
\*(``an integer value other than \fBERR\fP\*('') upon successful completion,
unless otherwise noted in the preceding routine descriptions.
.PP
Functions with a \*(``mv\*('' prefix first perform a cursor movement using
\fBwmove\fP, and return an error if the position is outside the window,
or if the window pointer is null.
.PP
If it is not possible to add a complete character,
an error is returned:
.bP
If \fBscrollok\fP(3) is not enabled,
writing a character at the lower right margin succeeds.
However, an error is returned because
it is not possible to wrap to a new line
.bP
If an error is detected when converting a multibyte character to a sequence
of bytes,
or if it is not possible to add all of the resulting bytes in the window,
an error is returned.
.SH NOTES
Note that \fBaddch\fR, \fBmvaddch\fR, \fBmvwaddch\fR, and
\fBechochar\fR may be macros.
Note that \fBaddch\fP, \fBmvaddch\fP, \fBmvwaddch\fP, and
\fBechochar\fP may be macros.
.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.
.SS ACS Symbols
X/Open Curses states that the \fBACS_\fP definitions are \fBchar\fP constants.
For the wide-character implementation (see \fBcurs_add_wch\fP),
there are analogous \fBWACS_\fP definitions which are \fBcchar_t\fP constants.
Some implementations are problematic:
.bP
Some implementations define the ACS symbols to a constant
(such as Solaris), while others define those to entries in an array.
.IP
This implementation uses an array \fBacs_map\fP, as done in SVr4 curses.
NetBSD also uses an array, actually named \fB_acs_char\fP, with a \fB#define\fP
for compatibility.
.bP
HPUX curses equates some of the \fBACS_\fP symbols
to the analogous \fBWACS_\fP symbols as if the \fBACS_\fP symbols were
wide characters.
The misdefined symbols are the arrows
and other symbols which are not used for line-drawing.
.bP
X/Open Curses (issues 2 through 7) has a typographical error
for the ACS_LANTERN symbol, equating its \*(``VT100+ Character\*(''
to \fBI\fP (capital I), while the header files for SVr4 curses
and the various implementations use \fBi\fP (lowercase).
.IP
None of the terminal descriptions on Unix platforms use uppercase-I,
except for Solaris (i.e., \fBscreen\fP's terminal description,
apparently based on the X/Open documentation around 1995).
On the other hand, the terminal description \fIgs6300\fP
(AT&T PC6300 with EMOTS Terminal Emulator) uses lowercase-i.
.LP
Some ACS symbols
(ACS_S3,
@ -152,32 +245,79 @@ ACS_PI,
ACS_NEQUAL,
ACS_STERLING)
were not documented in
any publicly released System V. However, many publicly available terminfos
include \fBacsc\fR strings in which their key characters (pryz{|}) are
any publicly released System V.
However, many publicly available terminfos
include \fBacsc\fP 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).
to light.
The ACS-prefixed names for them were invented for \fBncurses\fP(3).
.LP
The \fBTABSIZE\fR variable is implemented in some versions of curses,
but is not part of X/Open curses.
The \fIdisplayed\fP values for the \fBACS_\fP and \fBWACS_\fP constants
depend on
.bP
the library configuration, i.e., \fBncurses\fP versus \fBncursesw\fP,
where the latter is capable of displaying Unicode while the former is not, and
.bP
whether the \fIlocale\fP uses UTF-8 encoding.
.LP
If \fIch\fR is a carriage return,
In certain cases, the terminal is unable to display line-drawing characters
except by using UTF-8 (see the discussion of \fBNCURSES_NO_UTF8_ACS\fP in
ncurses(3)).
.SS Character Set
X/Open Curses assumes that the parameter passed to \fBwaddch\fP contains
a single character.
As discussed in \fBcurs_attr\fP(3), that character may have been
more than eight bits in an SVr3 or SVr4 implementation,
but in the X/Open Curses model, the details are not given.
The important distinction between SVr4 curses and X/Open Curses is
that the non-character information (attributes and color) was
separated from the character information which is packed in a \fBchtype\fP
to pass to \fBwaddch\fP.
.PP
In this implementation, \fBchtype\fP holds an eight-bit character.
But ncurses allows multibyte characters to be passed in a succession
of calls to \fBwaddch\fP.
The other implementations do not do this;
a call to \fBwaddch\fP passes exactly one character
which may be rendered as one or more cells on the screen
depending on whether it is printable.
.PP
Depending on the locale settings,
ncurses will inspect the byte passed in each call to \fBwaddch\fP,
and check if the latest call will continue a multibyte sequence.
When a character is \fIcomplete\fP,
ncurses displays the character and moves to the next position in the screen.
.PP
If the calling application interrupts the succession of bytes in
a multibyte character by moving the current location (e.g., using \fBwmove\fP),
ncurses discards the partially built character,
starting over again.
.PP
For portability to other implementations,
do not rely upon this behavior:
.bP
check if a character can be represented as a single byte in the current locale
before attempting call \fBwaddch\fP, and
.bP
call \fBwadd_wch\fP for characters which cannot be handled by \fBwaddch\fP.
.SS TABSIZE
The \fBTABSIZE\fP variable is implemented in SVr4 and other versions of curses,
but is not part of X/Open curses
(see \fBcurs_variables\fP(3) for more details).
.LP
If \fIch\fP 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),
\fBputc\fR(3).
\fBcurses\fP(3),
\fBcurs_attr\fP(3),
\fBcurs_clear\fP(3),
\fBcurs_inch\fP(3),
\fBcurs_outopts\fP(3),
\fBcurs_refresh\fP(3),
\fBcurs_variables\fP(3),
\fBputc\fP(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:
.\"# mode:nroff
.\"# fill-column:79
.\"# End:
\fBcurs_add_wch\fP(3).

View file

@ -1,7 +1,8 @@
.\" $OpenBSD: curs_addchstr.3,v 1.9 2010/01/12 23:21:58 nicm Exp $
.\" $OpenBSD: curs_addchstr.3,v 1.10 2023/10/17 09:52:08 nicm Exp $
.\"
.\"***************************************************************************
.\" Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. *
.\" Copyright 2019-2021,2022 Thomas E. Dickey *
.\" Copyright 1998-2012,2017 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,74 +29,91 @@
.\" authorization. *
.\"***************************************************************************
.\"
.\" $Id: curs_addchstr.3,v 1.9 2010/01/12 23:21:58 nicm Exp $
.TH curs_addchstr 3 ""
.\" $Id: curs_addchstr.3,v 1.10 2023/10/17 09:52:08 nicm Exp $
.TH curs_addchstr 3 2022-02-12 "ncurses 6.4" "Library calls"
.ie \n(.g .ds `` \(lq
.el .ds `` ``
.ie \n(.g .ds '' \(rq
.el .ds '' ''
.de bP
.ie n .IP \(bu 4
.el .IP \(bu 2
..
.na
.hy 0
.SH NAME
\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
\fBaddchstr\fP,
\fBaddchnstr\fP,
\fBwaddchstr\fP,
\fBwaddchnstr\fP,
\fBmvaddchstr\fP,
\fBmvaddchnstr\fP,
\fBmvwaddchstr\fP,
\fBmvwaddchnstr\fP \- add a string of characters (and attributes) to a \fBcurses\fP window
.ad
.hy
.SH SYNOPSIS
\fB#include <curses.h>\fR
.nf
\fB#include <curses.h>\fP
.PP
\fBint addchstr(const chtype *chstr);\fR
\fBint addchstr(const chtype *\fIchstr\fB);\fR
.br
\fBint addchnstr(const chtype *chstr, int n);\fR
\fBint addchnstr(const chtype *\fIchstr\fB, int \fIn\fB);\fR
.br
\fBint waddchstr(WINDOW *win, const chtype *chstr);\fR
\fBint waddchstr(WINDOW *\fIwin\fB, const chtype *\fIchstr\fB);\fR
.br
\fBint waddchnstr(WINDOW *win, const chtype *chstr, int n);\fR
\fBint waddchnstr(WINDOW *\fIwin\fB, const chtype *\fIchstr\fB, int \fIn\fB);\fR
.sp
\fBint mvaddchstr(int \fIy\fB, int \fIx\fB, const chtype *\fIchstr\fB);\fR
.br
\fBint mvaddchstr(int y, int x, const chtype *chstr);\fR
\fBint mvaddchnstr(int \fIy\fB, int \fIx\fB, const chtype *\fIchstr\fB, int \fIn\fB);\fR
.br
\fBint mvaddchnstr(int y, int x, const chtype *chstr, int n);\fR
\fBint mvwaddchstr(WINDOW *\fIwin\fB, int \fIy\fB, int \fIx\fB, const chtype *\fIchstr\fB);\fR
.br
\fBint mvwaddchstr(WINDOW *win, int y, int x, const chtype *chstr);\fR
.br
\fBint mvwaddchnstr(WINDOW *win, int y, int x, const chtype *chstr, int n);\fR
\fBint mvwaddchnstr(WINDOW *\fIwin\fB, int \fIy\fB, int \fIx\fB, const chtype *\fIchstr\fB, int \fIn\fB);\fR
.fi
.SH DESCRIPTION
These routines copy \fIchstr\fR into the window image structure at and after
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.
These functions copy the (null-terminated)
\fIchstr\fP array
into the window image structure
starting at the current cursor position.
The four functions with \fIn\fP as the last
argument copy at most \fIn\fP elements,
but no more than will fit on the line.
If \fBn\fP=\fB\-1\fP then the whole array 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 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,
The window cursor is \fInot\fP advanced.
These functions work faster than \fBwaddnstr\fP.
On the other hand:
.bP
they do not perform checking
(such as for the newline, backspace, or carriage return characters),
.bP
they do not advance the current cursor position,
.bP
they do not expand other control characters to ^-escapes, and
.bP
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.
.SH RETURN VALUE
All functions return the integer \fBERR\fP upon failure and \fBOK\fP on success.
.PP
X/Open does not define any error conditions.
This implementation returns an error
if the window pointer is null.
.PP
Functions with a \*(``mv\*('' prefix first perform a cursor movement using
\fBwmove\fP, and return an error if the position is outside the window,
or if the window pointer is null.
.SH NOTES
Note that all routines except \fBwaddchnstr\fR may be macros.
All functions except \fBwaddchnstr\fP may be macros.
.SH PORTABILITY
These entry points are described in the XSI Curses standard, Issue 4.
.SH SEE ALSO
\fBcurses\fR(3).
\fBcurses\fP(3),
\fBcurs_addstr\fP(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:
.\"# mode:nroff
.\"# fill-column:79
.\"# End:
\fBcurs_add_wchstr\fP(3).

Some files were not shown because too many files have changed in this diff Show more