diff options
author | ache <ache@FreeBSD.org> | 2000-03-19 22:00:57 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 2000-03-19 22:00:57 +0000 |
commit | c0502b59de9b1867c80d1f7c141eb7e01e803c49 (patch) | |
tree | 021889acf6387146348bb609412748223ae44f33 /contrib/libreadline | |
parent | f14c3bda44fa0a848a56d984661f9685bba97044 (diff) | |
download | FreeBSD-src-c0502b59de9b1867c80d1f7c141eb7e01e803c49.zip FreeBSD-src-c0502b59de9b1867c80d1f7c141eb7e01e803c49.tar.gz |
Merge conflicts
Diffstat (limited to 'contrib/libreadline')
-rw-r--r-- | contrib/libreadline/acconfig.h | 30 | ||||
-rw-r--r-- | contrib/libreadline/complete.c | 136 | ||||
-rw-r--r-- | contrib/libreadline/display.c | 359 | ||||
-rw-r--r-- | contrib/libreadline/doc/readline.3 | 12 | ||||
-rw-r--r-- | contrib/libreadline/readline.3 | 12 | ||||
-rw-r--r-- | contrib/libreadline/readline.h | 34 | ||||
-rw-r--r-- | contrib/libreadline/rlconf.h | 9 | ||||
-rw-r--r-- | contrib/libreadline/shell.c | 51 | ||||
-rw-r--r-- | contrib/libreadline/terminal.c | 211 | ||||
-rw-r--r-- | contrib/libreadline/util.c | 25 |
10 files changed, 532 insertions, 347 deletions
diff --git a/contrib/libreadline/acconfig.h b/contrib/libreadline/acconfig.h deleted file mode 100644 index 4f42238..0000000 --- a/contrib/libreadline/acconfig.h +++ /dev/null @@ -1,30 +0,0 @@ -/* acconfig.h - This file is in the public domain. - - Descriptive text for the C preprocessor macros that - the distributed Autoconf macros can define. - No software package will use all of them; autoheader copies the ones - your configure.in uses into your configuration header file templates. - - The entries are in sort -df order: alphabetical, case insensitive, - ignoring punctuation (such as underscores). Although this order - can split up related entries, it makes it easier to check whether - a given entry is in the file. - - Leave the following blank line there!! Autoheader needs it. */ - - -/* Definitions pulled in from aclocal.m4. */ -#undef VOID_SIGHANDLER - -#undef TIOCGWINSZ_IN_SYS_IOCTL - -#undef TIOCSTAT_IN_SYS_IOCTL - -#undef HAVE_GETPW_DECLS - - -/* Leave that blank line there!! Autoheader needs it. - If you're adding to this file, keep in mind: - The entries are in sort -df order: alphabetical, case insensitive, - ignoring punctuation (such as underscores). */ diff --git a/contrib/libreadline/complete.c b/contrib/libreadline/complete.c index 714a2bf..b8d1f6a 100644 --- a/contrib/libreadline/complete.c +++ b/contrib/libreadline/complete.c @@ -1,3 +1,4 @@ +/* $FreeBSD$ */ /* complete.c -- filename completion for readline. */ /* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc. @@ -7,7 +8,7 @@ The GNU Readline Library 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 1, or + as published by the Free Software Foundation; either version 2, or (at your option) any later version. The GNU Readline Library is distributed in the hope that it will be @@ -18,7 +19,7 @@ The GNU General Public License is often shipped with GNU software, and is generally kept in a file called COPYING or LICENSE. If you do not have a copy of the license, write to the Free Software Foundation, - 675 Mass Ave, Cambridge, MA 02139, USA. */ + 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ #define READLINE_LIBRARY #if defined (HAVE_CONFIG_H) @@ -70,20 +71,14 @@ extern struct passwd *getpwent (); /* Some standard library routines. */ #include "readline.h" +#include "xmalloc.h" +#include "rlprivate.h" -extern char *tilde_expand (); -extern char *rl_copy_text (); -extern void _rl_abort_internal (); -extern int _rl_qsort_string_compare (); -extern void _rl_replace_text (); - -extern Function *rl_last_func; -extern int rl_editing_mode; -extern int screenwidth; - -extern void _rl_move_vert (); -extern int _rl_vis_botlin; -extern int rl_display_fixed; +#ifdef __STDC__ +typedef int QSFUNC (const void *, const void *); +#else +typedef int QSFUNC (); +#endif /* If non-zero, then this is the address of a function to call when completing a word would normally display the list of possible matches. @@ -95,27 +90,25 @@ extern int rl_display_fixed; VFunction *rl_completion_display_matches_hook = (VFunction *)NULL; /* Forward declarations for functions defined and used in this file. */ -char *filename_completion_function (); -char **completion_matches (); +char *filename_completion_function __P((char *, int)); +char **completion_matches __P((char *, CPFunction *)); #if defined (VISIBLE_STATS) # if !defined (X_OK) # define X_OK 1 # endif -static int stat_char (); +static int stat_char __P((char *)); #endif -static char *rl_quote_filename (); -static char *rl_strpbrk (); - -static char **remove_duplicate_matches (); -static void insert_match (); -static int append_to_match (); -static void insert_all_matches (); -static void display_matches (); -static int compute_lcd_of_matches (); +static char *rl_quote_filename __P((char *, int, char *)); +static char *rl_strpbrk __P((char *, char *)); -extern char *xmalloc (), *xrealloc (); +static char **remove_duplicate_matches __P((char **)); +static void insert_match __P((char *, int, int, char *)); +static int append_to_match __P((char *, int, int)); +static void insert_all_matches __P((char **, int, char *)); +static void display_matches __P((char **)); +static int compute_lcd_of_matches __P((char **, int, char *)); /* **************************************************************** */ /* */ @@ -136,7 +129,11 @@ int _rl_complete_mark_directories = 1; int _rl_print_completions_horizontally; /* Non-zero means that case is not significant in filename completion. */ +#if defined (__MSDOS__) && !defined (__DJGPP__) +int _rl_completion_case_fold = 1; +#else int _rl_completion_case_fold; +#endif /* Global variables available to applications using readline. */ @@ -417,6 +414,10 @@ printable_part (pathname) char *temp; temp = rl_filename_completion_desired ? strrchr (pathname, '/') : (char *)NULL; +#if defined (__MSDOS__) + if (rl_filename_completion_desired && temp == 0 && isalpha (pathname[0]) && pathname[1] == ':') + temp = pathname + 1; +#endif return (temp ? ++temp : pathname); } @@ -477,7 +478,12 @@ print_filename (to_print, full_pathname) c = to_print[-1]; to_print[-1] = '\0'; - s = tilde_expand (full_pathname); + /* If setting the last slash in full_pathname to a NUL results in + full_pathname being the empty string, we are trying to complete + files in the root directory. If we pass a null string to the + bash directory completion hook, for example, it will expand it + to the current directory. We just want the `/'. */ + s = tilde_expand (full_pathname && *full_pathname ? full_pathname : "/"); if (rl_directory_completion_hook) (*rl_directory_completion_hook) (&s); @@ -627,25 +633,31 @@ find_completion_word (fp, dp) /* If there is an application-specific function to say whether or not a character is quoted and we found a quote character, let that function decide whether or not a character is a word break, even - if it is found in rl_completer_word_break_characters. */ - if (rl_char_is_quoted_p) - isbrk = (found_quote == 0 || - (*rl_char_is_quoted_p) (rl_line_buffer, rl_point) == 0) && - strchr (rl_completer_word_break_characters, scan) != 0; - else - isbrk = strchr (rl_completer_word_break_characters, scan) != 0; - - if (isbrk) + if it is found in rl_completer_word_break_characters. Don't bother + if we're at the end of the line, though. */ + if (scan) { - /* If the character that caused the word break was a quoting - character, then remember it as the delimiter. */ - if (rl_basic_quote_characters && strchr (rl_basic_quote_characters, scan) && (end - rl_point) > 1) - delimiter = scan; - - /* If the character isn't needed to determine something special - about what kind of completion to perform, then advance past it. */ - if (rl_special_prefixes == 0 || strchr (rl_special_prefixes, scan) == 0) - rl_point++; + if (rl_char_is_quoted_p) + isbrk = (found_quote == 0 || + (*rl_char_is_quoted_p) (rl_line_buffer, rl_point) == 0) && + strchr (rl_completer_word_break_characters, scan) != 0; + else + isbrk = strchr (rl_completer_word_break_characters, scan) != 0; + + if (isbrk) + { + /* If the character that caused the word break was a quoting + character, then remember it as the delimiter. */ + if (rl_basic_quote_characters && + strchr (rl_basic_quote_characters, scan) && + (end - rl_point) > 1) + delimiter = scan; + + /* If the character isn't needed to determine something special + about what kind of completion to perform, then advance past it. */ + if (rl_special_prefixes == 0 || strchr (rl_special_prefixes, scan) == 0) + rl_point++; + } } if (fp) @@ -715,7 +727,7 @@ remove_duplicate_matches (matches) /* Sort the array without matches[0], since we need it to stay in place no matter what. */ if (i) - qsort (matches+1, i-1, sizeof (char *), _rl_qsort_string_compare); + qsort (matches+1, i-1, sizeof (char *), (QSFUNC *)_rl_qsort_string_compare); /* Remember the lowest common denominator for it may be unique. */ lowest_common = savestring (matches[0]); @@ -908,7 +920,7 @@ rl_display_match_list (matches, len, max) /* Sort the items if they are not already sorted. */ if (rl_ignore_completion_duplicates == 0) - qsort (matches + 1, len, sizeof (char *), _rl_qsort_string_compare); + qsort (matches + 1, len, sizeof (char *), (QSFUNC *)_rl_qsort_string_compare); crlf (); @@ -1407,9 +1419,9 @@ username_completion_function (text, state) char *text; int state; { -#if defined (__GO32__) || defined (__WIN32__) || defined (__OPENNT) +#if defined (__WIN32__) || defined (__OPENNT) return (char *)NULL; -#else /* !__GO32__ */ +#else /* !__WIN32__ && !__OPENNT) */ static char *username = (char *)NULL; static struct passwd *entry; static int namelen, first_char, first_char_loc; @@ -1452,7 +1464,7 @@ username_completion_function (text, state) return (value); } -#endif /* !__GO32__ */ +#endif /* !__WIN32__ && !__OPENNT */ } /* Okay, now we write the entry_function for filename completion. In the @@ -1494,11 +1506,25 @@ filename_completion_function (text, state) temp = strrchr (dirname, '/'); +#if defined (__MSDOS__) + /* special hack for //X/... */ + if (dirname[0] == '/' && dirname[1] == '/' && isalpha (dirname[2]) && dirname[3] == '/') + temp = strrchr (dirname + 3, '/'); +#endif + if (temp) { strcpy (filename, ++temp); *temp = '\0'; } +#if defined (__MSDOS__) + /* searches from current directory on the drive */ + else if (isalpha (dirname[0]) && dirname[1] == ':') + { + strcpy (filename, dirname + 2); + dirname[2] = '\0'; + } +#endif else { dirname[0] = '.'; @@ -1660,11 +1686,7 @@ rl_menu_complete (count, ignore) /* Clean up from previous call, if any. */ FREE (orig_text); if (matches) - { - for (match_list_index = 0; matches[match_list_index]; match_list_index++) - free (matches[match_list_index]); - free (matches); - } + free_match_list (matches); match_list_index = match_list_size = 0; matches = (char **)NULL; diff --git a/contrib/libreadline/display.c b/contrib/libreadline/display.c index 25aba64..a0f61057 100644 --- a/contrib/libreadline/display.c +++ b/contrib/libreadline/display.c @@ -1,3 +1,4 @@ +/* $FreeBSD$ */ /* display.c -- readline redisplay facility. */ /* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc. @@ -7,7 +8,7 @@ The GNU Readline Library 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 1, or + as published by the Free Software Foundation; either version 2, or (at your option) any later version. The GNU Readline Library is distributed in the hope that it will be @@ -18,7 +19,7 @@ The GNU General Public License is often shipped with GNU software, and is generally kept in a file called COPYING or LICENSE. If you do not have a copy of the license, write to the Free Software Foundation, - 675 Mass Ave, Cambridge, MA 02139, USA. */ + 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ #define READLINE_LIBRARY #if defined (HAVE_CONFIG_H) @@ -41,11 +42,6 @@ #include <stdio.h> -#if defined (__GO32__) -# include <go32.h> -# include <pc.h> -#endif /* __GO32__ */ - /* System-specific feature definitions and include files. */ #include "rldefs.h" @@ -56,48 +52,25 @@ #include "readline.h" #include "history.h" +#include "rlprivate.h" +#include "xmalloc.h" + #if !defined (strchr) && !defined (__STDC__) extern char *strchr (), *strrchr (); #endif /* !strchr && !__STDC__ */ -/* Global and pseudo-global variables and functions - imported from readline.c. */ -extern char *rl_prompt; -extern int readline_echoing_p; - -extern int _rl_output_meta_chars; -extern int _rl_horizontal_scroll_mode; -extern int _rl_mark_modified_lines; -extern int _rl_prefer_visible_bell; - -/* Variables and functions imported from terminal.c */ -extern void _rl_output_some_chars (); -#ifdef _MINIX -extern void _rl_output_character_function (); -#else -extern int _rl_output_character_function (); +#if defined (HACK_TERMCAP_MOTION) +extern char *term_forward_char; #endif -extern int _rl_backspace (); - -extern char *term_clreol, *term_clrpag; -extern char *term_im, *term_ic, *term_ei, *term_DC; -extern char *term_up, *term_dc, *term_cr, *term_IC; -extern int screenheight, screenwidth, screenchars; -extern int terminal_can_insert, _rl_term_autowrap; - -/* Pseudo-global functions (local to the readline library) exported - by this file. */ -void _rl_move_cursor_relative (), _rl_output_some_chars (); -void _rl_move_vert (); -void _rl_clear_to_eol (), _rl_clear_screen (); -static void update_line (), space_to_eol (); -static void delete_chars (), insert_some_chars (); -static void cr (); +static void update_line __P((char *, char *, int, int, int, int)); +static void space_to_eol __P((int)); +static void delete_chars __P((int)); +static void insert_some_chars __P((char *, int)); +static void cr __P((void)); static int *inv_lbreaks, *vis_lbreaks; - -extern char *xmalloc (), *xrealloc (); +static int inv_lbsize, vis_lbsize; /* Heuristic used to decide whether it is faster to move from CUR to NEW by backing up or outputting a carriage return and moving forward. */ @@ -190,7 +163,7 @@ static int visible_first_line_len; /* Expand the prompt string S and return the number of visible characters in *LP, if LP is not null. This is currently more-or-less a placeholder for expansion. LIP, if non-null is a place to store the - index of the last invisible character in ther eturned string. */ + index of the last invisible character in the returned string. */ /* Current implementation: \001 (^A) start non-visible characters @@ -250,6 +223,18 @@ expand_prompt (pmt, lp, lip) return ret; } +/* Just strip out RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE from + PMT and return the rest of PMT. */ +char * +_rl_strip_prompt (pmt) + char *pmt; +{ + char *ret; + + ret = expand_prompt (pmt, (int *)NULL, (int *)NULL); + return ret; +} + /* * Expand the prompt string into the various display components, if * necessary. @@ -307,6 +292,49 @@ rl_expand_prompt (prompt) } } +/* Initialize the VISIBLE_LINE and INVISIBLE_LINE arrays, and their associated + arrays of line break markers. MINSIZE is the minimum size of VISIBLE_LINE + and INVISIBLE_LINE; if it is greater than LINE_SIZE, LINE_SIZE is + increased. If the lines have already been allocated, this ensures that + they can hold at least MINSIZE characters. */ +static void +init_line_structures (minsize) + int minsize; +{ + register int n; + + if (invisible_line == 0) /* initialize it */ + { + if (line_size < minsize) + line_size = minsize; + visible_line = xmalloc (line_size); + invisible_line = xmalloc (line_size); + } + else if (line_size < minsize) /* ensure it can hold MINSIZE chars */ + { + line_size *= 2; + if (line_size < minsize) + line_size = minsize; + visible_line = xrealloc (visible_line, line_size); + invisible_line = xrealloc (invisible_line, line_size); + } + + for (n = minsize; n < line_size; n++) + { + visible_line[n] = 0; + invisible_line[n] = 1; + } + + if (vis_lbreaks == 0) + { + /* should be enough. */ + inv_lbsize = vis_lbsize = 256; + inv_lbreaks = (int *)xmalloc (inv_lbsize * sizeof (int)); + vis_lbreaks = (int *)xmalloc (vis_lbsize * sizeof (int)); + inv_lbreaks[0] = vis_lbreaks[0] = 0; + } +} + /* Basic redisplay algorithm. */ void rl_redisplay () @@ -325,19 +353,7 @@ rl_redisplay () if (invisible_line == 0) { - visible_line = xmalloc (line_size); - invisible_line = xmalloc (line_size); - for (in = 0; in < line_size; in++) - { - visible_line[in] = 0; - invisible_line[in] = 1; - } - - /* should be enough, but then again, this is just for testing. */ - inv_lbreaks = (int *)malloc (256 * sizeof (int)); - vis_lbreaks = (int *)malloc (256 * sizeof (int)); - inv_lbreaks[0] = vis_lbreaks[0] = 0; - + init_line_structures (0); rl_on_new_line (); } @@ -395,12 +411,13 @@ rl_redisplay () else { prompt_this_line++; + pmtlen = prompt_this_line - rl_display_prompt; /* temp var */ if (forced_display) { - _rl_output_some_chars (rl_display_prompt, prompt_this_line - rl_display_prompt); + _rl_output_some_chars (rl_display_prompt, pmtlen); /* Make sure we are at column zero even after a newline, regardless of the state of terminal output processing. */ - if (prompt_this_line[-2] != '\r') + if (pmtlen < 2 || prompt_this_line[-2] != '\r') cr (); } } @@ -419,11 +436,25 @@ rl_redisplay () wrap_offset = 0; } +#define CHECK_INV_LBREAKS() \ + do { \ + if (newlines >= (inv_lbsize - 2)) \ + { \ + inv_lbsize *= 2; \ + inv_lbreaks = (int *)xrealloc (inv_lbreaks, inv_lbsize * sizeof (int)); \ + } \ + } while (0) + #define CHECK_LPOS() \ do { \ lpos++; \ if (lpos >= screenwidth) \ { \ + if (newlines >= (inv_lbsize - 2)) \ + { \ + inv_lbsize *= 2; \ + inv_lbreaks = (int *)xrealloc (inv_lbreaks, inv_lbsize * sizeof (int)); \ + } \ inv_lbreaks[++newlines] = out; \ lpos = 0; \ } \ @@ -437,14 +468,13 @@ rl_redisplay () contents of the command line? */ while (lpos >= screenwidth) { -#if 0 - temp = ((newlines + 1) * screenwidth) - ((newlines == 0) ? wrap_offset : 0); -#else /* XXX - possible fix from Darin Johnson <darin@acuson.com> for prompt string with invisible characters that is longer than the screen - width. */ + width. XXX - this doesn't work right if invisible characters have + to be put on the second screen line -- it adds too much (the number + of invisible chars after the screenwidth). */ temp = ((newlines + 1) * screenwidth) + ((newlines == 0) ? wrap_offset : 0); -#endif + inv_lbreaks[++newlines] = temp; lpos -= screenwidth; } @@ -477,6 +507,7 @@ rl_redisplay () if (lpos + 4 >= screenwidth) { temp = screenwidth - lpos; + CHECK_INV_LBREAKS (); inv_lbreaks[++newlines] = out + temp; lpos = 4 - temp; } @@ -506,6 +537,7 @@ rl_redisplay () { register int temp2; temp2 = screenwidth - lpos; + CHECK_INV_LBREAKS (); inv_lbreaks[++newlines] = out + temp2; lpos = temp - temp2; while (out < newout) @@ -522,6 +554,7 @@ rl_redisplay () else if (c == '\n' && _rl_horizontal_scroll_mode == 0 && term_up && *term_up) { line[out++] = '\0'; /* XXX - sentinel */ + CHECK_INV_LBREAKS (); inv_lbreaks[++newlines] = out; lpos = 0; } @@ -546,6 +579,7 @@ rl_redisplay () } inv_botlin = lb_botlin = newlines; + CHECK_INV_LBREAKS (); inv_lbreaks[newlines+1] = out; cursor_linenum = lb_linenum; @@ -651,8 +685,12 @@ rl_redisplay () if (cursor_linenum == 0 && wrap_offset > 0 && _rl_last_c_pos > 0 && _rl_last_c_pos <= last_invisible && local_prompt) { +#if defined (__MSDOS__) + putc ('\r', rl_outstream); +#else if (term_cr) tputs (term_cr, 1, _rl_output_character_function); +#endif _rl_output_some_chars (local_prompt, nleft); _rl_last_c_pos = nleft; } @@ -772,11 +810,17 @@ rl_redisplay () /* Swap visible and non-visible lines. */ { char *temp = visible_line; - int *itemp = vis_lbreaks; + int *itemp = vis_lbreaks, ntemp = vis_lbsize; + visible_line = invisible_line; invisible_line = temp; + vis_lbreaks = inv_lbreaks; inv_lbreaks = itemp; + + vis_lbsize = inv_lbsize; + inv_lbsize = ntemp; + rl_display_fixed = 0; /* If we are displaying on a single line, and last_lmargin is > 0, we are not displaying any invisible characters, so set visible_wrap_offset @@ -899,7 +943,11 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) term_cr && lendiff > visible_length && _rl_last_c_pos > 0 && od > lendiff && _rl_last_c_pos < last_invisible) { +#if defined (__MSDOS__) + putc ('\r', rl_outstream); +#else tputs (term_cr, 1, _rl_output_character_function); +#endif _rl_output_some_chars (local_prompt, lendiff); _rl_last_c_pos = lendiff; } @@ -1029,6 +1077,58 @@ rl_on_new_line () return 0; } +/* Tell the update routines that we have moved onto a new line with the + prompt already displayed. Code originally from the version of readline + distributed with CLISP. */ +int +rl_on_new_line_with_prompt () +{ + int prompt_size, i, l, real_screenwidth, newlines; + char *prompt_last_line; + + /* Initialize visible_line and invisible_line to ensure that they can hold + the already-displayed prompt. */ + prompt_size = strlen (rl_prompt) + 1; + init_line_structures (prompt_size); + + /* Make sure the line structures hold the already-displayed prompt for + redisplay. */ + strcpy (visible_line, rl_prompt); + strcpy (invisible_line, rl_prompt); + + /* If the prompt contains newlines, take the last tail. */ + prompt_last_line = strrchr (rl_prompt, '\n'); + if (!prompt_last_line) + prompt_last_line = rl_prompt; + + l = strlen (prompt_last_line); + _rl_last_c_pos = l; + + /* Dissect prompt_last_line into screen lines. Note that here we have + to use the real screenwidth. Readline's notion of screenwidth might be + one less, see terminal.c. */ + real_screenwidth = screenwidth + (_rl_term_autowrap ? 0 : 1); + _rl_last_v_pos = l / real_screenwidth; + /* If the prompt length is a multiple of real_screenwidth, we don't know + whether the cursor is at the end of the last line, or already at the + beginning of the next line. Output a newline just to be safe. */ + if (l > 0 && (l % real_screenwidth) == 0) + _rl_output_some_chars ("\n", 1); + last_lmargin = 0; + + newlines = 0; i = 0; + while (i <= l) + { + _rl_vis_botlin = newlines; + vis_lbreaks[newlines++] = i; + i += real_screenwidth; + } + vis_lbreaks[newlines] = l; + visible_wrap_offset = 0; + + return 0; +} + /* Actually update the display, period. */ int rl_forced_update_display () @@ -1086,8 +1186,6 @@ _rl_move_cursor_relative (new, data) That kind of control is for people who don't know what the data is underneath the cursor. */ #if defined (HACK_TERMCAP_MOTION) - extern char *term_forward_char; - if (term_forward_char) for (i = _rl_last_c_pos; i < new; i++) tputs (term_forward_char, 1, _rl_output_character_function); @@ -1114,20 +1212,15 @@ _rl_move_vert (to) if (_rl_last_v_pos == to || to > screenheight) return; -#if defined (__GO32__) - { - int row, col; - - ScreenGetCursor (&row, &col); - ScreenSetCursor ((row + to - _rl_last_v_pos), col); - } -#else /* !__GO32__ */ - if ((delta = to - _rl_last_v_pos) > 0) { for (i = 0; i < delta; i++) putc ('\n', rl_outstream); +#if defined (__MSDOS__) + putc ('\r', rl_outstream); +#else tputs (term_cr, 1, _rl_output_character_function); +#endif _rl_last_c_pos = 0; } else @@ -1136,7 +1229,7 @@ _rl_move_vert (to) for (i = 0; i < -delta; i++) tputs (term_up, 1, _rl_output_character_function); } -#endif /* !__GO32__ */ + _rl_last_v_pos = to; /* Now TO is here */ } @@ -1344,11 +1437,9 @@ void _rl_clear_to_eol (count) int count; { -#if !defined (__GO32__) if (term_clreol) tputs (term_clreol, 1, _rl_output_character_function); else if (count) -#endif /* !__GO32__ */ space_to_eol (count); } @@ -1369,11 +1460,9 @@ space_to_eol (count) void _rl_clear_screen () { -#if !defined (__GO32__) if (term_clrpag) tputs (term_clrpag, 1, _rl_output_character_function); else -#endif /* !__GO32__ */ crlf (); } @@ -1383,20 +1472,6 @@ insert_some_chars (string, count) char *string; int count; { -#if defined (__GO32__) - int row, col, width; - char *row_start; - - ScreenGetCursor (&row, &col); - width = ScreenCols (); - row_start = ScreenPrimary + (row * width); - - memcpy (row_start + col + count, row_start + col, width - col - count); - - /* Place the text on the screen. */ - _rl_output_some_chars (string, count); -#else /* !_GO32 */ - /* If IC is defined, then we do not have to "enter" insert mode. */ if (term_IC) { @@ -1429,7 +1504,6 @@ insert_some_chars (string, count) if (term_ei && *term_ei) tputs (term_ei, 1, _rl_output_character_function); } -#endif /* !__GO32__ */ } /* Delete COUNT characters from the display line. */ @@ -1437,18 +1511,6 @@ static void delete_chars (count) int count; { -#if defined (__GO32__) - int row, col, width; - char *row_start; - - ScreenGetCursor (&row, &col); - width = ScreenCols (); - row_start = ScreenPrimary + (row * width); - - memcpy (row_start + col, row_start + col + count, width - col - count); - memset (row_start + width - count, 0, count * 2); -#else /* !_GO32 */ - if (count > screenwidth) /* XXX */ return; @@ -1464,7 +1526,6 @@ delete_chars (count) while (count--) tputs (term_dc, 1, _rl_output_character_function); } -#endif /* !__GO32__ */ } void @@ -1486,7 +1547,11 @@ _rl_update_final () if (full_lines && _rl_term_autowrap && (VIS_LLEN(_rl_vis_botlin) == screenwidth)) { char *last_line; +#if 0 last_line = &visible_line[inv_lbreaks[_rl_vis_botlin]]; +#else + last_line = &visible_line[vis_lbreaks[_rl_vis_botlin]]; +#endif _rl_move_cursor_relative (screenwidth - 1, last_line); _rl_clear_to_eol (0); putc (last_line[screenwidth - 1], rl_outstream); @@ -1503,23 +1568,66 @@ cr () { if (term_cr) { +#if defined (__MSDOS__) + putc ('\r', rl_outstream); +#else tputs (term_cr, 1, _rl_output_character_function); +#endif _rl_last_c_pos = 0; } } +/* Redraw the last line of a multi-line prompt that may possibly contain + terminal escape sequences. Called with the cursor at column 0 of the + line to draw the prompt on. */ +static void +redraw_prompt (t) + char *t; +{ + char *oldp, *oldl, *oldlprefix; + int oldlen, oldlast, oldplen; + + /* Geez, I should make this a struct. */ + oldp = rl_display_prompt; + oldl = local_prompt; + oldlprefix = local_prompt_prefix; + oldlen = visible_length; + oldplen = prefix_length; + oldlast = last_invisible; + + rl_display_prompt = t; + local_prompt = expand_prompt (t, &visible_length, &last_invisible); + local_prompt_prefix = (char *)NULL; + rl_forced_update_display (); + + rl_display_prompt = oldp; + local_prompt = oldl; + local_prompt_prefix = oldlprefix; + visible_length = oldlen; + prefix_length = oldplen; + last_invisible = oldlast; +} + /* Redisplay the current line after a SIGWINCH is received. */ void _rl_redisplay_after_sigwinch () { - char *t, *oldp, *oldl, *oldlprefix; + char *t; /* Clear the current line and put the cursor at column 0. Make sure the right thing happens if we have wrapped to a new screen line. */ if (term_cr) { +#if defined (__MSDOS__) + putc ('\r', rl_outstream); +#else tputs (term_cr, 1, _rl_output_character_function); +#endif _rl_last_c_pos = 0; +#if defined (__MSDOS__) + space_to_eol (screenwidth); + putc ('\r', rl_outstream); +#else if (term_clreol) tputs (term_clreol, 1, _rl_output_character_function); else @@ -1527,6 +1635,7 @@ _rl_redisplay_after_sigwinch () space_to_eol (screenwidth); tputs (term_cr, 1, _rl_output_character_function); } +#endif if (_rl_last_v_pos > 0) _rl_move_vert (0); } @@ -1536,17 +1645,7 @@ _rl_redisplay_after_sigwinch () /* Redraw only the last line of a multi-line prompt. */ t = strrchr (rl_display_prompt, '\n'); if (t) - { - oldp = rl_display_prompt; - oldl = local_prompt; - oldlprefix = local_prompt_prefix; - rl_display_prompt = ++t; - local_prompt = local_prompt_prefix = (char *)NULL; - rl_forced_update_display (); - rl_display_prompt = oldp; - local_prompt = oldl; - local_prompt_prefix = oldlprefix; - } + redraw_prompt (++t); else rl_forced_update_display (); } @@ -1571,3 +1670,25 @@ _rl_erase_entire_line () cr (); fflush (rl_outstream); } + +/* return the `current display line' of the cursor -- the number of lines to + move up to get to the first screen line of the current readline line. */ +int +_rl_current_display_line () +{ + int ret, nleft; + + /* Find out whether or not there might be invisible characters in the + editing buffer. */ + if (rl_display_prompt == rl_prompt) + nleft = _rl_last_c_pos - screenwidth - rl_visible_prompt_length; + else + nleft = _rl_last_c_pos - screenwidth; + + if (nleft > 0) + ret = 1 + nleft / screenwidth; + else + ret = 0; + + return ret; +} diff --git a/contrib/libreadline/doc/readline.3 b/contrib/libreadline/doc/readline.3 index 5f01b6c..dce095f 100644 --- a/contrib/libreadline/doc/readline.3 +++ b/contrib/libreadline/doc/readline.3 @@ -1,3 +1,4 @@ +.\" $FreeBSD$ .\" .\" MAN PAGE COMMENTS to .\" @@ -6,9 +7,9 @@ .\" Case Western Reserve University .\" chet@ins.CWRU.Edu .\" -.\" Last Change: Thu Dec 31 10:16:30 EST 1998 +.\" Last Change: Tue Jun 1 13:28:03 EDT 1999 .\" -.TH READLINE 3 "1998 Dec 31" GNU +.TH READLINE 3 "1999 Jun 1" GNU .\" .\" File Name macro. This used to be `.PN', for Path Name, .\" but Sun doesn't seem to like that very much. @@ -148,6 +149,7 @@ processing key bindings: .IR SPACE , and .IR TAB . +.PP In addition to command names, readline allows keys to be bound to a string that is inserted when the key is pressed (a \fImacro\fP). .PP @@ -564,7 +566,7 @@ Move forward to the end of the next word. Words are composed of alphanumeric characters (letters and digits). .TP .B backward\-word (M\-b) -Move back to the start of this, or the previous, word. Words are +Move back to the start of the current or previous word. Words are composed of alphanumeric characters (letters and digits). .TP .B clear\-screen (C\-l) @@ -1172,9 +1174,9 @@ VI Command Mode functions Individual \fBreadline\fP initialization file .PD .SH AUTHORS -Brian Fox, Free Software Foundation (primary author) +Brian Fox, Free Software Foundation .br -bfox@ai.MIT.Edu +bfox@gnu.org .PP Chet Ramey, Case Western Reserve University .br diff --git a/contrib/libreadline/readline.3 b/contrib/libreadline/readline.3 index 5f01b6c..dce095f 100644 --- a/contrib/libreadline/readline.3 +++ b/contrib/libreadline/readline.3 @@ -1,3 +1,4 @@ +.\" $FreeBSD$ .\" .\" MAN PAGE COMMENTS to .\" @@ -6,9 +7,9 @@ .\" Case Western Reserve University .\" chet@ins.CWRU.Edu .\" -.\" Last Change: Thu Dec 31 10:16:30 EST 1998 +.\" Last Change: Tue Jun 1 13:28:03 EDT 1999 .\" -.TH READLINE 3 "1998 Dec 31" GNU +.TH READLINE 3 "1999 Jun 1" GNU .\" .\" File Name macro. This used to be `.PN', for Path Name, .\" but Sun doesn't seem to like that very much. @@ -148,6 +149,7 @@ processing key bindings: .IR SPACE , and .IR TAB . +.PP In addition to command names, readline allows keys to be bound to a string that is inserted when the key is pressed (a \fImacro\fP). .PP @@ -564,7 +566,7 @@ Move forward to the end of the next word. Words are composed of alphanumeric characters (letters and digits). .TP .B backward\-word (M\-b) -Move back to the start of this, or the previous, word. Words are +Move back to the start of the current or previous word. Words are composed of alphanumeric characters (letters and digits). .TP .B clear\-screen (C\-l) @@ -1172,9 +1174,9 @@ VI Command Mode functions Individual \fBreadline\fP initialization file .PD .SH AUTHORS -Brian Fox, Free Software Foundation (primary author) +Brian Fox, Free Software Foundation .br -bfox@ai.MIT.Edu +bfox@gnu.org .PP Chet Ramey, Case Western Reserve University .br diff --git a/contrib/libreadline/readline.h b/contrib/libreadline/readline.h index 21fe31b..feb54a0 100644 --- a/contrib/libreadline/readline.h +++ b/contrib/libreadline/readline.h @@ -1,3 +1,4 @@ +/* $FreeBSD$ */ /* Readline.h -- the names of functions callable from within readline. */ /* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc. @@ -7,7 +8,7 @@ The GNU Readline Library 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 1, or + as published by the Free Software Foundation; either version 2, or (at your option) any later version. The GNU Readline Library is distributed in the hope that it will be @@ -18,9 +19,7 @@ The GNU General Public License is often shipped with GNU software, and is generally kept in a file called COPYING or LICENSE. If you do not have a copy of the license, write to the Free Software Foundation, - 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* $FreeBSD$ */ + 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ #if !defined (_READLINE_H_) #define _READLINE_H_ @@ -194,7 +193,7 @@ extern int rl_noninc_reverse_search __P((int, int)); extern int rl_noninc_forward_search_again __P((int, int)); extern int rl_noninc_reverse_search_again __P((int, int)); -/* Not available unless readline is compiled -DPAREN_MATCHING. */ +/* Bindable command used when inserting a matching close character. */ extern int rl_insert_close __P((int, int)); /* Not available unless READLINE_CALLBACKS is defined. */ @@ -302,7 +301,15 @@ extern int rl_read_init_file __P((char *)); extern int rl_parse_and_bind __P((char *)); /* Functions for manipulating keymaps. */ +extern Keymap rl_make_bare_keymap __P((void)); +extern Keymap rl_copy_keymap __P((Keymap)); +extern Keymap rl_make_keymap __P((void)); +extern void rl_discard_keymap __P((Keymap)); + +extern Keymap rl_get_keymap_by_name __P((char *)); extern char *rl_get_keymap_name __P((Keymap)); +extern void rl_set_keymap __P((Keymap)); +extern Keymap rl_get_keymap __P((void)); extern void rl_set_keymap_from_edit_mode __P((void)); extern char *rl_get_keymap_name_from_edit_mode __P((void)); @@ -325,11 +332,12 @@ extern int rl_modifying __P((int, int)); /* Functions for redisplay. */ extern void rl_redisplay __P((void)); extern int rl_on_new_line __P((void)); +extern int rl_on_new_line_with_prompt __P((void)); extern int rl_forced_update_display __P((void)); extern int rl_clear_message __P((void)); extern int rl_reset_line_state __P((void)); -#if defined (__STDC__) && defined (USE_VARARGS) && defined (PREFER_STDARG) +#if (defined (__STDC__) || defined (__cplusplus)) && defined (USE_VARARGS) && defined (PREFER_STDARG) extern int rl_message (const char *, ...); #else extern int rl_message (); @@ -399,6 +407,9 @@ extern char *filename_completion_function __P((char *, int)); /* The version of this incarnation of the readline library. */ extern char *rl_library_version; +/* True if this is real GNU readline. */ +extern int rl_gnu_readline_p; + /* The name of the calling program. You should initialize this to whatever was in argv[0]. It is used when parsing conditionals. */ extern char *rl_readline_name; @@ -462,6 +473,15 @@ extern Keymap rl_binding_keymap; rl_newline. */ extern int rl_erase_empty_line; +/* If non-zero, the application has already printed the prompt (rl_prompt) + before calling readline, so readline should not output it the first time + redisplay is done. */ +extern int rl_already_prompted; + +/* A non-zero value means to read only this many characters rather than + up to a character bound to accept-line. */ +extern int rl_num_chars_to_read; + /* Variables to control readline signal handling. */ /* If non-zero, readline will install its own signal handlers for SIGINT, SIGTERM, SIGQUIT, SIGALRM, SIGTSTP, SIGTTIN, and SIGTTOU. */ @@ -606,7 +626,7 @@ extern int rl_inhibit_completion; #if !defined (savestring) #define savestring rl_savestring -extern char *savestring (); /* XXX backwards compatibility */ +extern char *savestring __P((char *)); /* XXX backwards compatibility */ #endif #ifdef __cplusplus diff --git a/contrib/libreadline/rlconf.h b/contrib/libreadline/rlconf.h index 1356fd8..fcac3cc 100644 --- a/contrib/libreadline/rlconf.h +++ b/contrib/libreadline/rlconf.h @@ -1,3 +1,4 @@ +/* $FreeBSD$ */ /* rlconf.h -- readline configuration definitions */ /* Copyright (C) 1994 Free Software Foundation, Inc. @@ -8,7 +9,7 @@ The Library 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 1, or (at your option) + the Free Software Foundation; either version 2, or (at your option) any later version. The Library is distributed in the hope that it will be useful, but @@ -19,7 +20,7 @@ The GNU General Public License is often shipped with GNU software, and is generally kept in a file called COPYING or LICENSE. If you do not have a copy of the license, write to the Free Software Foundation, - 675 Mass Ave, Cambridge, MA 02139, USA. */ + 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ #if !defined (_RLCONF_H_) #define _RLCONF_H_ @@ -30,10 +31,6 @@ /* Define this to get an indication of file type when listing completions. */ #define VISIBLE_STATS -/* If defined, readline shows opening parens and braces when closing - paren or brace entered. */ -/* #define PAREN_MATCHING */ - /* This definition is needed by readline.c, rltty.c, and signals.c. */ /* If on, then readline handles signals in a way that doesn't screw. */ #define HANDLE_SIGNALS diff --git a/contrib/libreadline/shell.c b/contrib/libreadline/shell.c index 091ec08..10571e3 100644 --- a/contrib/libreadline/shell.c +++ b/contrib/libreadline/shell.c @@ -1,3 +1,4 @@ +/* $FreeBSD$ */ /* shell.c -- readline utility functions that are normally provided by bash when readline is linked as part of the shell. */ @@ -8,7 +9,7 @@ The GNU Readline Library 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 1, or + as published by the Free Software Foundation; either version 2, or (at your option) any later version. The GNU Readline Library is distributed in the hope that it will be @@ -19,7 +20,7 @@ The GNU General Public License is often shipped with GNU software, and is generally kept in a file called COPYING or LICENSE. If you do not have a copy of the license, write to the Free Software Foundation, - 675 Mass Ave, Cambridge, MA 02139, USA. */ + 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ #define READLINE_LIBRARY #if defined (HAVE_CONFIG_H) @@ -44,13 +45,21 @@ # include <strings.h> #endif /* !HAVE_STRING_H */ +#include <fcntl.h> #include <pwd.h> +#include <stdio.h> + +#include "rlshell.h" +#include "xmalloc.h" + #if !defined (HAVE_GETPW_DECLS) extern struct passwd *getpwuid (); #endif /* !HAVE_GETPW_DECLS */ -extern char *xmalloc (); +#ifndef NULL +# define NULL 0 +#endif /* All of these functions are resolved from bash if we are linking readline as part of bash. */ @@ -63,7 +72,7 @@ single_quote (string) register int c; char *result, *r, *s; - result = (char *)xmalloc (3 + (3 * strlen (string))); + result = (char *)xmalloc (3 + (4 * strlen (string))); r = result; *r++ = '\''; @@ -131,3 +140,37 @@ get_home_dir () home_dir = entry->pw_dir; return (home_dir); } + +#if !defined (O_NDELAY) +# if defined (FNDELAY) +# define O_NDELAY FNDELAY +# endif +#endif + +int +unset_nodelay_mode (fd) + int fd; +{ + int flags, bflags; + + if ((flags = fcntl (fd, F_GETFL, 0)) < 0) + return -1; + + bflags = 0; + +#ifdef O_NONBLOCK + bflags |= O_NONBLOCK; +#endif + +#ifdef O_NDELAY + bflags |= O_NDELAY; +#endif + + if (flags & bflags) + { + flags &= ~bflags; + return (fcntl (fd, F_SETFL, flags)); + } + + return 0; +} diff --git a/contrib/libreadline/terminal.c b/contrib/libreadline/terminal.c index e62b76c..61a28f3 100644 --- a/contrib/libreadline/terminal.c +++ b/contrib/libreadline/terminal.c @@ -1,3 +1,4 @@ +/* $FreeBSD$ */ /* terminal.c -- controlling the terminal with termcap. */ /* Copyright (C) 1996 Free Software Foundation, Inc. @@ -7,7 +8,7 @@ The GNU Readline Library 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 1, or + as published by the Free Software Foundation; either version 2, or (at your option) any later version. The GNU Readline Library is distributed in the hope that it will be @@ -18,7 +19,7 @@ The GNU General Public License is often shipped with GNU software, and is generally kept in a file called COPYING or LICENSE. If you do not have a copy of the license, write to the Free Software Foundation, - 675 Mass Ave, Cambridge, MA 02139, USA. */ + 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ #define READLINE_LIBRARY #if defined (HAVE_CONFIG_H) @@ -46,9 +47,7 @@ # include <locale.h> #endif -#include <signal.h> #include <stdio.h> -#include <setjmp.h> /* System-specific feature definitions and include files. */ #include "rldefs.h" @@ -64,18 +63,8 @@ #include "readline.h" #include "history.h" -/* Variables and functions imported from readline.c */ -extern FILE *_rl_in_stream, *_rl_out_stream; -extern int readline_echoing_p; -extern int _rl_bell_preference; -extern Keymap _rl_keymap; - -/* Functions imported from bind.c */ -extern void _rl_bind_if_unbound (); - -/* Functions imported from shell.c */ -extern void set_lines_and_columns (); -extern char *get_env_value (); +#include "rlprivate.h" +#include "rlshell.h" /* **************************************************************** */ /* */ @@ -149,6 +138,22 @@ 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) + int *swp, *shp; +{ + int sz[2]; + + _scrsize (sz); + + if (swp) + *swp = sz[0]; + if (shp) + *shp = sz[1]; +} +#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 @@ -161,9 +166,6 @@ _rl_get_screen_size (tty, ignore_env) #if defined (TIOCGWINSZ) struct winsize window_size; #endif /* TIOCGWINSZ */ -#if defined (__EMX__) - int sz[2]; -#endif #if defined (TIOCGWINSZ) if (ioctl (tty, TIOCGWINSZ, &window_size) == 0) @@ -174,9 +176,7 @@ _rl_get_screen_size (tty, ignore_env) #endif /* TIOCGWINSZ */ #if defined (__EMX__) - _scrsize (sz); - screenwidth = sz[0]; - screenheight = sz[1]; + _emx_get_screensize (&screenwidth, &screenheight); #endif /* Environment variable COLUMNS overrides setting of "co" if IGNORE_ENV @@ -186,8 +186,10 @@ _rl_get_screen_size (tty, ignore_env) if (ignore_env == 0 && (ss = get_env_value ("COLUMNS"))) screenwidth = atoi (ss); +#if !defined (__DJGPP__) if (screenwidth <= 0 && term_string_buffer) screenwidth = tgetnum ("co"); +#endif } /* Environment variable LINES overrides setting of "li" if IGNORE_ENV @@ -197,8 +199,10 @@ _rl_get_screen_size (tty, ignore_env) if (ignore_env == 0 && (ss = get_env_value ("LINES"))) screenheight = atoi (ss); +#if !defined (__DJGPP__) if (screenheight <= 0 && term_string_buffer) screenheight = tgetnum ("li"); +#endif } /* If all else fails, default to 80x24 terminal. */ @@ -213,7 +217,7 @@ _rl_get_screen_size (tty, ignore_env) do a pair of putenv () or setenv () calls. */ set_lines_and_columns (screenheight, screenwidth); - if (!_rl_term_autowrap) + if (_rl_term_autowrap == 0) screenwidth--; screenchars = screenwidth * screenheight; @@ -251,32 +255,32 @@ struct _tc_string { search algorithm to something smarter. */ static struct _tc_string tc_strings[] = { - "DC", &term_DC, - "IC", &term_IC, - "ce", &term_clreol, - "cl", &term_clrpag, - "cr", &term_cr, - "dc", &term_dc, - "ei", &term_ei, - "ic", &term_ic, - "im", &term_im, - "kd", &term_kd, - "kh", &term_kh, /* home */ - "@7", &term_kH, /* end */ - "kl", &term_kl, - "kr", &term_kr, - "ku", &term_ku, - "ks", &term_ks, - "ke", &term_ke, - "le", &term_backspace, - "mm", &term_mm, - "mo", &term_mo, + { "DC", &term_DC }, + { "IC", &term_IC }, + { "ce", &term_clreol }, + { "cl", &term_clrpag }, + { "cr", &term_cr }, + { "dc", &term_dc }, + { "ei", &term_ei }, + { "ic", &term_ic }, + { "im", &term_im }, + { "kd", &term_kd }, + { "kh", &term_kh }, /* home */ + { "@7", &term_kH }, /* end */ + { "kl", &term_kl }, + { "kr", &term_kr }, + { "ku", &term_ku }, + { "ks", &term_ks }, + { "ke", &term_ke }, + { "le", &term_backspace }, + { "mm", &term_mm }, + { "mo", &term_mo }, #if defined (HACK_TERMCAP_MOTION) - "nd", &term_forward_char, + { "nd", &term_forward_char }, #endif - "pc", &term_pc, - "up", &term_up, - "vb", &visible_bell, + { "pc", &term_pc }, + { "up", &term_up }, + { "vb", &visible_bell }, }; #define NUM_TC_STRINGS (sizeof (tc_strings) / sizeof (struct _tc_string)) @@ -287,72 +291,96 @@ 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 (tc_strings[i].tc_var, bp); +#endif tcap_initialized = 1; } +#define CUSTOM_REDISPLAY_FUNC() (rl_redisplay_function != rl_redisplay) +#define CUSTOM_INPUT_FUNC() (rl_getc_function != rl_getc) + int _rl_init_terminal_io (terminal_name) char *terminal_name; { -#if defined (__GO32__) - screenwidth = ScreenCols (); - screenheight = ScreenRows (); - screenchars = screenwidth * screenheight; - term_cr = "\r"; - term_im = term_ei = term_ic = term_IC = (char *)NULL; - term_up = term_dc = term_DC = visible_bell = (char *)NULL; - - /* Does the __GO32__ have a meta key? I don't know. */ - term_has_meta = 0; - term_mm = term_mo = (char *)NULL; - - /* It probably has arrow keys, but I don't know what they are. */ - term_ku = term_kd = term_kr = term_kl = (char *)NULL; - -#if defined (HACK_TERMCAP_MOTION) - term_forward_char = (char *)NULL; -#endif /* HACK_TERMCAP_MOTION */ - terminal_can_insert = _rl_term_autowrap = 0; - return; -#else /* !__GO32__ */ - char *term, *buffer; - int tty; + int tty, tgetent_ret; Keymap xkeymap; term = terminal_name ? terminal_name : get_env_value ("TERM"); + term_clrpag = term_cr = term_clreol = (char *)NULL; + tty = rl_instream ? fileno (rl_instream) : 0; + screenwidth = screenheight = 0; - if (term_string_buffer == 0) - term_string_buffer = xmalloc (2032); + if (term == 0) + term = "dumb"; - if (term_buffer == 0) - term_buffer = xmalloc (4080); + /* I've separated this out for later work on not calling tgetent at all + if the calling application has supplied a custom redisplay function, + (and possibly if the application has supplied a custom input function). */ + if (CUSTOM_REDISPLAY_FUNC()) + { + tgetent_ret = -1; + } + else + { + if (term_string_buffer == 0) + term_string_buffer = xmalloc(2032); - buffer = term_string_buffer; + if (term_buffer == 0) + term_buffer = xmalloc(4080); - term_clrpag = term_cr = term_clreol = (char *)NULL; + buffer = term_string_buffer; - if (term == 0) - term = "dumb"; + tgetent_ret = tgetent (term_buffer, term); + } - if (tgetent (term_buffer, term) <= 0) + if (tgetent_ret <= 0) { + FREE (term_string_buffer); + FREE (term_buffer); + buffer = term_buffer = term_string_buffer = (char *)NULL; + dumb_term = 1; - screenwidth = 79; - screenheight = 24; - screenchars = 79 * 24; + _rl_term_autowrap = 0; /* used by _rl_get_screen_size */ + +#if defined (__EMX__) + _emx_get_screensize (&screenwidth, &screenheight); + screenwidth--; +#else /* !__EMX__ */ + _rl_get_screen_size (tty, 0); +#endif /* !__EMX__ */ + + /* Defaults. */ + if (screenwidth <= 0 || screenheight <= 0) + { + screenwidth = 79; + screenheight = 24; + } + + /* Everything below here is used by the redisplay code (tputs). */ + screenchars = screenwidth * screenheight; term_cr = "\r"; term_im = term_ei = term_ic = term_IC = (char *)NULL; term_up = term_dc = term_DC = visible_bell = (char *)NULL; term_ku = term_kd = term_kl = term_kr = (char *)NULL; + term_mm = term_mo = (char *)NULL; #if defined (HACK_TERMCAP_MOTION) term_forward_char = (char *)NULL; #endif - terminal_can_insert = 0; + terminal_can_insert = term_has_meta = 0; + + /* Reasonable defaults for tgoto(). Readline currently only uses + tgoto if term_IC or term_DC is defined, but just in case we + change that later... */ + PC = '\0'; + BC = term_backspace = "\b"; + UP = term_up; + return 0; } @@ -367,10 +395,6 @@ _rl_init_terminal_io (terminal_name) if (!term_cr) term_cr = "\r"; - tty = rl_instream ? fileno (rl_instream) : 0; - - screenwidth = screenheight = 0; - _rl_term_autowrap = tgetflag ("am") && tgetflag ("xn"); _rl_get_screen_size (tty, 0); @@ -413,7 +437,6 @@ _rl_init_terminal_io (terminal_name) _rl_keymap = xkeymap; -#endif /* !__GO32__ */ return 0; } @@ -459,6 +482,7 @@ _rl_output_character_function (c) return putc (c, _rl_out_stream); } #endif /* !_MINIX */ + /* Write COUNT characters from STRING to the output stream. */ void _rl_output_some_chars (string, count) @@ -475,12 +499,10 @@ _rl_backspace (count) { register int i; -#if !defined (__GO32__) if (term_backspace) for (i = 0; i < count; i++) tputs (term_backspace, 1, _rl_output_character_function); else -#endif /* !__GO32__ */ for (i = 0; i < count; i++) putc ('\b', _rl_out_stream); return 0; @@ -504,7 +526,6 @@ ding () { if (readline_echoing_p) { -#if !defined (__GO32__) switch (_rl_bell_preference) { case NO_BELL: @@ -522,10 +543,6 @@ ding () fflush (stderr); break; } -#else /* __GO32__ */ - fprintf (stderr, "\007"); - fflush (stderr); -#endif /* __GO32__ */ return (0); } return (-1); @@ -540,16 +557,20 @@ ding () void _rl_enable_meta_key () { +#if !defined (__DJGPP__) if (term_has_meta && term_mm) tputs (term_mm, 1, _rl_output_character_function); +#endif } void _rl_control_keypad (on) int on; { +#if !defined (__DJGPP__) if (on && term_ks) tputs (term_ks, 1, _rl_output_character_function); else if (!on && term_ke) tputs (term_ke, 1, _rl_output_character_function); +#endif } diff --git a/contrib/libreadline/util.c b/contrib/libreadline/util.c index 1dc3b66..cd6a3b0 100644 --- a/contrib/libreadline/util.c +++ b/contrib/libreadline/util.c @@ -1,3 +1,4 @@ +/* $FreeBSD$ */ /* util.c -- readline utility functions */ /* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc. @@ -7,7 +8,7 @@ The GNU Readline Library 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 1, or + as published by the Free Software Foundation; either version 2, or (at your option) any later version. The GNU Readline Library is distributed in the hope that it will be @@ -18,7 +19,7 @@ The GNU General Public License is often shipped with GNU software, and is generally kept in a file called COPYING or LICENSE. If you do not have a copy of the license, write to the Free Software Foundation, - 675 Mass Ave, Cambridge, MA 02139, USA. */ + 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ #define READLINE_LIBRARY #if defined (HAVE_CONFIG_H) @@ -52,24 +53,10 @@ /* Some standard library routines. */ #include "readline.h" -#define SWAP(s, e) do { int t; t = s; s = e; e = t; } while (0) - -/* Pseudo-globals imported from readline.c */ -extern int readline_echoing_p; -extern procenv_t readline_top_level; -extern int rl_line_buffer_len; -extern Function *rl_last_func; - -extern int _rl_defining_kbd_macro; -extern char *_rl_executing_macro; +#include "rlprivate.h" +#include "xmalloc.h" -/* Pseudo-global functions imported from other library files. */ -extern void _rl_replace_text (); -extern void _rl_pop_executing_macro (); -extern void _rl_set_the_line (); -extern void _rl_init_argument (); - -extern char *xmalloc (), *xrealloc (); +#define SWAP(s, e) do { int t; t = s; s = e; e = t; } while (0) /* **************************************************************** */ /* */ |