zsh-workers
 help / color / mirror / code / Atom feed
* Re: PATCH: _whois
@ 1999-11-09  8:58 Sven Wischnowsky
  1999-11-09  9:09 ` Tanaka Akira
  1999-11-09 10:53 ` Bart Schaefer
  0 siblings, 2 replies; 6+ messages in thread
From: Sven Wischnowsky @ 1999-11-09  8:58 UTC (permalink / raw)
  To: zsh-workers


Tanaka Akira wrote:

> I modified _whois to complete arguments of fwhois.
> 
> And I found a problem.
> 
> Z:akr@is27e1u11% Src/zsh -f
> is27e1u11% bindkey -e; fpath=($PWD/Completion/*(/)); autoload -U compinit; compinit -D; compdef _tst tst
> is27e1u11% compconf group_matches=yes message_format='%d' description_format='%d'
> is27e1u11% compconf describe_options=yes describe_values=yes option_prefix=yes
> is27e1u11% comptag argument='*=1' option='*=2[describe]' glob='*=1' path='*=2' file='*=3'
> is27e1u11% fwhois 'DOMAIN <TAB>
> zsh: segmentation fault (core dumped)  Src/zsh -f
> 
> (gdb) where
> #0  0xff136d84 in strlen ()
> #1  0xa15d0 in bslashquote (s=0x0, e=0x0, instring=1) at utils.c:3011
> #2  0xff06da80 in multiquote (s=0x0, ign=1) at compcore.c:933
> #3  0xff071348 in addmatches (dat=0xffbe7280, argv=0x1d2634) at compcore.c:1711
> #4  0xff068238 in bin_compadd (name=0x1d24f0 "compadd", argv=0x1d2634, 
>     ops=0xffbe7388 "", func=0) at complete.c:606


I couldn't reproduce it, but judging from the stack trace, the patch
should fix this (patch-readers will notice that there even is some
redundancy in this patch, trying to avoid getting this bug again
later).

So, does it fix it?

Bye
 Sven

diff -u oldsrc/Zle/compcore.c Src/Zle/compcore.c
--- oldsrc/Zle/compcore.c	Mon Nov  8 13:29:49 1999
+++ Src/Zle/compcore.c	Tue Nov  9 09:11:12 1999
@@ -923,34 +923,40 @@
 char *
 multiquote(char *s, int ign)
 {
-    char *os = s, *p = compqstack;
+    if (s) {
+	char *os = s, *p = compqstack;
 
-    if (p && *p && (ign < 1 || p[ign])) {
-	if (ign > 0)
-	    p += ign;
-	while (*p) {
-	    if (ign >= 0 || p[1])
-		s = bslashquote(s, NULL,
-				(*p == '\'' ? 1 : (*p == '"' ? 2 : 0)));
-	    p++;
+	if (p && *p && (ign < 1 || p[ign])) {
+	    if (ign > 0)
+		p += ign;
+	    while (*p) {
+		if (ign >= 0 || p[1])
+		    s = bslashquote(s, NULL,
+				    (*p == '\'' ? 1 : (*p == '"' ? 2 : 0)));
+		p++;
+	    }
 	}
+	return (s == os ? dupstring(s) : s);
     }
-    return (s == os ? dupstring(s) : s);
+    return NULL;
 }
 
 /**/
 char *
 tildequote(char *s, int ign)
 {
-    int tilde;
+    if (s) {
+	int tilde;
 
-    if ((tilde = (*s == '~')))
-	*s = 'x';
-    s = multiquote(s, ign);
-    if (tilde)
-	*s = '~';
+	if ((tilde = (*s == '~')))
+	    *s = 'x';
+	s = multiquote(s, ign);
+	if (tilde)
+	    *s = '~';
 
-    return s;
+	return s;
+    }
+    return NULL;
 }
 
 /* Check if we have to complete a parameter name. */
@@ -1708,10 +1714,12 @@
 		} else if (dat->rems)
 		    dat->rems = dupstring(dat->rems);
 
-		lpre = ((!(dat->aflags & CAF_QUOTE) &&
-			 (!dat->ppre && (dat->flags & CMF_FILE))) ?
-			tildequote(lpre, 1) : multiquote(lpre, 1));
-		lsuf = multiquote(lsuf, 1);
+		if (lpre)
+		    lpre = ((!(dat->aflags & CAF_QUOTE) &&
+			     (!dat->ppre && (dat->flags & CMF_FILE))) ?
+			    tildequote(lpre, 1) : multiquote(lpre, 1));
+		if (lsuf)
+		    lsuf = multiquote(lsuf, 1);
 	    }
 	    /* Walk through the matches given. */
 	    obpl = bpl;

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 6+ messages in thread
* Re: PATCH: _whois
@ 1999-11-09 11:01 Sven Wischnowsky
  0 siblings, 0 replies; 6+ messages in thread
From: Sven Wischnowsky @ 1999-11-09 11:01 UTC (permalink / raw)
  To: zsh-workers


Bart Schaefer wrote:

