Commit Graph

951 Commits

Author SHA1 Message Date
rin a1122fa99f Do not compile in whole fileio.c for LIBHACK.
Fix build failure when built as libhack, due to missing fileio.h.

IMO, this should be cleaner than generating fileio.h for {get,put}win(3),
that are useless for install media.
2021-09-07 12:36:57 +00:00
rin 43ea4784d7 PR lib/56388
For __newwin() and __resizewin(), the line hash was calculated as if
HAVE_WCHAR is disabled.

Fix this bug by refactoring __hash_line() function, which calculates
the line hash by an appropriate method.
2021-09-07 01:23:09 +00:00
rin 31a83dd923 Always autogen fileio.h.
Bump CURSES_LIB_MAJOR.CURSES_LIB_MINOR to 9.0 belatedly.
2021-09-06 15:17:25 +00:00
rin b09154d5e3 Style fixes most for __CTRACE(). 2021-09-06 07:45:48 +00:00
rin e149a10083 Unifdef DEBUG for CTRACE(). 2021-09-06 07:08:25 +00:00
rin 0bd3a62045 Expand __CTRACE() to __nothing #ifndef DEBUG.
Remove most of #ifdef DEBUG around __CTRACE() calls.

No binary changes, except for line numbers for assert().
2021-09-06 07:03:49 +00:00
rin 39c0485813 Fix old-style definition: curses_version() --> curses_version(void) 2021-09-06 02:50:43 +00:00
rin 19d0649ccf Fix old-style definition: use_default_colors() --> use_default_colors(void) 2021-09-06 02:48:54 +00:00
rillig 54391ee928 libcurses: fix usage of __warn_references
Since that macro can expand to an empty token list, it adds its own
semicolon as needed.  Removing the extra semicolon fixes the lint
warnings about empty declarations.  These empty declarations are a GCC
extension.
2021-08-15 15:12:36 +00:00
christos 596ba706cc This is a mess; always define MB_LEN_MAX so both the regular and libhack
version of curses compiles. Really we should not be defining MB_LEN_MAX here,
and include <limits.h> in curses_private.h to get it.
2021-08-15 12:39:39 +00:00
christos 9494102ed0 need limits.h 2021-08-15 11:54:12 +00:00
christos 1ac1056e8d Use MBL_LEN_MAX (constant) so that SSP works 2021-08-15 11:44:39 +00:00
nia 083e568bb3 curses: clarify standout as the "best" _supported_ highlighting mode
of the current terminal
2021-08-03 07:58:50 +00:00
nia e8507174be curses: clarify documentation regarding the standout attribute 2021-08-02 11:11:20 +00:00
nia 1515619f1b The BUGS sections is incorrect again for "modern" terminals.
For example, wscons and xterm both display standout differently to bold.
2021-07-26 20:17:09 +00:00
blymn d08b4150a2 Fix PR lib/55931
Only reset outcol if we actually emit a \n as cursor_down may not may
not put the cursor at the start of the next line.
2021-06-27 23:57:08 +00:00
christos 30911e5794 Fix SSP build 2021-06-27 16:24:52 +00:00
martin 042ecb94ba Fix printf format for size_t 2021-06-24 15:41:25 +00:00
blymn 5e680e5b3e Make sure we don't use wide char routines when DISABLE_WCHAR is in
effect.
2021-06-24 05:53:05 +00:00
blymn 73328adf3a Rework the fix for lib/56224.
Move the scroll check to _cursesi_addwchar
Perform the scroll check before updating the cursor location when
processing \n.
2021-06-22 07:49:09 +00:00
blymn e5cd7ade44 Fix how the slk are drawn by making sure we use ins_wchar in the
bottom left of the screen to avoid a scroll because this may cause
an ERR if scrollok is false.
2021-06-22 07:26:45 +00:00
blymn e204b5b4b7 Fix the debug output to stop spamming out the aline for row 0, we
may not be working on that row so the output is pointless.
2021-06-22 07:22:44 +00:00
blymn 98f6983ffd Correct a previous fix for PR lib/56224.
Use wdwitch to determine the width of a wide character on the screen not
the number from mbrtowc which is the number of bytes in the character.
Thanks to Michael Forney for spotting this.
2021-06-15 22:18:55 +00:00
mcf 21db06c179 Add missing newline to debug trace message
ok blymn@
2021-06-10 07:15:40 +00:00
blymn 7a398f9f51 Fix for PR lib/56224
Correct addstr behaviour so it truncates the string in the case where
a string is added on the bottom line of a window where scrolling is
disabled as per the SUSv2 specification.
2021-06-06 05:06:44 +00:00
mcf bd85fcf225 Fix initial line hash calculation for subwindows
lp->hash is not initialized at this point. Since the hash is
calculated in chunks using __hash_more(), it needs to be initialized
to 0 first (just as in doupdate()).

