Bug 287358 - [ncurses] Cannot handle termcap-style 'tputs("50")' on freebsd-current and 14.2-RELEASE due to wrong definition in lib/ncurses/tinfo/ncurses_cfg.h
Summary: [ncurses] Cannot handle termcap-style 'tputs("50")' on freebsd-current and 14...
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 15.0-CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-06-07 13:09 UTC by WATANABE Kazuhiro
Modified: 2025-06-07 15:01 UTC (History)
0 users

See Also:


Attachments
git diff for lib/ncurses/tinfo/ncurses_cfg.h (419 bytes, patch)
2025-06-07 13:09 UTC, WATANABE Kazuhiro
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description WATANABE Kazuhiro 2025-06-07 13:09:54 UTC
Created attachment 261063 [details]
git diff for lib/ncurses/tinfo/ncurses_cfg.h

On freebsd-current and 14.2-RELEASE, ports/games/nethack34 remains garbage
characters on the tty interface.  The x11 interface has not affected.

games/nethack{32,33}* and japanese/nethack34 has the same problem.  
games/nethack36 has not affected.  The other nethack variants has not tested.


* How to repeat (e.g. games/nethack34, Ranger-elf-male)

| 
| 
|                                            -------------
|                                            |..{....d...|
|                                ------    ##............|
|                                +....|    # |..........@|
|                                |.....##### |...........|
|                                |....|      -.-----------
|                                |....|
|                                |<...|
|                                |....|
|                                ------
| 
| Nabe the Tenderfoot          St:15 Dx:10 Co:12 In:15 Wi:13 Ch:8  Chaotic
| Dlvl:1  $:16 HP:14(14) Pw:3(3) AC:7  Exp:1

When I hit 'f' to shoot allows, the screen becomes corrupted:

| You shoot 3 elven arrows.
| 
|                                            -------------
|                                            |..{....d...|           .
|                                ------    ##............|
|                                +....|    # |.......d.)))))))..50
|                                |.....##### |...........|
|                                |....|      -.-----------
|                                |....|
|                                |<...|
|                                |....|
|                                ------
| 
| Nabe the Tenderfoot          St:15 Dx:10 Co:12 In:15 Wi:13 Ch:8  Chaotic
| Dlvl:1  $:16 HP:14(14) Pw:3(3) AC:7  Exp:1

Then if I hit '^R' to redraw the screen, it becomes normally:

| 
| 
|                                            -------------
|                                            |..{........|
|                                ------    ##............|
|                                +....|    # |..)....d..@|
|                                |.....##### |...........|
|                                |....|      -.-----------
|                                |....|
|                                |<...|
|                                |....|
|                                ------
| 
| Nabe the Tenderfoot          St:15 Dx:10 Co:12 In:15 Wi:13 Ch:8  Chaotic
| Dlvl:1  $:16 HP:14(14) Pw:3(3) AC:7  Exp:1


 * Workaround

If I build games/nethack34 with not system ncurses but devel/ncurses,
the problem has gone.


 * How to fix

It is caused by the code in tty_delay_output()@nethack-3.4.3/win/tty/termcap.c
like this:

> tputs("50", 1, xputc);

Described in BUGS section in curs_termcap(3X), it is interpreted as
busy-wait for 50 msec by termcap.

On ncurses these interpretation is enabled with adding '--enable-bsdpad'
argument to the configure script.  devel/ncurses has built with the option.

In June, 2024, ncurses-6.5 is imported to the FreeBSD main branch and
stable/14 branch.

And then committed "ncurses: reinstantiate bsd specific code" to the both
branch:

https://cgit.freebsd.org/src/commit/lib/ncurses/tinfo/ncurses_cfg.h?id=e402155e1ad7ec92a1fbd1712ce86c2ca43e1823
> diff --git a/lib/ncurses/tinfo/ncurses_cfg.h b/lib/ncurses/tinfo/ncurses_cfg.h
> index ced59c68e93c..33890f300310 100644
> --- a/lib/ncurses/tinfo/ncurses_cfg.h
> +++ b/lib/ncurses/tinfo/ncurses_cfg.h
> @@ -60,6 +60,9 @@
>  #define HAVE_LONG_FILE_NAMES 1
>  #define MIXEDCASE_FILENAMES 1
>  #define STDC_HEADERS 1
> +#define USE_GETCAP 1
> +#define USE_BSD_TPUTS 1
> +#define HAVE_BSD_CGETENT 1
>  #define HAVE_SYS_TYPES_H 1
>  #define HAVE_SYS_STAT_H 1
>  #define HAVE_STDLIB_H 1

Unfortunately, on ncurses-6.5 '--enable-bsdpad' defines not USE_BSD_TPUTS
but BSD_TPUTS.  The other two defines seems correct.

After apply the attached patch and rebuild the system, games/nethack34
(and others) works correctly in the tty interface.  The patch has tested
on freebsd-current and 14.2-RELEASE.
Comment 1 Mark Linimon freebsd_committer freebsd_triage 2025-06-07 15:01:30 UTC
^Triage: set Patch flag in attachment, which obsoletes use of "[patch]"
in Summary.