[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 003/177] Make winnwstr() actually handle a negative argument.
From: |
G. Branden Robinson |
Subject: |
[PATCH 003/177] Make winnwstr() actually handle a negative argument. |
Date: |
Mon, 13 Jan 2025 11:14:08 -0600 |
inwstr(3X) says:
winwstr extracts a wide‐character string from a curses window win,
starting at the cursor and stopping at the end of the line, and
stores it in wstr, terminating it with a wide null character and
omitting any attributes and color pair identifier that curses
associates with each character. winnwstr does the same, but copies
at most n wide characters from win. An n of -1 implies no limit;
winnwstr then works like winwstr.
But the final sentence was not actually true; the function would skip
its primary loop if the `n` argument was negative, because a comparison
of the `count` of copied characters was always greater than that value.
Fix it.
* include/curses.wide: Mark `winwstr` as generated rather than
implemented. Define it as a macro analogous to `winstr` (expanding to
a `winnwstr()` call with a `-1` argument for `n`).
* ncurses/widechar/lib_inwstr.c (winnwstr): If `n` is less than zero,
set its value to the number of character cells on the line from the
cursor to the right margin times `CCHARW_MAX` (the maximimum number of
`wchar_t`s in a `cchar_t`.
(winwstr): Delete.
---
include/curses.wide | 3 ++-
ncurses/widechar/lib_inwstr.c | 18 ++++--------------
2 files changed, 6 insertions(+), 15 deletions(-)
diff --git a/include/curses.wide b/include/curses.wide
index 5efff15e4..5d1a848a3 100644
--- a/include/curses.wide
+++ b/include/curses.wide
@@ -213,7 +213,7 @@ extern NCURSES_EXPORT(int) winnwstr (WINDOW *, wchar_t *,
int); /* implemented
extern NCURSES_EXPORT(int) wins_nwstr (WINDOW *, const wchar_t *, int);
/* implemented */
extern NCURSES_EXPORT(int) wins_wch (WINDOW *, const cchar_t *); /*
implemented */
extern NCURSES_EXPORT(int) wins_wstr (WINDOW *, const wchar_t *); /*
generated:WIDEC */
-extern NCURSES_EXPORT(int) winwstr (WINDOW *, wchar_t *); /*
implemented */
+extern NCURSES_EXPORT(int) winwstr (WINDOW *, wchar_t *); /*
generated:WIDEC */
extern NCURSES_EXPORT(wchar_t*) wunctrl (cchar_t *); /*
implemented */
extern NCURSES_EXPORT(int) wvline_set (WINDOW *, const cchar_t *, int);
/* implemented */
@@ -261,6 +261,7 @@ extern NCURSES_EXPORT(wchar_t*) NCURSES_SP_NAME(wunctrl)
(SCREEN*, cchar_t *); /
#define wget_wstr(w,t) wgetn_wstr((w),(t),-1)
#define win_wchstr(w,c) win_wchnstr((w),(c),-1)
#define wins_wstr(w,t) wins_nwstr((w),(t),-1)
+#define winwstr(w,c) winnwstr((w),(c),-1)
#if !NCURSES_OPAQUE
#define wgetbkgrnd(win,wch) (NCURSES_OK_ADDR(wch) ? ((win) ?
(*(wch) = (win)->_bkgrnd) : *(wch), OK) : ERR)
diff --git a/ncurses/widechar/lib_inwstr.c b/ncurses/widechar/lib_inwstr.c
index d081e02c8..0c1317e1d 100644
--- a/ncurses/widechar/lib_inwstr.c
+++ b/ncurses/widechar/lib_inwstr.c
@@ -34,7 +34,7 @@
/*
** lib_inwstr.c
**
-** The routines winnwstr() and winwstr().
+** The routine winnwstr().
**
*/
@@ -57,6 +57,9 @@ winnwstr(WINDOW *win, wchar_t *wstr, int n)
getyx(win, row, col);
+ if (n < 0)
+ n = CCHARW_MAX * (win->_maxx - win->_curx + 1);
+
text = win->_line[row].text;
while (count < n && !done && count != ERR) {
@@ -92,16 +95,3 @@ winnwstr(WINDOW *win, wchar_t *wstr, int n)
}
returnCode(count);
}
-
-NCURSES_EXPORT(int)
-winwstr(WINDOW *win, wchar_t *wstr)
-{
- int result = ERR;
-
- T((T_CALLED("winwstr(%p,%p)"), (void *) win, (void *) wstr));
- if (win != NULL) {
- result = winnwstr(win, wstr,
- CCHARW_MAX * (win->_maxx - win->_curx + 1));
- }
- returnCode(result);
-}
--
2.30.2
signature.asc
Description: PGP signature
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH 003/177] Make winnwstr() actually handle a negative argument.,
G. Branden Robinson <=