* PATCH: Readline for MinGW
@ 2005-06-08 17:43 Mark Mitchell
2005-06-12 7:33 ` Mark Kettenis
0 siblings, 1 reply; 7+ messages in thread
From: Mark Mitchell @ 2005-06-08 17:43 UTC (permalink / raw)
To: gdb-patches, bug-readline
With much help from the GDB and readline maintainers, it's *almost*
possible to use FSF GDB on MinGW. The missing bit is that readline
will not compile. I posted a previous hack, which was shot down; this
is my long-promised attempt to do a better job.
With these changes, it is possible to build GDB for MinGW with no
additional patches. Furthermore, readline works, in that using arrow
keys to access the history, and using key sequences like C-a for
cursor movement have their expected effects. I have not tried to
comprehensively test all readline key sequences, but I have not found
any problems.
The problems solved by this patch are:
1. Windows does not have termcap/curses/etc. So, we provide a stub
files that contains basic implementations of the relevant
functions. That permits the remainder of the code to continue
using the POSIX interfaces unchanged.
2. The arrow keys use different extended key sequences on Windows than
on POSIX systems; we introduce readline macros to transform the
Windows sequences into their POSIX equivalents. This approach
again confines the Windows-isms to a single point.
The patch itself isn't quite ready to commit (even if it met with
reviewer approval!) in that:
1. The stub file is called "rlnotty.c", which is horrible. I would
like to rename it "rlwin32tty.c".
2. The stub file is entirely lacking in comments.
Assuming the above changes, would this patch be acceptable? Or are
their problems requiring another trip back to the drawing board?
Thanks,
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
2005-03-28 Mark Mitchell <mark@codesourcery.com>
* Makefile.in (RLTTYOBJ): New variable.
(OBJECTS): Use RLTTYOBJ.
* configure.in: Handle MinGW when cross compiling.
Set RLTTYOBJ.
* configure: Regenerated.
* input.c (rl_getc): Use getch to read console input on
Windows.
* readline.c (bind_arrow_keys_internal): Translate
Windows keysequences into POSIX key sequences.
* rldefs.h (NEW_TTY_DRIVER): Do not define for Windows.
* rlnotty.c: New file.
Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/readline/Makefile.in,v
retrieving revision 1.5
retrieving revision 1.5.56.1
diff -c -5 -p -r1.5 -r1.5.56.1
*** Makefile.in 3 Mar 2003 14:45:42 -0000 1.5
--- Makefile.in 28 Mar 2005 19:34:24 -0000 1.5.56.1
*************** HSOURCES = readline.h rldefs.h chardefs.
*** 108,119 ****
ansi_stdlib.h tcap.h rlstdc.h xmalloc.h rlprivate.h rlshell.h \
rltypedefs.h rlmbutil.h
HISTOBJ = history.o histexpand.o histfile.o histsearch.o shell.o mbutil.o
TILDEOBJ = tilde.o
OBJECTS = readline.o vi_mode.o funmap.o keymaps.o parens.o search.o \
! rltty.o complete.o bind.o isearch.o display.o signals.o \
util.o kill.o undo.o macro.o input.o callback.o terminal.o \
text.o nls.o misc.o compat.o xmalloc.o $(HISTOBJ) $(TILDEOBJ) \
$(WCWIDTH_OBJ)
# The texinfo files which document this library.
--- 108,120 ----
ansi_stdlib.h tcap.h rlstdc.h xmalloc.h rlprivate.h rlshell.h \
rltypedefs.h rlmbutil.h
HISTOBJ = history.o histexpand.o histfile.o histsearch.o shell.o mbutil.o
TILDEOBJ = tilde.o
+ RLTTYOBJ = @RLTTYOBJ@
OBJECTS = readline.o vi_mode.o funmap.o keymaps.o parens.o search.o \
! $(RLTTYOBJ) complete.o bind.o isearch.o display.o signals.o \
util.o kill.o undo.o macro.o input.o callback.o terminal.o \
text.o nls.o misc.o compat.o xmalloc.o $(HISTOBJ) $(TILDEOBJ) \
$(WCWIDTH_OBJ)
# The texinfo files which document this library.
Index: configure.in
===================================================================
RCS file: /cvs/src/src/readline/configure.in,v
retrieving revision 1.6
retrieving revision 1.6.60.1
diff -c -5 -p -r1.6 -r1.6.60.1
*** configure.in 17 Dec 2002 02:52:32 -0000 1.6
--- configure.in 28 Mar 2005 19:34:27 -0000 1.6.60.1
*************** dnl load up the cross-building cache fil
*** 54,73 ****
dnl files as necessary
if test "x$cross_compiling" = "xyes"; then
case "${host}" in
*-cygwin*)
cross_cache=${srcdir}/cross-build/cygwin.cache
- if test -r "${cross_cache}"; then
- echo "loading cross-build cache file ${cross_cache}"
- . ${cross_cache}
- fi
LOCAL_CFLAGS="$LOCAL_CFLAGS -I${srcdir}/../libtermcap"
- unset cross_cache
;;
*) echo "configure: cross-compiling for a non-cygwin target is not supported" >&2
;;
esac
fi
if test "x$cross_compiling" = "xyes"; then
CROSS_COMPILING_FLAG=-DCROSS_COMPILING
else
--- 54,79 ----
dnl files as necessary
if test "x$cross_compiling" = "xyes"; then
case "${host}" in
*-cygwin*)
cross_cache=${srcdir}/cross-build/cygwin.cache
LOCAL_CFLAGS="$LOCAL_CFLAGS -I${srcdir}/../libtermcap"
;;
+ *-mingw32*)
+ cross_cache=${srcdir}/cross-build/mingw.cache
+ ;;
*) echo "configure: cross-compiling for a non-cygwin target is not supported" >&2
;;
esac
+
+ if test "x$cross_cache" != "x"; then
+ if test -r "${cross_cache}"; then
+ echo "loading cross-build cache file ${cross_cache}"
+ . ${cross_cache}
+ fi
+ unset cross_cache
+ fi
fi
if test "x$cross_compiling" = "xyes"; then
CROSS_COMPILING_FLAG=-DCROSS_COMPILING
else
*************** AC_SUBST(host_os)
*** 234,243 ****
--- 242,257 ----
AC_SUBST(LIBVERSION)
AC_SUBST(TERMCAP_LIB)
+ case "$host_os" in
+ mingw*) RLTTYOBJ=rlnotty.o ;;
+ *) RLTTYOBJ=rltty.o ;;
+ esac
+ AC_SUBST(RLTTYOBJ)
+
AC_OUTPUT([Makefile doc/Makefile examples/Makefile shlib/Makefile],
[
# Makefile uses this timestamp file to record whether config.h is up to date.
echo > stamp-h
])
Index: input.c
===================================================================
RCS file: /cvs/src/src/readline/input.c,v
retrieving revision 1.5
retrieving revision 1.5.60.2
diff -c -5 -p -r1.5 -r1.5.60.2
*** input.c 8 Dec 2002 22:31:37 -0000 1.5
--- input.c 8 Jun 2005 16:38:24 -0000 1.5.60.2
*************** rl_getc (stream)
*** 422,431 ****
--- 422,438 ----
int result;
unsigned char c;
while (1)
{
+ #ifdef __MINGW32__
+ /* On Windows, use a special routine to read a single character
+ from the console. (Otherwise, no characters are available
+ until the user hits the return key.) */
+ if (isatty (fileno (stream)))
+ return getch ();
+ #endif
result = read (fileno (stream), &c, sizeof (unsigned char));
if (result == sizeof (unsigned char))
return (c);
Index: readline.c
===================================================================
RCS file: /cvs/src/src/readline/readline.c,v
retrieving revision 1.7
retrieving revision 1.7.18.1
diff -c -5 -p -r1.7 -r1.7.18.1
*** readline.c 27 Jan 2004 22:25:15 -0000 1.7
--- readline.c 8 Jun 2005 16:38:25 -0000 1.7.18.1
*************** bind_arrow_keys_internal (map)
*** 866,875 ****
--- 866,891 ----
_rl_bind_if_unbound ("\033[0B", rl_backward_char);
_rl_bind_if_unbound ("\033[0C", rl_forward_char);
_rl_bind_if_unbound ("\033[0D", rl_get_next_history);
#endif
+ #ifdef __MINGW32__
+ /* Under Windows, when an extend key (like an arrow key) is
+ pressed, getch() will return 0xE0 followed by a code for the
+ extended key. We use macros to transform those into the normal
+ UNIX sequences for these keys. */
+
+ /* Up arrow. */
+ rl_macro_bind ("\340H", "\033[A", map);
+ /* Left arrow. */
+ rl_macro_bind ("\340K", "\033[D", map);
+ /* Right arrow. */
+ rl_macro_bind ("\340M", "\033[C", map);
+ /* Down arrow. */
+ rl_macro_bind ("\340P", "\033[B", map);
+ #endif
+
_rl_bind_if_unbound ("\033[A", rl_get_previous_history);
_rl_bind_if_unbound ("\033[B", rl_get_next_history);
_rl_bind_if_unbound ("\033[C", rl_forward_char);
_rl_bind_if_unbound ("\033[D", rl_backward_char);
_rl_bind_if_unbound ("\033[H", rl_beg_of_line);
Index: rldefs.h
===================================================================
RCS file: /cvs/src/src/readline/rldefs.h,v
retrieving revision 1.4
retrieving revision 1.4.60.1
diff -c -5 -p -r1.4 -r1.4.60.1
*** rldefs.h 8 Dec 2002 22:31:37 -0000 1.4
--- rldefs.h 28 Mar 2005 19:34:27 -0000 1.4.60.1
***************
*** 35,45 ****
#if defined (_POSIX_VERSION) && !defined (TERMIOS_MISSING)
# define TERMIOS_TTY_DRIVER
#else
# if defined (HAVE_TERMIO_H)
# define TERMIO_TTY_DRIVER
! # else
# define NEW_TTY_DRIVER
# endif
#endif
/* Posix macro to check file in statbuf for directory-ness.
--- 35,45 ----
#if defined (_POSIX_VERSION) && !defined (TERMIOS_MISSING)
# define TERMIOS_TTY_DRIVER
#else
# if defined (HAVE_TERMIO_H)
# define TERMIO_TTY_DRIVER
! # elif !defined (__MINGW32__)
# define NEW_TTY_DRIVER
# endif
#endif
/* Posix macro to check file in statbuf for directory-ness.
Index: rlnotty.c
===================================================================
RCS file: rlnotty.c
diff -N rlnotty.c
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- rlnotty.c 8 Jun 2005 17:29:15 -0000
***************
*** 0 ****
--- 1,101 ----
+ #define READLINE_LIBRARY
+
+ #if defined (HAVE_CONFIG_H)
+ # include <config.h>
+ #endif
+
+ #include <stdio.h>
+ #include "readline.h"
+ #include "rlprivate.h"
+
+ rl_vintfunc_t *rl_prep_term_function = rl_prep_terminal;
+ rl_voidfunc_t *rl_deprep_term_function = rl_deprep_terminal;
+
+ int
+ tgetent (buffer, termtype)
+ char *buffer;
+ char *termtype;
+ {
+ return -1;
+ }
+
+ int
+ tgetnum (name)
+ char *name;
+ {
+ return -1;
+ }
+
+ int
+ tgetflag (name)
+ char *name;
+ {
+ return -1;
+ }
+
+ char *
+ tgetstr (name, area)
+ char *name;
+ char **area;
+ {
+ return NULL;
+ }
+
+ int
+ tputs (string, nlines, outfun)
+ char *string;
+ int nlines;
+ int (*outfun) ();
+ {
+ while (*string)
+ outfun (*string++);
+ }
+
+ char *
+ tgoto (cap, col, row)
+ const char *cap;
+ int col;
+ int row;
+ {
+ return NULL;
+ }
+
+ int
+ _rl_disable_tty_signals ()
+ {
+ return 0;
+ }
+
+ int
+ _rl_restore_tty_signals ()
+ {
+ return 0;
+ }
+
+ void
+ rl_prep_terminal (meta_flag)
+ int meta_flag;
+ {
+ readline_echoing_p = 1;
+ return;
+ }
+
+ void
+ rl_deprep_terminal ()
+ {
+ return;
+ }
+
+ int
+ rl_restart_output (count, key)
+ int count;
+ int key;
+ {
+ return 0;
+ }
+
+ void
+ rl_tty_set_default_bindings (kmap)
+ Keymap kmap;
+ {
+ }
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: PATCH: Readline for MinGW
2005-06-08 17:43 PATCH: Readline for MinGW Mark Mitchell
@ 2005-06-12 7:33 ` Mark Kettenis
2005-06-12 8:43 ` Eli Zaretskii
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Mark Kettenis @ 2005-06-12 7:33 UTC (permalink / raw)
To: mark; +Cc: gdb-patches, bug-readline
Date: Wed, 8 Jun 2005 10:42:06 -0700
From: Mark Mitchell <mark@codesourcery.com>
The problems solved by this patch are:
1. Windows does not have termcap/curses/etc. So, we provide a stub
files that contains basic implementations of the relevant
functions. That permits the remainder of the code to continue
using the POSIX interfaces unchanged.
2. The arrow keys use different extended key sequences on Windows than
on POSIX systems; we introduce readline macros to transform the
Windows sequences into their POSIX equivalents. This approach
again confines the Windows-isms to a single point.
Huh? AFAIK, POSIX doesn't say anything about arrow keys or the
sequences produced by it. That's all determined by the terminal type.
Hmm, it looks like that readline simply hardcodes the ANSI sequences
for these keys instead of consulting termcap. Not your fault though.
But if it did consult termcap, you could provide a stub tgetent() that
did the mapping.
Incidentally, I find the way you find you write the macros a bit
confusing:
+ #ifdef __MINGW32__
+ /* Under Windows, when an extend key (like an arrow key) is
+ pressed, getch() will return 0xE0 followed by a code for the
+ extended key. We use macros to transform those into the normal
+ UNIX sequences for these keys. */
+
+ /* Up arrow. */
+ rl_macro_bind ("\340H", "\033[A", map);
+ /* Left arrow. */
+ rl_macro_bind ("\340K", "\033[D", map);
+ /* Right arrow. */
+ rl_macro_bind ("\340M", "\033[C", map);
+ /* Down arrow. */
+ rl_macro_bind ("\340P", "\033[B", map);
+ #endif
It has "\34" and "\033" on the same line so I get confused whether
"\34" is octal or not...
Also, I don't see any trace of the 0xE0 you mention in the comment.
Mark
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: PATCH: Readline for MinGW
2005-06-12 7:33 ` Mark Kettenis
@ 2005-06-12 8:43 ` Eli Zaretskii
2005-06-12 9:27 ` Mark Kettenis
2005-06-13 6:09 ` Mark Mitchell
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2005-06-12 8:43 UTC (permalink / raw)
To: Mark Kettenis; +Cc: mark, gdb-patches, bug-readline
> Date: Sun, 12 Jun 2005 09:31:22 +0200 (CEST)
> From: Mark Kettenis <mark.kettenis@xs4all.nl>
> CC: gdb-patches@sources.redhat.com, bug-readline@gnu.org
>
> 2. The arrow keys use different extended key sequences on Windows than
> on POSIX systems; we introduce readline macros to transform the
> Windows sequences into their POSIX equivalents. This approach
> again confines the Windows-isms to a single point.
>
> Huh? AFAIK, POSIX doesn't say anything about arrow keys or the
> sequences produced by it.
Yes, "ANSI" would be a better term here.
> + #ifdef __MINGW32__
> + /* Under Windows, when an extend key (like an arrow key) is
> + pressed, getch() will return 0xE0 followed by a code for the
> + extended key. We use macros to transform those into the normal
> + UNIX sequences for these keys. */
> +
> + /* Up arrow. */
> + rl_macro_bind ("\340H", "\033[A", map);
> + /* Left arrow. */
> + rl_macro_bind ("\340K", "\033[D", map);
> + /* Right arrow. */
> + rl_macro_bind ("\340M", "\033[C", map);
> + /* Down arrow. */
> + rl_macro_bind ("\340P", "\033[B", map);
> + #endif
>
> It has "\34" and "\033" on the same line so I get confused whether
> "\34" is octal or not...
That's not "\34", that's "\340". Which I guess explains the other
confusion:
> Also, I don't see any trace of the 0xE0 you mention in the comment.
340 in octal is E0 in hex. I.e., the up arrow, for example, produces
two characters: 0xE0 followed by H.
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: PATCH: Readline for MinGW
2005-06-12 8:43 ` Eli Zaretskii
@ 2005-06-12 9:27 ` Mark Kettenis
0 siblings, 0 replies; 7+ messages in thread
From: Mark Kettenis @ 2005-06-12 9:27 UTC (permalink / raw)
To: eliz; +Cc: mark.kettenis, mark, gdb-patches, bug-readline
Date: Sun, 12 Jun 2005 11:42:46 +0300
From: Eli Zaretskii <eliz@gnu.org>
> + #ifdef __MINGW32__
> + /* Under Windows, when an extend key (like an arrow key) is
> + pressed, getch() will return 0xE0 followed by a code for the
> + extended key. We use macros to transform those into the normal
> + UNIX sequences for these keys. */
> +
> + /* Up arrow. */
> + rl_macro_bind ("\340H", "\033[A", map);
> + /* Left arrow. */
> + rl_macro_bind ("\340K", "\033[D", map);
> + /* Right arrow. */
> + rl_macro_bind ("\340M", "\033[C", map);
> + /* Down arrow. */
> + rl_macro_bind ("\340P", "\033[B", map);
> + #endif
>
> It has "\34" and "\033" on the same line so I get confused whether
> "\34" is octal or not...
That's not "\34", that's "\340". Which I guess explains the other
confusion:
> Also, I don't see any trace of the 0xE0 you mention in the comment.
340 in octal is E0 in hex. I.e., the up arrow, for example, produces
two characters: 0xE0 followed by H.
Duh! Thanks Eli.
Mark
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: PATCH: Readline for MinGW
2005-06-12 7:33 ` Mark Kettenis
2005-06-12 8:43 ` Eli Zaretskii
@ 2005-06-13 6:09 ` Mark Mitchell
2005-06-15 18:14 ` James Lemke
2005-06-22 1:22 ` Chet Ramey
3 siblings, 0 replies; 7+ messages in thread
From: Mark Mitchell @ 2005-06-13 6:09 UTC (permalink / raw)
To: Mark Kettenis; +Cc: gdb-patches, bug-readline
Mark Kettenis wrote:
> Huh? AFAIK, POSIX doesn't say anything about arrow keys or the
> sequences produced by it. That's all determined by the terminal type.
Yes. Good point.
> Hmm, it looks like that readline simply hardcodes the ANSI sequences
> for these keys instead of consulting termcap. Not your fault though.
> But if it did consult termcap, you could provide a stub tgetent() that
> did the mapping.
Indeed.
> Incidentally, I find the way you find you write the macros a bit
> confusing:
>
> + #ifdef __MINGW32__
> + /* Under Windows, when an extend key (like an arrow key) is
> + pressed, getch() will return 0xE0 followed by a code for the
> + extended key. We use macros to transform those into the normal
> + UNIX sequences for these keys. */
> +
> + /* Up arrow. */
> + rl_macro_bind ("\340H", "\033[A", map);
> + /* Left arrow. */
> + rl_macro_bind ("\340K", "\033[D", map);
> + /* Right arrow. */
> + rl_macro_bind ("\340M", "\033[C", map);
> + /* Down arrow. */
> + rl_macro_bind ("\340P", "\033[B", map);
> + #endif
>
> It has "\34" and "\033" on the same line so I get confused whether
> "\34" is octal or not...
>
> Also, I don't see any trace of the 0xE0 you mention in the comment.
You're right; that's a suboptimal comment. Both "\340" and "\033" are
octal constants; "\033" is 0x27, or escape, and "\340" is 0xe0, which is
the Windows way of providing an escape sequence. I have updated my copy
of the comment to:
.... return 340 (octal) followed by a ...
Thanks,
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
(916) 791-8304
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: PATCH: Readline for MinGW
2005-06-12 7:33 ` Mark Kettenis
2005-06-12 8:43 ` Eli Zaretskii
2005-06-13 6:09 ` Mark Mitchell
@ 2005-06-15 18:14 ` James Lemke
2005-06-22 1:22 ` Chet Ramey
3 siblings, 0 replies; 7+ messages in thread
From: James Lemke @ 2005-06-15 18:14 UTC (permalink / raw)
To: Mark Kettenis; +Cc: Mark Mitchell, gdb-patches, bug-readline
On Sun, 2005-06-12 at 03:31, Mark Kettenis wrote:
> Date: Wed, 8 Jun 2005 10:42:06 -0700
> From: Mark Mitchell <mark@codesourcery.com>
>
> The problems solved by this patch are:
>
> 1. Windows does not have termcap/curses/etc. So, we provide a stub
> files that contains basic implementations of the relevant
> functions. That permits the remainder of the code to continue
> using the POSIX interfaces unchanged.
>
> 2. The arrow keys use different extended key sequences on Windows than
> on POSIX systems; we introduce readline macros to transform the
> Windows sequences into their POSIX equivalents. This approach
> again confines the Windows-isms to a single point.
FWIW, Mark's patch built fine for me.
--
James Lemke jim@wasabisystems.com Orillia, Ontario
http://www.wasabisystems.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: PATCH: Readline for MinGW
2005-06-12 7:33 ` Mark Kettenis
` (2 preceding siblings ...)
2005-06-15 18:14 ` James Lemke
@ 2005-06-22 1:22 ` Chet Ramey
3 siblings, 0 replies; 7+ messages in thread
From: Chet Ramey @ 2005-06-22 1:22 UTC (permalink / raw)
To: Mark Kettenis; +Cc: mark, gdb-patches, bug-readline
Mark Kettenis wrote:
> Hmm, it looks like that readline simply hardcodes the ANSI sequences
> for these keys instead of consulting termcap.
You didn't look hard enough.
Readline binds the termcap key sequences for the arrow keys, then, in
an attempt to be helpful, binds a few common arrow key prefixes to the
appropriate functions, if they're not already bound.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet )
Live...Laugh...Love
Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2005-06-22 1:22 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-08 17:43 PATCH: Readline for MinGW Mark Mitchell
2005-06-12 7:33 ` Mark Kettenis
2005-06-12 8:43 ` Eli Zaretskii
2005-06-12 9:27 ` Mark Kettenis
2005-06-13 6:09 ` Mark Mitchell
2005-06-15 18:14 ` James Lemke
2005-06-22 1:22 ` Chet Ramey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox