diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2023-10-17 09:52:12 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2023-10-17 09:52:12 +0000 |
commit | 4dd5152bda3754d6c8238063f70a240feb2e0e01 (patch) | |
tree | 6761e0e8227c4b726ec8793dfd89d53fcf7c2e8a /lib/libcurses/base/lib_slkset.c | |
parent | 19c1736b607cf07af1e272ef5638ff0d90b4faff (diff) |
Update ncurses and associated libraries (form, panel, menu) to
6.4-20230826 (from 5.7-20081102).
Based on result from Thomas Dickey's ncu2openbsd script and then
modified. Switches to the upstream tput. Major bump for the ncurses
libraries and for libedit and libreadline.
Help from tb, millert.
ok deraadt sthen
Diffstat (limited to 'lib/libcurses/base/lib_slkset.c')
-rw-r--r-- | lib/libcurses/base/lib_slkset.c | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/lib/libcurses/base/lib_slkset.c b/lib/libcurses/base/lib_slkset.c index 6958f8d2a9a..4a14d669161 100644 --- a/lib/libcurses/base/lib_slkset.c +++ b/lib/libcurses/base/lib_slkset.c @@ -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 |