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
#include <sys/types.h>
#ifdefined (HAVE_UNISTD_H) # include <unistd.h> /* for _POSIX_VERSION */ #endif/* HAVE_UNISTD_H */
#ifdefined (HAVE_STDLIB_H) # include <stdlib.h> #else # include "ansi_stdlib.h" #endif/* HAVE_STDLIB_H */
#include <stdio.h>
/* System-specific feature definitions and include files. */ #include"rldefs.h"
/* Some standard library routines. */ #include"readline.h" #include"history.h"
/* How to say that you only want to save a certain amount
of kill material. */ int
rl_set_retained_kills (num) int num __attribute__((unused));
{ return0;
}
/* Add TEXT to the kill ring, allocating a new kill ring slot as necessary. ThisusesTEXTdirectly,sothecallermustnotfreeit.IfAPPENDis non-zero,andthelastcommandwasakill,thetextisappendedtothe
current kill ring slot, otherwise prepended. */ staticint
_rl_copy_to_kill_ring (text, append) char *text; int append;
{ char *old, *new; int slot;
/* First, find the slot to work with. */ if (_rl_last_command_was_kill == 0)
{ /* Get a new slot. */ if (rl_kill_ring == 0)
{ /* If we don't have any defined, then make one. */
rl_kill_ring = (char **)
xmalloc (((rl_kill_ring_length = 1) + 1) * sizeof (char *));
rl_kill_ring[slot = 0] = (char *)NULL;
} else
{ /* We have to add a new slot on the end, unless we have
exceeded the max limit for remembering kills. */
slot = rl_kill_ring_length; if (slot == rl_max_kills)
{ registerint i;
free (rl_kill_ring[0]); for (i = 0; i < slot; i++)
rl_kill_ring[i] = rl_kill_ring[i + 1];
} else
{
slot = rl_kill_ring_length += 1;
rl_kill_ring = (char **)xrealloc (rl_kill_ring, slot * sizeof (char *));
}
rl_kill_ring[--slot] = (char *)NULL;
}
} else
slot = rl_kill_ring_length - 1;
/* If the last command was a kill, prepend or append. */ if (_rl_last_command_was_kill && rl_editing_mode != vi_mode)
{
old = rl_kill_ring[slot]; new = (char *)xmalloc (1 + strlen (old) + strlen (text));
/* The way to kill something. This appends or prepends to the last kill,ifthelastcommandwasakillcommand.ifFROMisless thanTO,thenthetextisappended,otherwiseprepended.Ifthe lastcommandwasnotakillcommand,thenanewslotismadefor
this kill. */ int
rl_kill_text (from, to) int from, to;
{ char *text;
/* Is there anything to kill? */ if (from == to)
{
_rl_last_command_was_kill++; return0;
}
text = rl_copy_text (from, to);
/* Delete the copied text from the line. */
rl_delete_text (from, to);
_rl_copy_to_kill_ring (text, from < to);
_rl_last_command_was_kill++; return0;
}
/* Now REMEMBER! In order to do prepending or appending correctly, kill commandsalwaysmakerl_point'soriginalpositionbetheFROMargument,
and rl_point's extent be the TO argument. */
if (rl_point != orig_point)
rl_kill_text (orig_point, rl_point);
if (rl_editing_mode == emacs_mode)
rl_mark = rl_point;
} return0;
}
/* Kill from here to the end of the line. If DIRECTION is negative, kill
back to the line start instead. */ int
rl_kill_line (direction, ignore) int direction, ignore;
{ int orig_point;
/* Kill backwards to the start of the line. If DIRECTION is negative, kill
forwards to the line end instead. */ int
rl_backward_kill_line (direction, ignore) int direction, ignore;
{ int orig_point;
if (direction < 0) return (rl_kill_line (1, ignore)); else
{ if (!rl_point)
rl_ding (); else
{
orig_point = rl_point;
rl_beg_of_line (1, ignore); if (rl_point != orig_point)
rl_kill_text (orig_point, rl_point); if (rl_editing_mode == emacs_mode)
rl_mark = rl_point;
}
} return0;
}
/* Kill the whole line, no matter where point is. */ int
rl_kill_full_line (count, ignore) int count __attribute__((unused)), ignore __attribute__((unused));
{
rl_begin_undo_group ();
rl_point = 0;
rl_kill_text (rl_point, rl_end);
rl_mark = 0;
rl_end_undo_group (); return0;
}
/* The next two functions mimic unix line editing behaviour, except they savethedeletedtextonthekillring.Thisissaferthannotsaving
it, and since we have a ring, nobody should get screwed. */
/* This does what C-w does in Unix. We can't prevent people from
using behaviour that they expect. */ int
rl_unix_word_rubout (count, key) int count, key __attribute__((unused));
{ int orig_point;
if (rl_point == 0)
rl_ding (); else
{
orig_point = rl_point; if (count <= 0)
count = 1;
while (count--)
{ while (rl_point && whitespace (rl_line_buffer[rl_point - 1]))
rl_point--;
/* This deletes one filename component in a Unix pathname. That is, it
deletes backward to directory separator (`/') or whitespace. */ int
rl_unix_filename_rubout (count, key) int count, key __attribute__((unused));
{ int orig_point, c;
if (rl_point == 0)
rl_ding (); else
{
orig_point = rl_point; if (count <= 0)
count = 1;
while (count--)
{
c = rl_line_buffer[rl_point - 1]; while (rl_point && (whitespace (c) || c == '/'))
{
rl_point--;
c = rl_line_buffer[rl_point - 1];
}
while (rl_point && (whitespace (c) == 0) && c != '/')
{
rl_point--;
c = rl_line_buffer[rl_point - 1];
}
}
/* Here is C-u doing what Unix does. You don't *have* to use these key-bindings.Wehaveachoiceofkillingtheentireline,or killingfromwherewearetothestartoftheline.Wechoosethe latter,becauseifyouareaUnixweenie,thenyouhaven'tbackspaced intothelineatall,andifyouaren't,thenyouknowwhatyouare
doing. */ int
rl_unix_line_discard (count, key) int count __attribute__((unused)), key __attribute__((unused));
{ if (rl_point == 0)
rl_ding (); else
{
rl_kill_text (rl_point, 0);
rl_point = 0; if (rl_editing_mode == emacs_mode)
rl_mark = rl_point;
} return0;
}
/* Copy the text in the `region' to the kill ring. If DELETE is non-zero,
delete the text from the line as well. */ staticint
region_kill_internal (delete) intdelete;
{ char *text;
if (rl_mark != rl_point)
{
text = rl_copy_text (rl_point, rl_mark); if (delete)
rl_delete_text (rl_point, rl_mark);
_rl_copy_to_kill_ring (text, rl_point < rl_mark);
}
_rl_last_command_was_kill++; return0;
}
/* Copy the text in the region to the kill ring. */ int
rl_copy_region_to_kill (count, ignore) int count __attribute__((unused)), ignore __attribute__((unused));
{ return (region_kill_internal (0));
}
/* Kill the text between the point and mark. */ int
rl_kill_region (count, ignore) int count __attribute__((unused)), ignore __attribute__((unused));
{ int r, npoint;
/* Copy COUNT words to the kill ring. DIR says which direction we look
to find the words. */ staticint
_rl_copy_word_as_kill (count, dir) int count, dir;
{ int om, op, r;
int
rl_copy_forward_word (count, key) int count, key;
{ if (count < 0) return (rl_copy_backward_word (-count, key));
return (_rl_copy_word_as_kill (count, 1));
}
int
rl_copy_backward_word (count, key) int count, key;
{ if (count < 0) return (rl_copy_forward_word (-count, key));
return (_rl_copy_word_as_kill (count, -1));
}
/* Yank back the last killed text. This ignores arguments. */ int
rl_yank (count, ignore) int count __attribute__((unused)), ignore __attribute__((unused));
{ if (rl_kill_ring == 0)
{
_rl_abort_internal (); return -1;
}
/* If the last command was yank, or yank_pop, and the text just beforepointisidenticaltothecurrentkillitem,then deletethattextfromtheline,rotatetheindexdown,and
yank back some other text. */ int
rl_yank_pop (count, key) int count __attribute__((unused)), key __attribute__((unused));
{ int l, n;
l = strlen (rl_kill_ring[rl_kill_index]);
n = rl_point - l; if (n >= 0 && STREQN (rl_line_buffer + n, rl_kill_ring[rl_kill_index], l))
{
rl_delete_text (n, rl_point);
rl_point = n;
rl_kill_index--; if (rl_kill_index < 0)
rl_kill_index = rl_kill_ring_length - 1;
rl_yank (1, 0); return0;
} else
{
_rl_abort_internal (); return -1;
}
}
/* Yank the COUNTh argument from the previous history line, skipping
HISTORY_SKIP lines before looking for the `previous line'. */ staticint
rl_yank_nth_arg_internal (count, ignore, history_skip) int count, ignore, history_skip;
{ register HIST_ENTRY *entry; char *arg; int i, pos;
pos = where_history ();
if (history_skip)
{ for (i = 0; i < history_skip; i++)
entry = previous_history ();
}
#ifdefined (VI_MODE) /* Vi mode always inserts a space before yanking the argument, and it
inserts it right *after* rl_point. */ if (rl_editing_mode == vi_mode)
{
rl_vi_append_mode (1, ignore);
rl_insert_text (" ");
} #endif/* VI_MODE */
rl_insert_text (arg);
free (arg);
rl_end_undo_group (); return0;
}
/* Yank the COUNTth argument from the previous history line. */ int
rl_yank_nth_arg (count, ignore) int count, ignore;
{ return (rl_yank_nth_arg_internal (count, ignore, 0));
}
/* Yank the last argument from the previous history line. This `knows' howrl_yank_nth_argtreatsacountof`$'.Withanargument,this
behaves the same as rl_yank_nth_arg. */ int
rl_yank_last_arg (count, key) int count, key;
{ staticint history_skip = 0; staticint explicit_arg_p = 0; staticint count_passed = 1; staticint direction = 1; staticint undo_needed = 0; int retval;
if (rl_last_func != rl_yank_last_arg)
{
history_skip = 0;
explicit_arg_p = rl_explicit_arg;
count_passed = count;
direction = 1;
} else
{ if (undo_needed)
rl_do_undo (); if (count < 1)
direction = -direction;
history_skip += direction; if (history_skip < 0)
history_skip = 0;
}
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.