aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorJari Aalto <jari.aalto@cante.net>2002-07-17 14:10:11 +0000
committerJari Aalto <jari.aalto@cante.net>2009-09-12 16:46:55 +0000
commit7117c2d221b2aed4ede8600f6a36b7c1454b4f55 (patch)
treeb792f26ecca68813c51ed5ba2e381790758ef31b /include
parentf73dda092b33638d2d5e9c35375f687a607b5403 (diff)
downloadandroid_external_bash-7117c2d221b2aed4ede8600f6a36b7c1454b4f55.tar.gz
android_external_bash-7117c2d221b2aed4ede8600f6a36b7c1454b4f55.tar.bz2
android_external_bash-7117c2d221b2aed4ede8600f6a36b7c1454b4f55.zip
Imported from ../bash-2.05b.tar.gz.
Diffstat (limited to 'include')
-rw-r--r--include/chartypes.h24
-rw-r--r--include/ocache.h133
-rw-r--r--include/posixdir.h8
-rw-r--r--include/shmbutil.h347
-rw-r--r--include/stdc.h16
5 files changed, 512 insertions, 16 deletions
diff --git a/include/chartypes.h b/include/chartypes.h
index d19b7f6..4f47b99 100644
--- a/include/chartypes.h
+++ b/include/chartypes.h
@@ -82,6 +82,8 @@
#define DIGIT(c) ((c) >= '0' && (c) <= '9')
+#define ISWORD(c) (ISLETTER(c) || DIGIT(c) || ((c) == '_'))
+
#define HEXVALUE(c) \
(((c) >= 'a' && (c) <= 'f') \
? (c)-'a'+10 \
@@ -98,22 +100,14 @@
#define TOLOWER(c) (ISUPPER(c) ? tolower(c) : (c))
#define TOUPPER(c) (ISLOWER(c) ? toupper(c) : (c))
-#ifdef toascii
-# define TOASCII(c) (toascii(c))
-#else
-# define TOASCII(c) ((c) & 0x7F)
+#ifndef TOCTRL
+ /* letter to control char -- ASCII. The TOUPPER is in there so \ce and
+ \cE will map to the same character in $'...' expansions. */
+# define TOCTRL(x) (TOUPPER(x) & 037)
#endif
-
-/* We remove any previous definition of `SIGN_EXTEND_CHAR',
- since ours (we hope) works properly with all combinations of
- machines, compilers, `char' and `unsigned char' argument types.
- (Per Bothner suggested the basic approach.) */
-#undef SIGN_EXTEND_CHAR
-#if __STDC__
-# define SIGN_EXTEND_CHAR(c) ((signed char) (c))
-#else /* not __STDC__ */
- /* As in Harbison and Steele. */
-# define SIGN_EXTEND_CHAR(c) ((((unsigned char) (c)) ^ 128) - 128)
+#ifndef UNCTRL
+ /* control char to letter -- ASCII */
+# define UNCTRL(x) (TOUPPER((x) | 0x40))
#endif
#endif /* _SH_CHARTYPES_H */
diff --git a/include/ocache.h b/include/ocache.h
new file mode 100644
index 0000000..67448c3
--- /dev/null
+++ b/include/ocache.h
@@ -0,0 +1,133 @@
+/* ocache.h -- a minimal object caching implementation. */
+
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+
+ This file is part of GNU Bash, the Bourne Again SHell.
+
+ Bash is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2, or (at your option) any later
+ version.
+
+ Bash is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with Bash; see the file COPYING. If not, write to the Free Software
+ Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
+
+#if !defined (_OCACHE_H_)
+#define _OCACHE_H_ 1
+
+#ifndef PTR_T
+
+#if defined (__STDC__)
+# define PTR_T void *
+#else
+# define PTR_T char *
+#endif
+
+#endif /* PTR_T */
+
+#define OC_MEMSET(memp, xch, nbytes) \
+do { \
+ if ((nbytes) <= 32) { \
+ register char * mzp = (char *)(memp); \
+ 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 ((memp), (xch), (nbytes)); \
+} while(0)
+
+typedef struct objcache {
+ PTR_T data;
+ int cs; /* cache size, number of objects */
+ int nc; /* number of cache entries */
+} sh_obj_cache_t;
+
+/* Create an object cache C of N pointers to OTYPE. */
+#define ocache_create(c, otype, n) \
+ do { \
+ (c).data = xmalloc((n) * sizeof (otype *)); \
+ (c).cs = (n); \
+ (c).nc = 0; \
+ } while (0)
+
+/* Destroy an object cache C. */
+#define ocache_destroy(c) \
+ do { \
+ if ((c).data) \
+ xfree ((c).data); \
+ (c).data = 0; \
+ (c).cs = (c).nc = 0; \
+ } while (0)
+
+/* Free all cached items, which are pointers to OTYPE, in object cache C. */
+#define ocache_flush(c, otype) \
+ do { \
+ while ((c).nc > 0) \
+ xfree (((otype **)((c).data))[--(c).nc]); \
+ } while (0)
+
+/*
+ * Allocate a new item of type pointer to OTYPE, using data from object
+ * cache C if any cached items exist, otherwise calling xmalloc. Return
+ * the object in R.
+ */
+#define ocache_alloc(c, otype, r) \
+ do { \
+ if ((c).nc > 0) { \
+ (r) = (otype *)((otype **)((c).data))[--(c).nc]; \
+ } else \
+ (r) = (otype *)xmalloc (sizeof (otype)); \
+ } while (0)
+
+/*
+ * Free an item R of type pointer to OTYPE, adding to object cache C if
+ * there is room and calling xfree if the cache is full. If R is added
+ * to the object cache, the contents are scrambled.
+ */
+#define ocache_free(c, otype, r) \
+ do { \
+ if ((c).nc < (c).cs) { \
+ OC_MEMSET ((r), 0xdf, sizeof(otype)); \
+ ((otype **)((c).data))[(c).nc++] = (r); \
+ } else \
+ xfree (r); \
+ } while (0)
+
+/*
+ * One may declare and use an object cache as (for instance):
+ *
+ * sh_obj_cache_t wdcache = {0, 0, 0};
+ * sh_obj_cache_t wlcache = {0, 0, 0};
+ *
+ * ocache_create(wdcache, WORD_DESC, 30);
+ * ocache_create(wlcache, WORD_LIST, 30);
+ *
+ * WORD_DESC *wd;
+ * ocache_alloc (wdcache, WORD_DESC, wd);
+ *
+ * WORD_LIST *wl;
+ * ocache_alloc (wlcache, WORD_LIST, wl);
+ *
+ * ocache_free(wdcache, WORD_DESC, wd);
+ * ocache_free(wlcache, WORD_LIST, wl);
+ *
+ * The use is almost arbitrary.
+ */
+
+#endif /* _OCACHE_H */
diff --git a/include/posixdir.h b/include/posixdir.h
index 98ced75..505e279 100644
--- a/include/posixdir.h
+++ b/include/posixdir.h
@@ -46,4 +46,12 @@
# define d_fileno d_ino
#endif
+#if defined (_POSIX_SOURCE) && (!defined (STRUCT_DIRENT_HAS_D_INO) || defined (BROKEN_DIRENT_D_INO))
+/* Posix does not require that the d_ino field be present, and some
+ systems do not provide it. */
+# define REAL_DIR_ENTRY(dp) 1
+#else
+# define REAL_DIR_ENTRY(dp) (dp->d_ino != 0)
+#endif /* _POSIX_SOURCE */
+
#endif /* !_POSIXDIR_H_ */
diff --git a/include/shmbutil.h b/include/shmbutil.h
new file mode 100644
index 0000000..7fe2f8e
--- /dev/null
+++ b/include/shmbutil.h
@@ -0,0 +1,347 @@
+/* shmbutil.h -- utility functions for multibyte characters. */
+
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+
+ This file is part of GNU Bash, the Bourne Again SHell.
+
+ Bash is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2, or (at your option) any later
+ version.
+
+ Bash is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with Bash; see the file COPYING. If not, write to the Free Software
+ Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
+
+#if !defined (_SH_MBUTIL_H_)
+#define _SH_MBUTIL_H_
+
+#include "stdc.h"
+
+/************************************************/
+/* check multibyte capability for I18N code */
+/************************************************/
+
+/* For platforms which support the ISO C amendement 1 functionality we
+ support user defined character classes. */
+ /* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>. */
+#if defined (HAVE_WCTYPE_H) && defined (HAVE_WCHAR_H)
+# include <wchar.h>
+# include <wctype.h>
+# if defined (HAVE_MBSRTOWCS) /* system is supposed to support XPG5 */
+# define HANDLE_MULTIBYTE 1
+# endif
+#endif /* HAVE_WCTYPE_H && HAVE_WCHAR_H */
+
+/* Some systems, like BeOS, have multibyte encodings but lack mbstate_t. */
+#if HANDLE_MULTIBYTE && !defined (HAVE_MBSTATE_T)
+# define wcsrtombs(dest, src, len, ps) (wcsrtombs) (dest, src, len, 0)
+# define mbsrtowcs(dest, src, len, ps) (mbsrtowcs) (dest, src, len, 0)
+# define wcrtomb(s, wc, ps) (wcrtomb) (s, wc, 0)
+# define mbrtowc(pwc, s, n, ps) (mbrtowc) (pwc, s, n, 0)
+# define mbrlen(s, n, ps) (mbrlen) (s, n, 0)
+# define mbstate_t int
+#endif /* HANDLE_MULTIBYTE && !HAVE_MBSTATE_T */
+
+/* Make sure MB_LEN_MAX is at least 16 on systems that claim to be able to
+ handle multibyte chars (some systems define MB_LEN_MAX as 1) */
+#ifdef HANDLE_MULTIBYTE
+# include <limits.h>
+# if defined(MB_LEN_MAX) && (MB_LEN_MAX < 16)
+# undef MB_LEN_MAX
+# endif
+# if !defined (MB_LEN_MAX)
+# define MB_LEN_MAX 16
+# endif
+#endif /* HANDLE_MULTIBYTE */
+
+/************************************************/
+/* end of multibyte capability checks for I18N */
+/************************************************/
+
+#if defined (HANDLE_MULTIBYTE)
+
+extern size_t xmbsrtowcs __P((wchar_t *, const char **, size_t, mbstate_t *));
+
+extern char *xstrchr __P((const char *, int));
+
+#else /* !HANDLE_MULTIBYTE */
+
+#undef MB_LEN_MAX
+#undef MB_CUR_MAX
+
+#define MB_LEN_MAX 1
+#define MB_CUR_MAX 1
+
+#undef xstrchr
+#define xstrchr(s, c) strchr(s, c)
+
+#endif /* !HANDLE_MULTIBYTE */
+
+/* Declare and initialize a multibyte state. Call must be terminated
+ with `;'. */
+#if defined (HANDLE_MULTIBYTE)
+# define DECLARE_MBSTATE \
+ mbstate_t state; \
+ memset (&state, '\0', sizeof (mbstate_t))
+#else
+# define DECLARE_MBSTATE
+#endif /* !HANDLE_MULTIBYTE */
+
+/* Initialize or reinitialize a multibyte state named `state'. Call must be
+ terminated with `;'. */
+#if defined (HANDLE_MULTIBYTE)
+# define INITIALIZE_MBSTATE memset (&state, '\0', sizeof (mbstate_t))
+#else
+# define INITIALIZE_MBSTATE
+#endif /* !HANDLE_MULTIBYTE */
+
+/* Advance one (possibly multi-byte) character in string _STR of length
+ _STRSIZE, starting at index _I. STATE must have already been declared. */
+#if defined (HANDLE_MULTIBYTE)
+# define ADVANCE_CHAR(_str, _strsize, _i) \
+ do \
+ { \
+ if (MB_CUR_MAX > 1) \
+ { \
+ mbstate_t state_bak; \
+ size_t mblength; \
+\
+ state_bak = state; \
+ mblength = mbrlen ((_str) + (_i), (_strsize) - (_i), &state); \
+\
+ if (mblength == (size_t)-2 || mblength == (size_t)-1) \
+ { \
+ state = state_bak; \
+ (_i)++; \
+ } \
+ else \
+ (_i) += mblength; \
+ } \
+ else \
+ (_i)++; \
+ } \
+ while (0)
+#else
+# define ADVANCE_CHAR(_str, _strsize, _i) (_i)++
+#endif /* !HANDLE_MULTIBYTE */
+
+/* Advance one (possibly multibyte) character in the string _STR of length
+ _STRSIZE.
+ SPECIAL: assume that _STR will be incremented by 1 after this call. */
+#if defined (HANDLE_MULTIBYTE)
+# define ADVANCE_CHAR_P(_str, _strsize) \
+ do \
+ { \
+ if (MB_CUR_MAX > 1) \
+ { \
+ mbstate_t state_bak; \
+ size_t mblength; \
+\
+ state_bak = state; \
+ mblength = mbrlen ((_str), (_strsize), &state); \
+\
+ if (mblength == (size_t)-2 || mblength == (size_t)-1) \
+ { \
+ state = state_bak; \
+ mblength = 1; \
+ } \
+ else \
+ (_str) += (mblength < 1) ? 0 : (mblength - 1); \
+ } \
+ } \
+ while (0)
+#else
+# define ADVANCE_CHAR_P(_str, _strsize)
+#endif /* !HANDLE_MULTIBYTE */
+
+/* Copy a single character from the string _SRC to the string _DST.
+ _SRCEND is a pointer to the end of _SRC. */
+#if defined (HANDLE_MULTIBYTE)
+# define COPY_CHAR_P(_dst, _src, _srcend) \
+ do \
+ { \
+ if (MB_CUR_MAX > 1) \
+ { \
+ mbstate_t state_bak; \
+ size_t mblength; \
+ int _k; \
+\
+ state_bak = state; \
+ mblength = mbrlen ((_src), (_srcend) - (_src), &state); \
+ if (mblength == (size_t)-2 || mblength == (size_t)-1) \
+ { \
+ state = state_bak; \
+ mblength = 1; \
+ } \
+ else \
+ mblength = (mblength < 1) ? 1 : mblength; \
+\
+ for (_k = 0; _k < mblength; _k++) \
+ *(_dst)++ = *(_src)++; \
+ } \
+ else \
+ *(_dst)++ = *(_src)++; \
+ } \
+ while (0)
+#else
+# define COPY_CHAR_P(_dst, _src, _srcend) *(_dst)++ = *(_src)++
+#endif /* !HANDLE_MULTIBYTE */
+
+/* Copy a single character from the string _SRC at index _SI to the string
+ _DST at index _DI. _SRCEND is a pointer to the end of _SRC. */
+#if defined (HANDLE_MULTIBYTE)
+# define COPY_CHAR_I(_dst, _di, _src, _srcend, _si) \
+ do \
+ { \
+ if (MB_CUR_MAX > 1) \
+ { \
+ mbstate_t state_bak; \
+ size_t mblength; \
+ int _k; \
+\
+ state_bak = state; \
+ mblength = mbrlen ((_src) + (_si), (_srcend) - ((_src)+(_si)), &state); \
+ if (mblength == (size_t)-2 || mblength == (size_t)-1) \
+ { \
+ state = state_bak; \
+ mblength = 1; \
+ } \
+ else \
+ mblength = (mblength < 1) ? 1 : mblength; \
+\
+ for (_k = 0; _k < mblength; _k++) \
+ _dst[_di++] = _src[_si++]; \
+ } \
+ else \
+ _dst[_di++] = _src[_si++]; \
+ } \
+ while (0)
+#else
+# define COPY_CHAR_I(_dst, _di, _src, _srcend, _si) _dst[_di++] = _src[_si++]
+#endif /* !HANDLE_MULTIBYTE */
+
+/****************************************************************
+ * *
+ * The following are only guaranteed to work in subst.c *
+ * *
+ ****************************************************************/
+
+#if defined (HANDLE_MULTIBYTE)
+# define SCOPY_CHAR_I(_dst, _escchar, _sc, _src, _si, _slen) \
+ do \
+ { \
+ if (MB_CUR_MAX > 1) \
+ { \
+ mbstate_t state_bak; \
+ size_t mblength; \
+ int _i; \
+\
+ state_bak = state; \
+ mblength = mbrlen ((_src) + (_si), (_slen) - (_si), &state); \
+ if (mblength == (size_t)-2 || mblength == (size_t)-1) \
+ { \
+ state = state_bak; \
+ mblength = 1; \
+ } \
+ else \
+ mblength = (mblength < 1) ? 1 : mblength; \
+\
+ temp = xmalloc (mblength + 2); \
+ temp[0] = _escchar; \
+ for (_i = 0; _i < mblength; _i++) \
+ temp[_i + 1] = _src[_si++]; \
+ temp[mblength + 1] = '\0'; \
+\
+ goto add_string; \
+ } \
+ else \
+ { \
+ _dst[0] = _escchar; \
+ _dst[1] = _sc; \
+ } \
+ } \
+ while (0)
+#else
+# define SCOPY_CHAR_I(_dst, _escchar, _sc, _src, _si, _slen) \
+ _dst[0] = _escchar; \
+ _dst[1] = _sc
+#endif /* !HANDLE_MULTIBYTE */
+
+#if defined (HANDLE_MULTIBYTE)
+# define SCOPY_CHAR_M(_dst, _src, _srcend, _si) \
+ do \
+ { \
+ if (MB_CUR_MAX > 1) \
+ { \
+ mbstate_t state_bak; \
+ size_t mblength; \
+\
+ state_bak = state; \
+ mblength = mbrlen ((_src) + (_si), (_srcend) - ((_src) + (_si)), &state); \
+ if (mblength == (size_t)-2 || mblength == (size_t)-1) \
+ { \
+ state = state_bak; \
+ mblength = 1; \
+ } \
+ else \
+ mblength = (mblength < 1) ? 1 : mblength; \
+\
+ FASTCOPY(((_src) + (_si)), (_dst), mblength); \
+\
+ (_dst) += mblength; \
+ (_si) += mblength; \
+ } \
+ else \
+ { \
+ *(_dst)++ = _src[(_si)]; \
+ (_si)++; \
+ } \
+ } \
+ while (0)
+#else
+# define SCOPY_CHAR_M(_dst, _src, _srcend, _si) \
+ *(_dst)++ = _src[(_si)]; \
+ (_si)++
+#endif /* !HANDLE_MULTIBYTE */
+
+#if HANDLE_MULTIBYTE
+# define SADD_MBCHAR(_dst, _src, _si, _srcsize) \
+ do \
+ { \
+ if (MB_CUR_MAX > 1) \
+ { \
+ int i; \
+ mbstate_t state_bak; \
+ size_t mblength; \
+\
+ state_bak = state; \
+ mblength = mbrlen ((_src) + (_si), (_srcsize) - (_si), &state); \
+ if (mblength == (size_t)-1 || mblength == (size_t)-2) \
+ { \
+ state = state_bak; \
+ mblength = 1; \
+ } \
+ if (mblength < 1) \
+ mblength = 1; \
+\
+ _dst = (char *)xmalloc (mblength + 1); \
+ for (i = 0; i < mblength; i++) \
+ (_dst)[i] = (_src)[(_si)++]; \
+ (_dst)[mblength] = '\0'; \
+\
+ goto add_string; \
+ } \
+ } \
+ while (0)
+
+#else
+# define SADD_MBCHAR(_dst, _src, _si, _srcsize)
+#endif
+
+#endif /* _SH_MBUTIL_H_ */
diff --git a/include/stdc.h b/include/stdc.h
index 3106a90..05b743e 100644
--- a/include/stdc.h
+++ b/include/stdc.h
@@ -29,7 +29,7 @@
extern char *func __P((char *, char *, int)); */
#if !defined (__P)
-# if defined (__STDC__) || defined (__GNUC__) || defined (__cplusplus)
+# if defined (__STDC__) || defined (__GNUC__) || defined (__cplusplus) || defined (PROTOTYPES)
# define __P(protos) protos
# else
# define __P(protos) ()
@@ -71,4 +71,18 @@
# endif
#endif
+/* For those situations when gcc handles inlining a particular function but
+ other compilers complain. */
+#ifdef __GNUC__
+# define INLINE inline
+#else
+# define INLINE
+#endif
+
+#if defined (PREFER_STDARG)
+# define SH_VA_START(va, arg) va_start(va, arg)
+#else
+# define SH_VA_START(va, arg) va_start(va)
+#endif
+
#endif /* !_STDC_H_ */