Detected with valgrind while running python's test suite when
debugging an unrelated issue.

ok uwe@
2021-06-01 00:59:01 +00:00
nia 70294c72b4 wresize: don't bound pads to the size of the screen
allows avoiding a workaround in aiomixer,

ok blymn uwe
2021-05-29 09:11:14 +00:00
uwe 21d563f5dc __newwin - fix BGWCOL initialization.
From Michael Forney in PR lib/56174
2021-05-15 11:06:07 +00:00
mrg ef48836c2e avoid accessing stack garbage.
on arm64eb resuming vi(1) would often crash.  in makech(), the 'csp'
variable is either set to current window data, or a local stack
variable's address '&blank'.  the window data has many lines of info
stored, and 'csp++' is used per line here.  unfortunately, a case
existed where 'csp++' operated on csp initialised from '&blank' which
eventually crashes when, on my display with 160 columns and 'csp + 155'
exceeds the mapped stack and crashes.

match the '!_cursesi_screen->curwin' conditional that initialises csp,
and avoid csp++ here.  assert() that csp != &blank in both places that
modify csp.

thanks to jdc@ and mlelstv@.

XXX: possibly also should avoid the putch() here as well.
2021-05-08 04:29:07 +00:00
rillig 609d11bc47 libcurses: fix wrong tab width for addch
In sysinst, the installation screen is indented with tabs.  Sysinst uses
msgc, which brings its own text layout engine.  This engine does not use
addbytes but addch.  In addch, the x position for each tab was advanced
twice as much as needed.  The menu items were thus not indented by 8
spaces but by 16, which caused an ugly line break in the German
translation.

This bug largely went unnoticed because most other applications use
addbytes instead, which worked fine all the time.  It had been
introduced somewhere between NetBSD 8.0 and NetBSD 9.0.

The code around this bug used aliased variables for win->curx and
win->cury a lot.  Getting this right is difficult and needs a thorough
test suite.  Even though libcurses has 201 tests, that is not nearly
enough to cover all the relations between the various functions in
libcurses that call each other, crossing API boundaries from internal
to external, doing character conversions on the way and juggling around
4 different types of characters (char, wchar_t, chtype, cchar_t).

The simplest fix was to remove all this aliasing, while keeping the
API the same.  If _cursesi_waddbytes is not considered part of the API,
it would be possible to replace px with win->curx in all places, same
for py and win->cury.

The complicated code with the aliasing may have been meant for
performance reasons, but it's hard to see any advantage if both points
of truth need to be synchronized all the time.

Libcurses can be built in 2 modes: with wide character support or
without (-DDISABLE_WCHAR).  The test suite only covers the variant with
wide characters.  The single-byte variant has to be tested manually.
Running sysinst with the single-byte libcurses produces the correct
layout.
2021-02-13 14:30:37 +00:00
rillig 76716cd400 curses.h: proofread, indent a bit more consistently 2021-02-13 10:37:00 +00:00
rillig a9a73810b2 curses_screen.3: fix typo 2021-02-07 23:00:57 +00:00
rillig ae30211ba7 libcurses: fix spelling in comment 2021-02-06 19:41:14 +00:00
rillig e89f2cb186 libncurses: fix grammar in manual page 2021-02-06 13:58:09 +00:00
uwe ccb2ee4b73 newwin - fix crash with negative ncols.
When support for negative nrows/ncols was added, one s/ncols/maxx/ was
missed so we ended up passing negative (i.e. huge unsigned) length
when hashing the line contents.

Reported by Naman Jain in PR lib/55484
2020-07-14 04:39:39 +00:00
uwe 70f6ed9ef6 Pads are not to be automatically refreshed on input.
X/Open Curses says in the documentation for newpad():

  Automatic refreshes of pads (e.g., from scrolling or echoing of
  input) do not occur.

And in the documentation for get*():

  If the current or specified window is not a pad, and it has been
  moved or modified since the last refresh operation, then it will be
  refreshed before another character is read.

