Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: A more complete "limit ... unlimited"
- X-seq: zsh-workers 16197
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: PATCH: A more complete "limit ... unlimited"
- Date: Wed, 31 Oct 2001 17:12:22 +0000
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
This adds a completion for _limit that understands that the limit names are
the odd-numbered arguments, with values between them, and completes the
value "unlimited" in the same way that _ulimit does.
The patch to rlimits.c itself has also become a bit simpler.
Index: zsh-4.1/Completion/Zsh/Command/.distfiles
--- zsh-forge/current/Completion/Zsh/Command/.distfiles Wed May 30 08:07:16 2001
+++ zsh-4.1/Completion/Zsh/Command/.distfiles Thu Oct 25 08:53:00 2001
@@ -1,10 +1,10 @@
DISTFILES_SRC='
.distfiles
-_autoload _disable _kill _sched _typeset _zed
-_bindkey _echotc _mere _set _unhash _zftp
-_builtin _emulate _precommand _setopt _unsetopt _zle
-_cd _enable _print _source _wait _zmodload
-_command _fc _prompt _stat _which _zpty
-_compdef _hash _read _trap _zcompile _zstyle
-_echoti _ttyctl _ulimit _vared _alias _jobs_builtin
+_alias _disable _jobs_builtin _read _ttyctl _which _zstyle
+_autoload _echotc _kill _sched _typeset _zcompile
+_bindkey _echoti _limit _set _ulimit _zed
+_builtin _emulate _mere _setopt _unhash _zftp
+_cd _enable _precommand _source _unsetopt _zle
+_command _fc _print _stat _vared _zmodload
+_compdef _hash _prompt _trap _wait _zpty
'
Index: zsh-4.1/Completion/Zsh/Command/_limit
--- zsh-forge/current/Completion/Zsh/Command/_limit Wed Dec 31 16:00:00 1969
+++ zsh-4.1/Completion/Zsh/Command/_limit Wed Oct 24 09:32:56 2001
@@ -0,0 +1,9 @@
+#compdef limit
+
+if ! ((CURRENT % 2)); then
+ _limits
+elif [[ $PREFIX = u* ]]; then
+ compadd unlimited
+else
+ _message "number and scaling factor"
+fi
Index: zsh-4.1/Completion/Zsh/Type/_limits
--- zsh-forge/current/Completion/Zsh/Type/_limits Mon Apr 2 04:18:56 2001
+++ zsh-4.1/Completion/Zsh/Type/_limits Wed Oct 24 09:30:10 2001
@@ -1,4 +1,4 @@
-#compdef limit unlimit
+#compdef unlimit
local expl
Index: zsh-4.1/Src/Builtins/rlimits.c
--- zsh-forge/current/Src/Builtins/rlimits.c Thu Oct 25 08:49:02 2001
+++ zsh-4.1/Src/Builtins/rlimits.c Sun Oct 28 14:21:43 2001
@@ -44,12 +44,17 @@
# include "rlimits.h"
-# if defined(RLIM_T_IS_QUAD_T) || defined(RLIM_T_IS_LONG_LONG) || defined(RLIM_T_IS_UNSIGNED)
static rlim_t
zstrtorlimt(const char *s, char **t, int base)
{
rlim_t ret = 0;
-
+
+ if (strcmp(s, "unlimited") == 0) {
+ if (t)
+ *t = (char *) s + 9;
+ return RLIM_INFINITY;
+ }
+# if defined(RLIM_T_IS_QUAD_T) || defined(RLIM_T_IS_LONG_LONG) || defined(RLIM_T_IS_UNSIGNED)
if (!base) {
if (*s != '0')
base = 10;
@@ -67,11 +72,11 @@
ret = ret * base + (idigit(*s) ? (*s - '0') : (*s & 0x1f) + 9);
if (t)
*t = (char *)s;
- return ret;
-}
# else /* !RLIM_T_IS_QUAD_T && !RLIM_T_IS_LONG_LONG && !RLIM_T_IS_UNSIGNED */
-# define zstrtorlimt(a, b, c) zstrtol((a), (b), (c))
+ ret = zstrtol(s, t, base);
# endif /* !RLIM_T_IS_QUAD_T && !RLIM_T_IS_LONG_LONG && !RLIM_T_IS_UNSIGNED */
+ return ret;
+}
/* Display resource limits. hard indicates whether `hard' or `soft' *
* limits should be displayed. lim specifies the limit, or may be -1 *
@@ -348,9 +353,10 @@
/* memory-type resource -- `k' and `M' modifiers are permitted,
meaning (respectively) 2^10 and 2^20. */
val = zstrtorlimt(s, &s, 10);
- if (!*s || ((*s == 'k' || *s == 'K') && !s[1]))
- val *= 1024L;
- else if ((*s == 'M' || *s == 'm') && !s[1])
+ if (!*s || ((*s == 'k' || *s == 'K') && !s[1])) {
+ if (val != RLIM_INFINITY)
+ val *= 1024L;
+ } else if ((*s == 'M' || *s == 'm') && !s[1])
val *= 1024L * 1024;
else {
zwarnnam("limit", "unknown scaling factor: %s", s, 0);
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net
Messages sorted by:
Reverse Date,
Date,
Thread,
Author