mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-07-04 10:50:50 +02:00
more changes for here-docs and $'...'; command optimization updates
This commit is contained in:
@@ -1184,10 +1184,13 @@ Returns 0 if the timeout is set successfully.
|
||||
|
||||
@deftypefun int rl_timeout_remaining (unsigned int *secs, unsigned int *usecs)
|
||||
Return the number of seconds and microseconds remaining in the current
|
||||
timeout duration in @code{*secs} and @code{*usecs}, respectively.
|
||||
Returns -1 on error or when there is no timeout set, 0 when the timeout has
|
||||
expired (leaving @code{*secs} and @code{*usecs} unchanged), and 1 if the
|
||||
timeout has not expired. If @code{secs} and @code{usecs} are @code{NULL},
|
||||
timeout duration in @var{*secs} and @var{*usecs}, respectively.
|
||||
Both @var{*secs} and @var{*usecs} must be non-NULL to return any values.
|
||||
The return value is -1 on error or when there is no timeout set,
|
||||
0 when the timeout has expired (leaving @var{*secs} and @var{*usecs}
|
||||
unchanged),
|
||||
and 1 if the timeout has not expired.
|
||||
If either of @var{secs} and @var{usecs} is @code{NULL},
|
||||
the return value indicates whether the timeout has expired.
|
||||
@end deftypefun
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ typedef char *histdata_t;
|
||||
|
||||
/* Let's not step on anyone else's define for now, since we don't use this yet. */
|
||||
#ifndef HS_HISTORY_VERSION
|
||||
# define HS_HISTORY_VERSION 0x0801 /* History 8.1 */
|
||||
# define HS_HISTORY_VERSION 0x0802 /* History 8.2 */
|
||||
#endif
|
||||
|
||||
/* The structure used to store a history entry. */
|
||||
|
||||
@@ -39,9 +39,9 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
/* Hex-encoded Readline version number. */
|
||||
#define RL_READLINE_VERSION 0x0801 /* Readline 8.1 */
|
||||
#define RL_READLINE_VERSION 0x0802 /* Readline 8.2 */
|
||||
#define RL_VERSION_MAJOR 8
|
||||
#define RL_VERSION_MINOR 1
|
||||
#define RL_VERSION_MINOR 2
|
||||
|
||||
/* Readline data structures. */
|
||||
|
||||
|
||||
+10
-3
@@ -2,7 +2,7 @@
|
||||
# Makefile for the Bash library
|
||||
#
|
||||
#
|
||||
# Copyright (C) 1998-2020 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1998-2022 Free Software Foundation, Inc.
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -94,7 +94,7 @@ CSOURCES = clktck.c clock.c getcwd.c getenv.c oslib.c setlinebuf.c \
|
||||
wcsdup.c fpurge.c zgetline.c mbscmp.c uconvert.c ufuncs.c \
|
||||
casemod.c dprintf.c input_avail.c mbscasecmp.c fnxform.c \
|
||||
strchrnul.c unicode.c wcswidth.c wcsnwidth.c shmbchar.c strdup.c \
|
||||
utf8.c random.c gettimeofday.c timers.c
|
||||
strvis.c utf8.c random.c gettimeofday.c timers.c
|
||||
|
||||
# The header files for this library.
|
||||
HSOURCES =
|
||||
@@ -108,7 +108,7 @@ OBJECTS = clktck.o clock.o getenv.o oslib.o setlinebuf.o strnlen.o \
|
||||
strtrans.o snprintf.o mailstat.o fmtulong.o \
|
||||
fmtullong.o fmtumax.o zcatfd.o zmapfd.o winsize.o wcsdup.o \
|
||||
fpurge.o zgetline.o mbscmp.o uconvert.o ufuncs.o casemod.o \
|
||||
input_avail.o mbscasecmp.o fnxform.o unicode.o shmbchar.o \
|
||||
input_avail.o mbscasecmp.o fnxform.o unicode.o shmbchar.o strvis.o \
|
||||
utf8.o random.o gettimeofday.o timers.o wcsnwidth.o ${LIBOBJS}
|
||||
|
||||
SUPPORT = Makefile
|
||||
@@ -198,6 +198,7 @@ strtoul.o: strtoul.c
|
||||
strtoull.o: strtoull.c
|
||||
strtoumax.o: strtoumax.c
|
||||
strtrans.o: strtrans.c
|
||||
strvis.o: strvis.c
|
||||
timers.o: timers.c
|
||||
times.o: times.c
|
||||
timeval.o: timeval.c
|
||||
@@ -279,6 +280,7 @@ strtoul.o: ${BUILD_DIR}/config.h
|
||||
strtoull.o: ${BUILD_DIR}/config.h
|
||||
strtoumax.o: ${BUILD_DIR}/config.h
|
||||
strtrans.o: ${BUILD_DIR}/config.h
|
||||
strvis.o: ${BUILD_DIR}/config.h
|
||||
timers.o: ${BUILD_DIR}/config.h
|
||||
times.o: ${BUILD_DIR}/config.h
|
||||
timeval.o: ${BUILD_DIR}/config.h
|
||||
@@ -512,6 +514,11 @@ strtrans.o: ${BUILD_DIR}/pathnames.h ${topdir}/externs.h
|
||||
strtrans.o: ${BASHINCDIR}/shmbutil.h ${BASHINCDIR}/shmbchar.h
|
||||
#strtrans.o: ${BUILD_DIR}/version.h
|
||||
|
||||
strvis.o: ${topdir}/bashansi.h
|
||||
strvis.o: ${BASHINCDIR}/ansi_stdlib.h ${BASHINCDIR}/chartypes.h
|
||||
strvis.o: ${BASHINCDIR}/shmbutil.h ${BASHINCDIR}/shmbchar.h
|
||||
strvis.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
|
||||
|
||||
times.o: ${BASHINCDIR}/systimes.h
|
||||
times.o: ${BASHINCDIR}/posixtime.h
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Bash. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
|
||||
+145
@@ -0,0 +1,145 @@
|
||||
/* strvis.c - make unsafe graphical characters in a string visible. */
|
||||
|
||||
/* Copyright (C) 2022 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 3 of the License, 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. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* This is a stripped-down version suitable for the shell's use. */
|
||||
#include <config.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "bashansi.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include "chartypes.h"
|
||||
#include "bashintl.h"
|
||||
#include "shmbutil.h"
|
||||
|
||||
#define SAFECHAR(c) ((c) == ' ' || (c) == '\t')
|
||||
|
||||
#ifndef RUBOUT
|
||||
#define RUBOUT 0x7f
|
||||
#endif
|
||||
|
||||
#ifndef CTRL_CHAR
|
||||
#define CTRL_CHAR(c) ((c) < 0x20)
|
||||
#endif
|
||||
|
||||
#ifndef META_CHAR
|
||||
#define META_CHAR(c) ((c) > 0x7f && (c) <= UCHAR_MAX)
|
||||
#endif
|
||||
|
||||
#ifndef UNCTRL
|
||||
#define UNCTRL(c) (TOUPPER ((c) | 0x40))
|
||||
#endif
|
||||
|
||||
#ifndef UNMETA
|
||||
#define UNMETA(c) ((c) & 0x7f)
|
||||
#endif
|
||||
|
||||
static int
|
||||
charvis (s, sindp, ret, rindp)
|
||||
const char *s;
|
||||
size_t *sindp;
|
||||
char *ret;
|
||||
size_t *rindp;
|
||||
{
|
||||
unsigned char c;
|
||||
size_t si, ri;
|
||||
const char *send;
|
||||
DECLARE_MBSTATE;
|
||||
|
||||
si = *sindp;
|
||||
ri = *rindp;
|
||||
c = s[*sindp];
|
||||
|
||||
send = (locale_mb_cur_max > 1) ? s + strlen (s) : 0;
|
||||
|
||||
if (SAFECHAR (c))
|
||||
{
|
||||
ret[ri++] = c;
|
||||
si++;
|
||||
}
|
||||
else if (c == RUBOUT)
|
||||
{
|
||||
ret[ri++] = '^';
|
||||
ret[ri++] = '?';
|
||||
si++;
|
||||
}
|
||||
else if (CTRL_CHAR (c))
|
||||
{
|
||||
ret[ri++] = '^';
|
||||
ret[ri++] = UNCTRL (c);
|
||||
si++;
|
||||
}
|
||||
else if (locale_mb_cur_max > 1)
|
||||
COPY_CHAR_I (ret, ri, s, send, si);
|
||||
else if (META_CHAR (c))
|
||||
{
|
||||
ret[ri++] = 'M';
|
||||
ret[ri++] = '-';
|
||||
ret[ri++] = UNMETA (c);
|
||||
si++;
|
||||
}
|
||||
else
|
||||
ret[ri++] = s[si++];
|
||||
|
||||
*sindp = si;
|
||||
*rindp = ri;
|
||||
|
||||
return si;
|
||||
}
|
||||
|
||||
/* Return a new string with `unsafe' non-graphical characters in S rendered
|
||||
in a visible way. */
|
||||
char *
|
||||
sh_strvis (string)
|
||||
const char *string;
|
||||
{
|
||||
size_t slen, sind;
|
||||
char *ret;
|
||||
size_t retind, retsize;
|
||||
unsigned char c;
|
||||
DECLARE_MBSTATE;
|
||||
|
||||
if (string == 0)
|
||||
return 0;
|
||||
if (*string == '\0')
|
||||
{
|
||||
if ((ret = (char *)malloc (1)) == 0)
|
||||
return 0;
|
||||
ret[0] = '\0';
|
||||
return ret;
|
||||
}
|
||||
|
||||
slen = strlen (string);
|
||||
retsize = 3 * slen + 1;
|
||||
|
||||
ret = (char *)malloc (retsize);
|
||||
if (ret == 0)
|
||||
return 0;
|
||||
|
||||
retind = 0;
|
||||
sind = 0;
|
||||
|
||||
while (string[sind])
|
||||
sind = charvis (string, &sind, ret, &retind);
|
||||
|
||||
ret[retind] = '\0';
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user