From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4618 invoked from network); 14 Nov 2003 14:12:09 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 14 Nov 2003 14:12:09 -0000 Received: (qmail 26330 invoked by alias); 14 Nov 2003 14:12:02 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 19247 Received: (qmail 12110 invoked from network); 14 Nov 2003 14:10:20 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 14 Nov 2003 14:10:20 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [213.154.224.1] by sunsite.dk (MessageWall 1.0.8) with SMTP; 14 Nov 2003 14:10:20 -0000 Received: from elektron.atoom.net (f52166.upc-f.chello.nl [80.56.52.166]) by open.nlnetlabs.nl (8.12.8p2/8.12.8) with ESMTP id hAEEAGGl051473 for ; Fri, 14 Nov 2003 15:10:16 +0100 (CET) (envelope-from miekg@atoom.net) Received: from elektron.atoom.net (localhost [127.0.0.1]) by elektron.atoom.net (8.12.10/8.12.10/Debian-4) with ESMTP id hAEEAG2R012863 for ; Fri, 14 Nov 2003 15:10:16 +0100 Received: (from miekg@localhost) by elektron.atoom.net (8.12.10/8.12.10/Debian-4) id hAEEAGII012862 for zsh-workers@sunsite.dk; Fri, 14 Nov 2003 15:10:16 +0100 Date: Fri, 14 Nov 2003 15:10:15 +0100 From: Miek Gieben To: zsh-workers@sunsite.dk Subject: new builtin 'help' Message-ID: <20031114141015.GA12667@atoom.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="MGYHOYXEY6WxJCY8" Content-Disposition: inline User-Agent: Vim/Mutt/Linux X-Home: www.miek.nl X-Spam-Status: No, hits=0.0 required=5.0 tests=none autolearn=no version=2.60 X-Spam-Checker-Version: SpamAssassin 2.60 (1.212-2003-09-23-exp) on open.nlnetlabs.nl X-Virus-Scanned: by amavisd-new --MGYHOYXEY6WxJCY8 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hello, after having used bash for 8 years i've switch to zsh. Boy, what a difference :-) But one of the things i missed was a 'help' builtin function. So I took the liberty to add it to zsh, I used version 4.0.7 for it. How it works: It just prints out the files in /usr/share/zsh/help/ when the help builtin is used. The path is currently hardcoded. I've just looked at the sources for a few hours, so a lot of stuff in my patch will be not in the zsh-way of doing it. If there is interest in this patch I will of course fix that. Todo: o program more in zsh style (remove hardcoded paths) o identation is wrong o make a help help work o write doc for help o port it to latest development version of zsh Patch is attached (against 4.0.7). Is this considered usefull? thanks, grtz Miek Oh btw, i'm not subscribed to the workers ML, only to the zsh-users ML. -- "So long, and thanks for all the fish." -- Hitchhikers Guide to the Galaxy --MGYHOYXEY6WxJCY8 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="zsh-help.patch" diff -u zsh-4.0.7/Src/builtin.c zsh-4.0.7-help/Src/builtin.c --- zsh-4.0.7/Src/builtin.c 2003-05-07 11:28:23.000000000 +0200 +++ zsh-4.0.7-help/Src/builtin.c 2003-11-14 14:26:38.000000000 +0100 @@ -73,6 +73,7 @@ BUILTIN("hashinfo", 0, bin_hashinfo, 0, 0, 0, NULL, NULL), #endif + BUILTIN("help", 0, bin_help, 0, -1, 0, NULL, NULL), BUILTIN("history", 0, bin_fc, 0, -1, BIN_FC, "nrdDfEim", "l"), BUILTIN("integer", BINF_TYPEOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "Hghilrtux", "i"), BUILTIN("jobs", 0, bin_fg, 0, -1, BIN_JOBS, "dlpZrs", NULL), @@ -1202,6 +1203,50 @@ } } +/* bin_help */ + +/**/ +int +bin_help(char *nam, char **argv, char *ops, int func) +{ + /* + * look the explanation up in /usr/share/zsh/help + * and print it on stdout + */ + + char *helpfile = NULL; + char *line = NULL; + FILE *help = NULL; + size_t j = 0; + + if ( argv[0] == NULL ) + return 1; + + helpfile = (char*)zalloc(strlen("/usr/share/zsh/help/") + strlen(argv[0]) + 1); + sprintf(helpfile,"/usr/share/zsh/help/%s",argv[0]); + + /* open the file, if that works print out the contents to screen */ + help = fopen(helpfile, "r"); + zfree(helpfile, 0); + if ( help == NULL ) { + zwarnnam(nam, "no help available for: %s", argv[0], 0); + return 1; + } + + + line = (char*)zalloc(90); /* 90 bytes per line should be enough */ + + /* getline, does some resizing of its own --- *frown* */ + while ( getline(&line, &j, help ) != 1 ) + printf("%s",line); + + zfree(line,90); /* this could be too little... */ + fclose(help); + + return 0; +} + + /**** history list functions ****/ /* fc, history, r */ diff -u zsh-4.0.7/Src/builtin.epro zsh-4.0.7-help/Src/builtin.epro --- zsh-4.0.7/Src/builtin.epro 2003-11-14 14:42:45.000000000 +0100 +++ zsh-4.0.7-help/Src/builtin.epro 2003-11-14 14:40:36.000000000 +0100 @@ -17,6 +17,7 @@ extern int fixdir _((char*src)); extern mod_import_function void printqt _((char*str)); extern mod_import_function void printif _((char*str,int c)); +extern int bin_help _((char*nam,char**argv,char*ops,int func)); extern int bin_fc _((char*nam,char**argv,char*ops,int func)); extern Param typeset_single _((char*cname,char*pname,Param pm,int func,int on,int off,int roff,char*value,Param altpm)); extern int bin_typeset _((char*name,char**argv,char*ops,int func)); Binary files zsh-4.0.7/Src/builtin.o and zsh-4.0.7-help/Src/builtin.o differ Common subdirectories: zsh-4.0.7/Src/Builtins and zsh-4.0.7-help/Src/Builtins diff -u zsh-4.0.7/Src/builtin.syms zsh-4.0.7-help/Src/builtin.syms --- zsh-4.0.7/Src/builtin.syms 2003-11-14 14:42:45.000000000 +0100 +++ zsh-4.0.7-help/Src/builtin.syms 2003-11-14 14:40:36.000000000 +0100 @@ -27,6 +27,7 @@ Eextern mod_import_function void printqt _((char*str)); Xprintif Eextern mod_import_function void printif _((char*str,int c)); +Eextern int bin_help _((char*nam,char**argv,char*ops,int func)); Eextern int bin_fc _((char*nam,char**argv,char*ops,int func)); Lstatic int fcgetcomm _((char*s)); Lstatic int fcsubs _((char**sp,struct asgment*sub)); diff -u zsh-4.0.7/Src/hashtable.h zsh-4.0.7-help/Src/hashtable.h --- zsh-4.0.7/Src/hashtable.h 1999-04-15 20:05:38.000000000 +0200 +++ zsh-4.0.7-help/Src/hashtable.h 2003-11-14 13:54:21.000000000 +0100 @@ -56,6 +56,7 @@ #define BIN_ECHO 22 #define BIN_DISABLE 23 #define BIN_ENABLE 24 +#define BIN_HELP 25 /* These currently depend on being 0 and 1. */ #define BIN_SETOPT 0 Common subdirectories: zsh-4.0.7/Src/Modules and zsh-4.0.7-help/Src/Modules Common subdirectories: zsh-4.0.7/Src/Zle and zsh-4.0.7-help/Src/Zle Binary files zsh-4.0.7/Src/zsh and zsh-4.0.7-help/Src/zsh differ --MGYHOYXEY6WxJCY8--