From: Eli Zaretskii <eliz@gnu.org>
To: tromey@redhat.com, gdb-patches@sources.redhat.com
Subject: Re: Configuring gdb_wchar.h
Date: Sat, 18 Apr 2009 09:47:00 -0000 [thread overview]
Message-ID: <83prfai991.fsf@gnu.org> (raw)
In-Reply-To: <83hc0plli1.fsf@gnu.org>
> Date: Wed, 15 Apr 2009 23:17:42 +0300
> From: Eli Zaretskii <eliz@gnu.org>
> Cc: gdb-patches@sources.redhat.com
>
> > Cc: gdb-patches@sources.redhat.com
> > From: Tom Tromey <tromey@redhat.com>
> > Date: Wed, 15 Apr 2009 13:52:50 -0600
> >
> > >>>>> "Eli" == Eli Zaretskii <eliz@gnu.org> writes:
> >
> > Tom> If there is a way to detect the current DOS codepage, and if that is
> > Tom> equivalent to the notion of the host charset (I don't know), then we
> > Tom> could put the needed code into _initialize_charset.
> >
> > Eli> There's a system call to do that, yes. Perhaps I should just write a
> > Eli> limited emulation of nl_langinfo which will do the job. That would
> > Eli> avoid ugly system-dependent code in charset.c. WDYT?
> >
> > Either way is fine by me.
> >
> > libiconv also includes "libcharset", which includes a locale_charset
> > function to do this. So, we could use that if it is available. I
> > couldn't immediately tell when that was added to the libiconv package.
>
> OK, I will look into both possibilities and see what I come up with.
Here's what I finally ended up with. I decided to write an emulation
of nl_langinfo, instead of using locale_charset, because of these
reasons:
. The DJGPP port of locale_charset returns an empty string or
"ASCII" (depending on the version), if none of the environment
variables LC_ALL, LC_TYPE, or LANG is defined. It ought to fall
back on the DOS codepage, but it doesn't.
. Using locale_charset needs a change in the configury (to link
against libcharset), which I wanted to avoid. If GDB ends up
using locale_charset, and thus the necessary configury stuff will
be added anyway, I might reconsider (e.g., I could include a call
to locale_charset inside the emulated nl_langinfo).
. If the appropriate LC_* variables are set in the environment, then
using locale_charset is better than just having an nl_langinfo
that always returns the system codepage, but for GDB, this is only
marginally better, and can easily be fixed by a simple command or
a line in gdb.ini.
If there are no objections, I will commit the patch below.
Thanks.
2009-04-17 Eli Zaretskii <eliz@gnu.org>
* config/djgpp/config.sed (am_cv_langinfo_codeset)
(bash_cv_langinfo_codeset, ac_cv_header_nl_types_h): Set to "yes"
in all configure scripts that define ac_cv_env_CPP_value.
* go32-nat.c (dos_codepage, nl_langinfo): New functions.
Include langinfo.h.
* config/djgpp/nl_types.h: New file.
* config/djgpp/langinfo.h: New file.
* config/i386/go32.mh (MH_CFLAGS): Add $(srcdir)/config/djgpp.
--- go32-nat.c~1 2009-04-11 19:55:40.984375000 +0300
+++ go32-nat.c 2009-04-18 12:09:08.503000000 +0300
@@ -53,6 +53,8 @@
#include <debug/redir.h>
#endif
+#include <langinfo.h>
+
#if __DJGPP_MINOR__ < 3
/* This code will be provided from DJGPP 2.03 on. Until then I code it
here */
@@ -938,6 +940,47 @@
strcpy (gdbinit, "gdb.ini");
}
+/* Return the current DOS codepage number. */
+static int
+dos_codepage (void)
+{
+ __dpmi_regs regs;
+
+ regs.x.ax = 0x6601;
+ __dpmi_int (0x21, ®s);
+ if (!(regs.x.flags & 1))
+ return regs.x.bx & 0xffff;
+ else
+ return 437; /* default */
+}
+
+/* Limited emulation of `nl_langinfo', for charset.c. */
+char *
+nl_langinfo (nl_item item)
+{
+ char *retval;
+
+ switch (item)
+ {
+ case CODESET:
+ {
+ /* 8 is enough for SHORT_MAX + "CP" + null. */
+ char buf[8];
+ int blen = sizeof (buf);
+ int needed = snprintf (buf, blen, "CP%d", dos_codepage ());
+
+ if (needed > blen) /* should never happen */
+ buf[0] = 0;
+ retval = xstrdup (buf);
+ }
+ break;
+ default:
+ retval = xstrdup ("");
+ break;
+ }
+ return retval;
+}
+
unsigned short windows_major, windows_minor;
/* Compute the version Windows reports via Int 2Fh/AX=1600h. */
--- config/djgpp/config.s~1 2009-04-10 17:01:57.221500000 +0300
+++ config/djgpp/config.sed 2009-04-18 10:45:48.393625000 +0300
@@ -25,6 +25,12 @@
s,config\\.h\\.in,config.h-in,g;t t\
s,po2tbl\\.sed\\.in,po2tblsed.in,g;t t
+# We have an emulation of nl_langinfo in go32-nat.c that supports CODESET.
+/^ac_cv_env_CPP_value=/a\
+am_cv_langinfo_codeset=yes\
+bash_cv_langinfo_codeset=yes\
+ac_cv_header_nl_types_h=yes
+
# Prevent splitting of config.status substitutions, because that
# might break multi-line sed commands.
/ac_max_sed_lines=[0-9]/s,=.*$,=`sed -n "$=" $tmp/subs.sed`,
--- /dev/null 1970-01-01 02:00:00.000000000 +0200
+++ config/djgpp/nl_types.h 2009-04-17 15:54:34.440500000 +0300
@@ -0,0 +1,25 @@
+/* nl_types.h for DJGPP.
+ Copyright (C) 2009 Free Software Foundation, Inc.
+ Written by Eli Zaretskii.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _NL_TYPES_H
+#define _NL_TYPES_H
+
+typedef int nl_item;
+
+#endif /* _NL_TYPES_H */
--- /dev/null 1970-01-01 02:00:00.000000000 +0200
+++ config/djgpp/langinfo.h 2009-04-17 15:54:43.081125000 +0300
@@ -0,0 +1,35 @@
+/* langinfo.h file for DJGPP.
+ Copyright (C) 2009 Free Software Foundation, Inc.
+ Written by Eli Zaretskii.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _LANGINFO_H
+#define _LANGINFO_H
+
+#include <nl_types.h>
+
+enum {
+ CODESET,
+ /* Number of enumerated values. */
+ _NL_NUM
+};
+
+#define CODESET CODESET
+
+extern char *nl_langinfo (nl_item);
+
+#endif /* _LANGINFO_H */
--- config/i386/go32.m~0 2005-05-14 16:13:23.000000000 +0300
+++ config/i386/go32.mh 2009-04-17 14:47:12.393625000 +0300
@@ -1,5 +1,7 @@
# Host: Intel x86 running DJGPP
-MH_CFLAGS=
+
+# We include several header files from config/djgpp
+MH_CFLAGS= -I$(srcdir)/config/djgpp
NAT_FILE= nm-go32.h
NATDEPFILES= go32-nat.o i386-nat.o
next prev parent reply other threads:[~2009-04-18 9:47 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-11 17:53 Eli Zaretskii
2009-04-13 17:54 ` Tom Tromey
2009-04-14 12:03 ` Eli Zaretskii
2009-04-14 16:31 ` Tom Tromey
2009-04-14 17:11 ` Eli Zaretskii
2009-04-14 17:42 ` Tom Tromey
2009-04-14 18:04 ` Eli Zaretskii
2009-04-14 18:15 ` Tom Tromey
2009-04-14 20:17 ` Eli Zaretskii
2009-04-15 0:23 ` Tom Tromey
2009-04-15 10:06 ` Eli Zaretskii
2009-04-15 14:01 ` Eli Zaretskii
2009-04-15 15:14 ` Tom Tromey
2009-04-15 15:33 ` Eli Zaretskii
2009-04-15 18:04 ` Tom Tromey
2009-04-15 19:20 ` Eli Zaretskii
2009-04-15 19:53 ` Tom Tromey
2009-04-15 20:18 ` Eli Zaretskii
2009-04-18 9:47 ` Eli Zaretskii [this message]
2009-04-18 17:28 ` Tom Tromey
2009-04-19 18:30 ` Eli Zaretskii
2009-04-15 15:08 ` Tom Tromey
2009-04-15 15:12 ` Pedro Alves
2009-04-15 15:26 ` Tom Tromey
2009-04-15 15:47 ` Eli Zaretskii
2009-04-15 18:07 ` Tom Tromey
2009-04-15 22:13 ` Tom Tromey
2009-04-18 11:05 ` Eli Zaretskii
2009-04-18 17:34 ` Tom Tromey
2009-04-18 20:56 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=83prfai991.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=gdb-patches@sources.redhat.com \
--cc=tromey@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox