2012-01-15 Juan Manuel Guerrero  <juan.guerrero@gmx.de>

	DJGPP specific patch for readline 5.1 to be used with DJGPP's port of gdb.







diff -aprNU5 gdb-7.3.1.orig/readline/complete.c gdb-7.3.1/readline/complete.c
--- gdb-7.3.1.orig/readline/complete.c	2006-05-05 18:26:12 +0000
+++ gdb-7.3.1/readline/complete.c	2012-01-15 19:02:06 +0000
@@ -152,11 +152,11 @@ int _rl_complete_mark_symlink_dirs = 0;
 /* If non-zero, completions are printed horizontally in alphabetical order,
    like `ls -x'. */
 int _rl_print_completions_horizontally;
 
 /* Non-zero means that case is not significant in filename completion. */
-#if defined (__MSDOS__) && !defined (__DJGPP__)
+#if defined (__MSDOS__) && !defined (__DJGPPXXX__)
 int _rl_completion_case_fold = 1;
 #else
 int _rl_completion_case_fold;
 #endif
 
@@ -537,16 +537,17 @@ printable_part (pathname)
   char *temp, *x;
 
   if (rl_filename_completion_desired == 0)	/* don't need to do anything */
     return (pathname);
 
-  temp = strrchr (pathname, '/');
-#if defined (__MSDOS__)
-  if (temp == 0 && ISALPHA ((unsigned char)pathname[0]) && pathname[1] == ':')
-    temp = pathname + 1;
+#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
+  temp = basename(pathname);
+  return temp;
 #endif
 
+  temp = strrchr (pathname, '/');
+
   if (temp == 0 || *temp == '\0')
     return (pathname);
   /* If the basename is NULL, we might have a pathname like '/usr/src/'.
      Look for a previous slash and, if one is found, return the portion
      following that slash.  If there's no previous slash, just return the
@@ -888,10 +889,15 @@ _rl_find_completion_word (fp, dp)
 	  scan = rl_line_buffer[rl_point];
 
 	  if (strchr (brkchars, scan) == 0)
 	    continue;
 
+#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
+	  /* Ignore colons.  */
+	  if (scan == ':' && (rl_completion_entry_function == NULL || (rl_completion_entry_function == rl_filename_completion_function)))
+	    continue;
+#endif
 	  /* Call the application-specific function to tell us whether
 	     this word break character is quoted and should be skipped. */
 	  if (rl_char_is_quoted_p && found_quote &&
 	      (*rl_char_is_quoted_p) (rl_line_buffer, rl_point))
 	    continue;
