diff mbox series

[v6,2/4] curses: Fixes compiler error that complain don't have langinfo.h on msys2/mingw

Message ID 20201001173230.829-3-luoyonggang@gmail.com
State Superseded
Headers show
Series Fixes curses on msys2/mingw | expand

Commit Message

罗勇刚(Yonggang Luo) Oct. 1, 2020, 5:32 p.m. UTC
msys2/mingw lacks the POSIX-required langinfo.h.

gcc test.c -DNCURSES_WIDECHAR -I/mingw64/include/ncursesw -pipe -lncursesw -lgnurx -ltre -lintl -liconv
test.c:4:10: fatal error: langinfo.h: No such file or directory
    4 | #include <langinfo.h>
      |          ^~~~~~~~~~~~
compilation terminated.

So we using g_get_codeset instead of nl_langinfo(CODESET)

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
---
 ui/curses.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Daniel P. Berrangé Oct. 2, 2020, 3:35 p.m. UTC | #1
On Fri, Oct 02, 2020 at 01:32:28AM +0800, Yonggang Luo wrote:
> msys2/mingw lacks the POSIX-required langinfo.h.

> 

> gcc test.c -DNCURSES_WIDECHAR -I/mingw64/include/ncursesw -pipe -lncursesw -lgnurx -ltre -lintl -liconv

> test.c:4:10: fatal error: langinfo.h: No such file or directory

>     4 | #include <langinfo.h>

>       |          ^~~~~~~~~~~~

> compilation terminated.

> 

> So we using g_get_codeset instead of nl_langinfo(CODESET)

> 

> Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>

> Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>

> ---

>  ui/curses.c | 10 +++++-----

>  1 file changed, 5 insertions(+), 5 deletions(-)

> 

> diff --git a/ui/curses.c b/ui/curses.c

> index a59b23a9cf..12bc682cf9 100644

> --- a/ui/curses.c

> +++ b/ui/curses.c

> @@ -30,7 +30,6 @@

>  #endif

>  #include <locale.h>

>  #include <wchar.h>

> -#include <langinfo.h>

>  #include <iconv.h>

>  

>  #include "qapi/error.h"

> @@ -526,6 +525,7 @@ static void font_setup(void)

>      iconv_t nativecharset_to_ucs2;

>      iconv_t font_conv;

>      int i;

> +    g_autofree gchar *local_codeset = g_get_codeset();

>  

>      /*

>       * Control characters are normally non-printable, but VGA does have

> @@ -566,14 +566,14 @@ static void font_setup(void)

>        0x25bc

>      };

>  

> -    ucs2_to_nativecharset = iconv_open(nl_langinfo(CODESET), "UCS-2");

> +    ucs2_to_nativecharset = iconv_open(local_codeset, "UCS-2");

>      if (ucs2_to_nativecharset == (iconv_t) -1) {

>          fprintf(stderr, "Could not convert font glyphs from UCS-2: '%s'\n",

>                          strerror(errno));

>          exit(1);

>      }

>  

> -    nativecharset_to_ucs2 = iconv_open("UCS-2", nl_langinfo(CODESET));

> +    nativecharset_to_ucs2 = iconv_open("UCS-2", local_codeset);

>      if (nativecharset_to_ucs2 == (iconv_t) -1) {

>          iconv_close(ucs2_to_nativecharset);

>          fprintf(stderr, "Could not convert font glyphs to UCS-2: '%s'\n",

> @@ -581,7 +581,7 @@ static void font_setup(void)

>          exit(1);

>      }

>  

> -    font_conv = iconv_open(nl_langinfo(CODESET), font_charset);

> +    font_conv = iconv_open(local_codeset, font_charset);

>      if (font_conv == (iconv_t) -1) {

>          iconv_close(ucs2_to_nativecharset);

>          iconv_close(nativecharset_to_ucs2);

> @@ -602,7 +602,7 @@ static void font_setup(void)

>      /* DEL */

>      convert_ucs(0x7F, 0x2302, ucs2_to_nativecharset);

>  

