aboutsummaryrefslogtreecommitdiffstats
path: root/lib/tilde
diff options
context:
space:
mode:
authorJari Aalto <jari.aalto@cante.net>1996-12-23 17:02:34 +0000
committerJari Aalto <jari.aalto@cante.net>2009-09-12 16:46:49 +0000
commitccc6cda312fea9f0468ee65b8f368e9653e1380b (patch)
treeb059878adcfd876c4acb8030deda1eeb918c7e75 /lib/tilde
parent726f63884db0132f01745f1fb4465e6621088ccf (diff)
downloadandroid_external_bash-ccc6cda312fea9f0468ee65b8f368e9653e1380b.tar.gz
android_external_bash-ccc6cda312fea9f0468ee65b8f368e9653e1380b.tar.bz2
android_external_bash-ccc6cda312fea9f0468ee65b8f368e9653e1380b.zip
Imported from ../bash-2.0.tar.gz.
Diffstat (limited to 'lib/tilde')
-rw-r--r--lib/tilde/Makefile98
-rw-r--r--lib/tilde/Makefile.in98
-rw-r--r--lib/tilde/doc/Makefile6
-rw-r--r--lib/tilde/memalloc.h56
-rw-r--r--lib/tilde/tilde.c152
-rw-r--r--lib/tilde/tilde.h31
6 files changed, 208 insertions, 233 deletions
diff --git a/lib/tilde/Makefile b/lib/tilde/Makefile
deleted file mode 100644
index 50b4285..0000000
--- a/lib/tilde/Makefile
+++ /dev/null
@@ -1,98 +0,0 @@
-## -*- text -*- ####################################################
-# #
-# Makefile for the GNU Tilde Library. #
-# #
-####################################################################
-
-# This Makefile is hand made from a template file, found in
-# ../template. Each library must provide several Makefile
-# targets: `all', `clean', `documentation', `install', and
-# `what-tar'. The `what-tar' target reports the names of the
-# files that need to be included in a tarfile to build the full
-# code and documentation for this library.
-
-# Please note that the values for INCLUDES, CC, AR, RM, CP,
-# RANLIB, and selfdir are passed in from ../Makefile, and do
-# not need to be defined here.
-RM = rm -f
-MV = mv
-CP = cp
-
-srcdir = .
-VPATH = .:$(srcdir)
-
-# 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:
- $(CC) -c $(CFLAGS) $(INCLUDES) $(LOCAL_DEFINES) $(CPPFLAGS) $<
-
-# LOCAL_DEFINES are flags that are specific to this library.
-# Define -DUSG if you are using a System V operating system.
-LOCAL_DEFINES = $(LOCAL_INCLUDES) #-DUSG
-
-# For libraries which include headers from other libraries.
-LOCAL_INCLUDES = -I..
-
-# The name of the library target.
-LIBRARY_NAME = libtilde.a
-
-# The C code source files for this library.
-CSOURCES = $(srcdir)/tilde.c
-
-# The header files for this library.
-HSOURCES = $(srcdir)/tilde.h
-
-OBJECTS = tilde.o
-
-# The texinfo files which document this library.
-DOCSOURCE = doc/tilde.texi
-DOCOBJECT = doc/tilde.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) $@
- $(AR) cq $@ $(OBJECTS)
- -[ -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:
- -$(MV) $(bindir)/$(LIBRARY_NAME) $(bindir)/$(LIBRARY_NAME)-old
- $(CP) $(LIBRARY_NAME) $(bindir)/$(LIBRARY_NAME)
- -[ -n "$(RANLIB)" ] && $(RANLIB) -t $(bindir)/$(LIBRARY_NAME)
-
-clean:
- $(RM) $(OBJECTS) $(LIBRARY_NAME)
- -(cd doc && $(MAKE) $(MFLAGS) $@)
-
-maintainer-clean realclean mostlyclean distclean: clean
-
-
-######################################################################
-# #
-# Dependencies for the object files which make up this library. #
-# #
-######################################################################
-
-tilde.o: tilde.h tilde.c
diff --git a/lib/tilde/Makefile.in b/lib/tilde/Makefile.in
new file mode 100644
index 0000000..acecee3
--- /dev/null
+++ b/lib/tilde/Makefile.in
@@ -0,0 +1,98 @@
+## -*- text -*- ####################################################
+# #
+# Makefile for the GNU Tilde Library. #
+# #
+####################################################################
+
+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@
+RM = rm
+CP = cp
+MV = mv
+
+CFLAGS = @CFLAGS@ @LOCAL_CFLAGS@
+CPPFLAGS = @CPPFLAGS@
+LDFLAGS = @LDFLAGS@ @LOCAL_LDFLAGS@
+
+DEFS = @DEFS@
+
+INCLUDES = -I. -I../.. -I$(topdir) -I$(topdir)/lib
+
+CCFLAGS = $(CFLAGS) $(DEFS) $(CPPFLAGS) ${INCLUDES}
+
+.c.o:
+ $(CC) -c $(CCFLAGS) $<
+
+# The name of the library target.
+LIBRARY_NAME = libtilde.a
+
+# The C code source files for this library.
+CSOURCES = $(srcdir)/tilde.c
+
+# The header files for this library.
+HSOURCES = $(srcdir)/tilde.h
+
+OBJECTS = tilde.o
+
+# The texinfo files which document this library.
+DOCSOURCE = doc/tilde.texi
+DOCOBJECT = doc/tilde.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) cr $@ $(OBJECTS)
+ -test -n "$(RANLIB)" && $(RANLIB) $@
+
+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:
+ $(INSTALL_DATA) -c -m 644 $(LIBRARY_NAME) $(bindir)/$(LIBRARY_NAME)
+ -test -n "$(RANLIB)" && $(RANLIB) -t $(bindir)/$(LIBRARY_NAME)
+
+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) $@ )
+
+######################################################################
+# #
+# Dependencies for the object files which make up this library. #
+# #
+######################################################################
+
+tilde.o: tilde.h tilde.c
+tilde.o: $(BUILD_DIR)/config.h
diff --git a/lib/tilde/doc/Makefile b/lib/tilde/doc/Makefile
index 4e158bf..a2246db 100644
--- a/lib/tilde/doc/Makefile
+++ b/lib/tilde/doc/Makefile
@@ -1,5 +1,5 @@
+clean distclean mostlyclean maintainer-clean:
+ rm -f tilde.??
+
all:
cp tilde.texi tilde.info
-
-clean realclean maintainer-clean:
- rm -f tilde.?? tilde.info
diff --git a/lib/tilde/memalloc.h b/lib/tilde/memalloc.h
deleted file mode 100644
index 750d53d..0000000
--- a/lib/tilde/memalloc.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/* memalloc.h -- consolidate code for including alloca.h or malloc.h and
- defining alloca. */
-
-/* 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 2, or (at your option) any later
- version.
-
- Bash is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- for more details.
-
- You should have received a copy of the GNU General Public License along
- with Bash; see the file COPYING. If not, write to the Free Software
- Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
-
-#if !defined (__MEMALLOC_H__)
-# define __MEMALLOC_H__
-
-#if defined (sparc) && defined (sun) && !defined (HAVE_ALLOCA_H)
-# define HAVE_ALLOCA_H
-#endif
-
-#if defined (__GNUC__) && !defined (HAVE_ALLOCA)
-# define HAVE_ALLOCA
-#endif
-
-#if defined (HAVE_ALLOCA_H) && !defined (HAVE_ALLOCA)
-# define HAVE_ALLOCA
-#endif /* HAVE_ALLOCA_H && !HAVE_ALLOCA */
-
-#if !defined (BUILDING_MAKEFILE)
-
-#if defined (__GNUC__)
-# undef alloca
-# define alloca __builtin_alloca
-#else /* !__GNUC__ */
-# if defined (HAVE_ALLOCA_H)
-# if defined (IBMESA)
-# include <malloc.h>
-# else /* !IBMESA */
-# include <alloca.h>
-# endif /* !IBMESA */
-# else
-extern char *alloca ();
-# endif /* !HAVE_ALLOCA_H */
-#endif /* !__GNUC__ */
-
-#endif /* !BUILDING_MAKEFILE */
-
-#endif /* __MEMALLOC_H__ */
diff --git a/lib/tilde/tilde.c b/lib/tilde/tilde.c
index da75d95..69f5768 100644
--- a/lib/tilde/tilde.c
+++ b/lib/tilde/tilde.c
@@ -19,6 +19,10 @@
along with Readline; see the file COPYING. If not, write to the Free
Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
+#if defined (HAVE_CONFIG_H)
+# include <config.h>
+#endif
+
#if defined (HAVE_STRING_H)
# include <string.h>
#else /* !HAVE_STRING_H */
@@ -31,13 +35,14 @@
# include "ansi_stdlib.h"
#endif /* HAVE_STDLIB_H */
-#include "tilde.h"
#include <sys/types.h>
#include <pwd.h>
-#if defined (USG) && !defined (HAVE_GETPW_DECLS)
+#include "tilde.h"
+
+#if !defined (HAVE_GETPW_DECLS)
extern struct passwd *getpwuid (), *getpwnam ();
-#endif /* USG && !defined (HAVE_GETPW_DECLS) */
+#endif /* !HAVE_GETPW_DECLS */
#if !defined (savestring)
extern char *xmalloc ();
@@ -171,7 +176,7 @@ tilde_expand (string)
/* Copy the skipped text into the result. */
if ((result_index + start + 1) > result_size)
- result = (char *)xrealloc (result, 1 + (result_size += (start + 20)));
+ result = xrealloc (result, 1 + (result_size += (start + 20)));
strncpy (result + result_index, string, start);
result_index += start;
@@ -188,7 +193,7 @@ tilde_expand (string)
break;
/* Expand the entire tilde word, and copy it into RESULT. */
- tilde_word = (char *)xmalloc (1 + end);
+ tilde_word = xmalloc (1 + end);
strncpy (tilde_word, string, end);
tilde_word[end] = '\0';
string += end;
@@ -198,7 +203,7 @@ tilde_expand (string)
len = strlen (expansion);
if ((result_index + len + 1) > result_size)
- result = (char *)xrealloc (result, 1 + (result_size += (len + 20)));
+ result = xrealloc (result, 1 + (result_size += (len + 20)));
strcpy (result + result_index, expansion);
result_index += len;
@@ -217,85 +222,90 @@ tilde_expand_word (filename)
char *filename;
{
char *dirname;
+ char *temp_name;
- dirname = filename ? savestring (filename) : (char *)NULL;
+ if (filename == (char *)0)
+ return ((char *)NULL);
- if (dirname && *dirname == '~')
+ dirname = savestring (filename);
+
+ if (*dirname != '~')
+ return (dirname);
+
+ if (!dirname[1] || dirname[1] == '/')
{
- char *temp_name;
- if (!dirname[1] || dirname[1] == '/')
+ /* Prepend $HOME to the rest of the string. */
+ char *temp_home = (char *)getenv ("HOME");
+ int home_len;
+
+ /* If there is no HOME variable, look up the directory in
+ the password database. */
+ if (!temp_home)
{
- /* Prepend $HOME to the rest of the string. */
- char *temp_home = (char *)getenv ("HOME");
+ struct passwd *entry;
- /* If there is no HOME variable, look up the directory in
- the password database. */
- if (!temp_home)
- {
- struct passwd *entry;
+ entry = getpwuid (getuid ());
+ if (entry)
+ temp_home = entry->pw_dir;
+ }
- entry = getpwuid (getuid ());
- if (entry)
- temp_home = entry->pw_dir;
- }
+ home_len = temp_home ? strlen (temp_home) : 0;
+ temp_name = xmalloc (1 + strlen (dirname + 1) + home_len);
+
+ if (temp_home)
+ strcpy (temp_name, temp_home);
+ strcpy (temp_name + home_len, dirname + 1);
+ free (dirname);
+ dirname = temp_name;
+ }
+ else
+ {
+ char *username;
+ struct passwd *user_entry;
+ int i, len;
- temp_name = xmalloc (1 + strlen (&dirname[1])
- + (temp_home ? strlen (temp_home) : 0));
- temp_name[0] = '\0';
- if (temp_home)
- strcpy (temp_name, temp_home);
- strcat (temp_name, dirname + 1);
- free (dirname);
- dirname = temp_name;
- }
- else
+ username = xmalloc (strlen (dirname));
+ for (i = 1; dirname[i] && dirname[i] != '/'; i++)
+ username[i - 1] = dirname[i];
+ username[i - 1] = '\0';
+
+ if ((user_entry = getpwnam (username)) == (struct passwd *)0)
{
- char *username;
- struct passwd *user_entry;
- int i;
+ /* If the calling program has a special syntax for
+ expanding tildes, and we couldn't find a standard
+ expansion, then let them try. */
+ if (tilde_expansion_failure_hook)
+ {
+ char *expansion;
- username = xmalloc (strlen (dirname));
- for (i = 1; dirname[i] && dirname[i] != '/'; i++)
- username[i - 1] = dirname[i];
- username[i - 1] = '\0';
+ expansion = (*tilde_expansion_failure_hook) (username);
- if ((user_entry = getpwnam (username)) == 0)
- {
- /* If the calling program has a special syntax for
- expanding tildes, and we couldn't find a standard
- expansion, then let them try. */
- if (tilde_expansion_failure_hook)
+ if (expansion)
{
- char *expansion;
-
- expansion = (*tilde_expansion_failure_hook) (username);
-
- if (expansion)
- {
- temp_name = xmalloc (1 + strlen (expansion)
- + strlen (&dirname[i]));
- strcpy (temp_name, expansion);
- strcat (temp_name, &dirname[i]);
- free (expansion);
- free (dirname);
- dirname = temp_name;
- }
+ len = strlen (expansion);
+ temp_name = xmalloc (1 + len + strlen (dirname + i));
+ strcpy (temp_name, expansion);
+ strcpy (temp_name + len, dirname + i);
+ free (expansion);
+ free (dirname);
+ dirname = temp_name;
}
- /* We shouldn't report errors. */
- }
- else
- {
- temp_name = xmalloc (1 + strlen (user_entry->pw_dir)
- + strlen (&dirname[i]));
- strcpy (temp_name, user_entry->pw_dir);
- strcat (temp_name, &dirname[i]);
- free (dirname);
- dirname = temp_name;
}
- endpwent ();
- free (username);
+ /* We shouldn't report errors. */
}
+ else
+ {
+ len = strlen (user_entry->pw_dir);
+ temp_name = xmalloc (1 + len + strlen (dirname + i));
+ strcpy (temp_name, user_entry->pw_dir);
+ strcpy (temp_name + len, dirname + i);
+ free (dirname);
+ dirname = temp_name;
+ }
+ endpwent ();
+ free (username);
}
+
return (dirname);
}
@@ -368,7 +378,7 @@ xrealloc (pointer, bytes)
static void
memory_error_and_abort ()
{
- fprintf (stderr, "readline: Out of virtual memory!\n");
+ fprintf (stderr, "readline: out of virtual memory\n");
abort ();
}
diff --git a/lib/tilde/tilde.h b/lib/tilde/tilde.h
index 726d081..6f0898c 100644
--- a/lib/tilde/tilde.h
+++ b/lib/tilde/tilde.h
@@ -1,11 +1,32 @@
/* tilde.h: Externally available variables and function in libtilde.a. */
-#if !defined (__TILDE_H__)
-# define __TILDE_H__
+/* Copyright (C) 1992 Free Software Foundation, Inc.
+
+ This file contains the Readline Library (the Library), a set of
+ routines for providing Emacs style line input to programs that ask
+ for it.
+
+ The Library 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 1, or (at your option)
+ any later version.
+
+ The Library 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.
+
+ The GNU General Public License is often shipped with GNU software, and
+ is generally kept in a file called COPYING or LICENSE. If you do not
+ have a copy of the license, write to the Free Software Foundation,
+ 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#if !defined (_TILDE_H_)
+# define _TILDE_H_
/* Function pointers can be declared as (Function *)foo. */
-#if !defined (__FUNCTION_DEF)
-# define __FUNCTION_DEF
+#if !defined (_FUNCTION_DEF)
+# define _FUNCTION_DEF
typedef int Function ();
typedef void VFunction ();
typedef char *CPFunction ();
@@ -35,4 +56,4 @@ extern char *tilde_expand ();
tilde. If there is no expansion, call tilde_expansion_failure_hook. */
extern char *tilde_expand_word ();
-#endif /* __TILDE_H__ */
+#endif /* _TILDE_H_ */