TheGNUGeneralPublicLicenseisoftenshippedwithGNUsoftware,and isgenerallykeptinafilecalledCOPYINGorLICENSE.Ifyoudonot haveacopyofthelicense,writetotheFreeSoftwareFoundation,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA. */ #define READLINE_LIBRARY
#ifdefined (HAVE_CONFIG_H) # include "config_readline.h" #endif
/* True if this is `real' readline as opposed to some stub substitute. */ int rl_gnu_readline_p = 1;
/* A pointer to the keymap that is currently in use.
By default, it is the standard emacs keymap. */
Keymap _rl_keymap = emacs_standard_keymap;
/* The current style of editing. */ int rl_editing_mode = emacs_mode;
/* The current insert mode: input (the default) or overwrite */ int rl_insert_mode = RL_IM_DEFAULT;
/* Non-zero if we called this function from _rl_dispatch(). It's present sofunctionscanfindoutwhethertheywerecalledfromakeybinding
or directly from an application. */ int rl_dispatching;
/* Non-zero if the previous command was a kill command. */ int _rl_last_command_was_kill = 0;
/* The current value of the numeric argument specified by the user. */ int rl_numeric_arg = 1;
/* Non-zero if an argument was typed. */ int rl_explicit_arg = 0;
/* Temporary value used while generating the argument. */ int rl_arg_sign = 1;
/* Non-zero means we have been called at least once before. */ staticint rl_initialized;
#if0 /* If non-zero, this program is running in an EMACS buffer. */ staticint running_in_emacs; #endif
/* Flags word encapsulating the current readline state. */ int rl_readline_state = RL_STATE_NONE;
/* The current offset in the current input line. */ int rl_point;
/* Mark in the current input line. */ int rl_mark;
/* Length of the current input line. */ int rl_end;
/* Make this non-zero to return the current input_line. */ int rl_done;
/* The last function executed by readline. */
rl_command_func_t *rl_last_func = (rl_command_func_t *)NULL;
/* Top level environment for readline_internal (). */
procenv_t readline_top_level;
/* The streams we interact with. */
FILE *_rl_in_stream, *_rl_out_stream;
/* The names of the streams that we do input and output to. */
FILE *rl_instream = (FILE *)NULL;
FILE *rl_outstream = (FILE *)NULL;
/* Non-zero means echo characters as they are read. Defaults to no echo; setto1ifthereisacontrollingterminal,wecangetitsattributes, andtheattributesinclude`echo'.Lookatrltty.c:prepare_terminal_settings
for the code that sets it. */ int readline_echoing_p = 0;
/* Current prompt. */ char *rl_prompt = (char *)NULL; int rl_visible_prompt_length = 0;
/* Set to non-zero by calling application if it has already printed rl_prompt
and does not want readline to do it the first time. */ int rl_already_prompted = 0;
/* The number of characters read in order to type this complete command. */ int rl_key_sequence_length = 0;
/* If non-zero, then this is the address of a function to call just
before readline_internal_setup () prints the first prompt. */
rl_hook_func_t *rl_startup_hook = (rl_hook_func_t *)NULL;
/* If non-zero, this is the address of a function to call just before readline_internal_setup()returnsandreadline_internalstarts
reading input characters. */
rl_hook_func_t *rl_pre_input_hook = (rl_hook_func_t *)NULL;
/* What we use internally. You should always refer to RL_LINE_BUFFER. */ staticchar *the_line;
/* The character that can generate an EOF. Really read from
the terminal driver... just defaulted here. */ int _rl_eof_char = CTRL ('D');
/* Non-zero makes this the next keystroke to read. */ int rl_pending_input = 0;
/* Pointer to a useful terminal name. */ constchar *rl_terminal_name = (constchar *)NULL;
/* Non-zero means to always use horizontal scrolling in line display. */ int _rl_horizontal_scroll_mode = 0;
/* Non-zero means to display an asterisk at the starts of history lines
which have been modified. */ int _rl_mark_modified_lines = 0;
/* The style of `bell' notification preferred. This can be set to NO_BELL,
AUDIBLE_BELL, or VISIBLE_BELL. */ int _rl_bell_preference = AUDIBLE_BELL;
/* String inserted into the line by rl_insert_comment (). */ char *_rl_comment_begin;
/* Keymap holding the function currently being executed. */
Keymap rl_executing_keymap;
/* Keymap we're currently using to dispatch. */
Keymap _rl_dispatching_keymap;
/* Non-zero means to erase entire line, including prompt, on empty input lines. */ int rl_erase_empty_line = 0;
/* Non-zero means to read only this many characters rather than up to a
character bound to accept-line. */ int rl_num_chars_to_read;
/* Line buffer and maintenence. */ char *rl_line_buffer = (char *)NULL; int rl_line_buffer_len = 0;
/* Non-zero means do not parse any lines other than comments and
parser directives. */ unsignedchar _rl_parsing_conditionalized_out = 0;
/* Non-zero means to convert characters with the meta bit set to escape-prefixedcharacterssowecanindirectthrough
emacs_meta_keymap or vi_escape_keymap. */ int _rl_convert_meta_chars_to_ascii = 1;
/* Non-zero means to output characters with the meta bit set directly
rather than as a meta-prefixed escape sequence. */ int _rl_output_meta_chars = 0;
/* Non-zero means to look at the termios special characters and bind
them to equivalent readline functions at startup. */ int _rl_bind_stty_chars = 1;
/* Non-zero means treat 0200 bit in terminal input as Meta bit. */ int _rl_meta_flag = 0; /* Forward declaration */
/* Set up the prompt and expand it. Called from readline() and
rl_callback_handler_install (). */ int
rl_set_prompt (prompt) constchar *prompt;
{
FREE (rl_prompt);
rl_prompt = prompt ? savestring (prompt) : (char *)NULL;
rl_display_prompt = rl_prompt ? rl_prompt : (char*) "";
/* Read a line of input. Prompt with PROMPT. An empty PROMPT means
none. A return value of NULL means that EOF was encountered. */ char *
readline (prompt) constchar *prompt;
{ char *value;
/* If we are at EOF return a NULL string. */ if (rl_pending_input == EOF)
{
rl_clear_pending_input (); return ((char *)NULL);
}
rl_set_prompt (prompt);
rl_initialize (); if (rl_prep_term_function)
(*rl_prep_term_function) (_rl_meta_flag);
/* If we're not echoing, we still want to at least print a prompt, because rl_redisplaywillnotdoitforus.Ifthecallingapplicationhasa
custom redisplay function, though, let that function handle it. */ if (readline_echoing_p == 0 && rl_redisplay_function == rl_redisplay)
{ if (rl_prompt && rl_already_prompted == 0)
{
nprompt = _rl_strip_prompt (rl_prompt);
fprintf (_rl_out_stream, "%s", nprompt);
fflush (_rl_out_stream);
free (nprompt);
}
} else
{ if (rl_prompt && rl_already_prompted)
rl_on_new_line_with_prompt (); else
rl_on_new_line ();
(*rl_redisplay_function) ();
}
/* Restore the original of this history line, iff the line that we
are editing was originally in the history, AND the line has changed. */
entry = current_history ();
void
_rl_internal_char_cleanup ()
{ #ifdefined (VI_MODE) /* In vi mode, when you exit insert mode, the cursor moves back
over the previous character. We explicitly check for that here. */ if (rl_editing_mode == vi_mode && _rl_keymap == vi_movement_keymap)
rl_vi_check (); #endif/* VI_MODE */
/* If the application writer has told us to erase the entire line if
the only character typed was something bound to rl_newline, do so. */ if (rl_erase_empty_line && rl_done && rl_last_func == rl_newline &&
rl_point == 0 && rl_end == 0)
_rl_erase_entire_line ();
}
STATIC_CALLBACK int #ifdefined (READLINE_CALLBACKS)
readline_internal_char () #else
readline_internal_charloop () #endif
{ staticint lastc; int c, code, lk;
if (code)
{
(*rl_redisplay_function) ();
_rl_want_redisplay = 0; /* If we get here, we're not being called from something dispatched from_rl_callback_read_char(),whichsetsupitsownvalueof readline_top_level(savingandrestoringtheold,ofcourse),so
we can just return here. */ if (RL_ISSTATE (RL_STATE_CALLBACK)) return (0);
}
if (rl_pending_input == 0)
{ /* Then initialize the argument and number of keys read. */
_rl_reset_argument ();
rl_key_sequence_length = 0;
}
RL_SETSTATE(RL_STATE_READCMD);
c = rl_read_key ();
RL_UNSETSTATE(RL_STATE_READCMD);
/* look at input.c:rl_getc() for the circumstances under which this will bereturned;puntimmediatelyonreaderrorwithoutconvertingitto
a newline. */ if (c == READERR)
{ #ifdefined (READLINE_CALLBACKS)
RL_SETSTATE(RL_STATE_DONE); return (rl_done = 1); #else
eof_found = 1; break; #endif
}
/* EOF typed to a non-blank line is a <NL>. */ if (c == EOF && rl_end)
c = NEWLINE;
/* The character _rl_eof_char typed to blank line, and not as the
previous character is interpreted as EOF. */ if (((c == _rl_eof_char && lastc != c) || c == EOF) && !rl_end)
{ #ifdefined (READLINE_CALLBACKS)
RL_SETSTATE(RL_STATE_DONE); return (rl_done = 1); #else
eof_found = 1; break; #endif
}
/* If there was no change in _rl_last_command_was_kill, then no kill hastakenplace.Notethatifinputispendingwearereading
a prefix command, so nothing has changed yet. */ if (rl_pending_input == 0 && lk == _rl_last_command_was_kill)
_rl_last_command_was_kill = 0;
_rl_internal_char_cleanup ();
#ifdefined (READLINE_CALLBACKS) return0; #else
}
return (eof_found); #endif
}
#ifdefined (READLINE_CALLBACKS) staticint
readline_internal_charloop ()
{ int eof = 1;
/* Read a line of input from the global rl_instream, doing output on theglobalrl_outstream.
If rl_prompt is non-null, then that is our prompt. */ staticchar *
readline_internal ()
{ int eof;
staticint
_rl_subseq_getchar (key) int key;
{ int k;
if (key == ESC)
RL_SETSTATE(RL_STATE_METANEXT);
RL_SETSTATE(RL_STATE_MOREINPUT);
k = rl_read_key ();
RL_UNSETSTATE(RL_STATE_MOREINPUT); if (key == ESC)
RL_UNSETSTATE(RL_STATE_METANEXT);
return k;
}
#ifdefined (READLINE_CALLBACKS) int
_rl_dispatch_callback (cxt)
_rl_keyseq_cxt *cxt;
{ int nkey, r;
/* For now */ #if1 /* The first time this context is used, we want to read input and dispatch onit.Whentraversingthechainofcontextsback`up',wewanttouse thevaluefromthenextcontextdown.We'resimulatingrecursionusing
a chain of contexts. */ if ((cxt->flags & KSEQ_DISPATCHED) == 0)
{
nkey = _rl_subseq_getchar (cxt->okey);
r = _rl_dispatch_subseq (nkey, cxt->dmap, cxt->subseq_arg);
cxt->flags |= KSEQ_DISPATCHED;
} else
r = cxt->childval; #else
r = _rl_dispatch_subseq (nkey, cxt->dmap, cxt->subseq_arg); #endif
/* For now */
r = _rl_subseq_result (r, cxt->oldmap, cxt->okey, (cxt->flags & KSEQ_SUBSEQ));
if (r != -3) /* magic value that says we added to the chain */
_rl_kscxt = cxt->ocxt; if (_rl_kscxt)
_rl_kscxt->childval = r; if (r != -3)
_rl_keyseq_cxt_dispose (cxt);
return r;
} #endif/* READLINE_CALLBACKS */
/* Do the command associated with KEY in MAP. Iftheassociatedcommandisreallyakeymap,thenread
another key, and dispatch into that map. */ int
_rl_dispatch (key, map) registerint key;
Keymap map;
{
_rl_dispatching_keymap = map; return _rl_dispatch_subseq (key, map, 0);
}
int
_rl_dispatch_subseq (key, map, got_subseq) registerint key;
Keymap map; int got_subseq;
{ int r, newkey; char *macro;
rl_command_func_t *func; #ifdefined (READLINE_CALLBACKS)
_rl_keyseq_cxt *cxt; #endif
if (RL_ISSTATE (RL_STATE_MACRODEF))
_rl_add_macro_char (key);
r = 0; switch (map[key].type)
{ case ISFUNC:
func = map[key].function; if (func)
{ /* Special case rl_do_lowercase_version (). */ if (func == rl_do_lowercase_version) return (_rl_dispatch (_rl_to_lower (key), map));
/* If we have input pending, then the last command was a prefix command.Don'tchangethestateofrl_last_func.Otherwise,
remember the last command executed in this variable. */ if (rl_pending_input == 0 && map[key].function != rl_digit_argument)
rl_last_func = map[key].function;
} elseif (map[ANYOTHERKEY].function)
{ /* OK, there's no function bound in this map, but there is a shadowfunctionthatwasoverriddenwhenthecurrentkeymap
was created. Return -2 to note that. */
_rl_unget_char (key); return -2;
} elseif (got_subseq)
{ /* Return -1 to note that we're in a subsequence, but we don't haveamatchingkey,norwasoneoverridden.Thismeans weneedtobackuptherecursionchainandfindthelast
subsequence that is bound to a function. */
_rl_unget_char (key); return -1;
} else
{ #ifdefined (READLINE_CALLBACKS)
RL_UNSETSTATE (RL_STATE_MULTIKEY);
_rl_keyseq_chain_dispose (); #endif
_rl_abort_internal (); return -1;
} break;
case ISKMAP: if (map[key].function != 0)
{ #ifdefined (VI_MODE) /* The only way this test will be true is if a subsequence has been boundstartingwithESC,generallythearrowkeys.Whatwedois checkwhetherthere'sinputinthequeue,whichtheregenerally willbeifanarrowkeyhasbeenpressed,and,ifthere'snot, justdispatchto(whatweassumeis)rl_vi_movement_moderight
away. This is essentially an input test with a zero timeout. */ if (rl_editing_mode == vi_mode && key == ESC && map == vi_insertion_keymap
&& _rl_input_queued (0) == 0) return (_rl_dispatch (ANYOTHERKEY, FUNCTION_TO_KEYMAP (map, key))); #endif
/* Allocate new context here. Use linked contexts (linked through
cxt->ocxt) to simulate recursion */ #ifdefined (READLINE_CALLBACKS) if (RL_ISSTATE (RL_STATE_CALLBACK))
{ /* Return 0 only the first time, to indicate success to _rl_callback_read_char.Therestofthetime,we'recalled from_rl_dispatch_callback,sowereturn3toindicate
special handling is necessary. */
r = RL_ISSTATE (RL_STATE_MULTIKEY) ? -3 : 0;
cxt = _rl_keyseq_cxt_alloc ();
staticint
_rl_subseq_result (r, map, key, got_subseq) int r;
Keymap map; int key, got_subseq;
{
Keymap m; int type, nt;
rl_command_func_t *func, *nf;
if (r == -2) /* We didn't match anything, and the keymap we're indexed into shadowedafunctionpreviouslyboundtothatprefix.Call thefunction.Therecursivecallto_rl_dispatch_subseqhas alreadytakencareofpushinganynecessaryinputbackonto
the input queue with _rl_unget_char. */
{
m = _rl_dispatching_keymap;
type = m[ANYOTHERKEY].type;
func = m[ANYOTHERKEY].function; if (type == ISFUNC && func == rl_do_lowercase_version)
r = _rl_dispatch (_rl_to_lower (key), map); elseif (type == ISFUNC && func == rl_insert)
{ /* If the function that was shadowed was self-insert, we somehowneedakeymapwithmap[key].func==self-insert.
Let's use this one. */
nt = m[key].type;
nf = m[key].function;
m[key].type = type;
m[key].function = func;
r = _rl_dispatch (key, m);
m[key].type = nt;
m[key].function = nf;
} else
r = _rl_dispatch (ANYOTHERKEY, m);
} elseif (r && map[ANYOTHERKEY].function)
{ /* We didn't match (r is probably -1), so return something to tellthecallerthatitshouldtryANYOTHERKEYforan
overridden function. */
_rl_unget_char (key);
_rl_dispatching_keymap = map; return -2;
} elseif (r && got_subseq)
{ /* OK, back up the chain. */
_rl_unget_char (key);
_rl_dispatching_keymap = map; return -1;
}
/* Initialize readline (and terminal if not already). */ int
rl_initialize ()
{ /* If we have never been called before, initialize the
terminal and data structures. */ if (!rl_initialized)
{
RL_SETSTATE(RL_STATE_INITIALIZING);
readline_initialize_everything ();
RL_UNSETSTATE(RL_STATE_INITIALIZING);
rl_initialized++;
RL_SETSTATE(RL_STATE_INITIALIZED);
}
/* Initalize the current line information. */
_rl_init_line_state ();
/* We aren't done yet. We haven't even gotten started yet! */
rl_done = 0;
RL_UNSETSTATE(RL_STATE_DONE);
/* Tell the history routines what is going on. */
_rl_start_using_history ();
/* Make the display buffer match the state of the line. */
rl_reset_line_state ();
/* No such function typed yet. */
rl_last_func = (rl_command_func_t *)NULL;
/* Parsing of key-bindings begins in an enabled state. */
_rl_parsing_conditionalized_out = 0;
#ifdefined (VI_MODE) if (rl_editing_mode == vi_mode)
_rl_vi_initialize_line (); #endif
/* Each line starts in insert mode (the default). */
_rl_set_insert_mode (RL_IM_DEFAULT, 1);
DosGetInfoBlocks (&tibp, &pibp);
t = pibp->pib_pchenv; for (c = 1; *t; c++)
t += strlen (t) + 1;
tp = environ = (char **)xmalloc ((c + 1) * sizeof (char *));
t = pibp->pib_pchenv; while (*t)
{
*tp++ = t;
t += strlen (t) + 1;
}
*tp = 0;
} #endif/* __EMX__ */ #endif
/* Initialize the entire state of the world. */ staticvoid
readline_initialize_everything ()
{ #if0 #ifdefined (__EMX__) if (environ == 0)
_emx_build_environ (); #endif #endif
#if0 /* Find out if we are running in Emacs -- UNUSED. */
running_in_emacs = sh_get_env_value ("EMACS") != (char *)0; #endif
/* Set up input and output if they are not already set up. */ if (!rl_instream)
rl_instream = stdin;
if (!rl_outstream)
rl_outstream = stdout;
/* Bind _rl_in_stream and _rl_out_stream immediately. These values maychange,buttheymayalsobeusedbeforereadline_internal()
is called. */
_rl_in_stream = rl_instream;
_rl_out_stream = rl_outstream;
/* Allocate data structures. */ if (rl_line_buffer == 0)
rl_line_buffer = (char *)xmalloc (rl_line_buffer_len = DEFAULT_BUFFER_SIZE);
/* Initialize the terminal interface. */ if (rl_terminal_name == 0)
rl_terminal_name = sh_get_env_value ("TERM");
_rl_init_terminal_io (rl_terminal_name);
/* Bind tty characters to readline functions. */
readline_default_bindings ();
/* Initialize the function names. */
rl_initialize_funmap ();
/* Decide whether we should automatically go into eight-bit mode. */
_rl_init_eightbit ();
/* Read in the init file. */
rl_read_init_file ((char *)NULL);
/* Override the effect of any `set keymap' assignments in the
inputrc file. */
rl_set_keymap_from_edit_mode ();
/* Try to bind a common arrow key prefix, if not already bound. */
bind_arrow_keys ();
/* Enable the meta key, if this terminal has one. */ if (_rl_enable_meta)
_rl_enable_meta_key ();
/* If the completion parser's default word break characters haven't
been set yet, then do so now. */ if (rl_completer_word_break_characters == (char *)NULL)
rl_completer_word_break_characters = (char *)rl_basic_word_break_characters;
}
/* If this system allows us to look at the values of the regular inputeditingcharacters,thenbindthemtotheirreadline
equivalents, iff the characters are not bound to keymaps. */ staticvoid
readline_default_bindings ()
{ if (_rl_bind_stty_chars)
rl_tty_set_default_bindings (_rl_keymap);
}
/* Bind some common arrow key sequences in MAP. */ staticvoid
bind_arrow_keys_internal (map)
Keymap map;
{
Keymap xkeymap;
/* Try and bind the common arrow key prefixes after giving termcap and theinputrcfileachancetobindthemandcreate`real'keymaps
for the arrow key prefix. */ staticvoid
bind_arrow_keys ()
{
bind_arrow_keys_internal (emacs_standard_keymap);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.