@@ -1464,14 +1470,28 @@ make_quoted_replacement (match, mtype, q
   if (should_quote)
     {
       /* If there is a single match, see if we need to quote it.
          This also checks whether the common prefix of several
 	 matches needs to be quoted. */
+#if !defined (HAVE_DOS_BASED_FILE_SYSTEM)
       should_quote = rl_filename_quote_characters
 			? (_rl_strpbrk (match, rl_filename_quote_characters) != 0)
 			: 0;
 
+#else /* HAVE_DOS_BASED_FILE_SYSTEM */
+     {
+        /* To get here, the match must be a filename.
+           Do not allow ':' to be quoted in DOS-style filenames,
+           to avoid confusing people.  */
+        char *token = NULL;
+        should_quote = rl_filename_quote_characters
+                        ? ((token = _rl_strpbrk (match, rl_filename_quote_characters)) != 0)
+			: 0;
+        if (token && *token == ':')
+          should_quote = 0;
+      }
+#endif
       do_replace = should_quote ? mtype : NO_MATCH;
       /* Quote the replacement, since we found an embedded
 	 word break character in a potential match. */
       if (do_replace != NO_MATCH && rl_filename_quoting_function)
 	replacement = (*rl_filename_quoting_function) (match, do_replace, qc);
@@ -1932,11 +1952,11 @@ rl_filename_completion_function (text, s
 	text = ".";
       dirname = savestring (text);
 
       temp = strrchr (dirname, '/');
 
-#if defined (__MSDOS__)
+#if defined (__MSDOS__) && !defined (__DJGPP__)
       /* special hack for //X/... */
       if (dirname[0] == '/' && dirname[1] == '/' && ISALPHA ((unsigned char)dirname[2]) && dirname[3] == '/')
         temp = strrchr (dirname + 3, '/');
 #endif
 
diff -aprNU5 gdb-7.3.1.orig/readline/display.c gdb-7.3.1/readline/display.c
--- gdb-7.3.1.orig/readline/display.c	2008-03-24 12:59:50 +0000
+++ gdb-7.3.1/readline/display.c	2012-01-15 19:22:06 +0000
@@ -2256,19 +2256,19 @@ _rl_redisplay_after_sigwinch ()
 #endif
       _rl_last_c_pos = 0;
 #if defined (__MSDOS__)
       space_to_eol (_rl_screenwidth);
       putc ('\r', rl_outstream);
-#else
+#else /* ! __MSDOS__ */
       if (_rl_term_clreol)
 	tputs (_rl_term_clreol, 1, _rl_output_character_function);
       else
 	{
 	  space_to_eol (_rl_screenwidth);
 	  tputs (_rl_term_cr, 1, _rl_output_character_function);
 	}
-#endif
+#endif /* ! __MSDOS__ */
       if (_rl_last_v_pos > 0)
 	_rl_move_vert (0);
     }
   else
     rl_crlf ();
diff -aprNU5 gdb-7.3.1.orig/readline/funmap.c gdb-7.3.1/readline/funmap.c
--- gdb-7.3.1.orig/readline/funmap.c	2006-05-05 18:26:12 +0000
+++ gdb-7.3.1/readline/funmap.c	2012-01-15 19:02:06 +0000
@@ -109,11 +109,11 @@ static FUNMAP default_funmap[] = {
   { "non-incremental-forward-search-history", rl_noninc_forward_search },
   { "non-incremental-reverse-search-history", rl_noninc_reverse_search },
   { "non-incremental-forward-search-history-again", rl_noninc_forward_search_again },
   { "non-incremental-reverse-search-history-again", rl_noninc_reverse_search_again },
   { "overwrite-mode", rl_overwrite_mode },
-#ifdef __CYGWIN__
+#if defined (__WIN32__) || defined (__DJGPP__)
   { "paste-from-clipboard", rl_paste_from_clipboard },
 #endif
   { "possible-completions", rl_possible_completions },
   { "previous-history", rl_get_previous_history },
   { "quoted-insert", rl_quoted_insert },
diff -aprNU5 gdb-7.3.1.orig/readline/histfile.c gdb-7.3.1/readline/histfile.c
--- gdb-7.3.1.orig/readline/histfile.c	2006-05-05 18:26:12 +0000
+++ gdb-7.3.1/readline/histfile.c	2012-01-15 19:02:06 +0000
@@ -73,21 +73,22 @@
 #  endif
 
 #endif /* HISTORY_USE_MMAP */
 
 /* If we're compiling for __EMX__ (OS/2) or __CYGWIN__ (cygwin32 environment
-   on win 95/98/nt), we want to open files with O_BINARY mode so that there
-   is no \n -> \r\n conversion performed.  On other systems, we don't want to
-   mess around with O_BINARY at all, so we ensure that it's defined to 0. */
-#if defined (__EMX__) || defined (__CYGWIN__)
+   on win 95/98/nt), or DJGPP (DOS), we want to open files with O_BINARY mode
+   so that there is no \n -> \r\n conversion performed.  On other systems,
+   we don't want to mess around with O_BINARY at all, so we ensure that
+   it's defined to 0. */
+#if defined (__EMX__) || defined (__CYGWIN__) || defined (__DJGPP__)
 #  ifndef O_BINARY
 #    define O_BINARY 0
 #  endif
-#else /* !__EMX__ && !__CYGWIN__ */
+#else /* !__EMX__ && !__CYGWIN__ && !__DJGPP__ */
 #  undef O_BINARY
 #  define O_BINARY 0
-#endif /* !__EMX__ && !__CYGWIN__ */
+#endif /* !__EMX__ && !__CYGWIN__ && !__DJGPP__ */
 
 #include <errno.h>
 #if !defined (errno)
 extern int errno;
 #endif /* !errno */
diff -aprNU5 gdb-7.3.1.orig/readline/kill.c gdb-7.3.1/readline/kill.c
--- gdb-7.3.1.orig/readline/kill.c	2006-05-05 18:26:12 +0000
+++ gdb-7.3.1/readline/kill.c	2012-01-15 19:02:06 +0000
@@ -653,12 +653,12 @@ rl_yank_last_arg (count, key)
 
   undo_needed = retval == 0;
   return retval;
 }
 
-/* A special paste command for users of Cygnus's cygwin32. */
-#if defined (__CYGWIN__)
+/* A special paste command for Win32. */
+#if defined (__WIN32__)
 #include <windows.h>
 
 int
 rl_paste_from_clipboard (count, key)
      int count, key;
@@ -688,6 +688,75 @@ rl_paste_from_clipboard (count, key)
 	free (ptr);
       CloseClipboard ();
     }
   return (0);
 }