From Michael Forney in PR lib/55457
2020-07-06 23:33:38 +00:00
uwe f6dea36d0e mvwins*(WINDOW *win, ...) functions - call wins* on win, not stdscr.
From Naman Jain in PR lib/55460.
2020-07-06 22:46:50 +00:00
uwe 71a0f0ceb5 wtouchln - verify/clip input parameters
From Naman Jain in PR lib/55454
2020-07-03 23:28:51 +00:00
uwe 939fb589cb setcchar - don't lose combining marks to a typo.
We copy len wchars but set the length field to 1, instead of len.
From Naman Jain in PR lib/55443
2020-07-02 23:43:01 +00:00
uwe 1765a45b05 hline, vline - don't lose attributes when using default character.
Make default (wide) and non-wide behavior match.  If the character
argument has (only) attributes set, use them with the default line
character.

In the wide case don't do the fallback in hline - it just calls
hline_set that needs to do it anyway.  Fix the latter to check the
wcwidth of the right character and avoid division by zero.
2020-07-01 02:57:01 +00:00
uwe 4eb5fad78b Oops. Fix y/x typo in the previous whline() fix for !HAVE_WCHAR. 2020-07-01 02:14:41 +00:00
uwe d9a8ae84b1 Fix indentation in the copyright.
Make it match its siblings in other files.
2020-06-30 21:27:18 +00:00
uwe 9c6a61e7ae whline - save/restore the y coordinate too.
Reaching the right side of the screen can cause a line wrap.
Forgot to apply the fix to the !HAVE_WCHAR case.
PR lib/55434
2020-06-30 21:10:13 +00:00
uwe 1eecb61d77 whline_set - save/restore the y coordinate too.
Reaching the right side of the screen can cause a line wrap.
PR lib/55434
2020-06-30 21:02:24 +00:00
simonb a5e6defa61 KNF nit. 2020-05-14 11:50:04 +00:00
wiz e9fe6f785f Fix synopsis, use more markup. 2020-03-23 16:14:20 +00:00
roy 41aea6ac80 Add missing man page for curses mouse functions. 2020-03-23 15:32:56 +00:00
roy bb2ce1fb3d curses: Add stubs for mouse functions
No mouse support actually included.
But that doesn't matter because most terms don't actually support a mouse.

We should look into hooking these into wsmouse(4) and xterm mouse
in the future.

Compatable with nCurses mouse API version 2.
2020-03-23 13:37:36 +00:00
uwe eea4ed980c werase, wclrtobot, wclrtoeol - make code even more similar.
Rename attr to battr to match bch and WINDOW::battr.
No functional change intended.
2020-03-15 01:18:43 +00:00
uwe 878e2e095f __NEED_ERASE - don't shadow __LDATA::attr with macro parameter name. 2020-03-15 01:12:47 +00:00
roy aadfdb111b terminfo: promote numeric parameters from short to int
POSIX mandates implementations must support upto a short but may exceed it.
When NetBSD terminfo was implemented, no terminfo description used over
a short, but because ncurses has supported ints for some time, some now do.

Infact, such a terminfo description was imported where colour pairs for
screen-256color went up to 65536 which exposed a bug in the existing
implementation where it set to zero. Because the number might mean
something more than a range, we need to be able to store it accurately.

This requires a version bump because whilst the API hasn't changed thanks
to C int promotion, the ABI has. Also the underlying database structure
has changed as well - we now store the numeric paramter inside a uint32_t
field rather than a uint16_t one.
Whilst this change can still read the old style database, the old one
cannot read the new one and thus we now maintain the database as
terminfo2.cdb, leaving the old library and database alone so old programs
still work fine.

libcurses, libfrom, libmenu and libpanel have also been bumped to
accomoate this change.
2020-03-13 15:19:24 +00:00
roy 66ae8b28c2 curses: wrap the erase logic in a macro
Easier to use, it's in one place and now hopefully everyone is happy.

X
2020-03-13 02:57:26 +00:00
roy 8a456320fe curses: use perror rather than err in initscr
libhack lacks err and perror is more portable.
2020-03-12 15:50:11 +00:00
roy d93d20bc2b curses: normalise erase logic with clrtoeol and clrtobot
Define WA_ATTRIBUTES as 0 for the non wide case just to make our code
easier to write.
2020-03-12 12:17:15 +00:00
roy 8e383c4d06 curses: note the change in initscr in our fine man page. 2020-03-12 11:38:28 +00:00
roy 63d07d6408 curses: Fix werase(3) wide character support
We need to consider erasing all attributes, not just WA_ATTRIBUTES.
Fixes PR lib/23910.

