From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11795 invoked from network); 18 Jun 2008 16:16:23 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.4 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 18 Jun 2008 16:16:23 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 97368 invoked from network); 18 Jun 2008 16:16:13 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 18 Jun 2008 16:16:13 -0000 Received: (qmail 18501 invoked by alias); 18 Jun 2008 16:16:10 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 25210 Received: (qmail 18486 invoked from network); 18 Jun 2008 16:16:10 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 18 Jun 2008 16:16:10 -0000 Received: from mail.o2.co.uk (yoda.london.02.net [82.132.130.151]) by bifrost.dotsrc.org (Postfix) with ESMTP id 80EE98084FA0 for ; Wed, 18 Jun 2008 18:16:03 +0200 (CEST) Received: from sc.homeunix.net (78.105.216.138) by mail.o2.co.uk (8.0.013.3) (authenticated as stephane.chazelas) id 4851DD950101E867 for zsh-workers@sunsite.dk; Wed, 18 Jun 2008 17:16:02 +0100 Received: from chazelas by sc.homeunix.net with local (Exim 4.69) (envelope-from ) id 1K90KI-0007CS-Gz for zsh-workers@sunsite.dk; Wed, 18 Jun 2008 17:16:02 +0100 Date: Wed, 18 Jun 2008 17:16:02 +0100 From: Stephane Chazelas To: Zsh hackers list Subject: LD_PRELOAD trick for completing command options Message-ID: <20080618161602.GD5016@sc.homeunix.net> Mail-Followup-To: Zsh hackers list MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.5.16 (2007-09-19) X-Virus-Scanned: ClamAV 0.92.1/7499/Wed Jun 18 15:02:05 2008 on bifrost X-Virus-Status: Clean Hiya, I'm just submitting this idea in case nobody had it before: what about adding a small LD_PRELOAD wrapper for the getopts and getopt_long functions in the installation of zsh (on systems that support it) that could be used by the completion system for the completion of options: The completion system could do some nm -D to check whether the command uses getopt or getopt_long, check that the command is not setuid/setgid, and run the command with LD_PRELOAD=/that/wrapper cmd, and parse the output from the wrapper. Maybe not something to do for every command, but for commands for which we don't have a completion yet and know that doing this hack won't harm. Something like: $ LD_PRELOAD=./a.so w -: 3>&1 hlusfVo $ LD_PRELOAD=./a.so who -: 3>&1 abdlmpqrstuwHT all:0:a boot:0:b count:0:q dead:0:d heading:0:H ips:0: login:0:l lookup:0: message:0:T mesg:0:T process:0:p runlevel:0:r short:0:s time:0:t users:0:u writable:0:T help:0: version:0: #define _GNU_SOURCE #include #include #include #include int getopt_long(int argc, char * const argv[], const char *optstring, const struct option *longopts, int *longindex) { FILE* f = fdopen(3, "w"); if (!f) exit(111); fprintf(f, "%s\n", optstring); while (longopts->name) { int val = longopts->val; fprintf(f, "%s:%d:", longopts->name, longopts->has_arg); if (longopts->flag == NULL && val > 0 && val <= 0xFF && val != ':' && strchr(optstring, val)) fprintf(f, "%c\n", val); else fprintf(f, "\n"); longopts++; } exit(112); } int getopt(int argc, char * const argv[], const char *optstring) { FILE* f = fdopen(3, "w"); if (!f) exit(111); fprintf(f, "%s\n", optstring); exit(112); } Cheers, Stéphane