zsh-workers
 help / color / mirror / code / Atom feed
From: Miek Gieben <miekg@atoom.net>
To: zsh-workers@sunsite.dk
Subject: new builtin 'help'
Date: Fri, 14 Nov 2003 15:10:15 +0100	[thread overview]
Message-ID: <20031114141015.GA12667@atoom.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 954 bytes --]

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

[-- Attachment #2: zsh-help.patch --]
[-- Type: text/plain, Size: 3830 bytes --]

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

             reply	other threads:[~2003-11-14 14:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-14 14:10 Miek Gieben [this message]
2003-11-14 14:34 ` DervishD
2003-11-14 14:52   ` Miek Gieben
2003-11-14 17:01 ` Dan Nelson
2003-11-14 17:24   ` Miek Gieben

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20031114141015.GA12667@atoom.net \
    --to=miekg@atoom.net \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).