-#endif /* __CYGWIN__ */
+#endif /* __WIN32__ */
+
+/* A special paste command to allow DJGPP users to paste
+   from the Windows clipboard. */
+#if defined (__DJGPP__)
+#  include <dpmi.h>
+#  include <sys/farptr.h>
+#  include <go32.h>
+
+int
+rl_paste_from_clipboard (count, key)
+     int count, key;
+{
+  char *data, *ptr;
+  int len, index;
+  __dpmi_regs r;
+  unsigned long offset;
+  char ch;
+ 
+  /* Open the Windows clipboard.  */
+  r.x.ax = 0x1701;
+  __dpmi_int (0x2f, &r);
+  if (r.x.ax == 0)
+    return 0;
+
+  /* Get the size of the text in the clipboard.  */
+  r.x.ax = 0x1704;
+  r.x.dx = 1; /* Select plain text.  */
+  __dpmi_int (0x2f, &r);
+  len = r.x.ax + 65536 * r.x.dx;
+  if (len == 0)
+    return (0);
+
+  /* Get a pointer to the text.  */
+  r.x.ax = 0x1705;
+  r.x.dx = 1;
+  __dpmi_int (0x2f, &r);
+
+  offset = r.x.bx + 16 * r.x.es;
+  if (offset == 0)
+    return 0;
+
+  _farsetsel(_dos_ds);
+  while ((ch = _farnspeekb(offset++)) != '\0')
+    if (ch == '\r')
+      break;
+  len = offset - (r.x.bx + 16 * r.x.es);
+  if (ch == '\r')
+    --len;
+
+  ptr = xmalloc (len + 1);
+  offset = r.x.bx + 16 * r.x.es;
+
+  index = 0;
+  _farsetsel(_dos_ds);
+  while (index < len)
+  {
+    ch = _farnspeekb(offset++);
+    ptr[index++] = ch;
+  }
+  ptr[len] = '\0';
+
+  /* Close the clipboard.  */
+  r.x.ax = 0x1708;
+  __dpmi_int (0x2f, &r);
+
+  rl_insert_text (ptr);
+  free (ptr);
+}
+#endif /* __DJGPP__ */
diff -aprNU5 gdb-7.3.1.orig/readline/readline.c gdb-7.3.1/readline/readline.c
--- gdb-7.3.1.orig/readline/readline.c	2006-05-05 18:26:12 +0000
+++ gdb-7.3.1/readline/readline.c	2012-01-15 19:02:06 +0000
@@ -1073,11 +1073,11 @@ bind_arrow_keys_internal (map)
   Keymap xkeymap;
 
   xkeymap = _rl_keymap;
   _rl_keymap = map;
 
-#if defined (__MSDOS__)
+#if defined (__MSDOS__) && !defined (__DJGPP__)
   rl_bind_keyseq_if_unbound ("\033[0A", rl_get_previous_history);
   rl_bind_keyseq_if_unbound ("\033[0B", rl_backward_char);
   rl_bind_keyseq_if_unbound ("\033[0C", rl_forward_char);
   rl_bind_keyseq_if_unbound ("\033[0D", rl_get_next_history);
 #endif
@@ -1153,11 +1153,13 @@ rl_save_state (sp)
   sp->outf = rl_outstream;
   sp->pendingin = rl_pending_input;
   sp->macro = rl_executing_macro;
 
   sp->catchsigs = rl_catch_signals;
+#ifdef SIGWINCH
   sp->catchsigwinch = rl_catch_sigwinch;
+#endif
 
   return (0);
 }
 
 int
@@ -1187,9 +1189,11 @@ rl_restore_state (sp)
   rl_outstream = sp->outf;
   rl_pending_input = sp->pendingin;
   rl_executing_macro = sp->macro;
 
   rl_catch_signals = sp->catchsigs;
+#ifdef SIGWINCH
   rl_catch_sigwinch = sp->catchsigwinch;
+#endif
 
   return (0);
 }