While here, make the function a little more readable.
2020-03-11 23:47:40 +00:00
roy 5e81f724dc curses: application should exit if initscr(3) fails
POSIX defines this behaviour here:
https://pubs.opengroup.org/onlinepubs/7908799/xcurses/initscr.html

Partial fix for PR lib/23910
2020-03-11 21:33:38 +00:00
rin 4ecd76e535 0x%p --> %p for non-external codes. 2020-02-24 12:20:29 +00:00
roy cc96515f67 curses: believe in unicorns
Hopefully this ends the bikeshed.
If you don't believe in unicorns, please #if 0 it out to preserve
the humour.
2019-09-03 13:43:34 +00:00
roy b02c2cea81 curses: Add __NetBSD_Curses_Version__
Similar to __NetBSD_Version__ from sys/param.h but has no
correlation to it or the ELF symver libcurses is built as.

If we say that v1 was everything prior to this, it makes sense to
start this from v2.
2019-09-03 10:36:17 +00:00
roy c977d4cfab curses(3): add curses_version()
Returns NetBSD-Curses %s
Where %s is the NetBSD version taken from sys/param.h

Discussed on tech-net@, only for ncurses compat.
2019-09-02 09:08:29 +00:00
sevan 7cc04b4007 typo 2019-07-28 14:28:50 +00:00
uwe 4753bc1e70 __slk_set_finalise - fix length vs. width confusion 2019-07-28 00:51:59 +00:00
uwe 96ffe7929a __slk_set - fix calculating "len" for HAVE_WCHAR 2019-07-28 00:15:38 +00:00
sevan 5442ac99a4 nit 2019-07-27 16:15:58 +00:00
sevan 09453b8368 list the wide variant of functions. 2019-07-27 16:00:02 +00:00
uwe 7cefafafd5 Put slk_color() undef #ifdef HAVE_WCHAR too. 2019-07-27 00:58:34 +00:00
uwe acf023e482 Put wide character functions under #ifdef HAVE_WCHAR 2019-07-27 00:46:43 +00:00
uwe 7e8b9e03e4 #ifdef HAVE_WCHAR around enhanced curses stuff. 2019-07-25 20:18:50 +00:00
blymn cb5c29f5ae Fix return for mvscanw to return ERR/OK instead of the number of
elements scanned, now matches SUSv2 specification

Bump lib major due to return change.
2019-06-30 22:16:20 +00:00
blymn febeea01e0 Fix typo for unknown key keyname return. 2019-06-11 10:17:24 +00:00
blymn 2a780e62ed Rework previous fix for getch cursor position when cursor is moved
without refresh.  If the window is not dirty but the window cursor
position does not match curscr then move the cursor.  This fixes
the issues seen in PR lib/54263.
2019-06-09 07:40:14 +00:00
blymn e2cfd49c61 Back out incorrect fix for PR 53617 and fix it in a different way.
Keep track of the cursor location, if getch is called without a refresh
and without pending updates (dirty windows) then move the cursor to the
correct location directly.  Doing this prevents unnecessary refreshes.
2019-05-20 22:17:41 +00:00
blymn 652cdcd214 Fix _cursesi_addwchar so that it performs line wrap. SUSv2 says
add_wch line wraps and updates position.  Since wrap is done we are
not past EOL.
2019-05-12 02:29:00 +00:00
blymn d63c9d29fb Add more debug to _wnoutrefresh 2019-05-12 02:19:23 +00:00
blymn 7d6b8c3110 Add/improve debug output for some routines. 2019-04-24 07:09:44 +00:00
roy 69f3641e49 printw: rework vw_printw so it uses open_memstream rather than funopen2
This makes it more portable as open_memstream is POSIX and fixes a
potential issue with wide characters not fully being printed
due to any buffer overflow.
2019-04-01 11:39:15 +00:00
roy fb513c8258 Minor adjustment to prior to match putch 2019-03-29 18:32:45 +00:00
roy c571d3a4f2 Use WCOL rather than wcwidth(3) as we should already know the width
during refresh.
Ensure the character width is not negative when advancing during refresh
(unlikely) and we actually have something to insert in the lower right
corner depending on terminal caps.

Fixes PR lib/54085
2019-03-29 16:56:58 +00:00
uwe f03d7d49dc winwrite - using addch() on individual bytes of e.g. UTF-8 encoding
doesn't work that well.  addstr() the whole buffer instead.  This is
still not enirely correct b/c printf can run out of stdio buffer
mid-character for very long output, but deal with it later.
2019-03-28 23:24:22 +00:00
uwe 5190e47618 winwrite - deobfuscate a bit. 2019-03-21 21:28:55 +00:00
rin 441ba19f0d Rename global variable "state" to "_cursesi_state".
Until now, if application happens to have a global variable of the same
name, it was overridden by curses routines. This is the scenario in
which aspell crashes when linked to our curses, reported in pkg/44005.

