bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Converting cchar_t to wchar_t


From: Mike Gran
Subject: Re: Converting cchar_t to wchar_t
Date: Fri, 14 Jun 2019 11:19:01 -0700
User-agent: Mutt/1.11.3 (2019-02-01)

On Fri, Jun 14, 2019 at 11:32:06AM -0500, Bryan Christ wrote:
> This code works in Linux and FreeBSD but I suspect is not working on Mac OS
> because of how NCURSES_WACS() may be implemented on Mac OS.

Hi,

I think the canonical way of doing it would be something like the following.
Remember that a cchar_t may be more than one character, because a cchar_t
can represent more than one character overstriking the same location.

Regards,

Mike Gran

----

  // Given a cchar_t * named x
  attr_t attr;
  short color_pair;
  size_t len;

  len = getcchar (x, 0, 0, 0, 0);
  /* Starting from the patch on 2009/07/18, the length returned by
     getcchar includes the trailing NULL.  Prior to that, it did not
     include the trailing NULL. */
  if (NCURSES_VERSION_MAJOR > 5
     || (NCURSES_VERSION_MAJOR == 5 && NCURSES_VERSION_MINOR > 7)
     || (NCURSES_VERSION_MAJOR == 5 && NCURSES_VERSION_MINOR == 7
      && NCURSES_VERSION_PATCH >= 20090718))
         len--;

  wchar_t *wch = calloc(len + 1, sizeof(wchar_t));

  ret = getcchar (x, wch, &attr, &color_pair, NULL);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]