summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManuel Presnitz <mpy@gmx.net>2014-02-19 14:12:03 +0100
committerPeter Stephenson <p.w.stephenson@ntlworld.com>2014-03-01 19:08:17 +0000
commit973e5dc37d27cf5c39f33b0ff8839b167004bf3f (patch)
treeb570ea6986e73a3693f30b68bae36ff63df1f1f3
parentf798f13b0eba1f31cd2d760441ac9d36a6ac5263 (diff)
downloadzsh-973e5dc37d27cf5c39f33b0ff8839b167004bf3f.tar.gz
zsh-973e5dc37d27cf5c39f33b0ff8839b167004bf3f.zip
32412 / 32415: New giga- and terabyte units for glob qualifiers
-rw-r--r--ChangeLog8
-rw-r--r--Completion/Zsh/Type/_globquals6
-rw-r--r--Doc/Zsh/expn.yo10
-rw-r--r--Src/glob.c22
-rw-r--r--Src/zsh.h29
5 files changed, 62 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index 201f27399..7344e7a16 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2014-03-01 Peter Stephenson <p.w.stephenson@ntlworld.com>
+
+ * Manuel Presnitz: 32412 modified c.f. 32415:
+ Completion/Zsh/Type/_globquals, Doc/Zsh/expn.yo, Src/glob.c,
+ Src/zsh.h: gigabyte and terabyte units for glob qualifiers.
+
2014-02-28 Peter Stephenson <p.stephenson@samsung.com>
* users/18531 plus doc etc.: Doc/Zsh/contrib.yo,
@@ -6,7 +12,7 @@
2014-02-26 Peter Stephenson <p.w.stephenson@ntlworld.com>
- * Jun T: Completion/Base/Core/_description,
+ * Jun T: 32435: Completion/Base/Core/_description,
Completion/Unix/Command/_rm: improved quoting for ignore-line
style.
diff --git a/Completion/Zsh/Type/_globquals b/Completion/Zsh/Type/_globquals
index 9de7742ff..c98bd0c82 100644
--- a/Completion/Zsh/Type/_globquals
+++ b/Completion/Zsh/Type/_globquals
@@ -132,13 +132,13 @@ while [[ -n $PREFIX ]]; do
(L)
# complete/skip file size
- if ! compset -P '([kKmMpP]|)([-+]|)<->'; then
+ if ! compset -P '([kKmMgGtTpP]|)([-+]|)<->'; then
# complete/skip size spec
alts=()
- if ! compset -P '[kKmMpP]' && [[ -z $PREFIX ]]; then
+ if ! compset -P '[kKmMgGtTpP]' && [[ -z $PREFIX ]]; then
alts+=(
"size-specifiers:size specifier:\
-((k\:kb m\:mb p\:512-byte\ blocks))")
+((k\:kb m\:mb g\:gb t\:tb p\:512-byte\ blocks))")
fi
if ! compset -P '[-+]' && [[ -z $PREFIX ]]; then
alts+=("senses:sense:((-\:less\ than +\:more\ than))")
diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo
index 6459c6ff7..de0f454c4 100644
--- a/Doc/Zsh/expn.yo
+++ b/Doc/Zsh/expn.yo
@@ -2521,10 +2521,12 @@ item(tt(L)[tt(PLUS())|tt(-)]var(n))(
files less than var(n) bytes (tt(-)), more than var(n) bytes (tt(PLUS())), or
exactly var(n) bytes in length.
-If this flag is directly followed by a `tt(k)' (`tt(K)'), `tt(m)'
-(`tt(M)'), or `tt(p)' (`tt(P)') (e.g. `tt(Lk-50)') the check is performed
-with kilobytes, megabytes, or blocks (of 512 bytes) instead. In this
-case a file is regarded as "exactly" the size if the file size rounded up
+If this flag is directly followed by a em(size specifier) `tt(k)' (`tt(K)'),
+`tt(m)' (`tt(M)'), or `tt(p)' (`tt(P)') (e.g. `tt(Lk-50)') the check is
+performed with kilobytes, megabytes, or blocks (of 512 bytes) instead.
+(On some systems additional specifiers are available for gigabytes,
+`tt(g)' or `tt(G)', and terabytes, `tt(t)' or `tt(T)'.) If a size specifier
+is used a file is regarded as "exactly" the size if the file size rounded up
to the next unit is equal to the test size. Hence `tt(*LPAR()Lm1+RPAR())'
matches files from 1 byte up to 1 Megabyte inclusive. Note also that
the set of files "less than" the test size only includes files that would
diff --git a/Src/glob.c b/Src/glob.c
index c32d581a3..07dd7c2d4 100644
--- a/Src/glob.c
+++ b/Src/glob.c
@@ -120,6 +120,8 @@ typedef struct stat *Statptr; /* This makes the Ultrix compiler happy. Go figu
#define TT_POSIX_BLOCKS 1
#define TT_KILOBYTES 2
#define TT_MEGABYTES 3
+#define TT_GIGABYTES 4
+#define TT_TERABYTES 5
typedef int (*TestMatchFunc) _((char *, struct stat *, off_t, char *));
@@ -1486,6 +1488,12 @@ zglob(LinkList list, LinkNode np, int nountok)
g_units = TT_KILOBYTES, ++s;
else if (*s == 'm' || *s == 'M')
g_units = TT_MEGABYTES, ++s;
+#if defined(ZSH_64_BIT_TYPE) || defined(LONG_IS_64_BIT)
+ else if (*s == 'g' || *s == 'G')
+ g_units = TT_GIGABYTES, ++s;
+ else if (*s == 't' || *s == 'T')
+ g_units = TT_TERABYTES, ++s;
+#endif
getrange:
/* Get time multiplier */
if (g_amc >= 0) {
@@ -3538,9 +3546,9 @@ qualiscom(UNUSED(char *name), struct stat *buf, UNUSED(off_t mod), UNUSED(char *
static int
qualsize(UNUSED(char *name), struct stat *buf, off_t size, UNUSED(char *dummy))
{
-#if defined(LONG_IS_64_BIT) || defined(OFF_T_IS_64_BIT)
+#if defined(ZSH_64_BIT_TYPE) || defined(LONG_IS_64_BIT)
# define QS_CAST_SIZE()
- off_t scaled = buf->st_size;
+ zlong scaled = buf->st_size;
#else
# define QS_CAST_SIZE() (unsigned long)
unsigned long scaled = (unsigned long)buf->st_size;
@@ -3559,6 +3567,16 @@ qualsize(UNUSED(char *name), struct stat *buf, off_t size, UNUSED(char *dummy))
scaled += 1048575l;
scaled /= 1048576l;
break;
+#if defined(ZSH_64_BIT_TYPE) || defined(LONG_IS_64_BIT)
+ case TT_GIGABYTES:
+ scaled += ZLONG_CONST(1073741823);
+ scaled /= ZLONG_CONST(1073741824);
+ break;
+ case TT_TERABYTES:
+ scaled += ZLONG_CONST(1099511627775);
+ scaled /= ZLONG_CONST(1099511627776);
+ break;
+#endif
}
return (g_range < 0 ? scaled < QS_CAST_SIZE() size :
diff --git a/Src/zsh.h b/Src/zsh.h
index c86d2a62c..5fbff5767 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -33,9 +33,6 @@
/*
* Our longest integer type: will be a 64 bit either if long already is,
* or if we found some alternative such as long long.
- * Currently we only define this to be longer than a long if
- * --enable-largefile * was given. That enables internal use of 64-bit
- * types even if no actual large file support is present.
*/
#ifdef ZSH_64_BIT_TYPE
typedef ZSH_64_BIT_TYPE zlong;
@@ -50,6 +47,32 @@ typedef unsigned long zulong;
#endif
/*
+ * Work out how to define large integer constants that will fit
+ * in a zlong.
+ */
+#if defined(ZSH_64_BIT_TYPE) || defined(LONG_IS_64_BIT)
+/* We have some 64-bit type */
+#ifdef LONG_IS_64_BIT
+/* It's long */
+#define ZLONG_CONST(x) x ## l
+#else
+/* It's long long */
+#ifdef ZLONG_IS_LONG_LONG
+#define ZLONG_CONST(x) x ## ll
+#else
+/*
+ * There's some 64-bit type, but we don't know what it is.
+ * We'll just cast it and hope the compiler does the right thing.
+ */
+#define ZLONG_CONST(x) ((zlong)x)
+#endif
+#endif
+#else
+/* We're stuck with long */
+#define ZLONG_CONST(x) (x ## l)
+#endif
+
+/*
* Double float support requires 64-bit alignment, so if longs and
* pointers are less we need to pad out.
*/