> -    if (strcmp(nl_langinfo(CODESET), "UTF-8")) {

> +    if (strcmp(local_codeset, "UTF-8")) {


If you're removing use of nl_langinfo / langinfo.h then you need
to also update configure, because it is checking for this function
and header file when validating curses library support.


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
罗勇刚(Yonggang Luo) Oct. 2, 2020, 4:38 p.m. UTC | #2
On Fri, Oct 2, 2020 at 11:36 PM Daniel P. Berrangé <berrange@redhat.com>
wrote:
>

> On Fri, Oct 02, 2020 at 01:32:28AM +0800, Yonggang Luo wrote:

> > msys2/mingw lacks the POSIX-required langinfo.h.

> >

> > gcc test.c -DNCURSES_WIDECHAR -I/mingw64/include/ncursesw -pipe

-lncursesw -lgnurx -ltre -lintl -liconv
> > test.c:4:10: fatal error: langinfo.h: No such file or directory

> >     4 | #include <langinfo.h>

> >       |          ^~~~~~~~~~~~

> > compilation terminated.

> >

> > So we using g_get_codeset instead of nl_langinfo(CODESET)

> >

> > Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>

> > Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>

> > ---

> >  ui/curses.c | 10 +++++-----

> >  1 file changed, 5 insertions(+), 5 deletions(-)

> >

> > diff --git a/ui/curses.c b/ui/curses.c

> > index a59b23a9cf..12bc682cf9 100644

> > --- a/ui/curses.c

> > +++ b/ui/curses.c

> > @@ -30,7 +30,6 @@

> >  #endif

> >  #include <locale.h>

> >  #include <wchar.h>

> > -#include <langinfo.h>

> >  #include <iconv.h>

> >

> >  #include "qapi/error.h"

> > @@ -526,6 +525,7 @@ static void font_setup(void)

> >      iconv_t nativecharset_to_ucs2;

> >      iconv_t font_conv;

> >      int i;

> > +    g_autofree gchar *local_codeset = g_get_codeset();

> >

> >      /*

> >       * Control characters are normally non-printable, but VGA does have

> > @@ -566,14 +566,14 @@ static void font_setup(void)

> >        0x25bc

> >      };

> >

> > -    ucs2_to_nativecharset = iconv_open(nl_langinfo(CODESET), "UCS-2");

> > +    ucs2_to_nativecharset = iconv_open(local_codeset, "UCS-2");

> >      if (ucs2_to_nativecharset == (iconv_t) -1) {

> >          fprintf(stderr, "Could not convert font glyphs from UCS-2:

'%s'\n",
> >                          strerror(errno));

> >          exit(1);

> >      }

> >

> > -    nativecharset_to_ucs2 = iconv_open("UCS-2", nl_langinfo(CODESET));

> > +    nativecharset_to_ucs2 = iconv_open("UCS-2", local_codeset);

> >      if (nativecharset_to_ucs2 == (iconv_t) -1) {

> >          iconv_close(ucs2_to_nativecharset);

> >          fprintf(stderr, "Could not convert font glyphs to UCS-2:

'%s'\n",
> > @@ -581,7 +581,7 @@ static void font_setup(void)

> >          exit(1);

> >      }

> >

> > -    font_conv = iconv_open(nl_langinfo(CODESET), font_charset);

> > +    font_conv = iconv_open(local_codeset, font_charset);

> >      if (font_conv == (iconv_t) -1) {

> >          iconv_close(ucs2_to_nativecharset);

> >          iconv_close(nativecharset_to_ucs2);

> > @@ -602,7 +602,7 @@ static void font_setup(void)

> >      /* DEL */

> >      convert_ucs(0x7F, 0x2302, ucs2_to_nativecharset);

> >

> > -    if (strcmp(nl_langinfo(CODESET), "UTF-8")) {

> > +    if (strcmp(local_codeset, "UTF-8")) {

>

> If you're removing use of nl_langinfo / langinfo.h then you need

> to also update configure, because it is checking for this function

> and header file when validating curses library support.

The change of configure are waiting for meson 0.56, so I didn't post that
yet And this patch
is a pre-request for msys2/mingw support and won't hurt other platform

We are converting everything to meson, so I am not willing to change
configure this time
>

>

> Regards,

> Daniel

> --

> |: https://berrange.com      -o-

https://www.flickr.com/photos/dberrange :|
> |: https://libvirt.org         -o-

https://fstop138.berrange.com :|
> |: https://entangle-photo.org    -o-

https://www.instagram.com/dberrange :|
>



--
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
<div dir="ltr"><br><br>On Fri, Oct 2, 2020 at 11:36 PM Daniel P. Berrangé &lt;<a href="mailto:berrange@redhat.com">berrange@redhat.com</a>&gt; wrote:<br>&gt;<br>&gt; On Fri, Oct 02, 2020 at 01:32:28AM +0800, Yonggang Luo wrote:<br>&gt; &gt; msys2/mingw lacks the POSIX-required langinfo.h.<br>&gt; &gt;<br>&gt; &gt; gcc test.c -DNCURSES_WIDECHAR -I/mingw64/include/ncursesw -pipe -lncursesw -lgnurx -ltre -lintl -liconv<br>&gt; &gt; test.c:4:10: fatal error: langinfo.h: No such file or directory<br>&gt; &gt;     4 | #include &lt;langinfo.h&gt;<br>&gt; &gt;       |          ^~~~~~~~~~~~<br>&gt; &gt; compilation terminated.<br>&gt; &gt;<br>&gt; &gt; So we using g_get_codeset instead of nl_langinfo(CODESET)<br>&gt; &gt;<br>&gt; &gt; Signed-off-by: Yonggang Luo &lt;<a href="mailto:luoyonggang@gmail.com">luoyonggang@gmail.com</a>&gt;<br>&gt; &gt; Reviewed-by: Gerd Hoffmann &lt;<a href="mailto:kraxel@redhat.com">kraxel@redhat.com</a>&gt;<br>&gt; &gt; ---<br>&gt; &gt;  ui/curses.c | 10 +++++-----<br>&gt; &gt;  1 file changed, 5 insertions(+), 5 deletions(-)<br>&gt; &gt;<br>&gt; &gt; diff --git a/ui/curses.c b/ui/curses.c<br>&gt; &gt; index a59b23a9cf..12bc682cf9 100644<br>&gt; &gt; --- a/ui/curses.c<br>&gt; &gt; +++ b/ui/curses.c<br>&gt; &gt; @@ -30,7 +30,6 @@<br>&gt; &gt;  #endif<br>&gt; &gt;  #include &lt;locale.h&gt;<br>&gt; &gt;  #include &lt;wchar.h&gt;<br>&gt; &gt; -#include &lt;langinfo.h&gt;<br>&gt; &gt;  #include &lt;iconv.h&gt;<br>&gt; &gt; <br>&gt; &gt;  #include &quot;qapi/error.h&quot;<br>&gt; &gt; @@ -526,6 +525,7 @@ static void font_setup(void)<br>&gt; &gt;      iconv_t nativecharset_to_ucs2;<br>&gt; &gt;      iconv_t font_conv;<br>&gt; &gt;      int i;<br>&gt; &gt; +    g_autofree gchar *local_codeset = g_get_codeset();<br>&gt; &gt; <br>&gt; &gt;      /*<br>&gt; &gt;       * Control characters are normally non-printable, but VGA does have<br>&gt; &gt; @@ -566,14 +566,14 @@ static void font_setup(void)<br>&gt; &gt;        0x25bc<br>&gt; &gt;      };<br>&gt; &gt; <br>&gt; &gt; -    ucs2_to_nativecharset = iconv_open(nl_langinfo(CODESET), &quot;UCS-2&quot;);<br>&gt; &gt; +    ucs2_to_nativecharset = iconv_open(local_codeset, &quot;UCS-2&quot;);<br>&gt; &gt;      if (ucs2_to_nativecharset == (iconv_t) -1) {<br>&gt; &gt;          fprintf(stderr, &quot;Could not convert font glyphs from UCS-2: &#39;%s&#39;\n&quot;,<br>&gt; &gt;                          strerror(errno));<br>&gt; &gt;          exit(1);<br>&gt; &gt;      }<br>&gt; &gt; <br>&gt; &gt; -    nativecharset_to_ucs2 = iconv_open(&quot;UCS-2&quot;, nl_langinfo(CODESET));<br>&gt; &gt; +    nativecharset_to_ucs2 = iconv_open(&quot;UCS-2&quot;, local_codeset);<br>&gt; &gt;      if (nativecharset_to_ucs2 == (iconv_t) -1) {<br>&gt; &gt;          iconv_close(ucs2_to_nativecharset);<br>&gt; &gt;          fprintf(stderr, &quot;Could not convert font glyphs to UCS-2: &#39;%s&#39;\n&quot;,<br>&gt; &gt; @@ -581,7 +581,7 @@ static void font_setup(void)<br>&gt; &gt;          exit(1);<br>&gt; &gt;      }<br>&gt; &gt; <br>&gt; &gt; -    font_conv = iconv_open(nl_langinfo(CODESET), font_charset);<br>&gt; &gt; +    font_conv = iconv_open(local_codeset, font_charset);<br>&gt; &gt;      if (font_conv == (iconv_t) -1) {<br>&gt; &gt;          iconv_close(ucs2_to_nativecharset);<br>&gt; &gt;          iconv_close(nativecharset_to_ucs2);<br>&gt; &gt; @@ -602,7 +602,7 @@ static void font_setup(void)<br>&gt; &gt;      /* DEL */<br>&gt; &gt;      convert_ucs(0x7F, 0x2302, ucs2_to_nativecharset);<br>&gt; &gt; <br>&gt; &gt; -    if (strcmp(nl_langinfo(CODESET), &quot;UTF-8&quot;)) {<br>&gt; &gt; +    if (strcmp(local_codeset, &quot;UTF-8&quot;)) {<br>&gt;<br>&gt; If you&#39;re removing use of nl_langinfo / langinfo.h then you need<br>&gt; to also update configure, because it is checking for this function<br>&gt; and header file when validating curses library support.<div>The change of configure are waiting for meson 0.56, so I didn&#39;t post that yet And this patch</div><div>is a pre-request for msys2/mingw support and won&#39;t hurt other platform</div><div><br></div><div>We are converting everything to meson, so I am not willing to change configure this time<br>&gt;<br>&gt;<br>&gt; Regards,<br>&gt; Daniel<br>&gt; --<br>&gt; |: <a href="https://berrange.com">https://berrange.com</a>      -o-    <a href="https://www.flickr.com/photos/dberrange">https://www.flickr.com/photos/dberrange</a> :|<br>&gt; |: <a href="https://libvirt.org">https://libvirt.org</a>         -o-            <a href="https://fstop138.berrange.com">https://fstop138.berrange.com</a> :|<br>&gt; |: <a href="https://entangle-photo.org">https://entangle-photo.org</a>    -o-    <a href="https://www.instagram.com/dberrange">https://www.instagram.com/dberrange</a> :|<br>&gt;<br><br><br>--<br>         此致<br>礼<br>罗勇刚<br>Yours<br>    sincerely,<br>Yonggang Luo</div></div>
Daniel P. Berrangé Oct. 2, 2020, 4:42 p.m. UTC | #3
On Sat, Oct 03, 2020 at 12:38:50AM +0800, 罗勇刚(Yonggang Luo) wrote:
> On Fri, Oct 2, 2020 at 11:36 PM Daniel P. Berrangé <berrange@redhat.com>
> wrote:
> >
> > On Fri, Oct 02, 2020 at 01:32:28AM +0800, Yonggang Luo wrote:
> > > msys2/mingw lacks the POSIX-required langinfo.h.
> > >
> > > gcc test.c -DNCURSES_WIDECHAR -I/mingw64/include/ncursesw -pipe
> -lncursesw -lgnurx -ltre -lintl -liconv
> > > test.c:4:10: fatal error: langinfo.h: No such file or directory
> > >     4 | #include <langinfo.h>
> > >       |          ^~~~~~~~~~~~
> > > compilation terminated.
> > >
> > > So we using g_get_codeset instead of nl_langinfo(CODESET)
> > >
> > > Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
> > > Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
> > > ---
> > >  ui/curses.c | 10 +++++-----
> > >  1 file changed, 5 insertions(+), 5 deletions(-)
> > >
> > > diff --git a/ui/curses.c b/ui/curses.c
> > > index a59b23a9cf..12bc682cf9 100644
> > > --- a/ui/curses.c
> > > +++ b/ui/curses.c
> > > @@ -30,7 +30,6 @@
> > >  #endif
> > >  #include <locale.h>
> > >  #include <wchar.h>
> > > -#include <langinfo.h>
> > >  #include <iconv.h>
> > >
> > >  #include "qapi/error.h"
> > > @@ -526,6 +525,7 @@ static void font_setup(void)
> > >      iconv_t nativecharset_to_ucs2;
> > >      iconv_t font_conv;
> > >      int i;
> > > +    g_autofree gchar *local_codeset = g_get_codeset();
> > >
> > >      /*
> > >       * Control characters are normally non-printable, but VGA does have
> > > @@ -566,14 +566,14 @@ static void font_setup(void)
> > >        0x25bc
> > >      };
> > >
> > > -    ucs2_to_nativecharset = iconv_open(nl_langinfo(CODESET), "UCS-2");
> > > +    ucs2_to_nativecharset = iconv_open(local_codeset, "UCS-2");
> > >      if (ucs2_to_nativecharset == (iconv_t) -1) {
> > >          fprintf(stderr, "Could not convert font glyphs from UCS-2:
> '%s'\n",
> > >                          strerror(errno));
> > >          exit(1);
> > >      }
> > >
> > > -    nativecharset_to_ucs2 = iconv_open("UCS-2", nl_langinfo(CODESET));
> > > +    nativecharset_to_ucs2 = iconv_open("UCS-2", local_codeset);
> > >      if (nativecharset_to_ucs2 == (iconv_t) -1) {
> > >          iconv_close(ucs2_to_nativecharset);
> > >          fprintf(stderr, "Could not convert font glyphs to UCS-2:
> '%s'\n",
> > > @@ -581,7 +581,7 @@ static void font_setup(void)
> > >          exit(1);
> > >      }
> > >
> > > -    font_conv = iconv_open(nl_langinfo(CODESET), font_charset);
> > > +    font_conv = iconv_open(local_codeset, font_charset);
> > >      if (font_conv == (iconv_t) -1) {
> > >          iconv_close(ucs2_to_nativecharset);
> > >          iconv_close(nativecharset_to_ucs2);
> > > @@ -602,7 +602,7 @@ static void font_setup(void)
> > >      /* DEL */
> > >      convert_ucs(0x7F, 0x2302, ucs2_to_nativecharset);
> > >
> > > -    if (strcmp(nl_langinfo(CODESET), "UTF-8")) {
> > > +    if (strcmp(local_codeset, "UTF-8")) {
> >
> > If you're removing use of nl_langinfo / langinfo.h then you need
> > to also update configure, because it is checking for this function
> > and header file when validating curses library support.
> The change of configure are waiting for meson 0.56, so I didn't post that
> yet And this patch
> is a pre-request for msys2/mingw support and won't hurt other platform
> 
> We are converting everything to meson, so I am not willing to change
> configure this time

I don't see why the configure change has any dependancy on meson 0.56.
It just requires you to remove the mentioned header file and function
from the configure check. This patch needs to include that or it is
incomplete IMHO

Regards,
Daniel
Paolo Bonzini Oct. 2, 2020, 5:46 p.m. UTC | #4
On 02/10/20 18:42, Daniel P. Berrangé wrote:
> I don't see why the configure change has any dependancy on meson 0.56.

> It just requires you to remove the mentioned header file and function

> from the configure check. This patch needs to include that or it is

> incomplete IMHO


I agree, moving the check to Meson is waiting for 0.56 but for now the
configure check needs to be maintained.

Paolo
罗勇刚(Yonggang Luo) Oct. 2, 2020, 5:47 p.m. UTC | #5
On Sat, Oct 3, 2020 at 12:42 AM Daniel P. Berrangé <berrange@redhat.com>
wrote:
>
> On Sat, Oct 03, 2020 at 12:38:50AM +0800, 罗勇刚(Yonggang Luo) wrote:
> > On Fri, Oct 2, 2020 at 11:36 PM Daniel P. Berrangé <berrange@redhat.com>
> > wrote:
> > >
> > > On Fri, Oct 02, 2020 at 01:32:28AM +0800, Yonggang Luo wrote:
> > > > msys2/mingw lacks the POSIX-required langinfo.h.
> > > >
> > > > gcc test.c -DNCURSES_WIDECHAR -I/mingw64/include/ncursesw -pipe
> > -lncursesw -lgnurx -ltre -lintl -liconv
> > > > test.c:4:10: fatal error: langinfo.h: No such file or directory
> > > >     4 | #include <langinfo.h>
> > > >       |          ^~~~~~~~~~~~
> > > > compilation terminated.
> > > >
> > > > So we using g_get_codeset instead of nl_langinfo(CODESET)
> > > >
> > > > Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
> > > > Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
> > > > ---
> > > >  ui/curses.c | 10 +++++-----
> > > >  1 file changed, 5 insertions(+), 5 deletions(-)
> > > >
> > > > diff --git a/ui/curses.c b/ui/curses.c
> > > > index a59b23a9cf..12bc682cf9 100644
> > > > --- a/ui/curses.c
> > > > +++ b/ui/curses.c
> > > > @@ -30,7 +30,6 @@
> > > >  #endif
> > > >  #include <locale.h>
> > > >  #include <wchar.h>
> > > > -#include <langinfo.h>
> > > >  #include <iconv.h>
> > > >
> > > >  #include "qapi/error.h"
> > > > @@ -526,6 +525,7 @@ static void font_setup(void)
> > > >      iconv_t nativecharset_to_ucs2;
> > > >      iconv_t font_conv;
> > > >      int i;
> > > > +    g_autofree gchar *local_codeset = g_get_codeset();
> > > >
> > > >      /*
> > > >       * Control characters are normally non-printable, but VGA does
have
> > > > @@ -566,14 +566,14 @@ static void font_setup(void)
> > > >        0x25bc
> > > >      };
> > > >
> > > > -    ucs2_to_nativecharset = iconv_open(nl_langinfo(CODESET),
"UCS-2");
> > > > +    ucs2_to_nativecharset = iconv_open(local_codeset, "UCS-2");
> > > >      if (ucs2_to_nativecharset == (iconv_t) -1) {
> > > >          fprintf(stderr, "Could not convert font glyphs from UCS-2:
> > '%s'\n",
> > > >                          strerror(errno));
> > > >          exit(1);
> > > >      }
> > > >
> > > > -    nativecharset_to_ucs2 = iconv_open("UCS-2",
nl_langinfo(CODESET));
> > > > +    nativecharset_to_ucs2 = iconv_open("UCS-2", local_codeset);
> > > >      if (nativecharset_to_ucs2 == (iconv_t) -1) {
> > > >          iconv_close(ucs2_to_nativecharset);
> > > >          fprintf(stderr, "Could not convert font glyphs to UCS-2:
> > '%s'\n",
> > > > @@ -581,7 +581,7 @@ static void font_setup(void)
> > > >          exit(1);
> > > >      }
> > > >
> > > > -    font_conv = iconv_open(nl_langinfo(CODESET), font_charset);
> > > > +    font_conv = iconv_open(local_codeset, font_charset);
> > > >      if (font_conv == (iconv_t) -1) {
> > > >          iconv_close(ucs2_to_nativecharset);
> > > >          iconv_close(nativecharset_to_ucs2);
> > > > @@ -602,7 +602,7 @@ static void font_setup(void)
> > > >      /* DEL */
> > > >      convert_ucs(0x7F, 0x2302, ucs2_to_nativecharset);
> > > >
> > > > -    if (strcmp(nl_langinfo(CODESET), "UTF-8")) {
> > > > +    if (strcmp(local_codeset, "UTF-8")) {
> > >
> > > If you're removing use of nl_langinfo / langinfo.h then you need
> > > to also update configure, because it is checking for this function
> > > and header file when validating curses library support.
> > The change of configure are waiting for meson 0.56, so I didn't post
that
> > yet And this patch
> > is a pre-request for msys2/mingw support and won't hurt other platform
> >
> > We are converting everything to meson, so I am not willing to change
> > configure this time
>
> I don't see why the configure change has any dependancy on meson 0.56.
> It just requires you to remove the mentioned header file and function
> from the configure check. This patch needs to include that or it is
> incomplete IMHO
>
Because the configure script change far more complicated than you imgaine.
And I post that before
> Regards,
> Daniel
> --
> |: https://berrange.com      -o-
https://www.flickr.com/photos/dberrange :|
> |: https://libvirt.org         -o-
https://fstop138.berrange.com :|
> |: https://entangle-photo.org    -o-
https://www.instagram.com/dberrange :|
>


--
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
<div dir="ltr"><br><br>On Sat, Oct 3, 2020 at 12:42 AM Daniel P. Berrangé &lt;<a href="mailto:berrange@redhat.com">berrange@redhat.com</a>&gt; wrote:<br>&gt;<br>&gt; On Sat, Oct 03, 2020 at 12:38:50AM +0800, 罗勇刚(Yonggang Luo) wrote:<br>&gt; &gt; On Fri, Oct 2, 2020 at 11:36 PM Daniel P. Berrangé &lt;<a href="mailto:berrange@redhat.com">berrange@redhat.com</a>&gt;<br>&gt; &gt; wrote:<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; On Fri, Oct 02, 2020 at 01:32:28AM +0800, Yonggang Luo wrote:<br>&gt; &gt; &gt; &gt; msys2/mingw lacks the POSIX-required langinfo.h.<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; gcc test.c -DNCURSES_WIDECHAR -I/mingw64/include/ncursesw -pipe<br>&gt; &gt; -lncursesw -lgnurx -ltre -lintl -liconv<br>&gt; &gt; &gt; &gt; test.c:4:10: fatal error: langinfo.h: No such file or directory<br>&gt; &gt; &gt; &gt;     4 | #include &lt;langinfo.h&gt;<br>&gt; &gt; &gt; &gt;       |          ^~~~~~~~~~~~<br>&gt; &gt; &gt; &gt; compilation terminated.<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; So we using g_get_codeset instead of nl_langinfo(CODESET)<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; Signed-off-by: Yonggang Luo &lt;<a href="mailto:luoyonggang@gmail.com">luoyonggang@gmail.com</a>&gt;<br>&gt; &gt; &gt; &gt; Reviewed-by: Gerd Hoffmann &lt;<a href="mailto:kraxel@redhat.com">kraxel@redhat.com</a>&gt;<br>&gt; &gt; &gt; &gt; ---<br>&gt; &gt; &gt; &gt;  ui/curses.c | 10 +++++-----<br>&gt; &gt; &gt; &gt;  1 file changed, 5 insertions(+), 5 deletions(-)<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; diff --git a/ui/curses.c b/ui/curses.c<br>&gt; &gt; &gt; &gt; index a59b23a9cf..12bc682cf9 100644<br>&gt; &gt; &gt; &gt; --- a/ui/curses.c<br>&gt; &gt; &gt; &gt; +++ b/ui/curses.c<br>&gt; &gt; &gt; &gt; @@ -30,7 +30,6 @@<br>&gt; &gt; &gt; &gt;  #endif<br>&gt; &gt; &gt; &gt;  #include &lt;locale.h&gt;<br>&gt; &gt; &gt; &gt;  #include &lt;wchar.h&gt;<br>&gt; &gt; &gt; &gt; -#include &lt;langinfo.h&gt;<br>&gt; &gt; &gt; &gt;  #include &lt;iconv.h&gt;<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt;  #include &quot;qapi/error.h&quot;<br>&gt; &gt; &gt; &gt; @@ -526,6 +525,7 @@ static void font_setup(void)<br>&gt; &gt; &gt; &gt;      iconv_t nativecharset_to_ucs2;<br>&gt; &gt; &gt; &gt;      iconv_t font_conv;<br>&gt; &gt; &gt; &gt;      int i;<br>&gt; &gt; &gt; &gt; +    g_autofree gchar *local_codeset = g_get_codeset();<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt;      /*<br>&gt; &gt; &gt; &gt;       * Control characters are normally non-printable, but VGA does have<br>&gt; &gt; &gt; &gt; @@ -566,14 +566,14 @@ static void font_setup(void)<br>&gt; &gt; &gt; &gt;        0x25bc<br>&gt; &gt; &gt; &gt;      };<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; -    ucs2_to_nativecharset = iconv_open(nl_langinfo(CODESET), &quot;UCS-2&quot;);<br>&gt; &gt; &gt; &gt; +    ucs2_to_nativecharset = iconv_open(local_codeset, &quot;UCS-2&quot;);<br>&gt; &gt; &gt; &gt;      if (ucs2_to_nativecharset == (iconv_t) -1) {<br>&gt; &gt; &gt; &gt;          fprintf(stderr, &quot;Could not convert font glyphs from UCS-2:<br>&gt; &gt; &#39;%s&#39;\n&quot;,<br>&gt; &gt; &gt; &gt;                          strerror(errno));<br>&gt; &gt; &gt; &gt;          exit(1);<br>&gt; &gt; &gt; &gt;      }<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; -    nativecharset_to_ucs2 = iconv_open(&quot;UCS-2&quot;, nl_langinfo(CODESET));<br>&gt; &gt; &gt; &gt; +    nativecharset_to_ucs2 = iconv_open(&quot;UCS-2&quot;, local_codeset);<br>&gt; &gt; &gt; &gt;      if (nativecharset_to_ucs2 == (iconv_t) -1) {<br>&gt; &gt; &gt; &gt;          iconv_close(ucs2_to_nativecharset);<br>&gt; &gt; &gt; &gt;          fprintf(stderr, &quot;Could not convert font glyphs to UCS-2:<br>&gt; &gt; &#39;%s&#39;\n&quot;,<br>&gt; &gt; &gt; &gt; @@ -581,7 +581,7 @@ static void font_setup(void)<br>&gt; &gt; &gt; &gt;          exit(1);<br>&gt; &gt; &gt; &gt;      }<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; -    font_conv = iconv_open(nl_langinfo(CODESET), font_charset);<br>&gt; &gt; &gt; &gt; +    font_conv = iconv_open(local_codeset, font_charset);<br>&gt; &gt; &gt; &gt;      if (font_conv == (iconv_t) -1) {<br>&gt; &gt; &gt; &gt;          iconv_close(ucs2_to_nativecharset);<br>&gt; &gt; &gt; &gt;          iconv_close(nativecharset_to_ucs2);<br>&gt; &gt; &gt; &gt; @@ -602,7 +602,7 @@ static void font_setup(void)<br>&gt; &gt; &gt; &gt;      /* DEL */<br>&gt; &gt; &gt; &gt;      convert_ucs(0x7F, 0x2302, ucs2_to_nativecharset);<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; -    if (strcmp(nl_langinfo(CODESET), &quot;UTF-8&quot;)) {<br>&gt; &gt; &gt; &gt; +    if (strcmp(local_codeset, &quot;UTF-8&quot;)) {<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; If you&#39;re removing use of nl_langinfo / langinfo.h then you need<br>&gt; &gt; &gt; to also update configure, because it is checking for this function<br>&gt; &gt; &gt; and header file when validating curses library support.<br>&gt; &gt; The change of configure are waiting for meson 0.56, so I didn&#39;t post that<br>&gt; &gt; yet And this patch<br>&gt; &gt; is a pre-request for msys2/mingw support and won&#39;t hurt other platform<br>&gt; &gt;<br>&gt; &gt; We are converting everything to meson, so I am not willing to change<br>&gt; &gt; configure this time<br>&gt;<br>&gt; I don&#39;t see why the configure change has any dependancy on meson 0.56.<br>&gt; It just requires you to remove the mentioned header file and function<br>&gt; from the configure check. This patch needs to include that or it is<br>&gt; incomplete IMHO<br>&gt;<div>Because the configure script change far more complicated than you imgaine. And I post that before<br>&gt; Regards,<br>&gt; Daniel<br>&gt; --<br>&gt; |: <a href="https://berrange.com">https://berrange.com</a>      -o-    <a href="https://www.flickr.com/photos/dberrange">https://www.flickr.com/photos/dberrange</a> :|<br>&gt; |: <a href="https://libvirt.org">https://libvirt.org</a>         -o-            <a href="https://fstop138.berrange.com">https://fstop138.berrange.com</a> :|<br>&gt; |: <a href="https://entangle-photo.org">https://entangle-photo.org</a>    -o-    <a href="https://www.instagram.com/dberrange">https://www.instagram.com/dberrange</a> :|<br>&gt;<br><br><br>--<br>         此致<br>礼<br>罗勇刚<br>Yours<br>    sincerely,<br>Yonggang Luo</div></div>
Paolo Bonzini Oct. 2, 2020, 5:49 p.m. UTC | #6
On 02/10/20 19:47, 罗勇刚(Yonggang Luo) wrote:
> Because the configure script change far more complicated than you
> imgaine. And I post that before

Daniel is literally asking for a two-line change:

diff --git a/configure b/configure
index fee5faa054..ffd72b571d 100755
--- a/configure
+++ b/configure
@@ -3671,7 +3671,6 @@ if test "$curses" != "no" ; then
 #include <locale.h>
 #include <curses.h>
 #include <wchar.h>
-#include <langinfo.h>
 int main(void) {
   const char *codeset;
   wchar_t wch = L'w';
@@ -3680,7 +3679,6 @@ int main(void) {
   addwstr(L"wide chars\n");
   addnwstr(&wch, 1);
   add_wch(WACS_DEGREE);
-  codeset = nl_langinfo(CODESET);
   return codeset != 0;
 }
 EOF

Paolo
罗勇刚(Yonggang Luo) Oct. 2, 2020, 5:54 p.m. UTC | #7
gotcha
On Sat, Oct 3, 2020 at 1:49 AM Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> On 02/10/20 19:47, 罗勇刚(Yonggang Luo) wrote:
> > Because the configure script change far more complicated than you
> > imgaine. And I post that before
>
> Daniel is literally asking for a two-line change:
>
> diff --git a/configure b/configure
> index fee5faa054..ffd72b571d 100755
> --- a/configure
> +++ b/configure
> @@ -3671,7 +3671,6 @@ if test "$curses" != "no" ; then
>  #include <locale.h>
>  #include <curses.h>
>  #include <wchar.h>
> -#include <langinfo.h>
>  int main(void) {
>    const char *codeset;
>    wchar_t wch = L'w';
> @@ -3680,7 +3679,6 @@ int main(void) {
>    addwstr(L"wide chars\n");
>    addnwstr(&wch, 1);
>    add_wch(WACS_DEGREE);
> -  codeset = nl_langinfo(CODESET);
>    return codeset != 0;
>  }
>  EOF
>
> Paolo
>


--
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
<div dir="ltr"><br>gotcha<br>On Sat, Oct 3, 2020 at 1:49 AM Paolo Bonzini &lt;<a href="mailto:pbonzini@redhat.com">pbonzini@redhat.com</a>&gt; wrote:<br>&gt;<br>&gt; On 02/10/20 19:47, 罗勇刚(Yonggang Luo) wrote:<br>&gt; &gt; Because the configure script change far more complicated than you<br>&gt; &gt; imgaine. And I post that before<br>&gt;<br>&gt; Daniel is literally asking for a two-line change:<br>&gt;<br>&gt; diff --git a/configure b/configure<br>&gt; index fee5faa054..ffd72b571d 100755<br>&gt; --- a/configure<br>&gt; +++ b/configure<br>&gt; @@ -3671,7 +3671,6 @@ if test &quot;$curses&quot; != &quot;no&quot; ; then<br>&gt;  #include &lt;locale.h&gt;<br>&gt;  #include &lt;curses.h&gt;<br>&gt;  #include &lt;wchar.h&gt;<br>&gt; -#include &lt;langinfo.h&gt;<br>&gt;  int main(void) {<br>&gt;    const char *codeset;<br>&gt;    wchar_t wch = L&#39;w&#39;;<br>&gt; @@ -3680,7 +3679,6 @@ int main(void) {<br>&gt;    addwstr(L&quot;wide chars\n&quot;);<br>&gt;    addnwstr(&amp;wch, 1);<br>&gt;    add_wch(WACS_DEGREE);<br>&gt; -  codeset = nl_langinfo(CODESET);<br>&gt;    return codeset != 0;<br>&gt;  }<br>&gt;  EOF<br>&gt;<br>&gt; Paolo<br>&gt;<br><br><br>--<br>         此致<br>礼<br>罗勇刚<br>Yours<br>    sincerely,<br>Yonggang Luo</div>
diff mbox series

Patch

diff --git a/ui/curses.c b/ui/curses.c
index a59b23a9cf..12bc682cf9 100644
--- a/ui/curses.c
+++ b/ui/curses.c
@@ -30,7 +30,6 @@ 
 #endif
 #include <locale.h>
 #include <wchar.h>
-#include <langinfo.h>
 #include <iconv.h>
 
 #include "qapi/error.h"
@@ -526,6 +525,7 @@  static void font_setup(void)
     iconv_t nativecharset_to_ucs2;
     iconv_t font_conv;
     int i;
+    g_autofree gchar *local_codeset = g_get_codeset();
 
     /*
      * Control characters are normally non-printable, but VGA does have
@@ -566,14 +566,14 @@  static void font_setup(void)
       0x25bc
     };
 
-    ucs2_to_nativecharset = iconv_open(nl_langinfo(CODESET), "UCS-2");
+    ucs2_to_nativecharset = iconv_open(local_codeset, "UCS-2");
     if (ucs2_to_nativecharset == (iconv_t) -1) {
         fprintf(stderr, "Could not convert font glyphs from UCS-2: '%s'\n",
                         strerror(errno));
         exit(1);
     }
 
-    nativecharset_to_ucs2 = iconv_open("UCS-2", nl_langinfo(CODESET));
+    nativecharset_to_ucs2 = iconv_open("UCS-2", local_codeset);
     if (nativecharset_to_ucs2 == (iconv_t) -1) {
         iconv_close(ucs2_to_nativecharset);
         fprintf(stderr, "Could not convert font glyphs to UCS-2: '%s'\n",
@@ -581,7 +581,7 @@  static void font_setup(void)
         exit(1);
     }
 
-    font_conv = iconv_open(nl_langinfo(CODESET), font_charset);
+    font_conv = iconv_open(local_codeset, font_charset);
     if (font_conv == (iconv_t) -1) {
         iconv_close(ucs2_to_nativecharset);
         iconv_close(nativecharset_to_ucs2);
@@ -602,7 +602,7 @@  static void font_setup(void)
     /* DEL */
     convert_ucs(0x7F, 0x2302, ucs2_to_nativecharset);
 
-    if (strcmp(nl_langinfo(CODESET), "UTF-8")) {
+    if (strcmp(local_codeset, "UTF-8")) {
         /* Non-Unicode capable, use termcap equivalents for those available */
         for (i = 0; i <= 0xFF; i++) {
             wchar_t wch[CCHARW_MAX];