mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-26 22:07:58 +08:00
Touched all sources to ease import of readline 2.2.1
This commit is contained in:
58
readline/examples/Inputrc
Normal file
58
readline/examples/Inputrc
Normal file
@ -0,0 +1,58 @@
|
||||
# My ~/.inputrc file is in -*- text -*- for easy editing with Emacs.
|
||||
#
|
||||
# Notice the various bindings which are conditionalized depending
|
||||
# on which program is running, or what terminal is active.
|
||||
#
|
||||
|
||||
# In all programs, all terminals, make sure this is bound.
|
||||
"\C-x\C-r": re-read-init-file
|
||||
|
||||
# Hp terminals (and some others) have ugly default behaviour for C-h.
|
||||
"\C-h": backward-delete-char
|
||||
"\e\C-h": backward-kill-word
|
||||
"\C-xd": dump-functions
|
||||
|
||||
# In xterm windows, make the arrow keys do the right thing.
|
||||
$if TERM=xterm
|
||||
"\e[A": previous-history
|
||||
"\e[B": next-history
|
||||
"\e[C": forward-char
|
||||
"\e[D": backward-char
|
||||
|
||||
# Under Xterm in Bash, we bind local Function keys to do something useful.
|
||||
$if Bash
|
||||
"\e[11~": "Function Key 1"
|
||||
"\e[12~": "Function Key 2"
|
||||
"\e[13~": "Function Key 3"
|
||||
"\e[14~": "Function Key 4"
|
||||
"\e[15~": "Function Key 5"
|
||||
|
||||
# I know the following escape sequence numbers are 1 greater than
|
||||
# the function key. Don't ask me why, I didn't design the xterm terminal.
|
||||
"\e[17~": "Function Key 6"
|
||||
"\e[18~": "Function Key 7"
|
||||
"\e[19~": "Function Key 8"
|
||||
"\e[20~": "Function Key 9"
|
||||
"\e[21~": "Function Key 10"
|
||||
$endif
|
||||
$endif
|
||||
|
||||
# For Bash, all terminals, add some Bash specific hacks.
|
||||
$if Bash
|
||||
"\C-xv": show-bash-version
|
||||
"\C-x\C-e": shell-expand-line
|
||||
|
||||
# Here is one for editing my path.
|
||||
"\C-xp": "$PATH\C-x\C-e\C-e\"\C-aPATH=\":\C-b"
|
||||
|
||||
# Make C-x r read my mail in emacs.
|
||||
# "\C-xr": "emacs -f rmail\C-j"
|
||||
$endif
|
||||
|
||||
# For FTP, different hacks:
|
||||
$if Ftp
|
||||
"\C-xg": "get \M-?"
|
||||
"\C-xt": "put \M-?"
|
||||
$endif
|
||||
|
||||
" ": self-insert
|
96
readline/examples/manexamp.c
Normal file
96
readline/examples/manexamp.c
Normal file
@ -0,0 +1,96 @@
|
||||
/* manexamp.c -- The examples which appear in the documentation are here. */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <readline/readline.h>
|
||||
|
||||
|
||||
/* **************************************************************** */
|
||||
/* */
|
||||
* How to Emulate gets () */
|
||||
/* */
|
||||
/* **************************************************************** */
|
||||
|
||||
/* A static variable for holding the line. */
|
||||
static char *line_read = (char *)NULL;
|
||||
|
||||
/* Read a string, and return a pointer to it. Returns NULL on EOF. */
|
||||
char *
|
||||
do_gets ()
|
||||
{
|
||||
/* If the buffer has already been allocated, return the memory
|
||||
to the free pool. */
|
||||
if (line_read != (char *)NULL)
|
||||
{
|
||||
free (line_read);
|
||||
line_read = (char *)NULL;
|
||||
}
|
||||
|
||||
/* Get a line from the user. */
|
||||
line_read = readline ("");
|
||||
|
||||
/* If the line has any text in it, save it on the history. */
|
||||
if (line_read && *line_read)
|
||||
add_history (line_read);
|
||||
|
||||
return (line_read);
|
||||
}
|
||||
|
||||
|
||||
/* **************************************************************** */
|
||||
/* */
|
||||
/* Writing a Function to be Called by Readline. */
|
||||
/* */
|
||||
/* **************************************************************** */
|
||||
|
||||
/* Invert the case of the COUNT following characters. */
|
||||
invert_case_line (count, key)
|
||||
int count, key;
|
||||
{
|
||||
register int start, end;
|
||||
|
||||
start = rl_point;
|
||||
|
||||
if (count < 0)
|
||||
{
|
||||
direction = -1;
|
||||
count = -count;
|
||||
}
|
||||
else
|
||||
direction = 1;
|
||||
|
||||
/* Find the end of the range to modify. */
|
||||
end = start + (count * direction);
|
||||
|
||||
/* Force it to be within range. */
|
||||
if (end > rl_end)
|
||||
end = rl_end;
|
||||
else if (end < 0)
|
||||
end = -1;
|
||||
|
||||
if (start > end)
|
||||
{
|
||||
int temp = start;
|
||||
start = end;
|
||||
end = temp;
|
||||
}
|
||||
|
||||
if (start == end)
|
||||
return;
|
||||
|
||||
/* Tell readline that we are modifying the line, so save the undo
|
||||
information. */
|
||||
rl_modifying (start, end);
|
||||
|
||||
for (; start != end; start += direction)
|
||||
{
|
||||
if (uppercase_p (rl_line_buffer[start]))
|
||||
rl_line_buffer[start] = to_lower (rl_line_buffer[start]);
|
||||
else if (lowercase_p (rl_line_buffer[start]))
|
||||
rl_line_buffer[start] = to_upper (rl_line_buffer[start]);
|
||||
}
|
||||
|
||||
/* Move point to on top of the last character changed. */
|
||||
rl_point = end - direction;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user