zsh-workers
 help / color / mirror / code / Atom feed
* new builtin 'help'
@ 2003-11-14 14:10 Miek Gieben
  2003-11-14 14:34 ` DervishD
  2003-11-14 17:01 ` Dan Nelson
  0 siblings, 2 replies; 5+ messages in thread
From: Miek Gieben @ 2003-11-14 14:10 UTC (permalink / raw)
  To: zsh-workers

[-- 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

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

* Re: new builtin 'help'
  2003-11-14 14:10 new builtin 'help' Miek Gieben
@ 2003-11-14 14:34 ` DervishD
  2003-11-14 14:52   ` Miek Gieben
  2003-11-14 17:01 ` Dan Nelson
  1 sibling, 1 reply; 5+ messages in thread
From: DervishD @ 2003-11-14 14:34 UTC (permalink / raw)
  To: Miek Gieben; +Cc: zsh-workers

    Hi Miek :)

 * Miek Gieben <miekg@atoom.net> dixit:
> after having used bash for 8 years i've switch to zsh. Boy, what a 
> difference :-)

    Yes ;))

> But one of the things i missed was a 'help' builtin function.

    Me too! But certainly I can't live without it ;)
 
> It just prints out the files in /usr/share/zsh/help/ when the help
> builtin is used. The path is currently hardcoded.

    And it shouldn't... How about taking it from a environment
variable? I mean, this way you can use the help shipped with zsh, or
other if you want to.

    IMHO, and taking into account that I don't decide, of course, is
a very good idea... Anyway, this can be implemented in a shell
function, is not necessary doing that in a builtin...

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/


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

* Re: new builtin 'help'
  2003-11-14 14:34 ` DervishD
@ 2003-11-14 14:52   ` Miek Gieben
  0 siblings, 0 replies; 5+ messages in thread
From: Miek Gieben @ 2003-11-14 14:52 UTC (permalink / raw)
  To: zsh-workers

[On 14 Nov, @15:34, DervishD wrote in "Re: new builtin 'help' ..."]
>     Hi Miek :)
> 
>  * Miek Gieben <miekg@atoom.net> dixit:
> > after having used bash for 8 years i've switch to zsh. Boy, what a 
> > difference :-)
> 
>     Yes ;))
> 
> > But one of the things i missed was a 'help' builtin function.
> 
>     Me too! But certainly I can't live without it ;)
>  
> > It just prints out the files in /usr/share/zsh/help/ when the help
> > builtin is used. The path is currently hardcoded.
> 
>     And it shouldn't... How about taking it from a environment
> variable? I mean, this way you can use the help shipped with zsh, or
> other if you want to.

that is an option, but I would have thought that such a path is
set at compile time. So maybe using a configure-var is what is needed.
OTOH using an ENV var is also nice and clean.

>     IMHO, and taking into account that I don't decide, of course, is
> a very good idea... Anyway, this can be implemented in a shell
> function, is not necessary doing that in a builtin...

true, but I felt liking coding in C ;-) (and in the same hold for bash btw,
it could also be a function there)

grtz
      Miek
--
"So long, and thanks for all the fish." 
-- Hitchhikers Guide to the Galaxy


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

* Re: new builtin 'help'
  2003-11-14 14:10 new builtin 'help' Miek Gieben
  2003-11-14 14:34 ` DervishD
@ 2003-11-14 17:01 ` Dan Nelson
  2003-11-14 17:24   ` Miek Gieben
  1 sibling, 1 reply; 5+ messages in thread
From: Dan Nelson @ 2003-11-14 17:01 UTC (permalink / raw)
  To: Miek Gieben; +Cc: zsh-workers

In the last episode (Nov 14), Miek Gieben said:
> 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.

You must have missed Functions/Misc/run-help :)  Set HELPDIR, and it
will look there, or fall back to manpages.

-- 
	Dan Nelson
	dnelson@allantgroup.com


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

* Re: new builtin 'help'
  2003-11-14 17:01 ` Dan Nelson
@ 2003-11-14 17:24   ` Miek Gieben
  0 siblings, 0 replies; 5+ messages in thread
From: Miek Gieben @ 2003-11-14 17:24 UTC (permalink / raw)
  To: Dan Nelson; +Cc: zsh-workers

[On 14 Nov, @18:01, Dan wrote in "Re: new builtin 'help' ..."]
> In the last episode (Nov 14), Miek Gieben said:
> > 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.
> 
> You must have missed Functions/Misc/run-help :)  Set HELPDIR, and it
> will look there, or fall back to manpages.

I sure did ;_) that works pretty neat. 

And it is even installed on my debian system by default :)

ah well, it was fun to make the patch,

thanks,
grtz Miek


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

end of thread, other threads:[~2003-11-14 17:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-14 14:10 new builtin 'help' Miek Gieben
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

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).