mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-08-08 19:22:39 +02:00
commit bash-20060727 snapshot
This commit is contained in:
+1
-1
@@ -184,7 +184,7 @@ mbskipname (pat, dname)
|
||||
{
|
||||
int ret;
|
||||
wchar_t *pat_wc, *dn_wc;
|
||||
size_t pat_n, dn_n, n;
|
||||
size_t pat_n, dn_n;
|
||||
|
||||
pat_n = xdupmbstowcs (&pat_wc, NULL, pat);
|
||||
dn_n = xdupmbstowcs (&dn_wc, NULL, dname);
|
||||
|
||||
@@ -247,7 +247,6 @@ rangecmp_wc (c1, c2)
|
||||
{
|
||||
static wchar_t s1[2] = { L' ', L'\0' };
|
||||
static wchar_t s2[2] = { L' ', L'\0' };
|
||||
int ret;
|
||||
|
||||
if (c1 == c2)
|
||||
return 0;
|
||||
|
||||
@@ -1537,7 +1537,6 @@ rl_variable_value (name)
|
||||
const char *name;
|
||||
{
|
||||
register int i;
|
||||
int v;
|
||||
|
||||
/* Check for simple variables first. */
|
||||
i = find_boolean_var (name);
|
||||
|
||||
@@ -1104,7 +1104,8 @@ compute_lcd_of_matches (match_list, matches, text)
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
{
|
||||
mbstate_t ps_back = ps1;
|
||||
mbstate_t ps_back;
|
||||
ps_back = ps1;
|
||||
if (!_rl_compare_chars (match_list[i], si, &ps1, match_list[i+1], si, &ps2))
|
||||
break;
|
||||
else if ((v = _rl_get_char_len (&match_list[i][si], &ps_back)) > 1)
|
||||
@@ -1896,7 +1897,6 @@ rl_filename_completion_function (text, state)
|
||||
static char *filename = (char *)NULL;
|
||||
static char *dirname = (char *)NULL;
|
||||
static char *users_dirname = (char *)NULL;
|
||||
static char *orig_filename = (char *)NULL;
|
||||
static int filename_len;
|
||||
char *temp;
|
||||
int dirlen;
|
||||
|
||||
@@ -950,7 +950,7 @@ gen_completion_matches (text, start, end, our_func, found_quote, quote_char)
|
||||
rl_compentry_func_t *our_func;
|
||||
int found_quote, quote_char;
|
||||
{
|
||||
char **matches, *temp;
|
||||
char **matches;
|
||||
|
||||
rl_completion_found_quote = found_quote;
|
||||
rl_completion_quote_character = quote_char;
|
||||
@@ -969,28 +969,9 @@ gen_completion_matches (text, start, end, our_func, found_quote, quote_char)
|
||||
}
|
||||
}
|
||||
|
||||
/* Beware -- we're stripping the quotes here. Do this only if we know
|
||||
we are doing filename completion and the application has defined a
|
||||
filename dequoting function. */
|
||||
/* XXX -- can move this into rl_filename_completion_function and use
|
||||
rl_completion_found_quote and rl_completion_quote_char. Should be
|
||||
after the directory rewriting hook and maybe the directory completion
|
||||
hook. Also need to change bash_directory_expansion in the same way
|
||||
as rl_filename_completion_function. */
|
||||
temp = (char *)NULL;
|
||||
|
||||
#if 0
|
||||
if (found_quote && our_func == rl_filename_completion_function &&
|
||||
rl_filename_dequoting_function)
|
||||
{
|
||||
/* delete single and double quotes */
|
||||
temp = (*rl_filename_dequoting_function) (text, quote_char);
|
||||
text = temp; /* not freeing text is not a memory leak */
|
||||
}
|
||||
#endif
|
||||
/* XXX -- filename dequoting moved into rl_filename_completion_function */
|
||||
|
||||
matches = rl_completion_matches (text, our_func);
|
||||
FREE (temp);
|
||||
return matches;
|
||||
}
|
||||
|
||||
|
||||
@@ -2365,12 +2365,14 @@ _rl_col_width (str, start, end)
|
||||
int start, end;
|
||||
{
|
||||
wchar_t wc;
|
||||
mbstate_t ps = {0};
|
||||
mbstate_t ps;
|
||||
int tmp, point, width, max;
|
||||
|
||||
if (end <= start)
|
||||
return 0;
|
||||
|
||||
memset (&ps, 0, sizeof (mbstate_t));
|
||||
|
||||
point = 0;
|
||||
max = end;
|
||||
|
||||
|
||||
+44
-38
@@ -1,6 +1,6 @@
|
||||
/* display.c -- readline redisplay facility. */
|
||||
|
||||
/* Copyright (C) 1987-2005 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1987-2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of the GNU Readline Library, a library for
|
||||
reading lines of text with interactive input and history editing.
|
||||
@@ -59,10 +59,6 @@
|
||||
extern char *strchr (), *strrchr ();
|
||||
#endif /* !strchr && !__STDC__ */
|
||||
|
||||
#if defined (HACK_TERMCAP_MOTION)
|
||||
extern char *_rl_term_forward_char;
|
||||
#endif
|
||||
|
||||
static void update_line PARAMS((char *, char *, int, int, int, int));
|
||||
static void space_to_eol PARAMS((int));
|
||||
static void delete_chars PARAMS((int));
|
||||
@@ -80,7 +76,8 @@ static int *inv_lbreaks, *vis_lbreaks;
|
||||
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. */
|
||||
by backing up or outputting a carriage return and moving forward. CUR
|
||||
and NEW are either both buffer positions or absolute screen positions. */
|
||||
#define CR_FASTER(new, cur) (((new) + 1) < ((cur) - (new)))
|
||||
|
||||
/* _rl_last_c_pos is an absolute cursor position in multibyte locales and a
|
||||
@@ -143,6 +140,7 @@ int _rl_last_c_pos = 0;
|
||||
int _rl_last_v_pos = 0;
|
||||
|
||||
static int cpos_adjusted;
|
||||
static int cpos_buffer_position;
|
||||
|
||||
/* Number of lines currently on screen minus 1. */
|
||||
int _rl_vis_botlin = 0;
|
||||
@@ -460,7 +458,7 @@ rl_redisplay ()
|
||||
{
|
||||
register int in, out, c, linenum, cursor_linenum;
|
||||
register char *line;
|
||||
int c_pos, inv_botlin, lb_botlin, lb_linenum, o_cpos;
|
||||
int inv_botlin, lb_botlin, lb_linenum, o_cpos;
|
||||
int newlines, lpos, temp, modmark, n0, num;
|
||||
char *prompt_this_line;
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
@@ -484,7 +482,7 @@ rl_redisplay ()
|
||||
}
|
||||
|
||||
/* Draw the line into the buffer. */
|
||||
c_pos = -1;
|
||||
cpos_buffer_position = -1;
|
||||
|
||||
line = invisible_line;
|
||||
out = inv_botlin = 0;
|
||||
@@ -666,7 +664,7 @@ rl_redisplay ()
|
||||
prompt_last_screen_line = newlines;
|
||||
|
||||
/* Draw the rest of the line (after the prompt) into invisible_line, keeping
|
||||
track of where the cursor is (c_pos), the number of the line containing
|
||||
track of where the cursor is (cpos_buffer_position), the number of the line containing
|
||||
the cursor (lb_linenum), the last line number (lb_botlin and inv_botlin).
|
||||
It maintains an array of line breaks for display (inv_lbreaks).
|
||||
This handles expanding tabs for display and displaying meta characters. */
|
||||
@@ -719,7 +717,7 @@ rl_redisplay ()
|
||||
|
||||
if (in == rl_point)
|
||||
{
|
||||
c_pos = out;
|
||||
cpos_buffer_position = out;
|
||||
lb_linenum = newlines;
|
||||
}
|
||||
|
||||
@@ -813,7 +811,7 @@ rl_redisplay ()
|
||||
}
|
||||
if (in == rl_point)
|
||||
{
|
||||
c_pos = out;
|
||||
cpos_buffer_position = out;
|
||||
lb_linenum = newlines;
|
||||
}
|
||||
for (i = in; i < in+wc_bytes; i++)
|
||||
@@ -844,9 +842,9 @@ rl_redisplay ()
|
||||
|
||||
}
|
||||
line[out] = '\0';
|
||||
if (c_pos < 0)
|
||||
if (cpos_buffer_position < 0)
|
||||
{
|
||||
c_pos = out;
|
||||
cpos_buffer_position = out;
|
||||
lb_linenum = newlines;
|
||||
}
|
||||
|
||||
@@ -855,7 +853,7 @@ rl_redisplay ()
|
||||
inv_lbreaks[newlines+1] = out;
|
||||
cursor_linenum = lb_linenum;
|
||||
|
||||
/* C_POS == position in buffer where cursor should be placed.
|
||||
/* CPOS_BUFFER_POSITION == position in buffer where cursor should be placed.
|
||||
CURSOR_LINENUM == line number where the cursor should be placed. */
|
||||
|
||||
/* PWP: now is when things get a bit hairy. The visible and invisible
|
||||
@@ -1011,7 +1009,7 @@ rl_redisplay ()
|
||||
pos = inv_lbreaks[cursor_linenum];
|
||||
/* nleft == number of characters in the line buffer between the
|
||||
start of the line and the desired cursor position. */
|
||||
nleft = c_pos - pos;
|
||||
nleft = cpos_buffer_position - pos;
|
||||
|
||||
/* NLEFT is now a number of characters in a buffer. When in a
|
||||
multibyte locale, however, _rl_last_c_pos is an absolute cursor
|
||||
@@ -1057,11 +1055,11 @@ rl_redisplay ()
|
||||
will be LMARGIN. */
|
||||
|
||||
/* The number of characters that will be displayed before the cursor. */
|
||||
ndisp = c_pos - wrap_offset;
|
||||
ndisp = cpos_buffer_position - wrap_offset;
|
||||
nleft = prompt_visible_length + wrap_offset;
|
||||
/* Where the new cursor position will be on the screen. This can be
|
||||
longer than SCREENWIDTH; if it is, lmargin will be adjusted. */
|
||||
phys_c_pos = c_pos - (last_lmargin ? last_lmargin : wrap_offset);
|
||||
phys_c_pos = cpos_buffer_position - (last_lmargin ? last_lmargin : wrap_offset);
|
||||
t = _rl_screenwidth / 3;
|
||||
|
||||
/* If the number of characters had already exceeded the screenwidth,
|
||||
@@ -1072,7 +1070,7 @@ rl_redisplay ()
|
||||
two-thirds of the way across the screen. */
|
||||
if (phys_c_pos > _rl_screenwidth - 2)
|
||||
{
|
||||
lmargin = c_pos - (2 * t);
|
||||
lmargin = cpos_buffer_position - (2 * t);
|
||||
if (lmargin < 0)
|
||||
lmargin = 0;
|
||||
/* If the left margin would be in the middle of a prompt with
|
||||
@@ -1086,7 +1084,7 @@ rl_redisplay ()
|
||||
{
|
||||
/* If we are moving back towards the beginning of the line and
|
||||
the last margin is no longer correct, compute a new one. */
|
||||
lmargin = ((c_pos - 1) / t) * t; /* XXX */
|
||||
lmargin = ((cpos_buffer_position - 1) / t) * t; /* XXX */
|
||||
if (wrap_offset && lmargin > 0 && lmargin < nleft)
|
||||
lmargin = nleft;
|
||||
}
|
||||
@@ -1131,7 +1129,7 @@ rl_redisplay ()
|
||||
if (visible_first_line_len > _rl_screenwidth)
|
||||
visible_first_line_len = _rl_screenwidth;
|
||||
|
||||
_rl_move_cursor_relative (c_pos - lmargin, &invisible_line[lmargin]);
|
||||
_rl_move_cursor_relative (cpos_buffer_position - lmargin, &invisible_line[lmargin]);
|
||||
last_lmargin = lmargin;
|
||||
}
|
||||
}
|
||||
@@ -1724,13 +1722,12 @@ _rl_move_cursor_relative (new, data)
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
{
|
||||
dpos = _rl_col_width (data, 0, new);
|
||||
#if 0
|
||||
if (dpos > woff)
|
||||
#else
|
||||
if (dpos > prompt_last_invisible)
|
||||
#endif
|
||||
if (dpos > prompt_last_invisible) /* XXX - don't use woff here */
|
||||
{
|
||||
dpos -= woff;
|
||||
/* Since this will be assigned to _rl_last_c_pos at the end (more
|
||||
precisely, _rl_last_c_pos == dpos when this function returns),
|
||||
let the caller know. */
|
||||
cpos_adjusted = 1;
|
||||
}
|
||||
}
|
||||
@@ -1751,7 +1748,7 @@ _rl_move_cursor_relative (new, data)
|
||||
else
|
||||
#endif
|
||||
i = _rl_last_c_pos - woff;
|
||||
if (new == 0 || CR_FASTER (new, _rl_last_c_pos) ||
|
||||
if (dpos == 0 || CR_FASTER (dpos, _rl_last_c_pos) ||
|
||||
(_rl_term_autowrap && i == _rl_screenwidth))
|
||||
{
|
||||
#if defined (__MSDOS__)
|
||||
@@ -1773,19 +1770,27 @@ _rl_move_cursor_relative (new, data)
|
||||
sequence telling the terminal to move forward one character.
|
||||
That kind of control is for people who don't know what the
|
||||
data is underneath the cursor. */
|
||||
#if defined (HACK_TERMCAP_MOTION)
|
||||
if (_rl_term_forward_char)
|
||||
{
|
||||
for (i = cpos; i < dpos; i++)
|
||||
tputs (_rl_term_forward_char, 1, _rl_output_character_function);
|
||||
}
|
||||
else
|
||||
#endif /* HACK_TERMCAP_MOTION */
|
||||
|
||||
/* However, we need a handle on where the current display position is
|
||||
in the buffer for the immediately preceding comment to be true.
|
||||
In multibyte locales, we don't currently have that info available.
|
||||
Without it, we don't know where the data we have to display begins
|
||||
in the buffer and we have to go back to the beginning of the screen
|
||||
line. In this case, we can use the terminal sequence to move forward
|
||||
if it's available. */
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
{
|
||||
tputs (_rl_term_cr, 1, _rl_output_character_function);
|
||||
for (i = 0; i < new; i++)
|
||||
putc (data[i], rl_outstream);
|
||||
if (_rl_term_forward_char)
|
||||
{
|
||||
for (i = cpos; i < dpos; i++)
|
||||
tputs (_rl_term_forward_char, 1, _rl_output_character_function);
|
||||
}
|
||||
else
|
||||
{
|
||||
tputs (_rl_term_cr, 1, _rl_output_character_function);
|
||||
for (i = 0; i < new; i++)
|
||||
putc (data[i], rl_outstream);
|
||||
}
|
||||
}
|
||||
else
|
||||
for (i = cpos; i < new; i++)
|
||||
@@ -2213,7 +2218,8 @@ _rl_update_final ()
|
||||
char *last_line;
|
||||
|
||||
last_line = &visible_line[vis_lbreaks[_rl_vis_botlin]];
|
||||
_rl_move_cursor_relative (_rl_screenwidth - 1, last_line);
|
||||
cpos_buffer_position = -1; /* don't know where we are in buffer */
|
||||
_rl_move_cursor_relative (_rl_screenwidth - 1, last_line); /* XXX */
|
||||
_rl_clear_to_eol (0);
|
||||
putc (last_line[_rl_screenwidth - 1], rl_outstream);
|
||||
}
|
||||
|
||||
@@ -56,8 +56,6 @@
|
||||
|
||||
typedef int _hist_search_func_t PARAMS((const char *, int));
|
||||
|
||||
extern int rl_byte_oriented; /* declared in mbutil.c */
|
||||
|
||||
static char error_pointer;
|
||||
|
||||
static char *subst_lhs;
|
||||
@@ -564,12 +562,12 @@ history_expand_internal (string, start, end_index_ptr, ret_string, current_line)
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
{
|
||||
int c, l;
|
||||
int ch, l;
|
||||
l = _rl_find_prev_mbchar (string, i, MB_FIND_ANY);
|
||||
c = string[l];
|
||||
ch = string[l];
|
||||
/* XXX - original patch had i - 1 ??? If i == 0 it would fail. */
|
||||
if (i && (c == '\'' || c == '"'))
|
||||
quoted_search_delimiter = c;
|
||||
if (i && (ch == '\'' || ch == '"'))
|
||||
quoted_search_delimiter = ch;
|
||||
}
|
||||
else
|
||||
#endif /* HANDLE_MULTIBYTE */
|
||||
@@ -1430,6 +1428,8 @@ history_tokenize_word (string, ind)
|
||||
{
|
||||
if (peek == '<' && string[i + 2] == '-')
|
||||
i++;
|
||||
else if (peek == '<' && string[i + 2] == '<')
|
||||
i++;
|
||||
i += 2;
|
||||
return i;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -550,21 +550,21 @@ _rl_read_mbchar (mbchar, size)
|
||||
}
|
||||
|
||||
/* Read a multibyte-character string whose first character is FIRST into
|
||||
the buffer MB of length MBLEN. Returns the last character read, which
|
||||
the buffer MB of length MLEN. Returns the last character read, which
|
||||
may be FIRST. Used by the search functions, among others. Very similar
|
||||
to _rl_read_mbchar. */
|
||||
int
|
||||
_rl_read_mbstring (first, mb, mblen)
|
||||
_rl_read_mbstring (first, mb, mlen)
|
||||
int first;
|
||||
char *mb;
|
||||
int mblen;
|
||||
int mlen;
|
||||
{
|
||||
int i, c;
|
||||
mbstate_t ps;
|
||||
|
||||
c = first;
|
||||
memset (mb, 0, mblen);
|
||||
for (i = 0; i < mblen; i++)
|
||||
memset (mb, 0, mlen);
|
||||
for (i = 0; i < mlen; i++)
|
||||
{
|
||||
mb[i] = (char)c;
|
||||
memset (&ps, 0, sizeof (mbstate_t));
|
||||
|
||||
+14
-1
@@ -179,6 +179,7 @@ rl_gather_tyi ()
|
||||
struct timeval timeout;
|
||||
#endif
|
||||
|
||||
chars_avail = 0;
|
||||
tty = fileno (rl_instream);
|
||||
|
||||
#if defined (HAVE_SELECT)
|
||||
@@ -220,6 +221,13 @@ rl_gather_tyi ()
|
||||
}
|
||||
#endif /* O_NDELAY */
|
||||
|
||||
#if defined (__MINGW32__)
|
||||
/* Use getch/_kbhit to check for available console input, in the same way
|
||||
that we read it normally. */
|
||||
chars_avail = isatty (tty) ? _kbhit () : 0;
|
||||
result = 0;
|
||||
#endif
|
||||
|
||||
/* If there's nothing available, don't waste time trying to read
|
||||
something. */
|
||||
if (chars_avail <= 0)
|
||||
@@ -263,7 +271,7 @@ rl_set_keyboard_input_timeout (u)
|
||||
int o;
|
||||
|
||||
o = _keyboard_input_timeout;
|
||||
if (u > 0)
|
||||
if (u >= 0)
|
||||
_keyboard_input_timeout = u;
|
||||
return (o);
|
||||
}
|
||||
@@ -303,6 +311,11 @@ _rl_input_available ()
|
||||
return (chars_avail);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if defined (__MINGW32__)
|
||||
if (isatty (tty))
|
||||
return (_kbhit ());
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
||||
+8
-8
@@ -1237,8 +1237,8 @@ rl_change_case (count, op)
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
wchar_t wc, nwc;
|
||||
char mb[MB_LEN_MAX+1];
|
||||
int mblen;
|
||||
mbstate_t ps;
|
||||
int mlen;
|
||||
mbstate_t mps;
|
||||
#endif
|
||||
|
||||
start = rl_point;
|
||||
@@ -1255,7 +1255,7 @@ rl_change_case (count, op)
|
||||
SWAP (start, end);
|
||||
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
memset (&ps, 0, sizeof (mbstate_t));
|
||||
memset (&mps, 0, sizeof (mbstate_t));
|
||||
#endif
|
||||
|
||||
/* We are going to modify some text, so let's prepare to undo it. */
|
||||
@@ -1290,15 +1290,15 @@ rl_change_case (count, op)
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
else
|
||||
{
|
||||
mbrtowc (&wc, rl_line_buffer + start, end - start, &ps);
|
||||
mbrtowc (&wc, rl_line_buffer + start, end - start, &mps);
|
||||
nwc = (nop == UpCase) ? _rl_to_wupper (wc) : _rl_to_wlower (wc);
|
||||
if (nwc != wc) /* just skip unchanged characters */
|
||||
{
|
||||
mblen = wcrtomb (mb, nwc, &ps);
|
||||
if (mblen > 0)
|
||||
mb[mblen] = '\0';
|
||||
mlen = wcrtomb (mb, nwc, &mps);
|
||||
if (mlen > 0)
|
||||
mb[mlen] = '\0';
|
||||
/* Assume the same width */
|
||||
strncpy (rl_line_buffer + start, mb, mblen);
|
||||
strncpy (rl_line_buffer + start, mb, mlen);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1237,8 +1237,8 @@ rl_change_case (count, op)
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
wchar_t wc, nwc;
|
||||
char mb[MB_LEN_MAX+1];
|
||||
int mblen, p;
|
||||
mbstate_t ps;
|
||||
int mblen;
|
||||
mbstate_t mps;
|
||||
#endif
|
||||
|
||||
start = rl_point;
|
||||
@@ -1255,7 +1255,7 @@ rl_change_case (count, op)
|
||||
SWAP (start, end);
|
||||
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
memset (&ps, 0, sizeof (mbstate_t));
|
||||
memset (&mps, 0, sizeof (mbstate_t));
|
||||
#endif
|
||||
|
||||
/* We are going to modify some text, so let's prepare to undo it. */
|
||||
@@ -1290,11 +1290,11 @@ rl_change_case (count, op)
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
else
|
||||
{
|
||||
mbrtowc (&wc, rl_line_buffer + start, end - start, &ps);
|
||||
mbrtowc (&wc, rl_line_buffer + start, end - start, &mps);
|
||||
nwc = (nop == UpCase) ? _rl_to_wupper (wc) : _rl_to_wlower (wc);
|
||||
if (nwc != wc) /* just skip unchanged characters */
|
||||
{
|
||||
mblen = wcrtomb (mb, nwc, &ps);
|
||||
mblen = wcrtomb (mb, nwc, &mps);
|
||||
if (mblen > 0)
|
||||
mb[mblen] = '\0';
|
||||
/* Assume the same width */
|
||||
|
||||
@@ -738,7 +738,7 @@ _rl_vi_change_mbchar_case (count)
|
||||
{
|
||||
wchar_t wc;
|
||||
char mb[MB_LEN_MAX+1];
|
||||
int mblen, p;
|
||||
int mlen, p;
|
||||
mbstate_t ps;
|
||||
|
||||
memset (&ps, 0, sizeof (mbstate_t));
|
||||
@@ -762,9 +762,9 @@ _rl_vi_change_mbchar_case (count)
|
||||
if (wc)
|
||||
{
|
||||
p = rl_point;
|
||||
mblen = wcrtomb (mb, wc, &ps);
|
||||
if (mblen >= 0)
|
||||
mb[mblen] = '\0';
|
||||
mlen = wcrtomb (mb, wc, &ps);
|
||||
if (mlen >= 0)
|
||||
mb[mlen] = '\0';
|
||||
rl_begin_undo_group ();
|
||||
rl_vi_delete (1, 0);
|
||||
if (rl_point < p) /* Did we retreat at EOL? */
|
||||
@@ -1457,9 +1457,9 @@ _rl_vi_change_char (count, c, mb)
|
||||
}
|
||||
|
||||
static int
|
||||
_rl_vi_callback_getchar (mb, mblen)
|
||||
_rl_vi_callback_getchar (mb, mlen)
|
||||
char *mb;
|
||||
int mblen;
|
||||
int mlen;
|
||||
{
|
||||
int c;
|
||||
|
||||
@@ -1469,7 +1469,7 @@ _rl_vi_callback_getchar (mb, mblen)
|
||||
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
c = _rl_read_mbstring (c, mb, mblen);
|
||||
c = _rl_read_mbstring (c, mb, mlen);
|
||||
#endif
|
||||
|
||||
return c;
|
||||
|
||||
@@ -653,7 +653,7 @@ _rl_vi_save_insert (up)
|
||||
{
|
||||
int len, start, end;
|
||||
|
||||
if (up == 0)
|
||||
if (up == 0 || up->what != UNDO_INSERT)
|
||||
{
|
||||
if (vi_insert_buffer_size >= 1)
|
||||
vi_insert_buffer[0] = '\0';
|
||||
@@ -1457,9 +1457,9 @@ _rl_vi_change_char (count, c, mb)
|
||||
}
|
||||
|
||||
static int
|
||||
_rl_vi_callback_getchar (mb, mblen)
|
||||
_rl_vi_callback_getchar (mb, mlen)
|
||||
char *mb;
|
||||
int mblen;
|
||||
int mlen;
|
||||
{
|
||||
int c;
|
||||
|
||||
@@ -1469,7 +1469,7 @@ _rl_vi_callback_getchar (mb, mblen)
|
||||
|
||||
#if defined (HANDLE_MULTIBYTE)
|
||||
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
||||
c = _rl_read_mbstring (c, mb, mblen);
|
||||
c = _rl_read_mbstring (c, mb, mlen);
|
||||
#endif
|
||||
|
||||
return c;
|
||||
|
||||
@@ -66,6 +66,16 @@ extern int errno;
|
||||
extern int inet_aton __P((const char *, struct in_addr *));
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_GETADDRINFO
|
||||
static int _getaddr __P((char *, struct in_addr));
|
||||
static int _getserv __P((char *, int, unsigned short));
|
||||
static int _netopen4 __P((char *, char *, int));
|
||||
#else /* HAVE_GETADDRINFO */
|
||||
static int _netopen6 __P((char *, char *, int));
|
||||
#endif
|
||||
|
||||
static int _netopen __P((char *, char *, int));
|
||||
|
||||
#ifndef HAVE_GETADDRINFO
|
||||
/* Stuff the internet address corresponding to HOST into AP, in network
|
||||
byte order. Return 1 on success, 0 on failure. */
|
||||
|
||||
@@ -0,0 +1,340 @@
|
||||
/*
|
||||
* netopen.c -- functions to make tcp/udp connections
|
||||
*
|
||||
* Chet Ramey
|
||||
* chet@ins.CWRU.Edu
|
||||
*/
|
||||
|
||||
/* Copyright (C) 1987-2002 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne Again SHell.
|
||||
|
||||
Bash 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 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
Bash is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Bash; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#if defined (HAVE_NETWORK)
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#if defined (HAVE_SYS_SOCKET_H)
|
||||
# include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
#if defined (HAVE_NETINET_IN_H)
|
||||
# include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
#if defined (HAVE_NETDB_H)
|
||||
# include <netdb.h>
|
||||
#endif
|
||||
|
||||
#if defined (HAVE_ARPA_INET_H)
|
||||
# include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include <bashansi.h>
|
||||
#include <bashintl.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include <shell.h>
|
||||
#include <xmalloc.h>
|
||||
|
||||
#ifndef errno
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
#if !defined (HAVE_INET_ATON)
|
||||
extern int inet_aton __P((const char *, struct in_addr *));
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_GETADDRINFO
|
||||
/* Stuff the internet address corresponding to HOST into AP, in network
|
||||
byte order. Return 1 on success, 0 on failure. */
|
||||
|
||||
static int
|
||||
_getaddr (host, ap)
|
||||
char *host;
|
||||
struct in_addr *ap;
|
||||
{
|
||||
struct hostent *h;
|
||||
int r;
|
||||
|
||||
r = 0;
|
||||
if (host[0] >= '0' && host[0] <= '9')
|
||||
{
|
||||
/* If the first character is a digit, guess that it's an
|
||||
Internet address and return immediately if inet_aton succeeds. */
|
||||
r = inet_aton (host, ap);
|
||||
if (r)
|
||||
return r;
|
||||
}
|
||||
#if !defined (HAVE_GETHOSTBYNAME)
|
||||
return 0;
|
||||
#else
|
||||
h = gethostbyname (host);
|
||||
if (h && h->h_addr)
|
||||
{
|
||||
bcopy(h->h_addr, (char *)ap, h->h_length);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
/* Return 1 if SERV is a valid port number and stuff the converted value into
|
||||
PP in network byte order. */
|
||||
static int
|
||||
_getserv (serv, proto, pp)
|
||||
char *serv;
|
||||
int proto;
|
||||
unsigned short *pp;
|
||||
{
|
||||
intmax_t l;
|
||||
unsigned short s;
|
||||
|
||||
if (legal_number (serv, &l))
|
||||
{
|
||||
s = (unsigned short)(l & 0xFFFF);
|
||||
if (s != l)
|
||||
return (0);
|
||||
s = htons (s);
|
||||
if (pp)
|
||||
*pp = s;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
#if defined (HAVE_GETSERVBYNAME)
|
||||
{
|
||||
struct servent *se;
|
||||
|
||||
se = getservbyname (serv, (proto == 't') ? "tcp" : "udp");
|
||||
if (se == 0)
|
||||
return 0;
|
||||
if (pp)
|
||||
*pp = se->s_port; /* ports returned in network byte order */
|
||||
return 1;
|
||||
}
|
||||
#else /* !HAVE_GETSERVBYNAME */
|
||||
return 0;
|
||||
#endif /* !HAVE_GETSERVBYNAME */
|
||||
}
|
||||
|
||||
/*
|
||||
* Open a TCP or UDP connection to HOST on port SERV. Uses the
|
||||
* traditional BSD mechanisms. Returns the connected socket or -1 on error.
|
||||
*/
|
||||
static int
|
||||
_netopen4(host, serv, typ)
|
||||
char *host, *serv;
|
||||
int typ;
|
||||
{
|
||||
struct in_addr ina;
|
||||
struct sockaddr_in sin;
|
||||
unsigned short p;
|
||||
int s, e;
|
||||
|
||||
if (_getaddr(host, &ina) == 0)
|
||||
{
|
||||
internal_error (_("%s: host unknown"), host);
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (_getserv(serv, typ, &p) == 0)
|
||||
{
|
||||
internal_error(_("%s: invalid service"), serv);
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset ((char *)&sin, 0, sizeof(sin));
|
||||
sin.sin_family = AF_INET;
|
||||
sin.sin_port = p;
|
||||
sin.sin_addr = ina;
|
||||
|
||||
s = socket(AF_INET, (typ == 't') ? SOCK_STREAM : SOCK_DGRAM, 0);
|
||||
if (s < 0)
|
||||
{
|
||||
sys_error ("socket");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (connect (s, (struct sockaddr *)&sin, sizeof (sin)) < 0)
|
||||
{
|
||||
e = errno;
|
||||
sys_error("connect");
|
||||
close(s);
|
||||
errno = e;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return(s);
|
||||
}
|
||||
#endif /* ! HAVE_GETADDRINFO */
|
||||
|
||||
#ifdef HAVE_GETADDRINFO
|
||||
/*
|
||||
* Open a TCP or UDP connection to HOST on port SERV. Uses getaddrinfo(3)
|
||||
* which provides support for IPv6. Returns the connected socket or -1
|
||||
* on error.
|
||||
*/
|
||||
static int
|
||||
_netopen6 (host, serv, typ)
|
||||
char *host, *serv;
|
||||
int typ;
|
||||
{
|
||||
int s, e;
|
||||
struct addrinfo hints, *res, *res0;
|
||||
int gerr;
|
||||
|
||||
memset ((char *)&hints, 0, sizeof (hints));
|
||||
/* XXX -- if problems with IPv6, set to PF_INET for IPv4 only */
|
||||
#ifdef DEBUG /* PF_INET is the one that works for me */
|
||||
hints.ai_family = PF_INET;
|
||||
#else
|
||||
hints.ai_family = PF_UNSPEC;
|
||||
#endif
|
||||
hints.ai_socktype = (typ == 't') ? SOCK_STREAM : SOCK_DGRAM;
|
||||
|
||||
gerr = getaddrinfo (host, serv, &hints, &res0);
|
||||
if (gerr)
|
||||
{
|
||||
if (gerr == EAI_SERVICE)
|
||||
internal_error ("%s: %s", serv, gai_strerror (gerr));
|
||||
else
|
||||
internal_error ("%s: %s", host, gai_strerror (gerr));
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (res = res0; res; res = res->ai_next)
|
||||
{
|
||||
if ((s = socket (res->ai_family, res->ai_socktype, res->ai_protocol)) < 0)
|
||||
{
|
||||
if (res->ai_next)
|
||||
continue;
|
||||
sys_error ("socket");
|
||||
freeaddrinfo (res0);
|
||||
return -1;
|
||||
}
|
||||
if (connect (s, res->ai_addr, res->ai_addrlen) < 0)
|
||||
{
|
||||
if (res->ai_next)
|
||||
{
|
||||
close (s);
|
||||
continue;
|
||||
}
|
||||
e = errno;
|
||||
sys_error ("connect");
|
||||
close (s);
|
||||
freeaddrinfo (res0);
|
||||
errno = e;
|
||||
return -1;
|
||||
}
|
||||
freeaddrinfo (res0);
|
||||
break;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
#endif /* HAVE_GETADDRINFO */
|
||||
|
||||
/*
|
||||
* Open a TCP or UDP connection to HOST on port SERV. Uses getaddrinfo(3)
|
||||
* if available, falling back to the traditional BSD mechanisms otherwise.
|
||||
* Returns the connected socket or -1 on error.
|
||||
*/
|
||||
static int
|
||||
_netopen(host, serv, typ)
|
||||
char *host, *serv;
|
||||
int typ;
|
||||
{
|
||||
#ifdef HAVE_GETADDRINFO
|
||||
return (_netopen6 (host, serv, typ));
|
||||
#else
|
||||
return (_netopen4 (host, serv, typ));
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Open a TCP or UDP connection given a path like `/dev/tcp/host/port' to
|
||||
* host `host' on port `port' and return the connected socket.
|
||||
*/
|
||||
int
|
||||
netopen (path)
|
||||
char *path;
|
||||
{
|
||||
char *np, *s, *t;
|
||||
int fd;
|
||||
|
||||
np = (char *)xmalloc (strlen (path) + 1);
|
||||
strcpy (np, path);
|
||||
|
||||
s = np + 9;
|
||||
t = strchr (s, '/');
|
||||
if (t == 0)
|
||||
{
|
||||
internal_error (_("%s: bad network path specification"), path);
|
||||
return -1;
|
||||
}
|
||||
*t++ = '\0';
|
||||
fd = _netopen (s, t, path[5]);
|
||||
free (np);
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/*
|
||||
* Open a TCP connection to host `host' on the port defined for service
|
||||
* `serv' and return the connected socket.
|
||||
*/
|
||||
int
|
||||
tcpopen (host, serv)
|
||||
char *host, *serv;
|
||||
{
|
||||
return (_netopen (host, serv, 't'));
|
||||
}
|
||||
|
||||
/*
|
||||
* Open a UDP connection to host `host' on the port defined for service
|
||||
* `serv' and return the connected socket.
|
||||
*/
|
||||
int
|
||||
udpopen (host, serv)
|
||||
char *host, *serv;
|
||||
{
|
||||
return _netopen (host, serv, 'u');
|
||||
}
|
||||
#endif
|
||||
|
||||
#else /* !HAVE_NETWORK */
|
||||
|
||||
int
|
||||
netopen (path)
|
||||
char *path;
|
||||
{
|
||||
internal_error (_("network operations not supported"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif /* !HAVE_NETWORK */
|
||||
+1
-2
@@ -57,8 +57,7 @@ sh_regmatch (string, pattern, flags)
|
||||
char *subexp_str;
|
||||
int subexp_len;
|
||||
#endif
|
||||
int result;
|
||||
|
||||
int result;
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
rematch = (SHELL_VAR *)NULL;
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
/* Copyright (C) 2003 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne Again SHell.
|
||||
|
||||
Bash 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 2, or (at your option) any later
|
||||
version.
|
||||
|
||||
Bash is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with Bash; see the file COPYING. If not, write to the Free Software
|
||||
Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
|
||||
|
||||
/*
|
||||
* shmatch.c -- shell interface to posix regular expression matching.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#if defined (HAVE_POSIX_REGEXP)
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "bashansi.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <regex.h>
|
||||
|
||||
#include "shell.h"
|
||||
#include "variables.h"
|
||||
#include "externs.h"
|
||||
|
||||
extern int glob_ignore_case, match_ignore_case;
|
||||
|
||||
int
|
||||
sh_regmatch (string, pattern, flags)
|
||||
const char *string;
|
||||
const char *pattern;
|
||||
int flags;
|
||||
{
|
||||
regex_t regex = { 0 };
|
||||
regmatch_t *matches;
|
||||
int rflags;
|
||||
#if defined (ARRAY_VARS)
|
||||
SHELL_VAR *rematch;
|
||||
ARRAY *amatch;
|
||||
int subexp_ind;
|
||||
char *subexp_str;
|
||||
int subexp_len;
|
||||
#endif
|
||||
int result;
|
||||
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
rematch = (SHELL_VAR *)NULL;
|
||||
#endif
|
||||
|
||||
rflags = REG_EXTENDED;
|
||||
if (glob_ignore_case || match_ignore_case)
|
||||
rflags |= REG_ICASE;
|
||||
#if !defined (ARRAY_VARS)
|
||||
rflags |= REG_NOSUB;
|
||||
#endif
|
||||
|
||||
if (regcomp (®ex, pattern, rflags))
|
||||
return 2; /* flag for printing a warning here. */
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
matches = (regmatch_t *)malloc (sizeof (regmatch_t) * (regex.re_nsub + 1));
|
||||
#else
|
||||
matches = NULL;
|
||||
#endif
|
||||
|
||||
if (regexec (®ex, string, regex.re_nsub + 1, matches, 0))
|
||||
result = EXECUTION_FAILURE;
|
||||
else
|
||||
result = EXECUTION_SUCCESS; /* match */
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
subexp_len = strlen (string) + 10;
|
||||
subexp_str = malloc (subexp_len + 1);
|
||||
|
||||
/* Store the parenthesized subexpressions in the array BASH_REMATCH.
|
||||
Element 0 is the portion that matched the entire regexp. Element 1
|
||||
is the part that matched the first subexpression, and so on. */
|
||||
unbind_variable ("BASH_REMATCH");
|
||||
rematch = make_new_array_variable ("BASH_REMATCH");
|
||||
amatch = array_cell (rematch);
|
||||
|
||||
if ((flags & SHMAT_SUBEXP) && result == EXECUTION_SUCCESS && subexp_str)
|
||||
{
|
||||
for (subexp_ind = 0; subexp_ind <= regex.re_nsub; subexp_ind++)
|
||||
{
|
||||
memset (subexp_str, 0, subexp_len);
|
||||
strncpy (subexp_str, string + matches[subexp_ind].rm_so,
|
||||
matches[subexp_ind].rm_eo - matches[subexp_ind].rm_so);
|
||||
array_insert (amatch, subexp_ind, subexp_str);
|
||||
}
|
||||
}
|
||||
|
||||
VSETATTR (rematch, att_readonly);
|
||||
|
||||
free (subexp_str);
|
||||
free (matches);
|
||||
#endif /* ARRAY_VARS */
|
||||
|
||||
regfree (®ex);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif /* HAVE_POSIX_REGEXP */
|
||||
+1
-1
@@ -176,7 +176,7 @@ ansic_quote (str, flags, rlen)
|
||||
int flags, *rlen;
|
||||
{
|
||||
char *r, *ret, *s;
|
||||
int l, rsize, t;
|
||||
int l, rsize;
|
||||
unsigned char c;
|
||||
|
||||
if (str == 0 || *str == 0)
|
||||
|
||||
+3
-2
@@ -47,6 +47,9 @@ extern int errno;
|
||||
|
||||
extern pid_t dollar_dollar_pid;
|
||||
|
||||
static char *get_sys_tmpdir __P((void));
|
||||
static char *get_tmpdir __P((int));
|
||||
|
||||
static char *sys_tmpdir = (char *)NULL;
|
||||
static int ntmpfiles;
|
||||
static int tmpnamelen = -1;
|
||||
@@ -55,8 +58,6 @@ static unsigned long filenum = 1L;
|
||||
static char *
|
||||
get_sys_tmpdir ()
|
||||
{
|
||||
struct stat sb;
|
||||
|
||||
if (sys_tmpdir)
|
||||
return sys_tmpdir;
|
||||
|
||||
|
||||
@@ -0,0 +1,214 @@
|
||||
/*
|
||||
* tmpfile.c - functions to create and safely open temp files for the shell.
|
||||
*/
|
||||
|
||||
/* Copyright (C) 2000 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne Again SHell.
|
||||
|
||||
Bash 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 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
Bash is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Bash; see the file COPYING. If not, write to the Free
|
||||
Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <bashtypes.h>
|
||||
#include <posixstat.h>
|
||||
#include <posixtime.h>
|
||||
#include <filecntl.h>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <shell.h>
|
||||
|
||||
#ifndef errno
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
#define BASEOPENFLAGS (O_CREAT | O_TRUNC | O_EXCL)
|
||||
|
||||
#define DEFAULT_TMPDIR "." /* bogus default, should be changed */
|
||||
#define DEFAULT_NAMEROOT "shtmp"
|
||||
|
||||
extern pid_t dollar_dollar_pid;
|
||||
|
||||
static char *sys_tmpdir = (char *)NULL;
|
||||
static int ntmpfiles;
|
||||
static int tmpnamelen = -1;
|
||||
static unsigned long filenum = 1L;
|
||||
|
||||
static char *
|
||||
get_sys_tmpdir ()
|
||||
{
|
||||
if (sys_tmpdir)
|
||||
return sys_tmpdir;
|
||||
|
||||
#ifdef P_tmpdir
|
||||
sys_tmpdir = P_tmpdir;
|
||||
if (file_iswdir (sys_tmpdir))
|
||||
return sys_tmpdir;
|
||||
#endif
|
||||
|
||||
sys_tmpdir = "/tmp";
|
||||
if (file_iswdir (sys_tmpdir))
|
||||
return sys_tmpdir;
|
||||
|
||||
sys_tmpdir = "/var/tmp";
|
||||
if (file_iswdir (sys_tmpdir))
|
||||
return sys_tmpdir;
|
||||
|
||||
sys_tmpdir = "/usr/tmp";
|
||||
if (file_iswdir (sys_tmpdir))
|
||||
return sys_tmpdir;
|
||||
|
||||
sys_tmpdir = DEFAULT_TMPDIR;
|
||||
|
||||
return sys_tmpdir;
|
||||
}
|
||||
|
||||
static char *
|
||||
get_tmpdir (flags)
|
||||
int flags;
|
||||
{
|
||||
char *tdir;
|
||||
|
||||
tdir = (flags & MT_USETMPDIR) ? get_string_value ("TMPDIR") : (char *)NULL;
|
||||
if (tdir == 0)
|
||||
tdir = get_sys_tmpdir ();
|
||||
|
||||
#if defined (HAVE_PATHCONF) && defined (_PC_NAME_MAX)
|
||||
if (tmpnamelen == -1)
|
||||
tmpnamelen = pathconf (tdir, _PC_NAME_MAX);
|
||||
#else
|
||||
tmpnamelen = 0;
|
||||
#endif
|
||||
|
||||
return tdir;
|
||||
}
|
||||
|
||||
char *
|
||||
sh_mktmpname (nameroot, flags)
|
||||
char *nameroot;
|
||||
int flags;
|
||||
{
|
||||
char *filename, *tdir, *lroot;
|
||||
struct stat sb;
|
||||
int r, tdlen;
|
||||
|
||||
filename = (char *)xmalloc (PATH_MAX + 1);
|
||||
tdir = get_tmpdir (flags);
|
||||
tdlen = strlen (tdir);
|
||||
|
||||
lroot = nameroot ? nameroot : DEFAULT_NAMEROOT;
|
||||
|
||||
#ifdef USE_MKTEMP
|
||||
sprintf (filename, "%s/%s.XXXXXX", tdir, lroot);
|
||||
if (mktemp (filename) == 0)
|
||||
{
|
||||
free (filename);
|
||||
filename = NULL;
|
||||
}
|
||||
#else /* !USE_MKTEMP */
|
||||
while (1)
|
||||
{
|
||||
filenum = (filenum << 1) ^
|
||||
(unsigned long) time ((time_t *)0) ^
|
||||
(unsigned long) dollar_dollar_pid ^
|
||||
(unsigned long) ((flags & MT_USERANDOM) ? get_random_number () : ntmpfiles++);
|
||||
sprintf (filename, "%s/%s-%lu", tdir, lroot, filenum);
|
||||
if (tmpnamelen > 0 && tmpnamelen < 32)
|
||||
filename[tdlen + 1 + tmpnamelen] = '\0';
|
||||
# ifdef HAVE_LSTAT
|
||||
r = lstat (filename, &sb);
|
||||
# else
|
||||
r = stat (filename, &sb);
|
||||
# endif
|
||||
if (r < 0 && errno == ENOENT)
|
||||
break;
|
||||
}
|
||||
#endif /* !USE_MKTEMP */
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
int
|
||||
sh_mktmpfd (nameroot, flags, namep)
|
||||
char *nameroot;
|
||||
int flags;
|
||||
char **namep;
|
||||
{
|
||||
char *filename, *tdir, *lroot;
|
||||
int fd, tdlen;
|
||||
|
||||
filename = (char *)xmalloc (PATH_MAX + 1);
|
||||
tdir = get_tmpdir (flags);
|
||||
tdlen = strlen (tdir);
|
||||
|
||||
lroot = nameroot ? nameroot : DEFAULT_NAMEROOT;
|
||||
|
||||
#ifdef USE_MKSTEMP
|
||||
sprintf (filename, "%s/%s.XXXXXX", tdir, lroot);
|
||||
fd = mkstemp (filename);
|
||||
if (fd < 0 || namep == 0)
|
||||
{
|
||||
free (filename);
|
||||
filename = NULL;
|
||||
}
|
||||
if (namep)
|
||||
*namep = filename;
|
||||
return fd;
|
||||
#else /* !USE_MKSTEMP */
|
||||
do
|
||||
{
|
||||
filenum = (filenum << 1) ^
|
||||
(unsigned long) time ((time_t *)0) ^
|
||||
(unsigned long) dollar_dollar_pid ^
|
||||
(unsigned long) ((flags & MT_USERANDOM) ? get_random_number () : ntmpfiles++);
|
||||
sprintf (filename, "%s/%s-%lu", tdir, lroot, filenum);
|
||||
if (tmpnamelen > 0 && tmpnamelen < 32)
|
||||
filename[tdlen + 1 + tmpnamelen] = '\0';
|
||||
fd = open (filename, BASEOPENFLAGS | ((flags & MT_READWRITE) ? O_RDWR : O_WRONLY), 0600);
|
||||
}
|
||||
while (fd < 0 && errno == EEXIST);
|
||||
|
||||
if (namep)
|
||||
*namep = filename;
|
||||
else
|
||||
free (filename);
|
||||
|
||||
return fd;
|
||||
#endif /* !USE_MKSTEMP */
|
||||
}
|
||||
|
||||
FILE *
|
||||
sh_mktmpfp (nameroot, flags, namep)
|
||||
char *nameroot;
|
||||
int flags;
|
||||
char **namep;
|
||||
{
|
||||
int fd;
|
||||
FILE *fp;
|
||||
|
||||
fd = sh_mktmpfd (nameroot, flags, namep);
|
||||
if (fd < 0)
|
||||
return ((FILE *)NULL);
|
||||
fp = fdopen (fd, (flags & MT_READWRITE) ? "w+" : "w");
|
||||
if (fp == 0)
|
||||
close (fd);
|
||||
return fp;
|
||||
}
|
||||
@@ -55,6 +55,7 @@ extern int shell_tty;
|
||||
#if defined (READLINE)
|
||||
extern void rl_set_screen_size __P((int, int));
|
||||
#endif
|
||||
extern void sh_set_lines_and_columns __P((int, int));
|
||||
|
||||
void
|
||||
get_new_window_size (from_sig, rp, cp)
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/* Handle window size changes and information. */
|
||||
|
||||
/* Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne Again SHell.
|
||||
|
||||
Bash 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 2, or (at your option) any later
|
||||
version.
|
||||
|
||||
Bash is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with Bash; see the file COPYING. If not, write to the Free Software
|
||||
Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdc.h>
|
||||
|
||||
#include "bashtypes.h"
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#if !defined (STRUCT_WINSIZE_IN_SYS_IOCTL)
|
||||
/* For struct winsize on SCO */
|
||||
/* sys/ptem.h has winsize but needs mblk_t from sys/stream.h */
|
||||
# if defined (HAVE_SYS_PTEM_H) && defined (TIOCGWINSZ) && defined (SIGWINCH)
|
||||
# if defined (HAVE_SYS_STREAM_H)
|
||||
# include <sys/stream.h>
|
||||
# endif
|
||||
# include <sys/ptem.h>
|
||||
# endif /* HAVE_SYS_PTEM_H && TIOCGWINSZ && SIGWINCH */
|
||||
#endif /* !STRUCT_WINSIZE_IN_SYS_IOCTL */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* Return the fd from which we are actually getting input. */
|
||||
#define input_tty() (shell_tty != -1) ? shell_tty : fileno (stderr)
|
||||
|
||||
#if !defined (errno)
|
||||
extern int errno;
|
||||
#endif /* !errno */
|
||||
|
||||
extern int shell_tty;
|
||||
|
||||
#if defined (READLINE)
|
||||
extern void rl_set_screen_size __P((int, int));
|
||||
#endif
|
||||
|
||||
void
|
||||
get_new_window_size (from_sig, rp, cp)
|
||||
int from_sig;
|
||||
int *rp, *cp;
|
||||
{
|
||||
#if defined (TIOCGWINSZ)
|
||||
struct winsize win;
|
||||
int tty;
|
||||
|
||||
tty = input_tty ();
|
||||
if (tty >= 0 && (ioctl (tty, TIOCGWINSZ, &win) == 0) &&
|
||||
win.ws_row > 0 && win.ws_col > 0)
|
||||
{
|
||||
sh_set_lines_and_columns (win.ws_row, win.ws_col);
|
||||
#if defined (READLINE)
|
||||
rl_set_screen_size (win.ws_row, win.ws_col);
|
||||
if (rp)
|
||||
*rp = win.ws_row;
|
||||
if (cp)
|
||||
*cp = win.ws_col;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user