> On Nov 9,  9:58am, Sven Wischnowsky wrote:
> } Subject: Re: PATCH: _whois
> }
> } (patch-readers will notice that there even is some
> } redundancy in this patch, trying to avoid getting this bug again
> } later).
> 
> I always experience some ambivalence about this sort of thing:
> 
> ...
> 
> So it would seem to me that there should at least be a DPUTS() in there,
> to mitigate the first couple of those effects.

I'm not really against this because, actually, I was thinking about
doing it myself. But then I decided that maybe it should be ok to call 
these two functions with a NULL pointer in the same way as it is ok to 
call functions like dupstring() with a NULL pointer.

Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 6+ messages in thread
* PATCH: _whois
@ 1999-11-08 22:09 Tanaka Akira
  0 siblings, 0 replies; 6+ messages in thread
From: Tanaka Akira @ 1999-11-08 22:09 UTC (permalink / raw)
  To: zsh-workers

I modified _whois to complete arguments of fwhois.

And I found a problem.

Z:akr@is27e1u11% Src/zsh -f
is27e1u11% bindkey -e; fpath=($PWD/Completion/*(/)); autoload -U compinit; compinit -D; compdef _tst tst
is27e1u11% compconf group_matches=yes message_format='%d' description_format='%d'
is27e1u11% compconf describe_options=yes describe_values=yes option_prefix=yes
is27e1u11% comptag argument='*=1' option='*=2[describe]' glob='*=1' path='*=2' file='*=3'
is27e1u11% fwhois 'DOMAIN <TAB>
zsh: segmentation fault (core dumped)  Src/zsh -f

(gdb) where
#0  0xff136d84 in strlen ()
#1  0xa15d0 in bslashquote (s=0x0, e=0x0, instring=1) at utils.c:3011
#2  0xff06da80 in multiquote (s=0x0, ign=1) at compcore.c:933
#3  0xff071348 in addmatches (dat=0xffbe7280, argv=0x1d2634) at compcore.c:1711
#4  0xff068238 in bin_compadd (name=0x1d24f0 "compadd", argv=0x1d2634, 
    ops=0xffbe7388 "", func=0) at complete.c:606
...

This may relate to 8588 since _whois use `compset -q'.

Index: Completion/User/_whois
===================================================================
RCS file: /projects/zsh/zsh/Completion/User/_whois,v
retrieving revision 1.1.1.3
diff -u -r1.1.1.3 _whois
--- Completion/User/_whois	1999/11/02 12:26:46	1.1.1.3
+++ Completion/User/_whois	1999/11/08 22:04:47
@@ -1,8 +1,11 @@
-#compdef whois
+#compdef whois fwhois
 
 _whois () {
   _whois_setup
-  $_whois_comp
+  case "$0" in
+  fwhois) _whois_fwhois;;
+  *) $_whois_comp;;
+  esac
 }
 
 (( $+functions[_whois_setup] )) ||
-- 
Tanaka Akira


^ permalink raw reply	[flat|nested] 6+ messages in thread
* PATCH: _whois
@ 1999-10-16  5:12 Tanaka Akira
  0 siblings, 0 replies; 6+ messages in thread
From: Tanaka Akira @ 1999-10-16  5:12 UTC (permalink / raw)
  To: zsh-workers

I wrote a completion function for whois.

Since whois has many variant (than telnet), it may not support some
variant.  I saw FreeBSD, BSD/OS, SunOS, Slackware and Debian for
reference.  At least it doesn't support ripe-whois enough yet.

--- /dev/null	Sat Oct 16 12:11:10 1999
+++ Completion/User/_whois	Sat Oct 16 14:05:29 1999
@@ -0,0 +1,211 @@
+#compdef whois
+
+_whois () {
+  setopt localoptions extendedglob
+  _whois_setup
+  $_whois_comp
+}
+
+builtin functions _whois_setup >&- ||
+_whois_setup () {
+  (( $+_whois_defaultserver )) ||
+    _whois_defaultserver='whois.internic.net'
+
+  (( $+_whois_servers )) || {
+    typeset -gUa _whois_servers
+    _whois_servers=(
+      $_whois_defaultserver
+      domain-registry.nl
+      is.nic.pw
+      whois.apnic.net:p
+      whois.arin.net:a
+      whois.aunic.net
+      whois.berkeley.edu
+      whois.cdnnet.ca
+      whois.dns.pt
+      whois.funet.fi
+      whois.gb.com
+      whois.gb.net
+      whois.internic.net
+      whois.jpl.nasa.gov
+      whois.nic-se.se
+      whois.nic.ad.jp
+      whois.nic.af
+      whois.nic.as
+      whois.nic.br
+      whois.nic.bt
+      whois.nic.ch
+      whois.nic.cx
+      whois.nic.fr
+      whois.nic.gov:g
+      whois.nic.hm
+      whois.nic.it
+      whois.nic.li
+      whois.nic.lk
+      whois.nic.mil:d
+      whois.nic.mx
+      whois.nic.nu
+      whois.nic.or.kr
+      whois.nic.sh
+      whois.nic.tj
+      whois.nic.tm
+      whois.nic.uk
+      whois.ripe.net:r
+      whois.ripn.net:R
+      whois.sics.se
+      whois.stanford.edu
+      whois.uk.com
+      www.nic.at
+      $(functions -m '_whois:*' |
+	awk '/^undefined _whois:/ {print substr($2,8,length($2)-7)}
+	     /^_whois:/ {print substr($1,8,length($1)-7)}')
+    )
+  }
+
+  (( $+_whois_arguments )) || {
+    local help="$(whois </dev/null 2>&1)"
+    local tmp opt opts
+
+    if [[ $help = *"user[@<whois.server>]"* ]]; then
+      _whois_comp=_whois_fwhois
+    elif [[ $help = *(name\ ...|OBJECT...)* ]]; then
+      _whois_comp=_whois_multi
+    else
+      _whois_comp=_whois_single
+    fi
+
+    _whois_arguments=()
+
+    if [[ $help = *"-p PORT"* ]]; then
+      _whois_arguments=("$_whois_arguments[@]"
+        '-p[port]:port:_whois_ports'
+      )
+    fi
+
+    tmp="${(j::)${(@)${(@M)_whois_servers:#*:?}##*:}}" 
+    if [[ $help = (#b)*\[-([$tmp]##)\]* ]]; then
+      tmp=(${(s::)match[1]})
+    else
+      tmp=()
+    fi
+
+    if [[ $help = *"-h host"* ]]; then
+      tmp=($tmp h)
+    fi
+
+    for opt in $tmp; do
+      opts=(-${^tmp:#$opt})
+      if (( $#opts )); then opts="($opts)"; else opts=; fi
+      _whois_arguments=("$_whois_arguments[@]"
+	"${opts}-${opt}[${${${(@M)_whois_servers:#*:$opt}%:?}:-specify host}]${(M)${(M)opt:#h}/h/:host:_whois_hosts}"
+      )
+    done
+  }
+}
+
+_whois_single () {
+  local state line expl
+  typeset -A opt_args
+  local tmp host
+
+  _arguments \
+    "$_whois_arguments[@]" \
+    ':identifier:->identifier'
+
+  case "$state" in
+  identifier)
+    if [[ -z "$QIPREFIX" ]]; then
+      compadd -QS '' \'
+      return
+    fi
+    compset -q
+    host="${opt_args[-h]:-$_whois_defaultserver}"
+    for tmp in $_whois_servers; do
+      if [[ $tmp = *:? && $+opt_args[-${tmp##*:}] -ne 0 ]]; then
+	host="${tmp%:?}"
+        break
+      fi
+    done
+    if builtin functions "_whois:$host" >&-; then
+      "_whois:$host" "$expl[@]"
+    else
+      _message "identifier"
+    fi
+    ;;
+  esac
+}
+
+_whois_multi () {
+  local state line expl
+  typeset -A opt_args
+  local tmp host
+
+  _arguments \
+    "$_whois_arguments[@]" \
+    '*::identifier:->identifier'
+
+  case "$state" in
+  identifier)
+    host="${opt_args[-h]:-$_whois_defaultserver}"
+    for tmp in $_whois_servers; do
+      if [[ $tmp = *:? && $+opt_args[-${tmp##*:}] -ne 0 ]]; then
+	host="${tmp%:?}"
+        break
+      fi
+    done
+    if builtin functions "_whois:$host" >&-; then
+      "_whois:$host" "$expl[@]"
+    else
+      _message "identifier"
+    fi
+    ;;
+  esac
+}
+
+_whois_fwhois () {
+  if compset -P '*@'; then
+    _whois_hosts "$@"
+  else
+    if [[ -z "$QIPREFIX" ]]; then
+      compadd -QS '' \'
+      return
+    fi
+    compset -q
+    host="$_whois_defaultserver"
+    if builtin functions "_whois:$host" >&-; then
+      "_whois:$host" "$@"
+    else
+      _message "identifier"
+    fi
+  fi
+}
+
+_whois_hosts () {
+  compadd "$@" \
+    -M 'm:{a-zA-Z}={A-Za-z} r:|.=* r:|=*' \
+    - ${_whois_servers%:?} || _hosts "$@"
+}
+
+_whois_ports () {
+  compadd "$@" - whois || _ports "$@"
+}
+
+builtin functions _whois:whois.internic.net >&- ||
+_whois:whois.internic.net () {
+  if (( CURRENT == 1 )); then
+    compadd HELP DOMAIN HOST
+  else
+    _message 'string'
+  fi
+}
+
+builtin functions _whois:whois.nic.ad.jp >&- ||
+_whois:whois.nic.ad.jp () {
+  if (( CURRENT == 1 )); then
+    compadd HELP DOM NET HOST PERSON CONN COM
+  else
+    _message 'string'
+  fi
+}
+
+_whois "$@"
-- 
Tanaka Akira


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~1999-11-09 11:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-11-09  8:58 PATCH: _whois Sven Wischnowsky
1999-11-09  9:09 ` Tanaka Akira
1999-11-09 10:53 ` Bart Schaefer
  -- strict thread matches above, loose matches on Subject: below --
1999-11-09 11:01 Sven Wischnowsky
1999-11-08 22:09 Tanaka Akira
1999-10-16  5:12 Tanaka Akira

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).