We need to wipe out global/static variables like "_cursesi_state" or
"wstate" for thread safety. But it would be a future task...

XXX pullup to netbsd-8 and netbsd-7
2019-03-14 00:36:06 +00:00
roy 4650f8774d Fix warn macro usage.
Thanks to rofl0r.
2019-02-24 20:20:18 +00:00
dholland 43fda370f5 At some point we lost the text that explains the difference between
clear() and erase(). Or possibly we never had any. Put some back.
Bump date.
2019-01-11 06:14:39 +00:00
uwe 5b2acdab92 _wnoutrefresh - extend current position checks.
Also verify that dwin->cury >= begy (ditto for x), i.e. for pads make
sure that the current position is after the beginning of the displayed
portion.  While here refactor the checks for better readability.

We should probably combine the y and x checks b/c if one of them is
not in the range, the current position as a whole is not in the range
and it doesn't make sense to pick and set just the y or just the x
part of it.
2019-01-06 04:27:53 +00:00
uwe aa9d3f22ec _wnoutrefresh - fix current position checks for pads
maxy is an absolute value and should not be adjusted for begy when we
check also absolute cury.  Note that this change does not affect
calculations for normal windows as for them we always pass zero for
begy.  Ditto for x.
2019-01-06 03:59:17 +00:00
uwe 182a153ef7 prefresh - fix current position calculations
The code was copy-pasted from wrefresh(), but for pads we need to
adjust for (pbegy, pbegx).

PR lib/53801
2019-01-06 03:46:11 +00:00
roy ae8e2e2858 curses: Fix inverted logic when drawing LR corner with auto margins
Thanks to M. Levinson.
2018-11-30 04:38:14 +00:00
wiz 9be4740cf8 Grammar improvements. 2018-11-24 11:04:39 +00:00
uwe 80d62aa1ec attron(), attroff() - don't take a shortcut. 2018-11-24 01:04:18 +00:00
uwe 3981bd4fdf wattr_set - turn off all wide attributes (fix unedited copy/paste). 2018-11-23 11:16:59 +00:00
uwe 19b437abe9 Rename the reserved argument from "opt" to "opts" to match SUS text. 2018-11-23 11:15:14 +00:00
uwe 44b007ca68 Refactor. Move code to turn attributes on/off into separate
functions.  Express both old and new functions to manipulate
attributes using those functions.  Check that the the new API's opts
argument (reserved by the standard for future use) is NULL and error
out if not (like getcchar/setcchar).  No functional change intended.
2018-11-23 11:11:59 +00:00
uwe 801bc96314 Drop a few redundant casts of a variable to its own type. 2018-11-22 23:37:31 +00:00
uwe 485cf0548e Move getattrs() and wcolor_set() so that they are with their peers and
so that wide and non-wide functions are in the same order.  While here,
make __wcolor_set() static.  No functional change intended.
2018-11-22 23:29:09 +00:00
uwe b717da4cab Drop HAVE_WCHAR ifdefs from code that is not even compiled with !HAVE_WCHAR.
We still try to mainain the ability to build our curses with
!HAVE_WCHAR, but it doesn't make sense to provide stubs for new wide
API functions that just error out when !HAVE_WCHAR.  Any code that
only uses old API (and can work with !HAVE_WCHAR curses) doesn't use
those new functions.  The code that uses new API obviosly cannot work
when all the new API is stubbed out.

So the plan is to drop the stubs.  This commit does that for files
that are not even compiled with !HAVE_WCHAR (not only those stubs are
useless, they were not even there to begin with).

Same object code is generated for the normal HAVE_WCHAR case.  Nothing
is even recompiled for !HAVE_WCHAR.

Ok by blymn@ jdc@ roy@
2018-11-22 22:16:45 +00:00
uwe e0a45a7a9d We need insstr.c for !HAVE_WCHAR too. 2018-11-22 22:00:49 +00:00
uwe 9d5d4061af Compare pointers to NULL, not to zero. 2018-11-20 22:02:31 +00:00
uwe 042640f557 Drop bogus cast. 2018-11-20 21:42:52 +00:00
uwe 039bdd2780 Don't hide assignments inside tests. 2018-11-20 21:41:31 +00:00