1
0
Fork 0

Adding upstream version 5.2.37.

Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
This commit is contained in:
Daniel Baumann 2025-06-21 06:49:21 +02:00
parent cf91100bce
commit fa1b3d3922
Signed by: daniel.baumann
GPG key ID: BCC918A2ABD66424
1435 changed files with 757174 additions and 0 deletions

169
lib/glob/Makefile.in Normal file
View file

@ -0,0 +1,169 @@
## -*- text -*- ####################################################
# #
# Makefile for the GNU Glob Library. #
# #
####################################################################
#
# Copyright (C) 1996-2009 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
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
srcdir = @srcdir@
VPATH = @srcdir@
topdir = @top_srcdir@
BUILD_DIR = @BUILD_DIR@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
CC = @CC@
RANLIB = @RANLIB@
AR = @AR@
ARFLAGS = @ARFLAGS@
RM = rm -f
CP = cp
MV = mv
SHELL = @MAKE_SHELL@
PROFILE_FLAGS = @PROFILE_FLAGS@
CFLAGS = @CFLAGS@
LOCAL_CFLAGS = @LOCAL_CFLAGS@
STYLE_CFLAGS = @STYLE_CFLAGS@
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@ @LOCAL_LDFLAGS@
DEFS = @DEFS@
LOCAL_DEFS = @LOCAL_DEFS@
BASHINCDIR = ${topdir}/include
INCLUDES = -I. -I../.. -I$(topdir) -I$(BASHINCDIR) -I$(topdir)/lib
CCFLAGS = $(PROFILE_FLAGS) $(DEFS) $(LOCAL_DEFS) ${INCLUDES} $(CPPFLAGS) \
$(STYLE_CFLAGS) $(LOCAL_CFLAGS) $(CFLAGS) ${ADDON_CFLAGS}
# Here is a rule for making .o files from .c files that doesn't force
# the type of the machine (like -sun3) into the flags.
.c.o:
$(RM) $@
$(CC) -c $(CCFLAGS) $<
# The name of the library target.
LIBRARY_NAME = libglob.a
# The C code source files for this library.
CSOURCES = $(srcdir)/glob.c $(srcdir)/strmatch.c $(srcdir)/smatch.c \
$(srcdir)/xmbsrtowcs.c
# The header files for this library.
HSOURCES = $(srcdir)/strmatch.h
OBJECTS = glob.o strmatch.o smatch.o xmbsrtowcs.o gmisc.o
# The texinfo files which document this library.
DOCSOURCE = doc/glob.texi
DOCOBJECT = doc/glob.dvi
DOCSUPPORT = doc/Makefile
DOCUMENTATION = $(DOCSOURCE) $(DOCOBJECT) $(DOCSUPPORT)
SUPPORT = Makefile ChangeLog $(DOCSUPPORT)
SOURCES = $(CSOURCES) $(HSOURCES) $(DOCSOURCE)
THINGS_TO_TAR = $(SOURCES) $(SUPPORT)
######################################################################
all: $(LIBRARY_NAME)
$(LIBRARY_NAME): $(OBJECTS)
$(RM) -f $@
$(AR) $(ARFLAGS) $@ $(OBJECTS)
-test -n "$(RANLIB)" && $(RANLIB) $@
what-tar:
@for file in $(THINGS_TO_TAR); do \
echo $(selfdir)$$file; \
done
documentation: force
-(cd doc; $(MAKE) $(MFLAGS))
force:
# The rule for 'includes' is written funny so that the if statement
# always returns TRUE unless there really was an error installing the
# include files.
install:
clean:
rm -f $(OBJECTS) $(LIBRARY_NAME)
-(cd doc && $(MAKE) $(MFLAGS) $@ )
realclean distclean maintainer-clean: clean
-( cd doc && $(MAKE) $(MFLAGS) $@ )
$(RM) -f Makefile
mostlyclean: clean
-( cd doc && $(MAKE) $(MFLAGS) $@ )
${BUILD_DIR}/pathnames.h: ${BUILD_DIR}/config.h ${BUILD_DIR}/Makefile Makefile
-( cd ${BUILD_DIR} && ${MAKE} ${MFLAGS} pathnames.h )
######################################################################
# #
# Dependencies for the object files which make up this library. #
# #
######################################################################
smatch.o: strmatch.h
smatch.o: $(BUILD_DIR)/config.h
smatch.o: $(BASHINCDIR)/chartypes.h
smatch.o: $(BASHINCDIR)/ansi_stdlib.h $(topdir)/bashansi.h
smatch.o: $(BASHINCDIR)/shmbutil.h
smatch.o: $(topdir)/xmalloc.h
strmatch.o: strmatch.h
strmatch.o: $(BUILD_DIR)/config.h
strmatch.o: $(BASHINCDIR)/stdc.h
glob.o: $(BUILD_DIR)/config.h
glob.o: $(topdir)/shell.h $(BUILD_DIR)/pathnames.h
glob.o: $(topdir)/bashtypes.h $(BASHINCDIR)/ansi_stdlib.h $(topdir)/bashansi.h
glob.o: $(BASHINCDIR)/posixstat.h $(BASHINCDIR)/memalloc.h
glob.o: strmatch.h glob.h
glob.o: $(BASHINCDIR)/shmbutil.h
glob.o: $(topdir)/xmalloc.h
gmisc.o: $(BUILD_DIR)/config.h
gmisc.o: $(topdir)/bashtypes.h $(BASHINCDIR)/ansi_stdlib.h $(topdir)/bashansi.h
gmisc.o: $(BASHINCDIR)/shmbutil.h
xmbsrtowcs.o: ${BUILD_DIR}/config.h
xmbsrtowcs.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h
xmbsrtowcs.o: ${BASHINCDIR}/shmbutil.h
# Rules for deficient makes, like SunOS and Solaris
glob.o: glob.c
gmisc.o: gmisc.c
strmatch.o: strmatch.c
smatch.o: smatch.c
xmbsrtowcs.o: xmbsrtowcs.c
# dependencies for C files that include other C files
glob.o: glob_loop.c
gmisc.o: gm_loop.c
smatch.o: sm_loop.c

140
lib/glob/collsyms.h Normal file
View file

@ -0,0 +1,140 @@
/* collsyms.h -- collating symbol names and their corresponding characters
(in ascii) as given by POSIX.2 in table 2.8. */
/* Copyright (C) 1997-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 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/>.
*/
/* The upper-case letters, lower-case letters, and digits are omitted from
this table. The digits are not included in the table in the POSIX.2
spec. The upper and lower case letters are translated by the code
in smatch.c:collsym(). */
typedef struct _COLLSYM {
XCHAR *name;
CHAR code;
} __COLLSYM;
static __COLLSYM POSIXCOLL [] =
{
{ L("NUL"), L('\0') },
{ L("SOH"), L('\001') },
{ L("STX"), L('\002') },
{ L("ETX"), L('\003') },
{ L("EOT"), L('\004') },
{ L("ENQ"), L('\005') },
{ L("ACK"), L('\006') },
#ifdef __STDC__
{ L("alert"), L('\a') },
#else
{ L("alert"), L('\007') },
#endif
{ L("BS"), L('\010') },
{ L("backspace"), L('\b') },
{ L("HT"), L('\011') },
{ L("tab"), L('\t') },
{ L("LF"), L('\012') },
{ L("newline"), L('\n') },
{ L("VT"), L('\013') },
{ L("vertical-tab"), L('\v') },
{ L("FF"), L('\014') },
{ L("form-feed"), L('\f') },
{ L("CR"), L('\015') },
{ L("carriage-return"), L('\r') },
{ L("SO"), L('\016') },
{ L("SI"), L('\017') },
{ L("DLE"), L('\020') },
{ L("DC1"), L('\021') },
{ L("DC2"), L('\022') },
{ L("DC3"), L('\023') },
{ L("DC4"), L('\024') },
{ L("NAK"), L('\025') },
{ L("SYN"), L('\026') },
{ L("ETB"), L('\027') },
{ L("CAN"), L('\030') },
{ L("EM"), L('\031') },
{ L("SUB"), L('\032') },
{ L("ESC"), L('\033') },
{ L("IS4"), L('\034') },
{ L("FS"), L('\034') },
{ L("IS3"), L('\035') },
{ L("GS"), L('\035') },
{ L("IS2"), L('\036') },
{ L("RS"), L('\036') },
{ L("IS1"), L('\037') },
{ L("US"), L('\037') },
{ L("space"), L(' ') },
{ L("exclamation-mark"), L('!') },
{ L("quotation-mark"), L('"') },
{ L("number-sign"), L('#') },
{ L("dollar-sign"), L('$') },
{ L("percent-sign"), L('%') },
{ L("ampersand"), L('&') },
{ L("apostrophe"), L('\'') },
{ L("left-parenthesis"), L('(') },
{ L("right-parenthesis"), L(')') },
{ L("asterisk"), L('*') },
{ L("plus-sign"), L('+') },
{ L("comma"), L(',') },
{ L("hyphen"), L('-') },
{ L("hyphen-minus"), L('-') },
{ L("minus"), L('-') }, /* extension from POSIX.2 */
{ L("dash"), L('-') }, /* extension from POSIX.2 */
{ L("period"), L('.') },
{ L("full-stop"), L('.') },
{ L("slash"), L('/') },
{ L("solidus"), L('/') }, /* extension from POSIX.2 */
{ L("zero"), L('0') },
{ L("one"), L('1') },
{ L("two"), L('2') },
{ L("three"), L('3') },
{ L("four"), L('4') },
{ L("five"), L('5') },
{ L("six"), L('6') },
{ L("seven"), L('7') },
{ L("eight"), L('8') },
{ L("nine"), L('9') },
{ L("colon"), L(':') },
{ L("semicolon"), L(';') },
{ L("less-than-sign"), L('<') },
{ L("equals-sign"), L('=') },
{ L("greater-than-sign"), L('>') },
{ L("question-mark"), L('?') },
{ L("commercial-at"), L('@') },
/* upper-case letters omitted */
{ L("left-square-bracket"), L('[') },
{ L("backslash"), L('\\') },
{ L("reverse-solidus"), L('\\') },
{ L("right-square-bracket"), L(']') },
{ L("circumflex"), L('^') },
{ L("circumflex-accent"), L('^') }, /* extension from POSIX.2 */
{ L("underscore"), L('_') },
{ L("grave-accent"), L('`') },
/* lower-case letters omitted */
{ L("left-brace"), L('{') }, /* extension from POSIX.2 */
{ L("left-curly-bracket"), L('{') },
{ L("vertical-line"), L('|') },
{ L("right-brace"), L('}') }, /* extension from POSIX.2 */
{ L("right-curly-bracket"), L('}') },
{ L("tilde"), L('~') },
{ L("DEL"), L('\177') },
{ 0, 0 },
};
#undef _COLLSYM
#undef __COLLSYM
#undef POSIXCOLL

5
lib/glob/doc/Makefile Normal file
View file

@ -0,0 +1,5 @@
all:
cp glob.texi glob.info
clean distclean mostlyclean maintainer-clean:
rm -f glob.?? glob.info

1
lib/glob/doc/glob.texi Normal file
View file

@ -0,0 +1 @@
Nothing happens here.

1609
lib/glob/glob.c Normal file

File diff suppressed because it is too large Load diff

47
lib/glob/glob.h Normal file
View file

@ -0,0 +1,47 @@
/* File-name wildcard pattern matching for GNU.
Copyright (C) 1985-2021 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/>.
*/
#ifndef _GLOB_H_
#define _GLOB_H_
#include "stdc.h"
#define GX_MARKDIRS 0x001 /* mark directory names with trailing `/' */
#define GX_NOCASE 0x002 /* ignore case */
#define GX_MATCHDOT 0x004 /* match `.' literally */
#define GX_MATCHDIRS 0x008 /* match only directory names */
#define GX_ALLDIRS 0x010 /* match all directory names, no others */
#define GX_NULLDIR 0x100 /* internal -- no directory preceding pattern */
#define GX_ADDCURDIR 0x200 /* internal -- add passed directory name */
#define GX_GLOBSTAR 0x400 /* turn on special handling of ** */
#define GX_RECURSE 0x800 /* internal -- glob_filename called recursively */
#define GX_SYMLINK 0x1000 /* internal -- symlink to a directory */
#define GX_NEGATE 0x2000 /* internal -- extglob pattern being negated */
extern int glob_pattern_p PARAMS((const char *));
extern char **glob_vector PARAMS((char *, char *, int));
extern char **glob_filename PARAMS((char *, int));
extern int extglob_pattern_p PARAMS((const char *));
extern char *glob_error_return;
extern int noglob_dot_filenames;
extern int glob_ignore_case;
#endif /* _GLOB_H_ */

84
lib/glob/glob_loop.c Normal file
View file

@ -0,0 +1,84 @@
/* Copyright (C) 1991-2020 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/>.
*/
static int INTERNAL_GLOB_PATTERN_P PARAMS((const GCHAR *));
/* Return nonzero if PATTERN has any special globbing chars in it.
Compiled twice, once each for single-byte and multibyte characters. */
static int
INTERNAL_GLOB_PATTERN_P (pattern)
const GCHAR *pattern;
{
register const GCHAR *p;
register GCHAR c;
int bopen, bsquote;
p = pattern;
bopen = bsquote = 0;
while ((c = *p++) != L('\0'))
switch (c)
{
case L('?'):
case L('*'):
return 1;
case L('['): /* Only accept an open brace if there is a close */
bopen++; /* brace to match it. Bracket expressions must be */
continue; /* complete, according to Posix.2 */
case L(']'):
if (bopen)
return 1;
continue;
case L('+'): /* extended matching operators */
case L('@'):
case L('!'):
if (*p == L('(')) /*) */
return 1;
continue;
case L('\\'):
/* Don't let the pattern end in a backslash (GMATCH returns no match
if the pattern ends in a backslash anyway), but otherwise note that
we have seen this, since the matching engine uses backslash as an
escape character and it can be removed. We return 2 later if we
have seen only backslash-escaped characters, so interested callers
know they can shortcut and just dequote the pathname. */
if (*p != L('\0'))
{
p++;
bsquote = 1;
continue;
}
else /* (*p == L('\0')) */
return 0;
}
#if 0
return bsquote ? 2 : 0;
#else
return (0);
#endif
}
#undef INTERNAL_GLOB_PATTERN_P
#undef L
#undef INT
#undef CHAR
#undef GCHAR

208
lib/glob/gm_loop.c Normal file
View file

@ -0,0 +1,208 @@
/* Copyright (C) 1991-2017 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/>.
*/
#if EXTENDED_GLOB
int
EXTGLOB_PATTERN_P (pat)
const CHAR *pat;
{
switch (pat[0])
{
case L('*'):
case L('+'):
case L('!'):
case L('@'):
case L('?'):
return (pat[1] == L('(')); /* ) */
default:
return 0;
}
return 0;
}
#endif
/* Return 1 of the first character of STRING could match the first
character of pattern PAT. Compiled to both single and wiide character
versions. FLAGS is a subset of strmatch flags; used to do case-insensitive
matching for now. */
int
MATCH_PATTERN_CHAR (pat, string, flags)
CHAR *pat, *string;
int flags;
{
CHAR c;
if (*string == 0)
return (*pat == L('*')); /* XXX - allow only * to match empty string */
switch (c = *pat++)
{
default:
return (FOLD(*string) == FOLD(c));
case L('\\'):
return (FOLD(*string) == FOLD(*pat));
case L('?'):
return (*pat == L('(') ? 1 : (*string != L'\0'));
case L('*'):
return (1);
case L('+'):
case L('!'):
case L('@'):
return (*pat == L('(') ? 1 : (FOLD(*string) == FOLD(c)));
case L('['):
return (*string != L('\0'));
}
}
int
MATCHLEN (pat, max)
CHAR *pat;
size_t max;
{
CHAR c;
int matlen, bracklen, t, in_cclass, in_collsym, in_equiv;
if (*pat == 0)
return (0);
matlen = in_cclass = in_collsym = in_equiv = 0;
while (c = *pat++)
{
switch (c)
{
default:
matlen++;
break;
case L('\\'):
if (*pat == 0)
return ++matlen;
else
{
matlen++;
pat++;
}
break;
case L('?'):
if (*pat == LPAREN)
return (matlen = -1); /* XXX for now */
else
matlen++;
break;
case L('*'):
return (matlen = -1);
case L('+'):
case L('!'):
case L('@'):
if (*pat == LPAREN)
return (matlen = -1); /* XXX for now */
else
matlen++;
break;
case L('['):
/* scan for ending `]', skipping over embedded [:...:] */
bracklen = 1;
c = *pat++;
do
{
if (c == 0)
{
pat--; /* back up to NUL */
matlen += bracklen;
goto bad_bracket;
}
else if (c == L('\\'))
{
/* *pat == backslash-escaped character */
bracklen++;
/* If the backslash or backslash-escape ends the string,
bail. The ++pat skips over the backslash escape */
if (*pat == 0 || *++pat == 0)
{
matlen += bracklen;
goto bad_bracket;
}
}
else if (c == L('[') && *pat == L(':')) /* character class */
{
pat++;
bracklen++;
in_cclass = 1;
}
else if (in_cclass && c == L(':') && *pat == L(']'))
{
pat++;
bracklen++;
in_cclass = 0;
}
else if (c == L('[') && *pat == L('.')) /* collating symbol */
{
pat++;
bracklen++;
if (*pat == L(']')) /* right bracket can appear as collating symbol */
{
pat++;
bracklen++;
}
in_collsym = 1;
}
else if (in_collsym && c == L('.') && *pat == L(']'))
{
pat++;
bracklen++;
in_collsym = 0;
}
else if (c == L('[') && *pat == L('=')) /* equivalence class */
{
pat++;
bracklen++;
if (*pat == L(']')) /* right bracket can appear as equivalence class */
{
pat++;
bracklen++;
}
in_equiv = 1;
}
else if (in_equiv && c == L('=') && *pat == L(']'))
{
pat++;
bracklen++;
in_equiv = 0;
}
else
bracklen++;
}
while ((c = *pat++) != L(']'));
matlen++; /* bracket expression can only match one char */
bad_bracket:
break;
}
}
return matlen;
}
#undef EXTGLOB_PATTERN_P
#undef MATCH_PATTERN_CHAR
#undef MATCHLEN
#undef FOLD
#undef L
#undef LPAREN
#undef RPAREN
#undef INT
#undef CHAR

108
lib/glob/gmisc.c Normal file
View file

@ -0,0 +1,108 @@
/* gmisc.c -- miscellaneous pattern matching utility functions for Bash.
Copyright (C) 2010-2020 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/>.
*/
#include <config.h>
#include "bashtypes.h"
#if defined (HAVE_UNISTD_H)
# include <unistd.h>
#endif
#include "bashansi.h"
#include "shmbutil.h"
#include "chartypes.h"
#include "stdc.h"
#ifndef FNM_CASEFOLD
# include "strmatch.h"
#endif
#include "glob.h"
/* Make sure these names continue to agree with what's in smatch.c */
extern char *glob_patscan PARAMS((char *, char *, int));
/* Compile `gm_loop.c' for single-byte characters. */
#define CHAR char
#define INT int
#define L(CS) CS
#define EXTGLOB_PATTERN_P extglob_pattern_p
#define MATCH_PATTERN_CHAR match_pattern_char
#define MATCHLEN umatchlen
#define FOLD(c) ((flags & FNM_CASEFOLD) \
? TOLOWER ((unsigned char)c) \
: ((unsigned char)c))
#ifndef LPAREN
#define LPAREN '('
#define RPAREN ')'
#endif
#include "gm_loop.c"
/* Compile `gm_loop.c' again for multibyte characters. */
#if HANDLE_MULTIBYTE
#define CHAR wchar_t
#define INT wint_t
#define L(CS) L##CS
#define EXTGLOB_PATTERN_P wextglob_pattern_p
#define MATCH_PATTERN_CHAR match_pattern_wchar
#define MATCHLEN wmatchlen
#define FOLD(c) ((flags & FNM_CASEFOLD) && iswupper (c) ? towlower (c) : (c))
#define LPAREN L'('
#define RPAREN L')'
#include "gm_loop.c"
#endif /* HANDLE_MULTIBYTE */
#if defined (EXTENDED_GLOB)
/* Skip characters in PAT and return the final occurrence of DIRSEP. This
is only called when extended_glob is set, so we have to skip over extglob
patterns x(...) */
char *
glob_dirscan (pat, dirsep)
char *pat;
int dirsep;
{
char *p, *d, *pe, *se;
d = pe = se = 0;
for (p = pat; p && *p; p++)
{
if (extglob_pattern_p (p))
{
if (se == 0)
se = p + strlen (p) - 1;
pe = glob_patscan (p + 2, se, 0);
if (pe == 0)
continue;
else if (*pe == 0)
break;
p = pe - 1; /* will do increment above */
continue;
}
if (*p == dirsep)
d = p;
}
return d;
}
#endif /* EXTENDED_GLOB */

50
lib/glob/ndir.h Normal file
View file

@ -0,0 +1,50 @@
/* <dir.h> -- definitions for 4.2BSD-compatible directory access.
last edit: 09-Jul-1983 D A Gwyn. */
#if defined (VMS)
# if !defined (FAB$C_BID)
# include <fab.h>
# endif
# if !defined (NAM$C_BID)
# include <nam.h>
# endif
# if !defined (RMS$_SUC)
# include <rmsdef.h>
# endif
# include "dir.h"
#endif /* VMS */
/* Size of directory block. */
#define DIRBLKSIZ 512
/* NOTE: MAXNAMLEN must be one less than a multiple of 4 */
#if defined (VMS)
# define MAXNAMLEN (DIR$S_NAME + 7) /* 80 plus room for version #. */
# define MAXFULLSPEC NAM$C_MAXRSS /* Maximum full spec */
#else
# define MAXNAMLEN 15 /* Maximum filename length. */
#endif /* VMS */
/* Data from readdir (). */
struct direct {
long d_ino; /* Inode number of entry. */
unsigned short d_reclen; /* Length of this record. */
unsigned short d_namlen; /* Length of string in d_name. */
char d_name[MAXNAMLEN + 1]; /* Name of file. */
};
/* Stream data from opendir (). */
typedef struct {
int dd_fd; /* File descriptor. */
int dd_loc; /* Offset in block. */
int dd_size; /* Amount of valid data. */
char dd_buf[DIRBLKSIZ]; /* Directory block. */
} DIR;
extern DIR *opendir ();
extern struct direct *readdir ();
extern long telldir ();
extern void seekdir (), closedir ();
#define rewinddir(dirp) seekdir (dirp, 0L)

981
lib/glob/sm_loop.c Normal file
View file

@ -0,0 +1,981 @@
/* Copyright (C) 1991-2021 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/>.
*/
extern int interrupt_state, terminating_signal;
struct STRUCT
{
CHAR *pattern;
CHAR *string;
};
int FCT PARAMS((CHAR *, CHAR *, int));
static int GMATCH PARAMS((CHAR *, CHAR *, CHAR *, CHAR *, struct STRUCT *, int));
static CHAR *PARSE_COLLSYM PARAMS((CHAR *, INT *));
static CHAR *BRACKMATCH PARAMS((CHAR *, U_CHAR, int));
static int EXTMATCH PARAMS((INT, CHAR *, CHAR *, CHAR *, CHAR *, int));
extern void DEQUOTE_PATHNAME PARAMS((CHAR *));
/*static*/ CHAR *PATSCAN PARAMS((CHAR *, CHAR *, INT));
int
FCT (pattern, string, flags)
CHAR *pattern;
CHAR *string;
int flags;
{
CHAR *se, *pe;
if (string == 0 || pattern == 0)
return FNM_NOMATCH;
se = string + STRLEN ((XCHAR *)string);
pe = pattern + STRLEN ((XCHAR *)pattern);
return (GMATCH (string, se, pattern, pe, (struct STRUCT *)NULL, flags));
}
/* Match STRING against the filename pattern PATTERN, returning zero if
it matches, FNM_NOMATCH if not. */
static int
GMATCH (string, se, pattern, pe, ends, flags)
CHAR *string, *se;
CHAR *pattern, *pe;
struct STRUCT *ends;
int flags;
{
CHAR *p, *n; /* pattern, string */
INT c; /* current pattern character - XXX U_CHAR? */
INT sc; /* current string character - XXX U_CHAR? */
p = pattern;
n = string;
if (string == 0 || pattern == 0)
return FNM_NOMATCH;
#if DEBUG_MATCHING
fprintf(stderr, "gmatch: string = %s; se = %s\n", string, se);
fprintf(stderr, "gmatch: pattern = %s; pe = %s\n", pattern, pe);
#endif
while (p < pe)
{
c = *p++;
c = FOLD (c);
sc = n < se ? *n : '\0';
if (interrupt_state || terminating_signal)
return FNM_NOMATCH;
#ifdef EXTENDED_GLOB
/* EXTMATCH () will handle recursively calling GMATCH, so we can
just return what EXTMATCH() returns. */
if ((flags & FNM_EXTMATCH) && *p == L('(') &&
(c == L('+') || c == L('*') || c == L('?') || c == L('@') || c == L('!'))) /* ) */
{
int lflags;
/* If we're not matching the start of the string, we're not
concerned about the special cases for matching `.' */
lflags = (n == string) ? flags : (flags & ~(FNM_PERIOD|FNM_DOTDOT));
return (EXTMATCH (c, n, se, p, pe, lflags));
}
#endif /* EXTENDED_GLOB */
switch (c)
{
case L('?'): /* Match single character */
if (sc == '\0')
return FNM_NOMATCH;
else if ((flags & FNM_PATHNAME) && sc == L('/'))
/* If we are matching a pathname, `?' can never match a `/'. */
return FNM_NOMATCH;
else if ((flags & FNM_PERIOD) && sc == L('.') &&
(n == string || ((flags & FNM_PATHNAME) && n[-1] == L('/'))))
/* `?' cannot match a `.' if it is the first character of the
string or if it is the first character following a slash and
we are matching a pathname. */
return FNM_NOMATCH;
/* `?' cannot match `.' or `..' if it is the first character of the
string or if it is the first character following a slash and
we are matching a pathname. */
if ((flags & FNM_DOTDOT) &&
((n == string && SDOT_OR_DOTDOT(n)) ||
((flags & FNM_PATHNAME) && n[-1] == L('/') && PDOT_OR_DOTDOT(n))))
return FNM_NOMATCH;
break;
case L('\\'): /* backslash escape removes special meaning */
if (p == pe && sc == '\\' && (n+1 == se))
break;
if (p == pe)
return FNM_NOMATCH;
if ((flags & FNM_NOESCAPE) == 0)
{
c = *p++;
/* A trailing `\' cannot match. */
if (p > pe)
return FNM_NOMATCH;
c = FOLD (c);
}
if (FOLD (sc) != (U_CHAR)c)
return FNM_NOMATCH;
break;
case L('*'): /* Match zero or more characters */
/* See below for the reason for using this. It avoids backtracking
back to a previous `*'. Picked up from glibc. */
if (ends != NULL)
{
ends->pattern = p - 1;
ends->string = n;
return (0);
}
if ((flags & FNM_PERIOD) && sc == L('.') &&
(n == string || ((flags & FNM_PATHNAME) && n[-1] == L('/'))))
/* `*' cannot match a `.' if it is the first character of the
string or if it is the first character following a slash and
we are matching a pathname. */
return FNM_NOMATCH;
/* `*' cannot match `.' or `..' if it is the first character of the
string or if it is the first character following a slash and
we are matching a pathname. */
if ((flags & FNM_DOTDOT) &&
((n == string && SDOT_OR_DOTDOT(n)) ||
((flags & FNM_PATHNAME) && n[-1] == L('/') && PDOT_OR_DOTDOT(n))))
return FNM_NOMATCH;
if (p == pe)
return 0;
/* Collapse multiple consecutive `*' and `?', but make sure that
one character of the string is consumed for each `?'. */
for (c = *p++; (c == L('?') || c == L('*')); c = *p++)
{
if ((flags & FNM_PATHNAME) && sc == L('/'))
/* A slash does not match a wildcard under FNM_PATHNAME. */
return FNM_NOMATCH;
#ifdef EXTENDED_GLOB
else if ((flags & FNM_EXTMATCH) && c == L('?') && *p == L('(')) /* ) */
{
CHAR *newn;
/* We can match 0 or 1 times. If we match, return success */
if (EXTMATCH (c, n, se, p, pe, flags) == 0)
return (0);
/* We didn't match the extended glob pattern, but
that's OK, since we can match 0 or 1 occurrences.
We need to skip the glob pattern and see if we
match the rest of the string. */
newn = PATSCAN (p + 1, pe, 0);
/* If NEWN is 0, we have an ill-formed pattern. */
p = newn ? newn : pe;
}
#endif
else if (c == L('?'))
{
if (sc == L('\0'))
return FNM_NOMATCH;
/* One character of the string is consumed in matching
this ? wildcard, so *??? won't match if there are
fewer than three characters. */
n++;
sc = n < se ? *n : '\0';
}
#ifdef EXTENDED_GLOB
/* Handle ******(patlist) */
if ((flags & FNM_EXTMATCH) && c == L('*') && *p == L('(')) /*)*/
{
CHAR *newn;
/* We need to check whether or not the extended glob
pattern matches the remainder of the string.
If it does, we match the entire pattern. */
for (newn = n; newn < se; ++newn)
{
if (EXTMATCH (c, newn, se, p, pe, flags) == 0)
return (0);
}
/* We didn't match the extended glob pattern, but
that's OK, since we can match 0 or more occurrences.
We need to skip the glob pattern and see if we
match the rest of the string. */
newn = PATSCAN (p + 1, pe, 0);
/* If NEWN is 0, we have an ill-formed pattern. */
p = newn ? newn : pe;
}
#endif
if (p == pe)
break;
}
/* The wildcards are the last element of the pattern. The name
cannot match completely if we are looking for a pathname and
it contains another slash, unless FNM_LEADING_DIR is set. */
if (c == L('\0'))
{
int r = (flags & FNM_PATHNAME) == 0 ? 0 : FNM_NOMATCH;
if (flags & FNM_PATHNAME)
{
if (flags & FNM_LEADING_DIR)
r = 0;
else if (MEMCHR (n, L('/'), se - n) == NULL)
r = 0;
}
return r;
}
/* If we've hit the end of the pattern and the last character of
the pattern was handled by the loop above, we've succeeded.
Otherwise, we need to match that last character. */
if (p == pe && (c == L('?') || c == L('*')))
return (0);
/* If we've hit the end of the string and the rest of the pattern
is something that matches the empty string, we can succeed. */
#if defined (EXTENDED_GLOB)
if (n == se && ((flags & FNM_EXTMATCH) && (c == L('!') || c == L('?')) && *p == L('(')))
{
--p;
if (EXTMATCH (c, n, se, p, pe, flags) == 0)
return (c == L('!') ? FNM_NOMATCH : 0);
return (c == L('!') ? 0 : FNM_NOMATCH);
}
#endif
/* If we stop at a slash in the pattern and we are looking for a
pathname ([star]/foo), then consume enough of the string to stop
at any slash and then try to match the rest of the pattern. If
the string doesn't contain a slash, fail */
if (c == L('/') && (flags & FNM_PATHNAME))
{
while (n < se && *n != L('/'))
++n;
if (n < se && *n == L('/') && (GMATCH (n+1, se, p, pe, NULL, flags) == 0))
return 0;
return FNM_NOMATCH; /* XXX */
}
/* General case, use recursion. */
{
U_CHAR c1;
const CHAR *endp;
struct STRUCT end;
end.pattern = NULL;
endp = MEMCHR (n, (flags & FNM_PATHNAME) ? L('/') : L('\0'), se - n);
if (endp == 0)
endp = se;
c1 = ((flags & FNM_NOESCAPE) == 0 && c == L('\\')) ? *p : c;
c1 = FOLD (c1);
for (--p; n < endp; ++n)
{
/* Only call strmatch if the first character indicates a
possible match. We can check the first character if
we're not doing an extended glob match. */
if ((flags & FNM_EXTMATCH) == 0 && c != L('[') && FOLD (*n) != c1) /*]*/
continue;
/* If we're doing an extended glob match and the pattern is not
one of the extended glob patterns, we can check the first
character. */
if ((flags & FNM_EXTMATCH) && p[1] != L('(') && /*)*/
STRCHR (L("?*+@!"), *p) == 0 && c != L('[') && FOLD (*n) != c1) /*]*/
continue;
/* Otherwise, we just recurse. */
if (GMATCH (n, se, p, pe, &end, flags & ~(FNM_PERIOD|FNM_DOTDOT)) == 0)
{
if (end.pattern == NULL)
return (0);
break;
}
}
/* This is a clever idea from glibc, used to avoid backtracking
to a `*' that appears earlier in the pattern. We get away
without saving se and pe because they are always the same,
even in the recursive calls to gmatch */
if (end.pattern != NULL)
{
p = end.pattern;
n = end.string;
continue;
}
return FNM_NOMATCH;
}
case L('['):
{
if (sc == L('\0') || n == se)
return FNM_NOMATCH;
/* A character class cannot match a `.' if it is the first
character of the string or if it is the first character
following a slash and we are matching a pathname. */
if ((flags & FNM_PERIOD) && sc == L('.') &&
(n == string || ((flags & FNM_PATHNAME) && n[-1] == L('/'))))
return (FNM_NOMATCH);
/* `?' cannot match `.' or `..' if it is the first character of the
string or if it is the first character following a slash and
we are matching a pathname. */
if ((flags & FNM_DOTDOT) &&
((n == string && SDOT_OR_DOTDOT(n)) ||
((flags & FNM_PATHNAME) && n[-1] == L('/') && PDOT_OR_DOTDOT(n))))
return FNM_NOMATCH;
p = BRACKMATCH (p, sc, flags);
if (p == 0)
return FNM_NOMATCH;
}
break;
default:
if ((U_CHAR)c != FOLD (sc))
return (FNM_NOMATCH);
}
++n;
}
if (n == se)
return (0);
if ((flags & FNM_LEADING_DIR) && *n == L('/'))
/* The FNM_LEADING_DIR flag says that "foo*" matches "foobar/frobozz". */
return 0;
return (FNM_NOMATCH);
}
/* Parse a bracket expression collating symbol ([.sym.]) starting at P, find
the value of the symbol, and move P past the collating symbol expression.
The value is returned in *VP, if VP is not null. */
static CHAR *
PARSE_COLLSYM (p, vp)
CHAR *p;
INT *vp;
{
register int pc;
INT val;
p++; /* move past the `.' */
for (pc = 0; p[pc]; pc++)
if (p[pc] == L('.') && p[pc+1] == L(']'))
break;
if (p[pc] == 0)
{
if (vp)
*vp = INVALID;
return (p + pc);
}
val = COLLSYM (p, pc);
if (vp)
*vp = val;
return (p + pc + 2);
}
/* Use prototype definition here because of type promotion. */
static CHAR *
#if defined (PROTOTYPES)
BRACKMATCH (CHAR *p, U_CHAR test, int flags)
#else
BRACKMATCH (p, test, flags)
CHAR *p;
U_CHAR test;
int flags;
#endif
{
register CHAR cstart, cend, c;
register int not; /* Nonzero if the sense of the character class is inverted. */
int brcnt, forcecoll, isrange;
INT pc;
CHAR *savep;
CHAR *brchrp;
U_CHAR orig_test;
orig_test = test;
test = FOLD (orig_test);
savep = p;
/* POSIX.2 3.13.1 says that an exclamation mark (`!') shall replace the
circumflex (`^') in its role in a `nonmatching list'. A bracket
expression starting with an unquoted circumflex character produces
unspecified results. This implementation treats the two identically. */
if (not = (*p == L('!') || *p == L('^')))
++p;
c = *p++;
for (;;)
{
/* Initialize cstart and cend in case `-' is the last
character of the pattern. */
cstart = cend = c;
forcecoll = 0;
/* POSIX.2 equivalence class: [=c=]. See POSIX.2 2.8.3.2. Find
the end of the equivalence class, move the pattern pointer past
it, and check for equivalence. XXX - this handles only
single-character equivalence classes, which is wrong, or at
least incomplete. */
if (c == L('[') && *p == L('=') && p[2] == L('=') && p[3] == L(']'))
{
pc = FOLD (p[1]);
p += 4;
if (COLLEQUIV (test, pc))
{
/*[*/ /* Move past the closing `]', since the first thing we do at
the `matched:' label is back p up one. */
p++;
goto matched;
}
else
{
c = *p++;
if (c == L('\0'))
return ((test == L('[')) ? savep : (CHAR *)0); /*]*/
c = FOLD (c);
continue;
}
}
/* POSIX.2 character class expression. See POSIX.2 2.8.3.2. */
if (c == L('[') && *p == L(':'))
{
CHAR *close, *ccname;
pc = 0; /* make sure invalid char classes don't match. */
/* Find end of character class name */
for (close = p + 1; *close != '\0'; close++)
if (*close == L(':') && *(close+1) == L(']'))
break;
if (*close != L('\0'))
{
ccname = (CHAR *)malloc ((close - p) * sizeof (CHAR));
if (ccname == 0)
pc = 0;
else
{
bcopy (p + 1, ccname, (close - p - 1) * sizeof (CHAR));
*(ccname + (close - p - 1)) = L('\0');
/* As a result of a POSIX discussion, char class names are
allowed to be quoted (?) */
DEQUOTE_PATHNAME (ccname);
pc = IS_CCLASS (orig_test, (XCHAR *)ccname);
}
if (pc == -1)
{
/* CCNAME is not a valid character class in the current
locale. In addition to noting no match (pc = 0), we have
a choice about what to do with the invalid charclass.
Posix leaves the behavior unspecified, but we're going
to skip over the charclass and keep going instead of
testing ORIG_TEST against each character in the class
string. If we don't want to do that, take out the update
of P. */
pc = 0;
p = close + 2;
}
else
p = close + 2; /* move past the closing `]' */
free (ccname);
}
if (pc)
{
/*[*/ /* Move past the closing `]', since the first thing we do at
the `matched:' label is back p up one. */
p++;
goto matched;
}
else
{
/* continue the loop here, since this expression can't be
the first part of a range expression. */
c = *p++;
if (c == L('\0'))
return ((test == L('[')) ? savep : (CHAR *)0);
else if (c == L(']'))
break;
c = FOLD (c);
continue;
}
}
/* POSIX.2 collating symbols. See POSIX.2 2.8.3.2. Find the end of
the symbol name, make sure it is terminated by `.]', translate
the name to a character using the external table, and do the
comparison. */
if (c == L('[') && *p == L('.'))
{
p = PARSE_COLLSYM (p, &pc);
/* An invalid collating symbol cannot be the first point of a
range. If it is, we set cstart to one greater than `test',
so any comparisons later will fail. */
cstart = (pc == INVALID) ? test + 1 : pc;
forcecoll = 1;
}
if (!(flags & FNM_NOESCAPE) && c == L('\\'))
{
if (*p == '\0')
return (CHAR *)0;
cstart = cend = *p++;
}
cstart = cend = FOLD (cstart);
isrange = 0;
/* POSIX.2 2.8.3.1.2 says: `An expression containing a `[' that
is not preceded by a backslash and is not part of a bracket
expression produces undefined results.' This implementation
treats the `[' as just a character to be matched if there is
not a closing `]'. */
if (c == L('\0'))
return ((test == L('[')) ? savep : (CHAR *)0);
c = *p++;
c = FOLD (c);
if (c == L('\0'))
return ((test == L('[')) ? savep : (CHAR *)0);
if ((flags & FNM_PATHNAME) && c == L('/'))
/* [/] can never match when matching a pathname. */
return (CHAR *)0;
/* This introduces a range, unless the `-' is the last
character of the class. Find the end of the range
and move past it. */
if (c == L('-') && *p != L(']'))
{
cend = *p++;
if (!(flags & FNM_NOESCAPE) && cend == L('\\'))
cend = *p++;
if (cend == L('\0'))
return (CHAR *)0;
if (cend == L('[') && *p == L('.'))
{
p = PARSE_COLLSYM (p, &pc);
/* An invalid collating symbol cannot be the second part of a
range expression. If we get one, we set cend to one fewer
than the test character to make sure the range test fails. */
cend = (pc == INVALID) ? test - 1 : pc;
forcecoll = 1;
}
cend = FOLD (cend);
c = *p++;
/* POSIX.2 2.8.3.2: ``The ending range point shall collate
equal to or higher than the starting range point; otherwise
the expression shall be treated as invalid.'' Note that this
applies to only the range expression; the rest of the bracket
expression is still checked for matches. */
if (RANGECMP (cstart, cend, forcecoll) > 0)
{
if (c == L(']'))
break;
c = FOLD (c);
continue;
}
isrange = 1;
}
if (isrange == 0 && test == cstart)
goto matched;
if (isrange && RANGECMP (test, cstart, forcecoll) >= 0 && RANGECMP (test, cend, forcecoll) <= 0)
goto matched;
if (c == L(']'))
break;
}
/* No match. */
return (!not ? (CHAR *)0 : p);
matched:
/* Skip the rest of the [...] that already matched. */
c = *--p;
brcnt = 1;
brchrp = 0;
while (brcnt > 0)
{
int oc;
/* A `[' without a matching `]' is just another character to match. */
if (c == L('\0'))
return ((test == L('[')) ? savep : (CHAR *)0);
oc = c;
c = *p++;
if (c == L('[') && (*p == L('=') || *p == L(':') || *p == L('.')))
{
brcnt++;
brchrp = p++; /* skip over the char after the left bracket */
if ((c = *p) == L('\0'))
return ((test == L('[')) ? savep : (CHAR *)0);
/* If *brchrp == ':' we should check that the rest of the characters
form a valid character class name. We don't do that yet, but we
keep BRCHRP in case we want to. */
}
/* We only want to check brchrp if we set it above. */
else if (c == L(']') && brcnt > 1 && brchrp != 0 && oc == *brchrp)
{
brcnt--;
brchrp = 0; /* just in case */
}
/* Left bracket loses its special meaning inside a bracket expression.
It is only valid when followed by a `.', `=', or `:', which we check
for above. Technically the right bracket can appear in a collating
symbol, so we check for that here. Otherwise, it terminates the
bracket expression. */
else if (c == L(']') && (brchrp == 0 || *brchrp != L('.')) && brcnt >= 1)
brcnt = 0;
else if (!(flags & FNM_NOESCAPE) && c == L('\\'))
{
if (*p == '\0')
return (CHAR *)0;
/* XXX 1003.2d11 is unclear if this is right. */
++p;
}
}
return (not ? (CHAR *)0 : p);
}
#if defined (EXTENDED_GLOB)
/* ksh-like extended pattern matching:
[?*+@!](pat-list)
where pat-list is a list of one or patterns separated by `|'. Operation
is as follows:
?(patlist) match zero or one of the given patterns
*(patlist) match zero or more of the given patterns
+(patlist) match one or more of the given patterns
@(patlist) match exactly one of the given patterns
!(patlist) match anything except one of the given patterns
*/
/* Scan a pattern starting at STRING and ending at END, keeping track of
embedded () and []. If DELIM is 0, we scan until a matching `)'
because we're scanning a `patlist'. Otherwise, we scan until we see
DELIM. In all cases, we never scan past END. The return value is the
first character after the matching DELIM or NULL if the pattern is
empty or invalid. */
/*static*/ CHAR *
PATSCAN (string, end, delim)
CHAR *string, *end;
INT delim;
{
int pnest, bnest, skip;
INT cchar;
CHAR *s, c, *bfirst;
pnest = bnest = skip = 0;
cchar = 0;
bfirst = NULL;
if (string == end)
return (NULL);
for (s = string; c = *s; s++)
{
if (s >= end)
return (s);
if (skip)
{
skip = 0;
continue;
}
switch (c)
{
case L('\\'):
skip = 1;
break;
case L('\0'):
return ((CHAR *)NULL);
/* `[' is not special inside a bracket expression, but it may
introduce one of the special POSIX bracket expressions
([.SYM.], [=c=], [: ... :]) that needs special handling. */
case L('['):
if (bnest == 0)
{
bfirst = s + 1;
if (*bfirst == L('!') || *bfirst == L('^'))
bfirst++;
bnest++;
}
else if (s[1] == L(':') || s[1] == L('.') || s[1] == L('='))
cchar = s[1];
break;
/* `]' is not special if it's the first char (after a leading `!'
or `^') in a bracket expression or if it's part of one of the
special POSIX bracket expressions ([.SYM.], [=c=], [: ... :]) */
case L(']'):
if (bnest)
{
if (cchar && s[-1] == cchar)
cchar = 0;
else if (s != bfirst)
{
bnest--;
bfirst = 0;
}
}
break;
case L('('):
if (bnest == 0)
pnest++;
break;
case L(')'):
if (bnest == 0 && pnest-- <= 0)
return ++s;
break;
case L('|'):
if (bnest == 0 && pnest == 0 && delim == L('|'))
return ++s;
break;
}
}
return (NULL);
}
/* Return 0 if dequoted pattern matches S in the current locale. */
static int
STRCOMPARE (p, pe, s, se)
CHAR *p, *pe, *s, *se;
{
int ret;
CHAR c1, c2;
int l1, l2;
l1 = pe - p;
l2 = se - s;
if (l1 != l2)
return (FNM_NOMATCH); /* unequal lengths, can't be identical */
c1 = *pe;
c2 = *se;
if (c1 != 0)
*pe = '\0';
if (c2 != 0)
*se = '\0';
#if HAVE_MULTIBYTE || defined (HAVE_STRCOLL)
ret = STRCOLL ((XCHAR *)p, (XCHAR *)s);
#else
ret = STRCMP ((XCHAR *)p, (XCHAR *)s);
#endif
if (c1 != 0)
*pe = c1;
if (c2 != 0)
*se = c2;
return (ret == 0 ? ret : FNM_NOMATCH);
}
/* Match a ksh extended pattern specifier. Return FNM_NOMATCH on failure or
0 on success. This is handed the entire rest of the pattern and string
the first time an extended pattern specifier is encountered, so it calls
gmatch recursively. */
static int
EXTMATCH (xc, s, se, p, pe, flags)
INT xc; /* select which operation */
CHAR *s, *se;
CHAR *p, *pe;
int flags;
{
CHAR *prest; /* pointer to rest of pattern */
CHAR *psub; /* pointer to sub-pattern */
CHAR *pnext; /* pointer to next sub-pattern */
CHAR *srest; /* pointer to rest of string */
int m1, m2, xflags; /* xflags = flags passed to recursive matches */
#if DEBUG_MATCHING
fprintf(stderr, "extmatch: xc = %c\n", xc);
fprintf(stderr, "extmatch: s = %s; se = %s\n", s, se);
fprintf(stderr, "extmatch: p = %s; pe = %s\n", p, pe);
fprintf(stderr, "extmatch: flags = %d\n", flags);
#endif
prest = PATSCAN (p + (*p == L('(')), pe, 0); /* ) */
if (prest == 0)
/* If PREST is 0, we failed to scan a valid pattern. In this
case, we just want to compare the two as strings. */
return (STRCOMPARE (p - 1, pe, s, se));
switch (xc)
{
case L('+'): /* match one or more occurrences */
case L('*'): /* match zero or more occurrences */
/* If we can get away with no matches, don't even bother. Just
call GMATCH on the rest of the pattern and return success if
it succeeds. */
if (xc == L('*') && (GMATCH (s, se, prest, pe, NULL, flags) == 0))
return 0;
/* OK, we have to do this the hard way. First, we make sure one of
the subpatterns matches, then we try to match the rest of the
string. */
for (psub = p + 1; ; psub = pnext)
{
pnext = PATSCAN (psub, pe, L('|'));
for (srest = s; srest <= se; srest++)
{
/* Match this substring (S -> SREST) against this
subpattern (psub -> pnext - 1) */
m1 = GMATCH (s, srest, psub, pnext - 1, NULL, flags) == 0;
/* OK, we matched a subpattern, so make sure the rest of the
string matches the rest of the pattern. Also handle
multiple matches of the pattern. */
if (m1)
{
/* if srest > s, we are not at start of string */
xflags = (srest > s) ? (flags & ~(FNM_PERIOD|FNM_DOTDOT)) : flags;
m2 = (GMATCH (srest, se, prest, pe, NULL, xflags) == 0) ||
(s != srest && GMATCH (srest, se, p - 1, pe, NULL, xflags) == 0);
}
if (m1 && m2)
return (0);
}
if (pnext == prest)
break;
}
return (FNM_NOMATCH);
case L('?'): /* match zero or one of the patterns */
case L('@'): /* match one (or more) of the patterns */
/* If we can get away with no matches, don't even bother. Just
call gmatch on the rest of the pattern and return success if
it succeeds. */
if (xc == L('?') && (GMATCH (s, se, prest, pe, NULL, flags) == 0))
return 0;
/* OK, we have to do this the hard way. First, we see if one of
the subpatterns matches, then, if it does, we try to match the
rest of the string. */
for (psub = p + 1; ; psub = pnext)
{
pnext = PATSCAN (psub, pe, L('|'));
srest = (prest == pe) ? se : s;
for ( ; srest <= se; srest++)
{
/* if srest > s, we are not at start of string */
xflags = (srest > s) ? (flags & ~(FNM_PERIOD|FNM_DOTDOT)) : flags;
if (GMATCH (s, srest, psub, pnext - 1, NULL, flags) == 0 &&
GMATCH (srest, se, prest, pe, NULL, xflags) == 0)
return (0);
}
if (pnext == prest)
break;
}
return (FNM_NOMATCH);
case '!': /* match anything *except* one of the patterns */
for (srest = s; srest <= se; srest++)
{
m1 = 0;
for (psub = p + 1; ; psub = pnext)
{
pnext = PATSCAN (psub, pe, L('|'));
/* If one of the patterns matches, just bail immediately. */
if (m1 = (GMATCH (s, srest, psub, pnext - 1, NULL, flags) == 0))
break;
if (pnext == prest)
break;
}
/* If nothing matched, but the string starts with a period and we
need to match periods explicitly, don't return this as a match,
even for negation. */
if (m1 == 0 && (flags & FNM_PERIOD) && *s == '.')
return (FNM_NOMATCH);
if (m1 == 0 && (flags & FNM_DOTDOT) &&
(SDOT_OR_DOTDOT (s) ||
((flags & FNM_PATHNAME) && s[-1] == L('/') && PDOT_OR_DOTDOT(s))))
return (FNM_NOMATCH);
/* if srest > s, we are not at start of string */
xflags = (srest > s) ? (flags & ~(FNM_PERIOD|FNM_DOTDOT)) : flags;
if (m1 == 0 && GMATCH (srest, se, prest, pe, NULL, xflags) == 0)
return (0);
}
return (FNM_NOMATCH);
}
return (FNM_NOMATCH);
}
#endif /* EXTENDED_GLOB */
#undef IS_CCLASS
#undef FOLD
#undef CHAR
#undef U_CHAR
#undef XCHAR
#undef INT
#undef INVALID
#undef FCT
#undef GMATCH
#undef COLLSYM
#undef PARSE_COLLSYM
#undef PATSCAN
#undef STRCOMPARE
#undef EXTMATCH
#undef DEQUOTE_PATHNAME
#undef STRUCT
#undef BRACKMATCH
#undef STRCHR
#undef STRCOLL
#undef STRLEN
#undef STRCMP
#undef MEMCHR
#undef COLLEQUIV
#undef RANGECMP
#undef ISDIRSEP
#undef PATHSEP
#undef PDOT_OR_DOTDOT
#undef SDOT_OR_DOTDOT
#undef L

638
lib/glob/smatch.c Normal file
View file

@ -0,0 +1,638 @@
/* strmatch.c -- ksh-like extended pattern matching for the shell and filename
globbing. */
/* Copyright (C) 1991-2021 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/>.
*/
#include <config.h>
#include <stdio.h> /* for debugging */
#include "strmatch.h"
#include <chartypes.h>
#include "bashansi.h"
#include "shmbutil.h"
#include "xmalloc.h"
#include <errno.h>
#if !defined (errno)
extern int errno;
#endif
#if FNMATCH_EQUIV_FALLBACK
/* We don't include <fnmatch.h> in order to avoid namespace collisions; the
internal strmatch still uses the FNM_ constants. */
extern int fnmatch (const char *, const char *, int);
#endif
/* First, compile `sm_loop.c' for single-byte characters. */
#define CHAR unsigned char
#define U_CHAR unsigned char
#define XCHAR char
#define INT int
#define L(CS) CS
#define INVALID -1
#undef STREQ
#undef STREQN
#define STREQ(a, b) ((a)[0] == (b)[0] && strcmp(a, b) == 0)
#define STREQN(a, b, n) ((a)[0] == (b)[0] && strncmp(a, b, n) == 0)
#ifndef GLOBASCII_DEFAULT
# define GLOBASCII_DEFAULT 0
#endif
int glob_asciirange = GLOBASCII_DEFAULT;
#if FNMATCH_EQUIV_FALLBACK
/* Construct a string w1 = "c1" and a pattern w2 = "[[=c2=]]" and pass them
to fnmatch to see if wide characters c1 and c2 collate as members of the
same equivalence class. We can't really do this portably any other way */
static int
_fnmatch_fallback (s, p)
int s, p; /* string char, patchar */
{
char s1[2]; /* string */
char s2[8]; /* constructed pattern */
s1[0] = (unsigned char)s;
s1[1] = '\0';
/* reconstruct the pattern */
s2[0] = s2[1] = '[';
s2[2] = '=';
s2[3] = (unsigned char)p;
s2[4] = '=';
s2[5] = s2[6] = ']';
s2[7] = '\0';
return (fnmatch ((const char *)s2, (const char *)s1, 0));
}
#endif
/* We use strcoll(3) for range comparisons in bracket expressions,
even though it can have unwanted side effects in locales
other than POSIX or US. For instance, in the de locale, [A-Z] matches
all characters. If GLOB_ASCIIRANGE is non-zero, and we're not forcing
the use of strcoll (e.g., for explicit collating symbols), we use
straight ordering as if in the C locale. */
#if defined (HAVE_STRCOLL)
/* Helper functions for collating symbol equivalence. */
/* Return 0 if C1 == C2 or collates equally if FORCECOLL is non-zero. */
static int
charcmp (c1, c2, forcecoll)
int c1, c2;
int forcecoll;
{
static char s1[2] = { ' ', '\0' };
static char s2[2] = { ' ', '\0' };
int ret;
/* Eight bits only. Period. */
c1 &= 0xFF;
c2 &= 0xFF;
if (c1 == c2)
return (0);
if (forcecoll == 0 && glob_asciirange)
return (c1 - c2);
s1[0] = c1;
s2[0] = c2;
return (strcoll (s1, s2));
}
static int
rangecmp (c1, c2, forcecoll)
int c1, c2;
int forcecoll;
{
int r;
r = charcmp (c1, c2, forcecoll);
/* We impose a total ordering here by returning c1-c2 if charcmp returns 0 */
if (r != 0)
return r;
return (c1 - c2); /* impose total ordering */
}
#else /* !HAVE_STRCOLL */
# define rangecmp(c1, c2, f) ((int)(c1) - (int)(c2))
#endif /* !HAVE_STRCOLL */
#if defined (HAVE_STRCOLL)
/* Returns 1 if chars C and EQUIV collate equally in the current locale. */
static int
collequiv (c, equiv)
int c, equiv;
{
if (charcmp (c, equiv, 1) == 0)
return 1;
#if FNMATCH_EQUIV_FALLBACK
return (_fnmatch_fallback (c, equiv) == 0);
#else
return 0;
#endif
}
#else
# define collequiv(c, equiv) ((c) == (equiv))
#endif
#define _COLLSYM _collsym
#define __COLLSYM __collsym
#define POSIXCOLL posix_collsyms
#include "collsyms.h"
static int
collsym (s, len)
CHAR *s;
int len;
{
register struct _collsym *csp;
char *x;
x = (char *)s;
for (csp = posix_collsyms; csp->name; csp++)
{
if (STREQN(csp->name, x, len) && csp->name[len] == '\0')
return (csp->code);
}
if (len == 1)
return s[0];
return INVALID;
}
/* unibyte character classification */
#if !defined (isascii) && !defined (HAVE_ISASCII)
# define isascii(c) ((unsigned int)(c) <= 0177)
#endif
enum char_class
{
CC_NO_CLASS = 0,
CC_ASCII, CC_ALNUM, CC_ALPHA, CC_BLANK, CC_CNTRL, CC_DIGIT, CC_GRAPH,
CC_LOWER, CC_PRINT, CC_PUNCT, CC_SPACE, CC_UPPER, CC_WORD, CC_XDIGIT
};
static char const *const cclass_name[] =
{
"",
"ascii", "alnum", "alpha", "blank", "cntrl", "digit", "graph",
"lower", "print", "punct", "space", "upper", "word", "xdigit"
};
#define N_CHAR_CLASS (sizeof(cclass_name) / sizeof (cclass_name[0]))
static enum char_class
is_valid_cclass (name)
const char *name;
{
enum char_class ret;
int i;
ret = CC_NO_CLASS;
for (i = 1; i < N_CHAR_CLASS; i++)
{
if (STREQ (name, cclass_name[i]))
{
ret = (enum char_class)i;
break;
}
}
return ret;
}
static int
cclass_test (c, char_class)
int c;
enum char_class char_class;
{
int result;
switch (char_class)
{
case CC_ASCII:
result = isascii (c);
break;
case CC_ALNUM:
result = ISALNUM (c);
break;
case CC_ALPHA:
result = ISALPHA (c);
break;
case CC_BLANK:
result = ISBLANK (c);
break;
case CC_CNTRL:
result = ISCNTRL (c);
break;
case CC_DIGIT:
result = ISDIGIT (c);
break;
case CC_GRAPH:
result = ISGRAPH (c);
break;
case CC_LOWER:
result = ISLOWER (c);
break;
case CC_PRINT:
result = ISPRINT (c);
break;
case CC_PUNCT:
result = ISPUNCT (c);
break;
case CC_SPACE:
result = ISSPACE (c);
break;
case CC_UPPER:
result = ISUPPER (c);
break;
case CC_WORD:
result = (ISALNUM (c) || c == '_');
break;
case CC_XDIGIT:
result = ISXDIGIT (c);
break;
default:
result = -1;
break;
}
return result;
}
static int
is_cclass (c, name)
int c;
const char *name;
{
enum char_class char_class;
int result;
char_class = is_valid_cclass (name);
if (char_class == CC_NO_CLASS)
return -1;
result = cclass_test (c, char_class);
return (result);
}
/* Now include `sm_loop.c' for single-byte characters. */
/* The result of FOLD is an `unsigned char' */
# define FOLD(c) ((flags & FNM_CASEFOLD) \
? TOLOWER ((unsigned char)c) \
: ((unsigned char)c))
#if !defined (__CYGWIN__)
# define ISDIRSEP(c) ((c) == '/')
#else
# define ISDIRSEP(c) ((c) == '/' || (c) == '\\')
#endif /* __CYGWIN__ */
#define PATHSEP(c) (ISDIRSEP(c) || (c) == 0)
# define PDOT_OR_DOTDOT(s) (s[0] == '.' && (PATHSEP (s[1]) || (s[1] == '.' && PATHSEP (s[2]))))
# define SDOT_OR_DOTDOT(s) (s[0] == '.' && (s[1] == 0 || (s[1] == '.' && s[2] == 0)))
#define FCT internal_strmatch
#define GMATCH gmatch
#define COLLSYM collsym
#define PARSE_COLLSYM parse_collsym
#define BRACKMATCH brackmatch
#define PATSCAN glob_patscan
#define STRCOMPARE strcompare
#define EXTMATCH extmatch
#define DEQUOTE_PATHNAME udequote_pathname
#define STRUCT smat_struct
#define STRCHR(S, C) strchr((S), (C))
#define MEMCHR(S, C, N) memchr((S), (C), (N))
#define STRCOLL(S1, S2) strcoll((S1), (S2))
#define STRLEN(S) strlen(S)
#define STRCMP(S1, S2) strcmp((S1), (S2))
#define RANGECMP(C1, C2, F) rangecmp((C1), (C2), (F))
#define COLLEQUIV(C1, C2) collequiv((C1), (C2))
#define CTYPE_T enum char_class
#define IS_CCLASS(C, S) is_cclass((C), (S))
#include "sm_loop.c"
#if HANDLE_MULTIBYTE
# define CHAR wchar_t
# define U_CHAR wint_t
# define XCHAR wchar_t
# define INT wint_t
# define L(CS) L##CS
# define INVALID WEOF
# undef STREQ
# undef STREQN
# define STREQ(s1, s2) ((wcscmp (s1, s2) == 0))
# define STREQN(a, b, n) ((a)[0] == (b)[0] && wcsncmp(a, b, n) == 0)
extern char *mbsmbchar PARAMS((const char *));
#if FNMATCH_EQUIV_FALLBACK
/* Construct a string w1 = "c1" and a pattern w2 = "[[=c2=]]" and pass them
to fnmatch to see if wide characters c1 and c2 collate as members of the
same equivalence class. We can't really do this portably any other way */
static int
_fnmatch_fallback_wc (c1, c2)
wchar_t c1, c2; /* string char, patchar */
{
char w1[MB_LEN_MAX+1]; /* string */
char w2[MB_LEN_MAX+8]; /* constructed pattern */
int l1, l2;
l1 = wctomb (w1, c1);
if (l1 == -1)
return (2);
w1[l1] = '\0';
/* reconstruct the pattern */
w2[0] = w2[1] = '[';
w2[2] = '=';
l2 = wctomb (w2+3, c2);
if (l2 == -1)
return (2);
w2[l2+3] = '=';
w2[l2+4] = w2[l2+5] = ']';
w2[l2+6] = '\0';
return (fnmatch ((const char *)w2, (const char *)w1, 0));
}
#endif
static int
charcmp_wc (c1, c2, forcecoll)
wint_t c1, c2;
int forcecoll;
{
static wchar_t s1[2] = { L' ', L'\0' };
static wchar_t s2[2] = { L' ', L'\0' };
int r;
if (c1 == c2)
return 0;
if (forcecoll == 0 && glob_asciirange && c1 <= UCHAR_MAX && c2 <= UCHAR_MAX)
return ((int)(c1 - c2));
s1[0] = c1;
s2[0] = c2;
return (wcscoll (s1, s2));
}
static int
rangecmp_wc (c1, c2, forcecoll)
wint_t c1, c2;
int forcecoll;
{
int r;
r = charcmp_wc (c1, c2, forcecoll);
/* We impose a total ordering here by returning c1-c2 if charcmp returns 0,
as we do above in the single-byte case. */
if (r != 0 || forcecoll)
return r;
return ((int)(c1 - c2)); /* impose total ordering */
}
/* Returns 1 if wide chars C and EQUIV collate equally in the current locale. */
static int
collequiv_wc (c, equiv)
wint_t c, equiv;
{
wchar_t s, p;
if (charcmp_wc (c, equiv, 1) == 0)
return 1;
#if FNMATCH_EQUIV_FALLBACK
/* We check explicitly for success (fnmatch returns 0) to avoid problems if
our local definition of FNM_NOMATCH (strmatch.h) doesn't match the
system's (fnmatch.h). We don't care about error return values here. */
s = c;
p = equiv;
return (_fnmatch_fallback_wc (s, p) == 0);
#else
return 0;
#endif
}
/* Helper function for collating symbol. */
# define _COLLSYM _collwcsym
# define __COLLSYM __collwcsym
# define POSIXCOLL posix_collwcsyms
# include "collsyms.h"
static wint_t
collwcsym (s, len)
wchar_t *s;
int len;
{
register struct _collwcsym *csp;
for (csp = posix_collwcsyms; csp->name; csp++)
{
if (STREQN(csp->name, s, len) && csp->name[len] == L'\0')
return (csp->code);
}
if (len == 1)
return s[0];
return INVALID;
}
static int
is_wcclass (wc, name)
wint_t wc;
wchar_t *name;
{
char *mbs;
mbstate_t state;
size_t mbslength;
wctype_t desc;
int want_word;
if ((wctype ("ascii") == (wctype_t)0) && (wcscmp (name, L"ascii") == 0))
{
int c;
if ((c = wctob (wc)) == EOF)
return 0;
else
return (c <= 0x7F);
}
want_word = (wcscmp (name, L"word") == 0);
if (want_word)
name = L"alnum";
memset (&state, '\0', sizeof (mbstate_t));
mbs = (char *) malloc (wcslen(name) * MB_CUR_MAX + 1);
if (mbs == 0)
return -1;
mbslength = wcsrtombs (mbs, (const wchar_t **)&name, (wcslen(name) * MB_CUR_MAX + 1), &state);
if (mbslength == (size_t)-1 || mbslength == (size_t)-2)
{
free (mbs);
return -1;
}
desc = wctype (mbs);
free (mbs);
if (desc == (wctype_t)0)
return -1;
if (want_word)
return (iswctype (wc, desc) || wc == L'_');
else
return (iswctype (wc, desc));
}
/* Return 1 if there are no char class [:class:] expressions (degenerate case)
or only posix-specified (C locale supported) char class expressions in
PATTERN. These are the ones where it's safe to punt to the single-byte
code, since wide character support allows locale-defined char classes.
This only uses single-byte code, but is only needed to support multibyte
locales. */
static int
posix_cclass_only (pattern)
char *pattern;
{
char *p, *p1;
char cc[16]; /* sufficient for all valid posix char class names */
enum char_class valid;
p = pattern;
while (p = strchr (p, '['))
{
if (p[1] != ':')
{
p++;
continue;
}
p += 2; /* skip past "[:" */
/* Find end of char class expression */
for (p1 = p; *p1; p1++)
if (*p1 == ':' && p1[1] == ']')
break;
if (*p1 == 0) /* no char class expression found */
break;
/* Find char class name and validate it against posix char classes */
if ((p1 - p) >= sizeof (cc))
return 0;
bcopy (p, cc, p1 - p);
cc[p1 - p] = '\0';
valid = is_valid_cclass (cc);
if (valid == CC_NO_CLASS)
return 0; /* found unrecognized char class name */
p = p1 + 2; /* found posix char class name */
}
return 1; /* no char class names or only posix */
}
/* Now include `sm_loop.c' for multibyte characters. */
#define FOLD(c) ((flags & FNM_CASEFOLD) && iswupper (c) ? towlower (c) : (c))
# if !defined (__CYGWIN__)
# define ISDIRSEP(c) ((c) == L'/')
# else
# define ISDIRSEP(c) ((c) == L'/' || (c) == L'\\')
# endif /* __CYGWIN__ */
# define PATHSEP(c) (ISDIRSEP(c) || (c) == L'\0')
# define PDOT_OR_DOTDOT(w) (w[0] == L'.' && (PATHSEP(w[1]) || (w[1] == L'.' && PATHSEP(w[2]))))
# define SDOT_OR_DOTDOT(w) (w[0] == L'.' && (w[1] == L'\0' || (w[1] == L'.' && w[2] == L'\0')))
#define FCT internal_wstrmatch
#define GMATCH gmatch_wc
#define COLLSYM collwcsym
#define PARSE_COLLSYM parse_collwcsym
#define BRACKMATCH brackmatch_wc
#define PATSCAN glob_patscan_wc
#define STRCOMPARE wscompare
#define EXTMATCH extmatch_wc
#define DEQUOTE_PATHNAME wcdequote_pathname
#define STRUCT wcsmat_struct
#define STRCHR(S, C) wcschr((S), (C))
#define MEMCHR(S, C, N) wmemchr((S), (C), (N))
#define STRCOLL(S1, S2) wcscoll((S1), (S2))
#define STRLEN(S) wcslen(S)
#define STRCMP(S1, S2) wcscmp((S1), (S2))
#define RANGECMP(C1, C2, F) rangecmp_wc((C1), (C2), (F))
#define COLLEQUIV(C1, C2) collequiv_wc((C1), (C2))
#define CTYPE_T enum char_class
#define IS_CCLASS(C, S) is_wcclass((C), (S))
#include "sm_loop.c"
#endif /* HAVE_MULTIBYTE */
int
xstrmatch (pattern, string, flags)
char *pattern;
char *string;
int flags;
{
#if HANDLE_MULTIBYTE
int ret;
size_t n;
wchar_t *wpattern, *wstring;
size_t plen, slen, mplen, mslen;
if (MB_CUR_MAX == 1)
return (internal_strmatch ((unsigned char *)pattern, (unsigned char *)string, flags));
if (mbsmbchar (string) == 0 && mbsmbchar (pattern) == 0 && posix_cclass_only (pattern))
return (internal_strmatch ((unsigned char *)pattern, (unsigned char *)string, flags));
n = xdupmbstowcs (&wpattern, NULL, pattern);
if (n == (size_t)-1 || n == (size_t)-2)
return (internal_strmatch ((unsigned char *)pattern, (unsigned char *)string, flags));
n = xdupmbstowcs (&wstring, NULL, string);
if (n == (size_t)-1 || n == (size_t)-2)
{
free (wpattern);
return (internal_strmatch ((unsigned char *)pattern, (unsigned char *)string, flags));
}
ret = internal_wstrmatch (wpattern, wstring, flags);
free (wpattern);
free (wstring);
return ret;
#else
return (internal_strmatch ((unsigned char *)pattern, (unsigned char *)string, flags));
#endif /* !HANDLE_MULTIBYTE */
}

79
lib/glob/strmatch.c Normal file
View file

@ -0,0 +1,79 @@
/* strmatch.c -- ksh-like extended pattern matching for the shell and filename
globbing. */
/* Copyright (C) 1991-2020 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/>.
*/
#include <config.h>
#include "stdc.h"
#include "strmatch.h"
extern int xstrmatch PARAMS((char *, char *, int));
#if defined (HANDLE_MULTIBYTE)
extern int internal_wstrmatch PARAMS((wchar_t *, wchar_t *, int));
#endif
int
strmatch (pattern, string, flags)
char *pattern;
char *string;
int flags;
{
if (string == 0 || pattern == 0)
return FNM_NOMATCH;
return (xstrmatch (pattern, string, flags));
}
#if defined (HANDLE_MULTIBYTE)
int
wcsmatch (wpattern, wstring, flags)
wchar_t *wpattern;
wchar_t *wstring;
int flags;
{
if (wstring == 0 || wpattern == 0)
return (FNM_NOMATCH);
return (internal_wstrmatch (wpattern, wstring, flags));
}
#endif
#ifdef TEST
main (c, v)
int c;
char **v;
{
char *string, *pat;
string = v[1];
pat = v[2];
if (strmatch (pat, string, 0) == 0)
{
printf ("%s matches %s\n", string, pat);
exit (0);
}
else
{
printf ("%s does not match %s\n", string, pat);
exit (1);
}
}
#endif

65
lib/glob/strmatch.h Normal file
View file

@ -0,0 +1,65 @@
/* Copyright (C) 1991-2021 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/>.
*/
#ifndef _STRMATCH_H
#define _STRMATCH_H 1
#include <config.h>
#include "stdc.h"
/* We #undef these before defining them because some losing systems
(HP-UX A.08.07 for example) define these in <unistd.h>. */
#undef FNM_PATHNAME
#undef FNM_NOESCAPE
#undef FNM_PERIOD
/* Bits set in the FLAGS argument to `strmatch'. */
/* standard flags are like fnmatch(3). */
#define FNM_PATHNAME (1 << 0) /* No wildcard can ever match `/'. */
#define FNM_NOESCAPE (1 << 1) /* Backslashes don't quote special chars. */
#define FNM_PERIOD (1 << 2) /* Leading `.' is matched only explicitly. */
/* extended flags not available in most libc fnmatch versions, but we undef
them to avoid any possible warnings. */
#undef FNM_LEADING_DIR
#undef FNM_CASEFOLD
#undef FNM_EXTMATCH
#define FNM_LEADING_DIR (1 << 3) /* Ignore `/...' after a match. */
#define FNM_CASEFOLD (1 << 4) /* Compare without regard to case. */
#define FNM_EXTMATCH (1 << 5) /* Use ksh-like extended matching. */
#define FNM_FIRSTCHAR (1 << 6) /* Match only the first character */
#define FNM_DOTDOT (1 << 7) /* force `.' and `..' to match explicitly even if FNM_PERIOD not supplied. */
/* Value returned by `strmatch' if STRING does not match PATTERN. */
#undef FNM_NOMATCH
#define FNM_NOMATCH 1
/* Match STRING against the filename pattern PATTERN,
returning zero if it matches, FNM_NOMATCH if not. */
extern int strmatch PARAMS((char *, char *, int));
#if HANDLE_MULTIBYTE
extern int wcsmatch PARAMS((wchar_t *, wchar_t *, int));
#endif
#endif /* _STRMATCH_H */

523
lib/glob/xmbsrtowcs.c Normal file
View file

@ -0,0 +1,523 @@
/* xmbsrtowcs.c -- replacement function for mbsrtowcs */
/* Copyright (C) 2002-2020 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/>.
*/
/* Ask for GNU extensions to get extern declaration for mbsnrtowcs if
available via glibc. */
#ifndef _GNU_SOURCE
# define _GNU_SOURCE 1
#endif
#include <config.h>
#include <bashansi.h>
/* <wchar.h>, <wctype.h> and <stdlib.h> are included in "shmbutil.h".
If <wchar.h>, <wctype.h>, mbsrtowcs(), exist, HANDLE_MULTIBYTE
is defined as 1. */
#include <shmbutil.h>
#if HANDLE_MULTIBYTE
#include <errno.h>
#if !defined (errno)
extern int errno;
#endif
#define WSBUF_INC 32
#ifndef FREE
# define FREE(x) do { if (x) free (x); } while (0)
#endif
#if ! HAVE_STRCHRNUL
extern char *strchrnul PARAMS((const char *, int));
#endif
/* On some locales (ex. ja_JP.sjis), mbsrtowc doesn't convert 0x5c to U<0x5c>.
So, this function is made for converting 0x5c to U<0x5c>. */
static mbstate_t local_state;
static int local_state_use = 0;
size_t
xmbsrtowcs (dest, src, len, pstate)
wchar_t *dest;
const char **src;
size_t len;
mbstate_t *pstate;
{
mbstate_t *ps;
size_t mblength, wclength, n;
ps = pstate;
if (pstate == NULL)
{
if (!local_state_use)
{
memset (&local_state, '\0', sizeof(mbstate_t));
local_state_use = 1;
}
ps = &local_state;
}
n = strlen (*src);
if (dest == NULL)
{
wchar_t *wsbuf;
const char *mbs;
mbstate_t psbuf;
/* It doesn't matter if malloc fails here, since mbsrtowcs should do
the right thing with a NULL first argument. */
wsbuf = (wchar_t *) malloc ((n + 1) * sizeof(wchar_t));
mbs = *src;
psbuf = *ps;
wclength = mbsrtowcs (wsbuf, &mbs, n, &psbuf);
if (wsbuf)
free (wsbuf);
return wclength;
}
for (wclength = 0; wclength < len; wclength++, dest++)
{
if (mbsinit(ps))
{
if (**src == '\0')
{
*dest = L'\0';
*src = NULL;
return (wclength);
}
else if (**src == '\\')
{
*dest = L'\\';
mblength = 1;
}
else
mblength = mbrtowc(dest, *src, n, ps);
}
else
mblength = mbrtowc(dest, *src, n, ps);
/* Cannot convert multibyte character to wide character. */
if (mblength == (size_t)-1 || mblength == (size_t)-2)
return (size_t)-1;
*src += mblength;
n -= mblength;
/* The multibyte string has been completely converted,
including the terminating '\0'. */
if (*dest == L'\0')
{
*src = NULL;
break;
}
}
return (wclength);
}
#if HAVE_MBSNRTOWCS
/* Convert a multibyte string to a wide character string. Memory for the
new wide character string is obtained with malloc.
Fast multiple-character version of xdupmbstowcs used when the indices are
not required and mbsnrtowcs is available. */
static size_t
xdupmbstowcs2 (destp, src)
wchar_t **destp; /* Store the pointer to the wide character string */
const char *src; /* Multibyte character string */
{
const char *p; /* Conversion start position of src */
wchar_t *wsbuf; /* Buffer for wide characters. */
size_t wsbuf_size; /* Size of WSBUF */
size_t wcnum; /* Number of wide characters in WSBUF */
mbstate_t state; /* Conversion State */
size_t n, wcslength; /* Number of wide characters produced by the conversion. */
const char *end_or_backslash;
size_t nms; /* Number of multibyte characters to convert at one time. */
mbstate_t tmp_state;
const char *tmp_p;
memset (&state, '\0', sizeof(mbstate_t));
wsbuf_size = 0;
wsbuf = NULL;
p = src;
wcnum = 0;
do
{
end_or_backslash = strchrnul(p, '\\');
nms = end_or_backslash - p;
if (*end_or_backslash == '\0')
nms++;
/* Compute the number of produced wide-characters. */
tmp_p = p;
tmp_state = state;
if (nms == 0 && *p == '\\') /* special initial case */
nms = wcslength = 1;
else
wcslength = mbsnrtowcs (NULL, &tmp_p, nms, 0, &tmp_state);
if (wcslength == 0)
{
tmp_p = p; /* will need below */
tmp_state = state;
wcslength = 1; /* take a single byte */
}
/* Conversion failed. */
if (wcslength == (size_t)-1)
{
free (wsbuf);
*destp = NULL;
return (size_t)-1;
}
/* Resize the buffer if it is not large enough. */
if (wsbuf_size < wcnum+wcslength+1) /* 1 for the L'\0' or the potential L'\\' */
{
wchar_t *wstmp;
while (wsbuf_size < wcnum+wcslength+1) /* 1 for the L'\0' or the potential L'\\' */
wsbuf_size += WSBUF_INC;
wstmp = (wchar_t *) realloc (wsbuf, wsbuf_size * sizeof (wchar_t));
if (wstmp == NULL)
{
free (wsbuf);
*destp = NULL;
return (size_t)-1;
}
wsbuf = wstmp;
}
/* Perform the conversion. This is assumed to return 'wcslength'.
It may set 'p' to NULL. */
n = mbsnrtowcs(wsbuf+wcnum, &p, nms, wsbuf_size-wcnum, &state);
if (n == 0 && p == 0)
{
wsbuf[wcnum] = L'\0';
break;
}
/* Compensate for taking single byte on wcs conversion failure above. */
if (wcslength == 1 && (n == 0 || n == (size_t)-1))
{
state = tmp_state;
p = tmp_p;
wsbuf[wcnum] = *p;
if (*p == 0)
break;
else
{
wcnum++; p++;
}
}
else
wcnum += wcslength;
if (mbsinit (&state) && (p != NULL) && (*p == '\\'))
{
wsbuf[wcnum++] = L'\\';
p++;
}
}
while (p != NULL);
*destp = wsbuf;
/* Return the length of the wide character string, not including `\0'. */
return wcnum;
}
#endif /* HAVE_MBSNRTOWCS */
/* Convert a multibyte string to a wide character string. Memory for the
new wide character string is obtained with malloc.
The return value is the length of the wide character string. Returns a
pointer to the wide character string in DESTP. If INDICESP is not NULL,
INDICESP stores the pointer to the pointer array. Each pointer is to
the first byte of each multibyte character. Memory for the pointer array
is obtained with malloc, too.
If conversion is failed, the return value is (size_t)-1 and the values
of DESTP and INDICESP are NULL. */
size_t
xdupmbstowcs (destp, indicesp, src)
wchar_t **destp; /* Store the pointer to the wide character string */
char ***indicesp; /* Store the pointer to the pointer array. */
const char *src; /* Multibyte character string */
{
const char *p; /* Conversion start position of src */
wchar_t wc; /* Created wide character by conversion */
wchar_t *wsbuf; /* Buffer for wide characters. */
char **indices; /* Buffer for indices. */
size_t wsbuf_size; /* Size of WSBUF */
size_t wcnum; /* Number of wide characters in WSBUF */
mbstate_t state; /* Conversion State */
/* In case SRC or DESP is NULL, conversion doesn't take place. */
if (src == NULL || destp == NULL)
{
if (destp)
*destp = NULL;
if (indicesp)
*indicesp = NULL;
return (size_t)-1;
}
#if HAVE_MBSNRTOWCS
if (indicesp == NULL)
return (xdupmbstowcs2 (destp, src));
#endif
memset (&state, '\0', sizeof(mbstate_t));
wsbuf_size = WSBUF_INC;
wsbuf = (wchar_t *) malloc (wsbuf_size * sizeof(wchar_t));
if (wsbuf == NULL)
{
*destp = NULL;
if (indicesp)
*indicesp = NULL;
return (size_t)-1;
}
indices = NULL;
if (indicesp)
{
indices = (char **) malloc (wsbuf_size * sizeof(char *));
if (indices == NULL)
{
free (wsbuf);
*destp = NULL;
*indicesp = NULL;
return (size_t)-1;
}
}
p = src;
wcnum = 0;
do
{
size_t mblength; /* Byte length of one multibyte character. */
if (mbsinit (&state))
{
if (*p == '\0')
{
wc = L'\0';
mblength = 1;
}
else if (*p == '\\')
{
wc = L'\\';
mblength = 1;
}
else
mblength = mbrtowc(&wc, p, MB_LEN_MAX, &state);
}
else
mblength = mbrtowc(&wc, p, MB_LEN_MAX, &state);
/* Conversion failed. */
if (MB_INVALIDCH (mblength))
{
free (wsbuf);
FREE (indices);
*destp = NULL;
if (indicesp)
*indicesp = NULL;
return (size_t)-1;
}
++wcnum;
/* Resize buffers when they are not large enough. */
if (wsbuf_size < wcnum)
{
wchar_t *wstmp;
char **idxtmp;
wsbuf_size += WSBUF_INC;
wstmp = (wchar_t *) realloc (wsbuf, wsbuf_size * sizeof (wchar_t));
if (wstmp == NULL)
{
free (wsbuf);
FREE (indices);
*destp = NULL;
if (indicesp)
*indicesp = NULL;
return (size_t)-1;
}
wsbuf = wstmp;
if (indicesp)
{
idxtmp = (char **) realloc (indices, wsbuf_size * sizeof (char *));
if (idxtmp == NULL)
{
free (wsbuf);
free (indices);
*destp = NULL;
if (indicesp)
*indicesp = NULL;
return (size_t)-1;
}
indices = idxtmp;
}
}
wsbuf[wcnum - 1] = wc;
if (indices)
indices[wcnum - 1] = (char *)p;
p += mblength;
}
while (MB_NULLWCH (wc) == 0);
/* Return the length of the wide character string, not including `\0'. */
*destp = wsbuf;
if (indicesp != NULL)
*indicesp = indices;
return (wcnum - 1);
}
/* Convert wide character string to multibyte character string. Treat invalid
wide characters as bytes. Used only in unusual circumstances.
Written by Bruno Haible <bruno@clisp.org>, 2008, adapted by Chet Ramey
for use in Bash. */
/* Convert wide character string *SRCP to a multibyte character string and
store the result in DEST. Store at most LEN bytes in DEST. */
size_t
xwcsrtombs (char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps)
{
const wchar_t *src;
size_t cur_max; /* XXX - locale_cur_max */
char buf[64], *destptr, *tmp_dest;
unsigned char uc;
mbstate_t prev_state;
cur_max = MB_CUR_MAX;
if (cur_max > sizeof (buf)) /* Holy cow. */
return (size_t)-1;
src = *srcp;
if (dest != NULL)
{
destptr = dest;
for (; len > 0; src++)
{
wchar_t wc;
size_t ret;
wc = *src;
/* If we have room, store directly into DEST. */
tmp_dest = destptr;
ret = wcrtomb (len >= cur_max ? destptr : buf, wc, ps);
if (ret == (size_t)(-1)) /* XXX */
{
/* Since this is used for globbing and other uses of filenames,
treat invalid wide character sequences as bytes. This is
intended to be symmetric with xdupmbstowcs2. */
handle_byte:
destptr = tmp_dest; /* in case wcrtomb modified it */
uc = wc;
ret = 1;
if (len >= cur_max)
*destptr = uc;
else
buf[0] = uc;
if (ps)
memset (ps, 0, sizeof (mbstate_t));
}
if (ret > cur_max) /* Holy cow */
goto bad_input;
if (len < ret)
break;
if (len < cur_max)
memcpy (destptr, buf, ret);
if (wc == 0)
{
src = NULL;
/* Here mbsinit (ps). */
break;
}
destptr += ret;
len -= ret;
}
*srcp = src;
return destptr - dest;
}
else
{
/* Ignore dest and len, don't store *srcp at the end, and
don't clobber *ps. */
mbstate_t state = *ps;
size_t totalcount = 0;
for (;; src++)
{
wchar_t wc;
size_t ret;
wc = *src;
ret = wcrtomb (buf, wc, &state);
if (ret == (size_t)(-1))
goto bad_input2;
if (wc == 0)
{
/* Here mbsinit (&state). */
break;
}
totalcount += ret;
}
return totalcount;
}
bad_input:
*srcp = src;
bad_input2:
errno = EILSEQ;
return (size_t)(-1);
}
#endif /* HANDLE_MULTIBYTE */

4
lib/intl/ChangeLog Normal file
View file

@ -0,0 +1,4 @@
2003-05-22 GNU <bug-gnu-gettext@gnu.org>
* Version 0.12.1 released.

472
lib/intl/Makefile.in Normal file
View file

@ -0,0 +1,472 @@
# Makefile for directory with message catalog handling library of GNU gettext
# Copyright (C) 1995-1998, 2000-2003, 2008,2009 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
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
PACKAGE = @PACKAGE_NAME@
VERSION = @PACKAGE_VERSION@
SHELL = /bin/sh
srcdir = @srcdir@
top_srcdir = @top_srcdir@
top_builddir = @BUILD_DIR@
VPATH = $(srcdir)
prefix = @prefix@
exec_prefix = @exec_prefix@
transform = @program_transform_name@
datarootdir = @datarootdir@
libdir = @libdir@
includedir = @includedir@
datadir = @datadir@
localedir = @localedir@
gettextsrcdir = $(datadir)/gettext/intl
aliaspath = $(localedir)
subdir = intl
@SET_MAKE@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
MKINSTALLDIRS = @MKINSTALLDIRS@
mkinstalldirs = $(SHELL) $(MKINSTALLDIRS)
l = @INTL_LIBTOOL_SUFFIX_PREFIX@
AR = @AR@
CC = @CC@
LIBTOOL = @LIBTOOL@
RANLIB = @RANLIB@
YACC = @INTLBISON@ -y -d
YFLAGS = --name-prefix=__gettext
ARFLAGS = @ARFLAGS@
LOCAL_DEFS = @LOCAL_DEFS@
DEFS = -DLOCALEDIR=\"$(localedir)\" -DLOCALE_ALIAS_PATH=\"$(aliaspath)\" \
-DLIBDIR=\"$(prefix)/libdata\" -DIN_LIBINTL \
-DENABLE_RELOCATABLE=1 -DIN_LIBRARY -DINSTALLDIR=\"$(libdir)\" -DNO_XMALLOC \
-Dset_relocation_prefix=libintl_set_relocation_prefix \
-Drelocate=libintl_relocate \
-DDEPENDS_ON_LIBICONV=1 @DEFS@ ${LOCAL_DEFS}
CPPFLAGS = @CPPFLAGS@
CFLAGS = @CFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
COMPILE = $(CC) -c $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) $(XCFLAGS)
HEADERS = \
gmo.h \
gettextP.h \
hash-string.h \
loadinfo.h \
plural-exp.h \
eval-plural.h \
localcharset.h \
relocatable.h \
os2compat.h \
libgnuintl.h.in
SOURCES = \
bindtextdom.c \
dcgettext.c \
dgettext.c \
gettext.c \
finddomain.c \
loadmsgcat.c \
localealias.c \
textdomain.c \
l10nflist.c \
explodename.c \
dcigettext.c \
dcngettext.c \
dngettext.c \
ngettext.c \
plural.y \
plural-exp.c \
localcharset.c \
relocatable.c \
localename.c \
log.c \
osdep.c \
os2compat.c \
intl-compat.c
OBJECTS = \
bindtextdom.$lo \
dcgettext.$lo \
dgettext.$lo \
gettext.$lo \
finddomain.$lo \
loadmsgcat.$lo \
localealias.$lo \
textdomain.$lo \
l10nflist.$lo \
explodename.$lo \
dcigettext.$lo \
dcngettext.$lo \
dngettext.$lo \
ngettext.$lo \
plural.$lo \
plural-exp.$lo \
localcharset.$lo \
relocatable.$lo \
localename.$lo \
log.$lo \
osdep.$lo \
intl-compat.$lo
DISTFILES.common = Makefile.in \
config.charset locale.alias ref-add.sin ref-del.sin $(HEADERS) $(SOURCES)
DISTFILES.generated = plural.c
DISTFILES.normal = VERSION
DISTFILES.gettext = COPYING.LIB-2.0 COPYING.LIB-2.1 libintl.glibc \
Makefile.vms libgnuintl.h.msvc-shared README.woe32 Makefile.msvc
DISTFILES.obsolete = xopen-msg.sed linux-msg.sed po2tbl.sed.in cat-compat.c \
COPYING.LIB-2 gettext.h libgettext.h plural-eval.c libgnuintl.h
all: all-@USE_INCLUDED_LIBINTL@
all-yes: libintl.$la libintl.h charset.alias ref-add.sed ref-del.sed
all-no: all-no-@BUILD_INCLUDED_LIBINTL@
all-no-yes: libgnuintl.$la
all-no-no:
libintl.a libgnuintl.a: $(OBJECTS)
rm -f $@
$(AR) $(ARFLAGS) $@ $(OBJECTS)
$(RANLIB) $@
libintl.la libgnuintl.la: $(OBJECTS)
$(LIBTOOL) --mode=link \
$(CC) $(CPPFLAGS) $(CFLAGS) $(XCFLAGS) $(LDFLAGS) -o $@ \
$(OBJECTS) @LTLIBICONV@ $(LIBS) \
-version-info $(LTV_CURRENT):$(LTV_REVISION):$(LTV_AGE) \
-rpath $(libdir) \
-no-undefined
# Libtool's library version information for libintl.
# Before making a gettext release, the gettext maintainer must change this
# according to the libtool documentation, section "Library interface versions".
# Maintainers of other packages that include the intl directory must *not*
# change these values.
LTV_CURRENT=5
LTV_REVISION=0
LTV_AGE=3
.SUFFIXES:
.SUFFIXES: .c .y .o .lo .sin .sed
.c.o:
$(COMPILE) $<
.y.c:
$(YACC) $(YFLAGS) --output $@ $<
rm -f $*.h
bindtextdom.lo: $(srcdir)/bindtextdom.c
$(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/bindtextdom.c
dcgettext.lo: $(srcdir)/dcgettext.c
$(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/dcgettext.c
dgettext.lo: $(srcdir)/dgettext.c
$(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/dgettext.c
gettext.lo: $(srcdir)/gettext.c
$(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/gettext.c
finddomain.lo: $(srcdir)/finddomain.c
$(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/finddomain.c
loadmsgcat.lo: $(srcdir)/loadmsgcat.c
$(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/loadmsgcat.c
localealias.lo: $(srcdir)/localealias.c
$(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/localealias.c
textdomain.lo: $(srcdir)/textdomain.c
$(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/textdomain.c
l10nflist.lo: $(srcdir)/l10nflist.c
$(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/l10nflist.c
explodename.lo: $(srcdir)/explodename.c
$(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/explodename.c
dcigettext.lo: $(srcdir)/dcigettext.c
$(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/dcigettext.c
dcngettext.lo: $(srcdir)/dcngettext.c
$(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/dcngettext.c
dngettext.lo: $(srcdir)/dngettext.c
$(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/dngettext.c
ngettext.lo: $(srcdir)/ngettext.c
$(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/ngettext.c
plural.lo: $(srcdir)/plural.c
$(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/plural.c
plural-exp.lo: $(srcdir)/plural-exp.c
$(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/plural-exp.c
localcharset.lo: $(srcdir)/localcharset.c
$(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/localcharset.c
relocatable.lo: $(srcdir)/relocatable.c
$(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/relocatable.c
localename.lo: $(srcdir)/localename.c
$(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/localename.c
log.lo: $(srcdir)/log.c
$(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/log.c
osdep.lo: $(srcdir)/osdep.c
$(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/osdep.c
intl-compat.lo: $(srcdir)/intl-compat.c
$(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/intl-compat.c
ref-add.sed: $(srcdir)/ref-add.sin
sed -e '/^#/d' -e 's/@''PACKAGE''@/@PACKAGE@/g' $(srcdir)/ref-add.sin > t-ref-add.sed
mv t-ref-add.sed ref-add.sed
ref-del.sed: $(srcdir)/ref-del.sin
sed -e '/^#/d' -e 's/@''PACKAGE''@/@PACKAGE@/g' $(srcdir)/ref-del.sin > t-ref-del.sed
mv t-ref-del.sed ref-del.sed
INCLUDES = -I. -I$(srcdir) -I${top_builddir} -I${top_srcdir}
libgnuintl.h: $(srcdir)/libgnuintl.h.in
cp $(srcdir)/libgnuintl.h.in libgnuintl.h
libintl.h: libgnuintl.h
cmp libgnuintl.h libintl.h || cp libgnuintl.h libintl.h
charset.alias: $(srcdir)/config.charset
$(SHELL) $(srcdir)/config.charset '@host@' > t-$@
mv t-$@ $@
check: all
# We must not install the libintl.h/libintl.a files if we are on a
# system which has the GNU gettext() function in its C library or in a
# separate library.
# If you want to use the one which comes with this version of the
# package, you have to use `configure --with-included-gettext'.
install: install-exec install-data
install-exec: all
if { test "$(PACKAGE)" = "gettext-runtime" || test "$(PACKAGE)" = "gettext-tools"; } \
&& test '@USE_INCLUDED_LIBINTL@' = yes; then \
$(mkinstalldirs) $(DESTDIR)$(libdir) $(DESTDIR)$(includedir); \
$(INSTALL_DATA) libintl.h $(DESTDIR)$(includedir)/libintl.h; \
$(LIBTOOL) --mode=install \
$(INSTALL_DATA) libintl.$la $(DESTDIR)$(libdir)/libintl.$la; \
if test "@RELOCATABLE@" = yes; then \
dependencies=`sed -n -e 's,^dependency_libs=\(.*\),\1,p' < $(DESTDIR)$(libdir)/libintl.la | sed -e "s,^',," -e "s,'\$$,,"`; \
if test -n "$dependencies"; then \
rm -f $(DESTDIR)$(libdir)/libintl.la; \
fi; \
fi; \
else \
: ; \
fi
if test "$(PACKAGE)" = "gettext-tools" \
&& test '@USE_INCLUDED_LIBINTL@' = no; then \
$(mkinstalldirs) $(DESTDIR)$(libdir); \
$(LIBTOOL) --mode=install \
$(INSTALL_DATA) libgnuintl.$la $(DESTDIR)$(libdir)/libgnuintl.$la; \
rm -f $(DESTDIR)$(libdir)/preloadable_libintl.so; \
$(INSTALL_DATA) $(DESTDIR)$(libdir)/libgnuintl.so $(DESTDIR)$(libdir)/preloadable_libintl.so; \
$(LIBTOOL) --mode=uninstall \
rm -f $(DESTDIR)$(libdir)/libgnuintl.$la; \
else \
: ; \
fi
if test '@USE_INCLUDED_LIBINTL@' = yes; then \
$(mkinstalldirs) $(DESTDIR)$(localedir); \
test -f $(DESTDIR)$(localedir)/locale.alias \
&& orig=$(DESTDIR)$(localedir)/locale.alias \
|| orig=$(srcdir)/locale.alias; \
temp=$(DESTDIR)$(localedir)/t-locale.alias; \
dest=$(DESTDIR)$(localedir)/locale.alias; \
sed -f ref-add.sed $$orig > $$temp; \
$(INSTALL_DATA) $$temp $$dest; \
rm -f $$temp; \
else \
: ; \
fi
install-data: all
if test "$(PACKAGE)" = "gettext-tools"; then \
$(mkinstalldirs) $(DESTDIR)$(gettextsrcdir); \
$(INSTALL_DATA) VERSION $(DESTDIR)$(gettextsrcdir)/VERSION; \
$(INSTALL_DATA) ChangeLog.inst $(DESTDIR)$(gettextsrcdir)/ChangeLog; \
dists="COPYING.LIB-2.0 COPYING.LIB-2.1 $(DISTFILES.common)"; \
for file in $$dists; do \
$(INSTALL_DATA) $(srcdir)/$$file \
$(DESTDIR)$(gettextsrcdir)/$$file; \
done; \
chmod a+x $(DESTDIR)$(gettextsrcdir)/config.charset; \
dists="$(DISTFILES.generated)"; \
for file in $$dists; do \
if test -f $$file; then dir=.; else dir=$(srcdir); fi; \
$(INSTALL_DATA) $$dir/$$file \
$(DESTDIR)$(gettextsrcdir)/$$file; \
done; \
dists="$(DISTFILES.obsolete)"; \
for file in $$dists; do \
rm -f $(DESTDIR)$(gettextsrcdir)/$$file; \
done; \
else \
: ; \
fi
install-strip: install
installdirs:
if { test "$(PACKAGE)" = "gettext-runtime" || test "$(PACKAGE)" = "gettext-tools"; } \
&& test '@USE_INCLUDED_LIBINTL@' = yes; then \
$(mkinstalldirs) $(DESTDIR)$(libdir) $(DESTDIR)$(includedir); \
else \
: ; \
fi
if test "$(PACKAGE)" = "gettext-tools" \
&& test '@USE_INCLUDED_LIBINTL@' = no; then \
$(mkinstalldirs) $(DESTDIR)$(libdir); \
else \
: ; \
fi
if test '@USE_INCLUDED_LIBINTL@' = yes; then \
test @GLIBC21@ != no || $(mkinstalldirs) $(DESTDIR)$(libdir); \
$(mkinstalldirs) $(DESTDIR)$(localedir); \
else \
: ; \
fi
if test "$(PACKAGE)" = "gettext-tools"; then \
$(mkinstalldirs) $(DESTDIR)$(gettextsrcdir); \
else \
: ; \
fi
# Define this as empty until I found a useful application.
installcheck:
uninstall:
if { test "$(PACKAGE)" = "gettext-runtime" || test "$(PACKAGE)" = "gettext-tools"; } \
&& test '@USE_INCLUDED_LIBINTL@' = yes; then \
rm -f $(DESTDIR)$(includedir)/libintl.h; \
$(LIBTOOL) --mode=uninstall \
rm -f $(DESTDIR)$(libdir)/libintl.$la; \
else \
: ; \
fi
if test "$(PACKAGE)" = "gettext-tools" \
&& test '@USE_INCLUDED_LIBINTL@' = no; then \
rm -f $(DESTDIR)$(libdir)/preloadable_libintl.so; \
else \
: ; \
fi
if test '@USE_INCLUDED_LIBINTL@' = yes; then \
if test -f $(DESTDIR)$(prefix)/libdata/charset.alias; then \
temp=$(DESTDIR)$(prefix)/libdata/t-charset.alias; \
dest=$(DESTDIR)$(prefix)/libdata/charset.alias; \
sed -f ref-del.sed $$dest > $$temp; \
if grep '^# Packages using this file: $$' $$temp > /dev/null; then \
rm -f $$dest; \
else \
$(INSTALL_DATA) $$temp $$dest; \
fi; \
rm -f $$temp; \
fi; \
if test -f $(DESTDIR)$(localedir)/locale.alias; then \
temp=$(DESTDIR)$(localedir)/t-locale.alias; \
dest=$(DESTDIR)$(localedir)/locale.alias; \
sed -f ref-del.sed $$dest > $$temp; \
if grep '^# Packages using this file: $$' $$temp > /dev/null; then \
rm -f $$dest; \
else \
$(INSTALL_DATA) $$temp $$dest; \
fi; \
rm -f $$temp; \
fi; \
else \
: ; \
fi
if test "$(PACKAGE)" = "gettext-tools"; then \
for file in VERSION ChangeLog COPYING.LIB-2.0 COPYING.LIB-2.1 $(DISTFILES.common) $(DISTFILES.generated); do \
rm -f $(DESTDIR)$(gettextsrcdir)/$$file; \
done; \
else \
: ; \
fi
info dvi ps pdf html:
$(OBJECTS): ${top_builddir}/config.h libgnuintl.h
bindtextdom.$lo dcgettext.$lo dcigettext.$lo dcngettext.$lo dgettext.$lo dngettext.$lo finddomain.$lo gettext.$lo intl-compat.$lo loadmsgcat.$lo localealias.$lo ngettext.$lo textdomain.$lo: $(srcdir)/gettextP.h $(srcdir)/gmo.h $(srcdir)/loadinfo.h
dcigettext.$lo loadmsgcat.$lo: $(srcdir)/hash-string.h
explodename.$lo l10nflist.$lo: $(srcdir)/loadinfo.h
dcigettext.$lo loadmsgcat.$lo plural.$lo plural-exp.$lo: $(srcdir)/plural-exp.h
dcigettext.$lo: $(srcdir)/eval-plural.h
localcharset.$lo: $(srcdir)/localcharset.h
localealias.$lo localcharset.$lo relocatable.$lo: $(srcdir)/relocatable.h
tags: TAGS
TAGS: $(HEADERS) $(SOURCES)
here=`pwd`; cd $(srcdir) && etags -o $$here/TAGS $(HEADERS) $(SOURCES)
ctags: CTAGS
CTAGS: $(HEADERS) $(SOURCES)
here=`pwd`; cd $(srcdir) && ctags -o $$here/CTAGS $(HEADERS) $(SOURCES)
id: ID
ID: $(HEADERS) $(SOURCES)
here=`pwd`; cd $(srcdir) && mkid -f$$here/ID $(HEADERS) $(SOURCES)
mostlyclean:
rm -f *.a *.la *.o *.obj *.lo core core.*
rm -f libgnuintl.h libintl.h charset.alias ref-add.sed ref-del.sed
rm -f -r .libs _libs
clean: mostlyclean
distclean: clean
rm -f Makefile ID TAGS
if test "$(PACKAGE)" = "gettext-runtime" || test "$(PACKAGE)" = "gettext-tools"; then \
rm -f ChangeLog.inst $(DISTFILES.normal); \
else \
: ; \
fi
maintainer-clean: distclean
@echo "This command is intended for maintainers to use;"
@echo "it deletes files that may require special tools to rebuild."
# GNU gettext needs not contain the file `VERSION' but contains some
# other files which should not be distributed in other packages.
distdir = ../$(PACKAGE)-$(VERSION)/$(subdir)
dist distdir: Makefile
if test "$(PACKAGE)" = "gettext-tools"; then \
: ; \
else \
if test "$(PACKAGE)" = "gettext-runtime"; then \
additional="$(DISTFILES.gettext)"; \
else \
additional="$(DISTFILES.normal)"; \
fi; \
$(MAKE) $(DISTFILES.common) $(DISTFILES.generated) $$additional; \
for file in ChangeLog $(DISTFILES.common) $(DISTFILES.generated) $$additional; do \
if test -f $$file; then dir=.; else dir=$(srcdir); fi; \
cp -p $$dir/$$file $(distdir); \
done; \
fi
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
cd $(top_builddir) && $(SHELL) ./config.status
# This would be more efficient, but doesn't work any more with autoconf-2.57,
# when AC_CONFIG_FILES([intl/Makefile:somedir/Makefile.in]) is used.
# cd $(top_builddir) && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
# Tell versions [3.59,3.63) of GNU make not to export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

3
lib/intl/VERSION Normal file
View file

@ -0,0 +1,3 @@
GNU gettext library from gettext-0.12.1
This is here only in the case the system doesn't provide it

376
lib/intl/bindtextdom.c Normal file
View file

@ -0,0 +1,376 @@
/* bindtextdom.c - Implementation of the bindtextdomain(3) function */
/* Copyright (C) 1995-1998, 2000, 2001, 2002, 2005-2009 Free Software Foundation, Inc.
This file is part of GNU Bash.
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/>.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#ifdef _LIBC
# include <libintl.h>
#else
# include "libgnuintl.h"
#endif
#include "gettextP.h"
#ifdef _LIBC
/* We have to handle multi-threaded applications. */
# include <bits/libc-lock.h>
#else
/* Provide dummy implementation if this is outside glibc. */
# define __libc_rwlock_define(CLASS, NAME)
# define __libc_rwlock_wrlock(NAME)
# define __libc_rwlock_unlock(NAME)
#endif
/* The internal variables in the standalone libintl.a must have different
names than the internal variables in GNU libc, otherwise programs
using libintl.a cannot be linked statically. */
#if !defined _LIBC
# define _nl_default_dirname libintl_nl_default_dirname
# define _nl_domain_bindings libintl_nl_domain_bindings
#endif
/* Some compilers, like SunOS4 cc, don't have offsetof in <stddef.h>. */
#ifndef offsetof
# define offsetof(type,ident) ((size_t)&(((type*)0)->ident))
#endif
/* @@ end of prolog @@ */
/* Contains the default location of the message catalogs. */
extern const char _nl_default_dirname[];
#ifdef _LIBC
extern const char _nl_default_dirname_internal[] attribute_hidden;
#else
# define INTUSE(name) name
#endif
/* List with bindings of specific domains. */
extern struct binding *_nl_domain_bindings;
/* Lock variable to protect the global data in the gettext implementation. */
__libc_rwlock_define (extern, _nl_state_lock attribute_hidden)
/* Names for the libintl functions are a problem. They must not clash
with existing names and they should follow ANSI C. But this source
code is also used in GNU C Library where the names have a __
prefix. So we have to make a difference here. */
#ifdef _LIBC
# define BINDTEXTDOMAIN __bindtextdomain
# define BIND_TEXTDOMAIN_CODESET __bind_textdomain_codeset
# ifndef strdup
# define strdup(str) __strdup (str)
# endif
#else
# define BINDTEXTDOMAIN libintl_bindtextdomain
# define BIND_TEXTDOMAIN_CODESET libintl_bind_textdomain_codeset
#endif
/* Prototypes for local functions. */
static void set_binding_values PARAMS ((const char *domainname,
const char **dirnamep,
const char **codesetp));
/* Specifies the directory name *DIRNAMEP and the output codeset *CODESETP
to be used for the DOMAINNAME message catalog.
If *DIRNAMEP or *CODESETP is NULL, the corresponding attribute is not
modified, only the current value is returned.
If DIRNAMEP or CODESETP is NULL, the corresponding attribute is neither
modified nor returned. */
static void
set_binding_values (domainname, dirnamep, codesetp)
const char *domainname;
const char **dirnamep;
const char **codesetp;
{
struct binding *binding;
int modified;
/* Some sanity checks. */
if (domainname == NULL || domainname[0] == '\0')
{
if (dirnamep)
*dirnamep = NULL;
if (codesetp)
*codesetp = NULL;
return;
}
__libc_rwlock_wrlock (_nl_state_lock);
modified = 0;
for (binding = _nl_domain_bindings; binding != NULL; binding = binding->next)
{
int compare = strcmp (domainname, binding->domainname);
if (compare == 0)
/* We found it! */
break;
if (compare < 0)
{
/* It is not in the list. */
binding = NULL;
break;
}
}
if (binding != NULL)
{
if (dirnamep)
{
const char *dirname = *dirnamep;
if (dirname == NULL)
/* The current binding has be to returned. */
*dirnamep = binding->dirname;
else
{
/* The domain is already bound. If the new value and the old
one are equal we simply do nothing. Otherwise replace the
old binding. */
char *result = binding->dirname;
if (strcmp (dirname, result) != 0)
{
if (strcmp (dirname, INTUSE(_nl_default_dirname)) == 0)
result = (char *) INTUSE(_nl_default_dirname);
else
{
#if defined _LIBC || defined HAVE_STRDUP
result = strdup (dirname);
#else
size_t len = strlen (dirname) + 1;
result = (char *) malloc (len);
if (__builtin_expect (result != NULL, 1))
memcpy (result, dirname, len);
#endif
}
if (__builtin_expect (result != NULL, 1))
{
if (binding->dirname != INTUSE(_nl_default_dirname))
free (binding->dirname);
binding->dirname = result;
modified = 1;
}
}
*dirnamep = result;
}
}
if (codesetp)
{
const char *codeset = *codesetp;
if (codeset == NULL)
/* The current binding has be to returned. */
*codesetp = binding->codeset;
else
{
/* The domain is already bound. If the new value and the old
one are equal we simply do nothing. Otherwise replace the
old binding. */
char *result = binding->codeset;
if (result == NULL || strcmp (codeset, result) != 0)
{
#if defined _LIBC || defined HAVE_STRDUP
result = strdup (codeset);
#else
size_t len = strlen (codeset) + 1;
result = (char *) malloc (len);
if (__builtin_expect (result != NULL, 1))
memcpy (result, codeset, len);
#endif
if (__builtin_expect (result != NULL, 1))
{
if (binding->codeset != NULL)
free (binding->codeset);
binding->codeset = result;
binding->codeset_cntr++;
modified = 1;
}
}
*codesetp = result;
}
}
}
else if ((dirnamep == NULL || *dirnamep == NULL)
&& (codesetp == NULL || *codesetp == NULL))
{
/* Simply return the default values. */
if (dirnamep)
*dirnamep = INTUSE(_nl_default_dirname);
if (codesetp)
*codesetp = NULL;
}
else
{
/* We have to create a new binding. */
size_t len = strlen (domainname) + 1;
struct binding *new_binding =
(struct binding *) malloc (offsetof (struct binding, domainname) + len);
if (__builtin_expect (new_binding == NULL, 0))
goto failed;
memcpy (new_binding->domainname, domainname, len);
if (dirnamep)
{
const char *dirname = *dirnamep;
if (dirname == NULL)
/* The default value. */
dirname = INTUSE(_nl_default_dirname);
else
{
if (strcmp (dirname, INTUSE(_nl_default_dirname)) == 0)
dirname = INTUSE(_nl_default_dirname);
else
{
char *result;
#if defined _LIBC || defined HAVE_STRDUP
result = strdup (dirname);
if (__builtin_expect (result == NULL, 0))
goto failed_dirname;
#else
size_t len = strlen (dirname) + 1;
result = (char *) malloc (len);
if (__builtin_expect (result == NULL, 0))
goto failed_dirname;
memcpy (result, dirname, len);
#endif
dirname = result;
}
}
*dirnamep = dirname;
new_binding->dirname = (char *) dirname;
}
else
/* The default value. */
new_binding->dirname = (char *) INTUSE(_nl_default_dirname);
new_binding->codeset_cntr = 0;
if (codesetp)
{
const char *codeset = *codesetp;
if (codeset != NULL)
{
char *result;
#if defined _LIBC || defined HAVE_STRDUP
result = strdup (codeset);
if (__builtin_expect (result == NULL, 0))
goto failed_codeset;
#else
size_t len = strlen (codeset) + 1;
result = (char *) malloc (len);
if (__builtin_expect (result == NULL, 0))
goto failed_codeset;
memcpy (result, codeset, len);
#endif
codeset = result;
new_binding->codeset_cntr++;
}
*codesetp = codeset;
new_binding->codeset = (char *) codeset;
}
else
new_binding->codeset = NULL;
/* Now enqueue it. */
if (_nl_domain_bindings == NULL
|| strcmp (domainname, _nl_domain_bindings->domainname) < 0)
{
new_binding->next = _nl_domain_bindings;
_nl_domain_bindings = new_binding;
}
else
{
binding = _nl_domain_bindings;
while (binding->next != NULL
&& strcmp (domainname, binding->next->domainname) > 0)
binding = binding->next;
new_binding->next = binding->next;
binding->next = new_binding;
}
modified = 1;
/* Here we deal with memory allocation failures. */
if (0)
{
failed_codeset:
if (new_binding->dirname != INTUSE(_nl_default_dirname))
free (new_binding->dirname);
failed_dirname:
free (new_binding);
failed:
if (dirnamep)
*dirnamep = NULL;
if (codesetp)
*codesetp = NULL;
}
}
/* If we modified any binding, we flush the caches. */
if (modified)
++_nl_msg_cat_cntr;
__libc_rwlock_unlock (_nl_state_lock);
}
/* Specify that the DOMAINNAME message catalog will be found
in DIRNAME rather than in the system locale data base. */
char *
BINDTEXTDOMAIN (domainname, dirname)
const char *domainname;
const char *dirname;
{
set_binding_values (domainname, &dirname, NULL);
return (char *) dirname;
}
/* Specify the character encoding in which the messages from the
DOMAINNAME message catalog will be returned. */
char *
BIND_TEXTDOMAIN_CODESET (domainname, codeset)
const char *domainname;
const char *codeset;
{
set_binding_values (domainname, NULL, &codeset);
return (char *) codeset;
}
#ifdef _LIBC
/* Aliases for function names in GNU C Library. */
weak_alias (__bindtextdomain, bindtextdomain);
weak_alias (__bind_textdomain_codeset, bind_textdomain_codeset);
#endif

465
lib/intl/config.charset Normal file
View file

@ -0,0 +1,465 @@
#! /bin/sh
# Output a system dependent table of character encoding aliases.
#
# Copyright (C) 2000-2009 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
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
#
# The table consists of lines of the form
# ALIAS CANONICAL
#
# ALIAS is the (system dependent) result of "nl_langinfo (CODESET)".
# ALIAS is compared in a case sensitive way.
#
# CANONICAL is the GNU canonical name for this character encoding.
# It must be an encoding supported by libiconv. Support by GNU libc is
# also desirable. CANONICAL is case insensitive. Usually an upper case
# MIME charset name is preferred.
# The current list of GNU canonical charset names is as follows.
#
# name used by which systems a MIME name?
# ASCII, ANSI_X3.4-1968 glibc solaris freebsd
# ISO-8859-1 glibc aix hpux irix osf solaris freebsd yes
# ISO-8859-2 glibc aix hpux irix osf solaris freebsd yes
# ISO-8859-3 glibc solaris yes
# ISO-8859-4 osf solaris freebsd yes
# ISO-8859-5 glibc aix hpux irix osf solaris freebsd yes
# ISO-8859-6 glibc aix hpux solaris yes
# ISO-8859-7 glibc aix hpux irix osf solaris yes
# ISO-8859-8 glibc aix hpux osf solaris yes
# ISO-8859-9 glibc aix hpux irix osf solaris yes
# ISO-8859-13 glibc
# ISO-8859-14 glibc
# ISO-8859-15 glibc aix osf solaris freebsd
# KOI8-R glibc solaris freebsd yes
# KOI8-U glibc freebsd yes
# KOI8-T glibc
# CP437 dos
# CP775 dos
# CP850 aix osf dos
# CP852 dos
# CP855 dos
# CP856 aix
# CP857 dos
# CP861 dos
# CP862 dos
# CP864 dos
# CP865 dos
# CP866 freebsd dos
# CP869 dos
# CP874 woe32 dos
# CP922 aix
# CP932 aix woe32 dos
# CP943 aix
# CP949 osf woe32 dos
# CP950 woe32 dos
# CP1046 aix
# CP1124 aix
# CP1125 dos
# CP1129 aix
# CP1250 woe32
# CP1251 glibc solaris woe32
# CP1252 aix woe32
# CP1253 woe32
# CP1254 woe32
# CP1255 glibc woe32
# CP1256 woe32
# CP1257 woe32
# GB2312 glibc aix hpux irix solaris freebsd yes
# EUC-JP glibc aix hpux irix osf solaris freebsd yes
# EUC-KR glibc aix hpux irix osf solaris freebsd yes
# EUC-TW glibc aix hpux irix osf solaris
# BIG5 glibc aix hpux osf solaris freebsd yes
# BIG5-HKSCS glibc solaris
# GBK glibc aix osf solaris woe32 dos
# GB18030 glibc solaris
# SHIFT_JIS hpux osf solaris freebsd yes
# JOHAB glibc solaris woe32
# TIS-620 glibc aix hpux osf solaris
# VISCII glibc yes
# TCVN5712-1 glibc
# GEORGIAN-PS glibc
# HP-ROMAN8 hpux
# HP-ARABIC8 hpux
# HP-GREEK8 hpux
# HP-HEBREW8 hpux
# HP-TURKISH8 hpux
# HP-KANA8 hpux
# DEC-KANJI osf
# DEC-HANYU osf
# UTF-8 glibc aix hpux osf solaris yes
#
# Note: Names which are not marked as being a MIME name should not be used in
# Internet protocols for information interchange (mail, news, etc.).
#
# Note: ASCII and ANSI_X3.4-1968 are synonymous canonical names. Applications
# must understand both names and treat them as equivalent.
#
# The first argument passed to this file is the canonical host specification,
# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
# or
# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
host="$1"
os=`echo "$host" | sed -e 's/^[^-]*-[^-]*-\(.*\)$/\1/'`
echo "# This file contains a table of character encoding aliases,"
echo "# suitable for operating system '${os}'."
echo "# It was automatically generated from config.charset."
# List of references, updated during installation:
echo "# Packages using this file: "
case "$os" in
linux* | *-gnu*)
# With glibc-2.1 or newer, we don't need any canonicalization,
# because glibc has iconv and both glibc and libiconv support all
# GNU canonical names directly. Therefore, the Makefile does not
# need to install the alias file at all.
# The following applies only to glibc-2.0.x and older libcs.
echo "ISO_646.IRV:1983 ASCII"
;;
aix*)
echo "ISO8859-1 ISO-8859-1"
echo "ISO8859-2 ISO-8859-2"
echo "ISO8859-5 ISO-8859-5"
echo "ISO8859-6 ISO-8859-6"
echo "ISO8859-7 ISO-8859-7"
echo "ISO8859-8 ISO-8859-8"
echo "ISO8859-9 ISO-8859-9"
echo "ISO8859-15 ISO-8859-15"
echo "IBM-850 CP850"
echo "IBM-856 CP856"
echo "IBM-921 ISO-8859-13"
echo "IBM-922 CP922"
echo "IBM-932 CP932"
echo "IBM-943 CP943"
echo "IBM-1046 CP1046"
echo "IBM-1124 CP1124"
echo "IBM-1129 CP1129"
echo "IBM-1252 CP1252"
echo "IBM-eucCN GB2312"
echo "IBM-eucJP EUC-JP"
echo "IBM-eucKR EUC-KR"
echo "IBM-eucTW EUC-TW"
echo "big5 BIG5"
echo "GBK GBK"
echo "TIS-620 TIS-620"
echo "UTF-8 UTF-8"
;;
hpux*)
echo "iso88591 ISO-8859-1"
echo "iso88592 ISO-8859-2"
echo "iso88595 ISO-8859-5"
echo "iso88596 ISO-8859-6"
echo "iso88597 ISO-8859-7"
echo "iso88598 ISO-8859-8"
echo "iso88599 ISO-8859-9"
echo "iso885915 ISO-8859-15"
echo "roman8 HP-ROMAN8"
echo "arabic8 HP-ARABIC8"
echo "greek8 HP-GREEK8"
echo "hebrew8 HP-HEBREW8"
echo "turkish8 HP-TURKISH8"
echo "kana8 HP-KANA8"
echo "tis620 TIS-620"
echo "big5 BIG5"
echo "eucJP EUC-JP"
echo "eucKR EUC-KR"
echo "eucTW EUC-TW"
echo "hp15CN GB2312"
#echo "ccdc ?" # what is this?
echo "SJIS SHIFT_JIS"
echo "utf8 UTF-8"
;;
irix*)
echo "ISO8859-1 ISO-8859-1"
echo "ISO8859-2 ISO-8859-2"
echo "ISO8859-5 ISO-8859-5"
echo "ISO8859-7 ISO-8859-7"
echo "ISO8859-9 ISO-8859-9"
echo "eucCN GB2312"
echo "eucJP EUC-JP"
echo "eucKR EUC-KR"
echo "eucTW EUC-TW"
;;
osf*)
echo "ISO8859-1 ISO-8859-1"
echo "ISO8859-2 ISO-8859-2"
echo "ISO8859-4 ISO-8859-4"
echo "ISO8859-5 ISO-8859-5"
echo "ISO8859-7 ISO-8859-7"
echo "ISO8859-8 ISO-8859-8"
echo "ISO8859-9 ISO-8859-9"
echo "ISO8859-15 ISO-8859-15"
echo "cp850 CP850"
echo "big5 BIG5"
echo "dechanyu DEC-HANYU"
echo "dechanzi GB2312"
echo "deckanji DEC-KANJI"
echo "deckorean EUC-KR"
echo "eucJP EUC-JP"
echo "eucKR EUC-KR"
echo "eucTW EUC-TW"
echo "GBK GBK"
echo "KSC5601 CP949"
echo "sdeckanji EUC-JP"
echo "SJIS SHIFT_JIS"
echo "TACTIS TIS-620"
echo "UTF-8 UTF-8"
;;
solaris*)
echo "646 ASCII"
echo "ISO8859-1 ISO-8859-1"
echo "ISO8859-2 ISO-8859-2"
echo "ISO8859-3 ISO-8859-3"
echo "ISO8859-4 ISO-8859-4"
echo "ISO8859-5 ISO-8859-5"
echo "ISO8859-6 ISO-8859-6"
echo "ISO8859-7 ISO-8859-7"
echo "ISO8859-8 ISO-8859-8"
echo "ISO8859-9 ISO-8859-9"
echo "ISO8859-15 ISO-8859-15"
echo "koi8-r KOI8-R"
echo "ansi-1251 CP1251"
echo "BIG5 BIG5"
echo "Big5-HKSCS BIG5-HKSCS"
echo "gb2312 GB2312"
echo "GBK GBK"
echo "GB18030 GB18030"
echo "cns11643 EUC-TW"
echo "5601 EUC-KR"
echo "ko_KR.johap92 JOHAB"
echo "eucJP EUC-JP"
echo "PCK SHIFT_JIS"
echo "TIS620.2533 TIS-620"
#echo "sun_eu_greek ?" # what is this?
echo "UTF-8 UTF-8"
;;
freebsd* | os2*)
# FreeBSD 4.2 doesn't have nl_langinfo(CODESET); therefore
# localcharset.c falls back to using the full locale name
# from the environment variables.
# Likewise for OS/2. OS/2 has XFree86 just like FreeBSD. Just
# reuse FreeBSD's locale data for OS/2.
echo "C ASCII"
echo "US-ASCII ASCII"
for l in la_LN lt_LN; do
echo "$l.ASCII ASCII"
done
for l in da_DK de_AT de_CH de_DE en_AU en_CA en_GB en_US es_ES \
fi_FI fr_BE fr_CA fr_CH fr_FR is_IS it_CH it_IT la_LN \
lt_LN nl_BE nl_NL no_NO pt_PT sv_SE; do
echo "$l.ISO_8859-1 ISO-8859-1"
echo "$l.DIS_8859-15 ISO-8859-15"
done
for l in cs_CZ hr_HR hu_HU la_LN lt_LN pl_PL sl_SI; do
echo "$l.ISO_8859-2 ISO-8859-2"
done
for l in la_LN lt_LT; do
echo "$l.ISO_8859-4 ISO-8859-4"
done
for l in ru_RU ru_SU; do
echo "$l.KOI8-R KOI8-R"
echo "$l.ISO_8859-5 ISO-8859-5"
echo "$l.CP866 CP866"
done
echo "uk_UA.KOI8-U KOI8-U"
echo "zh_TW.BIG5 BIG5"
echo "zh_TW.Big5 BIG5"
echo "zh_CN.EUC GB2312"
echo "ja_JP.EUC EUC-JP"
echo "ja_JP.SJIS SHIFT_JIS"
echo "ja_JP.Shift_JIS SHIFT_JIS"
echo "ko_KR.EUC EUC-KR"
;;
netbsd*)
echo "646 ASCII"
echo "ISO8859-1 ISO-8859-1"
echo "ISO8859-2 ISO-8859-2"
echo "ISO8859-4 ISO-8859-4"
echo "ISO8859-5 ISO-8859-5"
echo "ISO8859-15 ISO-8859-15"
echo "eucCN GB2312"
echo "eucJP EUC-JP"
echo "eucKR EUC-KR"
echo "eucTW EUC-TW"
echo "BIG5 BIG5"
echo "SJIS SHIFT_JIS"
;;
beos*)
# BeOS has a single locale, and it has UTF-8 encoding.
echo "* UTF-8"
;;
msdosdjgpp*)
# DJGPP 2.03 doesn't have nl_langinfo(CODESET); therefore
# localcharset.c falls back to using the full locale name
# from the environment variables.
echo "#"
echo "# The encodings given here may not all be correct."
echo "# If you find that the encoding given for your language and"
echo "# country is not the one your DOS machine actually uses, just"
echo "# correct it in this file, and send a mail to"
echo "# Juan Manuel Guerrero <st001906@hrz1.hrz.tu-darmstadt.de>"
echo "# and Bruno Haible <bruno@clisp.org>."
echo "#"
echo "C ASCII"
# ISO-8859-1 languages
echo "ca CP850"
echo "ca_ES CP850"
echo "da CP865" # not CP850 ??
echo "da_DK CP865" # not CP850 ??
echo "de CP850"
echo "de_AT CP850"
echo "de_CH CP850"
echo "de_DE CP850"
echo "en CP850"
echo "en_AU CP850" # not CP437 ??
echo "en_CA CP850"
echo "en_GB CP850"
echo "en_NZ CP437"
echo "en_US CP437"
echo "en_ZA CP850" # not CP437 ??
echo "es CP850"
echo "es_AR CP850"
echo "es_BO CP850"
echo "es_CL CP850"
echo "es_CO CP850"
echo "es_CR CP850"
echo "es_CU CP850"
echo "es_DO CP850"
echo "es_EC CP850"
echo "es_ES CP850"
echo "es_GT CP850"
echo "es_HN CP850"
echo "es_MX CP850"
echo "es_NI CP850"
echo "es_PA CP850"
echo "es_PY CP850"
echo "es_PE CP850"
echo "es_SV CP850"
echo "es_UY CP850"
echo "es_VE CP850"
echo "et CP850"
echo "et_EE CP850"
echo "eu CP850"
echo "eu_ES CP850"
echo "fi CP850"
echo "fi_FI CP850"
echo "fr CP850"
echo "fr_BE CP850"
echo "fr_CA CP850"
echo "fr_CH CP850"
echo "fr_FR CP850"
echo "ga CP850"
echo "ga_IE CP850"
echo "gd CP850"
echo "gd_GB CP850"
echo "gl CP850"
echo "gl_ES CP850"
echo "id CP850" # not CP437 ??
echo "id_ID CP850" # not CP437 ??
echo "is CP861" # not CP850 ??
echo "is_IS CP861" # not CP850 ??
echo "it CP850"
echo "it_CH CP850"
echo "it_IT CP850"
echo "lt CP775"
echo "lt_LT CP775"
echo "lv CP775"
echo "lv_LV CP775"
echo "nb CP865" # not CP850 ??
echo "nb_NO CP865" # not CP850 ??
echo "nl CP850"
echo "nl_BE CP850"
echo "nl_NL CP850"
echo "nn CP865" # not CP850 ??
echo "nn_NO CP865" # not CP850 ??
echo "no CP865" # not CP850 ??
echo "no_NO CP865" # not CP850 ??
echo "pt CP850"
echo "pt_BR CP850"
echo "pt_PT CP850"
echo "sv CP850"
echo "sv_SE CP850"
# ISO-8859-2 languages
echo "cs CP852"
echo "cs_CZ CP852"
echo "hr CP852"
echo "hr_HR CP852"
echo "hu CP852"
echo "hu_HU CP852"
echo "pl CP852"
echo "pl_PL CP852"
echo "ro CP852"
echo "ro_RO CP852"
echo "sk CP852"
echo "sk_SK CP852"
echo "sl CP852"
echo "sl_SI CP852"
echo "sq CP852"
echo "sq_AL CP852"
echo "sr CP852" # CP852 or CP866 or CP855 ??
echo "sr_YU CP852" # CP852 or CP866 or CP855 ??
# ISO-8859-3 languages
echo "mt CP850"
echo "mt_MT CP850"
# ISO-8859-5 languages
echo "be CP866"
echo "be_BE CP866"
echo "bg CP866" # not CP855 ??
echo "bg_BG CP866" # not CP855 ??
echo "mk CP866" # not CP855 ??
echo "mk_MK CP866" # not CP855 ??
echo "ru CP866"
echo "ru_RU CP866"
echo "uk CP1125"
echo "uk_UA CP1125"
# ISO-8859-6 languages
echo "ar CP864"
echo "ar_AE CP864"
echo "ar_DZ CP864"
echo "ar_EG CP864"
echo "ar_IQ CP864"
echo "ar_IR CP864"
echo "ar_JO CP864"
echo "ar_KW CP864"
echo "ar_MA CP864"
echo "ar_OM CP864"
echo "ar_QA CP864"
echo "ar_SA CP864"
echo "ar_SY CP864"
# ISO-8859-7 languages
echo "el CP869"
echo "el_GR CP869"
# ISO-8859-8 languages
echo "he CP862"
echo "he_IL CP862"
# ISO-8859-9 languages
echo "tr CP857"
echo "tr_TR CP857"
# Japanese
echo "ja CP932"
echo "ja_JP CP932"
# Chinese
echo "zh_CN GBK"
echo "zh_TW CP950" # not CP938 ??
# Korean
echo "kr CP949" # not CP934 ??
echo "kr_KR CP949" # not CP934 ??
# Thai
echo "th CP874"
echo "th_TH CP874"
# Other
echo "eo CP850"
echo "eo_EO CP850"
;;
esac

61
lib/intl/dcgettext.c Normal file
View file

@ -0,0 +1,61 @@
/* dcgettext.c - Implementation of the dcgettext(3) function. */
/* Copyright (C) 1995-1999, 2000, 2001, 2002, 2006-2009 Free Software Foundation, Inc.
This file is part of GNU Bash.
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/>.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "gettextP.h"
#ifdef _LIBC
# include <libintl.h>
#else
# include "libgnuintl.h"
#endif
/* @@ end of prolog @@ */
/* Names for the libintl functions are a problem. They must not clash
with existing names and they should follow ANSI C. But this source
code is also used in GNU C Library where the names have a __
prefix. So we have to make a difference here. */
#ifdef _LIBC
# define DCGETTEXT __dcgettext
# define DCIGETTEXT __dcigettext
#else
# define DCGETTEXT libintl_dcgettext
# define DCIGETTEXT libintl_dcigettext
#endif
/* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY
locale. */
char *
DCGETTEXT (domainname, msgid, category)
const char *domainname;
const char *msgid;
int category;
{
return DCIGETTEXT (domainname, msgid, NULL, 0, 0, category);
}
#ifdef _LIBC
/* Alias for function name in GNU C Library. */
INTDEF(__dcgettext)
weak_alias (__dcgettext, dcgettext);
#endif

1248
lib/intl/dcigettext.c Normal file

File diff suppressed because it is too large Load diff

62
lib/intl/dcngettext.c Normal file
View file

@ -0,0 +1,62 @@
/* dcngettext.c - Implementation of the dcngettext(3) function. */
/* Copyright (C) 1995-1999, 2000, 2001, 2002, 2006-2009 Free Software Foundation, Inc.
This file is part of GNU Bash.
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/>.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "gettextP.h"
#ifdef _LIBC
# include <libintl.h>
#else
# include "libgnuintl.h"
#endif
/* @@ end of prolog @@ */
/* Names for the libintl functions are a problem. They must not clash
with existing names and they should follow ANSI C. But this source
code is also used in GNU C Library where the names have a __
prefix. So we have to make a difference here. */
#ifdef _LIBC
# define DCNGETTEXT __dcngettext
# define DCIGETTEXT __dcigettext
#else
# define DCNGETTEXT libintl_dcngettext
# define DCIGETTEXT libintl_dcigettext
#endif
/* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY
locale. */
char *
DCNGETTEXT (domainname, msgid1, msgid2, n, category)
const char *domainname;
const char *msgid1;
const char *msgid2;
unsigned long int n;
int category;
{
return DCIGETTEXT (domainname, msgid1, msgid2, 1, n, category);
}
#ifdef _LIBC
/* Alias for function name in GNU C Library. */
weak_alias (__dcngettext, dcngettext);
#endif

61
lib/intl/dgettext.c Normal file
View file

@ -0,0 +1,61 @@
/* dgettext.c - Implementation of the dgettext(3) function. */
/* Copyright (C) 1995-1997, 2000, 2001, 2002, 2006-2009 Free Software Foundation, Inc.
This file is part of GNU Bash.
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/>.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <locale.h>
#include "gettextP.h"
#ifdef _LIBC
# include <libintl.h>
#else
# include "libgnuintl.h"
#endif
/* @@ end of prolog @@ */
/* Names for the libintl functions are a problem. They must not clash
with existing names and they should follow ANSI C. But this source
code is also used in GNU C Library where the names have a __
prefix. So we have to make a difference here. */
#ifdef _LIBC
# define DGETTEXT __dgettext
# define DCGETTEXT INTUSE(__dcgettext)
#else
# define DGETTEXT libintl_dgettext
# define DCGETTEXT libintl_dcgettext
#endif
/* Look up MSGID in the DOMAINNAME message catalog of the current
LC_MESSAGES locale. */
char *
DGETTEXT (domainname, msgid)
const char *domainname;
const char *msgid;
{
return DCGETTEXT (domainname, msgid, LC_MESSAGES);
}
#ifdef _LIBC
/* Alias for function name in GNU C Library. */
weak_alias (__dgettext, dgettext);
#endif

63
lib/intl/dngettext.c Normal file
View file

@ -0,0 +1,63 @@
/* dngettext.c - Implementation of the dngettext(3) function. */
/* Copyright (C) 1995-1997, 2000, 2001, 2002, 2005, 2006, 2008,2009 Free Software Foundation, Inc.
This file is part of GNU Bash.
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/>.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <locale.h>
#include "gettextP.h"
#ifdef _LIBC
# include <libintl.h>
#else
# include "libgnuintl.h"
#endif
/* @@ end of prolog @@ */
/* Names for the libintl functions are a problem. They must not clash
with existing names and they should follow ANSI C. But this source
code is also used in GNU C Library where the names have a __
prefix. So we have to make a difference here. */
#ifdef _LIBC
# define DNGETTEXT __dngettext
# define DCNGETTEXT __dcngettext
#else
# define DNGETTEXT libintl_dngettext
# define DCNGETTEXT libintl_dcngettext
#endif
/* Look up MSGID in the DOMAINNAME message catalog of the current
LC_MESSAGES locale and skip message according to the plural form. */
char *
DNGETTEXT (domainname, msgid1, msgid2, n)
const char *domainname;
const char *msgid1;
const char *msgid2;
unsigned long int n;
{
return DCNGETTEXT (domainname, msgid1, msgid2, n, LC_MESSAGES);
}
#ifdef _LIBC
/* Alias for function name in GNU C Library. */
weak_alias (__dngettext, dngettext);
#endif

116
lib/intl/eval-plural.h Normal file
View file

@ -0,0 +1,116 @@
/* eval-plural.c - Plural expression evaluation. */
/* Copyright (C) 2000-2002, 2006-2009 Free Software Foundation, Inc.
This file is part of GNU Bash.
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/>.
*/
#ifndef STATIC
#define STATIC static
#endif
/* Evaluate the plural expression and return an index value. */
STATIC unsigned long int plural_eval PARAMS ((struct expression *pexp,
unsigned long int n))
internal_function;
STATIC
unsigned long int
internal_function
plural_eval (pexp, n)
struct expression *pexp;
unsigned long int n;
{
switch (pexp->nargs)
{
case 0:
switch (pexp->operation)
{
case var:
return n;
case num:
return pexp->val.num;
default:
break;
}
/* NOTREACHED */
break;
case 1:
{
/* pexp->operation must be lnot. */
unsigned long int arg = plural_eval (pexp->val.args[0], n);
return ! arg;
}
case 2:
{
unsigned long int leftarg = plural_eval (pexp->val.args[0], n);
if (pexp->operation == lor)
return leftarg || plural_eval (pexp->val.args[1], n);
else if (pexp->operation == land)
return leftarg && plural_eval (pexp->val.args[1], n);
else
{
unsigned long int rightarg = plural_eval (pexp->val.args[1], n);
switch (pexp->operation)
{
case mult:
return leftarg * rightarg;
case divide:
#if !INTDIV0_RAISES_SIGFPE
if (rightarg == 0)
raise (SIGFPE);
#endif
return leftarg / rightarg;
case module:
#if !INTDIV0_RAISES_SIGFPE
if (rightarg == 0)
raise (SIGFPE);
#endif
return leftarg % rightarg;
case plus:
return leftarg + rightarg;
case minus:
return leftarg - rightarg;
case less_than:
return leftarg < rightarg;
case greater_than:
return leftarg > rightarg;
case less_or_equal:
return leftarg <= rightarg;
case greater_or_equal:
return leftarg >= rightarg;
case equal:
return leftarg == rightarg;
case not_equal:
return leftarg != rightarg;
default:
break;
}
}
/* NOTREACHED */
break;
}
case 3:
{
/* pexp->operation must be qmop. */
unsigned long int boolarg = plural_eval (pexp->val.args[0], n);
return plural_eval (pexp->val.args[boolarg ? 1 : 2], n);
}
}
/* NOTREACHED */
return 0;
}

195
lib/intl/explodename.c Normal file
View file

@ -0,0 +1,195 @@
/* explodename.c */
/* Copyright (C) 1995-1998, 2000, 2001, 2005-2009 Free Software Foundation, Inc.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
This file is part of GNU Bash.
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/>.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "loadinfo.h"
/* On some strange systems still no definition of NULL is found. Sigh! */
#ifndef NULL
# if defined __STDC__ && __STDC__
# define NULL ((void *) 0)
# else
# define NULL 0
# endif
#endif
/* @@ end of prolog @@ */
char *
_nl_find_language (name)
const char *name;
{
while (name[0] != '\0' && name[0] != '_' && name[0] != '@'
&& name[0] != '+' && name[0] != ',')
++name;
return (char *) name;
}
int
_nl_explode_name (name, language, modifier, territory, codeset,
normalized_codeset, special, sponsor, revision)
char *name;
const char **language;
const char **modifier;
const char **territory;
const char **codeset;
const char **normalized_codeset;
const char **special;
const char **sponsor;
const char **revision;
{
enum { undecided, xpg, cen } syntax;
char *cp;
int mask;
*modifier = NULL;
*territory = NULL;
*codeset = NULL;
*normalized_codeset = NULL;
*special = NULL;
*sponsor = NULL;
*revision = NULL;
/* Now we determine the single parts of the locale name. First
look for the language. Termination symbols are `_' and `@' if
we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
mask = 0;
syntax = undecided;
*language = cp = name;
cp = _nl_find_language (*language);
if (*language == cp)
/* This does not make sense: language has to be specified. Use
this entry as it is without exploding. Perhaps it is an alias. */
cp = strchr (*language, '\0');
else if (cp[0] == '_')
{
/* Next is the territory. */
cp[0] = '\0';
*territory = ++cp;
while (cp[0] != '\0' && cp[0] != '.' && cp[0] != '@'
&& cp[0] != '+' && cp[0] != ',' && cp[0] != '_')
++cp;
mask |= TERRITORY;
if (cp[0] == '.')
{
/* Next is the codeset. */
syntax = xpg;
cp[0] = '\0';
*codeset = ++cp;
while (cp[0] != '\0' && cp[0] != '@')
++cp;
mask |= XPG_CODESET;
if (*codeset != cp && (*codeset)[0] != '\0')
{
*normalized_codeset = _nl_normalize_codeset (*codeset,
cp - *codeset);
if (strcmp (*codeset, *normalized_codeset) == 0)
free ((char *) *normalized_codeset);
else
mask |= XPG_NORM_CODESET;
}
}
}
if (cp[0] == '@' || (syntax != xpg && cp[0] == '+'))
{
/* Next is the modifier. */
syntax = cp[0] == '@' ? xpg : cen;
cp[0] = '\0';
*modifier = ++cp;
while (syntax == cen && cp[0] != '\0' && cp[0] != '+'
&& cp[0] != ',' && cp[0] != '_')
++cp;
mask |= XPG_MODIFIER | CEN_AUDIENCE;
}
if (syntax != xpg && (cp[0] == '+' || cp[0] == ',' || cp[0] == '_'))
{
syntax = cen;
if (cp[0] == '+')
{
/* Next is special application (CEN syntax). */
cp[0] = '\0';
*special = ++cp;
while (cp[0] != '\0' && cp[0] != ',' && cp[0] != '_')
++cp;
mask |= CEN_SPECIAL;
}
if (cp[0] == ',')
{
/* Next is sponsor (CEN syntax). */
cp[0] = '\0';
*sponsor = ++cp;
while (cp[0] != '\0' && cp[0] != '_')
++cp;
mask |= CEN_SPONSOR;
}
if (cp[0] == '_')
{
/* Next is revision (CEN syntax). */
cp[0] = '\0';
*revision = ++cp;
mask |= CEN_REVISION;
}
}
/* For CEN syntax values it might be important to have the
separator character in the file name, not for XPG syntax. */
if (syntax == xpg)
{
if (*territory != NULL && (*territory)[0] == '\0')
mask &= ~TERRITORY;
if (*codeset != NULL && (*codeset)[0] == '\0')
mask &= ~XPG_CODESET;
if (*modifier != NULL && (*modifier)[0] == '\0')
mask &= ~XPG_MODIFIER;
}
return mask;
}

197
lib/intl/finddomain.c Normal file
View file

@ -0,0 +1,197 @@
/* finddomain.c - Handle list of needed message catalogs */
/* Copyright (C) 1995-1999, 2000, 2001, 2005-2009 Free Software Foundation, Inc.
Written by Ulrich Drepper <drepper@gnu.org>, 1995.
This file is part of GNU Bash.
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/>.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#if defined HAVE_UNISTD_H || defined _LIBC
# include <unistd.h>
#endif
#include "gettextP.h"
#ifdef _LIBC
# include <libintl.h>
#else
# include "libgnuintl.h"
#endif
/* @@ end of prolog @@ */
/* List of already loaded domains. */
static struct loaded_l10nfile *_nl_loaded_domains;
/* Return a data structure describing the message catalog described by
the DOMAINNAME and CATEGORY parameters with respect to the currently
established bindings. */
struct loaded_l10nfile *
internal_function
_nl_find_domain (dirname, locale, domainname, domainbinding)
const char *dirname;
char *locale;
const char *domainname;
struct binding *domainbinding;
{
struct loaded_l10nfile *retval;
const char *language;
const char *modifier;
const char *territory;
const char *codeset;
const char *normalized_codeset;
const char *special;
const char *sponsor;
const char *revision;
const char *alias_value;
int mask;
/* LOCALE can consist of up to four recognized parts for the XPG syntax:
language[_territory[.codeset]][@modifier]
and six parts for the CEN syntax:
language[_territory][+audience][+special][,[sponsor][_revision]]
Beside the first part all of them are allowed to be missing. If
the full specified locale is not found, the less specific one are
looked for. The various parts will be stripped off according to
the following order:
(1) revision
(2) sponsor
(3) special
(4) codeset
(5) normalized codeset
(6) territory
(7) audience/modifier
*/
/* If we have already tested for this locale entry there has to
be one data set in the list of loaded domains. */
retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname,
strlen (dirname) + 1, 0, locale, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, domainname, 0);
if (retval != NULL)
{
/* We know something about this locale. */
int cnt;
if (retval->decided == 0)
_nl_load_domain (retval, domainbinding);
if (retval->data != NULL)
return retval;
for (cnt = 0; retval->successor[cnt] != NULL; ++cnt)
{
if (retval->successor[cnt]->decided == 0)
_nl_load_domain (retval->successor[cnt], domainbinding);
if (retval->successor[cnt]->data != NULL)
break;
}
return cnt >= 0 ? retval : NULL;
/* NOTREACHED */
}
/* See whether the locale value is an alias. If yes its value
*overwrites* the alias name. No test for the original value is
done. */
alias_value = _nl_expand_alias (locale);
if (alias_value != NULL)
{
#if defined _LIBC || defined HAVE_STRDUP
locale = strdup (alias_value);
if (locale == NULL)
return NULL;
#else
size_t len = strlen (alias_value) + 1;
locale = (char *) malloc (len);
if (locale == NULL)
return NULL;
memcpy (locale, alias_value, len);
#endif
}
/* Now we determine the single parts of the locale name. First
look for the language. Termination symbols are `_' and `@' if
we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
mask = _nl_explode_name (locale, &language, &modifier, &territory,
&codeset, &normalized_codeset, &special,
&sponsor, &revision);
/* Create all possible locale entries which might be interested in
generalization. */
retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname,
strlen (dirname) + 1, mask, language, territory,
codeset, normalized_codeset, modifier, special,
sponsor, revision, domainname, 1);
if (retval == NULL)
/* This means we are out of core. */
return NULL;
if (retval->decided == 0)
_nl_load_domain (retval, domainbinding);
if (retval->data == NULL)
{
int cnt;
for (cnt = 0; retval->successor[cnt] != NULL; ++cnt)
{
if (retval->successor[cnt]->decided == 0)
_nl_load_domain (retval->successor[cnt], domainbinding);
if (retval->successor[cnt]->data != NULL)
break;
}
}
/* The room for an alias was dynamically allocated. Free it now. */
if (alias_value != NULL)
free (locale);
/* The space for normalized_codeset is dynamically allocated. Free it. */
if (mask & XPG_NORM_CODESET)
free ((void *) normalized_codeset);
return retval;
}
#ifdef _LIBC
libc_freeres_fn (free_mem)
{
struct loaded_l10nfile *runp = _nl_loaded_domains;
while (runp != NULL)
{
struct loaded_l10nfile *here = runp;
if (runp->data != NULL)
_nl_unload_domain ((struct loaded_domain *) runp->data);
runp = runp->next;
free ((char *) here->filename);
free (here);
}
}
#endif

66
lib/intl/gettext.c Normal file
View file

@ -0,0 +1,66 @@
/* gettext.c - Implementation of gettext(3) function. */
/* Copyright (C) 1995, 1997, 2000, 2001, 2002, 2005-2009 Free Software Foundation, Inc.
This file is part of GNU Bash.
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/>.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifdef _LIBC
# define __need_NULL
# include <stddef.h>
#else
# include <stdlib.h> /* Just for NULL. */
#endif
#include "gettextP.h"
#ifdef _LIBC
# include <libintl.h>
#else
# include "libgnuintl.h"
#endif
/* @@ end of prolog @@ */
/* Names for the libintl functions are a problem. They must not clash
with existing names and they should follow ANSI C. But this source
code is also used in GNU C Library where the names have a __
prefix. So we have to make a difference here. */
#ifdef _LIBC
# define GETTEXT __gettext
# define DCGETTEXT INTUSE(__dcgettext)
#else
# define GETTEXT libintl_gettext
# define DCGETTEXT libintl_dcgettext
#endif
/* Look up MSGID in the current default message catalog for the current
LC_MESSAGES locale. If not found, returns MSGID itself (the default
text). */
char *
GETTEXT (msgid)
const char *msgid;
{
return DCGETTEXT (NULL, msgid, LC_MESSAGES);
}
#ifdef _LIBC
/* Alias for function name in GNU C Library. */
weak_alias (__gettext, gettext);
#endif

226
lib/intl/gettextP.h Normal file
View file

@ -0,0 +1,226 @@
/* gettextP.h - Header describing internals of libintl library. */
/* Copyright (C) 1995-1999, 2000-2003, 2005-2009 Free Software Foundation, Inc.
Written by Ulrich Drepper <drepper@cygnus.com>, 1995.
This file is part of GNU Bash.
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/>.
*/
#ifndef _GETTEXTP_H
#define _GETTEXTP_H
#include <stddef.h> /* Get size_t. */
#ifdef _LIBC
# include "../iconv/gconv_int.h"
#else
# if HAVE_ICONV
# include <iconv.h>
# endif
#endif
#include "loadinfo.h"
#include "gmo.h" /* Get nls_uint32. */
/* @@ end of prolog @@ */
#ifndef PARAMS
# if __STDC__ || defined __GNUC__ || defined __SUNPRO_C || defined __cplusplus || __PROTOTYPES
# define PARAMS(args) args
# else
# define PARAMS(args) ()
# endif
#endif
#ifndef internal_function
# define internal_function
#endif
#ifndef attribute_hidden
# define attribute_hidden
#endif
/* Tell the compiler when a conditional or integer expression is
almost always true or almost always false. */
#ifndef HAVE_BUILTIN_EXPECT
# define __builtin_expect(expr, val) (expr)
#endif
#ifndef W
# define W(flag, data) ((flag) ? SWAP (data) : (data))
#endif
#ifdef _LIBC
# include <byteswap.h>
# define SWAP(i) bswap_32 (i)
#else
static inline nls_uint32
SWAP (i)
nls_uint32 i;
{
return (i << 24) | ((i & 0xff00) << 8) | ((i >> 8) & 0xff00) | (i >> 24);
}
#endif
/* In-memory representation of system dependent string. */
struct sysdep_string_desc
{
/* Length of addressed string, including the trailing NUL. */
size_t length;
/* Pointer to addressed string. */
const char *pointer;
};
/* The representation of an opened message catalog. */
struct loaded_domain
{
/* Pointer to memory containing the .mo file. */
const char *data;
/* 1 if the memory is mmap()ed, 0 if the memory is malloc()ed. */
int use_mmap;
/* Size of mmap()ed memory. */
size_t mmap_size;
/* 1 if the .mo file uses a different endianness than this machine. */
int must_swap;
/* Pointer to additional malloc()ed memory. */
void *malloced;
/* Number of static strings pairs. */
nls_uint32 nstrings;
/* Pointer to descriptors of original strings in the file. */
const struct string_desc *orig_tab;
/* Pointer to descriptors of translated strings in the file. */
const struct string_desc *trans_tab;
/* Number of system dependent strings pairs. */
nls_uint32 n_sysdep_strings;
/* Pointer to descriptors of original sysdep strings. */
const struct sysdep_string_desc *orig_sysdep_tab;
/* Pointer to descriptors of translated sysdep strings. */
const struct sysdep_string_desc *trans_sysdep_tab;
/* Size of hash table. */
nls_uint32 hash_size;
/* Pointer to hash table. */
const nls_uint32 *hash_tab;
/* 1 if the hash table uses a different endianness than this machine. */
int must_swap_hash_tab;
int codeset_cntr;
#ifdef _LIBC
__gconv_t conv;
#else
# if HAVE_ICONV
iconv_t conv;
# endif
#endif
char **conv_tab;
struct expression *plural;
unsigned long int nplurals;
};
/* We want to allocate a string at the end of the struct. But ISO C
doesn't allow zero sized arrays. */
#ifdef __GNUC__
# define ZERO 0
#else
# define ZERO 1
#endif
/* A set of settings bound to a message domain. Used to store settings
from bindtextdomain() and bind_textdomain_codeset(). */
struct binding
{
struct binding *next;
char *dirname;
int codeset_cntr; /* Incremented each time codeset changes. */
char *codeset;
char domainname[ZERO];
};
/* A counter which is incremented each time some previous translations
become invalid.
This variable is part of the external ABI of the GNU libintl. */
extern int _nl_msg_cat_cntr;
#ifndef _LIBC
const char *_nl_locale_name PARAMS ((int category, const char *categoryname));
#endif
struct loaded_l10nfile *_nl_find_domain PARAMS ((const char *__dirname,
char *__locale,
const char *__domainname,
struct binding *__domainbinding))
internal_function;
void _nl_load_domain PARAMS ((struct loaded_l10nfile *__domain,
struct binding *__domainbinding))
internal_function;
void _nl_unload_domain PARAMS ((struct loaded_domain *__domain))
internal_function;
const char *_nl_init_domain_conv PARAMS ((struct loaded_l10nfile *__domain_file,
struct loaded_domain *__domain,
struct binding *__domainbinding))
internal_function;
void _nl_free_domain_conv PARAMS ((struct loaded_domain *__domain))
internal_function;
char *_nl_find_msg PARAMS ((struct loaded_l10nfile *domain_file,
struct binding *domainbinding,
const char *msgid, size_t *lengthp))
internal_function;
#ifdef _LIBC
extern char *__gettext PARAMS ((const char *__msgid));
extern char *__dgettext PARAMS ((const char *__domainname,
const char *__msgid));
extern char *__dcgettext PARAMS ((const char *__domainname,
const char *__msgid, int __category));
extern char *__ngettext PARAMS ((const char *__msgid1, const char *__msgid2,
unsigned long int __n));
extern char *__dngettext PARAMS ((const char *__domainname,
const char *__msgid1, const char *__msgid2,
unsigned long int n));
extern char *__dcngettext PARAMS ((const char *__domainname,
const char *__msgid1, const char *__msgid2,
unsigned long int __n, int __category));
extern char *__dcigettext PARAMS ((const char *__domainname,
const char *__msgid1, const char *__msgid2,
int __plural, unsigned long int __n,
int __category));
extern char *__textdomain PARAMS ((const char *__domainname));
extern char *__bindtextdomain PARAMS ((const char *__domainname,
const char *__dirname));
extern char *__bind_textdomain_codeset PARAMS ((const char *__domainname,
const char *__codeset));
#else
/* Declare the exported libintl_* functions, in a way that allows us to
call them under their real name. */
# define _INTL_REDIRECT_MACROS
# include "libgnuintl.h"
extern char *libintl_dcigettext PARAMS ((const char *__domainname,
const char *__msgid1,
const char *__msgid2,
int __plural, unsigned long int __n,
int __category));
#endif
/* @@ begin of epilog @@ */
#endif /* gettextP.h */

150
lib/intl/gmo.h Normal file
View file

@ -0,0 +1,150 @@
/* gmo.h - Description of GNU message catalog format: general file layout. */
/* Copyright (C) 1995, 1997, 2000-2002, 2005-2009 Free Software Foundation, Inc.
This file is part of GNU Bash.
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/>.
*/
#ifndef _GETTEXT_H
#define _GETTEXT_H 1
#include <limits.h>
/* @@ end of prolog @@ */
/* The magic number of the GNU message catalog format. */
#define _MAGIC 0x950412de
#define _MAGIC_SWAPPED 0xde120495
/* Revision number of the currently used .mo (binary) file format. */
#define MO_REVISION_NUMBER 0
/* The following contortions are an attempt to use the C preprocessor
to determine an unsigned integral type that is 32 bits wide. An
alternative approach is to use autoconf's AC_CHECK_SIZEOF macro, but
as of version autoconf-2.13, the AC_CHECK_SIZEOF macro doesn't work
when cross-compiling. */
#if __STDC__
# define UINT_MAX_32_BITS 4294967295U
#else
# define UINT_MAX_32_BITS 0xFFFFFFFF
#endif
/* If UINT_MAX isn't defined, assume it's a 32-bit type.
This should be valid for all systems GNU cares about because
that doesn't include 16-bit systems, and only modern systems
(that certainly have <limits.h>) have 64+-bit integral types. */
#ifndef UINT_MAX
# define UINT_MAX UINT_MAX_32_BITS
#endif
#if UINT_MAX == UINT_MAX_32_BITS
typedef unsigned nls_uint32;
#else
# if USHRT_MAX == UINT_MAX_32_BITS
typedef unsigned short nls_uint32;
# else
# if ULONG_MAX == UINT_MAX_32_BITS
typedef unsigned long nls_uint32;
# else
/* The following line is intended to throw an error. Using #error is
not portable enough. */
"Cannot determine unsigned 32-bit data type."
# endif
# endif
#endif
/* Header for binary .mo file format. */
struct mo_file_header
{
/* The magic number. */
nls_uint32 magic;
/* The revision number of the file format. */
nls_uint32 revision;
/* The following are only used in .mo files with major revision 0. */
/* The number of strings pairs. */
nls_uint32 nstrings;
/* Offset of table with start offsets of original strings. */
nls_uint32 orig_tab_offset;
/* Offset of table with start offsets of translated strings. */
nls_uint32 trans_tab_offset;
/* Size of hash table. */
nls_uint32 hash_tab_size;
/* Offset of first hash table entry. */
nls_uint32 hash_tab_offset;
/* The following are only used in .mo files with minor revision >= 1. */
/* The number of system dependent segments. */
nls_uint32 n_sysdep_segments;
/* Offset of table describing system dependent segments. */
nls_uint32 sysdep_segments_offset;
/* The number of system dependent strings pairs. */
nls_uint32 n_sysdep_strings;
/* Offset of table with start offsets of original sysdep strings. */
nls_uint32 orig_sysdep_tab_offset;
/* Offset of table with start offsets of translated sysdep strings. */
nls_uint32 trans_sysdep_tab_offset;
};
/* Descriptor for static string contained in the binary .mo file. */
struct string_desc
{
/* Length of addressed string, not including the trailing NUL. */
nls_uint32 length;
/* Offset of string in file. */
nls_uint32 offset;
};
/* The following are only used in .mo files with minor revision >= 1. */
/* Descriptor for system dependent string segment. */
struct sysdep_segment
{
/* Length of addressed string, including the trailing NUL. */
nls_uint32 length;
/* Offset of string in file. */
nls_uint32 offset;
};
/* Descriptor for system dependent string. */
struct sysdep_string
{
/* Offset of static string segments in file. */
nls_uint32 offset;
/* Alternating sequence of static and system dependent segments.
The last segment is a static segment, including the trailing NUL. */
struct segment_pair
{
/* Size of static segment. */
nls_uint32 segsize;
/* Reference to system dependent string segment, or ~0 at the end. */
nls_uint32 sysdepref;
} segments[1];
};
/* Marker for the end of the segments[] array. This has the value 0xFFFFFFFF,
regardless whether 'int' is 16 bit, 32 bit, or 64 bit. */
#define SEGMENTS_END ((nls_uint32) ~0)
/* @@ begin of epilog @@ */
#endif /* gettext.h */

61
lib/intl/hash-string.h Normal file
View file

@ -0,0 +1,61 @@
/* hash-string.h - Description of GNU message catalog format: string hashing function. */
/* Copyright (C) 1995, 1997, 1998, 2000, 2001, 2005-2009 Free Software Foundation, Inc.
This file is part of GNU Bash.
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/>.
*/
/* @@ end of prolog @@ */
#ifndef PARAMS
# if __STDC__ || defined __GNUC__ || defined __SUNPRO_C || defined __cplusplus || __PROTOTYPES
# define PARAMS(Args) Args
# else
# define PARAMS(Args) ()
# endif
#endif
/* We assume to have `unsigned long int' value with at least 32 bits. */
#define HASHWORDBITS 32
/* Defines the so called `hashpjw' function by P.J. Weinberger
[see Aho/Sethi/Ullman, COMPILERS: Principles, Techniques and Tools,
1986, 1987 Bell Telephone Laboratories, Inc.] */
static unsigned long int hash_string PARAMS ((const char *__str_param));
static inline unsigned long int
hash_string (str_param)
const char *str_param;
{
unsigned long int hval, g;
const char *str = str_param;
/* Compute the hash value for the given string. */
hval = 0;
while (*str != '\0')
{
hval <<= 4;
hval += (unsigned long int) *str++;
g = hval & ((unsigned long int) 0xf << (HASHWORDBITS - 4));
if (g != 0)
{
hval ^= g >> (HASHWORDBITS - 8);
hval ^= g;
}
}
return hval;
}

152
lib/intl/intl-compat.c Normal file
View file

@ -0,0 +1,152 @@
/* intl-compat.c - Stub functions to call gettext functions from GNU gettext library. */
/* Copyright (C) 1995, 2000-2003, 2005-2009 Free Software Foundation, Inc.
This file is part of GNU Bash.
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/>.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "gettextP.h"
/* @@ end of prolog @@ */
/* This file redirects the gettext functions (without prefix) to those
defined in the included GNU libintl library (with "libintl_" prefix).
It is compiled into libintl in order to make the AM_GNU_GETTEXT test
of gettext <= 0.11.2 work with the libintl library >= 0.11.3 which
has the redirections primarily in the <libintl.h> include file.
It is also compiled into libgnuintl so that libgnuintl.so can be used
as LD_PRELOADable library on glibc systems, to provide the extra
features that the functions in the libc don't have (namely, logging). */
#undef gettext
#undef dgettext
#undef dcgettext
#undef ngettext
#undef dngettext
#undef dcngettext
#undef textdomain
#undef bindtextdomain
#undef bind_textdomain_codeset
/* When building a DLL, we must export some functions. Note that because
the functions are only defined for binary backward compatibility, we
don't need to use __declspec(dllimport) in any case. */
#if defined _MSC_VER && BUILDING_DLL
# define DLL_EXPORTED __declspec(dllexport)
#else
# define DLL_EXPORTED
#endif
DLL_EXPORTED
char *
gettext (msgid)
const char *msgid;
{
return libintl_gettext (msgid);
}
DLL_EXPORTED
char *
dgettext (domainname, msgid)
const char *domainname;
const char *msgid;
{
return libintl_dgettext (domainname, msgid);
}
DLL_EXPORTED
char *
dcgettext (domainname, msgid, category)
const char *domainname;
const char *msgid;
int category;
{
return libintl_dcgettext (domainname, msgid, category);
}
DLL_EXPORTED
char *
ngettext (msgid1, msgid2, n)
const char *msgid1;
const char *msgid2;
unsigned long int n;
{
return libintl_ngettext (msgid1, msgid2, n);
}
DLL_EXPORTED
char *
dngettext (domainname, msgid1, msgid2, n)
const char *domainname;
const char *msgid1;
const char *msgid2;
unsigned long int n;
{
return libintl_dngettext (domainname, msgid1, msgid2, n);
}
DLL_EXPORTED
char *
dcngettext (domainname, msgid1, msgid2, n, category)
const char *domainname;
const char *msgid1;
const char *msgid2;
unsigned long int n;
int category;
{
return libintl_dcngettext (domainname, msgid1, msgid2, n, category);
}
DLL_EXPORTED
char *
textdomain (domainname)
const char *domainname;
{
return libintl_textdomain (domainname);
}
DLL_EXPORTED
char *
bindtextdomain (domainname, dirname)
const char *domainname;
const char *dirname;
{
return libintl_bindtextdomain (domainname, dirname);
}
DLL_EXPORTED
char *
bind_textdomain_codeset (domainname, codeset)
const char *domainname;
const char *codeset;
{
return libintl_bind_textdomain_codeset (domainname, codeset);
}

459
lib/intl/l10nflist.c Normal file
View file

@ -0,0 +1,459 @@
/* l10nflist.c - make localization file list. */
/* Copyright (C) 1995-1999, 2000, 2001, 2002, 2005-2009 Free Software Foundation, Inc.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
This file is part of GNU Bash.
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/>.
*/
/* Tell glibc's <string.h> to provide a prototype for stpcpy().
This must come before <config.h> because <config.h> may include
<features.h>, and once <features.h> has been included, it's too late. */
#ifndef _GNU_SOURCE
# define _GNU_SOURCE 1
#endif
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <string.h>
#if defined _LIBC || defined HAVE_ARGZ_H
# include <argz.h>
#endif
#include <ctype.h>
#include <sys/types.h>
#include <stdlib.h>
#include "loadinfo.h"
/* On some strange systems still no definition of NULL is found. Sigh! */
#ifndef NULL
# if defined __STDC__ && __STDC__
# define NULL ((void *) 0)
# else
# define NULL 0
# endif
#endif
/* @@ end of prolog @@ */
#ifdef _LIBC
/* Rename the non ANSI C functions. This is required by the standard
because some ANSI C functions will require linking with this object
file and the name space must not be polluted. */
# ifndef stpcpy
# define stpcpy(dest, src) __stpcpy(dest, src)
# endif
#else
# ifndef HAVE_STPCPY
static char *stpcpy PARAMS ((char *dest, const char *src));
# endif
#endif
/* Pathname support.
ISSLASH(C) tests whether C is a directory separator character.
IS_ABSOLUTE_PATH(P) tests whether P is an absolute path. If it is not,
it may be concatenated to a directory pathname.
*/
#if defined _WIN32 || defined __WIN32__ || defined __EMX__ || defined __DJGPP__
/* Win32, OS/2, DOS */
# define ISSLASH(C) ((C) == '/' || (C) == '\\')
# define HAS_DEVICE(P) \
((((P)[0] >= 'A' && (P)[0] <= 'Z') || ((P)[0] >= 'a' && (P)[0] <= 'z')) \
&& (P)[1] == ':')
# define IS_ABSOLUTE_PATH(P) (ISSLASH ((P)[0]) || HAS_DEVICE (P))
#else
/* Unix */
# define ISSLASH(C) ((C) == '/')
# define IS_ABSOLUTE_PATH(P) ISSLASH ((P)[0])
#endif
/* Define function which are usually not available. */
#if !defined _LIBC && !defined HAVE___ARGZ_COUNT
/* Returns the number of strings in ARGZ. */
static size_t argz_count__ PARAMS ((const char *argz, size_t len));
static size_t
argz_count__ (argz, len)
const char *argz;
size_t len;
{
size_t count = 0;
while (len > 0)
{
size_t part_len = strlen (argz);
argz += part_len + 1;
len -= part_len + 1;
count++;
}
return count;
}
# undef __argz_count
# define __argz_count(argz, len) argz_count__ (argz, len)
#else
# ifdef _LIBC
# define __argz_count(argz, len) INTUSE(__argz_count) (argz, len)
# endif
#endif /* !_LIBC && !HAVE___ARGZ_COUNT */
#if !defined _LIBC && !defined HAVE___ARGZ_STRINGIFY
/* Make '\0' separated arg vector ARGZ printable by converting all the '\0's
except the last into the character SEP. */
static void argz_stringify__ PARAMS ((char *argz, size_t len, int sep));
static void
argz_stringify__ (argz, len, sep)
char *argz;
size_t len;
int sep;
{
while (len > 0)
{
size_t part_len = strlen (argz);
argz += part_len;
len -= part_len + 1;
if (len > 0)
*argz++ = sep;
}
}
# undef __argz_stringify
# define __argz_stringify(argz, len, sep) argz_stringify__ (argz, len, sep)
#else
# ifdef _LIBC
# define __argz_stringify(argz, len, sep) \
INTUSE(__argz_stringify) (argz, len, sep)
# endif
#endif /* !_LIBC && !HAVE___ARGZ_STRINGIFY */
#if !defined _LIBC && !defined HAVE___ARGZ_NEXT
static char *argz_next__ PARAMS ((char *argz, size_t argz_len,
const char *entry));
static char *
argz_next__ (argz, argz_len, entry)
char *argz;
size_t argz_len;
const char *entry;
{
if (entry)
{
if (entry < argz + argz_len)
entry = strchr (entry, '\0') + 1;
return entry >= argz + argz_len ? NULL : (char *) entry;
}
else
if (argz_len > 0)
return argz;
else
return 0;
}
# undef __argz_next
# define __argz_next(argz, len, entry) argz_next__ (argz, len, entry)
#endif /* !_LIBC && !HAVE___ARGZ_NEXT */
/* Return number of bits set in X. */
static int pop PARAMS ((int x));
static inline int
pop (x)
int x;
{
/* We assume that no more than 16 bits are used. */
x = ((x & ~0x5555) >> 1) + (x & 0x5555);
x = ((x & ~0x3333) >> 2) + (x & 0x3333);
x = ((x >> 4) + x) & 0x0f0f;
x = ((x >> 8) + x) & 0xff;
return x;
}
struct loaded_l10nfile *
_nl_make_l10nflist (l10nfile_list, dirlist, dirlist_len, mask, language,
territory, codeset, normalized_codeset, modifier, special,
sponsor, revision, filename, do_allocate)
struct loaded_l10nfile **l10nfile_list;
const char *dirlist;
size_t dirlist_len;
int mask;
const char *language;
const char *territory;
const char *codeset;
const char *normalized_codeset;
const char *modifier;
const char *special;
const char *sponsor;
const char *revision;
const char *filename;
int do_allocate;
{
char *abs_filename;
struct loaded_l10nfile **lastp;
struct loaded_l10nfile *retval;
char *cp;
size_t dirlist_count;
size_t entries;
int cnt;
/* If LANGUAGE contains an absolute directory specification, we ignore
DIRLIST. */
if (IS_ABSOLUTE_PATH (language))
dirlist_len = 0;
/* Allocate room for the full file name. */
abs_filename = (char *) malloc (dirlist_len
+ strlen (language)
+ ((mask & TERRITORY) != 0
? strlen (territory) + 1 : 0)
+ ((mask & XPG_CODESET) != 0
? strlen (codeset) + 1 : 0)
+ ((mask & XPG_NORM_CODESET) != 0
? strlen (normalized_codeset) + 1 : 0)
+ (((mask & XPG_MODIFIER) != 0
|| (mask & CEN_AUDIENCE) != 0)
? strlen (modifier) + 1 : 0)
+ ((mask & CEN_SPECIAL) != 0
? strlen (special) + 1 : 0)
+ (((mask & CEN_SPONSOR) != 0
|| (mask & CEN_REVISION) != 0)
? (1 + ((mask & CEN_SPONSOR) != 0
? strlen (sponsor) : 0)
+ ((mask & CEN_REVISION) != 0
? strlen (revision) + 1 : 0)) : 0)
+ 1 + strlen (filename) + 1);
if (abs_filename == NULL)
return NULL;
/* Construct file name. */
cp = abs_filename;
if (dirlist_len > 0)
{
memcpy (cp, dirlist, dirlist_len);
__argz_stringify (cp, dirlist_len, PATH_SEPARATOR);
cp += dirlist_len;
cp[-1] = '/';
}
cp = stpcpy (cp, language);
if ((mask & TERRITORY) != 0)
{
*cp++ = '_';
cp = stpcpy (cp, territory);
}
if ((mask & XPG_CODESET) != 0)
{
*cp++ = '.';
cp = stpcpy (cp, codeset);
}
if ((mask & XPG_NORM_CODESET) != 0)
{
*cp++ = '.';
cp = stpcpy (cp, normalized_codeset);
}
if ((mask & (XPG_MODIFIER | CEN_AUDIENCE)) != 0)
{
/* This component can be part of both syntaxes but has different
leading characters. For CEN we use `+', else `@'. */
*cp++ = (mask & CEN_AUDIENCE) != 0 ? '+' : '@';
cp = stpcpy (cp, modifier);
}
if ((mask & CEN_SPECIAL) != 0)
{
*cp++ = '+';
cp = stpcpy (cp, special);
}
if ((mask & (CEN_SPONSOR | CEN_REVISION)) != 0)
{
*cp++ = ',';
if ((mask & CEN_SPONSOR) != 0)
cp = stpcpy (cp, sponsor);
if ((mask & CEN_REVISION) != 0)
{
*cp++ = '_';
cp = stpcpy (cp, revision);
}
}
*cp++ = '/';
stpcpy (cp, filename);
/* Look in list of already loaded domains whether it is already
available. */
lastp = l10nfile_list;
for (retval = *l10nfile_list; retval != NULL; retval = retval->next)
if (retval->filename != NULL)
{
int compare = strcmp (retval->filename, abs_filename);
if (compare == 0)
/* We found it! */
break;
if (compare < 0)
{
/* It's not in the list. */
retval = NULL;
break;
}
lastp = &retval->next;
}
if (retval != NULL || do_allocate == 0)
{
free (abs_filename);
return retval;
}
dirlist_count = (dirlist_len > 0 ? __argz_count (dirlist, dirlist_len) : 1);
/* Allocate a new loaded_l10nfile. */
retval =
(struct loaded_l10nfile *)
malloc (sizeof (*retval)
+ (((dirlist_count << pop (mask)) + (dirlist_count > 1 ? 1 : 0))
* sizeof (struct loaded_l10nfile *)));
if (retval == NULL)
{
free (abs_filename);
return NULL;
}
retval->filename = abs_filename;
/* We set retval->data to NULL here; it is filled in later.
Setting retval->decided to 1 here means that retval does not
correspond to a real file (dirlist_count > 1) or is not worth
looking up (if an unnormalized codeset was specified). */
retval->decided = (dirlist_count > 1
|| ((mask & XPG_CODESET) != 0
&& (mask & XPG_NORM_CODESET) != 0));
retval->data = NULL;
retval->next = *lastp;
*lastp = retval;
entries = 0;
/* Recurse to fill the inheritance list of RETVAL.
If the DIRLIST is a real list (i.e. DIRLIST_COUNT > 1), the RETVAL
entry does not correspond to a real file; retval->filename contains
colons. In this case we loop across all elements of DIRLIST and
across all bit patterns dominated by MASK.
If the DIRLIST is a single directory or entirely redundant (i.e.
DIRLIST_COUNT == 1), we loop across all bit patterns dominated by
MASK, excluding MASK itself.
In either case, we loop down from MASK to 0. This has the effect
that the extra bits in the locale name are dropped in this order:
first the modifier, then the territory, then the codeset, then the
normalized_codeset. */
for (cnt = dirlist_count > 1 ? mask : mask - 1; cnt >= 0; --cnt)
if ((cnt & ~mask) == 0
&& ((cnt & CEN_SPECIFIC) == 0 || (cnt & XPG_SPECIFIC) == 0)
&& ((cnt & XPG_CODESET) == 0 || (cnt & XPG_NORM_CODESET) == 0))
{
if (dirlist_count > 1)
{
/* Iterate over all elements of the DIRLIST. */
char *dir = NULL;
while ((dir = __argz_next ((char *) dirlist, dirlist_len, dir))
!= NULL)
retval->successor[entries++]
= _nl_make_l10nflist (l10nfile_list, dir, strlen (dir) + 1,
cnt, language, territory, codeset,
normalized_codeset, modifier, special,
sponsor, revision, filename, 1);
}
else
retval->successor[entries++]
= _nl_make_l10nflist (l10nfile_list, dirlist, dirlist_len,
cnt, language, territory, codeset,
normalized_codeset, modifier, special,
sponsor, revision, filename, 1);
}
retval->successor[entries] = NULL;
return retval;
}
/* Normalize codeset name. There is no standard for the codeset
names. Normalization allows the user to use any of the common
names. The return value is dynamically allocated and has to be
freed by the caller. */
const char *
_nl_normalize_codeset (codeset, name_len)
const char *codeset;
size_t name_len;
{
int len = 0;
int only_digit = 1;
char *retval;
char *wp;
size_t cnt;
for (cnt = 0; cnt < name_len; ++cnt)
if (isalnum ((unsigned char) codeset[cnt]))
{
++len;
if (isalpha ((unsigned char) codeset[cnt]))
only_digit = 0;
}
retval = (char *) malloc ((only_digit ? 3 : 0) + len + 1);
if (retval != NULL)
{
if (only_digit)
wp = stpcpy (retval, "iso");
else
wp = retval;
for (cnt = 0; cnt < name_len; ++cnt)
if (isalpha ((unsigned char) codeset[cnt]))
*wp++ = tolower ((unsigned char) codeset[cnt]);
else if (isdigit ((unsigned char) codeset[cnt]))
*wp++ = codeset[cnt];
*wp = '\0';
}
return (const char *) retval;
}
/* @@ begin of epilog @@ */
/* We don't want libintl.a to depend on any other library. So we
avoid the non-standard function stpcpy. In GNU C Library this
function is available, though. Also allow the symbol HAVE_STPCPY
to be defined. */
#if !_LIBC && !HAVE_STPCPY
static char *
stpcpy (dest, src)
char *dest;
const char *src;
{
while ((*dest++ = *src++) != '\0')
/* Do nothing. */ ;
return dest - 1;
}
#endif

311
lib/intl/libgnuintl.h.in Normal file
View file

@ -0,0 +1,311 @@
/* libgnuintl.h - Message catalogs for internationalization. */
/* Copyright (C) 1995-1997, 2000-2003, 2004-2009 Free Software Foundation, Inc.
This file is part of GNU Bash.
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/>.
*/
#ifndef _LIBINTL_H
#define _LIBINTL_H 1
#include <locale.h>
/* The LC_MESSAGES locale category is the category used by the functions
gettext() and dgettext(). It is specified in POSIX, but not in ANSI C.
On systems that don't define it, use an arbitrary value instead.
On Solaris, <locale.h> defines __LOCALE_H (or _LOCALE_H in Solaris 2.5)
then includes <libintl.h> (i.e. this file!) and then only defines
LC_MESSAGES. To avoid a redefinition warning, don't define LC_MESSAGES
in this case. */
#if !defined LC_MESSAGES && !(defined __LOCALE_H || (defined _LOCALE_H && defined __sun))
# define LC_MESSAGES 1729
#endif
/* We define an additional symbol to signal that we use the GNU
implementation of gettext. */
#define __USE_GNU_GETTEXT 1
/* Provide information about the supported file formats. Returns the
maximum minor revision number supported for a given major revision. */
#define __GNU_GETTEXT_SUPPORTED_REVISION(major) \
((major) == 0 ? 1 : -1)
/* Resolve a platform specific conflict on DJGPP. GNU gettext takes
precedence over _conio_gettext. */
#ifdef __DJGPP__
# undef gettext
#endif
/* Use _INTL_PARAMS, not PARAMS, in order to avoid clashes with identifiers
used by programs. Similarly, test __PROTOTYPES, not PROTOTYPES. */
#ifndef _INTL_PARAMS
# if __STDC__ || defined __GNUC__ || defined __SUNPRO_C || defined __cplusplus || __PROTOTYPES
# define _INTL_PARAMS(args) args
# else
# define _INTL_PARAMS(args) ()
# endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* We redirect the functions to those prefixed with "libintl_". This is
necessary, because some systems define gettext/textdomain/... in the C
library (namely, Solaris 2.4 and newer, and GNU libc 2.0 and newer).
If we used the unprefixed names, there would be cases where the
definition in the C library would override the one in the libintl.so
shared library. Recall that on ELF systems, the symbols are looked
up in the following order:
1. in the executable,
2. in the shared libraries specified on the link command line, in order,
3. in the dependencies of the shared libraries specified on the link
command line,
4. in the dlopen()ed shared libraries, in the order in which they were
dlopen()ed.
The definition in the C library would override the one in libintl.so if
either
* -lc is given on the link command line and -lintl isn't, or
* -lc is given on the link command line before -lintl, or
* libintl.so is a dependency of a dlopen()ed shared library but not
linked to the executable at link time.
Since Solaris gettext() behaves differently than GNU gettext(), this
would be unacceptable.
The redirection happens by default through macros in C, so that &gettext
is independent of the compilation unit, but through inline functions in
C++, in order not to interfere with the name mangling of class fields or
class methods called 'gettext'. */
/* The user can define _INTL_REDIRECT_INLINE or _INTL_REDIRECT_MACROS.
If he doesn't, we choose the method. A third possible method is
_INTL_REDIRECT_ASM, supported only by GCC. */
#if !(defined _INTL_REDIRECT_INLINE || defined _INTL_REDIRECT_MACROS)
# if __GNUC__ >= 2 && !defined __APPLE_CC__ && (defined __STDC__ || defined __cplusplus)
# define _INTL_REDIRECT_ASM
# else
# ifdef __cplusplus
# define _INTL_REDIRECT_INLINE
# else
# define _INTL_REDIRECT_MACROS
# endif
# endif
#endif
/* Auxiliary macros. */
#ifdef _INTL_REDIRECT_ASM
# define _INTL_ASM(cname) __asm__ (_INTL_ASMNAME (__USER_LABEL_PREFIX__, #cname))
# define _INTL_ASMNAME(prefix,cnamestring) _INTL_STRINGIFY (prefix) cnamestring
# define _INTL_STRINGIFY(prefix) #prefix
#else
# define _INTL_ASM(cname)
#endif
/* Look up MSGID in the current default message catalog for the current
LC_MESSAGES locale. If not found, returns MSGID itself (the default
text). */
#ifdef _INTL_REDIRECT_INLINE
extern char *libintl_gettext (const char *__msgid);
static inline char *gettext (const char *__msgid)
{
return libintl_gettext (__msgid);
}
#else
#ifdef _INTL_REDIRECT_MACROS
# define gettext libintl_gettext
#endif
extern char *gettext _INTL_PARAMS ((const char *__msgid))
_INTL_ASM (libintl_gettext);
#endif
/* Look up MSGID in the DOMAINNAME message catalog for the current
LC_MESSAGES locale. */
#ifdef _INTL_REDIRECT_INLINE
extern char *libintl_dgettext (const char *__domainname, const char *__msgid);
static inline char *dgettext (const char *__domainname, const char *__msgid)
{
return libintl_dgettext (__domainname, __msgid);
}
#else
#ifdef _INTL_REDIRECT_MACROS
# define dgettext libintl_dgettext
#endif
extern char *dgettext _INTL_PARAMS ((const char *__domainname,
const char *__msgid))
_INTL_ASM (libintl_dgettext);
#endif
/* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY
locale. */
#ifdef _INTL_REDIRECT_INLINE
extern char *libintl_dcgettext (const char *__domainname, const char *__msgid,
int __category);
static inline char *dcgettext (const char *__domainname, const char *__msgid,
int __category)
{
return libintl_dcgettext (__domainname, __msgid, __category);
}
#else
#ifdef _INTL_REDIRECT_MACROS
# define dcgettext libintl_dcgettext
#endif
extern char *dcgettext _INTL_PARAMS ((const char *__domainname,
const char *__msgid,
int __category))
_INTL_ASM (libintl_dcgettext);
#endif
/* Similar to `gettext' but select the plural form corresponding to the
number N. */
#ifdef _INTL_REDIRECT_INLINE
extern char *libintl_ngettext (const char *__msgid1, const char *__msgid2,
unsigned long int __n);
static inline char *ngettext (const char *__msgid1, const char *__msgid2,
unsigned long int __n)
{
return libintl_ngettext (__msgid1, __msgid2, __n);
}
#else
#ifdef _INTL_REDIRECT_MACROS
# define ngettext libintl_ngettext
#endif
extern char *ngettext _INTL_PARAMS ((const char *__msgid1,
const char *__msgid2,
unsigned long int __n))
_INTL_ASM (libintl_ngettext);
#endif
/* Similar to `dgettext' but select the plural form corresponding to the
number N. */
#ifdef _INTL_REDIRECT_INLINE
extern char *libintl_dngettext (const char *__domainname, const char *__msgid1,
const char *__msgid2, unsigned long int __n);
static inline char *dngettext (const char *__domainname, const char *__msgid1,
const char *__msgid2, unsigned long int __n)
{
return libintl_dngettext (__domainname, __msgid1, __msgid2, __n);
}
#else
#ifdef _INTL_REDIRECT_MACROS
# define dngettext libintl_dngettext
#endif
extern char *dngettext _INTL_PARAMS ((const char *__domainname,
const char *__msgid1,
const char *__msgid2,
unsigned long int __n))
_INTL_ASM (libintl_dngettext);
#endif
/* Similar to `dcgettext' but select the plural form corresponding to the
number N. */
#ifdef _INTL_REDIRECT_INLINE
extern char *libintl_dcngettext (const char *__domainname,
const char *__msgid1, const char *__msgid2,
unsigned long int __n, int __category);
static inline char *dcngettext (const char *__domainname,
const char *__msgid1, const char *__msgid2,
unsigned long int __n, int __category)
{
return libintl_dcngettext (__domainname, __msgid1, __msgid2, __n, __category);
}
#else
#ifdef _INTL_REDIRECT_MACROS
# define dcngettext libintl_dcngettext
#endif
extern char *dcngettext _INTL_PARAMS ((const char *__domainname,
const char *__msgid1,
const char *__msgid2,
unsigned long int __n,
int __category))
_INTL_ASM (libintl_dcngettext);
#endif
/* Set the current default message catalog to DOMAINNAME.
If DOMAINNAME is null, return the current default.
If DOMAINNAME is "", reset to the default of "messages". */
#ifdef _INTL_REDIRECT_INLINE
extern char *libintl_textdomain (const char *__domainname);
static inline char *textdomain (const char *__domainname)
{
return libintl_textdomain (__domainname);
}
#else
#ifdef _INTL_REDIRECT_MACROS
# define textdomain libintl_textdomain
#endif
extern char *textdomain _INTL_PARAMS ((const char *__domainname))
_INTL_ASM (libintl_textdomain);
#endif
/* Specify that the DOMAINNAME message catalog will be found
in DIRNAME rather than in the system locale data base. */
#ifdef _INTL_REDIRECT_INLINE
extern char *libintl_bindtextdomain (const char *__domainname,
const char *__dirname);
static inline char *bindtextdomain (const char *__domainname,
const char *__dirname)
{
return libintl_bindtextdomain (__domainname, __dirname);
}
#else
#ifdef _INTL_REDIRECT_MACROS
# define bindtextdomain libintl_bindtextdomain
#endif
extern char *bindtextdomain _INTL_PARAMS ((const char *__domainname,
const char *__dirname))
_INTL_ASM (libintl_bindtextdomain);
#endif
/* Specify the character encoding in which the messages from the
DOMAINNAME message catalog will be returned. */
#ifdef _INTL_REDIRECT_INLINE
extern char *libintl_bind_textdomain_codeset (const char *__domainname,
const char *__codeset);
static inline char *bind_textdomain_codeset (const char *__domainname,
const char *__codeset)
{
return libintl_bind_textdomain_codeset (__domainname, __codeset);
}
#else
#ifdef _INTL_REDIRECT_MACROS
# define bind_textdomain_codeset libintl_bind_textdomain_codeset
#endif
extern char *bind_textdomain_codeset _INTL_PARAMS ((const char *__domainname,
const char *__codeset))
_INTL_ASM (libintl_bind_textdomain_codeset);
#endif
/* Support for relocatable packages. */
/* Sets the original and the current installation prefix of the package.
Relocation simply replaces a pathname starting with the original prefix
by the corresponding pathname with the current prefix instead. Both
prefixes should be directory names without trailing slash (i.e. use ""
instead of "/"). */
#define libintl_set_relocation_prefix libintl_set_relocation_prefix
extern void
libintl_set_relocation_prefix _INTL_PARAMS ((const char *orig_prefix,
const char *curr_prefix));
#ifdef __cplusplus
}
#endif
#endif /* libintl.h */

159
lib/intl/loadinfo.h Normal file
View file

@ -0,0 +1,159 @@
/* loadinfo.c */
/* Copyright (C) 1996-1999, 2000-2002, 2005-2009 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
This file is part of GNU Bash.
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/>.
*/
#ifndef _LOADINFO_H
#define _LOADINFO_H 1
/* Declarations of locale dependent catalog lookup functions.
Implemented in
localealias.c Possibly replace a locale name by another.
explodename.c Split a locale name into its various fields.
l10nflist.c Generate a list of filenames of possible message catalogs.
finddomain.c Find and open the relevant message catalogs.
The main function _nl_find_domain() in finddomain.c is declared
in gettextP.h.
*/
#ifndef PARAMS
# if __STDC__ || defined __GNUC__ || defined __SUNPRO_C || defined __cplusplus || __PROTOTYPES
# define PARAMS(args) args
# else
# define PARAMS(args) ()
# endif
#endif
#ifndef internal_function
# define internal_function
#endif
/* Tell the compiler when a conditional or integer expression is
almost always true or almost always false. */
#ifndef HAVE_BUILTIN_EXPECT
# define __builtin_expect(expr, val) (expr)
#endif
/* Separator in PATH like lists of pathnames. */
#if defined _WIN32 || defined __WIN32__ || defined __EMX__ || defined __DJGPP__
/* Win32, OS/2, DOS */
# define PATH_SEPARATOR ';'
#else
/* Unix */
# define PATH_SEPARATOR ':'
#endif
/* Encoding of locale name parts. */
#define CEN_REVISION 1
#define CEN_SPONSOR 2
#define CEN_SPECIAL 4
#define XPG_NORM_CODESET 8
#define XPG_CODESET 16
#define TERRITORY 32
#define CEN_AUDIENCE 64
#define XPG_MODIFIER 128
#define CEN_SPECIFIC (CEN_REVISION|CEN_SPONSOR|CEN_SPECIAL|CEN_AUDIENCE)
#define XPG_SPECIFIC (XPG_CODESET|XPG_NORM_CODESET|XPG_MODIFIER)
struct loaded_l10nfile
{
const char *filename;
int decided;
const void *data;
struct loaded_l10nfile *next;
struct loaded_l10nfile *successor[1];
};
/* Normalize codeset name. There is no standard for the codeset
names. Normalization allows the user to use any of the common
names. The return value is dynamically allocated and has to be
freed by the caller. */
extern const char *_nl_normalize_codeset PARAMS ((const char *codeset,
size_t name_len));
/* Lookup a locale dependent file.
*L10NFILE_LIST denotes a pool of lookup results of locale dependent
files of the same kind, sorted in decreasing order of ->filename.
DIRLIST and DIRLIST_LEN are an argz list of directories in which to
look, containing at least one directory (i.e. DIRLIST_LEN > 0).
MASK, LANGUAGE, TERRITORY, CODESET, NORMALIZED_CODESET, MODIFIER,
SPECIAL, SPONSOR, REVISION are the pieces of the locale name, as
produced by _nl_explode_name(). FILENAME is the filename suffix.
The return value is the lookup result, either found in *L10NFILE_LIST,
or - if DO_ALLOCATE is nonzero - freshly allocated, or possibly NULL.
If the return value is non-NULL, it is added to *L10NFILE_LIST, and
its ->next field denotes the chaining inside *L10NFILE_LIST, and
furthermore its ->successor[] field contains a list of other lookup
results from which this lookup result inherits. */
extern struct loaded_l10nfile *
_nl_make_l10nflist PARAMS ((struct loaded_l10nfile **l10nfile_list,
const char *dirlist, size_t dirlist_len, int mask,
const char *language, const char *territory,
const char *codeset,
const char *normalized_codeset,
const char *modifier, const char *special,
const char *sponsor, const char *revision,
const char *filename, int do_allocate));
/* Lookup the real locale name for a locale alias NAME, or NULL if
NAME is not a locale alias (but possibly a real locale name).
The return value is statically allocated and must not be freed. */
extern const char *_nl_expand_alias PARAMS ((const char *name));
/* Split a locale name NAME into its pieces: language, modifier,
territory, codeset, special, sponsor, revision.
NAME gets destructively modified: NUL bytes are inserted here and
there. *LANGUAGE gets assigned NAME. Each of *MODIFIER, *TERRITORY,
*CODESET, *SPECIAL, *SPONSOR, *REVISION gets assigned either a
pointer into the old NAME string, or NULL. *NORMALIZED_CODESET
gets assigned the expanded *CODESET, if it is different from *CODESET;
this one is dynamically allocated and has to be freed by the caller.
The return value is a bitmask, where each bit corresponds to one
filled-in value:
XPG_MODIFIER, CEN_AUDIENCE for *MODIFIER,
TERRITORY for *TERRITORY,
XPG_CODESET for *CODESET,
XPG_NORM_CODESET for *NORMALIZED_CODESET,
CEN_SPECIAL for *SPECIAL,
CEN_SPONSOR for *SPONSOR,
CEN_REVISION for *REVISION.
*/
extern int _nl_explode_name PARAMS ((char *name, const char **language,
const char **modifier,
const char **territory,
const char **codeset,
const char **normalized_codeset,
const char **special,
const char **sponsor,
const char **revision));
/* Split a locale name NAME into a leading language part and all the
rest. Return a pointer to the first character after the language,
i.e. to the first byte of the rest. */
extern char *_nl_find_language PARAMS ((const char *name));
#endif /* loadinfo.h */

1336
lib/intl/loadmsgcat.c Normal file

File diff suppressed because it is too large Load diff

399
lib/intl/localcharset.c Normal file
View file

@ -0,0 +1,399 @@
/* localcharset.c - Determine a canonical name for the current locale's character encoding. */
/* Copyright (C) 2000-2003, 2005-2009 Free Software Foundation, Inc.
This file is part of GNU Bash.
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/>.
*/
/* Written by Bruno Haible <bruno@clisp.org>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
/* Specification. */
#include "localcharset.h"
#if HAVE_STDDEF_H
# include <stddef.h>
#endif
#include <stdio.h>
#if HAVE_STRING_H
# include <string.h>
#else
# include <strings.h>
#endif
#if HAVE_STDLIB_H
# include <stdlib.h>
#endif
#if defined _WIN32 || defined __WIN32__
# undef WIN32 /* avoid warning on mingw32 */
# define WIN32
#endif
#if defined __EMX__
/* Assume EMX program runs on OS/2, even if compiled under DOS. */
# define OS2
#endif
#if !defined WIN32
# if HAVE_LANGINFO_CODESET
# include <langinfo.h>
# else
# if HAVE_SETLOCALE
# include <locale.h>
# endif
# endif
#elif defined WIN32
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
#endif
#if defined OS2
# define INCL_DOS
# include <os2.h>
#endif
#if ENABLE_RELOCATABLE
# include "relocatable.h"
#else
# define relocate(pathname) (pathname)
#endif
#if defined _WIN32 || defined __WIN32__ || defined __EMX__ || defined __DJGPP__
/* Win32, OS/2, DOS */
# define ISSLASH(C) ((C) == '/' || (C) == '\\')
#endif
#ifndef DIRECTORY_SEPARATOR
# define DIRECTORY_SEPARATOR '/'
#endif
#ifndef ISSLASH
# define ISSLASH(C) ((C) == DIRECTORY_SEPARATOR)
#endif
#ifdef HAVE_GETC_UNLOCKED
# undef getc
# define getc getc_unlocked
#endif
/* The following static variable is declared 'volatile' to avoid a
possible multithread problem in the function get_charset_aliases. If we
are running in a threaded environment, and if two threads initialize
'charset_aliases' simultaneously, both will produce the same value,
and everything will be ok if the two assignments to 'charset_aliases'
are atomic. But I don't know what will happen if the two assignments mix. */
#if __STDC__ != 1
# define volatile /* empty */
#endif
/* Pointer to the contents of the charset.alias file, if it has already been
read, else NULL. Its format is:
ALIAS_1 '\0' CANONICAL_1 '\0' ... ALIAS_n '\0' CANONICAL_n '\0' '\0' */
static const char * volatile charset_aliases;
/* Return a pointer to the contents of the charset.alias file. */
static const char *
get_charset_aliases ()
{
const char *cp;
cp = charset_aliases;
if (cp == NULL)
{
#if !(defined VMS || defined WIN32)
FILE *fp;
const char *dir = relocate (LIBDIR);
const char *base = "charset.alias";
char *file_name;
/* Concatenate dir and base into freshly allocated file_name. */
{
size_t dir_len = strlen (dir);
size_t base_len = strlen (base);
int add_slash = (dir_len > 0 && !ISSLASH (dir[dir_len - 1]));
file_name = (char *) malloc (dir_len + add_slash + base_len + 1);
if (file_name != NULL)
{
memcpy (file_name, dir, dir_len);
if (add_slash)
file_name[dir_len] = DIRECTORY_SEPARATOR;
memcpy (file_name + dir_len + add_slash, base, base_len + 1);
}
}
if (file_name == NULL || (fp = fopen (file_name, "r")) == NULL)
/* Out of memory or file not found, treat it as empty. */
cp = "";
else
{
/* Parse the file's contents. */
int c;
char buf1[50+1];
char buf2[50+1];
char *res_ptr = NULL;
size_t res_size = 0;
size_t l1, l2;
for (;;)
{
c = getc (fp);
if (c == EOF)
break;
if (c == '\n' || c == ' ' || c == '\t')
continue;
if (c == '#')
{
/* Skip comment, to end of line. */
do
c = getc (fp);
while (!(c == EOF || c == '\n'));
if (c == EOF)
break;
continue;
}
ungetc (c, fp);
if (fscanf (fp, "%50s %50s", buf1, buf2) < 2)
break;
l1 = strlen (buf1);
l2 = strlen (buf2);
if (res_size == 0)
{
res_size = l1 + 1 + l2 + 1;
res_ptr = (char *) malloc (res_size + 1);
}
else
{
res_size += l1 + 1 + l2 + 1;
res_ptr = (char *) realloc (res_ptr, res_size + 1);
}
if (res_ptr == NULL)
{
/* Out of memory. */
res_size = 0;
break;
}
strcpy (res_ptr + res_size - (l2 + 1) - (l1 + 1), buf1);
strcpy (res_ptr + res_size - (l2 + 1), buf2);
}
fclose (fp);
if (res_size == 0)
cp = "";
else
{
*(res_ptr + res_size) = '\0';
cp = res_ptr;
}
}
if (file_name != NULL)
free (file_name);
#else
# if defined VMS
/* To avoid the troubles of an extra file charset.alias_vms in the
sources of many GNU packages, simply inline the aliases here. */
/* The list of encodings is taken from the OpenVMS 7.3-1 documentation
"Compaq C Run-Time Library Reference Manual for OpenVMS systems"
section 10.7 "Handling Different Character Sets". */
cp = "ISO8859-1" "\0" "ISO-8859-1" "\0"
"ISO8859-2" "\0" "ISO-8859-2" "\0"
"ISO8859-5" "\0" "ISO-8859-5" "\0"
"ISO8859-7" "\0" "ISO-8859-7" "\0"
"ISO8859-8" "\0" "ISO-8859-8" "\0"
"ISO8859-9" "\0" "ISO-8859-9" "\0"
/* Japanese */
"eucJP" "\0" "EUC-JP" "\0"
"SJIS" "\0" "SHIFT_JIS" "\0"
"DECKANJI" "\0" "DEC-KANJI" "\0"
"SDECKANJI" "\0" "EUC-JP" "\0"
/* Chinese */
"eucTW" "\0" "EUC-TW" "\0"
"DECHANYU" "\0" "DEC-HANYU" "\0"
"DECHANZI" "\0" "GB2312" "\0"
/* Korean */
"DECKOREAN" "\0" "EUC-KR" "\0";
# endif
# if defined WIN32
/* To avoid the troubles of installing a separate file in the same
directory as the DLL and of retrieving the DLL's directory at
runtime, simply inline the aliases here. */
cp = "CP936" "\0" "GBK" "\0"
"CP1361" "\0" "JOHAB" "\0"
"CP20127" "\0" "ASCII" "\0"
"CP20866" "\0" "KOI8-R" "\0"
"CP21866" "\0" "KOI8-RU" "\0"
"CP28591" "\0" "ISO-8859-1" "\0"
"CP28592" "\0" "ISO-8859-2" "\0"
"CP28593" "\0" "ISO-8859-3" "\0"
"CP28594" "\0" "ISO-8859-4" "\0"
"CP28595" "\0" "ISO-8859-5" "\0"
"CP28596" "\0" "ISO-8859-6" "\0"
"CP28597" "\0" "ISO-8859-7" "\0"
"CP28598" "\0" "ISO-8859-8" "\0"
"CP28599" "\0" "ISO-8859-9" "\0"
"CP28605" "\0" "ISO-8859-15" "\0";
# endif
#endif
charset_aliases = cp;
}
return cp;
}
/* Determine the current locale's character encoding, and canonicalize it
into one of the canonical names listed in config.charset.
The result must not be freed; it is statically allocated.
If the canonical name cannot be determined, the result is a non-canonical
name. */
#ifdef STATIC
STATIC
#endif
const char *
locale_charset ()
{
const char *codeset;
const char *aliases;
#if !(defined WIN32 || defined OS2)
# if HAVE_LANGINFO_CODESET
/* Most systems support nl_langinfo (CODESET) nowadays. */
codeset = nl_langinfo (CODESET);
# else
/* On old systems which lack it, use setlocale or getenv. */
const char *locale = NULL;
/* But most old systems don't have a complete set of locales. Some
(like SunOS 4 or DJGPP) have only the C locale. Therefore we don't
use setlocale here; it would return "C" when it doesn't support the
locale name the user has set. */
# if HAVE_SETLOCALE && 0
locale = setlocale (LC_CTYPE, NULL);
# endif
if (locale == NULL || locale[0] == '\0')
{
locale = getenv ("LC_ALL");
if (locale == NULL || locale[0] == '\0')
{
locale = getenv ("LC_CTYPE");
if (locale == NULL || locale[0] == '\0')
locale = getenv ("LANG");
}
}
/* On some old systems, one used to set locale = "iso8859_1". On others,
you set it to "language_COUNTRY.charset". In any case, we resolve it
through the charset.alias file. */
codeset = locale;
# endif
#elif defined WIN32
static char buf[2 + 10 + 1];
/* Woe32 has a function returning the locale's codepage as a number. */
sprintf (buf, "CP%u", GetACP ());
codeset = buf;
#elif defined OS2
const char *locale;
static char buf[2 + 10 + 1];
ULONG cp[3];
ULONG cplen;
/* Allow user to override the codeset, as set in the operating system,
with standard language environment variables. */
locale = getenv ("LC_ALL");
if (locale == NULL || locale[0] == '\0')
{
locale = getenv ("LC_CTYPE");
if (locale == NULL || locale[0] == '\0')
locale = getenv ("LANG");
}
if (locale != NULL && locale[0] != '\0')
{
/* If the locale name contains an encoding after the dot, return it. */
const char *dot = strchr (locale, '.');
if (dot != NULL)
{
const char *modifier;
dot++;
/* Look for the possible @... trailer and remove it, if any. */
modifier = strchr (dot, '@');
if (modifier == NULL)
return dot;
if (modifier - dot < sizeof (buf))
{
memcpy (buf, dot, modifier - dot);
buf [modifier - dot] = '\0';
return buf;
}
}
/* Resolve through the charset.alias file. */
codeset = locale;
}
else
{
/* OS/2 has a function returning the locale's codepage as a number. */
if (DosQueryCp (sizeof (cp), cp, &cplen))
codeset = "";
else
{
sprintf (buf, "CP%u", cp[0]);
codeset = buf;
}
}
#endif
if (codeset == NULL)
/* The canonical name cannot be determined. */
codeset = "";
/* Resolve alias. */
for (aliases = get_charset_aliases ();
*aliases != '\0';
aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1)
if (strcmp (codeset, aliases) == 0
|| (aliases[0] == '*' && aliases[1] == '\0'))
{
codeset = aliases + strlen (aliases) + 1;
break;
}
/* Don't return an empty string. GNU libc and GNU libiconv interpret
the empty string as denoting "the locale's character encoding",
thus GNU libiconv would call this function a second time. */
if (codeset[0] == '\0')
codeset = "ASCII";
return codeset;
}

43
lib/intl/localcharset.h Normal file
View file

@ -0,0 +1,43 @@
/* localcharset.h - Determine a canonical name for the current locale's character encoding. */
/* Copyright (C) 2000-2003, 2005-2009 Free Software Foundation, Inc.
This file is part of GNU Bash.
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/>.
*/
#ifndef _LOCALCHARSET_H
#define _LOCALCHARSET_H
#ifdef __cplusplus
extern "C" {
#endif
/* Determine the current locale's character encoding, and canonicalize it
into one of the canonical names listed in config.charset.
The result must not be freed; it is statically allocated.
If the canonical name cannot be determined, the result is a non-canonical
name. */
extern const char * locale_charset (void);
#ifdef __cplusplus
}
#endif
#endif /* _LOCALCHARSET_H */

78
lib/intl/locale.alias Normal file
View file

@ -0,0 +1,78 @@
# locale.alias - Locale name alias data base.
#
# Copyright (C) 1996,1997,1998,1999,2000,2001,2005-2009 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
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
#
# The format of this file is the same as for the corresponding file of
# the X Window System, which normally can be found in
# /usr/lib/X11/locale/locale.alias
# A single line contains two fields: an alias and a substitution value.
# All entries are case independent.
# Note: This file is far from being complete. If you have a value for
# your own site which you think might be useful for others too, share
# it with the rest of us. Send it using the `glibcbug' script to
# bugs@gnu.org.
# Packages using this file:
bokmal no_NO.ISO-8859-1
bokmål no_NO.ISO-8859-1
catalan ca_ES.ISO-8859-1
croatian hr_HR.ISO-8859-2
czech cs_CZ.ISO-8859-2
danish da_DK.ISO-8859-1
dansk da_DK.ISO-8859-1
deutsch de_DE.ISO-8859-1
dutch nl_NL.ISO-8859-1
eesti et_EE.ISO-8859-1
estonian et_EE.ISO-8859-1
finnish fi_FI.ISO-8859-1
français fr_FR.ISO-8859-1
french fr_FR.ISO-8859-1
galego gl_ES.ISO-8859-1
galician gl_ES.ISO-8859-1
german de_DE.ISO-8859-1
greek el_GR.ISO-8859-7
hebrew he_IL.ISO-8859-8
hrvatski hr_HR.ISO-8859-2
hungarian hu_HU.ISO-8859-2
icelandic is_IS.ISO-8859-1
italian it_IT.ISO-8859-1
japanese ja_JP.eucJP
japanese.euc ja_JP.eucJP
ja_JP ja_JP.eucJP
ja_JP.ujis ja_JP.eucJP
japanese.sjis ja_JP.SJIS
korean ko_KR.eucKR
korean.euc ko_KR.eucKR
ko_KR ko_KR.eucKR
lithuanian lt_LT.ISO-8859-13
nb_NO no_NO.ISO-8859-1
nb_NO.ISO-8859-1 no_NO.ISO-8859-1
norwegian no_NO.ISO-8859-1
nynorsk nn_NO.ISO-8859-1
polish pl_PL.ISO-8859-2
portuguese pt_PT.ISO-8859-1
romanian ro_RO.ISO-8859-2
russian ru_RU.ISO-8859-5
slovak sk_SK.ISO-8859-2
slovene sl_SI.ISO-8859-2
slovenian sl_SI.ISO-8859-2
spanish es_ES.ISO-8859-1
swedish sv_SE.ISO-8859-1
thai th_TH.TIS-620
turkish tr_TR.ISO-8859-9

427
lib/intl/localealias.c Normal file
View file

@ -0,0 +1,427 @@
/* localealias.c - Handle aliases for locale names. */
/* Copyright (C) 1995-1999, 2000-2001, 2003, 2005-2009 Free Software Foundation, Inc.
This file is part of GNU Bash.
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/>.
*/
/* Tell glibc's <string.h> to provide a prototype for mempcpy().
This must come before <config.h> because <config.h> may include
<features.h>, and once <features.h> has been included, it's too late. */
#ifndef _GNU_SOURCE
# define _GNU_SOURCE 1
#endif
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <ctype.h>
#include <stdio.h>
#if defined _LIBC || defined HAVE___FSETLOCKING
# include <stdio_ext.h>
#endif
#include <sys/types.h>
#ifdef __GNUC__
# undef alloca
# define alloca __builtin_alloca
# define HAVE_ALLOCA 1
#else
# ifdef _MSC_VER
# include <malloc.h>
# define alloca _alloca
# else
# if defined HAVE_ALLOCA_H || defined _LIBC
# include <alloca.h>
# else
# ifdef _AIX
#pragma alloca
# else
# ifndef alloca
char *alloca ();
# endif
# endif
# endif
# endif
#endif
#include <stdlib.h>
#include <string.h>
#include "gettextP.h"
#if ENABLE_RELOCATABLE
# include "relocatable.h"
#else
# define relocate(pathname) (pathname)
#endif
/* @@ end of prolog @@ */
#ifdef _LIBC
/* Rename the non ANSI C functions. This is required by the standard
because some ANSI C functions will require linking with this object
file and the name space must not be polluted. */
# define strcasecmp __strcasecmp
# ifndef mempcpy
# define mempcpy __mempcpy
# endif
# define HAVE_MEMPCPY 1
# define HAVE___FSETLOCKING 1
/* We need locking here since we can be called from different places. */
# include <bits/libc-lock.h>
__libc_lock_define_initialized (static, lock);
#endif
#ifndef internal_function
# define internal_function
#endif
/* Some optimizations for glibc. */
#ifdef _LIBC
# define FEOF(fp) feof_unlocked (fp)
# define FGETS(buf, n, fp) fgets_unlocked (buf, n, fp)
#else
# define FEOF(fp) feof (fp)
# define FGETS(buf, n, fp) fgets (buf, n, fp)
#endif
/* For those losing systems which don't have `alloca' we have to add
some additional code emulating it. */
#ifdef HAVE_ALLOCA
# define freea(p) /* nothing */
#else
# define alloca(n) malloc (n)
# define freea(p) free (p)
#endif
#if defined _LIBC_REENTRANT || defined HAVE_FGETS_UNLOCKED
# undef fgets
# define fgets(buf, len, s) fgets_unlocked (buf, len, s)
#endif
#if defined _LIBC_REENTRANT || defined HAVE_FEOF_UNLOCKED
# undef feof
# define feof(s) feof_unlocked (s)
#endif
struct alias_map
{
const char *alias;
const char *value;
};
#ifndef _LIBC
# define libc_freeres_ptr(decl) decl
#endif
libc_freeres_ptr (static char *string_space);
static size_t string_space_act;
static size_t string_space_max;
libc_freeres_ptr (static struct alias_map *map);
static size_t nmap;
static size_t maxmap;
/* Prototypes for local functions. */
static size_t read_alias_file PARAMS ((const char *fname, int fname_len))
internal_function;
static int extend_alias_table PARAMS ((void));
static int alias_compare PARAMS ((const struct alias_map *map1,
const struct alias_map *map2));
const char *
_nl_expand_alias (name)
const char *name;
{
static const char *locale_alias_path;
struct alias_map *retval;
const char *result = NULL;
size_t added;
#ifdef _LIBC
__libc_lock_lock (lock);
#endif
if (locale_alias_path == NULL)
locale_alias_path = LOCALE_ALIAS_PATH;
do
{
struct alias_map item;
item.alias = name;
if (nmap > 0)
retval = (struct alias_map *) bsearch (&item, map, nmap,
sizeof (struct alias_map),
(int (*) PARAMS ((const void *,
const void *))
) alias_compare);
else
retval = NULL;
/* We really found an alias. Return the value. */
if (retval != NULL)
{
result = retval->value;
break;
}
/* Perhaps we can find another alias file. */
added = 0;
while (added == 0 && locale_alias_path[0] != '\0')
{
const char *start;
while (locale_alias_path[0] == PATH_SEPARATOR)
++locale_alias_path;
start = locale_alias_path;
while (locale_alias_path[0] != '\0'
&& locale_alias_path[0] != PATH_SEPARATOR)
++locale_alias_path;
if (start < locale_alias_path)
added = read_alias_file (start, locale_alias_path - start);
}
}
while (added != 0);
#ifdef _LIBC
__libc_lock_unlock (lock);
#endif
return result;
}
static size_t
internal_function
read_alias_file (fname, fname_len)
const char *fname;
int fname_len;
{
FILE *fp;
char *full_fname;
size_t added;
static const char aliasfile[] = "/locale.alias";
full_fname = (char *) alloca (fname_len + sizeof aliasfile);
#ifdef HAVE_MEMPCPY
mempcpy (mempcpy (full_fname, fname, fname_len),
aliasfile, sizeof aliasfile);
#else
memcpy (full_fname, fname, fname_len);
memcpy (&full_fname[fname_len], aliasfile, sizeof aliasfile);
#endif
fp = fopen (relocate (full_fname), "r");
freea (full_fname);
if (fp == NULL)
return 0;
#ifdef HAVE___FSETLOCKING
/* No threads present. */
__fsetlocking (fp, FSETLOCKING_BYCALLER);
#endif
added = 0;
while (!FEOF (fp))
{
/* It is a reasonable approach to use a fix buffer here because
a) we are only interested in the first two fields
b) these fields must be usable as file names and so must not
be that long
We avoid a multi-kilobyte buffer here since this would use up
stack space which we might not have if the program ran out of
memory. */
char buf[400];
char *alias;
char *value;
char *cp;
if (FGETS (buf, sizeof buf, fp) == NULL)
/* EOF reached. */
break;
cp = buf;
/* Ignore leading white space. */
while (isspace ((unsigned char) cp[0]))
++cp;
/* A leading '#' signals a comment line. */
if (cp[0] != '\0' && cp[0] != '#')
{
alias = cp++;
while (cp[0] != '\0' && !isspace ((unsigned char) cp[0]))
++cp;
/* Terminate alias name. */
if (cp[0] != '\0')
*cp++ = '\0';
/* Now look for the beginning of the value. */
while (isspace ((unsigned char) cp[0]))
++cp;
if (cp[0] != '\0')
{
size_t alias_len;
size_t value_len;
value = cp++;
while (cp[0] != '\0' && !isspace ((unsigned char) cp[0]))
++cp;
/* Terminate value. */
if (cp[0] == '\n')
{
/* This has to be done to make the following test
for the end of line possible. We are looking for
the terminating '\n' which do not overwrite here. */
*cp++ = '\0';
*cp = '\n';
}
else if (cp[0] != '\0')
*cp++ = '\0';
if (nmap >= maxmap)
if (__builtin_expect (extend_alias_table (), 0))
{
fclose (fp);
return added;
}
alias_len = strlen (alias) + 1;
value_len = strlen (value) + 1;
if (string_space_act + alias_len + value_len > string_space_max)
{
/* Increase size of memory pool. */
size_t new_size = (string_space_max
+ (alias_len + value_len > 1024
? alias_len + value_len : 1024));
char *new_pool = (char *) realloc (string_space, new_size);
if (new_pool == NULL)
{
fclose (fp);
return added;
}
if (__builtin_expect (string_space != new_pool, 0))
{
size_t i;
for (i = 0; i < nmap; i++)
{
map[i].alias += new_pool - string_space;
map[i].value += new_pool - string_space;
}
}
string_space = new_pool;
string_space_max = new_size;
}
map[nmap].alias = memcpy (&string_space[string_space_act],
alias, alias_len);
string_space_act += alias_len;
map[nmap].value = memcpy (&string_space[string_space_act],
value, value_len);
string_space_act += value_len;
++nmap;
++added;
}
}
/* Possibly not the whole line fits into the buffer. Ignore
the rest of the line. */
while (strchr (buf, '\n') == NULL)
if (FGETS (buf, sizeof buf, fp) == NULL)
/* Make sure the inner loop will be left. The outer loop
will exit at the `feof' test. */
break;
}
/* Should we test for ferror()? I think we have to silently ignore
errors. --drepper */
fclose (fp);
if (added > 0)
qsort (map, nmap, sizeof (struct alias_map),
(int (*) PARAMS ((const void *, const void *))) alias_compare);
return added;
}
static int
extend_alias_table ()
{
size_t new_size;
struct alias_map *new_map;
new_size = maxmap == 0 ? 100 : 2 * maxmap;
new_map = (struct alias_map *) realloc (map, (new_size
* sizeof (struct alias_map)));
if (new_map == NULL)
/* Simply don't extend: we don't have any more core. */
return -1;
map = new_map;
maxmap = new_size;
return 0;
}
static int
alias_compare (map1, map2)
const struct alias_map *map1;
const struct alias_map *map2;
{
#if defined _LIBC || defined HAVE_STRCASECMP
return strcasecmp (map1->alias, map2->alias);
#else
const unsigned char *p1 = (const unsigned char *) map1->alias;
const unsigned char *p2 = (const unsigned char *) map2->alias;
unsigned char c1, c2;
if (p1 == p2)
return 0;
do
{
/* I know this seems to be odd but the tolower() function in
some systems libc cannot handle nonalpha characters. */
c1 = isupper (*p1) ? tolower (*p1) : *p1;
c2 = isupper (*p2) ? tolower (*p2) : *p2;
if (c1 == '\0')
break;
++p1;
++p2;
}
while (c1 == c2);
return c1 - c2;
#endif
}

774
lib/intl/localename.c Normal file
View file

@ -0,0 +1,774 @@
/* localename.c - Determine the current selected locale. */
/* Copyright (C) 1995-1999, 2000-2002, 2005-2009 Free Software Foundation, Inc.
This file is part of GNU Bash.
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/>.
*/
/* Written by Ulrich Drepper <drepper@gnu.org>, 1995. */
/* Win32 code written by Tor Lillqvist <tml@iki.fi>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <locale.h>
#if defined _WIN32 || defined __WIN32__
# undef WIN32 /* avoid warning on mingw32 */
# define WIN32
#endif
#ifdef WIN32
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
/* Mingw headers don't have latest language and sublanguage codes. */
# ifndef LANG_AFRIKAANS
# define LANG_AFRIKAANS 0x36
# endif
# ifndef LANG_ALBANIAN
# define LANG_ALBANIAN 0x1c
# endif
# ifndef LANG_ARABIC
# define LANG_ARABIC 0x01
# endif
# ifndef LANG_ARMENIAN
# define LANG_ARMENIAN 0x2b
# endif
# ifndef LANG_ASSAMESE
# define LANG_ASSAMESE 0x4d
# endif
# ifndef LANG_AZERI
# define LANG_AZERI 0x2c
# endif
# ifndef LANG_BASQUE
# define LANG_BASQUE 0x2d
# endif
# ifndef LANG_BELARUSIAN
# define LANG_BELARUSIAN 0x23
# endif
# ifndef LANG_BENGALI
# define LANG_BENGALI 0x45
# endif
# ifndef LANG_CATALAN
# define LANG_CATALAN 0x03
# endif
# ifndef LANG_DIVEHI
# define LANG_DIVEHI 0x65
# endif
# ifndef LANG_ESTONIAN
# define LANG_ESTONIAN 0x25
# endif
# ifndef LANG_FAEROESE
# define LANG_FAEROESE 0x38
# endif
# ifndef LANG_FARSI
# define LANG_FARSI 0x29
# endif
# ifndef LANG_GALICIAN
# define LANG_GALICIAN 0x56
# endif
# ifndef LANG_GEORGIAN
# define LANG_GEORGIAN 0x37
# endif
# ifndef LANG_GUJARATI
# define LANG_GUJARATI 0x47
# endif
# ifndef LANG_HEBREW
# define LANG_HEBREW 0x0d
# endif
# ifndef LANG_HINDI
# define LANG_HINDI 0x39
# endif
# ifndef LANG_INDONESIAN
# define LANG_INDONESIAN 0x21
# endif
# ifndef LANG_KANNADA
# define LANG_KANNADA 0x4b
# endif
# ifndef LANG_KASHMIRI
# define LANG_KASHMIRI 0x60
# endif
# ifndef LANG_KAZAK
# define LANG_KAZAK 0x3f
# endif
# ifndef LANG_KONKANI
# define LANG_KONKANI 0x57
# endif
# ifndef LANG_KYRGYZ
# define LANG_KYRGYZ 0x40
# endif
# ifndef LANG_LATVIAN
# define LANG_LATVIAN 0x26
# endif
# ifndef LANG_LITHUANIAN
# define LANG_LITHUANIAN 0x27
# endif
# ifndef LANG_MACEDONIAN
# define LANG_MACEDONIAN 0x2f
# endif
# ifndef LANG_MALAY
# define LANG_MALAY 0x3e
# endif
# ifndef LANG_MALAYALAM
# define LANG_MALAYALAM 0x4c
# endif
# ifndef LANG_MANIPURI
# define LANG_MANIPURI 0x58
# endif
# ifndef LANG_MARATHI
# define LANG_MARATHI 0x4e
# endif
# ifndef LANG_MONGOLIAN
# define LANG_MONGOLIAN 0x50
# endif
# ifndef LANG_NEPALI
# define LANG_NEPALI 0x61
# endif
# ifndef LANG_ORIYA
# define LANG_ORIYA 0x48
# endif
# ifndef LANG_PUNJABI
# define LANG_PUNJABI 0x46
# endif
# ifndef LANG_SANSKRIT
# define LANG_SANSKRIT 0x4f
# endif
# ifndef LANG_SERBIAN
# define LANG_SERBIAN 0x1a
# endif
# ifndef LANG_SINDHI
# define LANG_SINDHI 0x59
# endif
# ifndef LANG_SLOVAK
# define LANG_SLOVAK 0x1b
# endif
# ifndef LANG_SORBIAN
# define LANG_SORBIAN 0x2e
# endif
# ifndef LANG_SWAHILI
# define LANG_SWAHILI 0x41
# endif
# ifndef LANG_SYRIAC
# define LANG_SYRIAC 0x5a
# endif
# ifndef LANG_TAMIL
# define LANG_TAMIL 0x49
# endif
# ifndef LANG_TATAR
# define LANG_TATAR 0x44
# endif
# ifndef LANG_TELUGU
# define LANG_TELUGU 0x4a
# endif
# ifndef LANG_THAI
# define LANG_THAI 0x1e
# endif
# ifndef LANG_UKRAINIAN
# define LANG_UKRAINIAN 0x22
# endif
# ifndef LANG_URDU
# define LANG_URDU 0x20
# endif
# ifndef LANG_UZBEK
# define LANG_UZBEK 0x43
# endif
# ifndef LANG_VIETNAMESE
# define LANG_VIETNAMESE 0x2a
# endif
# ifndef SUBLANG_ARABIC_SAUDI_ARABIA
# define SUBLANG_ARABIC_SAUDI_ARABIA 0x01
# endif
# ifndef SUBLANG_ARABIC_IRAQ
# define SUBLANG_ARABIC_IRAQ 0x02
# endif
# ifndef SUBLANG_ARABIC_EGYPT
# define SUBLANG_ARABIC_EGYPT 0x03
# endif
# ifndef SUBLANG_ARABIC_LIBYA
# define SUBLANG_ARABIC_LIBYA 0x04
# endif
# ifndef SUBLANG_ARABIC_ALGERIA
# define SUBLANG_ARABIC_ALGERIA 0x05
# endif
# ifndef SUBLANG_ARABIC_MOROCCO
# define SUBLANG_ARABIC_MOROCCO 0x06
# endif
# ifndef SUBLANG_ARABIC_TUNISIA
# define SUBLANG_ARABIC_TUNISIA 0x07
# endif
# ifndef SUBLANG_ARABIC_OMAN
# define SUBLANG_ARABIC_OMAN 0x08
# endif
# ifndef SUBLANG_ARABIC_YEMEN
# define SUBLANG_ARABIC_YEMEN 0x09
# endif
# ifndef SUBLANG_ARABIC_SYRIA
# define SUBLANG_ARABIC_SYRIA 0x0a
# endif
# ifndef SUBLANG_ARABIC_JORDAN
# define SUBLANG_ARABIC_JORDAN 0x0b
# endif
# ifndef SUBLANG_ARABIC_LEBANON
# define SUBLANG_ARABIC_LEBANON 0x0c
# endif
# ifndef SUBLANG_ARABIC_KUWAIT
# define SUBLANG_ARABIC_KUWAIT 0x0d
# endif
# ifndef SUBLANG_ARABIC_UAE
# define SUBLANG_ARABIC_UAE 0x0e
# endif
# ifndef SUBLANG_ARABIC_BAHRAIN
# define SUBLANG_ARABIC_BAHRAIN 0x0f
# endif
# ifndef SUBLANG_ARABIC_QATAR
# define SUBLANG_ARABIC_QATAR 0x10
# endif
# ifndef SUBLANG_AZERI_LATIN
# define SUBLANG_AZERI_LATIN 0x01
# endif
# ifndef SUBLANG_AZERI_CYRILLIC
# define SUBLANG_AZERI_CYRILLIC 0x02
# endif
# ifndef SUBLANG_CHINESE_MACAU
# define SUBLANG_CHINESE_MACAU 0x05
# endif
# ifndef SUBLANG_ENGLISH_SOUTH_AFRICA
# define SUBLANG_ENGLISH_SOUTH_AFRICA 0x07
# endif
# ifndef SUBLANG_ENGLISH_JAMAICA
# define SUBLANG_ENGLISH_JAMAICA 0x08
# endif
# ifndef SUBLANG_ENGLISH_CARIBBEAN
# define SUBLANG_ENGLISH_CARIBBEAN 0x09
# endif
# ifndef SUBLANG_ENGLISH_BELIZE
# define SUBLANG_ENGLISH_BELIZE 0x0a
# endif
# ifndef SUBLANG_ENGLISH_TRINIDAD
# define SUBLANG_ENGLISH_TRINIDAD 0x0b
# endif
# ifndef SUBLANG_ENGLISH_ZIMBABWE
# define SUBLANG_ENGLISH_ZIMBABWE 0x0c
# endif
# ifndef SUBLANG_ENGLISH_PHILIPPINES
# define SUBLANG_ENGLISH_PHILIPPINES 0x0d
# endif
# ifndef SUBLANG_FRENCH_LUXEMBOURG
# define SUBLANG_FRENCH_LUXEMBOURG 0x05
# endif
# ifndef SUBLANG_FRENCH_MONACO
# define SUBLANG_FRENCH_MONACO 0x06
# endif
# ifndef SUBLANG_GERMAN_LUXEMBOURG
# define SUBLANG_GERMAN_LUXEMBOURG 0x04
# endif
# ifndef SUBLANG_GERMAN_LIECHTENSTEIN
# define SUBLANG_GERMAN_LIECHTENSTEIN 0x05
# endif
# ifndef SUBLANG_KASHMIRI_INDIA
# define SUBLANG_KASHMIRI_INDIA 0x02
# endif
# ifndef SUBLANG_MALAY_MALAYSIA
# define SUBLANG_MALAY_MALAYSIA 0x01
# endif
# ifndef SUBLANG_MALAY_BRUNEI_DARUSSALAM
# define SUBLANG_MALAY_BRUNEI_DARUSSALAM 0x02
# endif
# ifndef SUBLANG_NEPALI_INDIA
# define SUBLANG_NEPALI_INDIA 0x02
# endif
# ifndef SUBLANG_SERBIAN_LATIN
# define SUBLANG_SERBIAN_LATIN 0x02
# endif
# ifndef SUBLANG_SERBIAN_CYRILLIC
# define SUBLANG_SERBIAN_CYRILLIC 0x03
# endif
# ifndef SUBLANG_SPANISH_GUATEMALA
# define SUBLANG_SPANISH_GUATEMALA 0x04
# endif
# ifndef SUBLANG_SPANISH_COSTA_RICA
# define SUBLANG_SPANISH_COSTA_RICA 0x05
# endif
# ifndef SUBLANG_SPANISH_PANAMA
# define SUBLANG_SPANISH_PANAMA 0x06
# endif
# ifndef SUBLANG_SPANISH_DOMINICAN_REPUBLIC
# define SUBLANG_SPANISH_DOMINICAN_REPUBLIC 0x07
# endif
# ifndef SUBLANG_SPANISH_VENEZUELA
# define SUBLANG_SPANISH_VENEZUELA 0x08
# endif
# ifndef SUBLANG_SPANISH_COLOMBIA
# define SUBLANG_SPANISH_COLOMBIA 0x09
# endif
# ifndef SUBLANG_SPANISH_PERU
# define SUBLANG_SPANISH_PERU 0x0a
# endif
# ifndef SUBLANG_SPANISH_ARGENTINA
# define SUBLANG_SPANISH_ARGENTINA 0x0b
# endif
# ifndef SUBLANG_SPANISH_ECUADOR
# define SUBLANG_SPANISH_ECUADOR 0x0c
# endif
# ifndef SUBLANG_SPANISH_CHILE
# define SUBLANG_SPANISH_CHILE 0x0d
# endif
# ifndef SUBLANG_SPANISH_URUGUAY
# define SUBLANG_SPANISH_URUGUAY 0x0e
# endif
# ifndef SUBLANG_SPANISH_PARAGUAY
# define SUBLANG_SPANISH_PARAGUAY 0x0f
# endif
# ifndef SUBLANG_SPANISH_BOLIVIA
# define SUBLANG_SPANISH_BOLIVIA 0x10
# endif
# ifndef SUBLANG_SPANISH_EL_SALVADOR
# define SUBLANG_SPANISH_EL_SALVADOR 0x11
# endif
# ifndef SUBLANG_SPANISH_HONDURAS
# define SUBLANG_SPANISH_HONDURAS 0x12
# endif
# ifndef SUBLANG_SPANISH_NICARAGUA
# define SUBLANG_SPANISH_NICARAGUA 0x13
# endif
# ifndef SUBLANG_SPANISH_PUERTO_RICO
# define SUBLANG_SPANISH_PUERTO_RICO 0x14
# endif
# ifndef SUBLANG_SWEDISH_FINLAND
# define SUBLANG_SWEDISH_FINLAND 0x02
# endif
# ifndef SUBLANG_URDU_PAKISTAN
# define SUBLANG_URDU_PAKISTAN 0x01
# endif
# ifndef SUBLANG_URDU_INDIA
# define SUBLANG_URDU_INDIA 0x02
# endif
# ifndef SUBLANG_UZBEK_LATIN
# define SUBLANG_UZBEK_LATIN 0x01
# endif
# ifndef SUBLANG_UZBEK_CYRILLIC
# define SUBLANG_UZBEK_CYRILLIC 0x02
# endif
#endif
/* XPG3 defines the result of 'setlocale (category, NULL)' as:
"Directs 'setlocale()' to query 'category' and return the current
setting of 'local'."
However it does not specify the exact format. Neither do SUSV2 and
ISO C 99. So we can use this feature only on selected systems (e.g.
those using GNU C Library). */
#if defined _LIBC || (defined __GNU_LIBRARY__ && __GNU_LIBRARY__ >= 2)
# define HAVE_LOCALE_NULL
#endif
/* Determine the current locale's name, and canonicalize it into XPG syntax
language[_territory[.codeset]][@modifier]
The codeset part in the result is not reliable; the locale_charset()
should be used for codeset information instead.
The result must not be freed; it is statically allocated. */
const char *
_nl_locale_name (category, categoryname)
int category;
const char *categoryname;
{
const char *retval;
#ifndef WIN32
/* Use the POSIX methods of looking to 'LC_ALL', 'LC_xxx', and 'LANG'.
On some systems this can be done by the 'setlocale' function itself. */
# if defined HAVE_SETLOCALE && defined HAVE_LC_MESSAGES && defined HAVE_LOCALE_NULL
retval = setlocale (category, NULL);
# else
/* Setting of LC_ALL overwrites all other. */
retval = getenv ("LC_ALL");
if (retval == NULL || retval[0] == '\0')
{
/* Next comes the name of the desired category. */
retval = getenv (categoryname);
if (retval == NULL || retval[0] == '\0')
{
/* Last possibility is the LANG environment variable. */
retval = getenv ("LANG");
if (retval == NULL || retval[0] == '\0')
/* We use C as the default domain. POSIX says this is
implementation defined. */
retval = "C";
}
}
# endif
return retval;
#else /* WIN32 */
/* Return an XPG style locale name language[_territory][@modifier].
Don't even bother determining the codeset; it's not useful in this
context, because message catalogs are not specific to a single
codeset. */
LCID lcid;
LANGID langid;
int primary, sub;
/* Let the user override the system settings through environment
variables, as on POSIX systems. */
retval = getenv ("LC_ALL");
if (retval != NULL && retval[0] != '\0')
return retval;
retval = getenv (categoryname);
if (retval != NULL && retval[0] != '\0')
return retval;
retval = getenv ("LANG");
if (retval != NULL && retval[0] != '\0')
return retval;
/* Use native Win32 API locale ID. */
lcid = GetThreadLocale ();
/* Strip off the sorting rules, keep only the language part. */
langid = LANGIDFROMLCID (lcid);
/* Split into language and territory part. */
primary = PRIMARYLANGID (langid);
sub = SUBLANGID (langid);
/* Dispatch on language.
See also http://www.unicode.org/unicode/onlinedat/languages.html .
For details about languages, see http://www.ethnologue.com/ . */
switch (primary)
{
case LANG_AFRIKAANS: return "af_ZA";
case LANG_ALBANIAN: return "sq_AL";
case 0x5e: /* AMHARIC */ return "am_ET";
case LANG_ARABIC:
switch (sub)
{
case SUBLANG_ARABIC_SAUDI_ARABIA: return "ar_SA";
case SUBLANG_ARABIC_IRAQ: return "ar_IQ";
case SUBLANG_ARABIC_EGYPT: return "ar_EG";
case SUBLANG_ARABIC_LIBYA: return "ar_LY";
case SUBLANG_ARABIC_ALGERIA: return "ar_DZ";
case SUBLANG_ARABIC_MOROCCO: return "ar_MA";
case SUBLANG_ARABIC_TUNISIA: return "ar_TN";
case SUBLANG_ARABIC_OMAN: return "ar_OM";
case SUBLANG_ARABIC_YEMEN: return "ar_YE";
case SUBLANG_ARABIC_SYRIA: return "ar_SY";
case SUBLANG_ARABIC_JORDAN: return "ar_JO";
case SUBLANG_ARABIC_LEBANON: return "ar_LB";
case SUBLANG_ARABIC_KUWAIT: return "ar_KW";
case SUBLANG_ARABIC_UAE: return "ar_AE";
case SUBLANG_ARABIC_BAHRAIN: return "ar_BH";
case SUBLANG_ARABIC_QATAR: return "ar_QA";
}
return "ar";
case LANG_ARMENIAN: return "hy_AM";
case LANG_ASSAMESE: return "as_IN";
case LANG_AZERI:
switch (sub)
{
/* FIXME: Adjust this when Azerbaijani locales appear on Unix. */
case SUBLANG_AZERI_LATIN: return "az_AZ@latin";
case SUBLANG_AZERI_CYRILLIC: return "az_AZ@cyrillic";
}
return "az";
case LANG_BASQUE:
return "eu"; /* Ambiguous: could be "eu_ES" or "eu_FR". */
case LANG_BELARUSIAN: return "be_BY";
case LANG_BENGALI: return "bn_IN";
case LANG_BULGARIAN: return "bg_BG";
case 0x55: /* BURMESE */ return "my_MM";
case 0x53: /* CAMBODIAN */ return "km_KH";
case LANG_CATALAN: return "ca_ES";
case 0x5c: /* CHEROKEE */ return "chr_US";
case LANG_CHINESE:
switch (sub)
{
case SUBLANG_CHINESE_TRADITIONAL: return "zh_TW";
case SUBLANG_CHINESE_SIMPLIFIED: return "zh_CN";
case SUBLANG_CHINESE_HONGKONG: return "zh_HK";
case SUBLANG_CHINESE_SINGAPORE: return "zh_SG";
case SUBLANG_CHINESE_MACAU: return "zh_MO";
}
return "zh";
case LANG_CROATIAN: /* LANG_CROATIAN == LANG_SERBIAN
* What used to be called Serbo-Croatian
* should really now be two separate
* languages because of political reasons.
* (Says tml, who knows nothing about Serbian
* or Croatian.)
* (I can feel those flames coming already.)
*/
switch (sub)
{
case SUBLANG_DEFAULT: return "hr_HR";
case SUBLANG_SERBIAN_LATIN: return "sr_YU";
case SUBLANG_SERBIAN_CYRILLIC: return "sr_YU@cyrillic";
}
return "hr";
case LANG_CZECH: return "cs_CZ";
case LANG_DANISH: return "da_DK";
case LANG_DIVEHI: return "div_MV";
case LANG_DUTCH:
switch (sub)
{
case SUBLANG_DUTCH: return "nl_NL";
case SUBLANG_DUTCH_BELGIAN: /* FLEMISH, VLAAMS */ return "nl_BE";
}
return "nl";
case 0x66: /* EDO */ return "bin_NG";
case LANG_ENGLISH:
switch (sub)
{
/* SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. Heh. I thought
* English was the language spoken in England.
* Oh well.
*/
case SUBLANG_ENGLISH_US: return "en_US";
case SUBLANG_ENGLISH_UK: return "en_GB";
case SUBLANG_ENGLISH_AUS: return "en_AU";
case SUBLANG_ENGLISH_CAN: return "en_CA";
case SUBLANG_ENGLISH_NZ: return "en_NZ";
case SUBLANG_ENGLISH_EIRE: return "en_IE";
case SUBLANG_ENGLISH_SOUTH_AFRICA: return "en_ZA";
case SUBLANG_ENGLISH_JAMAICA: return "en_JM";
case SUBLANG_ENGLISH_CARIBBEAN: return "en_GD"; /* Grenada? */
case SUBLANG_ENGLISH_BELIZE: return "en_BZ";
case SUBLANG_ENGLISH_TRINIDAD: return "en_TT";
case SUBLANG_ENGLISH_ZIMBABWE: return "en_ZW";
case SUBLANG_ENGLISH_PHILIPPINES: return "en_PH";
}
return "en";
case LANG_ESTONIAN: return "et_EE";
case LANG_FAEROESE: return "fo_FO";
case LANG_FARSI: return "fa_IR";
case LANG_FINNISH: return "fi_FI";
case LANG_FRENCH:
switch (sub)
{
case SUBLANG_FRENCH: return "fr_FR";
case SUBLANG_FRENCH_BELGIAN: /* WALLOON */ return "fr_BE";
case SUBLANG_FRENCH_CANADIAN: return "fr_CA";
case SUBLANG_FRENCH_SWISS: return "fr_CH";
case SUBLANG_FRENCH_LUXEMBOURG: return "fr_LU";
case SUBLANG_FRENCH_MONACO: return "fr_MC";
}
return "fr";
case 0x62: /* FRISIAN */ return "fy_NL";
case 0x67: /* FULFULDE */ return "ful_NG";
case 0x3c: /* GAELIC */
switch (sub)
{
case 0x01: /* SCOTTISH */ return "gd_GB";
case 0x02: /* IRISH */ return "ga_IE";
}
return "C";
case LANG_GALICIAN: return "gl_ES";
case LANG_GEORGIAN: return "ka_GE";
case LANG_GERMAN:
switch (sub)
{
case SUBLANG_GERMAN: return "de_DE";
case SUBLANG_GERMAN_SWISS: return "de_CH";
case SUBLANG_GERMAN_AUSTRIAN: return "de_AT";
case SUBLANG_GERMAN_LUXEMBOURG: return "de_LU";
case SUBLANG_GERMAN_LIECHTENSTEIN: return "de_LI";
}
return "de";
case LANG_GREEK: return "el_GR";
case 0x74: /* GUARANI */ return "gn_PY";
case LANG_GUJARATI: return "gu_IN";
case 0x68: /* HAUSA */ return "ha_NG";
case 0x75: /* HAWAIIAN */
/* FIXME: Do they mean Hawaiian ("haw_US", 1000 speakers)
or Hawaii Creole English ("cpe_US", 600000 speakers)? */
return "cpe_US";
case LANG_HEBREW: return "he_IL";
case LANG_HINDI: return "hi_IN";
case LANG_HUNGARIAN: return "hu_HU";
case 0x69: /* IBIBIO */ return "nic_NG";
case LANG_ICELANDIC: return "is_IS";
case 0x70: /* IGBO */ return "ibo_NG";
case LANG_INDONESIAN: return "id_ID";
case 0x5d: /* INUKTITUT */ return "iu_CA";
case LANG_ITALIAN:
switch (sub)
{
case SUBLANG_ITALIAN: return "it_IT";
case SUBLANG_ITALIAN_SWISS: return "it_CH";
}
return "it";
case LANG_JAPANESE: return "ja_JP";
case LANG_KANNADA: return "kn_IN";
case 0x71: /* KANURI */ return "kau_NG";
case LANG_KASHMIRI:
switch (sub)
{
case SUBLANG_DEFAULT: return "ks_PK";
case SUBLANG_KASHMIRI_INDIA: return "ks_IN";
}
return "ks";
case LANG_KAZAK: return "kk_KZ";
case LANG_KONKANI:
/* FIXME: Adjust this when such locales appear on Unix. */
return "kok_IN";
case LANG_KOREAN: return "ko_KR";
case LANG_KYRGYZ: return "ky_KG";
case 0x54: /* LAO */ return "lo_LA";
case 0x76: /* LATIN */ return "la_VA";
case LANG_LATVIAN: return "lv_LV";
case LANG_LITHUANIAN: return "lt_LT";
case LANG_MACEDONIAN: return "mk_MK";
case LANG_MALAY:
switch (sub)
{
case SUBLANG_MALAY_MALAYSIA: return "ms_MY";
case SUBLANG_MALAY_BRUNEI_DARUSSALAM: return "ms_BN";
}
return "ms";
case LANG_MALAYALAM: return "ml_IN";
case 0x3a: /* MALTESE */ return "mt_MT";
case LANG_MANIPURI:
/* FIXME: Adjust this when such locales appear on Unix. */
return "mni_IN";
case LANG_MARATHI: return "mr_IN";
case LANG_MONGOLIAN:
return "mn"; /* Ambiguous: could be "mn_CN" or "mn_MN". */
case LANG_NEPALI:
switch (sub)
{
case SUBLANG_DEFAULT: return "ne_NP";
case SUBLANG_NEPALI_INDIA: return "ne_IN";
}
return "ne";
case LANG_NORWEGIAN:
switch (sub)
{
case SUBLANG_NORWEGIAN_BOKMAL: return "no_NO";
case SUBLANG_NORWEGIAN_NYNORSK: return "nn_NO";
}
return "no";
case LANG_ORIYA: return "or_IN";
case 0x72: /* OROMO */ return "om_ET";
case 0x79: /* PAPIAMENTU */ return "pap_AN";
case 0x63: /* PASHTO */
return "ps"; /* Ambiguous: could be "ps_PK" or "ps_AF". */
case LANG_POLISH: return "pl_PL";
case LANG_PORTUGUESE:
switch (sub)
{
case SUBLANG_PORTUGUESE: return "pt_PT";
/* Hmm. SUBLANG_PORTUGUESE_BRAZILIAN == SUBLANG_DEFAULT.
Same phenomenon as SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. */
case SUBLANG_PORTUGUESE_BRAZILIAN: return "pt_BR";
}
return "pt";
case LANG_PUNJABI: return "pa_IN";
case 0x17: /* RHAETO-ROMANCE */ return "rm_CH";
case LANG_ROMANIAN: return "ro_RO";
case LANG_RUSSIAN:
return "ru"; /* Ambiguous: could be "ru_RU" or "ru_UA". */
case 0x3b: /* SAMI */ return "se_NO";
case LANG_SANSKRIT: return "sa_IN";
case LANG_SINDHI: return "sd";
case 0x5b: /* SINHALESE */ return "si_LK";
case LANG_SLOVAK: return "sk_SK";
case LANG_SLOVENIAN: return "sl_SI";
case 0x77: /* SOMALI */ return "so_SO";
case LANG_SORBIAN:
/* FIXME: Adjust this when such locales appear on Unix. */
return "wen_DE";
case LANG_SPANISH:
switch (sub)
{
case SUBLANG_SPANISH: return "es_ES";
case SUBLANG_SPANISH_MEXICAN: return "es_MX";
case SUBLANG_SPANISH_MODERN:
return "es_ES@modern"; /* not seen on Unix */
case SUBLANG_SPANISH_GUATEMALA: return "es_GT";
case SUBLANG_SPANISH_COSTA_RICA: return "es_CR";
case SUBLANG_SPANISH_PANAMA: return "es_PA";
case SUBLANG_SPANISH_DOMINICAN_REPUBLIC: return "es_DO";
case SUBLANG_SPANISH_VENEZUELA: return "es_VE";
case SUBLANG_SPANISH_COLOMBIA: return "es_CO";
case SUBLANG_SPANISH_PERU: return "es_PE";
case SUBLANG_SPANISH_ARGENTINA: return "es_AR";
case SUBLANG_SPANISH_ECUADOR: return "es_EC";
case SUBLANG_SPANISH_CHILE: return "es_CL";
case SUBLANG_SPANISH_URUGUAY: return "es_UY";
case SUBLANG_SPANISH_PARAGUAY: return "es_PY";
case SUBLANG_SPANISH_BOLIVIA: return "es_BO";
case SUBLANG_SPANISH_EL_SALVADOR: return "es_SV";
case SUBLANG_SPANISH_HONDURAS: return "es_HN";
case SUBLANG_SPANISH_NICARAGUA: return "es_NI";
case SUBLANG_SPANISH_PUERTO_RICO: return "es_PR";
}
return "es";
case 0x30: /* SUTU */ return "bnt_TZ";
case LANG_SWAHILI: return "sw_KE";
case LANG_SWEDISH:
switch (sub)
{
case SUBLANG_DEFAULT: return "sv_SE";
case SUBLANG_SWEDISH_FINLAND: return "sv_FI";
}
return "sv";
case LANG_SYRIAC: return "syr_TR"; /* An extinct language. */
case 0x64: /* TAGALOG */ return "tl_PH";
case 0x28: /* TAJIK */ return "tg_TJ";
case 0x5f: /* TAMAZIGHT */ return "ber_MA";
case LANG_TAMIL:
return "ta"; /* Ambiguous: could be "ta_IN" or "ta_LK" or "ta_SG". */
case LANG_TATAR: return "tt_RU";
case LANG_TELUGU: return "te_IN";
case LANG_THAI: return "th_TH";
case 0x51: /* TIBETAN */ return "bo_CN";
case 0x73: /* TIGRINYA */ return "ti_ET";
case 0x31: /* TSONGA */ return "ts_ZA";
case LANG_TURKISH: return "tr_TR";
case 0x42: /* TURKMEN */ return "tk_TM";
case LANG_UKRAINIAN: return "uk_UA";
case LANG_URDU:
switch (sub)
{
case SUBLANG_URDU_PAKISTAN: return "ur_PK";
case SUBLANG_URDU_INDIA: return "ur_IN";
}
return "ur";
case LANG_UZBEK:
switch (sub)
{
/* FIXME: Adjust this when Uzbek locales appear on Unix. */
case SUBLANG_UZBEK_LATIN: return "uz_UZ@latin";
case SUBLANG_UZBEK_CYRILLIC: return "uz_UZ@cyrillic";
}
return "uz";
case 0x33: /* VENDA */ return "ven_ZA";
case LANG_VIETNAMESE: return "vi_VN";
case 0x52: /* WELSH */ return "cy_GB";
case 0x34: /* XHOSA */ return "xh_ZA";
case 0x78: /* YI */ return "sit_CN";
case 0x3d: /* YIDDISH */ return "yi_IL";
case 0x6a: /* YORUBA */ return "yo_NG";
case 0x35: /* ZULU */ return "zu_ZA";
default: return "C";
}
#endif
}

106
lib/intl/log.c Normal file
View file

@ -0,0 +1,106 @@
/* log.c - Log file output. */
/* Copyright (C) 2003, 2005-2009 Free Software Foundation, Inc.
This file is part of GNU Bash.
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/>.
*/
/* Written by Bruno Haible <bruno@clisp.org>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Print an ASCII string with quotes and escape sequences where needed. */
static void
print_escaped (stream, str)
FILE *stream;
const char *str;
{
putc ('"', stream);
for (; *str != '\0'; str++)
if (*str == '\n')
{
fputs ("\\n\"", stream);
if (str[1] == '\0')
return;
fputs ("\n\"", stream);
}
else
{
if (*str == '"' || *str == '\\')
putc ('\\', stream);
putc (*str, stream);
}
putc ('"', stream);
}
/* Add to the log file an entry denoting a failed translation. */
void
_nl_log_untranslated (logfilename, domainname, msgid1, msgid2, plural)
const char *logfilename;
const char *domainname;
const char *msgid1;
const char *msgid2;
int plural;
{
static char *last_logfilename = NULL;
static FILE *last_logfile = NULL;
FILE *logfile;
/* Can we reuse the last opened logfile? */
if (last_logfilename == NULL || strcmp (logfilename, last_logfilename) != 0)
{
/* Close the last used logfile. */
if (last_logfilename != NULL)
{
if (last_logfile != NULL)
{
fclose (last_logfile);
last_logfile = NULL;
}
free (last_logfilename);
last_logfilename = NULL;
}
/* Open the logfile. */
last_logfilename = (char *) malloc (strlen (logfilename) + 1);
if (last_logfilename == NULL)
return;
strcpy (last_logfilename, logfilename);
last_logfile = fopen (logfilename, "a");
if (last_logfile == NULL)
return;
}
logfile = last_logfile;
fprintf (logfile, "domain ");
print_escaped (logfile, domainname);
fprintf (logfile, "\nmsgid ");
print_escaped (logfile, msgid1);
if (plural)
{
fprintf (logfile, "\nmsgid_plural ");
print_escaped (logfile, msgid2);
fprintf (logfile, "\nmsgstr[0] \"\"\n");
}
else
fprintf (logfile, "\nmsgstr \"\"\n");
putc ('\n', logfile);
}

70
lib/intl/ngettext.c Normal file
View file

@ -0,0 +1,70 @@
/* ngettext.c - Implementation of ngettext(3) function. */
/* Copyright (C) 1995, 1997, 2000, 2001, 2002, 2005-2009 Free Software Foundation, Inc.
This file is part of GNU Bash.
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/>.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifdef _LIBC
# define __need_NULL
# include <stddef.h>
#else
# include <stdlib.h> /* Just for NULL. */
#endif
#include "gettextP.h"
#ifdef _LIBC
# include <libintl.h>
#else
# include "libgnuintl.h"
#endif
#include <locale.h>
/* @@ end of prolog @@ */
/* Names for the libintl functions are a problem. They must not clash
with existing names and they should follow ANSI C. But this source
code is also used in GNU C Library where the names have a __
prefix. So we have to make a difference here. */
#ifdef _LIBC
# define NGETTEXT __ngettext
# define DCNGETTEXT __dcngettext
#else
# define NGETTEXT libintl_ngettext
# define DCNGETTEXT libintl_dcngettext
#endif
/* Look up MSGID in the current default message catalog for the current
LC_MESSAGES locale. If not found, returns MSGID itself (the default
text). */
char *
NGETTEXT (msgid1, msgid2, n)
const char *msgid1;
const char *msgid2;
unsigned long int n;
{
return DCNGETTEXT (NULL, msgid1, msgid2, n, LC_MESSAGES);
}
#ifdef _LIBC
/* Alias for function name in GNU C Library. */
weak_alias (__ngettext, ngettext);
#endif

100
lib/intl/os2compat.c Normal file
View file

@ -0,0 +1,100 @@
/* os2compat.c - OS/2 compatibility functions. */
/* Copyright (C) 2001-2002, 2005-2009 Free Software Foundation, Inc.
This file is part of GNU Bash.
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/>.
*/
#define OS2_AWARE
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <sys/param.h>
/* A version of getenv() that works from DLLs */
extern unsigned long DosScanEnv (const unsigned char *pszName, unsigned char **ppszValue);
char *
_nl_getenv (const char *name)
{
unsigned char *value;
if (DosScanEnv (name, &value))
return NULL;
else
return value;
}
/* A fixed size buffer. */
char libintl_nl_default_dirname[MAXPATHLEN+1];
char *_nlos2_libdir = NULL;
char *_nlos2_localealiaspath = NULL;
char *_nlos2_localedir = NULL;
static __attribute__((constructor)) void
nlos2_initialize ()
{
char *root = getenv ("UNIXROOT");
char *gnulocaledir = getenv ("GNULOCALEDIR");
_nlos2_libdir = gnulocaledir;
if (!_nlos2_libdir)
{
if (root)
{
size_t sl = strlen (root);
_nlos2_libdir = (char *) malloc (sl + strlen (LIBDIR) + 1);
memcpy (_nlos2_libdir, root, sl);
memcpy (_nlos2_libdir + sl, LIBDIR, strlen (LIBDIR) + 1);
}
else
_nlos2_libdir = LIBDIR;
}
_nlos2_localealiaspath = gnulocaledir;
if (!_nlos2_localealiaspath)
{
if (root)
{
size_t sl = strlen (root);
_nlos2_localealiaspath = (char *) malloc (sl + strlen (LOCALE_ALIAS_PATH) + 1);
memcpy (_nlos2_localealiaspath, root, sl);
memcpy (_nlos2_localealiaspath + sl, LOCALE_ALIAS_PATH, strlen (LOCALE_ALIAS_PATH) + 1);
}
else
_nlos2_localealiaspath = LOCALE_ALIAS_PATH;
}
_nlos2_localedir = gnulocaledir;
if (!_nlos2_localedir)
{
if (root)
{
size_t sl = strlen (root);
_nlos2_localedir = (char *) malloc (sl + strlen (LOCALEDIR) + 1);
memcpy (_nlos2_localedir, root, sl);
memcpy (_nlos2_localedir + sl, LOCALEDIR, strlen (LOCALEDIR) + 1);
}
else
_nlos2_localedir = LOCALEDIR;
}
if (strlen (_nlos2_localedir) <= MAXPATHLEN)
strcpy (libintl_nl_default_dirname, _nlos2_localedir);
}

48
lib/intl/os2compat.h Normal file
View file

@ -0,0 +1,48 @@
/* os2compat.h - OS/2 compatibility defines. */
/* This file is intended to be included from config.h
Copyright (C) 2001-2002, 2005-2009 Free Software Foundation, Inc.
This file is part of GNU Bash.
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/>.
*/
/* When included from os2compat.h we need all the original definitions */
#ifndef OS2_AWARE
#undef LIBDIR
#define LIBDIR _nlos2_libdir
extern char *_nlos2_libdir;
#undef LOCALEDIR
#define LOCALEDIR _nlos2_localedir
extern char *_nlos2_localedir;
#undef LOCALE_ALIAS_PATH
#define LOCALE_ALIAS_PATH _nlos2_localealiaspath
extern char *_nlos2_localealiaspath;
#endif
#undef HAVE_STRCASECMP
#define HAVE_STRCASECMP 1
#define strcasecmp stricmp
#define strncasecmp strnicmp
/* We have our own getenv() which works even if library is compiled as DLL */
#define getenv _nl_getenv
/* Older versions of gettext used -1 as the value of LC_MESSAGES */
#define LC_MESSAGES_COMPAT (-1)

26
lib/intl/osdep.c Normal file
View file

@ -0,0 +1,26 @@
/* osdep.c - OS dependent parts of libintl. */
/* Copyright (C) 2001-2002, 2005-2009 Free Software Foundation, Inc.
This file is part of GNU Bash.
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/>.
*/
#if defined __EMX__
# include "os2compat.c"
#else
/* Avoid AIX compiler warning. */
typedef int dummy;
#endif

158
lib/intl/plural-exp.c Normal file
View file

@ -0,0 +1,158 @@
/* plural-exp.c - Expression parsing for plural form selection. */
/* Copyright (C) 2000, 2001, 2005-2009 Free Software Foundation, Inc.
Written by Ulrich Drepper <drepper@cygnus.com>, 2000.
This file is part of GNU Bash.
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/>.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "plural-exp.h"
#if (defined __GNUC__ && !defined __APPLE_CC__) \
|| (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)
/* These structs are the constant expression for the germanic plural
form determination. It represents the expression "n != 1". */
static const struct expression plvar =
{
.nargs = 0,
.operation = var,
};
static const struct expression plone =
{
.nargs = 0,
.operation = num,
.val =
{
.num = 1
}
};
struct expression GERMANIC_PLURAL =
{
.nargs = 2,
.operation = not_equal,
.val =
{
.args =
{
[0] = (struct expression *) &plvar,
[1] = (struct expression *) &plone
}
}
};
# define INIT_GERMANIC_PLURAL()
#else
/* For compilers without support for ISO C 99 struct/union initializers:
Initialization at run-time. */
static struct expression plvar;
static struct expression plone;
struct expression GERMANIC_PLURAL;
static void
init_germanic_plural ()
{
if (plone.val.num == 0)
{
plvar.nargs = 0;
plvar.operation = var;
plone.nargs = 0;
plone.operation = num;
plone.val.num = 1;
GERMANIC_PLURAL.nargs = 2;
GERMANIC_PLURAL.operation = not_equal;
GERMANIC_PLURAL.val.args[0] = &plvar;
GERMANIC_PLURAL.val.args[1] = &plone;
}
}
# define INIT_GERMANIC_PLURAL() init_germanic_plural ()
#endif
void
internal_function
EXTRACT_PLURAL_EXPRESSION (nullentry, pluralp, npluralsp)
const char *nullentry;
struct expression **pluralp;
unsigned long int *npluralsp;
{
if (nullentry != NULL)
{
const char *plural;
const char *nplurals;
plural = strstr (nullentry, "plural=");
nplurals = strstr (nullentry, "nplurals=");
if (plural == NULL || nplurals == NULL)
goto no_plural;
else
{
char *endp;
unsigned long int n;
struct parse_args args;
/* First get the number. */
nplurals += 9;
while (*nplurals != '\0' && isspace ((unsigned char) *nplurals))
++nplurals;
if (!(*nplurals >= '0' && *nplurals <= '9'))
goto no_plural;
#if defined HAVE_STRTOUL || defined _LIBC
n = strtoul (nplurals, &endp, 10);
#else
for (endp = nplurals, n = 0; *endp >= '0' && *endp <= '9'; endp++)
n = n * 10 + (*endp - '0');
#endif
if (nplurals == endp)
goto no_plural;
*npluralsp = n;
/* Due to the restrictions bison imposes onto the interface of the
scanner function we have to put the input string and the result
passed up from the parser into the same structure which address
is passed down to the parser. */
plural += 7;
args.cp = plural;
if (PLURAL_PARSE (&args) != 0)
goto no_plural;
*pluralp = args.res;
}
}
else
{
/* By default we are using the Germanic form: singular form only
for `one', the plural form otherwise. Yes, this is also what
English is using since English is a Germanic language. */
no_plural:
INIT_GERMANIC_PLURAL ();
*pluralp = &GERMANIC_PLURAL;
*npluralsp = 2;
}
}

128
lib/intl/plural-exp.h Normal file
View file

@ -0,0 +1,128 @@
/* plural-exp.h - defines for expression parsing and evaluation for plural form selection. */
/* Copyright (C) 2000, 2001, 2002, 2005-2009 Free Software Foundation, Inc.
Written by Ulrich Drepper <drepper@cygnus.com>, 2000.
This file is part of GNU Bash.
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/>.
*/
#ifndef _PLURAL_EXP_H
#define _PLURAL_EXP_H
#ifndef PARAMS
# if __STDC__ || defined __GNUC__ || defined __SUNPRO_C || defined __cplusplus || __PROTOTYPES
# define PARAMS(args) args
# else
# define PARAMS(args) ()
# endif
#endif
#ifndef internal_function
# define internal_function
#endif
#ifndef attribute_hidden
# define attribute_hidden
#endif
/* This is the representation of the expressions to determine the
plural form. */
struct expression
{
int nargs; /* Number of arguments. */
enum operator
{
/* Without arguments: */
var, /* The variable "n". */
num, /* Decimal number. */
/* Unary operators: */
lnot, /* Logical NOT. */
/* Binary operators: */
mult, /* Multiplication. */
divide, /* Division. */
module, /* Modulo operation. */
plus, /* Addition. */
minus, /* Subtraction. */
less_than, /* Comparison. */
greater_than, /* Comparison. */
less_or_equal, /* Comparison. */
greater_or_equal, /* Comparison. */
equal, /* Comparison for equality. */
not_equal, /* Comparison for inequality. */
land, /* Logical AND. */
lor, /* Logical OR. */
/* Ternary operators: */
qmop /* Question mark operator. */
} operation;
union
{
unsigned long int num; /* Number value for `num'. */
struct expression *args[3]; /* Up to three arguments. */
} val;
};
/* This is the data structure to pass information to the parser and get
the result in a thread-safe way. */
struct parse_args
{
const char *cp;
struct expression *res;
};
/* Names for the libintl functions are a problem. This source code is used
1. in the GNU C Library library,
2. in the GNU libintl library,
3. in the GNU gettext tools.
The function names in each situation must be different, to allow for
binary incompatible changes in 'struct expression'. Furthermore,
1. in the GNU C Library library, the names have a __ prefix,
2.+3. in the GNU libintl library and in the GNU gettext tools, the names
must follow ANSI C and not start with __.
So we have to distinguish the three cases. */
#ifdef _LIBC
# define FREE_EXPRESSION __gettext_free_exp
# define PLURAL_PARSE __gettextparse
# define GERMANIC_PLURAL __gettext_germanic_plural
# define EXTRACT_PLURAL_EXPRESSION __gettext_extract_plural
#elif defined (IN_LIBINTL)
# define FREE_EXPRESSION libintl_gettext_free_exp
# define PLURAL_PARSE libintl_gettextparse
# define GERMANIC_PLURAL libintl_gettext_germanic_plural
# define EXTRACT_PLURAL_EXPRESSION libintl_gettext_extract_plural
#else
# define FREE_EXPRESSION free_plural_expression
# define PLURAL_PARSE parse_plural_expression
# define GERMANIC_PLURAL germanic_plural
# define EXTRACT_PLURAL_EXPRESSION extract_plural_expression
#endif
extern void FREE_EXPRESSION PARAMS ((struct expression *exp))
internal_function;
extern int PLURAL_PARSE PARAMS ((void *arg));
extern struct expression GERMANIC_PLURAL attribute_hidden;
extern void EXTRACT_PLURAL_EXPRESSION PARAMS ((const char *nullentry,
struct expression **pluralp,
unsigned long int *npluralsp))
internal_function;
#if !defined (_LIBC) && !defined (IN_LIBINTL)
extern unsigned long int plural_eval PARAMS ((struct expression *pexp,
unsigned long int n));
#endif
#endif /* _PLURAL_EXP_H */

1679
lib/intl/plural.c Normal file

File diff suppressed because it is too large Load diff

411
lib/intl/plural.y Normal file
View file

@ -0,0 +1,411 @@
%{
/* plural.y - Expression parsing for plural form selection. */
/* Copyright (C) 2000, 2001, 2005-2009 Free Software Foundation, Inc.
Written by Ulrich Drepper <drepper@cygnus.com>, 2000.
This file is part of GNU Bash.
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/>.
*/
/* The bison generated parser uses alloca. AIX 3 forces us to put this
declaration at the beginning of the file. The declaration in bison's
skeleton file comes too late. This must come before <config.h>
because <config.h> may include arbitrary system headers. */
#if defined _AIX && !defined __GNUC__
#pragma alloca
#endif
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stddef.h>
#include <stdlib.h>
#include "plural-exp.h"
/* The main function generated by the parser is called __gettextparse,
but we want it to be called PLURAL_PARSE. */
#ifndef _LIBC
# define __gettextparse PLURAL_PARSE
#endif
#define YYLEX_PARAM &((struct parse_args *) arg)->cp
#define YYPARSE_PARAM arg
%}
%pure_parser
%expect 7
%union {
unsigned long int num;
enum operator op;
struct expression *exp;
}
%{
/* Prototypes for local functions. */
static struct expression *new_exp PARAMS ((int nargs, enum operator op,
struct expression * const *args));
static inline struct expression *new_exp_0 PARAMS ((enum operator op));
static inline struct expression *new_exp_1 PARAMS ((enum operator op,
struct expression *right));
static struct expression *new_exp_2 PARAMS ((enum operator op,
struct expression *left,
struct expression *right));
static inline struct expression *new_exp_3 PARAMS ((enum operator op,
struct expression *bexp,
struct expression *tbranch,
struct expression *fbranch));
static int yylex PARAMS ((YYSTYPE *lval, const char **pexp));
static void yyerror PARAMS ((const char *str));
/* Allocation of expressions. */
static struct expression *
new_exp (nargs, op, args)
int nargs;
enum operator op;
struct expression * const *args;
{
int i;
struct expression *newp;
/* If any of the argument could not be malloc'ed, just return NULL. */
for (i = nargs - 1; i >= 0; i--)
if (args[i] == NULL)
goto fail;
/* Allocate a new expression. */
newp = (struct expression *) malloc (sizeof (*newp));
if (newp != NULL)
{
newp->nargs = nargs;
newp->operation = op;
for (i = nargs - 1; i >= 0; i--)
newp->val.args[i] = args[i];
return newp;
}
fail:
for (i = nargs - 1; i >= 0; i--)
FREE_EXPRESSION (args[i]);
return NULL;
}
static inline struct expression *
new_exp_0 (op)
enum operator op;
{
return new_exp (0, op, NULL);
}
static inline struct expression *
new_exp_1 (op, right)
enum operator op;
struct expression *right;
{
struct expression *args[1];
args[0] = right;
return new_exp (1, op, args);
}
static struct expression *
new_exp_2 (op, left, right)
enum operator op;
struct expression *left;
struct expression *right;
{
struct expression *args[2];
args[0] = left;
args[1] = right;
return new_exp (2, op, args);
}
static inline struct expression *
new_exp_3 (op, bexp, tbranch, fbranch)
enum operator op;
struct expression *bexp;
struct expression *tbranch;
struct expression *fbranch;
{
struct expression *args[3];
args[0] = bexp;
args[1] = tbranch;
args[2] = fbranch;
return new_exp (3, op, args);
}
%}
/* This declares that all operators have the same associativity and the
precedence order as in C. See [Harbison, Steele: C, A Reference Manual].
There is no unary minus and no bitwise operators.
Operators with the same syntactic behaviour have been merged into a single
token, to save space in the array generated by bison. */
%right '?' /* ? */
%left '|' /* || */
%left '&' /* && */
%left EQUOP2 /* == != */
%left CMPOP2 /* < > <= >= */
%left ADDOP2 /* + - */
%left MULOP2 /* * / % */
%right '!' /* ! */
%token <op> EQUOP2 CMPOP2 ADDOP2 MULOP2
%token <num> NUMBER
%type <exp> exp
%%
start: exp
{
if ($1 == NULL)
YYABORT;
((struct parse_args *) arg)->res = $1;
}
;
exp: exp '?' exp ':' exp
{
$$ = new_exp_3 (qmop, $1, $3, $5);
}
| exp '|' exp
{
$$ = new_exp_2 (lor, $1, $3);
}
| exp '&' exp
{
$$ = new_exp_2 (land, $1, $3);
}
| exp EQUOP2 exp
{
$$ = new_exp_2 ($2, $1, $3);
}
| exp CMPOP2 exp
{
$$ = new_exp_2 ($2, $1, $3);
}
| exp ADDOP2 exp
{
$$ = new_exp_2 ($2, $1, $3);
}
| exp MULOP2 exp
{
$$ = new_exp_2 ($2, $1, $3);
}
| '!' exp
{
$$ = new_exp_1 (lnot, $2);
}
| 'n'
{
$$ = new_exp_0 (var);
}
| NUMBER
{
if (($$ = new_exp_0 (num)) != NULL)
$$->val.num = $1;
}
| '(' exp ')'
{
$$ = $2;
}
;
%%
void
internal_function
FREE_EXPRESSION (exp)
struct expression *exp;
{
if (exp == NULL)
return;
/* Handle the recursive case. */
switch (exp->nargs)
{
case 3:
FREE_EXPRESSION (exp->val.args[2]);
/* FALLTHROUGH */
case 2:
FREE_EXPRESSION (exp->val.args[1]);
/* FALLTHROUGH */
case 1:
FREE_EXPRESSION (exp->val.args[0]);
/* FALLTHROUGH */
default:
break;
}
free (exp);
}
static int
yylex (lval, pexp)
YYSTYPE *lval;
const char **pexp;
{
const char *exp = *pexp;
int result;
while (1)
{
if (exp[0] == '\0')
{
*pexp = exp;
return YYEOF;
}
if (exp[0] != ' ' && exp[0] != '\t')
break;
++exp;
}
result = *exp++;
switch (result)
{
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
{
unsigned long int n = result - '0';
while (exp[0] >= '0' && exp[0] <= '9')
{
n *= 10;
n += exp[0] - '0';
++exp;
}
lval->num = n;
result = NUMBER;
}
break;
case '=':
if (exp[0] == '=')
{
++exp;
lval->op = equal;
result = EQUOP2;
}
else
result = YYERRCODE;
break;
case '!':
if (exp[0] == '=')
{
++exp;
lval->op = not_equal;
result = EQUOP2;
}
break;
case '&':
case '|':
if (exp[0] == result)
++exp;
else
result = YYERRCODE;
break;
case '<':
if (exp[0] == '=')
{
++exp;
lval->op = less_or_equal;
}
else
lval->op = less_than;
result = CMPOP2;
break;
case '>':
if (exp[0] == '=')
{
++exp;
lval->op = greater_or_equal;
}
else
lval->op = greater_than;
result = CMPOP2;
break;
case '*':
lval->op = mult;
result = MULOP2;
break;
case '/':
lval->op = divide;
result = MULOP2;
break;
case '%':
lval->op = module;
result = MULOP2;
break;
case '+':
lval->op = plus;
result = ADDOP2;
break;
case '-':
lval->op = minus;
result = ADDOP2;
break;
case 'n':
case '?':
case ':':
case '(':
case ')':
/* Nothing, just return the character. */
break;
case ';':
case '\n':
case '\0':
/* Be safe and let the user call this function again. */
--exp;
result = YYEOF;
break;
default:
result = YYERRCODE;
#if YYDEBUG != 0
--exp;
#endif
break;
}
*pexp = exp;
return result;
}
static void
yyerror (str)
const char *str;
{
/* Do nothing. We don't print error messages here. */
}

29
lib/intl/ref-add.sin Normal file
View file

@ -0,0 +1,29 @@
# Add this package to a list of references stored in a text file.
#
# Copyright (C) 2000 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
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
#
# Written by Bruno Haible <haible@clisp.cons.org>.
#
/^# Packages using this file: / {
s/# Packages using this file://
ta
:a
s/ @PACKAGE@ / @PACKAGE@ /
tb
s/ $/ @PACKAGE@ /
:b
s/^/# Packages using this file:/
}

24
lib/intl/ref-del.sin Normal file
View file

@ -0,0 +1,24 @@
# Remove this package from a list of references stored in a text file.
#
# Copyright (C) 2000 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
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
#
# Written by Bruno Haible <haible@clisp.cons.org>.
#
/^# Packages using this file: / {
s/# Packages using this file://
s/ @PACKAGE@ / /
s/^/# Packages using this file:/
}

440
lib/intl/relocatable.c Normal file
View file

@ -0,0 +1,440 @@
/* relocatable.c - Provide relocatable packages. */
/* Copyright (C) 2003, 2005-2009 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2003.
This file is part of GNU Bash.
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/>.
*/
/* Tell glibc's <stdio.h> to provide a prototype for getline().
This must come before <config.h> because <config.h> may include
<features.h>, and once <features.h> has been included, it's too late. */
#ifndef _GNU_SOURCE
# define _GNU_SOURCE 1
#endif
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
/* Specification. */
#include "relocatable.h"
#if ENABLE_RELOCATABLE
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef NO_XMALLOC
# define xmalloc malloc
#else
# include "xmalloc.h"
#endif
#if DEPENDS_ON_LIBCHARSET
# include <libcharset.h>
#endif
#if DEPENDS_ON_LIBICONV && HAVE_ICONV
# include <iconv.h>
#endif
#if DEPENDS_ON_LIBINTL && ENABLE_NLS
# include <libintl.h>
#endif
/* Faked cheap 'bool'. */
#undef bool
#undef false
#undef true
#define bool int
#define false 0
#define true 1
/* Pathname support.
ISSLASH(C) tests whether C is a directory separator character.
IS_PATH_WITH_DIR(P) tests whether P contains a directory specification.
*/
#if defined _WIN32 || defined __WIN32__ || defined __EMX__ || defined __DJGPP__
/* Win32, OS/2, DOS */
# define ISSLASH(C) ((C) == '/' || (C) == '\\')
# define HAS_DEVICE(P) \
((((P)[0] >= 'A' && (P)[0] <= 'Z') || ((P)[0] >= 'a' && (P)[0] <= 'z')) \
&& (P)[1] == ':')
# define IS_PATH_WITH_DIR(P) \
(strchr (P, '/') != NULL || strchr (P, '\\') != NULL || HAS_DEVICE (P))
# define FILESYSTEM_PREFIX_LEN(P) (HAS_DEVICE (P) ? 2 : 0)
#else
/* Unix */
# define ISSLASH(C) ((C) == '/')
# define IS_PATH_WITH_DIR(P) (strchr (P, '/') != NULL)
# define FILESYSTEM_PREFIX_LEN(P) 0
#endif
/* Original installation prefix. */
static char *orig_prefix;
static size_t orig_prefix_len;
/* Current installation prefix. */
static char *curr_prefix;
static size_t curr_prefix_len;
/* These prefixes do not end in a slash. Anything that will be concatenated
to them must start with a slash. */
/* Sets the original and the current installation prefix of this module.
Relocation simply replaces a pathname starting with the original prefix
by the corresponding pathname with the current prefix instead. Both
prefixes should be directory names without trailing slash (i.e. use ""
instead of "/"). */
static void
set_this_relocation_prefix (const char *orig_prefix_arg,
const char *curr_prefix_arg)
{
if (orig_prefix_arg != NULL && curr_prefix_arg != NULL
/* Optimization: if orig_prefix and curr_prefix are equal, the
relocation is a nop. */
&& strcmp (orig_prefix_arg, curr_prefix_arg) != 0)
{
/* Duplicate the argument strings. */
char *memory;
orig_prefix_len = strlen (orig_prefix_arg);
curr_prefix_len = strlen (curr_prefix_arg);
memory = (char *) xmalloc (orig_prefix_len + 1 + curr_prefix_len + 1);
#ifdef NO_XMALLOC
if (memory != NULL)
#endif
{
memcpy (memory, orig_prefix_arg, orig_prefix_len + 1);
orig_prefix = memory;
memory += orig_prefix_len + 1;
memcpy (memory, curr_prefix_arg, curr_prefix_len + 1);
curr_prefix = memory;
return;
}
}
orig_prefix = NULL;
curr_prefix = NULL;
/* Don't worry about wasted memory here - this function is usually only
called once. */
}
/* Sets the original and the current installation prefix of the package.
Relocation simply replaces a pathname starting with the original prefix
by the corresponding pathname with the current prefix instead. Both
prefixes should be directory names without trailing slash (i.e. use ""
instead of "/"). */
void
set_relocation_prefix (const char *orig_prefix_arg, const char *curr_prefix_arg)
{
set_this_relocation_prefix (orig_prefix_arg, curr_prefix_arg);
/* Now notify all dependent libraries. */
#if DEPENDS_ON_LIBCHARSET
libcharset_set_relocation_prefix (orig_prefix_arg, curr_prefix_arg);
#endif
#if DEPENDS_ON_LIBICONV && HAVE_ICONV && _LIBICONV_VERSION >= 0x0109
libiconv_set_relocation_prefix (orig_prefix_arg, curr_prefix_arg);
#endif
#if DEPENDS_ON_LIBINTL && ENABLE_NLS && defined libintl_set_relocation_prefix
libintl_set_relocation_prefix (orig_prefix_arg, curr_prefix_arg);
#endif
}
/* Convenience function:
Computes the current installation prefix, based on the original
installation prefix, the original installation directory of a particular
file, and the current pathname of this file. Returns NULL upon failure. */
#ifdef IN_LIBRARY
#define compute_curr_prefix local_compute_curr_prefix
static
#endif
const char *
compute_curr_prefix (const char *orig_installprefix,
const char *orig_installdir,
const char *curr_pathname)
{
const char *curr_installdir;
const char *rel_installdir;
if (curr_pathname == NULL)
return NULL;
/* Determine the relative installation directory, relative to the prefix.
This is simply the difference between orig_installprefix and
orig_installdir. */
if (strncmp (orig_installprefix, orig_installdir, strlen (orig_installprefix))
!= 0)
/* Shouldn't happen - nothing should be installed outside $(prefix). */
return NULL;
rel_installdir = orig_installdir + strlen (orig_installprefix);
/* Determine the current installation directory. */
{
const char *p_base = curr_pathname + FILESYSTEM_PREFIX_LEN (curr_pathname);
const char *p = curr_pathname + strlen (curr_pathname);
char *q;
while (p > p_base)
{
p--;
if (ISSLASH (*p))
break;
}
q = (char *) xmalloc (p - curr_pathname + 1);
#ifdef NO_XMALLOC
if (q == NULL)
return NULL;
#endif
memcpy (q, curr_pathname, p - curr_pathname);
q[p - curr_pathname] = '\0';
curr_installdir = q;
}
/* Compute the current installation prefix by removing the trailing
rel_installdir from it. */
{
const char *rp = rel_installdir + strlen (rel_installdir);
const char *cp = curr_installdir + strlen (curr_installdir);
const char *cp_base =
curr_installdir + FILESYSTEM_PREFIX_LEN (curr_installdir);
while (rp > rel_installdir && cp > cp_base)
{
bool same = false;
const char *rpi = rp;
const char *cpi = cp;
while (rpi > rel_installdir && cpi > cp_base)
{
rpi--;
cpi--;
if (ISSLASH (*rpi) || ISSLASH (*cpi))
{
if (ISSLASH (*rpi) && ISSLASH (*cpi))
same = true;
break;
}
#if defined _WIN32 || defined __WIN32__ || defined __EMX__ || defined __DJGPP__
/* Win32, OS/2, DOS - case insignificant filesystem */
if ((*rpi >= 'a' && *rpi <= 'z' ? *rpi - 'a' + 'A' : *rpi)
!= (*cpi >= 'a' && *cpi <= 'z' ? *cpi - 'a' + 'A' : *cpi))
break;
#else
if (*rpi != *cpi)
break;
#endif
}
if (!same)
break;
/* The last pathname component was the same. opi and cpi now point
to the slash before it. */
rp = rpi;
cp = cpi;
}
if (rp > rel_installdir)
/* Unexpected: The curr_installdir does not end with rel_installdir. */
return NULL;
{
size_t curr_prefix_len = cp - curr_installdir;
char *curr_prefix;
curr_prefix = (char *) xmalloc (curr_prefix_len + 1);
#ifdef NO_XMALLOC
if (curr_prefix == NULL)
return NULL;
#endif
memcpy (curr_prefix, curr_installdir, curr_prefix_len);
curr_prefix[curr_prefix_len] = '\0';
return curr_prefix;
}
}
}
#if defined PIC && defined INSTALLDIR
/* Full pathname of shared library, or NULL. */
static char *shared_library_fullname;
#if defined _WIN32 || defined __WIN32__
/* Determine the full pathname of the shared library when it is loaded. */
BOOL WINAPI
DllMain (HINSTANCE module_handle, DWORD event, LPVOID reserved)
{
(void) reserved;
if (event == DLL_PROCESS_ATTACH)
{
/* The DLL is being loaded into an application's address range. */
static char location[MAX_PATH];
if (!GetModuleFileName (module_handle, location, sizeof (location)))
/* Shouldn't happen. */
return FALSE;
if (!IS_PATH_WITH_DIR (location))
/* Shouldn't happen. */
return FALSE;
shared_library_fullname = strdup (location);
}
return TRUE;
}
#else /* Unix */
static void
find_shared_library_fullname ()
{
#ifdef __linux__
FILE *fp;
/* Open the current process' maps file. It describes one VMA per line. */
fp = fopen ("/proc/self/maps", "r");
if (fp)
{
unsigned long address = (unsigned long) &find_shared_library_fullname;
for (;;)
{
unsigned long start, end;
int c;
if (fscanf (fp, "%lx-%lx", &start, &end) != 2)
break;
if (address >= start && address <= end - 1)
{
/* Found it. Now see if this line contains a filename. */
while (c = getc (fp), c != EOF && c != '\n' && c != '/')
continue;
if (c == '/')
{
size_t size;
int len;
ungetc (c, fp);
shared_library_fullname = NULL; size = 0;
len = getline (&shared_library_fullname, &size, fp);
if (len >= 0)
{
/* Success: filled shared_library_fullname. */
if (len > 0 && shared_library_fullname[len - 1] == '\n')
shared_library_fullname[len - 1] = '\0';
}
}
break;
}
while (c = getc (fp), c != EOF && c != '\n')
continue;
}
fclose (fp);
}
#endif
}
#endif /* WIN32 / Unix */
/* Return the full pathname of the current shared library.
Return NULL if unknown.
Guaranteed to work only on Linux and Woe32. */
static char *
get_shared_library_fullname ()
{
#if !(defined _WIN32 || defined __WIN32__)
static bool tried_find_shared_library_fullname;
if (!tried_find_shared_library_fullname)
{
find_shared_library_fullname ();
tried_find_shared_library_fullname = true;
}
#endif
return shared_library_fullname;
}
#endif /* PIC */
/* Returns the pathname, relocated according to the current installation
directory. */
const char *
relocate (const char *pathname)
{
#if defined PIC && defined INSTALLDIR
static int initialized;
/* Initialization code for a shared library. */
if (!initialized)
{
/* At this point, orig_prefix and curr_prefix likely have already been
set through the main program's set_program_name_and_installdir
function. This is sufficient in the case that the library has
initially been installed in the same orig_prefix. But we can do
better, to also cover the cases that 1. it has been installed
in a different prefix before being moved to orig_prefix and (later)
to curr_prefix, 2. unlike the program, it has not moved away from
orig_prefix. */
const char *orig_installprefix = INSTALLPREFIX;
const char *orig_installdir = INSTALLDIR;
const char *curr_prefix_better;
curr_prefix_better =
compute_curr_prefix (orig_installprefix, orig_installdir,
get_shared_library_fullname ());
if (curr_prefix_better == NULL)
curr_prefix_better = curr_prefix;
set_relocation_prefix (orig_installprefix, curr_prefix_better);
initialized = 1;
}
#endif
/* Note: It is not necessary to perform case insensitive comparison here,
even for DOS-like filesystems, because the pathname argument was
typically created from the same Makefile variable as orig_prefix came
from. */
if (orig_prefix != NULL && curr_prefix != NULL
&& strncmp (pathname, orig_prefix, orig_prefix_len) == 0)
{
if (pathname[orig_prefix_len] == '\0')
/* pathname equals orig_prefix. */
return curr_prefix;
if (ISSLASH (pathname[orig_prefix_len]))
{
/* pathname starts with orig_prefix. */
const char *pathname_tail = &pathname[orig_prefix_len];
char *result =
(char *) xmalloc (curr_prefix_len + strlen (pathname_tail) + 1);
#ifdef NO_XMALLOC
if (result != NULL)
#endif
{
memcpy (result, curr_prefix, curr_prefix_len);
strcpy (result + curr_prefix_len, pathname_tail);
return result;
}
}
}
/* Nothing to relocate. */
return pathname;
}
#endif

69
lib/intl/relocatable.h Normal file
View file

@ -0,0 +1,69 @@
/* relocatable.h - Provide relocatable packages. */
/* Copyright (C) 2003, 2005-2009 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2003.
This file is part of GNU Bash.
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/>.
*/
#ifndef _RELOCATABLE_H
#define _RELOCATABLE_H
/* This can be enabled through the configure --enable-relocatable option. */
#if ENABLE_RELOCATABLE
/* When building a DLL, we must export some functions. Note that because
this is a private .h file, we don't need to use __declspec(dllimport)
in any case. */
#if defined _MSC_VER && BUILDING_DLL
# define RELOCATABLE_DLL_EXPORTED __declspec(dllexport)
#else
# define RELOCATABLE_DLL_EXPORTED
#endif
/* Sets the original and the current installation prefix of the package.
Relocation simply replaces a pathname starting with the original prefix
by the corresponding pathname with the current prefix instead. Both
prefixes should be directory names without trailing slash (i.e. use ""
instead of "/"). */
extern RELOCATABLE_DLL_EXPORTED void
set_relocation_prefix (const char *orig_prefix,
const char *curr_prefix);
/* Returns the pathname, relocated according to the current installation
directory. */
extern const char * relocate (const char *pathname);
/* Memory management: relocate() leaks memory, because it has to construct
a fresh pathname. If this is a problem because your program calls
relocate() frequently, think about caching the result. */
/* Convenience function:
Computes the current installation prefix, based on the original
installation prefix, the original installation directory of a particular
file, and the current pathname of this file. Returns NULL upon failure. */
extern const char * compute_curr_prefix (const char *orig_installprefix,
const char *orig_installdir,
const char *curr_pathname);
#else
/* By default, we use the hardwired pathnames. */
#define relocate(pathname) (pathname)
#endif
#endif /* _RELOCATABLE_H */

144
lib/intl/textdomain.c Normal file
View file

@ -0,0 +1,144 @@
/* textdomain.c - Implementation of the textdomain(3) function. */
/* Copyright (C) 1995-1998, 2000, 2001, 2002, 2005-2009 Free Software Foundation, Inc.
This file is part of GNU Bash.
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/>.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#ifdef _LIBC
# include <libintl.h>
#else
# include "libgnuintl.h"
#endif
#include "gettextP.h"
#ifdef _LIBC
/* We have to handle multi-threaded applications. */
# include <bits/libc-lock.h>
#else
/* Provide dummy implementation if this is outside glibc. */
# define __libc_rwlock_define(CLASS, NAME)
# define __libc_rwlock_wrlock(NAME)
# define __libc_rwlock_unlock(NAME)
#endif
/* The internal variables in the standalone libintl.a must have different
names than the internal variables in GNU libc, otherwise programs
using libintl.a cannot be linked statically. */
#if !defined _LIBC
# define _nl_default_default_domain libintl_nl_default_default_domain
# define _nl_current_default_domain libintl_nl_current_default_domain
#endif
/* @@ end of prolog @@ */
/* Name of the default text domain. */
extern const char _nl_default_default_domain[] attribute_hidden;
/* Default text domain in which entries for gettext(3) are to be found. */
extern const char *_nl_current_default_domain attribute_hidden;
/* Names for the libintl functions are a problem. They must not clash
with existing names and they should follow ANSI C. But this source
code is also used in GNU C Library where the names have a __
prefix. So we have to make a difference here. */
#ifdef _LIBC
# define TEXTDOMAIN __textdomain
# ifndef strdup
# define strdup(str) __strdup (str)
# endif
#else
# define TEXTDOMAIN libintl_textdomain
#endif
/* Lock variable to protect the global data in the gettext implementation. */
__libc_rwlock_define (extern, _nl_state_lock attribute_hidden)
/* Set the current default message catalog to DOMAINNAME.
If DOMAINNAME is null, return the current default.
If DOMAINNAME is "", reset to the default of "messages". */
char *
TEXTDOMAIN (domainname)
const char *domainname;
{
char *new_domain;
char *old_domain;
/* A NULL pointer requests the current setting. */
if (domainname == NULL)
return (char *) _nl_current_default_domain;
__libc_rwlock_wrlock (_nl_state_lock);
old_domain = (char *) _nl_current_default_domain;
/* If domain name is the null string set to default domain "messages". */
if (domainname[0] == '\0'
|| strcmp (domainname, _nl_default_default_domain) == 0)
{
_nl_current_default_domain = _nl_default_default_domain;
new_domain = (char *) _nl_current_default_domain;
}
else if (strcmp (domainname, old_domain) == 0)
/* This can happen and people will use it to signal that some
environment variable changed. */
new_domain = old_domain;
else
{
/* If the following malloc fails `_nl_current_default_domain'
will be NULL. This value will be returned and so signals we
are out of core. */
#if defined _LIBC || defined HAVE_STRDUP
new_domain = strdup (domainname);
#else
size_t len = strlen (domainname) + 1;
new_domain = (char *) malloc (len);
if (new_domain != NULL)
memcpy (new_domain, domainname, len);
#endif
if (new_domain != NULL)
_nl_current_default_domain = new_domain;
}
/* We use this possibility to signal a change of the loaded catalogs
since this is most likely the case and there is no other easy we
to do it. Do it only when the call was successful. */
if (new_domain != NULL)
{
++_nl_msg_cat_cntr;
if (old_domain != new_domain && old_domain != _nl_default_default_domain)
free (old_domain);
}
__libc_rwlock_unlock (_nl_state_lock);
return new_domain;
}
#ifdef _LIBC
/* Alias for function name in GNU C Library. */
weak_alias (__textdomain, textdomain);
#endif

139
lib/malloc/Makefile.in Normal file
View file

@ -0,0 +1,139 @@
# Skeleton Makefile for the GNU malloc code
#
# Copyright (C) 1996-2021 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
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
srcdir = @srcdir@
VPATH = @srcdir@
topdir = @top_srcdir@
BUILD_DIR = @BUILD_DIR@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
CC = @CC@
RANLIB = @RANLIB@
AR = @AR@
ARFLAGS = @ARFLAGS@
RM = rm -f
CP = cp
MV = mv
SHELL = @MAKE_SHELL@
PROFILE_FLAGS = @PROFILE_FLAGS@
CFLAGS = @CFLAGS@
LOCAL_CFLAGS = @LOCAL_CFLAGS@
STYLE_CFLAGS = @STYLE_CFLAGS@
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
DEFS = @DEFS@
LOCAL_DEFS = @LOCAL_DEFS@
LIBBUILD = ${BUILD_DIR}/lib
BASHINCDIR = ${topdir}/include
INTL_LIBSRC = ${topdir}/lib/intl
INTL_BUILDDIR = ${LIBBUILD}/intl
INTL_INC = @INTL_INC@
LIBINTL_H = @LIBINTL_H@
INCLUDES = -I. -I../.. -I$(topdir) -I$(BASHINCDIR) -I$(topdir)/lib $(INTL_INC)
CCFLAGS = ${PROFILE_FLAGS} ${INCLUDES} $(DEFS) $(LOCAL_DEFS) $(LOCAL_CFLAGS) \
$(CFLAGS) $(MALLOC_CFLAGS) $(STYLE_CFLAGS) $(CPPFLAGS)
.c.o:
$(CC) $(CCFLAGS) -c $<
.s.o:
$(CC) $(CCFLAGS) -c $<
MALLOC_SOURCE = malloc.c
STUB_SOURCE = stub.c
ALLOCA_SOURCE = alloca.c
ALLOCA_OBJECT = alloca.o
MALLOC_SRC = @MALLOC_SRC@
MALLOC = @MALLOC@
ALLOCA = @ALLOCA@
MALLOC_OBJS = malloc.o $(ALLOCA) trace.o stats.o table.o watch.o
STUB_OBJS = $(ALLOCA) stub.o
.PHONY: malloc stubmalloc
all: malloc
malloc: ${MALLOC_OBJS}
${RM} libmalloc.a
${AR} ${ARFLAGS} libmalloc.a ${MALLOC_OBJS}
-test -n "$(RANLIB)" && $(RANLIB) libmalloc.a
stubmalloc: ${STUB_OBJS}
${RM} libmalloc.a
${AR} ${ARFLAGS} libmalloc.a ${STUB_OBJS}
-test -n "$(RANLIB)" && $(RANLIB) libmalloc.a
alloca: ${ALLOCA}
${RM} libmalloc.a
${AR} ${ARFLAGS} libmalloc.a ${ALLOCA}
-test -n "$(RANLIB)" && $(RANLIB) libmalloc.a
alloca.o: $(srcdir)/$(ALLOCA_SOURCE)
$(CC) $(CCFLAGS) -c $(srcdir)/$(ALLOCA_SOURCE)
@- if test "$(ALLOCA_OBJECT)" != alloca.o ; then \
mv $(ALLOCA_OBJECT) alloca.o >/dev/null 2>&1 ; \
fi
mostlyclean clean:
$(RM) *.o libmalloc.a
distclean realclean maintainer-clean: clean
$(RM) Makefile
alloca.o: $(BUILD_DIR)/config.h
malloc.o: $(BUILD_DIR)/config.h $(topdir)/bashtypes.h getpagesize.h
xmalloc.o: $(BUILD_DIR)/config.h $(BASHINCDIR)/ansi_stdlib.h
trace.o: ${BUILD_DIR}/config.h
stats.o: ${BUILD_DIR}/config.h
table.o: ${BUILD_DIR}/config.h
watch.o: ${BUILD_DIR}/config.h
malloc.o: ${srcdir}/imalloc.h ${srcdir}/mstats.h
malloc.o: ${srcdir}/table.h ${srcdir}/watch.h
stats.o: ${srcdir}/imalloc.h ${srcdir}/mstats.h
trace.o: ${srcdir}/imalloc.h
table.o: ${srcdir}/imalloc.h ${srcdir}/table.h
watch.o: ${srcdir}/imalloc.h ${srcdir}/watch.h
malloc.o: ${topdir}/bashintl.h ${LIBINTL_H} ${BASHINCDIR}/gettext.h
stats.o: ${topdir}/bashintl.h ${LIBINTL_H} ${BASHINCDIR}/gettext.h
trace.o: ${topdir}/bashintl.h ${LIBINTL_H} ${BASHINCDIR}/gettext.h
table.o: ${topdir}/bashintl.h ${LIBINTL_H} ${BASHINCDIR}/gettext.h
watch.o: ${topdir}/bashintl.h ${LIBINTL_H} ${BASHINCDIR}/gettext.h
# Rules for deficient makes, like SunOS and Solaris
stub.o: stub.c
malloc.o: malloc.c
table.o: table.c
trace.o: trace.c
stats.o: stats.c
watch.o: watch.c

482
lib/malloc/alloca.c Normal file
View file

@ -0,0 +1,482 @@
/* alloca.c -- allocate automatically reclaimed memory
(Mostly) portable public-domain implementation -- D A Gwyn
This implementation of the PWB library alloca function,
which is used to allocate space off the run-time stack so
that it is automatically reclaimed upon procedure exit,
was inspired by discussions with J. Q. Johnson of Cornell.
J.Otto Tennant <jot@cray.com> contributed the Cray support.
There are some preprocessor constants that can
be defined when compiling for your specific system, for
improved efficiency; however, the defaults should be okay.
The general concept of this implementation is to keep
track of all alloca-allocated blocks, and reclaim any
that are found to be deeper in the stack than the current
invocation. This heuristic does not reclaim storage as
soon as it becomes invalid, but it will do so eventually.
As a special case, alloca(0) reclaims storage without
allocating any. It is a good idea to use alloca(0) in
your main control loop, etc. to force garbage collection. */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
/* If compiling with GCC 2, this file's not needed. */
#if !defined (__GNUC__) || __GNUC__ < 2
#include <bashtypes.h> /* for size_t */
/* If alloca is defined somewhere, this file is not needed. */
#ifndef alloca
#ifdef emacs
#ifdef static
/* actually, only want this if static is defined as ""
-- this is for usg, in which emacs must undefine static
in order to make unexec workable
*/
#ifndef STACK_DIRECTION
you
lose
-- must know STACK_DIRECTION at compile-time
#endif /* STACK_DIRECTION undefined */
#endif /* static */
#endif /* emacs */
/* If your stack is a linked list of frames, you have to
provide an "address metric" ADDRESS_FUNCTION macro. */
#if defined (CRAY) && defined (CRAY_STACKSEG_END)
long i00afunc ();
#define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg))
#else
#define ADDRESS_FUNCTION(arg) &(arg)
#endif /* CRAY && CRAY_STACKSEG_END */
#if __STDC__
typedef void *pointer;
#else
typedef char *pointer;
#endif
#define NULL 0
/* Different portions of Emacs need to call different versions of
malloc. The Emacs executable needs alloca to call xmalloc, because
ordinary malloc isn't protected from input signals. On the other
hand, the utilities in lib-src need alloca to call malloc; some of
them are very simple, and don't have an xmalloc routine.
Non-Emacs programs expect this to call use xmalloc.
Callers below should use malloc. */
#ifndef emacs
#define malloc xmalloc
extern pointer xmalloc ();
#endif
/* Define STACK_DIRECTION if you know the direction of stack
growth for your system; otherwise it will be automatically
deduced at run-time.
STACK_DIRECTION > 0 => grows toward higher addresses
STACK_DIRECTION < 0 => grows toward lower addresses
STACK_DIRECTION = 0 => direction of growth unknown */
#ifndef STACK_DIRECTION
#define STACK_DIRECTION 0 /* Direction unknown. */
#endif
#if STACK_DIRECTION != 0
#define STACK_DIR STACK_DIRECTION /* Known at compile-time. */
#else /* STACK_DIRECTION == 0; need run-time code. */
static int stack_dir; /* 1 or -1 once known. */
#define STACK_DIR stack_dir
static void
find_stack_direction ()
{
static char *addr = NULL; /* Address of first `dummy', once known. */
auto char dummy; /* To get stack address. */
if (addr == NULL)
{ /* Initial entry. */
addr = ADDRESS_FUNCTION (dummy);
find_stack_direction (); /* Recurse once. */
}
else
{
/* Second entry. */
if (ADDRESS_FUNCTION (dummy) > addr)
stack_dir = 1; /* Stack grew upward. */
else
stack_dir = -1; /* Stack grew downward. */
}
}
#endif /* STACK_DIRECTION == 0 */
/* An "alloca header" is used to:
(a) chain together all alloca'ed blocks;
(b) keep track of stack depth.
It is very important that sizeof(header) agree with malloc
alignment chunk size. The following default should work okay. */
#ifndef ALIGN_SIZE
#define ALIGN_SIZE sizeof(double)
#endif
typedef union hdr
{
char align[ALIGN_SIZE]; /* To force sizeof(header). */
struct
{
union hdr *next; /* For chaining headers. */
char *deep; /* For stack depth measure. */
} h;
} header;
static header *last_alloca_header = NULL; /* -> last alloca header. */
/* Return a pointer to at least SIZE bytes of storage,
which will be automatically reclaimed upon exit from
the procedure that called alloca. Originally, this space
was supposed to be taken from the current stack frame of the
caller, but that method cannot be made to work for some
implementations of C, for example under Gould's UTX/32. */
pointer
alloca (size)
size_t size;
{
auto char probe; /* Probes stack depth: */
register char *depth = ADDRESS_FUNCTION (probe);
#if STACK_DIRECTION == 0
if (STACK_DIR == 0) /* Unknown growth direction. */
find_stack_direction ();
#endif
/* Reclaim garbage, defined as all alloca'd storage that
was allocated from deeper in the stack than currently. */
{
register header *hp; /* Traverses linked list. */
for (hp = last_alloca_header; hp != NULL;)
if ((STACK_DIR > 0 && hp->h.deep > depth)
|| (STACK_DIR < 0 && hp->h.deep < depth))
{
register header *np = hp->h.next;
free ((pointer) hp); /* Collect garbage. */
hp = np; /* -> next header. */
}
else
break; /* Rest are not deeper. */
last_alloca_header = hp; /* -> last valid storage. */
}
if (size == 0)
return NULL; /* No allocation required. */
/* Allocate combined header + user data storage. */
{
register pointer new = malloc (sizeof (header) + size);
/* Address of header. */
((header *) new)->h.next = last_alloca_header;
((header *) new)->h.deep = depth;
last_alloca_header = (header *) new;
/* User storage begins just after header. */
return (pointer) ((char *) new + sizeof (header));
}
}
#if defined (CRAY) && defined (CRAY_STACKSEG_END)
#ifdef DEBUG_I00AFUNC
#include <stdio.h>
#endif
#ifndef CRAY_STACK
#define CRAY_STACK
#ifndef CRAY2
/* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */
struct stack_control_header
{
long shgrow:32; /* Number of times stack has grown. */
long shaseg:32; /* Size of increments to stack. */
long shhwm:32; /* High water mark of stack. */
long shsize:32; /* Current size of stack (all segments). */
};
/* The stack segment linkage control information occurs at
the high-address end of a stack segment. (The stack
grows from low addresses to high addresses.) The initial
part of the stack segment linkage control information is
0200 (octal) words. This provides for register storage
for the routine which overflows the stack. */
struct stack_segment_linkage
{
long ss[0200]; /* 0200 overflow words. */
long sssize:32; /* Number of words in this segment. */
long ssbase:32; /* Offset to stack base. */
long:32;
long sspseg:32; /* Offset to linkage control of previous
segment of stack. */
long:32;
long sstcpt:32; /* Pointer to task common address block. */
long sscsnm; /* Private control structure number for
microtasking. */
long ssusr1; /* Reserved for user. */
long ssusr2; /* Reserved for user. */
long sstpid; /* Process ID for pid based multi-tasking. */
long ssgvup; /* Pointer to multitasking thread giveup. */
long sscray[7]; /* Reserved for Cray Research. */
long ssa0;
long ssa1;
long ssa2;
long ssa3;
long ssa4;
long ssa5;
long ssa6;
long ssa7;
long sss0;
long sss1;
long sss2;
long sss3;
long sss4;
long sss5;
long sss6;
long sss7;
};
#else /* CRAY2 */
/* The following structure defines the vector of words
returned by the STKSTAT library routine. */
struct stk_stat
{
long now; /* Current total stack size. */
long maxc; /* Amount of contiguous space which would
be required to satisfy the maximum
stack demand to date. */
long high_water; /* Stack high-water mark. */
long overflows; /* Number of stack overflow ($STKOFEN) calls. */
long hits; /* Number of internal buffer hits. */
long extends; /* Number of block extensions. */
long stko_mallocs; /* Block allocations by $STKOFEN. */
long underflows; /* Number of stack underflow calls ($STKRETN). */
long stko_free; /* Number of deallocations by $STKRETN. */
long stkm_free; /* Number of deallocations by $STKMRET. */
long segments; /* Current number of stack segments. */
long maxs; /* Maximum number of stack segments so far. */
long pad_size; /* Stack pad size. */
long current_address; /* Current stack segment address. */
long current_size; /* Current stack segment size. This
number is actually corrupted by STKSTAT to
include the fifteen word trailer area. */
long initial_address; /* Address of initial segment. */
long initial_size; /* Size of initial segment. */
};
/* The following structure describes the data structure which trails
any stack segment. I think that the description in 'asdef' is
out of date. I only describe the parts that I am sure about. */
struct stk_trailer
{
long this_address; /* Address of this block. */
long this_size; /* Size of this block (does not include
this trailer). */
long unknown2;
long unknown3;
long link; /* Address of trailer block of previous
segment. */
long unknown5;
long unknown6;
long unknown7;
long unknown8;
long unknown9;
long unknown10;
long unknown11;
long unknown12;
long unknown13;
long unknown14;
};
#endif /* CRAY2 */
#endif /* not CRAY_STACK */
#ifdef CRAY2
/* Determine a "stack measure" for an arbitrary ADDRESS.
I doubt that "lint" will like this much. */
static long
i00afunc (long *address)
{
struct stk_stat status;
struct stk_trailer *trailer;
long *block, size;
long result = 0;
/* We want to iterate through all of the segments. The first
step is to get the stack status structure. We could do this
more quickly and more directly, perhaps, by referencing the
$LM00 common block, but I know that this works. */
STKSTAT (&status);
/* Set up the iteration. */
trailer = (struct stk_trailer *) (status.current_address
+ status.current_size
- 15);
/* There must be at least one stack segment. Therefore it is
a fatal error if "trailer" is null. */
if (trailer == 0)
abort ();
/* Discard segments that do not contain our argument address. */
while (trailer != 0)
{
block = (long *) trailer->this_address;
size = trailer->this_size;
if (block == 0 || size == 0)
abort ();
trailer = (struct stk_trailer *) trailer->link;
if ((block <= address) && (address < (block + size)))
break;
}
/* Set the result to the offset in this segment and add the sizes
of all predecessor segments. */
result = address - block;
if (trailer == 0)
{
return result;
}
do
{
if (trailer->this_size <= 0)
abort ();
result += trailer->this_size;
trailer = (struct stk_trailer *) trailer->link;
}
while (trailer != 0);
/* We are done. Note that if you present a bogus address (one
not in any segment), you will get a different number back, formed
from subtracting the address of the first block. This is probably
not what you want. */
return (result);
}
#else /* not CRAY2 */
/* Stack address function for a CRAY-1, CRAY X-MP, or CRAY Y-MP.
Determine the number of the cell within the stack,
given the address of the cell. The purpose of this
routine is to linearize, in some sense, stack addresses
for alloca. */
static long
i00afunc (long address)
{
long stkl = 0;
long size, pseg, this_segment, stack;
long result = 0;
struct stack_segment_linkage *ssptr;
/* Register B67 contains the address of the end of the
current stack segment. If you (as a subprogram) store
your registers on the stack and find that you are past
the contents of B67, you have overflowed the segment.
B67 also points to the stack segment linkage control
area, which is what we are really interested in. */
/* This might be _getb67() or GETB67 () or getb67 () */
stkl = CRAY_STACKSEG_END ();
ssptr = (struct stack_segment_linkage *) stkl;
/* If one subtracts 'size' from the end of the segment,
one has the address of the first word of the segment.
If this is not the first segment, 'pseg' will be
nonzero. */
pseg = ssptr->sspseg;
size = ssptr->sssize;
this_segment = stkl - size;
/* It is possible that calling this routine itself caused
a stack overflow. Discard stack segments which do not
contain the target address. */
while (!(this_segment <= address && address <= stkl))
{
#ifdef DEBUG_I00AFUNC
fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl);
#endif
if (pseg == 0)
break;
stkl = stkl - pseg;
ssptr = (struct stack_segment_linkage *) stkl;
size = ssptr->sssize;
pseg = ssptr->sspseg;
this_segment = stkl - size;
}
result = address - this_segment;
/* If you subtract pseg from the current end of the stack,
you get the address of the previous stack segment's end.
This seems a little convoluted to me, but I'll bet you save
a cycle somewhere. */
while (pseg != 0)
{
#ifdef DEBUG_I00AFUNC
fprintf (stderr, "%011o %011o\n", pseg, size);
#endif
stkl = stkl - pseg;
ssptr = (struct stack_segment_linkage *) stkl;
size = ssptr->sssize;
pseg = ssptr->sspseg;
result += size;
}
return (result);
}
#endif /* not CRAY2 */
#endif /* CRAY && CRAY_STACKSEG_END */
#endif /* no alloca */
#endif /* !__GNUC__ || __GNUC__ < 2 */

60
lib/malloc/getpagesize.h Normal file
View file

@ -0,0 +1,60 @@
/* Emulation of getpagesize() for systems that need it.
Copyright (C) 1991-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 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/>.
*/
#if defined (HAVE_UNISTD_H)
# ifdef _MINIX
# include <sys/types.h>
# endif
# include <unistd.h>
# if defined (_SC_PAGESIZE)
# define getpagesize() sysconf(_SC_PAGESIZE)
# else
# if defined (_SC_PAGE_SIZE)
# define getpagesize() sysconf(_SC_PAGE_SIZE)
# endif /* _SC_PAGE_SIZE */
# endif /* _SC_PAGESIZE */
#endif
#if !defined (getpagesize)
# if defined (HAVE_SYS_PARAM_H)
# include <sys/param.h>
# endif
# if defined (PAGESIZE)
# define getpagesize() PAGESIZE
# else /* !PAGESIZE */
# if defined (EXEC_PAGESIZE)
# define getpagesize() EXEC_PAGESIZE
# else /* !EXEC_PAGESIZE */
# if defined (NBPG)
# if !defined (CLSIZE)
# define CLSIZE 1
# endif /* !CLSIZE */
# define getpagesize() (NBPG * CLSIZE)
# else /* !NBPG */
# if defined (NBPC)
# define getpagesize() NBPC
# endif /* NBPC */
# endif /* !NBPG */
# endif /* !EXEC_PAGESIZE */
# endif /* !PAGESIZE */
#endif /* !getpagesize */
#if !defined (getpagesize)
# define getpagesize() 4096 /* Just punt and use reasonable value */
#endif

16
lib/malloc/i386-alloca.s Normal file
View file

@ -0,0 +1,16 @@
.file "alloca.s"
.text
.align 4
.def alloca; .val alloca; .scl 2; .type 044; .endef
.globl alloca
alloca:
popl %edx
popl %eax
addl $3,%eax
andl $0xfffffffc,%eax
subl %eax,%esp
movl %esp,%eax
pushl %eax
pushl %edx
ret
.def alloca; .val .; .scl -1; .endef

178
lib/malloc/imalloc.h Normal file
View file

@ -0,0 +1,178 @@
/* imalloc.h -- internal malloc definitions shared by source files. */
/* Copyright (C) 2001-2020 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/>.
*/
/* Must be included *after* config.h */
#ifndef _IMALLOC_H
#define _IMALLOC_H
#ifdef MALLOC_DEBUG
#define MALLOC_STATS
#define MALLOC_TRACE
#define MALLOC_REGISTER
#define MALLOC_WATCH
#endif
#define MALLOC_WRAPFUNCS
/* If defined, as it is by default, use the lesscore() function to attempt
to reduce the top of the heap when freeing memory blocks larger than a
defined threshold. */
#define USE_LESSCORE
/* Generic pointer type. */
#ifndef PTR_T
# if defined (__STDC__)
# define PTR_T void *
# else
# define PTR_T char *
# endif
#endif
#if !defined (NULL)
# define NULL 0
#endif
#if !defined (CPP_STRING)
# if defined (HAVE_STRINGIZE)
# define CPP_STRING(x) #x
# else
# define CPP_STRING(x) "x"
# endif /* !HAVE_STRINGIZE */
#endif /* !__STRING */
#if __GNUC__ > 1
# define FASTCOPY(s, d, n) __builtin_memcpy (d, s, n)
#else /* !__GNUC__ */
# if !defined (HAVE_BCOPY)
# if !defined (HAVE_MEMMOVE)
# define FASTCOPY(s, d, n) memcpy (d, s, n)
# else
# define FASTCOPY(s, d, n) memmove (d, s, n)
# endif /* !HAVE_MEMMOVE */
# else /* HAVE_BCOPY */
# define FASTCOPY(s, d, n) bcopy (s, d, n)
# endif /* HAVE_BCOPY */
#endif /* !__GNUC__ */
#if !defined (PARAMS)
# if defined (__STDC__) || defined (__GNUC__) || defined (__cplusplus) || defined (PROTOTYPES)
# define PARAMS(protos) protos
# else
# define PARAMS(protos) ()
# endif
#endif
/* Use Duff's device for good zeroing/copying performance. DO NOT call the
Duff's device macros with NBYTES == 0. */
#define MALLOC_BZERO(charp, nbytes) \
do { \
if ((nbytes) <= 32) { \
size_t * mzp = (size_t *)(charp); \
unsigned long mctmp = (nbytes)/sizeof(size_t); \
long mcn; \
if (mctmp < 8) mcn = 0; else { mcn = (mctmp-1)/8; mctmp &= 7; } \
switch (mctmp) { \
case 0: for(;;) { *mzp++ = 0; \
case 7: *mzp++ = 0; \
case 6: *mzp++ = 0; \
case 5: *mzp++ = 0; \
case 4: *mzp++ = 0; \
case 3: *mzp++ = 0; \
case 2: *mzp++ = 0; \
case 1: *mzp++ = 0; if(mcn <= 0) break; mcn--; } \
} \
else \
memset ((charp), 0, (nbytes)); \
} while(0)
#define MALLOC_ZERO(charp, nbytes) \
do { \
size_t mzsz = (nbytes); \
if (mzsz <= 9 * sizeof(mzsz) { \
size_t *mz = (size_t *)(charp); \
if(mzsz >= 5*sizeof(mzsz)) { *mz++ = 0; \
*mz++ = 0; \
if(mzsz >= 7*sizeof(mzsz)) { *mz++ = 0; \
*mz++ = 0; \
if(mzsz >= 9*sizeof(mzsz)) { *mz++ = 0; \
*mz++ = 0; }}} \
*mz++ = 0; \
*mz++ = 0; \
*mz = 0; \
} else \
memset ((charp), 0, mzsz); \
} while (0)
#define MALLOC_MEMSET(charp, xch, nbytes) \
do { \
if ((nbytes) <= 32) { \
register char * mzp = (charp); \
unsigned long mctmp = (nbytes); \
register long mcn; \
if (mctmp < 8) mcn = 0; else { mcn = (mctmp-1)/8; mctmp &= 7; } \
switch (mctmp) { \
case 0: for(;;) { *mzp++ = xch; \
case 7: *mzp++ = xch; \
case 6: *mzp++ = xch; \
case 5: *mzp++ = xch; \
case 4: *mzp++ = xch; \
case 3: *mzp++ = xch; \
case 2: *mzp++ = xch; \
case 1: *mzp++ = xch; if(mcn <= 0) break; mcn--; } \
} \
} else \
memset ((charp), (xch), (nbytes)); \
} while(0)
#define MALLOC_MEMCPY(dest,src,nbytes) \
do { \
if ((nbytes) <= 32) { \
size_t* mcsrc = (size_t*) src; \
size_t* mcdst = (size_t*) dest; \
unsigned long mctmp = (nbytes)/sizeof(size_t); \
long mcn; \
if (mctmp < 8) mcn = 0; else { mcn = (mctmp-1)/8; mctmp &= 7; } \
switch (mctmp) { \
case 0: for(;;) { *mcdst++ = *mcsrc++; \
case 7: *mcdst++ = *mcsrc++; \
case 6: *mcdst++ = *mcsrc++; \
case 5: *mcdst++ = *mcsrc++; \
case 4: *mcdst++ = *mcsrc++; \
case 3: *mcdst++ = *mcsrc++; \
case 2: *mcdst++ = *mcsrc++; \
case 1: *mcdst++ = *mcsrc++; if(mcn <= 0) break; mcn--; } \
} else \
memcpy ((dest), (src), (nbytes)) \
} while(0)
#if defined (SHELL)
# include "bashintl.h"
#else
# define _(x) x
#endif
#include <signal.h>
extern void _malloc_block_signals PARAMS((sigset_t *, sigset_t *));
extern void _malloc_unblock_signals PARAMS((sigset_t *, sigset_t *));
#endif /* _IMALLOC_H */

1558
lib/malloc/malloc.c Normal file

File diff suppressed because it is too large Load diff

114
lib/malloc/mstats.h Normal file
View file

@ -0,0 +1,114 @@
/* mstats.h - definitions for malloc statistics */
/* Copyright (C) 2001-2021 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/>.
*/
#ifndef _MSTATS_H
#define _MSTATS_H
#include "imalloc.h"
#ifdef MALLOC_STATS
/* This needs to change if the definition in malloc.c changes */
#ifndef NBUCKETS
# define NBUCKETS 28
#endif
/*
* NMALLOC[i] is the difference between the number of mallocs and frees
* for a given block size. TMALLOC[i] is the total number of mallocs for
* a given block size. NMORECORE[i] is the total number of calls to
* morecore(i). NLESSCORE[i] is the total number of calls to lesscore(i).
*
* NMAL and NFRE are counts of the number of calls to malloc() and free(),
* respectively. NREALLOC is the total number of calls to realloc();
* NRCOPY is the number of times realloc() had to allocate new memory and
* copy to it. NRECURSE is a count of the number of recursive calls to
* malloc() for the same bucket size, which can be caused by calls to
* malloc() from a signal handler.
*
* NSBRK is the number of calls to sbrk() (whether by morecore() or for
* alignment); TSBRK is the total number of bytes requested from the kernel
* with sbrk().
*
* BYTESUSED is the total number of bytes consumed by blocks currently in
* use; BYTESFREE is the total number of bytes currently on all of the free
* lists. BYTESREQ is the total number of bytes requested by the caller
* via calls to malloc() and realloc().
*
* TBSPLIT is the number of times a larger block was split to satisfy a
* smaller request. NSPLIT[i] is the number of times a block of size I was
* split.
*
* TBCOALESCE is the number of times two adjacent smaller blocks off the free
* list were combined to satisfy a larger request.
*/
struct _malstats {
int nmalloc[NBUCKETS];
int tmalloc[NBUCKETS];
int nmorecore[NBUCKETS];
int nlesscore[NBUCKETS];
int nmal;
int nfre;
int nrealloc;
int nrcopy;
int nrecurse;
int nsbrk;
bits32_t tsbrk;
bits32_t bytesused;
bits32_t bytesfree;
u_bits32_t bytesreq;
int tbsplit;
int nsplit[NBUCKETS];
int tbcoalesce;
int ncoalesce[NBUCKETS];
int nmmap;
bits32_t tmmap;
};
/* Return statistics describing allocation of blocks of size BLOCKSIZE.
NFREE is the number of free blocks for this allocation size. NUSED
is the number of blocks in use. NMAL is the number of requests for
blocks of size BLOCKSIZE. NMORECORE is the number of times we had
to call MORECORE to repopulate the free list for this bucket.
NLESSCORE is the number of times we gave memory back to the system
from this bucket. NSPLIT is the number of times a block of this size
was split to satisfy a smaller request. NCOALESCE is the number of
times two blocks of this size were combined to satisfy a larger
request. */
struct bucket_stats {
u_bits32_t blocksize;
int nfree;
int nused;
int nmal;
int nmorecore;
int nlesscore;
int nsplit;
int ncoalesce;
int nmmap; /* currently unused */
};
extern struct bucket_stats malloc_bucket_stats PARAMS((int));
extern struct _malstats malloc_stats PARAMS((void));
extern void print_malloc_stats PARAMS((char *));
extern void trace_malloc_stats PARAMS((char *, char *));
#endif /* MALLOC_STATS */
#endif /* _MSTATS_H */

70
lib/malloc/shmalloc.h Normal file
View file

@ -0,0 +1,70 @@
/* Functions (currently) for use by the shell to do malloc debugging and
tracking. */
/* Copyright (C) 2001-2020 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/>.
*/
#ifndef _SH_MALLOC_H
#define _SH_MALLOC_H
#ifndef PARAMS
# if defined (__STDC__) || defined (__GNUC__) || defined (__cplusplus)
# define PARAMS(protos) protos
# else
# define PARAMS(protos) ()
# endif
#endif
/* Generic pointer type. */
#ifndef PTR_T
#if defined (__STDC__)
# define PTR_T void *
#else
# define PTR_T char *
#endif
#endif /* PTR_T */
extern PTR_T sh_malloc PARAMS((size_t, const char *, int));
extern PTR_T sh_realloc PARAMS((PTR_T, size_t, const char *, int));
extern void sh_free PARAMS((PTR_T, const char *, int));
extern PTR_T sh_memalign PARAMS((size_t, size_t, const char *, int));
extern PTR_T sh_calloc PARAMS((size_t, size_t, const char *, int));
extern void sh_cfree PARAMS((PTR_T, const char *, int));
extern PTR_T sh_valloc PARAMS((size_t, const char *, int));
/* trace.c */
extern int malloc_set_trace PARAMS((int));
extern void malloc_set_tracefp (); /* full prototype requires stdio.h */
extern void malloc_set_tracefn PARAMS((char *, char *));
/* table.c */
extern void mregister_dump_table PARAMS((void));
extern void mregister_table_init PARAMS((void));
extern int malloc_set_register PARAMS((int));
/* stats.c */
extern void print_malloc_stats PARAMS((char *));
extern void fprint_malloc_stats (); /* full prototype requires stdio.h */
extern void trace_malloc_stats PARAMS((char *, char *));
#endif

213
lib/malloc/stats.c Normal file
View file

@ -0,0 +1,213 @@
/* stats.c - malloc statistics */
/* Copyright (C) 2001-2020 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/>.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "imalloc.h"
#ifdef MALLOC_STATS
#include <stdio.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <string.h>
#include "mstats.h"
extern int malloc_free_blocks PARAMS((int));
extern int malloc_mmap_threshold;
extern struct _malstats _mstats;
extern FILE *_imalloc_fopen PARAMS((char *, char *, char *, char *, size_t));
struct bucket_stats
malloc_bucket_stats (size)
int size;
{
struct bucket_stats v;
v.nfree = 0;
if (size < 0 || size >= NBUCKETS)
{
v.blocksize = 0;
v.nused = v.nmal = v.nmorecore = v.nlesscore = v.nsplit = 0;
return v;
}
v.blocksize = 1 << (size + 3);
v.nused = _mstats.nmalloc[size];
v.nmal = _mstats.tmalloc[size];
v.nmorecore = _mstats.nmorecore[size];
v.nlesscore = _mstats.nlesscore[size];
v.nsplit = _mstats.nsplit[size];
v.ncoalesce = _mstats.ncoalesce[size];
v.nfree = malloc_free_blocks (size); /* call back to malloc.c */
return v;
}
/* Return a copy of _MSTATS, with two additional fields filled in:
BYTESFREE is the total number of bytes on free lists. BYTESUSED
is the total number of bytes in use. These two fields are fairly
expensive to compute, so we do it only when asked to. */
struct _malstats
malloc_stats ()
{
struct _malstats result;
struct bucket_stats v;
register int i;
result = _mstats;
result.bytesused = result.bytesfree = 0;
for (i = 0; i < NBUCKETS; i++)
{
v = malloc_bucket_stats (i);
result.bytesfree += v.nfree * v.blocksize;
result.bytesused += v.nused * v.blocksize;
}
return (result);
}
static void
_print_malloc_stats (s, fp)
char *s;
FILE *fp;
{
register int i;
unsigned long totused, totfree;
struct bucket_stats v;
fprintf (fp, "Memory allocation statistics: %s\n size\tfree\tin use\ttotal\tmorecore lesscore split\tcoalesce\n", s ? s : "");
for (i = totused = totfree = 0; i < NBUCKETS; i++)
{
v = malloc_bucket_stats (i);
/* Show where the mmap threshold is; sizes greater than this use mmap to
allocate and munmap to free (munmap shows up as lesscore). */
if (i == malloc_mmap_threshold+1)
fprintf (fp, "--------\n");
if (v.nmal > 0)
fprintf (fp, "%8lu\t%4d\t%6d\t%5d%8d\t%8d %5d %8d\n", (unsigned long)v.blocksize, v.nfree, v.nused, v.nmal, v.nmorecore, v.nlesscore, v.nsplit, v.ncoalesce);
totfree += v.nfree * v.blocksize;
totused += v.nused * v.blocksize;
}
fprintf (fp, "\nTotal bytes in use: %lu, total bytes free: %lu\n",
totused, totfree);
fprintf (fp, "\nTotal bytes requested by application: %lu\n", (unsigned long)_mstats.bytesreq);
fprintf (fp, "Total mallocs: %d, total frees: %d, total reallocs: %d (%d copies)\n",
_mstats.nmal, _mstats.nfre, _mstats.nrealloc, _mstats.nrcopy);
fprintf (fp, "Total sbrks: %d, total bytes via sbrk: %d\n",
_mstats.nsbrk, _mstats.tsbrk);
fprintf (fp, "Total mmaps: %d, total bytes via mmap: %d\n",
_mstats.nmmap, _mstats.tmmap);
fprintf (fp, "Total blocks split: %d, total block coalesces: %d\n",
_mstats.tbsplit, _mstats.tbcoalesce);
}
void
print_malloc_stats (s)
char *s;
{
_print_malloc_stats (s, stderr);
}
void
fprint_malloc_stats (s, fp)
char *s;
FILE *fp;
{
_print_malloc_stats (s, fp);
}
#define TRACEROOT "/var/tmp/maltrace/stats."
void
trace_malloc_stats (s, fn)
char *s, *fn;
{
FILE *fp;
char defname[sizeof (TRACEROOT) + 64];
static char mallbuf[1024];
fp = _imalloc_fopen (s, fn, TRACEROOT, defname, sizeof (defname));
if (fp)
{
setvbuf (fp, mallbuf, _IOFBF, sizeof (mallbuf));
_print_malloc_stats (s, fp);
fflush(fp);
fclose(fp);
}
}
#endif /* MALLOC_STATS */
#if defined (MALLOC_STATS) || defined (MALLOC_TRACE)
FILE *
_imalloc_fopen (s, fn, def, defbuf, defsiz)
char *s;
char *fn;
char *def;
char *defbuf;
size_t defsiz;
{
char fname[1024];
long l;
FILE *fp;
l = (long)getpid ();
if (fn == 0)
{
sprintf (defbuf, "%s%ld", def, l);
fp = fopen(defbuf, "w");
}
else
{
char *p, *q, *r;
char pidbuf[32];
int sp;
sprintf (pidbuf, "%ld", l);
if ((strlen (pidbuf) + strlen (fn) + 2) >= sizeof (fname))
return ((FILE *)0);
for (sp = 0, p = fname, q = fn; *q; )
{
if (sp == 0 && *q == '%' && q[1] == 'p')
{
sp = 1;
for (r = pidbuf; *r; )
*p++ = *r++;
q += 2;
}
else
*p++ = *q++;
}
*p = '\0';
fp = fopen (fname, "w");
}
return fp;
}
#endif /* MALLOC_STATS || MALLOC_TRACE */

22
lib/malloc/stub.c Normal file
View file

@ -0,0 +1,22 @@
/* Copyright (C) 1993-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 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/>.
*/
void
bash_malloc_stub()
{
}

429
lib/malloc/table.c Normal file
View file

@ -0,0 +1,429 @@
/* table.c - bookkeeping functions for allocated memory */
/* Copyright (C) 2001-2020 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/>.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <string.h>
#include "imalloc.h"
#include "table.h"
#ifdef SHELL
extern int running_trap;
extern int signal_is_trapped PARAMS((int));
#endif
extern int malloc_register;
#ifdef MALLOC_REGISTER
extern FILE *_imalloc_fopen PARAMS((char *, char *, char *, char *, size_t));
#define FIND_ALLOC 0x01 /* find slot for new allocation */
#define FIND_EXIST 0x02 /* find slot for existing entry for free() or search */
static int table_count = 0;
static int table_allocated = 0;
static int table_bucket_index = REG_TABLE_SIZE-1;
static mr_table_t mem_table[REG_TABLE_SIZE];
static mr_table_t mem_overflow;
#ifndef STREQ
#define STREQ(a, b) ((a)[0] == (b)[0] && strcmp(a, b) == 0)
#endif
static int location_table_index = 0;
static int location_table_count = 0;
static ma_table_t mlocation_table[REG_TABLE_SIZE];
/*
* NOTE: taken from dmalloc (http://dmalloc.com) and modified.
*/
static unsigned int
mt_hash (key)
const PTR_T key;
{
unsigned int a, b, c;
unsigned long x;
/* set up the internal state */
a = 0x9e3779b9; /* the golden ratio; an arbitrary value */
x = (unsigned long)key; /* truncation is OK */
b = x >> 8;
c = x >> 3; /* XXX - was >> 4 */
HASH_MIX(a, b, c);
return c;
}
#if 0
static unsigned int
which_bucket (mem)
PTR_T mem;
{
return (mt_hash ((unsigned char *)mem) & (REG_TABLE_SIZE-1));
}
#else
#define which_bucket(mem) (mt_hash ((unsigned char *)(mem)) & (REG_TABLE_SIZE-1));
#define next_bucket() ((table_bucket_index + 1) & (REG_TABLE_SIZE-1))
#define next_entry(mem) ((mem == mem_table + REG_TABLE_SIZE - 1) ? mem_table : ++mem)
#define prev_bucket() (table_bucket_index == 0 ? REG_TABLE_SIZE-1 : table_bucket_index-1)
#define prev_entry(mem) ((mem == mem_table) ? mem_table + REG_TABLE_SIZE - 1 : mem - 1)
#endif
static mr_table_t *
find_entry (mem, flags)
PTR_T mem;
int flags;
{
unsigned int bucket;
register mr_table_t *tp;
mr_table_t *endp;
if (mem_overflow.mem == mem)
return (&mem_overflow);
/* If we want to insert an allocation entry just use the next slot */
if (flags & FIND_ALLOC)
{
table_bucket_index = next_bucket();
table_count++;
tp = mem_table + table_bucket_index;
memset(tp, 0, sizeof (mr_table_t)); /* overwrite next existing entry */
return tp;
}
tp = endp = mem_table + table_bucket_index;
/* search for last allocation corresponding to MEM, return entry pointer */
while (1)
{
if (tp->mem == mem)
return (tp);
tp = prev_entry (tp);
/* if we went all the way around and didn't find it, return NULL */
if (tp == endp)
return ((mr_table_t *)NULL);
}
return (mr_table_t *)NULL;
}
mr_table_t *
mr_table_entry (mem)
PTR_T mem;
{
return (find_entry (mem, FIND_EXIST));
}
void
mregister_describe_mem (mem, fp)
PTR_T mem;
FILE *fp;
{
mr_table_t *entry;
entry = find_entry (mem, FIND_EXIST);
if (entry == 0)
return;
fprintf (fp, "malloc: %p: %s: last %s from %s:%d\n",
mem,
(entry->flags & MT_ALLOC) ? "allocated" : "free",
(entry->flags & MT_ALLOC) ? "allocated" : "freed",
entry->file ? entry->file : "unknown",
entry->line);
}
void
mregister_alloc (tag, mem, size, file, line)
const char *tag;
PTR_T mem;
size_t size;
const char *file;
int line;
{
mr_table_t *tentry;
sigset_t set, oset;
int blocked_sigs;
/* Block all signals in case we are executed from a signal handler. */
blocked_sigs = 0;
#ifdef SHELL
if (running_trap || signal_is_trapped (SIGINT) || signal_is_trapped (SIGCHLD))
#endif
{
_malloc_block_signals (&set, &oset);
blocked_sigs = 1;
}
mlocation_register_alloc (file, line);
tentry = find_entry (mem, FIND_ALLOC);
if (tentry == 0)
{
/* oops. table is full. punt. */
fprintf (stderr, _("register_alloc: alloc table is full with FIND_ALLOC?\n"));
if (blocked_sigs)
_malloc_unblock_signals (&set, &oset);
return;
}
if (tentry->flags & MT_ALLOC)
{
/* oops. bad bookkeeping. ignore for now */
fprintf (stderr, _("register_alloc: %p already in table as allocated?\n"), mem);
}
tentry->mem = mem;
tentry->size = size;
tentry->func = tag;
tentry->flags = MT_ALLOC;
tentry->file = file;
tentry->line = line;
tentry->nalloc++;
if (tentry != &mem_overflow)
table_allocated++;
if (blocked_sigs)
_malloc_unblock_signals (&set, &oset);
}
void
mregister_free (mem, size, file, line)
PTR_T mem;
int size;
const char *file;
int line;
{
mr_table_t *tentry;
sigset_t set, oset;
int blocked_sigs;
/* Block all signals in case we are executed from a signal handler. */
blocked_sigs = 0;
#ifdef SHELL
if (running_trap || signal_is_trapped (SIGINT) || signal_is_trapped (SIGCHLD))
#endif
{
_malloc_block_signals (&set, &oset);
blocked_sigs = 1;
}
tentry = find_entry (mem, FIND_EXIST);
if (tentry == 0)
{
/* oops. not found. */
#if 0
fprintf (stderr, "register_free: %p not in allocation table?\n", mem);
#endif
if (blocked_sigs)
_malloc_unblock_signals (&set, &oset);
return;
}
if (tentry->flags & MT_FREE)
{
/* oops. bad bookkeeping. ignore for now */
fprintf (stderr, _("register_free: %p already in table as free?\n"), mem);
}
tentry->flags = MT_FREE;
tentry->func = "free";
tentry->file = file;
tentry->line = line;
tentry->nfree++;
if (tentry != &mem_overflow)
table_allocated--;
if (blocked_sigs)
_malloc_unblock_signals (&set, &oset);
}
/* If we ever add more flags, this will require changes. */
static char *
_entry_flags(x)
int x;
{
if (x & MT_FREE)
return "free";
else if (x & MT_ALLOC)
return "allocated";
else
return "undetermined?";
}
static void
_register_dump_table(fp)
FILE *fp;
{
register int i;
mr_table_t entry;
for (i = 0; i < REG_TABLE_SIZE; i++)
{
entry = mem_table[i];
if (entry.mem)
fprintf (fp, "%s[%d] %p:%zu:%s:%s:%s:%d:%d:%d\n",
(i == table_bucket_index) ? "*" : "",
i,
entry.mem, entry.size,
_entry_flags(entry.flags),
entry.func ? entry.func : "unknown",
entry.file ? entry.file : "unknown",
entry.line,
entry.nalloc, entry.nfree);
}
}
void
mregister_dump_table()
{
_register_dump_table (stderr);
}
void
mregister_table_init ()
{
memset (mem_table, 0, sizeof(mr_table_t) * REG_TABLE_SIZE);
memset (&mem_overflow, 0, sizeof (mr_table_t));
table_count = 0;
}
/* Simple for now */
static ma_table_t *
find_location_entry (file, line)
const char *file;
int line;
{
register ma_table_t *tp, *endp;
endp = mlocation_table + location_table_count;
for (tp = mlocation_table; tp <= endp; tp++)
{
if (tp->line == line && STREQ (file, tp->file))
return tp;
}
return (ma_table_t *)NULL;
}
void
mlocation_register_alloc (file, line)
const char *file;
int line;
{
ma_table_t *lentry;
const char *nfile;
if (file == 0)
{
mlocation_table[0].nalloc++;
return;
}
nfile = strrchr (file, '/');
if (nfile)
nfile++;
else
nfile = file;
lentry = find_location_entry (nfile, line);
if (lentry == 0)
{
location_table_index++;
if (location_table_index == REG_TABLE_SIZE)
location_table_index = 1; /* slot 0 reserved */
lentry = mlocation_table + location_table_index;
lentry->file = nfile;
lentry->line = line;
lentry->nalloc = 1;
if (location_table_count < REG_TABLE_SIZE)
location_table_count++; /* clamp at REG_TABLE_SIZE for now */
}
else
lentry->nalloc++;
}
static void
_location_dump_table (fp)
FILE *fp;
{
register ma_table_t *tp, *endp;
endp = mlocation_table + location_table_count;
for (tp = mlocation_table; tp < endp; tp++)
fprintf (fp, "%s:%d\t%d\n", tp->file ? tp->file : "unknown",
tp->line ? tp->line : 0,
tp->nalloc);
}
void
mlocation_dump_table ()
{
_location_dump_table (stderr);
}
#define LOCROOT "/var/tmp/maltrace/locations."
void
mlocation_write_table ()
{
FILE *fp;
char defname[sizeof (LOCROOT) + 64];
fp = _imalloc_fopen ((char *)NULL, (char *)NULL, LOCROOT, defname, sizeof (defname));
if (fp == 0)
return; /* XXX - no error message yet */
_location_dump_table (fp);
fclose (fp);
}
void
mlocation_table_init ()
{
memset (mlocation_table, 0, sizeof (ma_table_t) * REG_TABLE_SIZE);
mlocation_table[0].file = ""; /* reserve slot 0 for unknown locations */
mlocation_table[0].line = 0;
mlocation_table[0].nalloc = 0;
location_table_count = 1;
}
#endif /* MALLOC_REGISTER */
int
malloc_set_register(n)
int n;
{
int old;
old = malloc_register;
malloc_register = n;
return old;
}

116
lib/malloc/table.h Normal file
View file

@ -0,0 +1,116 @@
/* table.h - definitions for tables for keeping track of allocated memory */
/* Copyright (C) 2001-2020 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/>.
*/
#ifndef _MTABLE_H
#define _MTABLE_H
#include "imalloc.h"
#ifdef MALLOC_REGISTER
/* values for flags byte. */
#define MT_ALLOC 0x01
#define MT_FREE 0x02
/*
* Memory table entry.
*
* MEM is the address of the allocated pointer.
* SIZE is the requested allocation size.
* FLAGS includes either MT_ALLOC (MEM is allocated) or MT_FREE (MEM is
* not allocated). Other flags later.
* FUNC is set to the name of the function doing the allocation (from the
* `tag' argument to register_alloc().
* FILE and LINE are the filename and line number of the last allocation
* and free (depending on STATUS) of MEM.
* NALLOC and NFREE are incremented on each allocation that returns MEM or
* each free of MEM, respectively (way to keep track of memory reuse
* and how well the free lists are working).
*
*/
typedef struct mr_table {
PTR_T mem;
size_t size;
char flags;
const char *func;
const char *file;
int line;
int nalloc, nfree;
} mr_table_t;
#define REG_TABLE_SIZE 8192
extern mr_table_t *mr_table_entry PARAMS((PTR_T));
extern void mregister_alloc PARAMS((const char *, PTR_T, size_t, const char *, int));
extern void mregister_free PARAMS((PTR_T, int, const char *, int));
extern void mregister_describe_mem ();
extern void mregister_dump_table PARAMS((void));
extern void mregister_table_init PARAMS((void));
typedef struct ma_table {
const char *file;
int line;
int nalloc;
} ma_table_t;
extern void mlocation_register_alloc PARAMS((const char *, int));
extern void mlocation_table_init PARAMS((void));
extern void mlocation_dump_table PARAMS((void));
extern void mlocation_write_table PARAMS((void));
/* NOTE: HASH_MIX taken from dmalloc (http://dmalloc.com) */
/*
* void HASH_MIX
*
* DESCRIPTION:
*
* Mix 3 32-bit values reversibly. For every delta with one or two
* bits set, and the deltas of all three high bits or all three low
* bits, whether the original value of a,b,c is almost all zero or is
* uniformly distributed.
*
* If HASH_MIX() is run forward or backward, at least 32 bits in a,b,c
* have at least 1/4 probability of changing. If mix() is run
* forward, every bit of c will change between 1/3 and 2/3 of the
* time. (Well, 22/100 and 78/100 for some 2-bit deltas.)
*
* HASH_MIX() takes 36 machine instructions, but only 18 cycles on a
* superscalar machine (like a Pentium or a Sparc). No faster mixer
* seems to work, that's the result of my brute-force search. There
* were about 2^68 hashes to choose from. I only tested about a
* billion of those.
*/
#define HASH_MIX(a, b, c) \
do { \
a -= b; a -= c; a ^= (c >> 13); \
b -= c; b -= a; b ^= (a << 8); \
c -= a; c -= b; c ^= (b >> 13); \
a -= b; a -= c; a ^= (c >> 12); \
b -= c; b -= a; b ^= (a << 16); \
c -= a; c -= b; c ^= (b >> 5); \
a -= b; a -= c; a ^= (c >> 3); \
b -= c; b -= a; b ^= (a << 10); \
c -= a; c -= b; c ^= (b >> 15); \
} while(0)
#endif /* MALLOC_REGISTER */
#endif /* _MTABLE_H */

126
lib/malloc/trace.c Normal file
View file

@ -0,0 +1,126 @@
/* trace.c - tracing functions for malloc */
/* Copyright (C) 2001-2020 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/>.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include "imalloc.h"
extern int malloc_trace;
static int _mtrace_verbose = 0;
#ifdef MALLOC_TRACE
extern FILE *_imalloc_fopen PARAMS((char *, char *, char *, char *, size_t));
FILE *_mtrace_fp = NULL;
extern char _malloc_trace_buckets[];
void
mtrace_alloc (tag, mem, size, file, line)
const char *tag;
PTR_T mem;
size_t size;
const char *file;
int line;
{
if (_mtrace_fp == NULL)
_mtrace_fp = stderr;
if (_mtrace_verbose)
fprintf (_mtrace_fp, "alloc: %s: %p (%zu bytes) from '%s:%d'\n",
tag, mem, size, file ? file : "unknown", line);
else
fprintf (_mtrace_fp, "alloc:%p:%zu:%s:%d\n",
mem, size, file ? file : "unknown", line);
}
void
mtrace_free (mem, size, file, line)
PTR_T mem;
int size;
const char *file;
int line;
{
if (_mtrace_fp == NULL)
_mtrace_fp = stderr;
if (_mtrace_verbose)
fprintf (_mtrace_fp, "free: %p (%d bytes) from '%s:%d'\n",
mem, size, file ? file : "unknown", line);
else
fprintf (_mtrace_fp, "free:%p:%d:%s:%d\n",
mem, size, file ? file : "unknown", line);
}
#endif /* MALLOC_TRACE */
int
malloc_set_trace (n)
int n;
{
int old;
old = malloc_trace;
malloc_trace = n;
_mtrace_verbose = (n > 1);
return old;
}
void
malloc_set_tracefp (fp)
FILE *fp;
{
#ifdef MALLOC_TRACE
_mtrace_fp = fp ? fp : stderr;
#endif
}
void
malloc_trace_bin (n)
int n;
{
#ifdef MALLOC_TRACE
_malloc_trace_buckets[n] = 1;
#endif
}
#define TRACEROOT "/var/tmp/maltrace/trace."
void
malloc_set_tracefn (s, fn)
char *s;
char *fn;
{
#ifdef MALLOC_TRACE
FILE *fp;
char defname[sizeof (TRACEROOT) + 64];
fp = _imalloc_fopen (s, fn, TRACEROOT, defname, sizeof (defname));
if (fp)
malloc_set_tracefp (fp);
#endif
}

151
lib/malloc/watch.c Normal file
View file

@ -0,0 +1,151 @@
/* watch.c - watchpoint functions for malloc */
/* Copyright (C) 2001-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 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/>.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include "imalloc.h"
#ifdef MALLOC_WATCH
#include "watch.h"
#define WATCH_MAX 32
int _malloc_nwatch;
static PTR_T _malloc_watch_list[WATCH_MAX];
static void
watch_warn (addr, file, line, type, data)
PTR_T addr;
const char *file;
int line, type;
unsigned long data;
{
char *tag;
if (type == W_ALLOC)
tag = "allocated";
else if (type == W_FREE)
tag = "freed";
else if (type == W_REALLOC)
tag = "requesting resize";
else if (type == W_RESIZED)
tag = "just resized";
else
tag = "bug: unknown operation";
fprintf (stderr, "malloc: watch alert: %p %s ", addr, tag);
if (data != (unsigned long)-1)
fprintf (stderr, "(size %lu) ", data);
fprintf (stderr, "from '%s:%d'\n", file ? file : "unknown", line);
}
void
_malloc_ckwatch (addr, file, line, type, data)
PTR_T addr;
const char *file;
int line, type;
unsigned long data;
{
register int i;
for (i = _malloc_nwatch - 1; i >= 0; i--)
{
if (_malloc_watch_list[i] == addr)
{
watch_warn (addr, file, line, type, data);
return;
}
}
}
#endif /* MALLOC_WATCH */
PTR_T
malloc_watch (addr)
PTR_T addr;
{
register int i;
PTR_T ret;
if (addr == 0)
return addr;
ret = (PTR_T)0;
#ifdef MALLOC_WATCH
for (i = _malloc_nwatch - 1; i >= 0; i--)
{
if (_malloc_watch_list[i] == addr)
break;
}
if (i < 0)
{
if (_malloc_nwatch == WATCH_MAX) /* full, take out first */
{
ret = _malloc_watch_list[0];
_malloc_nwatch--;
for (i = 0; i < _malloc_nwatch; i++)
_malloc_watch_list[i] = _malloc_watch_list[i+1];
}
_malloc_watch_list[_malloc_nwatch++] = addr;
}
#endif
return ret;
}
/* Remove a watchpoint set on ADDR. If ADDR is NULL, remove all
watchpoints. Returns ADDR if everything went OK, NULL if ADDR was
not being watched. */
PTR_T
malloc_unwatch (addr)
PTR_T addr;
{
#ifdef MALLOC_WATCH
register int i;
if (addr == 0)
{
for (i = 0; i < _malloc_nwatch; i++)
_malloc_watch_list[i] = (PTR_T)0;
_malloc_nwatch = 0;
return ((PTR_T)0);
}
else
{
for (i = 0; i < _malloc_nwatch; i++)
{
if (_malloc_watch_list[i] == addr)
break;
}
if (i == _malloc_nwatch)
return ((PTR_T)0); /* not found */
/* shuffle everything from i+1 to end down 1 */
_malloc_nwatch--;
for ( ; i < _malloc_nwatch; i++)
_malloc_watch_list[i] = _malloc_watch_list[i+1];
return addr;
}
#else
return ((PTR_T)0);
#endif
}

41
lib/malloc/watch.h Normal file
View file

@ -0,0 +1,41 @@
/* watch.h - definitions for tables for keeping track of allocated memory */
/* Copyright (C) 2001-2020 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/>.
*/
#ifndef _MWATCH_H
#define _MWATCH_H
#include "imalloc.h"
#ifdef MALLOC_WATCH
/* `Events' for watchpoints */
#define W_ALLOC 0x01
#define W_FREE 0x02
#define W_REALLOC 0x04
#define W_RESIZED 0x08
extern int _malloc_nwatch;
extern void _malloc_ckwatch PARAMS((PTR_T, const char *, int, int, unsigned long));
#endif /* MALLOC_WATCH */
#endif /* _MWATCH_H */

63
lib/malloc/x386-alloca.s Normal file
View file

@ -0,0 +1,63 @@
;; alloca386.s 1.2
;; GNU-compatible stack allocation function for Xenix/386.
;; Written by Chip Salzenberg at ComDev.
;; Last modified 90/01/11
;;> Is your alloca clearly better than the one in i386-alloca.s? I haven't
;;> looked at either.
;;
;;They're different because Xenix/386 has a different assembler. SCO
;;Xenix has the Microsoft C compiler and the Microsoft macro assembler,
;;called "masm". MASM's assembler syntax is quite different from AT&T's
;;in all sorts of ways. Xenix people can't use the AT&T version.
;;--
;;Chip Salzenberg at ComDev/TCT <chip@tct.uucp>, <uunet!ateng!tct!chip>
TITLE $alloca386
.386
DGROUP GROUP CONST, _BSS, _DATA
_DATA SEGMENT DWORD USE32 PUBLIC 'DATA'
_DATA ENDS
_BSS SEGMENT DWORD USE32 PUBLIC 'BSS'
_BSS ENDS
CONST SEGMENT DWORD USE32 PUBLIC 'CONST'
CONST ENDS
_TEXT SEGMENT DWORD USE32 PUBLIC 'CODE'
ASSUME CS: _TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP
PUBLIC _alloca
_alloca PROC NEAR
; Get argument.
pop edx ; edx -> return address
pop eax ; eax = amount to allocate
; Validate allocation amount.
add eax,3
and eax,not 3
cmp eax,0
jg aa_size_ok
mov eax,4
aa_size_ok:
; Allocate stack space.
mov ecx,esp ; ecx -> old stack pointer
sub esp,eax ; perform allocation
mov eax,esp ; eax -> new stack pointer
; Copy the three saved register variables from old stack top to new stack top.
; They may not be there. So we waste twelve bytes. Big fat hairy deal.
push DWORD PTR 8[ecx]
push DWORD PTR 4[ecx]
push DWORD PTR 0[ecx]
; Push something so the caller can pop it off.
push eax
; Return to caller.
jmp edx
_alloca ENDP
_TEXT ENDS
END

47
lib/malloc/xleaktrace Executable file
View file

@ -0,0 +1,47 @@
#! /usr/bin/awk -f
#
# xleaktrace - print unfreed memory using input generated by compact malloc
# tracing (malloc_set_trace(1))
#
# NOTE: we ignore `realloc' tags because they're just extra information
#
# Copyright (c) 2001 Chester Ramey
# Permission is hereby granted to deal in this Software without restriction.
# THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
#
# Chet Ramey
# chet@po.cwru.edu
#
BEGIN {
FS=":";
}
$1 == "alloc" {
alloc[$2] = 1;
size[$2] = $3;
file[$2] = $4;
line[$2] = $5;
# printf "allocated: %s %d %d %s %d\n", $2, alloc[$2], size[$2], file[$2], line[$2];
}
$1 == "free" {
if ($2 in alloc) {
alloc[$2] = 0;
# printf "freed: %s %d\n", $2, alloc[$2];
} else
printf "freeing unallocated pointer: %s\n", $2;
}
END {
printf "unfreed memory\n";
for (ptr in alloc) {
if (alloc[ptr] == 1) {
printf "%s (%d) from %s:%d\n", ptr, size[ptr], file[ptr], line[ptr];
}
}
}

94
lib/malloc/xmalloc.c Normal file
View file

@ -0,0 +1,94 @@
/* xmalloc.c -- safe versions of malloc and realloc */
/* Copyright (C) 1991-2003 Free Software Foundation, Inc.
This file is part of GNU Readline, a library for reading lines
of text with interactive input and history editing.
Readline 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.
Readline 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 Readline. If not, see <http://www.gnu.org/licenses/>.
*/
#if defined (HAVE_CONFIG_H)
#include <config.h>
#endif
#include <stdio.h>
#if defined (HAVE_STDLIB_H)
# include <stdlib.h>
#else
# include "ansi_stdlib.h"
#endif /* HAVE_STDLIB_H */
/* Generic pointer type. */
#ifndef PTR_T
#if defined (__STDC__)
# define PTR_T void *
#else
# define PTR_T char *
#endif
#endif /* PTR_T */
/* **************************************************************** */
/* */
/* Memory Allocation and Deallocation. */
/* */
/* **************************************************************** */
static void
memory_error_and_abort (fname)
char *fname;
{
fprintf (stderr, "%s: out of virtual memory\n", fname);
exit (2);
}
/* Return a pointer to free()able block of memory large enough
to hold BYTES number of bytes. If the memory cannot be allocated,
print an error message and abort. */
PTR_T
xmalloc (bytes)
size_t bytes;
{
PTR_T temp;
temp = malloc (bytes);
if (temp == 0)
memory_error_and_abort ("xmalloc");
return (temp);
}
PTR_T
xrealloc (pointer, bytes)
PTR_T pointer;
size_t bytes;
{
PTR_T temp;
temp = pointer ? realloc (pointer, bytes) : malloc (bytes);
if (temp == 0)
memory_error_and_abort ("xrealloc");
return (temp);
}
void
xfree (string)
PTR_T string;
{
if (string)
free (string);
}

674
lib/readline/COPYING Normal file
View file

@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

403
lib/readline/ChangeLog Normal file
View file

@ -0,0 +1,403 @@
Tue Mar 23 14:36:51 1993 Brian Fox (bfox@eos.crseo.ucsb.edu)
* readline.c (rl_copy): Changed name to rl_copy_text.
Mon Mar 22 19:16:05 1993 Brian Fox (bfox@eos.crseo.ucsb.edu)
* dispose_cmd.c, several other files. Declare dispose_xxx () as
"void".
* builtins/hashcom.h: Make declarations of hashed_filenames be
"extern" to keep the SGI compiler happy.
* readline.c (rl_initialize_everything): Assign values to
out_stream and in_stream immediately, since
output_character_function () can be called before
readline_internal () is called.
Tue Dec 8 09:30:56 1992 Brian Fox (bfox@cubit)
* readline.c (rl_init_terminal) Set PC from BC, not from *buffer.
Mon Nov 30 09:35:47 1992 Brian Fox (bfox@cubit)
* readline.c (invoking_keyseqs_in_map, rl_parse_and_bind) Allow
backslash to quote characters, such as backslash, double quote,
and space. Backslash quotes all character indiscriminately.
* funmap.c (vi_keymap) Fix type in "vi-replace" declaration.
Fri Nov 20 10:55:05 1992 Brian Fox (bfox@cubit)
* readline.c (init_terminal_io, rl_prep_terminal): FINALLY!
Declare and use termcap variable `ospeed' when setting up terminal
parameters.
Thu Oct 8 08:53:07 1992 Brian J. Fox (bfox@helios)
* Makefile, this directory: Include (as links to the canonical
sources), tilde.c, tilde.h, posixstat.h and xmalloc.c.
Tue Sep 29 13:07:21 1992 Brian J. Fox (bfox@helios)
* readline.c (init_terminal_io) Don't set arrow keys if the key
sequences that represent them are already set.
* readline.c (rl_function_of_keyseq) New function returns the first
function (or macro) found while searching a key sequence.
Mon Sep 28 00:34:04 1992 Brian J. Fox (bfox@helios)
* readline.c (LibraryVersion) New static char * contains current
version number. Version is at 2.0.
* readline.c (rl_complete_internal): Incorporated clean changes
from gilmore (gnu@cygnus.com) to support quoted substrings within
completion functions.
* readline.c (many locations) Added support for the _GO32_,
whatever that is. Patches supplied by Cygnus, typed in by hand,
with cleanups.
Sun Aug 16 12:46:24 1992 Brian Fox (bfox@cubit)
* readline.c (init_terminal_io): Find out the values of the keypad
arrows and bind them to appropriate RL functions if present.
Mon Aug 10 18:13:24 1992 Brian Fox (bfox@cubit)
* history.c (stifle_history): A negative argument to stifle
becomes zero.
Tue Jul 28 09:28:41 1992 Brian Fox (bfox@cubit)
* readline.c (rl_variable_bind): New local structure describes
booleans by name and address; code in rl_variable_bind () looks at
structure to set simple variables.
* parens.c (rl_insert_close): New variable rl_blink_matching_paren
is non-zero if we want to blink the matching open when a close is
inserted. If FD_SET is defined, rl_blink_matching_paren defaults
to 1, else 0. If FD_SET is not defined, and
rl_blink_matching_paren is non-zero, the close character(s) are/is
simply inserted.
Wed Jul 22 20:03:59 1992 Brian Fox (bfox@cubit)
* history.c, readline.c, vi_mode.c: Cause the functions strchr ()
and strrchr () to be used instead of index () and rindex ()
throughout the source.
Mon Jul 13 11:34:07 1992 Brian Fox (bfox@cubit)
* readline.c: (rl_variable_bind) New variable "meta-flag" if "on"
means force the use of the 8th bit as Meta bit. Internal variable
is called meta_flag.
Thu Jul 9 10:37:56 1992 Brian Fox (bfox@cubit)
* history.c (get_history_event) Change INDEX to LOCAL_INDEX. If
compiling for the shell, allow shell metacharacters to separate
history tokens as they would for shell tokens.
Sat Jul 4 19:29:12 1992 Brian Fox (bfox@cubit)
* vi_keymap.c: According to Posix, TAB self-inserts instead of
doing completion.
* vi_mode.c: (rl_vi_yank_arg) Enter VI insert mode after yanking
an arg from the previous line.
* search.c: New file takes over vi style searching and implements
non-incremental searching the history.
Makefile: Add search.c and search.o.
funmap.c: Add names for non-incremental-forward-search-history and
non-incremental-reverse-search-history.
readline.h: Add extern definitions for non-incremental searching.
vi_mode.c: Remove old search code; add calls to code in search.c.
Fri Jul 3 10:36:33 1992 Brian Fox (bfox@cubit)
* readline.c (rl_delete_horizontal_space); New function deletes
all whitespace surrounding point.
funmap.c: Add "delete-horizontal-space".
emacs_keymap.c: Put rl_delete_horizontal_space () on M-\.
* readline.c (rl_set_signals, rl_clear_signals); New function
rl_set_sighandler () is either defined in a Posix way (if
HAVE_POSIX_SIGNALS is defined) or in a BSD way. Function is
called from rl_set_signals () and rl_clear_signals ().
Fri May 8 12:50:15 1992 Brian Fox (bfox@cubit)
* readline.c: (readline_default_bindings) Do comparisons with
_POSIX_VDISABLE casted to `unsigned char'. Change tty characters
to be unsigned char.
Thu Apr 30 12:36:35 1992 Brian Fox (bfox@cubit)
* readline.c: (rl_getc) Handle "read would block" error on
non-blocking IO streams.
* readline.c: (rl_signal_handler): Unblock only the signal that we
have caught, not all signals.
Sun Feb 23 03:33:09 1992 Brian Fox (bfox at gnuwest.fsf.org)
* readline.c: Many functions. Use only the macros META_CHAR and
UNMETA to deal with meta characters. Prior to this, we used
numeric values and tests.
* readline.c (rl_complete_internal) Report exactly the number of
possible completions, not the number + 1.
* vi_mode.c (rl_do_move) Do not change the cursor position when
using `cw' or `cW'.
* vi_mode.c (rl_vi_complete) Enter insert mode after completing
with `*' or `\'.
Fri Feb 21 05:58:18 1992 Brian Fox (bfox at gnuwest.fsf.org)
* readline.c (rl_dispatch) Increment rl_key_sequence_length for
meta characters that map onto ESC map.
Mon Feb 10 01:41:35 1992 Brian Fox (bfox at gnuwest.fsf.org)
* history.c (history_do_write) Build a buffer of all of the lines
to write and write them in one fell swoop (lower overhead than
calling write () for each line). Suggested by Peter Ho.
* readline.c: Include hbullx20 as well as hpux for determining
USGr3ness.
* readline.c (rl_unix_word_rubout) As per the "Now REMEMBER"
comment, pass arguments to rl_kill_text () in the correct order to
preserve prepending and appending of killed text.
* readline.c (rl_search_history) malloc (), realloc (), and free
() SEARCH_STRING so that there are no static limits on searching.
* vi_mode.c (rl_vi_subst) Don't forget to end the undo group.
Fri Jan 31 14:51:02 1992 Brian Fox (bfox at gnuwest.fsf.org)
* readline.c (rl_signal_handler): Zero the current history entry's
pointer after freeing the undo_list when SIGINT received.
Reformat a couple of functions.
Sat Jan 25 13:47:35 1992 Brian Fox (bfox at bears)
* readline.c (parser_if): free () TNAME after use.
Tue Jan 21 01:01:35 1992 Brian Fox (bfox at gnuwest.fsf.org)
* readline.c (rl_redisplay) and (rl_character_len): Display
Control characters as "^c" and Meta characters as "\234", instead
of "C-C" and "M-C".
Sun Dec 29 10:59:00 1991 Brian Fox (bfox at gnuwest.fsf.org)
* readline.c (init_terminal_io) Default to environment variables
LINES and COLUMNS before termcap entry values. If all else fails,
then assume 80x24 terminal.
Sat Dec 28 16:33:11 1991 Brian Fox (bfox at gnuwest.fsf.org)
* readline.c: If this machine is USG and it is hpux, then define
USGr3.
* history.c: Cosmetic fixes.
Thu Nov 21 00:10:12 1991 Brian Fox (bfox at gnuwest.fsf.org)
* vi_mode.c: (rl_do_move) Place cursor at end of line, never at
next to last character.
Thu Nov 14 05:08:01 1991 Brian Fox (bfox at gnuwest.fsf.org)
* history.c (get_history_event) Non-anchored searches can have a
return index of greater than zero from get_history_event ().
Fri Nov 1 07:02:13 1991 Brian Fox (bfox at gnuwest.fsf.org)
* readline.c (rl_translate_keyseq) Make C-? translate to RUBOUT
unconditionally.
Mon Oct 28 11:34:52 1991 Brian Fox (bfox at gnuwest.fsf.org)
* readline.c; Use Posix directory routines and macros.
* funmap.c; Add entry for call-last-kbd-macro.
* readline.c (rl_prep_term); Use system EOF character on POSIX
systems also.
Thu Oct 3 16:19:53 1991 Brian Fox (bfox at gnuwest.fsf.org)
* readline.c; Make a distinction between having a TERMIOS tty
driver, and having POSIX signal handling. You might one without
the other. New defines used HAVE_POSIX_SIGNALS, and
TERMIOS_TTY_DRIVER.
Tue Jul 30 22:37:26 1991 Brian Fox (bfox at gnuwest.fsf.org)
* readline.c: rl_getc () If a call to read () returns without an
error, but with zero characters, the file is empty, so return EOF.
Thu Jul 11 20:58:38 1991 Brian Fox (bfox at gnuwest.fsf.org)
* readline.c: (rl_get_next_history, rl_get_previous_history)
Reallocate the buffer space if the line being moved to is longer
the the current space allocated. Amazing that no one has found
this bug until now.
Sun Jul 7 02:37:05 1991 Brian Fox (bfox at gnuwest.fsf.org)
* readline.c:(rl_parse_and_bind) Allow leading whitespace.
Make sure TERMIO and TERMIOS systems treat CR and NL
disctinctly.
Tue Jun 25 04:09:27 1991 Brian Fox (bfox at gnuwest.fsf.org)
* readline.c: Rework parsing conditionals to pay attention to the
prior states of the conditional stack. This makes $if statements
work correctly.
Mon Jun 24 20:45:59 1991 Brian Fox (bfox at gnuwest.fsf.org)
* readline.c: support for displaying key binding information
includes the functions rl_list_funmap_names (),
invoking_keyseqs_in_map (), rl_invoking_keyseqs (),
rl_dump_functions (), and rl_function_dumper ().
funmap.c: support for same includes rl_funmap_names ().
readline.c, funmap.c: no longer define STATIC_MALLOC. However,
update both version of xrealloc () to handle a null pointer.
Thu Apr 25 12:03:49 1991 Brian Fox (bfox at gnuwest.fsf.org)
* vi_mode.c (rl_vi_fword, fWord, etc. All functions use
the macro `isident()'. Fixed movement bug which prevents
continious movement through the text.
Fri Jul 27 16:47:01 1990 Brian Fox (bfox at gnuwest.fsf.org)
* readline.c (parser_if) Allow "$if term=foo" construct.
Wed May 23 16:10:33 1990 Brian Fox (bfox at gnuwest.fsf.org)
* readline.c (rl_dispatch) Correctly remember the last command
executed. Fixed typo in username_completion_function ().
Mon Apr 9 19:55:48 1990 Brian Fox (bfox at gnuwest.fsf.org)
* readline.c: username_completion_function (); For text passed in
with a leading `~', remember that this could be a filename (after
it is completed).
Thu Apr 5 13:44:24 1990 Brian Fox (bfox at gnuwest.fsf.org)
* readline.c: rl_search_history (): Correctly handle case of an
unfound search string, but a graceful exit (as with ESC).
* readline.c: rl_restart_output (); The Apollo passes the address
of the file descriptor to TIOCSTART, not the descriptor itself.
Tue Mar 20 05:38:55 1990 Brian Fox (bfox at gnuwest.fsf.org)
* readline.c: rl_complete (); second call in a row causes possible
completions to be listed.
* readline.c: rl_redisplay (), added prompt_this_line variable
which is the first character character following \n in prompt.
Sun Mar 11 04:32:03 1990 Brian Fox (bfox at gnuwest.fsf.org)
* Signals are now supposedly handled inside of SYSV compilation.
Wed Jan 17 19:24:09 1990 Brian Fox (bfox at sbphy.ucsb.edu)
* history.c: history_expand (); fixed overwriting memory error,
added needed argument to call to get_history_event ().
Thu Jan 11 10:54:04 1990 Brian Fox (bfox at sbphy.ucsb.edu)
* readline.c: added mark_modified_lines to control the
display of an asterisk on modified history lines. Also
added a user variable called mark-modified-lines to the
`set' command.
Thu Jan 4 10:38:05 1990 Brian Fox (bfox at sbphy.ucsb.edu)
* readline.c: start_insert (). Only use IC if we don't have an im
capability.
Fri Sep 8 09:00:45 1989 Brian Fox (bfox at aurel)
* readline.c: rl_prep_terminal (). Only turn on 8th bit
as meta-bit iff the terminal is not using parity.
Sun Sep 3 08:57:40 1989 Brian Fox (bfox at aurel)
* readline.c: start_insert (). Uses multiple
insertion call in cases where that makes sense.
rl_insert (). Read type-ahead buffer for additional
keys that are bound to rl_insert, and insert them
all at once. Make insertion of single keys given
with an argument much more efficient.
Tue Aug 8 18:13:57 1989 Brian Fox (bfox at aurel)
* readline.c: Changed handling of EOF. readline () returns
(char *)EOF or consed string. The EOF character is read from the
tty, or if the tty doesn't have one, defaults to C-d.
* readline.c: Added support for event driven programs.
rl_event_hook is the address of a function you want called
while Readline is waiting for input.
* readline.c: Cleanup time. Functions without type declarations
do not use return with a value.
* history.c: history_expand () has new variable which is the
characters to ignore immediately following history_expansion_char.
Sun Jul 16 08:14:00 1989 Brian Fox (bfox at aurel)
* rl_prep_terminal ()
BSD version turns off C-s, C-q, C-y, C-v.
* readline.c -- rl_prep_terminal ()
SYSV version hacks readline_echoing_p.
BSD version turns on passing of the 8th bit for the duration
of reading the line.
Tue Jul 11 06:25:01 1989 Brian Fox (bfox at aurel)
* readline.c: new variable rl_tilde_expander.
If non-null, this contains the address of a function to call if
the standard meaning for expanding a tilde fails. The function is
called with the text sans tilde (as in "foo"), and returns a
malloc()'ed string which is the expansion, or a NULL pointer if
there is no expansion.
* readline.h - new file chardefs.h
Separates things that only readline.c needs from the standard
header file publishing interesting things about readline.
* readline.c:
readline_default_bindings () now looks at terminal chararacters
and binds those as well.
Wed Jun 28 20:20:51 1989 Brian Fox (bfox at aurel)
* Made readline and history into independent libraries.

397
lib/readline/Makefile.in Normal file
View file

@ -0,0 +1,397 @@
## -*- text -*- #############################################################
# #
# Makefile for the Bash versions of the GNU Readline and History Libraries. #
# #
#############################################################################
# Copyright (C) 1994-2012 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
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
PACKAGE = @PACKAGE_NAME@
VERSION = @PACKAGE_VERSION@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_VERSION = @PACKAGE_VERSION@
srcdir = @srcdir@
VPATH = @srcdir@
topdir = @top_srcdir@
BUILD_DIR = @BUILD_DIR@
datarootdir = @datarootdir@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
CC = @CC@
RANLIB = @RANLIB@
AR = @AR@
ARFLAGS = @ARFLAGS@
RM = rm -f
CP = cp
MV = mv
SHELL = @MAKE_SHELL@
# Programs to make tags files.
ETAGS = etags -tw
CTAGS = ctags -tw
DEBUG = @DEBUG@
CFLAGS = @CFLAGS@
LOCAL_CFLAGS = @LOCAL_CFLAGS@ ${DEBUG}
STYLE_CFLAGS = @STYLE_CFLAGS@
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
DEFS = @DEFS@
LOCAL_DEFS = @LOCAL_DEFS@
INCLUDES = -I. -I$(BUILD_DIR) -I$(topdir) -I$(topdir)/lib
CCFLAGS = $(DEFS) $(LOCAL_DEFS) $(APP_CFLAGS) $(CPPFLAGS) ${INCLUDES} \
$(STYLE_CFLAGS) $(LOCAL_CFLAGS) $(CFLAGS) ${ADDON_CFLAGS}
.c.o:
${RM} $@
$(CC) -c $(CCFLAGS) $<
# The name of the main library target.
LIBRARY_NAME = libreadline.a
# The C code source files for this library.
CSOURCES = $(srcdir)/readline.c $(srcdir)/funmap.c $(srcdir)/keymaps.c \
$(srcdir)/vi_mode.c $(srcdir)/parens.c $(srcdir)/rltty.c \
$(srcdir)/complete.c $(srcdir)/bind.c $(srcdir)/isearch.c \
$(srcdir)/display.c $(srcdir)/signals.c $(srcdir)/emacs_keymap.c \
$(srcdir)/vi_keymap.c $(srcdir)/util.c $(srcdir)/kill.c \
$(srcdir)/undo.c $(srcdir)/macro.c $(srcdir)/input.c \
$(srcdir)/callback.c $(srcdir)/terminal.c $(srcdir)/xmalloc.c \
$(srcdir)/history.c $(srcdir)/histsearch.c $(srcdir)/histexpand.c \
$(srcdir)/histfile.c $(srcdir)/nls.c $(srcdir)/search.c \
$(srcdir)/shell.c $(srcdir)/tilde.c $(srcdir)/savestring.c \
$(srcdir)/text.c $(srcdir)/misc.c $(srcdir)/compat.c \
$(srcdir)/colors.c $(srcdir)/parse-colors.c \
$(srcdir)/mbutil.c $(srcdir)/xfree.c
# The header files for this library.
HSOURCES = readline.h rldefs.h chardefs.h keymaps.h history.h histlib.h \
posixstat.h posixdir.h posixjmp.h tilde.h rlconf.h rltty.h \
ansi_stdlib.h rlstdc.h tcap.h xmalloc.h rlprivate.h rlshell.h \
rltypedefs.h rlmbutil.h colors.h parse-colors.h
HISTOBJ = history.o histexpand.o histfile.o histsearch.o shell.o savestring.o \
mbutil.o
TILDEOBJ = tilde.o
COLORSOBJ = colors.o parse-colors.o
OBJECTS = readline.o vi_mode.o funmap.o keymaps.o parens.o search.o \
rltty.o complete.o bind.o isearch.o display.o signals.o \
util.o kill.o undo.o macro.o input.o callback.o terminal.o \
text.o nls.o misc.o $(HISTOBJ) $(TILDEOBJ) $(COLORSOBJ) \
xmalloc.o xfree.o compat.o
# The texinfo files which document this library.
DOCSOURCE = doc/rlman.texinfo doc/rltech.texinfo doc/rluser.texinfo
DOCOBJECT = doc/readline.dvi
DOCSUPPORT = doc/Makefile
DOCUMENTATION = $(DOCSOURCE) $(DOCOBJECT) $(DOCSUPPORT)
SUPPORT = Makefile ChangeLog $(DOCSUPPORT) examples/[-a-z.]*
SOURCES = $(CSOURCES) $(HSOURCES) $(DOCSOURCE)
THINGS_TO_TAR = $(SOURCES) $(SUPPORT)
INSTALLED_HEADERS = readline.h chardefs.h keymaps.h history.h tilde.h \
rlstdc.h rlconf.h rltypedefs.h
##########################################################################
all: libreadline.a libhistory.a
libreadline.a: $(OBJECTS)
$(RM) $@
$(AR) $(ARFLAGS) $@ $(OBJECTS)
-test -n "$(RANLIB)" && $(RANLIB) $@
libhistory.a: $(HISTOBJ) xmalloc.o xfree.o
$(RM) $@
$(AR) $(ARFLAGS) $@ $(HISTOBJ) xmalloc.o xfree.o
-test -n "$(RANLIB)" && $(RANLIB) $@
documentation: force
test -d doc || mkdir doc
-( cd doc && $(MAKE) $(MFLAGS) )
# Since tilde.c is shared between readline and bash, make sure we compile
# it with the right flags when it's built as part of readline
tilde.o: tilde.c
rm -f $@
$(CC) $(CCFLAGS) -DREADLINE_LIBRARY -c $(srcdir)/tilde.c
force:
install:
@echo "This version of the readline library should not be installed."
uninstall:
@echo "This version of the readline library should not be installed."
TAGS: force
$(ETAGS) $(CSOURCES) $(HSOURCES)
tags: force
$(CTAGS) $(CSOURCES) $(HSOURCES)
clean: force
$(RM) $(OBJECTS) *.a
-( cd doc && $(MAKE) $(MFLAGS) $@ )
mostlyclean: clean
-( cd doc && $(MAKE) $(MFLAGS) $@ )
distclean maintainer-clean: clean
-( cd doc && $(MAKE) $(MFLAGS) $@ )
$(RM) Makefile
$(RM) TAGS tags
# Dependencies
bind.o: ansi_stdlib.h posixstat.h
bind.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
bind.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
bind.o: history.h rlstdc.h
callback.o: rlconf.h ansi_stdlib.h
callback.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
callback.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h rlstdc.h
compat.o: ${BUILD_DIR}/config.h
compat.o: rlstdc.h rltypedefs.h
complete.o: ansi_stdlib.h posixdir.h posixstat.h
complete.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
complete.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h rlstdc.h
complete.o: colors.h
display.o: ansi_stdlib.h posixstat.h
display.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
display.o: tcap.h
display.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
display.o: history.h rlstdc.h
funmap.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
funmap.o: rlconf.h ansi_stdlib.h rlstdc.h
funmap.o: ${BUILD_DIR}/config.h
histexpand.o: ansi_stdlib.h
histexpand.o: history.h histlib.h rlstdc.h
histexpand.o: ${BUILD_DIR}/config.h
histfile.o: ansi_stdlib.h
histfile.o: history.h histlib.h rlstdc.h
histfile.o: ${BUILD_DIR}/config.h
history.o: ansi_stdlib.h
history.o: history.h histlib.h rlstdc.h
history.o: ${BUILD_DIR}/config.h
histsearch.o: ansi_stdlib.h
histsearch.o: history.h histlib.h rlstdc.h
histsearch.o: ${BUILD_DIR}/config.h
input.o: ansi_stdlib.h
input.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
input.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h rlstdc.h
isearch.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
isearch.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
isearch.o: ansi_stdlib.h history.h rlstdc.h
keymaps.o: emacs_keymap.c vi_keymap.c
keymaps.o: keymaps.h rltypedefs.h chardefs.h rlconf.h ansi_stdlib.h
keymaps.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
keymaps.o: ${BUILD_DIR}/config.h rlstdc.h
kill.o: ansi_stdlib.h
kill.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
kill.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
kill.o: history.h rlstdc.h
macro.o: ansi_stdlib.h
macro.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
macro.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
macro.o: history.h rlstdc.h
mbutil.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h rlmbutil.h
mbutil.o: readline.h keymaps.h rltypedefs.h chardefs.h rlstdc.h
misc.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
misc.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
misc.o: history.h rlstdc.h ansi_stdlib.h
nls.o: ansi_stdlib.h
nls.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
nls.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
nls.o: history.h rlstdc.h
parens.o: rlconf.h
parens.o: ${BUILD_DIR}/config.h
parens.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h rlstdc.h
readline.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
readline.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
readline.o: history.h rlstdc.h
readline.o: posixstat.h ansi_stdlib.h posixjmp.h
rltty.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
rltty.o: rltty.h
rltty.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h rlstdc.h
savestring.o: ${BUILD_DIR}/config.h
search.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
search.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
search.o: ansi_stdlib.h history.h rlstdc.h
shell.o: ${BUILD_DIR}/config.h ansi_stdlib.h
signals.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
signals.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
signals.o: history.h rlstdc.h
terminal.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
terminal.o: tcap.h
terminal.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
terminal.o: history.h rlstdc.h
text.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
text.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
text.o: history.h rlstdc.h ansi_stdlib.h
rltty.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
tilde.o: ansi_stdlib.h
tilde.o: ${BUILD_DIR}/config.h
tilde.o: tilde.h
undo.o: ansi_stdlib.h
undo.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
undo.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
undo.o: history.h rlstdc.h xmalloc.h
util.o: posixjmp.h ansi_stdlib.h
util.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
util.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h rlstdc.h
vi_mode.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
vi_mode.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
vi_mode.o: history.h ansi_stdlib.h rlstdc.h
xmalloc.o: ${BUILD_DIR}/config.h ansi_stdlib.h
xfree.o: ${BUILD_DIR}/config.h ansi_stdlib.h
colors.o: ${BUILD_DIR}/config.h colors.h
colors.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h rlstdc.h
colors.o: rlconf.h
colors.o: ansi_stdlib.h posixstat.h
parse-colors.o: ${BUILD_DIR}/config.h colors.h parse-colors.h
parse-colors.o: rldefs.h rlconf.h
parse-colors.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h rlstdc.h
bind.o: rlshell.h
histfile.o: rlshell.h
nls.o: rlshell.h
readline.o: rlshell.h
shell.o: rlshell.h
terminal.o: rlshell.h
histexpand.o: rlshell.h
bind.o: rlprivate.h
callback.o: rlprivate.h
complete.o: rlprivate.h
display.o: rlprivate.h
input.o: rlprivate.h
isearch.o: rlprivate.h
kill.o: rlprivate.h
macro.o: rlprivate.h
mbutil.o: rlprivate.h
misc.o: rlprivate.h
nls.o: rlprivate.h
parens.o: rlprivate.h
readline.o: rlprivate.h
rltty.o: rlprivate.h
search.o: rlprivate.h
signals.o: rlprivate.h
terminal.o: rlprivate.h
text.o: rlprivate.h
undo.o: rlprivate.h
util.o: rlprivate.h
vi_mode.o: rlprivate.h
colors.o: rlprivate.h
parse-colors.o: rlprivate.h
bind.o: xmalloc.h
complete.o: xmalloc.h
display.o: xmalloc.h
funmap.o: xmalloc.h
histexpand.o: xmalloc.h
histfile.o: xmalloc.h
history.o: xmalloc.h
input.o: xmalloc.h
isearch.o: xmalloc.h
keymaps.o: xmalloc.h
kill.o: xmalloc.h
macro.o: xmalloc.h
mbutil.o: xmalloc.h
misc.o: xmalloc.h
readline.o: xmalloc.h
savestring.o: xmalloc.h
search.o: xmalloc.h
shell.o: xmalloc.h
terminal.o: xmalloc.h
text.o: xmalloc.h
tilde.o: xmalloc.h
undo.o: xmalloc.h
util.o: xmalloc.h
vi_mode.o: xmalloc.h
xfree.o: xmalloc.h
xmalloc.o: xmalloc.h
colors.o: xmalloc.h
parse-colors.o: xmalloc.h
complete.o: rlmbutil.h
display.o: rlmbutil.h
histexpand.o: rlmbutil.h
input.o: rlmbutil.h
isearch.o: rlmbutil.h
mbutil.o: rlmbutil.h
misc.o: rlmbutil.h
readline.o: rlmbutil.h
search.o: rlmbutil.h
text.o: rlmbutil.h
vi_mode.o: rlmbutil.h
colors.o: rlmbutil.h
parse-colors.o: rlmbutil.h
# Rules for deficient makes, like SunOS and Solaris
bind.o: bind.c
callback.o: callback.c
compat.o: compat.c
complete.o: complete.c
display.o: display.c
funmap.o: funmap.c
input.o: input.c
isearch.o: isearch.c
keymaps.o: keymaps.c emacs_keymap.c vi_keymap.c
kill.o: kill.c
macro.o: macro.c
mbutil.o: mbutil.c
misc.o: misc.c
nls.o: nls.c
parens.o: parens.c
readline.o: readline.c
rltty.o: rltty.c
savestring.o: savestring.c
search.o: search.c
shell.o: shell.c
signals.o: signals.c
terminal.o: terminal.c
text.o: text.c
tilde.o: tilde.c
undo.o: undo.c
util.o: util.c
vi_mode.o: vi_mode.c
xfree.o: xfree.c
xmalloc.o: xmalloc.c
colors.o: colors.c
parse-colors.o: parse-colors.c
histexpand.o: histexpand.c
histfile.o: histfile.c
history.o: history.c
histsearch.o: histsearch.c

6
lib/readline/README Normal file
View file

@ -0,0 +1,6 @@
This is the distribution of the Gnu Readline library. See the file
STANDALONE for a description of the #defines that can be passed via
the makefile to build readline on different systems.
The file rlconf.h contains defines that enable and disable certain
readline features.

2
lib/readline/STANDALONE Normal file
View file

@ -0,0 +1,2 @@
This is not to be built as a standalone library to be installed in some
public place; get the full readline distribution instead.

View file

@ -0,0 +1,54 @@
/* ansi_stdlib.h -- An ANSI Standard stdlib.h. */
/* A minimal stdlib.h containing extern declarations for those functions
that bash uses. */
/* Copyright (C) 1993 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/>.
*/
#if !defined (_STDLIB_H_)
#define _STDLIB_H_ 1
/* String conversion functions. */
extern int atoi ();
extern double atof ();
extern double strtod ();
/* Memory allocation functions. */
/* Generic pointer type. */
#ifndef PTR_T
#if defined (__STDC__)
# define PTR_T void *
#else
# define PTR_T char *
#endif
#endif /* PTR_T */
extern PTR_T malloc ();
extern PTR_T realloc ();
extern void free ();
/* Other miscellaneous functions. */
extern void abort ();
extern void exit ();
extern char *getenv ();
extern void qsort ();
#endif /* _STDLIB_H */

3082
lib/readline/bind.c Normal file

File diff suppressed because it is too large Load diff

378
lib/readline/callback.c Normal file
View file

@ -0,0 +1,378 @@
/* callback.c -- functions to use readline as an X `callback' mechanism. */
/* Copyright (C) 1987-2022 Free Software Foundation, Inc.
This file is part of the GNU Readline Library (Readline), a library
for reading lines of text with interactive input and history editing.
Readline 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.
Readline 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 Readline. If not, see <http://www.gnu.org/licenses/>.
*/
#define READLINE_LIBRARY
#if defined (HAVE_CONFIG_H)
# include <config.h>
#endif
#include "rlconf.h"
#if defined (READLINE_CALLBACKS)
#include <sys/types.h>
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#else
# include "ansi_stdlib.h"
#endif
#include <stdio.h>
/* System-specific feature definitions and include files. */
#include "rldefs.h"
#include "readline.h"
#include "rlprivate.h"
#include "xmalloc.h"
/* Private data for callback registration functions. See comments in
rl_callback_read_char for more details. */
_rl_callback_func_t *_rl_callback_func = 0;
_rl_callback_generic_arg *_rl_callback_data = 0;
/* Applications can set this to non-zero to have readline's signal handlers
installed during the entire duration of reading a complete line, as in
readline-6.2. This should be used with care, because it can result in
readline receiving signals and not handling them until it's called again
via rl_callback_read_char, thereby stealing them from the application.
By default, signal handlers are only active while readline is active. */
int rl_persistent_signal_handlers = 0;
/* **************************************************************** */
/* */
/* Callback Readline Functions */
/* */
/* **************************************************************** */
/* Allow using readline in situations where a program may have multiple
things to handle at once, and dispatches them via select(). Call
rl_callback_handler_install() with the prompt and a function to call
whenever a complete line of input is ready. The user must then
call rl_callback_read_char() every time some input is available, and
rl_callback_read_char() will call the user's function with the complete
text read in at each end of line. The terminal is kept prepped
all the time, except during calls to the user's function. Signal
handlers are only installed when the application calls back into
readline, so readline doesn't `steal' signals from the application. */
rl_vcpfunc_t *rl_linefunc; /* user callback function */
static int in_handler; /* terminal_prepped and signals set? */
/* Make sure the terminal is set up, initialize readline, and prompt. */
static void
_rl_callback_newline (void)
{
rl_initialize ();
if (in_handler == 0)
{
in_handler = 1;
if (rl_prep_term_function)
(*rl_prep_term_function) (_rl_meta_flag);
#if defined (HANDLE_SIGNALS)
if (rl_persistent_signal_handlers)
rl_set_signals ();
#endif
}
readline_internal_setup ();
RL_CHECK_SIGNALS ();
}
/* Install a readline handler, set up the terminal, and issue the prompt. */
void
rl_callback_handler_install (const char *prompt, rl_vcpfunc_t *linefunc)
{
rl_set_prompt (prompt);
RL_SETSTATE (RL_STATE_CALLBACK);
rl_linefunc = linefunc;
_rl_callback_newline ();
}
#if defined (HANDLE_SIGNALS)
#define CALLBACK_READ_RETURN() \
do { \
if (rl_persistent_signal_handlers == 0) \
rl_clear_signals (); \
return; \
} while (0)
#else
#define CALLBACK_READ_RETURN() return
#endif
/* Read one character, and dispatch to the handler if it ends the line. */
void
rl_callback_read_char (void)
{
char *line;
int eof, jcode;
static procenv_t olevel;
if (rl_linefunc == NULL)
{
_rl_errmsg ("readline_callback_read_char() called with no handler!");
abort ();
}
eof = 0;
memcpy ((void *)olevel, (void *)_rl_top_level, sizeof (procenv_t));
#if defined (HAVE_POSIX_SIGSETJMP)
jcode = sigsetjmp (_rl_top_level, 0);
#else
jcode = setjmp (_rl_top_level);
#endif
if (jcode)
{
(*rl_redisplay_function) ();
_rl_want_redisplay = 0;
memcpy ((void *)_rl_top_level, (void *)olevel, sizeof (procenv_t));
/* If we longjmped because of a timeout, handle it here. */
if (RL_ISSTATE (RL_STATE_TIMEOUT))
{
RL_SETSTATE (RL_STATE_DONE);
rl_done = 1;
}
CALLBACK_READ_RETURN ();
}
#if defined (HANDLE_SIGNALS)
/* Install signal handlers only when readline has control. */
if (rl_persistent_signal_handlers == 0)
rl_set_signals ();
#endif
do
{
RL_CHECK_SIGNALS ();
if (RL_ISSTATE (RL_STATE_ISEARCH))
{
eof = _rl_isearch_callback (_rl_iscxt);
if (eof == 0 && (RL_ISSTATE (RL_STATE_ISEARCH) == 0) && RL_ISSTATE (RL_STATE_INPUTPENDING))
rl_callback_read_char ();
CALLBACK_READ_RETURN ();
}
else if (RL_ISSTATE (RL_STATE_NSEARCH))
{
eof = _rl_nsearch_callback (_rl_nscxt);
CALLBACK_READ_RETURN ();
}
#if defined (VI_MODE)
/* States that can occur while in state VIMOTION have to be checked
before RL_STATE_VIMOTION */
else if (RL_ISSTATE (RL_STATE_CHARSEARCH))
{
int k;
k = _rl_callback_data->i2;
eof = (*_rl_callback_func) (_rl_callback_data);
/* If the function `deregisters' itself, make sure the data is
cleaned up. */
if (_rl_callback_func == 0) /* XXX - just sanity check */
{
if (_rl_callback_data)
{
_rl_callback_data_dispose (_rl_callback_data);
_rl_callback_data = 0;
}
}
/* Messy case where vi motion command can be char search */
if (RL_ISSTATE (RL_STATE_VIMOTION))
{
_rl_vi_domove_motion_cleanup (k, _rl_vimvcxt);
_rl_internal_char_cleanup ();
CALLBACK_READ_RETURN ();
}
_rl_internal_char_cleanup ();
}
else if (RL_ISSTATE (RL_STATE_VIMOTION))
{
eof = _rl_vi_domove_callback (_rl_vimvcxt);
/* Should handle everything, including cleanup, numeric arguments,
and turning off RL_STATE_VIMOTION */
if (RL_ISSTATE (RL_STATE_NUMERICARG) == 0)
_rl_internal_char_cleanup ();
CALLBACK_READ_RETURN ();
}
#endif
else if (RL_ISSTATE (RL_STATE_NUMERICARG))
{
eof = _rl_arg_callback (_rl_argcxt);
if (eof == 0 && (RL_ISSTATE (RL_STATE_NUMERICARG) == 0) && RL_ISSTATE (RL_STATE_INPUTPENDING))
rl_callback_read_char ();
/* XXX - this should handle _rl_last_command_was_kill better */
else if (RL_ISSTATE (RL_STATE_NUMERICARG) == 0)
_rl_internal_char_cleanup ();
CALLBACK_READ_RETURN ();
}
else if (RL_ISSTATE (RL_STATE_MULTIKEY))
{
eof = _rl_dispatch_callback (_rl_kscxt); /* For now */
while ((eof == -1 || eof == -2) && RL_ISSTATE (RL_STATE_MULTIKEY) && _rl_kscxt && (_rl_kscxt->flags & KSEQ_DISPATCHED))
eof = _rl_dispatch_callback (_rl_kscxt);
if (RL_ISSTATE (RL_STATE_MULTIKEY) == 0)
{
_rl_internal_char_cleanup ();
_rl_want_redisplay = 1;
}
}
else if (_rl_callback_func)
{
/* This allows functions that simply need to read an additional
character (like quoted-insert) to register a function to be
called when input is available. _rl_callback_data is a
pointer to a struct that has the argument count originally
passed to the registering function and space for any additional
parameters. */
eof = (*_rl_callback_func) (_rl_callback_data);
/* If the function `deregisters' itself, make sure the data is
cleaned up. */
if (_rl_callback_func == 0)
{
if (_rl_callback_data)
{
_rl_callback_data_dispose (_rl_callback_data);
_rl_callback_data = 0;
}
_rl_internal_char_cleanup ();
}
}
else
eof = readline_internal_char ();
RL_CHECK_SIGNALS ();
if (rl_done == 0 && _rl_want_redisplay)
{
(*rl_redisplay_function) ();
_rl_want_redisplay = 0;
}
/* Make sure application hooks can see whether we saw EOF. */
if (eof > 0)
{
rl_eof_found = eof;
RL_SETSTATE(RL_STATE_EOF);
}
if (rl_done)
{
line = readline_internal_teardown (eof);
if (rl_deprep_term_function)
(*rl_deprep_term_function) ();
#if defined (HANDLE_SIGNALS)
rl_clear_signals ();
#endif
in_handler = 0;
if (rl_linefunc) /* just in case */
(*rl_linefunc) (line);
/* If the user did not clear out the line, do it for him. */
if (rl_line_buffer[0])
_rl_init_line_state ();
/* Redisplay the prompt if readline_handler_{install,remove}
not called. */
if (in_handler == 0 && rl_linefunc)
_rl_callback_newline ();
}
}
while (rl_pending_input || _rl_pushed_input_available () || RL_ISSTATE (RL_STATE_MACROINPUT));
CALLBACK_READ_RETURN ();
}
/* Remove the handler, and make sure the terminal is in its normal state. */
void
rl_callback_handler_remove (void)
{
rl_linefunc = NULL;
RL_UNSETSTATE (RL_STATE_CALLBACK);
RL_CHECK_SIGNALS ();
if (in_handler)
{
in_handler = 0;
if (rl_deprep_term_function)
(*rl_deprep_term_function) ();
#if defined (HANDLE_SIGNALS)
rl_clear_signals ();
#endif
}
}
_rl_callback_generic_arg *
_rl_callback_data_alloc (int count)
{
_rl_callback_generic_arg *arg;
arg = (_rl_callback_generic_arg *)xmalloc (sizeof (_rl_callback_generic_arg));
arg->count = count;
arg->i1 = arg->i2 = 0;
return arg;
}
void
_rl_callback_data_dispose (_rl_callback_generic_arg *arg)
{
xfree (arg);
}
/* Make sure that this agrees with cases in rl_callback_read_char */
void
rl_callback_sigcleanup (void)
{
if (RL_ISSTATE (RL_STATE_CALLBACK) == 0)
return;
if (RL_ISSTATE (RL_STATE_ISEARCH))
_rl_isearch_cleanup (_rl_iscxt, 0);
else if (RL_ISSTATE (RL_STATE_NSEARCH))
_rl_nsearch_cleanup (_rl_nscxt, 0);
else if (RL_ISSTATE (RL_STATE_VIMOTION))
RL_UNSETSTATE (RL_STATE_VIMOTION);
else if (RL_ISSTATE (RL_STATE_NUMERICARG))
{
_rl_argcxt = 0;
RL_UNSETSTATE (RL_STATE_NUMERICARG);
}
else if (RL_ISSTATE (RL_STATE_MULTIKEY))
RL_UNSETSTATE (RL_STATE_MULTIKEY);
if (RL_ISSTATE (RL_STATE_CHARSEARCH))
RL_UNSETSTATE (RL_STATE_CHARSEARCH);
_rl_callback_func = 0;
}
#endif

165
lib/readline/chardefs.h Normal file
View file

@ -0,0 +1,165 @@
/* chardefs.h -- Character definitions for readline. */
/* Copyright (C) 1994-2021 Free Software Foundation, Inc.
This file is part of the GNU Readline Library (Readline), a library
for reading lines of text with interactive input and history editing.
Readline 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.
Readline 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 Readline. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _CHARDEFS_H_
#define _CHARDEFS_H_
#include <ctype.h>
#if defined (HAVE_CONFIG_H)
# if defined (HAVE_STRING_H)
# include <string.h>
# endif /* HAVE_STRING_H */
# if defined (HAVE_STRINGS_H)
# include <strings.h>
# endif /* HAVE_STRINGS_H */
#else
# include <string.h>
#endif /* !HAVE_CONFIG_H */
#ifndef whitespace
#define whitespace(c) (((c) == ' ') || ((c) == '\t'))
#endif
#ifdef CTRL
# undef CTRL
#endif
#ifdef UNCTRL
# undef UNCTRL
#endif
/* Some character stuff. */
#define control_character_threshold 0x020 /* Smaller than this is control. */
#define control_character_mask 0x1f /* 0x20 - 1 */
#define meta_character_threshold 0x07f /* Larger than this is Meta. */
#define control_character_bit 0x40 /* 0x000000, must be off. */
#define meta_character_bit 0x080 /* x0000000, must be on. */
#define largest_char 255 /* Largest character value. */
#define CTRL_CHAR(c) ((c) < control_character_threshold && (((c) & 0x80) == 0))
#define META_CHAR(c) ((c) > meta_character_threshold && (c) <= largest_char)
#define CTRL(c) ((c) & control_character_mask)
#define META(c) ((c) | meta_character_bit)
#define UNMETA(c) ((c) & (~meta_character_bit))
#define UNCTRL(c) _rl_to_upper(((c)|control_character_bit))
#ifndef UCHAR_MAX
# define UCHAR_MAX 255
#endif
#ifndef CHAR_MAX
# define CHAR_MAX 127
#endif
/* use this as a proxy for C89 */
#if defined (HAVE_STDLIB_H) && defined (HAVE_STRING_H)
# define IN_CTYPE_DOMAIN(c) 1
# define NON_NEGATIVE(c) 1
#else
# define IN_CTYPE_DOMAIN(c) ((c) >= 0 && (c) <= CHAR_MAX)
# define NON_NEGATIVE(c) ((unsigned char)(c) == (c))
#endif
#if !defined (isxdigit) && !defined (HAVE_ISXDIGIT) && !defined (__cplusplus)
# define isxdigit(c) (isdigit((unsigned char)(c)) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))
#endif
/* Some systems define these; we want our definitions. */
#undef ISPRINT
/* Beware: these only work with single-byte ASCII characters. */
#define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum ((unsigned char)c))
#define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha ((unsigned char)c))
#define ISDIGIT(c) (IN_CTYPE_DOMAIN (c) && isdigit ((unsigned char)c))
#define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower ((unsigned char)c))
#define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint ((unsigned char)c))
#define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper ((unsigned char)c))
#define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit ((unsigned char)c))
#define _rl_lowercase_p(c) (NON_NEGATIVE(c) && ISLOWER(c))
#define _rl_uppercase_p(c) (NON_NEGATIVE(c) && ISUPPER(c))
#define _rl_digit_p(c) ((c) >= '0' && (c) <= '9')
#define _rl_alphabetic_p(c) (NON_NEGATIVE(c) && ISALNUM(c))
#define _rl_pure_alphabetic(c) (NON_NEGATIVE(c) && ISALPHA(c))
#ifndef _rl_to_upper
# define _rl_to_upper(c) (_rl_lowercase_p(c) ? toupper((unsigned char)(c)) : (c))
# define _rl_to_lower(c) (_rl_uppercase_p(c) ? tolower((unsigned char)(c)) : (c))
#endif
#ifndef _rl_digit_value
# define _rl_digit_value(x) ((x) - '0')
#endif
#ifndef _rl_isident
# define _rl_isident(c) (ISALNUM(c) || (c) == '_')
#endif
#ifndef ISOCTAL
# define ISOCTAL(c) ((c) >= '0' && (c) <= '7')
#endif
#define OCTVALUE(c) ((c) - '0')
#define HEXVALUE(c) \
(((c) >= 'a' && (c) <= 'f') \
? (c)-'a'+10 \
: (c) >= 'A' && (c) <= 'F' ? (c)-'A'+10 : (c)-'0')
#ifndef NEWLINE
#define NEWLINE '\n'
#endif
#ifndef RETURN
#define RETURN CTRL('M')
#endif
#ifndef RUBOUT
#define RUBOUT 0x7f
#endif
#ifndef TAB
#define TAB '\t'
#endif
#ifdef ABORT_CHAR
#undef ABORT_CHAR
#endif
#define ABORT_CHAR CTRL('G')
#ifdef PAGE
#undef PAGE
#endif
#define PAGE CTRL('L')
#ifdef SPACE
#undef SPACE
#endif
#define SPACE ' ' /* XXX - was 0x20 */
#ifdef ESC
#undef ESC
#endif
#define ESC CTRL('[')
#endif /* _CHARDEFS_H_ */

320
lib/readline/colors.c Normal file
View file

@ -0,0 +1,320 @@
/* `dir', `vdir' and `ls' directory listing programs for GNU.
Modified by Chet Ramey for Readline.
Copyright (C) 1985, 1988, 1990-1991, 1995-2021
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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
/* Written by Richard Stallman and David MacKenzie. */
/* Color support by Peter Anvin <Peter.Anvin@linux.org> and Dennis
Flaherty <dennisf@denix.elk.miles.com> based on original patches by
Greg Lee <lee@uhunix.uhcc.hawaii.edu>. */
#define READLINE_LIBRARY
#if defined (HAVE_CONFIG_H)
# include <config.h>
#endif
#include "rlconf.h"
#if defined __TANDEM
# define _XOPEN_SOURCE_EXTENDED 1
# define _TANDEM_SOURCE 1
# include <sys/types.h>
# include <sys/stat.h>
#endif
#include <stdio.h>
#include "posixstat.h" // stat related macros (S_ISREG, ...)
#include <fcntl.h> // S_ISUID
#ifndef S_ISDIR
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#endif
// strlen()
#if defined (HAVE_STRING_H)
# include <string.h>
#else /* !HAVE_STRING_H */
# include <strings.h>
#endif /* !HAVE_STRING_H */
// abort()
#if defined (HAVE_STDLIB_H)
# include <stdlib.h>
#else
# include "ansi_stdlib.h"
#endif /* HAVE_STDLIB_H */
#include "readline.h"
#include "rldefs.h"
#ifdef COLOR_SUPPORT
#include "xmalloc.h"
#include "colors.h"
static bool is_colored (enum indicator_no type);
static void restore_default_color (void);
#define RL_COLOR_PREFIX_EXTENSION ".readline-colored-completion-prefix"
COLOR_EXT_TYPE *_rl_color_ext_list = 0;
/* Output a color indicator (which may contain nulls). */
void
_rl_put_indicator (const struct bin_str *ind)
{
fwrite (ind->string, ind->len, 1, rl_outstream);
}
static bool
is_colored (enum indicator_no colored_filetype)
{
size_t len = _rl_color_indicator[colored_filetype].len;
char const *s = _rl_color_indicator[colored_filetype].string;
return ! (len == 0
|| (len == 1 && strncmp (s, "0", 1) == 0)
|| (len == 2 && strncmp (s, "00", 2) == 0));
}
static void
restore_default_color (void)
{
_rl_put_indicator (&_rl_color_indicator[C_LEFT]);
_rl_put_indicator (&_rl_color_indicator[C_RIGHT]);
}
void
_rl_set_normal_color (void)
{
if (is_colored (C_NORM))
{
_rl_put_indicator (&_rl_color_indicator[C_LEFT]);
_rl_put_indicator (&_rl_color_indicator[C_NORM]);
_rl_put_indicator (&_rl_color_indicator[C_RIGHT]);
}
}
static struct bin_str *
_rl_custom_readline_prefix (void)
{
size_t len;
COLOR_EXT_TYPE *ext;
len = strlen (RL_COLOR_PREFIX_EXTENSION);
for (ext = _rl_color_ext_list; ext; ext = ext->next)
if (ext->ext.len == len && STREQN (ext->ext.string, RL_COLOR_PREFIX_EXTENSION, len))
return (&ext->seq);
return (NULL);
}
bool
_rl_print_prefix_color (void)
{
struct bin_str *s;
/* What do we want to use for the prefix? Let's try cyan first, see colors.h */
s = _rl_custom_readline_prefix ();
if (s == 0)
s = &_rl_color_indicator[C_PREFIX];
if (s->string != NULL)
{
if (is_colored (C_NORM))
restore_default_color ();
_rl_put_indicator (&_rl_color_indicator[C_LEFT]);
_rl_put_indicator (s);
_rl_put_indicator (&_rl_color_indicator[C_RIGHT]);
return 0;
}
else
return 1;
}
/* Returns whether any color sequence was printed. */
bool
_rl_print_color_indicator (const char *f)
{
enum indicator_no colored_filetype;
COLOR_EXT_TYPE *ext; /* Color extension */
size_t len; /* Length of name */
const char* name;
char *filename;
struct stat astat, linkstat;
mode_t mode;
int linkok; /* 1 == ok, 0 == dangling symlink, -1 == missing */
int stat_ok;
name = f;
/* This should already have undergone tilde expansion */
filename = 0;
if (rl_filename_stat_hook)
{
filename = savestring (f);
(*rl_filename_stat_hook) (&filename);
name = filename;
}
#if defined (HAVE_LSTAT)
stat_ok = lstat(name, &astat);
#else
stat_ok = stat(name, &astat);
#endif
if (stat_ok == 0)
{
mode = astat.st_mode;
#if defined (HAVE_LSTAT)
if (S_ISLNK (mode))
{
linkok = stat (name, &linkstat) == 0;
if (linkok && strncmp (_rl_color_indicator[C_LINK].string, "target", 6) == 0)
mode = linkstat.st_mode;
}
else
#endif
linkok = 1;
}
else
linkok = -1;
/* Is this a nonexistent file? If so, linkok == -1. */
if (linkok == -1 && _rl_color_indicator[C_MISSING].string != NULL)
colored_filetype = C_MISSING;
else if (linkok == 0 && _rl_color_indicator[C_ORPHAN].string != NULL)
colored_filetype = C_ORPHAN; /* dangling symlink */
else if(stat_ok != 0)
{
static enum indicator_no filetype_indicator[] = FILETYPE_INDICATORS;
colored_filetype = filetype_indicator[normal]; //f->filetype];
}
else
{
if (S_ISREG (mode))
{
colored_filetype = C_FILE;
#if defined (S_ISUID)
if ((mode & S_ISUID) != 0 && is_colored (C_SETUID))
colored_filetype = C_SETUID;
else
#endif
#if defined (S_ISGID)
if ((mode & S_ISGID) != 0 && is_colored (C_SETGID))
colored_filetype = C_SETGID;
else
#endif
if (is_colored (C_CAP) && 0) //f->has_capability)
colored_filetype = C_CAP;
else if ((mode & S_IXUGO) != 0 && is_colored (C_EXEC))
colored_filetype = C_EXEC;
else if ((1 < astat.st_nlink) && is_colored (C_MULTIHARDLINK))
colored_filetype = C_MULTIHARDLINK;
}
else if (S_ISDIR (mode))
{
colored_filetype = C_DIR;
#if defined (S_ISVTX)
if ((mode & S_ISVTX) && (mode & S_IWOTH)
&& is_colored (C_STICKY_OTHER_WRITABLE))
colored_filetype = C_STICKY_OTHER_WRITABLE;
else
#endif
if ((mode & S_IWOTH) != 0 && is_colored (C_OTHER_WRITABLE))
colored_filetype = C_OTHER_WRITABLE;
#if defined (S_ISVTX)
else if ((mode & S_ISVTX) != 0 && is_colored (C_STICKY))
colored_filetype = C_STICKY;
#endif
}
#if defined (S_ISLNK)
else if (S_ISLNK (mode))
colored_filetype = C_LINK;
#endif
else if (S_ISFIFO (mode))
colored_filetype = C_FIFO;
#if defined (S_ISSOCK)
else if (S_ISSOCK (mode))
colored_filetype = C_SOCK;
#endif
#if defined (S_ISBLK)
else if (S_ISBLK (mode))
colored_filetype = C_BLK;
#endif
else if (S_ISCHR (mode))
colored_filetype = C_CHR;
else
{
/* Classify a file of some other type as C_ORPHAN. */
colored_filetype = C_ORPHAN;
}
}
/* Check the file's suffix only if still classified as C_FILE. */
ext = NULL;
if (colored_filetype == C_FILE)
{
/* Test if NAME has a recognized suffix. */
len = strlen (name);
name += len; /* Pointer to final \0. */
for (ext = _rl_color_ext_list; ext != NULL; ext = ext->next)
{
if (ext->ext.len <= len
&& strncmp (name - ext->ext.len, ext->ext.string,
ext->ext.len) == 0)
break;
}
}
free (filename); /* NULL or savestring return value */
{
const struct bin_str *const s
= ext ? &(ext->seq) : &_rl_color_indicator[colored_filetype];
if (s->string != NULL)
{
/* Need to reset so not dealing with attribute combinations */
if (is_colored (C_NORM))
restore_default_color ();
_rl_put_indicator (&_rl_color_indicator[C_LEFT]);
_rl_put_indicator (s);
_rl_put_indicator (&_rl_color_indicator[C_RIGHT]);
return 0;
}
else
return 1;
}
}
void
_rl_prep_non_filename_text (void)
{
if (_rl_color_indicator[C_END].string != NULL)
_rl_put_indicator (&_rl_color_indicator[C_END]);
else
{
_rl_put_indicator (&_rl_color_indicator[C_LEFT]);
_rl_put_indicator (&_rl_color_indicator[C_RESET]);
_rl_put_indicator (&_rl_color_indicator[C_RIGHT]);
}
}
#endif /* COLOR_SUPPORT */

126
lib/readline/colors.h Normal file
View file

@ -0,0 +1,126 @@
/* `dir', `vdir' and `ls' directory listing programs for GNU.
Modified by Chet Ramey for Readline.
Copyright (C) 1985, 1988, 1990-1991, 1995-2010, 2012, 2015
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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
/* Written by Richard Stallman and David MacKenzie. */
/* Color support by Peter Anvin <Peter.Anvin@linux.org> and Dennis
Flaherty <dennisf@denix.elk.miles.com> based on original patches by
Greg Lee <lee@uhunix.uhcc.hawaii.edu>. */
#ifndef _COLORS_H_
#define _COLORS_H_
#include <stdio.h> // size_t
#if defined(__TANDEM) && defined(HAVE_STDBOOL_H) && (__STDC_VERSION__ < 199901L)
typedef int _Bool;
#endif
#if defined (HAVE_STDBOOL_H)
# include <stdbool.h> // bool
#else
typedef int _rl_bool_t;
#ifdef bool
# undef bool
#endif
#define bool _rl_bool_t
#ifndef true
# define true 1
# define false 0
#endif
#endif /* !HAVE_STDBOOL_H */
/* Null is a valid character in a color indicator (think about Epson
printers, for example) so we have to use a length/buffer string
type. */
struct bin_str
{
size_t len;
const char *string;
};
/* file type indicators (dir, sock, fifo, ...)
Default value is initialized in parse-colors.c.
It is then modified from the values of $LS_COLORS. */
extern struct bin_str _rl_color_indicator[];
/* The LS_COLORS variable is in a termcap-like format. */
typedef struct _color_ext_type
{
struct bin_str ext; /* The extension we're looking for */
struct bin_str seq; /* The sequence to output when we do */
struct _color_ext_type *next; /* Next in list */
} COLOR_EXT_TYPE;
/* file extensions indicators (.txt, .log, .jpg, ...)
Values are taken from $LS_COLORS in rl_parse_colors(). */
extern COLOR_EXT_TYPE *_rl_color_ext_list;
#define FILETYPE_INDICATORS \
{ \
C_ORPHAN, C_FIFO, C_CHR, C_DIR, C_BLK, C_FILE, \
C_LINK, C_SOCK, C_FILE, C_DIR \
}
/* Whether we used any colors in the output so far. If so, we will
need to restore the default color later. If not, we will need to
call prep_non_filename_text before using color for the first time. */
enum indicator_no
{
C_LEFT, C_RIGHT, C_END, C_RESET, C_NORM, C_FILE, C_DIR, C_LINK,
C_FIFO, C_SOCK,
C_BLK, C_CHR, C_MISSING, C_ORPHAN, C_EXEC, C_DOOR, C_SETUID, C_SETGID,
C_STICKY, C_OTHER_WRITABLE, C_STICKY_OTHER_WRITABLE, C_CAP, C_MULTIHARDLINK,
C_CLR_TO_EOL
};
#if !S_IXUGO
# define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
#endif
enum filetype
{
unknown,
fifo,
chardev,
directory,
blockdev,
normal,
symbolic_link,
sock,
whiteout,
arg_directory
};
/* Prefix color, currently same as socket */
#define C_PREFIX C_SOCK
extern void _rl_put_indicator (const struct bin_str *ind);
extern void _rl_set_normal_color (void);
extern bool _rl_print_prefix_color (void);
extern bool _rl_print_color_indicator (const char *f);
extern void _rl_prep_non_filename_text (void);
#endif /* !_COLORS_H_ */

106
lib/readline/compat.c Normal file
View file

@ -0,0 +1,106 @@
/* compat.c -- backwards compatibility functions. */
/* Copyright (C) 2000-2021 Free Software Foundation, Inc.
This file is part of the GNU Readline Library (Readline), a library
for reading lines of text with interactive input and history editing.
Readline 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.
Readline 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 Readline. If not, see <http://www.gnu.org/licenses/>.
*/
#define READLINE_LIBRARY
#if defined (HAVE_CONFIG_H)
# include <config.h>
#endif
#include <stdio.h>
#include "rlstdc.h"
#include "rltypedefs.h"
extern void rl_free_undo_list (void);
extern int rl_maybe_save_line (void);
extern int rl_maybe_unsave_line (void);
extern int rl_maybe_replace_line (void);
extern int rl_crlf (void);
extern int rl_ding (void);
extern int rl_alphabetic (int);
extern char **rl_completion_matches (const char *, rl_compentry_func_t *);
extern char *rl_username_completion_function (const char *, int);
extern char *rl_filename_completion_function (const char *, int);
/* Provide backwards-compatible entry points for old function names. */
void
free_undo_list (void)
{
rl_free_undo_list ();
}
int
maybe_replace_line (void)
{
return rl_maybe_replace_line ();
}
int
maybe_save_line (void)
{
return rl_maybe_save_line ();
}
int
maybe_unsave_line (void)
{
return rl_maybe_unsave_line ();
}
int
ding (void)
{
return rl_ding ();
}
int
crlf (void)
{
return rl_crlf ();
}
int
alphabetic (int c)
{
return rl_alphabetic (c);
}
char **
completion_matches (const char *s, rl_compentry_func_t *f)
{
return rl_completion_matches (s, f);
}
char *
username_completion_function (const char *s, int i)
{
return rl_username_completion_function (s, i);
}
char *
filename_completion_function (const char *s, int i)
{
return rl_filename_completion_function (s, i);
}

3008
lib/readline/complete.c Normal file

File diff suppressed because it is too large Load diff

3580
lib/readline/display.c Normal file

File diff suppressed because it is too large Load diff

159
lib/readline/doc/Makefile Normal file
View file

@ -0,0 +1,159 @@
# Derived by hand from the generated readline-src/doc/Makefile
# This makefile for Readline library documentation is in -*- text -*- mode.
# Emacs likes it that way.
# Copyright (C) 1996-2002 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
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
#
topdir = .
srcdir = .
VPATH = .
prefix = /usr/local
infodir = ${prefix}/info
mandir = ${prefix}/man
manpfx = man
man1ext = 1
man1dir = $(mandir)/$(manpfx)$(man1ext)
man3ext = 3
man3dir = $(mandir)/$(manpfx)$(man3ext)
SHELL = /bin/sh
RM = rm -f
INSTALL = /usr/bin/install -c
INSTALL_DATA = ${INSTALL} -m 644
BUILD_DIR = .
TEXINPUTDIR = $(srcdir)
MAKEINFO = LANGUAGE= makeinfo
TEXI2DVI = $(srcdir)/texi2dvi
TEXI2HTML = $(srcdir)/texi2html
QUIETPS = #set this to -q to shut up dvips
PSDPI = 300 # I don't have any 600-dpi printers
DVIPS = dvips -D ${PSDPI} $(QUIETPS) -o $@ # tricky
DVIPDF = dvipdfm -o $@ -p ${PAPERSIZE}
PSPDF = gs -sPAPERSIZE=${PAPERSIZE} -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -sOutputFile=$@
RLSRC = $(srcdir)/rlman.texi $(srcdir)/rluser.texi \
$(srcdir)/rltech.texi $(srcdir)/version.texi \
$(srcdir)/rluserman.texi
HISTSRC = $(srcdir)/history.texi $(srcdir)/hsuser.texi \
$(srcdir)/hstech.texi $(srcdir)/version.texi
# This should be a program that converts troff to an ascii-readable format
NROFF = groff -Tascii
# This should be a program that converts troff to postscript
GROFF = groff
DVIOBJ = readline.dvi history.dvi rluserman.dvi
INFOOBJ = readline.info history.info rluserman.info
PSOBJ = readline.ps history.ps rluserman.ps
HTMLOBJ = readline.html history.html rluserman.html
PDFOBJ = readline.pdf history.pdf rluserman.pdf
INTERMEDIATE_OBJ = rlman.dvi
CREATED_DOCS = $(DVIOBJ) $(INFOOBJ) $(PSOBJ) $(HTMLOBJ) $(PDFOBJ)
.SUFFIXES: .ps .txt .dvi .html .pdf
.ps.pdf:
$(RM) $@
-${PSPDF} $<
.dvi.pdf:
$(RM) $@
-${DVIPDF} $<
all: info dvi html ps
nodvi: info html
pdf: $(PDFOBJ)
readline.dvi: $(RLSRC)
TEXINPUTS=.:$(TEXINPUTDIR):$$TEXINPUTS $(TEXI2DVI) $(srcdir)/rlman.texi
mv rlman.dvi readline.dvi
readline.info: $(RLSRC)
$(MAKEINFO) --no-split -I $(TEXINPUTDIR) -o $@ $(srcdir)/rlman.texi
rluserman.dvi: $(RLSRC)
TEXINPUTS=.:$(TEXINPUTDIR):$$TEXINPUTS $(TEXI2DVI) $(srcdir)/rluserman.texi
rluserman.info: $(RLSRC)
$(MAKEINFO) --no-split -I $(TEXINPUTDIR) -o $@ $(srcdir)/rluserman.texi
history.dvi: ${HISTSRC}
TEXINPUTS=.:$(TEXINPUTDIR):$$TEXINPUTS $(TEXI2DVI) $(srcdir)/history.texi
history.info: ${HISTSRC}
$(MAKEINFO) --no-split -I $(TEXINPUTDIR) -o $@ $(srcdir)/history.texi
readline.ps: readline.dvi
$(RM) $@
$(DVIPS) readline.dvi
rluserman.ps: rluserman.dvi
$(RM) $@
$(DVIPS) rluserman.dvi
history.ps: history.dvi
$(RM) $@
$(DVIPS) history.dvi
readline.html: ${RLSRC}
$(TEXI2HTML) -menu -monolithic -I $(TEXINPUTDIR) $(srcdir)/rlman.texi
sed -e 's:rlman.html:readline.html:' rlman.html > readline.html
$(RM) rlman.html
rluserman.html: ${RLSRC}
$(TEXI2HTML) -menu -monolithic -I $(TEXINPUTDIR) $(srcdir)/rluserman.texi
history.html: ${HISTSRC}
$(TEXI2HTML) -menu -monolithic -I $(TEXINPUTDIR) $(srcdir)/history.texi
info: $(INFOOBJ)
dvi: $(DVIOBJ)
ps: $(PSOBJ)
html: $(HTMLOBJ)
readline.pdf: readline.dvi
history.pdf: history.dvi
rluserman.pdf: rluserman.dvi
clean:
$(RM) *.aux *.cp *.fn *.ky *.log *.pg *.toc *.tp *.vr *.cps *.pgs \
*.fns *.kys *.tps *.vrs *.bt *.bts *.o core *.core
distclean: clean
$(RM) $(CREATED_DOCS)
$(RM) $(INTERMEDIATE_OBJ)
mostlyclean: clean
maintainer-clean: clean
$(RM) $(CREATED_DOCS)
$(RM) $(INTERMEDIATE_OBJ)
$(RM) Makefile
install:
@echo "This documentation should not be installed."
uninstall:

506
lib/readline/doc/fdl.texi Normal file
View file

@ -0,0 +1,506 @@
@c The GNU Free Documentation License.
@center Version 1.3, 3 November 2008
@c This file is intended to be included within another document,
@c hence no sectioning command or @node.
@display
Copyright @copyright{} 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
@uref{http://fsf.org/}
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
@end display
@enumerate 0
@item
PREAMBLE
The purpose of this License is to make a manual, textbook, or other
functional and useful document @dfn{free} in the sense of freedom: to
assure everyone the effective freedom to copy and redistribute it,
with or without modifying it, either commercially or noncommercially.
Secondarily, this License preserves for the author and publisher a way
to get credit for their work, while not being considered responsible
for modifications made by others.
This License is a kind of ``copyleft'', which means that derivative
works of the document must themselves be free in the same sense. It
complements the GNU General Public License, which is a copyleft
license designed for free software.
We have designed this License in order to use it for manuals for free
software, because free software needs free documentation: a free
program should come with manuals providing the same freedoms that the
software does. But this License is not limited to software manuals;
it can be used for any textual work, regardless of subject matter or
whether it is published as a printed book. We recommend this License
principally for works whose purpose is instruction or reference.
@item
APPLICABILITY AND DEFINITIONS
This License applies to any manual or other work, in any medium, that
contains a notice placed by the copyright holder saying it can be
distributed under the terms of this License. Such a notice grants a
world-wide, royalty-free license, unlimited in duration, to use that
work under the conditions stated herein. The ``Document'', below,
refers to any such manual or work. Any member of the public is a
licensee, and is addressed as ``you''. You accept the license if you
copy, modify or distribute the work in a way requiring permission
under copyright law.
A ``Modified Version'' of the Document means any work containing the
Document or a portion of it, either copied verbatim, or with
modifications and/or translated into another language.
A ``Secondary Section'' is a named appendix or a front-matter section
of the Document that deals exclusively with the relationship of the
publishers or authors of the Document to the Document's overall
subject (or to related matters) and contains nothing that could fall
directly within that overall subject. (Thus, if the Document is in
part a textbook of mathematics, a Secondary Section may not explain
any mathematics.) The relationship could be a matter of historical
connection with the subject or with related matters, or of legal,
commercial, philosophical, ethical or political position regarding
them.
The ``Invariant Sections'' are certain Secondary Sections whose titles
are designated, as being those of Invariant Sections, in the notice
that says that the Document is released under this License. If a
section does not fit the above definition of Secondary then it is not
allowed to be designated as Invariant. The Document may contain zero
Invariant Sections. If the Document does not identify any Invariant
Sections then there are none.
The ``Cover Texts'' are certain short passages of text that are listed,
as Front-Cover Texts or Back-Cover Texts, in the notice that says that
the Document is released under this License. A Front-Cover Text may
be at most 5 words, and a Back-Cover Text may be at most 25 words.
A ``Transparent'' copy of the Document means a machine-readable copy,
represented in a format whose specification is available to the
general public, that is suitable for revising the document
straightforwardly with generic text editors or (for images composed of
pixels) generic paint programs or (for drawings) some widely available
drawing editor, and that is suitable for input to text formatters or
for automatic translation to a variety of formats suitable for input
to text formatters. A copy made in an otherwise Transparent file
format whose markup, or absence of markup, has been arranged to thwart
or discourage subsequent modification by readers is not Transparent.
An image format is not Transparent if used for any substantial amount
of text. A copy that is not ``Transparent'' is called ``Opaque''.
Examples of suitable formats for Transparent copies include plain
@sc{ascii} without markup, Texinfo input format, La@TeX{} input
format, @acronym{SGML} or @acronym{XML} using a publicly available
@acronym{DTD}, and standard-conforming simple @acronym{HTML},
PostScript or @acronym{PDF} designed for human modification. Examples
of transparent image formats include @acronym{PNG}, @acronym{XCF} and
@acronym{JPG}. Opaque formats include proprietary formats that can be
read and edited only by proprietary word processors, @acronym{SGML} or
@acronym{XML} for which the @acronym{DTD} and/or processing tools are
not generally available, and the machine-generated @acronym{HTML},
PostScript or @acronym{PDF} produced by some word processors for
output purposes only.
The ``Title Page'' means, for a printed book, the title page itself,
plus such following pages as are needed to hold, legibly, the material
this License requires to appear in the title page. For works in
formats which do not have any title page as such, ``Title Page'' means
the text near the most prominent appearance of the work's title,
preceding the beginning of the body of the text.
The ``publisher'' means any person or entity that distributes copies
of the Document to the public.
A section ``Entitled XYZ'' means a named subunit of the Document whose
title either is precisely XYZ or contains XYZ in parentheses following
text that translates XYZ in another language. (Here XYZ stands for a
specific section name mentioned below, such as ``Acknowledgements'',
``Dedications'', ``Endorsements'', or ``History''.) To ``Preserve the Title''
of such a section when you modify the Document means that it remains a
section ``Entitled XYZ'' according to this definition.
The Document may include Warranty Disclaimers next to the notice which
states that this License applies to the Document. These Warranty
Disclaimers are considered to be included by reference in this
License, but only as regards disclaiming warranties: any other
implication that these Warranty Disclaimers may have is void and has
no effect on the meaning of this License.
@item
VERBATIM COPYING
You may copy and distribute the Document in any medium, either
commercially or noncommercially, provided that this License, the
copyright notices, and the license notice saying this License applies
to the Document are reproduced in all copies, and that you add no other
conditions whatsoever to those of this License. You may not use
technical measures to obstruct or control the reading or further
copying of the copies you make or distribute. However, you may accept
compensation in exchange for copies. If you distribute a large enough
number of copies you must also follow the conditions in section 3.
You may also lend copies, under the same conditions stated above, and
you may publicly display copies.
@item
COPYING IN QUANTITY
If you publish printed copies (or copies in media that commonly have
printed covers) of the Document, numbering more than 100, and the
Document's license notice requires Cover Texts, you must enclose the
copies in covers that carry, clearly and legibly, all these Cover
Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on
the back cover. Both covers must also clearly and legibly identify
you as the publisher of these copies. The front cover must present
the full title with all words of the title equally prominent and
visible. You may add other material on the covers in addition.
Copying with changes limited to the covers, as long as they preserve
the title of the Document and satisfy these conditions, can be treated
as verbatim copying in other respects.
If the required texts for either cover are too voluminous to fit
legibly, you should put the first ones listed (as many as fit
reasonably) on the actual cover, and continue the rest onto adjacent
pages.
If you publish or distribute Opaque copies of the Document numbering
more than 100, you must either include a machine-readable Transparent
copy along with each Opaque copy, or state in or with each Opaque copy
a computer-network location from which the general network-using
public has access to download using public-standard network protocols
a complete Transparent copy of the Document, free of added material.
If you use the latter option, you must take reasonably prudent steps,
when you begin distribution of Opaque copies in quantity, to ensure
that this Transparent copy will remain thus accessible at the stated
location until at least one year after the last time you distribute an
Opaque copy (directly or through your agents or retailers) of that
edition to the public.
It is requested, but not required, that you contact the authors of the
Document well before redistributing any large number of copies, to give
them a chance to provide you with an updated version of the Document.
@item
MODIFICATIONS
You may copy and distribute a Modified Version of the Document under
the conditions of sections 2 and 3 above, provided that you release
the Modified Version under precisely this License, with the Modified
Version filling the role of the Document, thus licensing distribution
and modification of the Modified Version to whoever possesses a copy
of it. In addition, you must do these things in the Modified Version:
@enumerate A
@item
Use in the Title Page (and on the covers, if any) a title distinct
from that of the Document, and from those of previous versions
(which should, if there were any, be listed in the History section
of the Document). You may use the same title as a previous version
if the original publisher of that version gives permission.
@item
List on the Title Page, as authors, one or more persons or entities
responsible for authorship of the modifications in the Modified
Version, together with at least five of the principal authors of the
Document (all of its principal authors, if it has fewer than five),
unless they release you from this requirement.
@item
State on the Title page the name of the publisher of the
Modified Version, as the publisher.
@item
Preserve all the copyright notices of the Document.
@item
Add an appropriate copyright notice for your modifications
adjacent to the other copyright notices.
@item
Include, immediately after the copyright notices, a license notice
giving the public permission to use the Modified Version under the
terms of this License, in the form shown in the Addendum below.
@item
Preserve in that license notice the full lists of Invariant Sections
and required Cover Texts given in the Document's license notice.
@item
Include an unaltered copy of this License.
@item
Preserve the section Entitled ``History'', Preserve its Title, and add
to it an item stating at least the title, year, new authors, and
publisher of the Modified Version as given on the Title Page. If
there is no section Entitled ``History'' in the Document, create one
stating the title, year, authors, and publisher of the Document as
given on its Title Page, then add an item describing the Modified
Version as stated in the previous sentence.
@item
Preserve the network location, if any, given in the Document for
public access to a Transparent copy of the Document, and likewise
the network locations given in the Document for previous versions
it was based on. These may be placed in the ``History'' section.
You may omit a network location for a work that was published at
least four years before the Document itself, or if the original
publisher of the version it refers to gives permission.
@item
For any section Entitled ``Acknowledgements'' or ``Dedications'', Preserve
the Title of the section, and preserve in the section all the
substance and tone of each of the contributor acknowledgements and/or
dedications given therein.
@item
Preserve all the Invariant Sections of the Document,
unaltered in their text and in their titles. Section numbers
or the equivalent are not considered part of the section titles.
@item
Delete any section Entitled ``Endorsements''. Such a section
may not be included in the Modified Version.
@item
Do not retitle any existing section to be Entitled ``Endorsements'' or
to conflict in title with any Invariant Section.
@item
Preserve any Warranty Disclaimers.
@end enumerate
If the Modified Version includes new front-matter sections or
appendices that qualify as Secondary Sections and contain no material
copied from the Document, you may at your option designate some or all
of these sections as invariant. To do this, add their titles to the
list of Invariant Sections in the Modified Version's license notice.
These titles must be distinct from any other section titles.
You may add a section Entitled ``Endorsements'', provided it contains
nothing but endorsements of your Modified Version by various
parties---for example, statements of peer review or that the text has
been approved by an organization as the authoritative definition of a
standard.
You may add a passage of up to five words as a Front-Cover Text, and a
passage of up to 25 words as a Back-Cover Text, to the end of the list
of Cover Texts in the Modified Version. Only one passage of
Front-Cover Text and one of Back-Cover Text may be added by (or
through arrangements made by) any one entity. If the Document already
includes a cover text for the same cover, previously added by you or
by arrangement made by the same entity you are acting on behalf of,
you may not add another; but you may replace the old one, on explicit
permission from the previous publisher that added the old one.
The author(s) and publisher(s) of the Document do not by this License
give permission to use their names for publicity for or to assert or
imply endorsement of any Modified Version.
@item
COMBINING DOCUMENTS
You may combine the Document with other documents released under this
License, under the terms defined in section 4 above for modified
versions, provided that you include in the combination all of the
Invariant Sections of all of the original documents, unmodified, and
list them all as Invariant Sections of your combined work in its
license notice, and that you preserve all their Warranty Disclaimers.
The combined work need only contain one copy of this License, and
multiple identical Invariant Sections may be replaced with a single
copy. If there are multiple Invariant Sections with the same name but
different contents, make the title of each such section unique by
adding at the end of it, in parentheses, the name of the original
author or publisher of that section if known, or else a unique number.
Make the same adjustment to the section titles in the list of
Invariant Sections in the license notice of the combined work.
In the combination, you must combine any sections Entitled ``History''
in the various original documents, forming one section Entitled
``History''; likewise combine any sections Entitled ``Acknowledgements'',
and any sections Entitled ``Dedications''. You must delete all
sections Entitled ``Endorsements.''
@item
COLLECTIONS OF DOCUMENTS
You may make a collection consisting of the Document and other documents
released under this License, and replace the individual copies of this
License in the various documents with a single copy that is included in
the collection, provided that you follow the rules of this License for
verbatim copying of each of the documents in all other respects.
You may extract a single document from such a collection, and distribute
it individually under this License, provided you insert a copy of this
License into the extracted document, and follow this License in all
other respects regarding verbatim copying of that document.
@item
AGGREGATION WITH INDEPENDENT WORKS
A compilation of the Document or its derivatives with other separate
and independent documents or works, in or on a volume of a storage or
distribution medium, is called an ``aggregate'' if the copyright
resulting from the compilation is not used to limit the legal rights
of the compilation's users beyond what the individual works permit.
When the Document is included in an aggregate, this License does not
apply to the other works in the aggregate which are not themselves
derivative works of the Document.
If the Cover Text requirement of section 3 is applicable to these
copies of the Document, then if the Document is less than one half of
the entire aggregate, the Document's Cover Texts may be placed on
covers that bracket the Document within the aggregate, or the
electronic equivalent of covers if the Document is in electronic form.
Otherwise they must appear on printed covers that bracket the whole
aggregate.
@item
TRANSLATION
Translation is considered a kind of modification, so you may
distribute translations of the Document under the terms of section 4.
Replacing Invariant Sections with translations requires special
permission from their copyright holders, but you may include
translations of some or all Invariant Sections in addition to the
original versions of these Invariant Sections. You may include a
translation of this License, and all the license notices in the
Document, and any Warranty Disclaimers, provided that you also include
the original English version of this License and the original versions
of those notices and disclaimers. In case of a disagreement between
the translation and the original version of this License or a notice
or disclaimer, the original version will prevail.
If a section in the Document is Entitled ``Acknowledgements'',
``Dedications'', or ``History'', the requirement (section 4) to Preserve
its Title (section 1) will typically require changing the actual
title.
@item
TERMINATION
You may not copy, modify, sublicense, or distribute the Document
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense, or distribute it is void, and
will automatically terminate your rights under this License.
However, if you cease all violation of this License, then your license
from a particular copyright holder is reinstated (a) provisionally,
unless and until the copyright holder explicitly and finally
terminates your license, and (b) permanently, if the copyright holder
fails to notify you of the violation by some reasonable means prior to
60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, receipt of a copy of some or all of the same material does
not give you any rights to use it.
@item
FUTURE REVISIONS OF THIS LICENSE
The Free Software Foundation may publish new, revised versions
of the GNU Free Documentation License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns. See
@uref{http://www.gnu.org/copyleft/}.
Each version of the License is given a distinguishing version number.
If the Document specifies that a particular numbered version of this
License ``or any later version'' applies to it, you have the option of
following the terms and conditions either of that specified version or
of any later version that has been published (not as a draft) by the
Free Software Foundation. If the Document does not specify a version
number of this License, you may choose any version ever published (not
as a draft) by the Free Software Foundation. If the Document
specifies that a proxy can decide which future versions of this
License can be used, that proxy's public statement of acceptance of a
version permanently authorizes you to choose that version for the
Document.
@item
RELICENSING
``Massive Multiauthor Collaboration Site'' (or ``MMC Site'') means any
World Wide Web server that publishes copyrightable works and also
provides prominent facilities for anybody to edit those works. A
public wiki that anybody can edit is an example of such a server. A
``Massive Multiauthor Collaboration'' (or ``MMC'') contained in the
site means any set of copyrightable works thus published on the MMC
site.
``CC-BY-SA'' means the Creative Commons Attribution-Share Alike 3.0
license published by Creative Commons Corporation, a not-for-profit
corporation with a principal place of business in San Francisco,
California, as well as future copyleft versions of that license
published by that same organization.
``Incorporate'' means to publish or republish a Document, in whole or
in part, as part of another Document.
An MMC is ``eligible for relicensing'' if it is licensed under this
License, and if all works that were first published under this License
somewhere other than this MMC, and subsequently incorporated in whole
or in part into the MMC, (1) had no cover texts or invariant sections,
and (2) were thus incorporated prior to November 1, 2008.
The operator of an MMC Site may republish an MMC contained in the site
under CC-BY-SA on the same site at any time before August 1, 2009,
provided the MMC is eligible for relicensing.
@end enumerate
@page
@heading ADDENDUM: How to use this License for your documents
To use this License in a document you have written, include a copy of
the License in the document and put the following copyright and
license notices just after the title page:
@smallexample
@group
Copyright (C) @var{year} @var{your name}.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3
or any later version published by the Free Software Foundation;
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
Texts. A copy of the license is included in the section entitled ``GNU
Free Documentation License''.
@end group
@end smallexample
If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts,
replace the ``with@dots{}Texts.'' line with this:
@smallexample
@group
with the Invariant Sections being @var{list their titles}, with
the Front-Cover Texts being @var{list}, and with the Back-Cover Texts
being @var{list}.
@end group
@end smallexample
If you have Invariant Sections without Cover Texts, or some other
combination of the three, merge those two alternatives to suit the
situation.
If your document contains nontrivial examples of program code, we
recommend releasing these examples in parallel under your choice of
free software license, such as the GNU General Public License,
to permit their use in free software.
@c Local Variables:
@c ispell-local-pdict: "ispell-dict"
@c End:

View file

@ -0,0 +1,85 @@
\input texinfo @c -*-texinfo-*-
@c %**start of header (This is for running Texinfo on a region.)
@setfilename history.info
@settitle GNU History Library
@include version.texi
@c %**end of header (This is for running Texinfo on a region.)
@copying
This document describes the GNU History library
(version @value{VERSION}, @value{UPDATED}),
a programming tool that provides a consistent user interface for
recalling lines of previously typed input.
Copyright @copyright{} 1988--2022 Free Software Foundation, Inc.
@quotation
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
A copy of the license is included in the section entitled
``GNU Free Documentation License''.
@end quotation
@end copying
@dircategory Libraries
@direntry
* History: (history). The GNU history library API.
@end direntry
@titlepage
@title GNU History Library
@subtitle Edition @value{EDITION}, for @code{History Library} Version @value{VERSION}.
@subtitle @value{UPDATED-MONTH}
@author Chet Ramey, Case Western Reserve University
@author Brian Fox, Free Software Foundation
@page
@vskip 0pt plus 1filll
@insertcopying
@end titlepage
@contents
@ifnottex
@node Top
@top GNU History Library
This document describes the GNU History library, a programming tool that
provides a consistent user interface for recalling lines of previously
typed input.
@menu
* Using History Interactively:: GNU History User's Manual.
* Programming with GNU History:: GNU History Programmer's Manual.
* GNU Free Documentation License:: License for copying this manual.
* Concept Index:: Index of concepts described in this manual.
* Function and Variable Index:: Index of externally visible functions
and variables.
@end menu
@end ifnottex
@syncodeindex fn vr
@include hsuser.texi
@include hstech.texi
@node GNU Free Documentation License
@appendix GNU Free Documentation License
@include fdl.texi
@node Concept Index
@appendix Concept Index
@printindex cp
@node Function and Variable Index
@appendix Function and Variable Index
@printindex vr
@bye

View file

@ -0,0 +1,602 @@
@ignore
This file documents the user interface to the GNU History library.
Copyright (C) 1988-2022 Free Software Foundation, Inc.
Authored by Brian Fox and Chet Ramey.
Permission is granted to make and distribute verbatim copies of this manual
provided the copyright notice and this permission notice are preserved on
all copies.
Permission is granted to process this file through Tex and print the
results, provided the printed document carries copying permission notice
identical to this one except for the removal of this paragraph (this
paragraph not being relevant to the printed manual).
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided also that the
GNU Copyright statement is available to the distributee, and provided that
the entire resulting derived work is distributed under the terms of a
permission notice identical to this one.
Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions.
@end ignore
@node Programming with GNU History
@chapter Programming with GNU History
This chapter describes how to interface programs that you write
with the @sc{gnu} History Library.
It should be considered a technical guide.
For information on the interactive use of @sc{gnu} History, @pxref{Using
History Interactively}.
@menu
* Introduction to History:: What is the GNU History library for?
* History Storage:: How information is stored.
* History Functions:: Functions that you can use.
* History Variables:: Variables that control behaviour.
* History Programming Example:: Example of using the GNU History Library.
@end menu
@node Introduction to History
@section Introduction to History
Many programs read input from the user a line at a time. The @sc{gnu}
History library is able to keep track of those lines, associate arbitrary
data with each line, and utilize information from previous lines in
composing new ones.
A programmer using the History library has available functions
for remembering lines on a history list, associating arbitrary data
with a line, removing lines from the list, searching through the list
for a line containing an arbitrary text string, and referencing any line
in the list directly. In addition, a history @dfn{expansion} function
is available which provides for a consistent user interface across
different programs.
The user using programs written with the History library has the
benefit of a consistent user interface with a set of well-known
commands for manipulating the text of previous lines and using that text
in new commands. The basic history manipulation commands are similar to
the history substitution provided by @code{csh}.
The programmer can also use the Readline library, which
includes some history manipulation by default, and has the added
advantage of command line editing.
Before declaring any functions using any functionality the History
library provides in other code, an application writer should include
the file @code{<readline/history.h>} in any file that uses the
History library's features. It supplies extern declarations for all
of the library's public functions and variables, and declares all of
the public data structures.
@node History Storage
@section History Storage
The history list is an array of history entries. A history entry is
declared as follows:
@example
typedef void *histdata_t;
typedef struct _hist_entry @{
char *line;
char *timestamp;
histdata_t data;
@} HIST_ENTRY;
@end example
The history list itself might therefore be declared as
@example
HIST_ENTRY **the_history_list;
@end example
The state of the History library is encapsulated into a single structure:
@example
/*
* A structure used to pass around the current state of the history.
*/
typedef struct _hist_state @{
HIST_ENTRY **entries; /* Pointer to the entries themselves. */
int offset; /* The location pointer within this array. */
int length; /* Number of elements within this array. */
int size; /* Number of slots allocated to this array. */
int flags;
@} HISTORY_STATE;
@end example
If the flags member includes @code{HS_STIFLED}, the history has been
stifled.
@node History Functions
@section History Functions
This section describes the calling sequence for the various functions
exported by the @sc{gnu} History library.
@menu
* Initializing History and State Management:: Functions to call when you
want to use history in a
program.
* History List Management:: Functions used to manage the list
of history entries.
* Information About the History List:: Functions returning information about
the history list.
* Moving Around the History List:: Functions used to change the position
in the history list.
* Searching the History List:: Functions to search the history list
for entries containing a string.
* Managing the History File:: Functions that read and write a file
containing the history list.
* History Expansion:: Functions to perform csh-like history
expansion.
@end menu
@node Initializing History and State Management
@subsection Initializing History and State Management
This section describes functions used to initialize and manage
the state of the History library when you want to use the history
functions in your program.
@deftypefun void using_history (void)
Begin a session in which the history functions might be used. This
initializes the interactive variables.
@end deftypefun
@deftypefun {HISTORY_STATE *} history_get_history_state (void)
Return a structure describing the current state of the input history.
@end deftypefun
@deftypefun void history_set_history_state (HISTORY_STATE *state)
Set the state of the history list according to @var{state}.
@end deftypefun
@node History List Management
@subsection History List Management
These functions manage individual entries on the history list, or set
parameters managing the list itself.
@deftypefun void add_history (const char *string)
Place @var{string} at the end of the history list. The associated data
field (if any) is set to @code{NULL}.
If the maximum number of history entries has been set using
@code{stifle_history()}, and the new number of history entries would exceed
that maximum, the oldest history entry is removed.
@end deftypefun
@deftypefun void add_history_time (const char *string)
Change the time stamp associated with the most recent history entry to
@var{string}.
@end deftypefun
@deftypefun {HIST_ENTRY *} remove_history (int which)
Remove history entry at offset @var{which} from the history. The
removed element is returned so you can free the line, data,
and containing structure.
@end deftypefun
@deftypefun {histdata_t} free_history_entry (HIST_ENTRY *histent)
Free the history entry @var{histent} and any history library private
data associated with it. Returns the application-specific data
so the caller can dispose of it.
@end deftypefun
@deftypefun {HIST_ENTRY *} replace_history_entry (int which, const char *line, histdata_t data)
Make the history entry at offset @var{which} have @var{line} and @var{data}.
This returns the old entry so the caller can dispose of any
application-specific data. In the case
of an invalid @var{which}, a @code{NULL} pointer is returned.
@end deftypefun
@deftypefun void clear_history (void)
Clear the history list by deleting all the entries.
@end deftypefun
@deftypefun void stifle_history (int max)
Stifle the history list, remembering only the last @var{max} entries.
The history list will contain only @var{max} entries at a time.
@end deftypefun
@deftypefun int unstifle_history (void)
Stop stifling the history. This returns the previously-set
maximum number of history entries (as set by @code{stifle_history()}).
The value is positive if the history was
stifled, negative if it wasn't.
@end deftypefun
@deftypefun int history_is_stifled (void)
Returns non-zero if the history is stifled, zero if it is not.
@end deftypefun
@node Information About the History List
@subsection Information About the History List
These functions return information about the entire history list or
individual list entries.
@deftypefun {HIST_ENTRY **} history_list (void)
Return a @code{NULL} terminated array of @code{HIST_ENTRY *} which is the
current input history. Element 0 of this list is the beginning of time.
If there is no history, return @code{NULL}.
@end deftypefun
@deftypefun int where_history (void)
Returns the offset of the current history element.
@end deftypefun
@deftypefun {HIST_ENTRY *} current_history (void)
Return the history entry at the current position, as determined by
@code{where_history()}. If there is no entry there, return a @code{NULL}
pointer.
@end deftypefun
@deftypefun {HIST_ENTRY *} history_get (int offset)
Return the history entry at position @var{offset}.
The range of valid
values of @var{offset} starts at @code{history_base} and ends at
@var{history_length} - 1 (@pxref{History Variables}).
If there is no entry there, or if @var{offset} is outside the valid
range, return a @code{NULL} pointer.
@end deftypefun
@deftypefun time_t history_get_time (HIST_ENTRY *entry)
Return the time stamp associated with the history entry @var{entry}.
If the timestamp is missing or invalid, return 0.
@end deftypefun
@deftypefun int history_total_bytes (void)
Return the number of bytes that the primary history entries are using.
This function returns the sum of the lengths of all the lines in the
history.
@end deftypefun
@node Moving Around the History List
@subsection Moving Around the History List
These functions allow the current index into the history list to be
set or changed.
@deftypefun int history_set_pos (int pos)
Set the current history offset to @var{pos}, an absolute index
into the list.
Returns 1 on success, 0 if @var{pos} is less than zero or greater
than the number of history entries.
@end deftypefun
@deftypefun {HIST_ENTRY *} previous_history (void)
Back up the current history offset to the previous history entry, and
return a pointer to that entry. If there is no previous entry, return
a @code{NULL} pointer.
@end deftypefun
@deftypefun {HIST_ENTRY *} next_history (void)
If the current history offset refers to a valid history entry,
increment the current history offset.
If the possibly-incremented history offset refers to a valid history
entry, return a pointer to that entry;
otherwise, return a @code{BNULL} pointer.
@end deftypefun
@node Searching the History List
@subsection Searching the History List
@cindex History Searching
These functions allow searching of the history list for entries containing
a specific string. Searching may be performed both forward and backward
from the current history position. The search may be @dfn{anchored},
meaning that the string must match at the beginning of the history entry.
@cindex anchored search
@deftypefun int history_search (const char *string, int direction)
Search the history for @var{string}, starting at the current history offset.
If @var{direction} is less than 0, then the search is through
previous entries, otherwise through subsequent entries.
If @var{string} is found, then
the current history index is set to that history entry, and the value
returned is the offset in the line of the entry where
@var{string} was found. Otherwise, nothing is changed, and a -1 is
returned.
@end deftypefun
@deftypefun int history_search_prefix (const char *string, int direction)
Search the history for @var{string}, starting at the current history
offset. The search is anchored: matching lines must begin with
@var{string}. If @var{direction} is less than 0, then the search is
through previous entries, otherwise through subsequent entries.
If @var{string} is found, then the
current history index is set to that entry, and the return value is 0.
Otherwise, nothing is changed, and a -1 is returned.
@end deftypefun
@deftypefun int history_search_pos (const char *string, int direction, int pos)
Search for @var{string} in the history list, starting at @var{pos}, an
absolute index into the list. If @var{direction} is negative, the search
proceeds backward from @var{pos}, otherwise forward. Returns the absolute
index of the history element where @var{string} was found, or -1 otherwise.
@end deftypefun
@node Managing the History File
@subsection Managing the History File
The History library can read the history from and write it to a file.
This section documents the functions for managing a history file.
@deftypefun int read_history (const char *filename)
Add the contents of @var{filename} to the history list, a line at a time.
If @var{filename} is @code{NULL}, then read from @file{~/.history}.
Returns 0 if successful, or @code{errno} if not.
@end deftypefun
@deftypefun int read_history_range (const char *filename, int from, int to)
Read a range of lines from @var{filename}, adding them to the history list.
Start reading at line @var{from} and end at @var{to}.
If @var{from} is zero, start at the beginning. If @var{to} is less than
@var{from}, then read until the end of the file. If @var{filename} is
@code{NULL}, then read from @file{~/.history}. Returns 0 if successful,
or @code{errno} if not.
@end deftypefun
@deftypefun int write_history (const char *filename)
Write the current history to @var{filename}, overwriting @var{filename}
if necessary.
If @var{filename} is @code{NULL}, then write the history list to
@file{~/.history}.
Returns 0 on success, or @code{errno} on a read or write error.
@end deftypefun
@deftypefun int append_history (int nelements, const char *filename)
Append the last @var{nelements} of the history list to @var{filename}.
If @var{filename} is @code{NULL}, then append to @file{~/.history}.
Returns 0 on success, or @code{errno} on a read or write error.
@end deftypefun
@deftypefun int history_truncate_file (const char *filename, int nlines)
Truncate the history file @var{filename}, leaving only the last
@var{nlines} lines.
If @var{filename} is @code{NULL}, then @file{~/.history} is truncated.
Returns 0 on success, or @code{errno} on failure.
@end deftypefun
@node History Expansion
@subsection History Expansion
These functions implement history expansion.
@deftypefun int history_expand (char *string, char **output)
Expand @var{string}, placing the result into @var{output}, a pointer
to a string (@pxref{History Interaction}). Returns:
@table @code
@item 0
If no expansions took place (or, if the only change in
the text was the removal of escape characters preceding the history expansion
character);
@item 1
if expansions did take place;
@item -1
if there was an error in expansion;
@item 2
if the returned line should be displayed, but not executed,
as with the @code{:p} modifier (@pxref{Modifiers}).
@end table
If an error occurred in expansion, then @var{output} contains a descriptive
error message.
@end deftypefun
@deftypefun {char *} get_history_event (const char *string, int *cindex, int qchar)
Returns the text of the history event beginning at @var{string} +
@var{*cindex}. @var{*cindex} is modified to point to after the event
specifier. At function entry, @var{cindex} points to the index into
@var{string} where the history event specification begins. @var{qchar}
is a character that is allowed to end the event specification in addition
to the ``normal'' terminating characters.
@end deftypefun
@deftypefun {char **} history_tokenize (const char *string)
Return an array of tokens parsed out of @var{string}, much as the
shell might. The tokens are split on the characters in the
@var{history_word_delimiters} variable,
and shell quoting conventions are obeyed as described below.
@end deftypefun
@deftypefun {char *} history_arg_extract (int first, int last, const char *string)
Extract a string segment consisting of the @var{first} through @var{last}
arguments present in @var{string}. Arguments are split using
@code{history_tokenize}.
@end deftypefun
@node History Variables
@section History Variables
This section describes the externally-visible variables exported by
the @sc{gnu} History Library.
@deftypevar int history_base
The logical offset of the first entry in the history list.
@end deftypevar
@deftypevar int history_length
The number of entries currently stored in the history list.
@end deftypevar
@deftypevar int history_max_entries
The maximum number of history entries. This must be changed using
@code{stifle_history()}.
@end deftypevar
@deftypevar int history_write_timestamps
If non-zero, timestamps are written to the history file, so they can be
preserved between sessions. The default value is 0, meaning that
timestamps are not saved.
The current timestamp format uses the value of @var{history_comment_char}
to delimit timestamp entries in the history file. If that variable does
not have a value (the default), timestamps will not be written.
@end deftypevar
@deftypevar char history_expansion_char
The character that introduces a history event. The default is @samp{!}.
Setting this to 0 inhibits history expansion.
@end deftypevar
@deftypevar char history_subst_char
The character that invokes word substitution if found at the start of
a line. The default is @samp{^}.
@end deftypevar
@deftypevar char history_comment_char
During tokenization, if this character is seen as the first character
of a word, then it and all subsequent characters up to a newline are
ignored, suppressing history expansion for the remainder of the line.
This is disabled by default.
@end deftypevar
@deftypevar {char *} history_word_delimiters
The characters that separate tokens for @code{history_tokenize()}.
The default value is @code{" \t\n()<>;&|"}.
@end deftypevar
@deftypevar {char *} history_search_delimiter_chars
The list of additional characters which can delimit a history search
string, in addition to space, TAB, @samp{:} and @samp{?} in the case of
a substring search. The default is empty.
@end deftypevar
@deftypevar {char *} history_no_expand_chars
The list of characters which inhibit history expansion if found immediately
following @var{history_expansion_char}. The default is space, tab, newline,
carriage return, and @samp{=}.
@end deftypevar
@deftypevar int history_quotes_inhibit_expansion
If non-zero, the history expansion code implements shell-like quoting:
single-quoted words are not scanned for the history expansion
character or the history comment character, and double-quoted words may
have history expansion performed, since single quotes are not special
within double quotes.
The default value is 0.
@end deftypevar
@deftypevar int history_quoting_state
An application may set this variable to indicate that the current line
being expanded is subject to existing quoting. If set to @samp{'}, the
history expansion function will assume that the line is single-quoted and
inhibit expansion until it reads an unquoted closing single quote; if set
to @samp{"}, history expansion will assume the line is double quoted until
it reads an unquoted closing double quote. If set to zero, the default,
the history expansion function will assume the line is not quoted and
treat quote characters within the line as described above.
This is only effective if @var{history_quotes_inhibit_expansion} is set.
@end deftypevar
@deftypevar {rl_linebuf_func_t *} history_inhibit_expansion_function
This should be set to the address of a function that takes two arguments:
a @code{char *} (@var{string})
and an @code{int} index into that string (@var{i}).
It should return a non-zero value if the history expansion starting at
@var{string[i]} should not be performed; zero if the expansion should
be done.
It is intended for use by applications like Bash that use the history
expansion character for additional purposes.
By default, this variable is set to @code{NULL}.
@end deftypevar
@node History Programming Example
@section History Programming Example
The following program demonstrates simple use of the @sc{gnu} History Library.
@smallexample
#include <stdio.h>
#include <readline/history.h>
main (argc, argv)
int argc;
char **argv;
@{
char line[1024], *t;
int len, done = 0;
line[0] = 0;
using_history ();
while (!done)
@{
printf ("history$ ");
fflush (stdout);
t = fgets (line, sizeof (line) - 1, stdin);
if (t && *t)
@{
len = strlen (t);
if (t[len - 1] == '\n')
t[len - 1] = '\0';
@}
if (!t)
strcpy (line, "quit");
if (line[0])
@{
char *expansion;
int result;
result = history_expand (line, &expansion);
if (result)
fprintf (stderr, "%s\n", expansion);
if (result < 0 || result == 2)
@{
free (expansion);
continue;
@}
add_history (expansion);
strncpy (line, expansion, sizeof (line) - 1);
free (expansion);
@}
if (strcmp (line, "quit") == 0)
done = 1;
else if (strcmp (line, "save") == 0)
write_history ("history_file");
else if (strcmp (line, "read") == 0)
read_history ("history_file");
else if (strcmp (line, "list") == 0)
@{
register HIST_ENTRY **the_list;
register int i;
the_list = history_list ();
if (the_list)
for (i = 0; the_list[i]; i++)
printf ("%d: %s\n", i + history_base, the_list[i]->line);
@}
else if (strncmp (line, "delete", 6) == 0)
@{
int which;
if ((sscanf (line + 6, "%d", &which)) == 1)
@{
HIST_ENTRY *entry = remove_history (which);
if (!entry)
fprintf (stderr, "No such entry %d\n", which);
else
@{
free (entry->line);
free (entry);
@}
@}
else
@{
fprintf (stderr, "non-numeric arg given to `delete'\n");
@}
@}
@}
@}
@end smallexample

View file

@ -0,0 +1,533 @@
@ignore
This file documents the user interface to the GNU History library.
Copyright (C) 1988--2022 Free Software Foundation, Inc.
Authored by Brian Fox and Chet Ramey.
Permission is granted to make and distribute verbatim copies of this manual
provided the copyright notice and this permission notice are preserved on
all copies.
Permission is granted to process this file through Tex and print the
results, provided the printed document carries copying permission notice
identical to this one except for the removal of this paragraph (this
paragraph not being relevant to the printed manual).
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided also that the
GNU Copyright statement is available to the distributee, and provided that
the entire resulting derived work is distributed under the terms of a
permission notice identical to this one.
Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions.
@end ignore
@node Using History Interactively
@chapter Using History Interactively
@ifclear BashFeatures
@defcodeindex bt
@end ifclear
@ifset BashFeatures
This chapter describes how to use the @sc{gnu} History Library
interactively, from a user's standpoint.
It should be considered a user's guide.
For information on using the @sc{gnu} History Library in other programs,
see the @sc{gnu} Readline Library Manual.
@end ifset
@ifclear BashFeatures
This chapter describes how to use the @sc{gnu} History Library interactively,
from a user's standpoint. It should be considered a user's guide. For
information on using the @sc{gnu} History Library in your own programs,
@pxref{Programming with GNU History}.
@end ifclear
@ifset BashFeatures
@menu
* Bash History Facilities:: How Bash lets you manipulate your command
history.
* Bash History Builtins:: The Bash builtin commands that manipulate
the command history.
* History Interaction:: What it feels like using History as a user.
@end menu
@end ifset
@ifclear BashFeatures
@menu
* History Interaction:: What it feels like using History as a user.
@end menu
@end ifclear
@ifset BashFeatures
@node Bash History Facilities
@section Bash History Facilities
@cindex command history
@cindex history list
When the @option{-o history} option to the @code{set} builtin
is enabled (@pxref{The Set Builtin}),
the shell provides access to the @dfn{command history},
the list of commands previously typed.
The value of the @env{HISTSIZE} shell variable is used as the
number of commands to save in a history list.
The text of the last @env{$HISTSIZE}
commands (default 500) is saved.
The shell stores each command in the history list prior to
parameter and variable expansion
but after history expansion is performed, subject to the
values of the shell variables
@env{HISTIGNORE} and @env{HISTCONTROL}.
When the shell starts up, the history is initialized from the
file named by the @env{HISTFILE} variable (default @file{~/.bash_history}).
The file named by the value of @env{HISTFILE} is truncated, if
necessary, to contain no more than the number of lines specified by
the value of the @env{HISTFILESIZE} variable.
When a shell with history enabled exits, the last
@env{$HISTSIZE} lines are copied from the history list to the file
named by @env{$HISTFILE}.
If the @code{histappend} shell option is set (@pxref{Bash Builtins}),
the lines are appended to the history file,
otherwise the history file is overwritten.
If @env{HISTFILE}
is unset, or if the history file is unwritable, the history is not saved.
After saving the history, the history file is truncated
to contain no more than @env{$HISTFILESIZE} lines.
If @env{HISTFILESIZE} is unset, or set to null, a non-numeric value, or
a numeric value less than zero, the history file is not truncated.
If the @env{HISTTIMEFORMAT} is set, the time stamp information
associated with each history entry is written to the history file,
marked with the history comment character.
When the history file is read, lines beginning with the history
comment character followed immediately by a digit are interpreted
as timestamps for the following history entry.
The builtin command @code{fc} may be used to list or edit and re-execute
a portion of the history list.
The @code{history} builtin may be used to display or modify the history
list and manipulate the history file.
When using command-line editing, search commands
are available in each editing mode that provide access to the
history list (@pxref{Commands For History}).
The shell allows control over which commands are saved on the history
list. The @env{HISTCONTROL} and @env{HISTIGNORE}
variables may be set to cause the shell to save only a subset of the
commands entered.
The @code{cmdhist}
shell option, if enabled, causes the shell to attempt to save each
line of a multi-line command in the same history entry, adding
semicolons where necessary to preserve syntactic correctness.
The @code{lithist}
shell option causes the shell to save the command with embedded newlines
instead of semicolons.
The @code{shopt} builtin is used to set these options.
@xref{The Shopt Builtin}, for a description of @code{shopt}.
@node Bash History Builtins
@section Bash History Builtins
@cindex history builtins
Bash provides two builtin commands which manipulate the
history list and history file.
@table @code
@item fc
@btindex fc
@example
@code{fc [-e @var{ename}] [-lnr] [@var{first}] [@var{last}]}
@code{fc -s [@var{pat}=@var{rep}] [@var{command}]}
@end example
The first form selects a range of commands from @var{first} to
@var{last} from the history list and displays or edits and re-executes
them.
Both @var{first} and
@var{last} may be specified as a string (to locate the most recent
command beginning with that string) or as a number (an index into the
history list, where a negative number is used as an offset from the
current command number).
When listing, a @var{first} or @var{last} of 0 is equivalent to -1
and -0 is equivalent to the current command (usually the @code{fc}
command);
otherwise 0 is equivalent to -1 and -0 is invalid.
If @var{last} is not specified, it is set to
@var{first}. If @var{first} is not specified, it is set to the previous
command for editing and @minus{}16 for listing. If the @option{-l} flag is
given, the commands are listed on standard output. The @option{-n} flag
suppresses the command numbers when listing. The @option{-r} flag
reverses the order of the listing. Otherwise, the editor given by
@var{ename} is invoked on a file containing those commands. If
@var{ename} is not given, the value of the following variable expansion
is used: @code{$@{FCEDIT:-$@{EDITOR:-vi@}@}}. This says to use the
value of the @env{FCEDIT} variable if set, or the value of the
@env{EDITOR} variable if that is set, or @code{vi} if neither is set.
When editing is complete, the edited commands are echoed and executed.
In the second form, @var{command} is re-executed after each instance
of @var{pat} in the selected command is replaced by @var{rep}.
@var{command} is interpreted the same as @var{first} above.
A useful alias to use with the @code{fc} command is @code{r='fc -s'}, so
that typing @samp{r cc} runs the last command beginning with @code{cc}
and typing @samp{r} re-executes the last command (@pxref{Aliases}).
@item history
@btindex history
@example
history [@var{n}]
history -c
history -d @var{offset}
history -d @var{start}-@var{end}
history [-anrw] [@var{filename}]
history -ps @var{arg}
@end example
With no options, display the history list with line numbers.
Lines prefixed with a @samp{*} have been modified.
An argument of @var{n} lists only the last @var{n} lines.
If the shell variable @env{HISTTIMEFORMAT} is set and not null,
it is used as a format string for @var{strftime} to display
the time stamp associated with each displayed history entry.
No intervening blank is printed between the formatted time stamp
and the history line.
Options, if supplied, have the following meanings:
@table @code
@item -c
Clear the history list. This may be combined
with the other options to replace the history list completely.
@item -d @var{offset}
Delete the history entry at position @var{offset}.
If @var{offset} is positive, it should be specified as it appears when
the history is displayed.
If @var{offset} is negative, it is interpreted as relative to one greater
than the last history position, so negative indices count back from the
end of the history, and an index of @samp{-1} refers to the current
@code{history -d} command.
@item -d @var{start}-@var{end}
Delete the range of history entries between positions @var{start} and
@var{end}, inclusive.
Positive and negative values for @var{start} and @var{end}
are interpreted as described above.
@item -a
Append the new history lines to the history file.
These are history lines entered since the beginning of the current
Bash session, but not already appended to the history file.
@item -n
Append the history lines not already read from the history file
to the current history list. These are lines appended to the history
file since the beginning of the current Bash session.
@item -r
Read the history file and append its contents to
the history list.
@item -w
Write out the current history list to the history file.
@item -p
Perform history substitution on the @var{arg}s and display the result
on the standard output, without storing the results in the history list.
@item -s
The @var{arg}s are added to the end of
the history list as a single entry.
@end table
If a @var{filename} argument is supplied
when any of the @option{-w}, @option{-r}, @option{-a}, or @option{-n} options
is used, Bash uses @var{filename} as the history file.
If not, then the value of the @env{HISTFILE} variable is used.
The return value is 0 unless an invalid option is encountered, an
error occurs while reading or writing the history file, an invalid
@var{offset} or range is supplied as an argument to @option{-d}, or the
history expansion supplied as an argument to @option{-p} fails.
@end table
@end ifset
@node History Interaction
@section History Expansion
@cindex history expansion
The History library provides a history expansion feature that is similar
to the history expansion provided by @code{csh}. This section
describes the syntax used to manipulate the history information.
History expansions introduce words from the history list into
the input stream, making it easy to repeat commands, insert the
arguments to a previous command into the current input line, or
fix errors in previous commands quickly.
@ifset BashFeatures
History expansion is performed immediately after a complete line
is read, before the shell breaks it into words, and is performed
on each line individually. Bash attempts to inform the history
expansion functions about quoting still in effect from previous lines.
@end ifset
History expansion takes place in two parts. The first is to determine
which line from the history list should be used during substitution.
The second is to select portions of that line for inclusion into the
current one. The line selected from the history is called the
@dfn{event}, and the portions of that line that are acted upon are
called @dfn{words}. Various @dfn{modifiers} are available to manipulate
the selected words. The line is broken into words in the same fashion
that Bash does, so that several words
surrounded by quotes are considered one word.
History expansions are introduced by the appearance of the
history expansion character, which is @samp{!} by default.
History expansion implements shell-like quoting conventions:
a backslash can be used to remove the special handling for the next character;
single quotes enclose verbatim sequences of characters, and can be used to
inhibit history expansion;
and characters enclosed within double quotes may be subject to history
expansion, since backslash can escape the history expansion character,
but single quotes may not, since they are not treated specially within
double quotes.
@ifset BashFeatures
When using the shell, only @samp{\} and @samp{'} may be used to escape the
history expansion character, but the history expansion character is
also treated as quoted if it immediately precedes the closing double quote
in a double-quoted string.
@end ifset
@ifset BashFeatures
Several shell options settable with the @code{shopt}
builtin (@pxref{The Shopt Builtin}) may be used to tailor
the behavior of history expansion. If the
@code{histverify} shell option is enabled, and Readline
is being used, history substitutions are not immediately passed to
the shell parser.
Instead, the expanded line is reloaded into the Readline
editing buffer for further modification.
If Readline is being used, and the @code{histreedit}
shell option is enabled, a failed history expansion will be
reloaded into the Readline editing buffer for correction.
The @option{-p} option to the @code{history} builtin command
may be used to see what a history expansion will do before using it.
The @option{-s} option to the @code{history} builtin may be used to
add commands to the end of the history list without actually executing
them, so that they are available for subsequent recall.
This is most useful in conjunction with Readline.
The shell allows control of the various characters used by the
history expansion mechanism with the @code{histchars} variable,
as explained above (@pxref{Bash Variables}). The shell uses
the history comment character to mark history timestamps when
writing the history file.
@end ifset
@menu
* Event Designators:: How to specify which history line to use.
* Word Designators:: Specifying which words are of interest.
* Modifiers:: Modifying the results of substitution.
@end menu
@node Event Designators
@subsection Event Designators
@cindex event designators
An event designator is a reference to a command line entry in the
history list.
Unless the reference is absolute, events are relative to the current
position in the history list.
@cindex history events
@table @asis
@item @code{!}
@ifset BashFeatures
Start a history substitution, except when followed by a space, tab,
the end of the line, @samp{=} or @samp{(} (when the
@code{extglob} shell option is enabled using the @code{shopt} builtin).
@end ifset
@ifclear BashFeatures
Start a history substitution, except when followed by a space, tab,
the end of the line, or @samp{=}.
@end ifclear
@item @code{!@var{n}}
Refer to command line @var{n}.
@item @code{!-@var{n}}
Refer to the command @var{n} lines back.
@item @code{!!}
Refer to the previous command. This is a synonym for @samp{!-1}.
@item @code{!@var{string}}
Refer to the most recent command
preceding the current position in the history list
starting with @var{string}.
@item @code{!?@var{string}[?]}
Refer to the most recent command
preceding the current position in the history list
containing @var{string}.
The trailing
@samp{?} may be omitted if the @var{string} is followed immediately by
a newline.
If @var{string} is missing, the string from the most recent search is used;
it is an error if there is no previous search string.
@item @code{^@var{string1}^@var{string2}^}
Quick Substitution. Repeat the last command, replacing @var{string1}
with @var{string2}. Equivalent to
@code{!!:s^@var{string1}^@var{string2}^}.
@item @code{!#}
The entire command line typed so far.
@end table
@node Word Designators
@subsection Word Designators
Word designators are used to select desired words from the event.
A @samp{:} separates the event specification from the word designator. It
may be omitted if the word designator begins with a @samp{^}, @samp{$},
@samp{*}, @samp{-}, or @samp{%}. Words are numbered from the beginning
of the line, with the first word being denoted by 0 (zero). Words are
inserted into the current line separated by single spaces.
@need 0.75
For example,
@table @code
@item !!
designates the preceding command. When you type this, the preceding
command is repeated in toto.
@item !!:$
designates the last argument of the preceding command. This may be
shortened to @code{!$}.
@item !fi:2
designates the second argument of the most recent command starting with
the letters @code{fi}.
@end table
@need 0.75
Here are the word designators:
@table @code
@item 0 (zero)
The @code{0}th word. For many applications, this is the command word.
@item @var{n}
The @var{n}th word.
@item ^
The first argument; that is, word 1.
@item $
The last argument.
@item %
The first word matched by the most recent @samp{?@var{string}?} search,
if the search string begins with a character that is part of a word.
@item @var{x}-@var{y}
A range of words; @samp{-@var{y}} abbreviates @samp{0-@var{y}}.
@item *
All of the words, except the @code{0}th. This is a synonym for @samp{1-$}.
It is not an error to use @samp{*} if there is just one word in the event;
the empty string is returned in that case.
@item @var{x}*
Abbreviates @samp{@var{x}-$}
@item @var{x}-
Abbreviates @samp{@var{x}-$} like @samp{@var{x}*}, but omits the last word.
If @samp{x} is missing, it defaults to 0.
@end table
If a word designator is supplied without an event specification, the
previous command is used as the event.
@node Modifiers
@subsection Modifiers
After the optional word designator, you can add a sequence of one or more
of the following modifiers, each preceded by a @samp{:}.
These modify, or edit, the word or words selected from the history event.
@table @code
@item h
Remove a trailing pathname component, leaving only the head.
@item t
Remove all leading pathname components, leaving the tail.
@item r
Remove a trailing suffix of the form @samp{.@var{suffix}}, leaving
the basename.
@item e
Remove all but the trailing suffix.
@item p
Print the new command but do not execute it.
@ifset BashFeatures
@item q
Quote the substituted words, escaping further substitutions.
@item x
Quote the substituted words as with @samp{q},
but break into words at spaces, tabs, and newlines.
The @samp{q} and @samp{x} modifiers are mutually exclusive; the last one
supplied is used.
@end ifset
@item s/@var{old}/@var{new}/
Substitute @var{new} for the first occurrence of @var{old} in the
event line.
Any character may be used as the delimiter in place of @samp{/}.
The delimiter may be quoted in @var{old} and @var{new}
with a single backslash. If @samp{&} appears in @var{new},
it is replaced by @var{old}. A single backslash will quote
the @samp{&}.
If @var{old} is null, it is set to the last @var{old}
substituted, or, if no previous history substitutions took place,
the last @var{string}
in a !?@var{string}@code{[?]}
search.
If @var{new} is null, each matching @var{old} is deleted.
The final delimiter is optional if it is the last
character on the input line.
@item &
Repeat the previous substitution.
@item g
@itemx a
Cause changes to be applied over the entire event line. Used in
conjunction with @samp{s}, as in @code{gs/@var{old}/@var{new}/},
or with @samp{&}.
@item G
Apply the following @samp{s} or @samp{&} modifier once to each word
in the event.
@end table

View file

@ -0,0 +1,84 @@
\input texinfo @c -*-texinfo-*-
@comment %**start of header (This is for running Texinfo on a region.)
@setfilename readline.info
@settitle GNU Readline Library
@include version.texi
@comment %**end of header (This is for running Texinfo on a region.)
@synindex vr fn
@copying
This manual describes the GNU Readline Library
(version @value{VERSION}, @value{UPDATED}), a library which aids in the
consistency of user interface across discrete programs which provide
a command line interface.
Copyright @copyright{} 1988--2022 Free Software Foundation, Inc.
@quotation
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
A copy of the license is included in the section entitled
``GNU Free Documentation License''.
@end quotation
@end copying
@dircategory Libraries
@direntry
* Readline: (readline). The GNU readline library API.
@end direntry
@titlepage
@title GNU Readline Library
@subtitle Edition @value{EDITION}, for @code{Readline Library} Version @value{VERSION}.
@subtitle @value{UPDATED-MONTH}
@author Chet Ramey, Case Western Reserve University
@author Brian Fox, Free Software Foundation
@page
@vskip 0pt plus 1filll
@insertcopying
@end titlepage
@contents
@ifnottex
@node Top
@top GNU Readline Library
This document describes the GNU Readline Library, a utility which aids
in the consistency of user interface across discrete programs which
provide a command line interface.
The Readline home page is @url{http://www.gnu.org/software/readline/}.
@menu
* Command Line Editing:: GNU Readline User's Manual.
* Programming with GNU Readline:: GNU Readline Programmer's Manual.
* GNU Free Documentation License:: License for copying this manual.
* Concept Index:: Index of concepts described in this manual.
* Function and Variable Index:: Index of externally visible functions
and variables.
@end menu
@end ifnottex
@include rluser.texi
@include rltech.texi
@node GNU Free Documentation License
@appendix GNU Free Documentation License
@include fdl.texi
@node Concept Index
@unnumbered Concept Index
@printindex cp
@node Function and Variable Index
@unnumbered Function and Variable Index
@printindex fn
@bye

2815
lib/readline/doc/rltech.texi Normal file

File diff suppressed because it is too large Load diff

2488
lib/readline/doc/rluser.texi Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,70 @@
\input texinfo @c -*-texinfo-*-
@comment %**start of header (This is for running Texinfo on a region.)
@setfilename rluserman.info
@settitle GNU Readline Library
@include version.texi
@comment %**end of header (This is for running Texinfo on a region.)
@copying
This manual describes the end user interface of the GNU Readline Library
(version @value{VERSION}, @value{UPDATED}), a library which aids in the
consistency of user interface across discrete programs which provide
a command line interface.
Copyright @copyright{} 1988--2022 Free Software Foundation, Inc.
@quotation
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
A copy of the license is included in the section entitled
``GNU Free Documentation License''.
@end quotation
@end copying
@dircategory Libraries
@direntry
* RLuserman: (rluserman). The GNU readline library User's Manual.
@end direntry
@titlepage
@title GNU Readline Library User Interface
@subtitle Edition @value{EDITION}, for @code{Readline Library} Version @value{VERSION}.
@subtitle @value{UPDATED-MONTH}
@author Chet Ramey, Case Western Reserve University
@author Brian Fox, Free Software Foundation
@page
@vskip 0pt plus 1filll
@insertcopying
@end titlepage
@contents
@ifnottex
@node Top
@top GNU Readline Library
This document describes the end user interface of the GNU Readline Library,
a utility which aids in the consistency of user interface across discrete
programs which provide a command line interface.
The Readline home page is @url{http://www.gnu.org/software/readline/}.
@menu
* Command Line Editing:: GNU Readline User's Manual.
* GNU Free Documentation License:: License for copying this manual.
@end menu
@end ifnottex
@include rluser.texi
@node GNU Free Documentation License
@appendix GNU Free Documentation License
@include fdl.texi
@bye

View file

@ -0,0 +1,11 @@
@ignore
Copyright (C) 1988-2022 Free Software Foundation, Inc.
@end ignore
@set EDITION 8.2
@set VERSION 8.2
@set UPDATED 19 September 2022
@set UPDATED-MONTH September 2022
@set LASTCHANGE Mon Sep 19 11:15:16 EDT 2022

872
lib/readline/emacs_keymap.c Normal file
View file

@ -0,0 +1,872 @@
/* emacs_keymap.c -- the keymap for emacs_mode in readline (). */
/* Copyright (C) 1987-2017 Free Software Foundation, Inc.
This file is part of the GNU Readline Library (Readline), a library
for reading lines of text with interactive input and history editing.
Readline 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.
Readline 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 Readline. If not, see <http://www.gnu.org/licenses/>.
*/
#if !defined (BUFSIZ)
#include <stdio.h>
#endif /* !BUFSIZ */
#include "readline.h"
/* An array of function pointers, one for each possible key.
If the type byte is ISKMAP, then the pointer is the address of
a keymap. */
KEYMAP_ENTRY_ARRAY emacs_standard_keymap = {
/* Control keys. */
{ ISFUNC, rl_set_mark }, /* Control-@ */
{ ISFUNC, rl_beg_of_line }, /* Control-a */
{ ISFUNC, rl_backward_char }, /* Control-b */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Control-c */
{ ISFUNC, rl_delete }, /* Control-d */
{ ISFUNC, rl_end_of_line }, /* Control-e */
{ ISFUNC, rl_forward_char }, /* Control-f */
{ ISFUNC, rl_abort }, /* Control-g */
{ ISFUNC, rl_rubout }, /* Control-h */
{ ISFUNC, rl_complete }, /* Control-i */
{ ISFUNC, rl_newline }, /* Control-j */
{ ISFUNC, rl_kill_line }, /* Control-k */
{ ISFUNC, rl_clear_screen }, /* Control-l */
{ ISFUNC, rl_newline }, /* Control-m */
{ ISFUNC, rl_get_next_history }, /* Control-n */
{ ISFUNC, rl_operate_and_get_next }, /* Control-o */
{ ISFUNC, rl_get_previous_history }, /* Control-p */
{ ISFUNC, rl_quoted_insert }, /* Control-q */
{ ISFUNC, rl_reverse_search_history }, /* Control-r */
{ ISFUNC, rl_forward_search_history }, /* Control-s */
{ ISFUNC, rl_transpose_chars }, /* Control-t */
{ ISFUNC, rl_unix_line_discard }, /* Control-u */
{ ISFUNC, rl_quoted_insert }, /* Control-v */
{ ISFUNC, rl_unix_word_rubout }, /* Control-w */
{ ISKMAP, (rl_command_func_t *)emacs_ctlx_keymap }, /* Control-x */
{ ISFUNC, rl_yank }, /* Control-y */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Control-z */
{ ISKMAP, (rl_command_func_t *)emacs_meta_keymap }, /* Control-[ */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Control-\ */
{ ISFUNC, rl_char_search }, /* Control-] */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Control-^ */
{ ISFUNC, rl_undo_command }, /* Control-_ */
/* The start of printing characters. */
{ ISFUNC, rl_insert }, /* SPACE */
{ ISFUNC, rl_insert }, /* ! */
{ ISFUNC, rl_insert }, /* " */
{ ISFUNC, rl_insert }, /* # */
{ ISFUNC, rl_insert }, /* $ */
{ ISFUNC, rl_insert }, /* % */
{ ISFUNC, rl_insert }, /* & */
{ ISFUNC, rl_insert }, /* ' */
{ ISFUNC, rl_insert }, /* ( */
{ ISFUNC, rl_insert }, /* ) */
{ ISFUNC, rl_insert }, /* * */
{ ISFUNC, rl_insert }, /* + */
{ ISFUNC, rl_insert }, /* , */
{ ISFUNC, rl_insert }, /* - */
{ ISFUNC, rl_insert }, /* . */
{ ISFUNC, rl_insert }, /* / */
/* Regular digits. */
{ ISFUNC, rl_insert }, /* 0 */
{ ISFUNC, rl_insert }, /* 1 */
{ ISFUNC, rl_insert }, /* 2 */
{ ISFUNC, rl_insert }, /* 3 */
{ ISFUNC, rl_insert }, /* 4 */
{ ISFUNC, rl_insert }, /* 5 */
{ ISFUNC, rl_insert }, /* 6 */
{ ISFUNC, rl_insert }, /* 7 */
{ ISFUNC, rl_insert }, /* 8 */
{ ISFUNC, rl_insert }, /* 9 */
/* A little more punctuation. */
{ ISFUNC, rl_insert }, /* : */
{ ISFUNC, rl_insert }, /* ; */
{ ISFUNC, rl_insert }, /* < */
{ ISFUNC, rl_insert }, /* = */
{ ISFUNC, rl_insert }, /* > */
{ ISFUNC, rl_insert }, /* ? */
{ ISFUNC, rl_insert }, /* @ */
/* Uppercase alphabet. */
{ ISFUNC, rl_insert }, /* A */
{ ISFUNC, rl_insert }, /* B */
{ ISFUNC, rl_insert }, /* C */
{ ISFUNC, rl_insert }, /* D */
{ ISFUNC, rl_insert }, /* E */
{ ISFUNC, rl_insert }, /* F */
{ ISFUNC, rl_insert }, /* G */
{ ISFUNC, rl_insert }, /* H */
{ ISFUNC, rl_insert }, /* I */
{ ISFUNC, rl_insert }, /* J */
{ ISFUNC, rl_insert }, /* K */
{ ISFUNC, rl_insert }, /* L */
{ ISFUNC, rl_insert }, /* M */
{ ISFUNC, rl_insert }, /* N */
{ ISFUNC, rl_insert }, /* O */
{ ISFUNC, rl_insert }, /* P */
{ ISFUNC, rl_insert }, /* Q */
{ ISFUNC, rl_insert }, /* R */
{ ISFUNC, rl_insert }, /* S */
{ ISFUNC, rl_insert }, /* T */
{ ISFUNC, rl_insert }, /* U */
{ ISFUNC, rl_insert }, /* V */
{ ISFUNC, rl_insert }, /* W */
{ ISFUNC, rl_insert }, /* X */
{ ISFUNC, rl_insert }, /* Y */
{ ISFUNC, rl_insert }, /* Z */
/* Some more punctuation. */
{ ISFUNC, rl_insert }, /* [ */
{ ISFUNC, rl_insert }, /* \ */
{ ISFUNC, rl_insert }, /* ] */
{ ISFUNC, rl_insert }, /* ^ */
{ ISFUNC, rl_insert }, /* _ */
{ ISFUNC, rl_insert }, /* ` */
/* Lowercase alphabet. */
{ ISFUNC, rl_insert }, /* a */
{ ISFUNC, rl_insert }, /* b */
{ ISFUNC, rl_insert }, /* c */
{ ISFUNC, rl_insert }, /* d */
{ ISFUNC, rl_insert }, /* e */
{ ISFUNC, rl_insert }, /* f */
{ ISFUNC, rl_insert }, /* g */
{ ISFUNC, rl_insert }, /* h */
{ ISFUNC, rl_insert }, /* i */
{ ISFUNC, rl_insert }, /* j */
{ ISFUNC, rl_insert }, /* k */
{ ISFUNC, rl_insert }, /* l */
{ ISFUNC, rl_insert }, /* m */
{ ISFUNC, rl_insert }, /* n */
{ ISFUNC, rl_insert }, /* o */
{ ISFUNC, rl_insert }, /* p */
{ ISFUNC, rl_insert }, /* q */
{ ISFUNC, rl_insert }, /* r */
{ ISFUNC, rl_insert }, /* s */
{ ISFUNC, rl_insert }, /* t */
{ ISFUNC, rl_insert }, /* u */
{ ISFUNC, rl_insert }, /* v */
{ ISFUNC, rl_insert }, /* w */
{ ISFUNC, rl_insert }, /* x */
{ ISFUNC, rl_insert }, /* y */
{ ISFUNC, rl_insert }, /* z */
/* Final punctuation. */
{ ISFUNC, rl_insert }, /* { */
{ ISFUNC, rl_insert }, /* | */
{ ISFUNC, rl_insert }, /* } */
{ ISFUNC, rl_insert }, /* ~ */
{ ISFUNC, rl_rubout }, /* RUBOUT */
#if KEYMAP_SIZE > 128
/* Pure 8-bit characters (128 - 159).
These might be used in some
character sets. */
{ ISFUNC, rl_insert }, /* ? */
{ ISFUNC, rl_insert }, /* ? */
{ ISFUNC, rl_insert }, /* ? */
{ ISFUNC, rl_insert }, /* ? */
{ ISFUNC, rl_insert }, /* ? */
{ ISFUNC, rl_insert }, /* ? */
{ ISFUNC, rl_insert }, /* ? */
{ ISFUNC, rl_insert }, /* ? */
{ ISFUNC, rl_insert }, /* ? */
{ ISFUNC, rl_insert }, /* ? */
{ ISFUNC, rl_insert }, /* ? */
{ ISFUNC, rl_insert }, /* ? */
{ ISFUNC, rl_insert }, /* ? */
{ ISFUNC, rl_insert }, /* ? */
{ ISFUNC, rl_insert }, /* ? */
{ ISFUNC, rl_insert }, /* ? */
{ ISFUNC, rl_insert }, /* ? */
{ ISFUNC, rl_insert }, /* ? */
{ ISFUNC, rl_insert }, /* ? */
{ ISFUNC, rl_insert }, /* ? */
{ ISFUNC, rl_insert }, /* ? */
{ ISFUNC, rl_insert }, /* ? */
{ ISFUNC, rl_insert }, /* ? */
{ ISFUNC, rl_insert }, /* ? */
{ ISFUNC, rl_insert }, /* ? */
{ ISFUNC, rl_insert }, /* ? */
{ ISFUNC, rl_insert }, /* ? */
{ ISFUNC, rl_insert }, /* ? */
{ ISFUNC, rl_insert }, /* ? */
{ ISFUNC, rl_insert }, /* ? */
{ ISFUNC, rl_insert }, /* ? */
{ ISFUNC, rl_insert }, /* ? */
/* ISO Latin-1 characters (160 - 255) */
{ ISFUNC, rl_insert }, /* No-break space */
{ ISFUNC, rl_insert }, /* Inverted exclamation mark */
{ ISFUNC, rl_insert }, /* Cent sign */
{ ISFUNC, rl_insert }, /* Pound sign */
{ ISFUNC, rl_insert }, /* Currency sign */
{ ISFUNC, rl_insert }, /* Yen sign */
{ ISFUNC, rl_insert }, /* Broken bar */
{ ISFUNC, rl_insert }, /* Section sign */
{ ISFUNC, rl_insert }, /* Diaeresis */
{ ISFUNC, rl_insert }, /* Copyright sign */
{ ISFUNC, rl_insert }, /* Feminine ordinal indicator */
{ ISFUNC, rl_insert }, /* Left pointing double angle quotation mark */
{ ISFUNC, rl_insert }, /* Not sign */
{ ISFUNC, rl_insert }, /* Soft hyphen */
{ ISFUNC, rl_insert }, /* Registered sign */
{ ISFUNC, rl_insert }, /* Macron */
{ ISFUNC, rl_insert }, /* Degree sign */
{ ISFUNC, rl_insert }, /* Plus-minus sign */
{ ISFUNC, rl_insert }, /* Superscript two */
{ ISFUNC, rl_insert }, /* Superscript three */
{ ISFUNC, rl_insert }, /* Acute accent */
{ ISFUNC, rl_insert }, /* Micro sign */
{ ISFUNC, rl_insert }, /* Pilcrow sign */
{ ISFUNC, rl_insert }, /* Middle dot */
{ ISFUNC, rl_insert }, /* Cedilla */
{ ISFUNC, rl_insert }, /* Superscript one */
{ ISFUNC, rl_insert }, /* Masculine ordinal indicator */
{ ISFUNC, rl_insert }, /* Right pointing double angle quotation mark */
{ ISFUNC, rl_insert }, /* Vulgar fraction one quarter */
{ ISFUNC, rl_insert }, /* Vulgar fraction one half */
{ ISFUNC, rl_insert }, /* Vulgar fraction three quarters */
{ ISFUNC, rl_insert }, /* Inverted questionk mark */
{ ISFUNC, rl_insert }, /* Latin capital letter a with grave */
{ ISFUNC, rl_insert }, /* Latin capital letter a with acute */
{ ISFUNC, rl_insert }, /* Latin capital letter a with circumflex */
{ ISFUNC, rl_insert }, /* Latin capital letter a with tilde */
{ ISFUNC, rl_insert }, /* Latin capital letter a with diaeresis */
{ ISFUNC, rl_insert }, /* Latin capital letter a with ring above */
{ ISFUNC, rl_insert }, /* Latin capital letter ae */
{ ISFUNC, rl_insert }, /* Latin capital letter c with cedilla */
{ ISFUNC, rl_insert }, /* Latin capital letter e with grave */
{ ISFUNC, rl_insert }, /* Latin capital letter e with acute */
{ ISFUNC, rl_insert }, /* Latin capital letter e with circumflex */
{ ISFUNC, rl_insert }, /* Latin capital letter e with diaeresis */
{ ISFUNC, rl_insert }, /* Latin capital letter i with grave */
{ ISFUNC, rl_insert }, /* Latin capital letter i with acute */
{ ISFUNC, rl_insert }, /* Latin capital letter i with circumflex */
{ ISFUNC, rl_insert }, /* Latin capital letter i with diaeresis */
{ ISFUNC, rl_insert }, /* Latin capital letter eth (Icelandic) */
{ ISFUNC, rl_insert }, /* Latin capital letter n with tilde */
{ ISFUNC, rl_insert }, /* Latin capital letter o with grave */
{ ISFUNC, rl_insert }, /* Latin capital letter o with acute */
{ ISFUNC, rl_insert }, /* Latin capital letter o with circumflex */
{ ISFUNC, rl_insert }, /* Latin capital letter o with tilde */
{ ISFUNC, rl_insert }, /* Latin capital letter o with diaeresis */
{ ISFUNC, rl_insert }, /* Multiplication sign */
{ ISFUNC, rl_insert }, /* Latin capital letter o with stroke */
{ ISFUNC, rl_insert }, /* Latin capital letter u with grave */
{ ISFUNC, rl_insert }, /* Latin capital letter u with acute */
{ ISFUNC, rl_insert }, /* Latin capital letter u with circumflex */
{ ISFUNC, rl_insert }, /* Latin capital letter u with diaeresis */
{ ISFUNC, rl_insert }, /* Latin capital letter Y with acute */
{ ISFUNC, rl_insert }, /* Latin capital letter thorn (Icelandic) */
{ ISFUNC, rl_insert }, /* Latin small letter sharp s (German) */
{ ISFUNC, rl_insert }, /* Latin small letter a with grave */
{ ISFUNC, rl_insert }, /* Latin small letter a with acute */
{ ISFUNC, rl_insert }, /* Latin small letter a with circumflex */
{ ISFUNC, rl_insert }, /* Latin small letter a with tilde */
{ ISFUNC, rl_insert }, /* Latin small letter a with diaeresis */
{ ISFUNC, rl_insert }, /* Latin small letter a with ring above */
{ ISFUNC, rl_insert }, /* Latin small letter ae */
{ ISFUNC, rl_insert }, /* Latin small letter c with cedilla */
{ ISFUNC, rl_insert }, /* Latin small letter e with grave */
{ ISFUNC, rl_insert }, /* Latin small letter e with acute */
{ ISFUNC, rl_insert }, /* Latin small letter e with circumflex */
{ ISFUNC, rl_insert }, /* Latin small letter e with diaeresis */
{ ISFUNC, rl_insert }, /* Latin small letter i with grave */
{ ISFUNC, rl_insert }, /* Latin small letter i with acute */
{ ISFUNC, rl_insert }, /* Latin small letter i with circumflex */
{ ISFUNC, rl_insert }, /* Latin small letter i with diaeresis */
{ ISFUNC, rl_insert }, /* Latin small letter eth (Icelandic) */
{ ISFUNC, rl_insert }, /* Latin small letter n with tilde */
{ ISFUNC, rl_insert }, /* Latin small letter o with grave */
{ ISFUNC, rl_insert }, /* Latin small letter o with acute */
{ ISFUNC, rl_insert }, /* Latin small letter o with circumflex */
{ ISFUNC, rl_insert }, /* Latin small letter o with tilde */
{ ISFUNC, rl_insert }, /* Latin small letter o with diaeresis */
{ ISFUNC, rl_insert }, /* Division sign */
{ ISFUNC, rl_insert }, /* Latin small letter o with stroke */
{ ISFUNC, rl_insert }, /* Latin small letter u with grave */
{ ISFUNC, rl_insert }, /* Latin small letter u with acute */
{ ISFUNC, rl_insert }, /* Latin small letter u with circumflex */
{ ISFUNC, rl_insert }, /* Latin small letter u with diaeresis */
{ ISFUNC, rl_insert }, /* Latin small letter y with acute */
{ ISFUNC, rl_insert }, /* Latin small letter thorn (Icelandic) */
{ ISFUNC, rl_insert } /* Latin small letter y with diaeresis */
#endif /* KEYMAP_SIZE > 128 */
};
KEYMAP_ENTRY_ARRAY emacs_meta_keymap = {
/* Meta keys. Just like above, but the high bit is set. */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-Control-@ */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-Control-a */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-Control-b */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-Control-c */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-Control-d */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-Control-e */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-Control-f */
{ ISFUNC, rl_abort }, /* Meta-Control-g */
{ ISFUNC, rl_backward_kill_word }, /* Meta-Control-h */
{ ISFUNC, rl_tab_insert }, /* Meta-Control-i */
{ ISFUNC, rl_vi_editing_mode }, /* Meta-Control-j */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-Control-k */
{ ISFUNC, rl_clear_display }, /* Meta-Control-l */
{ ISFUNC, rl_vi_editing_mode }, /* Meta-Control-m */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-Control-n */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-Control-o */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-Control-p */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-Control-q */
{ ISFUNC, rl_revert_line }, /* Meta-Control-r */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-Control-s */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-Control-t */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-Control-u */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-Control-v */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-Control-w */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-Control-x */
{ ISFUNC, rl_yank_nth_arg }, /* Meta-Control-y */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-Control-z */
{ ISFUNC, rl_complete }, /* Meta-Control-[ */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-Control-\ */
{ ISFUNC, rl_backward_char_search }, /* Meta-Control-] */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-Control-^ */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-Control-_ */
/* The start of printing characters. */
{ ISFUNC, rl_set_mark }, /* Meta-SPACE */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-! */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-" */
{ ISFUNC, rl_insert_comment }, /* Meta-# */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-$ */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-% */
{ ISFUNC, rl_tilde_expand }, /* Meta-& */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-' */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-( */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-) */
{ ISFUNC, rl_insert_completions }, /* Meta-* */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-+ */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-, */
{ ISFUNC, rl_digit_argument }, /* Meta-- */
{ ISFUNC, rl_yank_last_arg}, /* Meta-. */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-/ */
/* Regular digits. */
{ ISFUNC, rl_digit_argument }, /* Meta-0 */
{ ISFUNC, rl_digit_argument }, /* Meta-1 */
{ ISFUNC, rl_digit_argument }, /* Meta-2 */
{ ISFUNC, rl_digit_argument }, /* Meta-3 */
{ ISFUNC, rl_digit_argument }, /* Meta-4 */
{ ISFUNC, rl_digit_argument }, /* Meta-5 */
{ ISFUNC, rl_digit_argument }, /* Meta-6 */
{ ISFUNC, rl_digit_argument }, /* Meta-7 */
{ ISFUNC, rl_digit_argument }, /* Meta-8 */
{ ISFUNC, rl_digit_argument }, /* Meta-9 */
/* A little more punctuation. */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-: */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-; */
{ ISFUNC, rl_beginning_of_history }, /* Meta-< */
{ ISFUNC, rl_possible_completions }, /* Meta-= */
{ ISFUNC, rl_end_of_history }, /* Meta-> */
{ ISFUNC, rl_possible_completions }, /* Meta-? */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-@ */
/* Uppercase alphabet. */
{ ISFUNC, rl_do_lowercase_version }, /* Meta-A */
{ ISFUNC, rl_do_lowercase_version }, /* Meta-B */
{ ISFUNC, rl_do_lowercase_version }, /* Meta-C */
{ ISFUNC, rl_do_lowercase_version }, /* Meta-D */
{ ISFUNC, rl_do_lowercase_version }, /* Meta-E */
{ ISFUNC, rl_do_lowercase_version }, /* Meta-F */
{ ISFUNC, rl_do_lowercase_version }, /* Meta-G */
{ ISFUNC, rl_do_lowercase_version }, /* Meta-H */
{ ISFUNC, rl_do_lowercase_version }, /* Meta-I */
{ ISFUNC, rl_do_lowercase_version }, /* Meta-J */
{ ISFUNC, rl_do_lowercase_version }, /* Meta-K */
{ ISFUNC, rl_do_lowercase_version }, /* Meta-L */
{ ISFUNC, rl_do_lowercase_version }, /* Meta-M */
{ ISFUNC, rl_do_lowercase_version }, /* Meta-N */
{ ISFUNC, rl_do_lowercase_version }, /* Meta-O */
{ ISFUNC, rl_do_lowercase_version }, /* Meta-P */
{ ISFUNC, rl_do_lowercase_version }, /* Meta-Q */
{ ISFUNC, rl_do_lowercase_version }, /* Meta-R */
{ ISFUNC, rl_do_lowercase_version }, /* Meta-S */
{ ISFUNC, rl_do_lowercase_version }, /* Meta-T */
{ ISFUNC, rl_do_lowercase_version }, /* Meta-U */
{ ISFUNC, rl_do_lowercase_version }, /* Meta-V */
{ ISFUNC, rl_do_lowercase_version }, /* Meta-W */
{ ISFUNC, rl_do_lowercase_version }, /* Meta-X */
{ ISFUNC, rl_do_lowercase_version }, /* Meta-Y */
{ ISFUNC, rl_do_lowercase_version }, /* Meta-Z */
/* Some more punctuation. */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-[ */ /* was rl_arrow_keys */
{ ISFUNC, rl_delete_horizontal_space }, /* Meta-\ */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-] */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-^ */
{ ISFUNC, rl_yank_last_arg }, /* Meta-_ */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-` */
/* Lowercase alphabet. */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-a */
{ ISFUNC, rl_backward_word }, /* Meta-b */
{ ISFUNC, rl_capitalize_word }, /* Meta-c */
{ ISFUNC, rl_kill_word }, /* Meta-d */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-e */
{ ISFUNC, rl_forward_word }, /* Meta-f */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-g */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-h */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-i */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-j */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-k */
{ ISFUNC, rl_downcase_word }, /* Meta-l */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-m */
{ ISFUNC, rl_noninc_forward_search }, /* Meta-n */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-o */ /* was rl_arrow_keys */
{ ISFUNC, rl_noninc_reverse_search }, /* Meta-p */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-q */
{ ISFUNC, rl_revert_line }, /* Meta-r */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-s */
{ ISFUNC, rl_transpose_words }, /* Meta-t */
{ ISFUNC, rl_upcase_word }, /* Meta-u */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-v */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-w */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-x */
{ ISFUNC, rl_yank_pop }, /* Meta-y */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-z */
/* Final punctuation. */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-{ */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-| */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Meta-} */
{ ISFUNC, rl_tilde_expand }, /* Meta-~ */
{ ISFUNC, rl_backward_kill_word }, /* Meta-rubout */
#if KEYMAP_SIZE > 128
/* Undefined keys. */
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 }
#endif /* KEYMAP_SIZE > 128 */
};
KEYMAP_ENTRY_ARRAY emacs_ctlx_keymap = {
/* Control keys. */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Control-@ */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Control-a */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Control-b */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Control-c */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Control-d */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Control-e */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Control-f */
{ ISFUNC, rl_abort }, /* Control-g */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Control-h */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Control-i */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Control-j */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Control-k */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Control-l */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Control-m */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Control-n */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Control-o */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Control-p */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Control-q */
{ ISFUNC, rl_re_read_init_file }, /* Control-r */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Control-s */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Control-t */
{ ISFUNC, rl_undo_command }, /* Control-u */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Control-v */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Control-w */
{ ISFUNC, rl_exchange_point_and_mark }, /* Control-x */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Control-y */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Control-z */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Control-[ */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Control-\ */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Control-] */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Control-^ */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* Control-_ */
/* The start of printing characters. */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* SPACE */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* ! */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* " */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* # */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* $ */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* % */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* & */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* ' */
{ ISFUNC, rl_start_kbd_macro }, /* ( */
{ ISFUNC, rl_end_kbd_macro }, /* ) */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* * */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* + */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* , */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* - */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* . */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* / */
/* Regular digits. */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* 0 */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* 1 */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* 2 */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* 3 */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* 4 */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* 5 */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* 6 */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* 7 */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* 8 */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* 9 */
/* A little more punctuation. */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* : */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* ; */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* < */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* = */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* > */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* ? */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* @ */
/* Uppercase alphabet. */
{ ISFUNC, rl_do_lowercase_version }, /* A */
{ ISFUNC, rl_do_lowercase_version }, /* B */
{ ISFUNC, rl_do_lowercase_version }, /* C */
{ ISFUNC, rl_do_lowercase_version }, /* D */
{ ISFUNC, rl_do_lowercase_version }, /* E */
{ ISFUNC, rl_do_lowercase_version }, /* F */
{ ISFUNC, rl_do_lowercase_version }, /* G */
{ ISFUNC, rl_do_lowercase_version }, /* H */
{ ISFUNC, rl_do_lowercase_version }, /* I */
{ ISFUNC, rl_do_lowercase_version }, /* J */
{ ISFUNC, rl_do_lowercase_version }, /* K */
{ ISFUNC, rl_do_lowercase_version }, /* L */
{ ISFUNC, rl_do_lowercase_version }, /* M */
{ ISFUNC, rl_do_lowercase_version }, /* N */
{ ISFUNC, rl_do_lowercase_version }, /* O */
{ ISFUNC, rl_do_lowercase_version }, /* P */
{ ISFUNC, rl_do_lowercase_version }, /* Q */
{ ISFUNC, rl_do_lowercase_version }, /* R */
{ ISFUNC, rl_do_lowercase_version }, /* S */
{ ISFUNC, rl_do_lowercase_version }, /* T */
{ ISFUNC, rl_do_lowercase_version }, /* U */
{ ISFUNC, rl_do_lowercase_version }, /* V */
{ ISFUNC, rl_do_lowercase_version }, /* W */
{ ISFUNC, rl_do_lowercase_version }, /* X */
{ ISFUNC, rl_do_lowercase_version }, /* Y */
{ ISFUNC, rl_do_lowercase_version }, /* Z */
/* Some more punctuation. */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* [ */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* \ */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* ] */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* ^ */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* _ */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* ` */
/* Lowercase alphabet. */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* a */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* b */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* c */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* d */
{ ISFUNC, rl_call_last_kbd_macro }, /* e */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* f */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* g */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* h */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* i */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* j */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* k */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* l */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* m */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* n */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* o */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* p */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* q */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* r */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* s */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* t */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* u */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* v */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* w */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* x */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* y */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* z */
/* Final punctuation. */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* { */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* | */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* } */
{ ISFUNC, (rl_command_func_t *)0x0 }, /* ~ */
{ ISFUNC, rl_backward_kill_line }, /* RUBOUT */
#if KEYMAP_SIZE > 128
/* Undefined keys. */
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 },
{ ISFUNC, (rl_command_func_t *)0x0 }
#endif /* KEYMAP_SIZE > 128 */
};

View file

@ -0,0 +1,81 @@
# 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.
#
# Copyright (C) 1989-2009 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
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
#
# 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
# alternate arrow key prefix
"\eOA": previous-history
"\eOB": next-history
"\eOC": forward-char
"\eOD": 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-?"
"\M-.": yank-last-arg
$endif
" ": self-insert

Some files were not shown because too many files have changed in this diff Show more