diff -aprNU5 gdb-7.3.1.orig/readline/readline.h gdb-7.3.1/readline/readline.h
--- gdb-7.3.1.orig/readline/readline.h	2006-05-05 18:26:12 +0000
+++ gdb-7.3.1/readline/readline.h	2012-01-15 19:02:06 +0000
@@ -169,11 +169,11 @@ extern int rl_copy_backward_word PARAMS(
 extern int rl_yank PARAMS((int, int));
 extern int rl_yank_pop PARAMS((int, int));
 extern int rl_yank_nth_arg PARAMS((int, int));
 extern int rl_yank_last_arg PARAMS((int, int));
 /* Not available unless __CYGWIN__ is defined. */
-#ifdef __CYGWIN__
+#if defined (__WIN32__) || defined (__DJGPP__)
 extern int rl_paste_from_clipboard PARAMS((int, int));
 #endif
 
 /* Bindable commands for incremental searching. */
 extern int rl_reverse_search_history PARAMS((int, int));
diff -aprNU5 gdb-7.3.1.orig/readline/terminal.c gdb-7.3.1/readline/terminal.c
--- gdb-7.3.1.orig/readline/terminal.c	2006-11-13 09:33:30 +0000
+++ gdb-7.3.1/readline/terminal.c	2012-01-15 19:02:06 +0000
@@ -179,11 +179,11 @@ int _rl_enable_keypad;
 /* Non-zero means the user wants to enable a meta key. */
 int _rl_enable_meta = 1;
 
 #if defined (__EMX__)
 static void
-_emx_get_screensize (swp, shp)
+_get_screensize (swp, shp)
      int *swp, *shp;
 {
   int sz[2];
 
   _scrsize (sz);
@@ -193,10 +193,24 @@ _emx_get_screensize (swp, shp)
   if (shp)
     *shp = sz[1];
 }
 #endif
 
+#if defined (__MSDOS__)
+#  include <conio.h>
+
+static void
+_get_screensize (swp, shp)
+     int *swp, *shp;
+{
+  struct text_info screen_info;
+  gettextinfo (&screen_info);
+  *swp = (int)screen_info.screenwidth;
+  *shp = (int)screen_info.screenheight;
+}
+#endif
+
 /* Get readline's idea of the screen size.  TTY is a file descriptor open
    to the terminal.  If IGNORE_ENV is true, we do not pay attention to the
    values of $LINES and $COLUMNS.  The tests for TERM_STRING_BUFFER being
    non-null serve to check whether or not we have initialized termcap. */
 void
@@ -230,12 +244,12 @@ _rl_get_screen_size (tty, ignore_env)
 	  wr = scr.srWindow.Bottom - scr.srWindow.Top + 1;
 	}
     }
 #endif
 
-#if defined (__EMX__)
-  _emx_get_screensize (&_rl_screenwidth, &_rl_screenheight);
+#if defined (__EMX__) || defined (__DJGPP__)
+  _get_screensize (&_rl_screenwidth, &_rl_screenheight);
 #endif
 
   if (ignore_env || rl_prefer_env_winsize == 0)
     {
       _rl_screenwidth = wc;
@@ -405,16 +419,14 @@ static struct _tc_string tc_strings[] =
    are described in the TC_STRINGS table. */
 static void
 get_term_capabilities (bp)
      char **bp;
 {
-#if !defined (__DJGPP__)	/* XXX - doesn't DJGPP have a termcap library? */
   register int i;
 
   for (i = 0; i < NUM_TC_STRINGS; i++)
     *(tc_strings[i].tc_value) = tgetstr ((char *)tc_strings[i].tc_var, bp);
-#endif
   tcap_initialized = 1;
 }
 
 int
 _rl_init_terminal_io (terminal_name)
@@ -478,12 +490,12 @@ _rl_init_terminal_io (terminal_name)
 
       /* Allow calling application to set default height and width, using
 	 rl_set_screen_size */
       if (_rl_screenwidth <= 0 || _rl_screenheight <= 0)
 	{
-#if defined (__EMX__)
-	  _emx_get_screensize (&_rl_screenwidth, &_rl_screenheight);
+#if defined (__EMX__) || defined (__DJGPP__)
+	  _get_screensize (&_rl_screenwidth, &_rl_screenheight);
 	  _rl_screenwidth--;
 #else /* !__EMX__ */
 	  _rl_get_screen_size (tty, 0);
 #endif /* !__EMX__ */
 	}
